2 # Copyright (C) 2009-2013 by Daniel Stenberg
4 # Permission to use, copy, modify, and distribute this
5 # software and its documentation for any purpose and without
6 # fee is hereby granted, provided that the above copyright
7 # notice appear in all copies and that both that copyright
8 # notice and this permission notice appear in supporting
9 # documentation, and that the name of M.I.T. not be used in
10 # advertising or publicity pertaining to distribution of the
11 # software without specific, written prior permission.
12 # M.I.T. makes no representations about the suitability of
13 # this software for any purpose. It is provided "as is"
14 # without express or implied warranty.
16 # ------------------------------------------------------------------------------
18 # Makefile for building c-ares libraries and sample programs with MSVC.
20 # Usage: nmake /f makefile.msvc CFG=<config> <target>
22 # <config> must be one of: [ lib-release | lib-debug | dll-release | dll-debug }
23 # <target> must be one of: [ ALL | c-ares | acountry | adig | ahost | clean }
25 # If a <target> other than ALL or clean is given, <config> becomes mandatory.
27 # If neither <config> nor <target> are specified this results in
28 # all targets being built for all <config> c-ares library types.
30 # This makefile must be processed from the subdir where it is located.
32 # All results are generated below a subdirectory named msvcXXX.
34 # ------------------------------------------------------------------------------
38 # ------------------------------------------------
39 # c-ares static and dynamic libraries common base
40 # file names for release and debug configurations
41 # ------------------------------------------------
43 STA_LIB_REL = lib$(NAME)
45 STA_LIB_DBG = $(STA_LIB_REL)d
46 DYN_LIB_DBG = $(DYN_LIB_REL)d
48 # -------------------------------------------
49 # Base names for c-ares DLL import libraries
50 # -------------------------------------------
52 IMP_LIB_REL = $(DYN_LIB_REL)
53 IMP_LIB_DBG = $(DYN_LIB_DBG)
55 # --------------------------
56 # Runtime library selection
57 # --------------------------
62 !IF "$(RTLIBCFG)" == "static"
67 # --------------------------------------------------------
68 # Define USE_WATT32 to 1 to use the Watt-32 tcp/ip stack,
69 # otherwise Winsock tcp/ip stack will be used as default.
70 # --------------------------------------------------------
74 # -------------------------------------------
75 # Detect NMAKE version deducing MSVC version
76 # -------------------------------------------
79 ! MESSAGE Macro _NMAKE_VER not defined.
80 ! MESSAGE Use MSVC's NMAKE to process this makefile.
81 ! ERROR See previous message.
84 !IF "$(_NMAKE_VER)" == "6.00.8168.0"
86 !ELSEIF "$(_NMAKE_VER)" == "6.00.9782.0"
88 !ELSEIF "$(_NMAKE_VER)" == "7.00.8882"
90 !ELSEIF "$(_NMAKE_VER)" == "7.00.9466"
92 !ELSEIF "$(_NMAKE_VER)" == "7.00.9955"
94 !ELSEIF "$(_NMAKE_VER)" == "7.10.2240.8"
96 !ELSEIF "$(_NMAKE_VER)" == "7.10.3077"
98 !ELSEIF "$(_NMAKE_VER)" == "8.00.40607.16"
100 !ELSEIF "$(_NMAKE_VER)" == "8.00.50727.42"
102 !ELSEIF "$(_NMAKE_VER)" == "8.00.50727.762"
104 !ELSEIF "$(_NMAKE_VER)" == "9.00.20706.01"
106 !ELSEIF "$(_NMAKE_VER)" == "9.00.21022.08"
108 !ELSEIF "$(_NMAKE_VER)" == "9.00.30729.01"
110 !ELSEIF "$(_NMAKE_VER)" == "10.00.20506.01"
112 !ELSEIF "$(_NMAKE_VER)" == "10.00.21003.01"
114 !ELSEIF "$(_NMAKE_VER)" == "10.00.30128.01"
116 !ELSEIF "$(_NMAKE_VER)" == "10.00.30319.01"
118 !ELSEIF "$(_NMAKE_VER)" == "10.00.40219.01"
120 !ELSEIF "$(_NMAKE_VER)" == "11.00.50522.1"
122 !ELSEIF "$(_NMAKE_VER)" == "11.00.50727.1"
124 !ELSEIF "$(_NMAKE_VER)" == "11.00.51106.1"
127 ! MESSAGE Unknown value for _NMAKE_VER macro: "$(_NMAKE_VER)"
128 ! MESSAGE Please, report this condition on the c-ares development
129 ! MESSAGE mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
130 ! ERROR See previous message.
133 CC_VERS_STR = msvc$(CC_VERS_NUM)
135 # ----------------------------------------------------
136 # Verify that current subdir is the c-ares source one
137 # ----------------------------------------------------
139 !IF ! EXIST(.\ares_init.c)
140 ! MESSAGE Can not process Makefile.msvc from outside of c-ares source subdirectory.
141 ! MESSAGE Change to the subdirectory where Makefile.msvc is found, and try again.
142 ! ERROR See previous message.
145 # ------------------------------------------------------------------
146 # Base subdir is the common root from which other subdirs will hang,
147 # the name depends on MSVC version being used when building c-ares.
148 # ------------------------------------------------------------------
150 BASE_DIR = .\$(CC_VERS_STR)
152 # ----------------------------------------
153 # Subdir holding sources for all projects
154 # ----------------------------------------
158 # -----------------------------
159 # Default installation subdirs
160 # -----------------------------
166 !IFNDEF INSTALL_DIR_LIB
167 INSTALL_DIR_LIB = $(INSTALL_DIR)\lib
170 !IFNDEF INSTALL_DIR_INC
171 INSTALL_DIR_INC = $(INSTALL_DIR)\include
174 # -------------------------
175 # Configuration validation
176 # -------------------------
179 !IF "$(CFG)" == "lib-release" || "$(CFG)" == "lib-debug" || \
180 "$(CFG)" == "dll-release" || "$(CFG)" == "dll-debug"
184 !IF "$(VALID_CFGSET)" == "FALSE" && "$(CFG)" != ""
185 ! MESSAGE MSVC c-ares makefile
187 ! MESSAGE Usage: nmake /f makefile.msvc CFG=<config> <target>
189 ! MESSAGE <config> must be one of: [ lib-release | lib-debug | dll-release | dll-debug }
190 ! MESSAGE <target> must be one of: [ ALL | c-ares | acountry | adig | ahost | clean }
192 ! MESSAGE If a <target> other than ALL or clean is given, <config> becomes mandatory.
194 ! MESSAGE If neither <config> nor <target> are specified this results in
195 ! MESSAGE all targets being built for all <config> c-ares library types.
197 ! ERROR Choose a valid configuration.
200 # --------------------------------------------------------
201 # Project subdirs independent of configuration being used
202 # --------------------------------------------------------
204 CARES_DIR = $(BASE_DIR)\cares
205 PROG1_DIR = $(BASE_DIR)\acountry
206 PROG2_DIR = $(BASE_DIR)\adig
207 PROG3_DIR = $(BASE_DIR)\ahost
209 # ---------------------------------------------------
210 # Subdirs which are configuration dependent are only
211 # defined when a valid configuration has been given.
212 # ---------------------------------------------------
214 !IF "$(VALID_CFGSET)" == "TRUE"
215 CARES_OUTDIR = $(CARES_DIR)\$(CFG)
216 PROG1_OUTDIR = $(PROG1_DIR)\$(CFG)
217 PROG2_OUTDIR = $(PROG2_DIR)\$(CFG)
218 PROG3_OUTDIR = $(PROG3_DIR)\$(CFG)
219 CARES_OBJDIR = $(CARES_OUTDIR)\obj
220 PROG1_OBJDIR = $(PROG1_OUTDIR)\obj
221 PROG2_OBJDIR = $(PROG2_OUTDIR)\obj
222 PROG3_OBJDIR = $(PROG3_OUTDIR)\obj
234 # -------------------------------------
235 # Settings that depend on tcp/ip stack
236 # -------------------------------------
238 !IF "$(USE_WATT32)" == "1"
239 CFLAGS = /UWIN32 /DWATT32 /I$(WATT_ROOT)\inc
240 EX_LIBS_REL = $(WATT_ROOT)\lib\wattcpvc_imp.lib
241 EX_LIBS_DBG = $(WATT_ROOT)\lib\wattcpvc_imp_d.lib
244 EX_LIBS_REL = ws2_32.lib advapi32.lib kernel32.lib
245 EX_LIBS_DBG = ws2_32.lib advapi32.lib kernel32.lib
248 # -----------------------------------------
249 # Switches that depend on compiler version
250 # -----------------------------------------
252 !IF $(CC_VERS_NUM) == 60
254 PDBTYPE_CONSOLIDATE = /pdbtype:consolidate
257 !UNDEF PDBTYPE_CONSOLIDATE
260 !IF $(CC_VERS_NUM) <= 70
261 RT_ERROR_CHECKING = /GZ
263 RT_ERROR_CHECKING = /RTCsu
266 # ----------------------------
267 # Assorted commands and flags
268 # ----------------------------
270 CC_CMD_REL = cl.exe /nologo $(RTLIB) /DNDEBUG /O2
271 CC_CMD_DBG = cl.exe /nologo $(RTLIBD) /D_DEBUG /Od /Zi $(RT_ERROR_CHECKING)
272 CC_CFLAGS = $(CFLAGS) /I. /W3 /EHsc /FD
274 RC_CMD_REL = rc.exe /l 0x409 /d "NDEBUG"
275 RC_CMD_DBG = rc.exe /l 0x409 /d "_DEBUG"
277 LINK_CMD_LIB = link.exe /lib /nologo
278 LINK_CMD_DLL = link.exe /dll /nologo /incremental:no /fixed:no
279 LINK_CMD_EXE = link.exe /nologo /incremental:no /fixed:no /subsystem:console
281 LINK_CMD_EXE_REL = $(LINK_CMD_EXE) /release $(PDB_NONE)
282 LINK_CMD_EXE_DBG = $(LINK_CMD_EXE) /debug $(PDBTYPE_CONSOLIDATE)
284 # ---------------------------------
285 # Configuration dependent settings
286 # ---------------------------------
288 !IF "$(CFG)" == "lib-release"
289 CARES_TARGET = $(STA_LIB_REL).lib
290 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB
292 SPROG_CFLAGS = /DCARES_STATICLIB
293 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(STA_LIB_REL).lib
294 CARES_LINK = $(LINK_CMD_LIB)
295 SPROG_LINK = $(LINK_CMD_EXE_REL)
296 CC_CMD = $(CC_CMD_REL)
299 !IF "$(CFG)" == "lib-debug"
300 CARES_TARGET = $(STA_LIB_DBG).lib
301 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB /DDEBUGBUILD
303 SPROG_CFLAGS = /DCARES_STATICLIB
304 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(STA_LIB_DBG).lib
305 CARES_LINK = $(LINK_CMD_LIB)
306 SPROG_LINK = $(LINK_CMD_EXE_DBG)
307 CC_CMD = $(CC_CMD_DBG)
310 !IF "$(CFG)" == "dll-release"
311 CARES_TARGET = $(DYN_LIB_REL).dll
312 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY
313 CARES_LFLAGS = /release $(EX_LIBS_REL) /implib:$(CARES_OUTDIR)\$(IMP_LIB_REL).lib $(PDB_NONE)
315 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(IMP_LIB_REL).lib
316 CARES_LINK = $(LINK_CMD_DLL)
317 SPROG_LINK = $(LINK_CMD_EXE_REL)
318 CC_CMD = $(CC_CMD_REL)
320 RC_CMD = $(RC_CMD_REL)
323 !IF "$(CFG)" == "dll-debug"
324 CARES_TARGET = $(DYN_LIB_DBG).dll
325 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DDEBUGBUILD
326 CARES_LFLAGS = /debug $(EX_LIBS_DBG) /implib:$(CARES_OUTDIR)\$(IMP_LIB_DBG).lib /pdb:$(CARES_OUTDIR)\$(DYN_LIB_DBG).pdb $(PDBTYPE_CONSOLIDATE)
328 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(IMP_LIB_DBG).lib
329 CARES_LINK = $(LINK_CMD_DLL)
330 SPROG_LINK = $(LINK_CMD_EXE_DBG)
331 CC_CMD = $(CC_CMD_DBG)
333 RC_CMD = $(RC_CMD_DBG)
336 # --------------------------------------------
337 # Makefile.inc provides lists of source files
338 # --------------------------------------------
340 !INCLUDE .\Makefile.inc
342 # ----------------------------
343 # Build lists of object files
344 # ----------------------------
346 !IF "$(VALID_CFGSET)" == "TRUE"
348 !IF [ECHO CARES_OBJS=^$(CARES_OBJDIR)\$(CSOURCES: = $(CARES_OBJDIR^)\) > .\cares_objs.inc] == 0
349 !INCLUDE .\cares_objs.inc
350 !IF [DEL .\cares_objs.inc]
353 !ERROR Problem generating CARES_OBJS list.
355 CARES_OBJS = $(CARES_OBJS:.c=.obj)
356 !IF "$(USE_RES_FILE)" == "TRUE"
357 CARES_OBJS = $(CARES_OBJS) $(CARES_OBJDIR)\cares.res
360 !IF [ECHO PROG1_OBJS=^$(PROG1_OBJDIR)\$(SAMPLESOURCES: = $(PROG1_OBJDIR^)\) > .\prog1_objs.inc] == 0
361 !INCLUDE .\prog1_objs.inc
362 !IF [DEL .\prog1_objs.inc]
365 !ERROR Problem generating PROG1_OBJS list.
367 PROG1_OBJS = $(PROG1_OBJS:.c=.obj)
368 PROG1_OBJS = $(PROG1_OBJS) $(PROG1_OBJDIR)\acountry.obj
370 !IF [ECHO PROG2_OBJS=^$(PROG2_OBJDIR)\$(SAMPLESOURCES: = $(PROG2_OBJDIR^)\) > .\prog2_objs.inc] == 0
371 !INCLUDE .\prog2_objs.inc
372 !IF [DEL .\prog2_objs.inc]
375 !ERROR Problem generating PROG2_OBJS list.
377 PROG2_OBJS = $(PROG2_OBJS:.c=.obj)
378 PROG2_OBJS = $(PROG2_OBJS) $(PROG2_OBJDIR)\adig.obj
380 !IF [ECHO PROG3_OBJS=^$(PROG3_OBJDIR)\$(SAMPLESOURCES: = $(PROG3_OBJDIR^)\) > .\prog3_objs.inc] == 0
381 !INCLUDE .\prog3_objs.inc
382 !IF [DEL .\prog3_objs.inc]
385 !ERROR Problem generating PROG3_OBJS list.
387 PROG3_OBJS = $(PROG3_OBJS:.c=.obj)
388 PROG3_OBJS = $(PROG3_OBJS) $(PROG3_OBJDIR)\ahost.obj
392 # --------------------------------
393 # Only our custom inference rules
394 # --------------------------------
399 {$(SRCDIR)}.rc{$(CARES_OBJDIR)}.res:
402 {$(SRCDIR)}.c{$(CARES_OBJDIR)}.obj:
403 $(CC_CMD) $(CC_CFLAGS) $(CARES_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
405 {$(SRCDIR)}.c{$(PROG1_OBJDIR)}.obj:
406 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
408 {$(SRCDIR)}.c{$(PROG2_OBJDIR)}.obj:
409 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
411 {$(SRCDIR)}.c{$(PROG3_OBJDIR)}.obj:
412 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
414 # ------------------------------------------------------------- #
415 # ------------------------------------------------------------- #
416 # Default target when no CFG library type has been specified, #
417 # results in building target ALL for all c-ares library types. #
418 # ------------------------------------------------------------- #
419 # ------------------------------------------------------------- #
421 !IF "$(VALID_CFGSET)" == "FALSE"
424 $(MAKE) /f .\Makefile.msvc CFG=lib-release ALL
425 $(MAKE) /f .\Makefile.msvc CFG=lib-debug ALL
426 $(MAKE) /f .\Makefile.msvc CFG=dll-release ALL
427 $(MAKE) /f .\Makefile.msvc CFG=dll-debug ALL
430 @-RMDIR /S /Q $(BASE_DIR) >NUL 2>&1
433 @$(MAKE) /nologo /f .\Makefile.msvc CFG=lib-release install
434 @$(MAKE) /nologo /f .\Makefile.msvc CFG=lib-debug install
435 @$(MAKE) /nologo /f .\Makefile.msvc CFG=dll-release install
436 @$(MAKE) /nologo /f .\Makefile.msvc CFG=dll-debug install
440 # ---------------------------------------------------------------------
441 # Targets only available when a proper CFG library type has been given
442 # ---------------------------------------------------------------------
444 !IF "$(VALID_CFGSET)" == "TRUE"
446 ALL: c-ares acountry adig ahost
449 c-ares: $(HHEADERS) $(CSOURCES) $(CARES_OBJDIR) $(CARES_OBJS) $(CARES_OUTDIR)
450 $(CARES_LINK) $(CARES_LFLAGS) /out:$(CARES_OUTDIR)\$(CARES_TARGET) $(CARES_OBJS)
451 ! IF "$(USE_RES_FILE)" == "TRUE"
452 @if exist $(CARES_OUTDIR)\$(CARES_TARGET).manifest mt -nologo -manifest $(CARES_OUTDIR)\$(CARES_TARGET).manifest -outputresource:$(CARES_OUTDIR)\$(CARES_TARGET);2
455 acountry: c-ares acountry.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG1_OBJDIR) $(PROG1_OBJS) $(PROG1_OUTDIR)
456 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG1_OUTDIR)\acountry.exe $(PROG1_OBJS)
457 @if exist $(PROG1_OUTDIR)\acountry.exe.manifest mt -nologo -manifest $(PROG1_OUTDIR)\acountry.exe.manifest -outputresource:$(PROG1_OUTDIR)\acountry.exe;1
459 adig: c-ares adig.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG2_OBJDIR) $(PROG2_OBJS) $(PROG2_OUTDIR)
460 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG2_OUTDIR)\adig.exe $(PROG2_OBJS)
461 @if exist $(PROG2_OUTDIR)\adig.exe.manifest mt -nologo -manifest $(PROG2_OUTDIR)\adig.exe.manifest -outputresource:$(PROG2_OUTDIR)\adig.exe;1
463 ahost: c-ares ahost.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG3_OBJDIR) $(PROG3_OBJS) $(PROG3_OUTDIR)
464 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG3_OUTDIR)\ahost.exe $(PROG3_OBJS)
465 @if exist $(PROG3_OUTDIR)\ahost.exe.manifest mt -nologo -manifest $(PROG3_OUTDIR)\ahost.exe.manifest -outputresource:$(PROG3_OUTDIR)\ahost.exe;1
467 $(CARES_OUTDIR): $(CARES_DIR)
468 @if not exist $(CARES_OUTDIR) mkdir $(CARES_OUTDIR)
470 $(PROG1_OUTDIR): $(PROG1_DIR)
471 @if not exist $(PROG1_OUTDIR) mkdir $(PROG1_OUTDIR)
473 $(PROG2_OUTDIR): $(PROG2_DIR)
474 @if not exist $(PROG2_OUTDIR) mkdir $(PROG2_OUTDIR)
476 $(PROG3_OUTDIR): $(PROG3_DIR)
477 @if not exist $(PROG3_OUTDIR) mkdir $(PROG3_OUTDIR)
479 $(CARES_OBJDIR): $(CARES_OUTDIR)
480 @if not exist $(CARES_OBJDIR) mkdir $(CARES_OBJDIR)
482 $(PROG1_OBJDIR): $(PROG1_OUTDIR)
483 @if not exist $(PROG1_OBJDIR) mkdir $(PROG1_OBJDIR)
485 $(PROG2_OBJDIR): $(PROG2_OUTDIR)
486 @if not exist $(PROG2_OBJDIR) mkdir $(PROG2_OBJDIR)
488 $(PROG3_OBJDIR): $(PROG3_OUTDIR)
489 @if not exist $(PROG3_OBJDIR) mkdir $(PROG3_OBJDIR)
492 @-RMDIR /S /Q $(CARES_OUTDIR) >NUL 2>&1
493 @-RMDIR /S /Q $(PROG1_OUTDIR) >NUL 2>&1
494 @-RMDIR /S /Q $(PROG2_OUTDIR) >NUL 2>&1
495 @-RMDIR /S /Q $(PROG3_OUTDIR) >NUL 2>&1
498 @if not exist $(CARES_OUTDIR)\$(CARES_TARGET) \
499 $(MAKE) /f .\Makefile.msvc CFG=$(CFG) c-ares
500 @if not exist "$(INSTALL_DIR)" mkdir "$(INSTALL_DIR)"
501 @if not exist "$(INSTALL_DIR_LIB)" mkdir "$(INSTALL_DIR_LIB)"
502 @if not exist "$(INSTALL_DIR_INC)" mkdir "$(INSTALL_DIR_INC)"
503 @copy /y $(CARES_OUTDIR)\*.* "$(INSTALL_DIR_LIB)" >NUL
504 @copy /y $(SRCDIR)\ares.h "$(INSTALL_DIR_INC)" >NUL
505 @copy /y $(SRCDIR)\ares_build.h "$(INSTALL_DIR_INC)" >NUL
506 @copy /y $(SRCDIR)\ares_rules.h "$(INSTALL_DIR_INC)" >NUL
507 @copy /y $(SRCDIR)\ares_version.h "$(INSTALL_DIR_INC)" >NUL
508 @echo Installed c-ares $(CFG)
513 @if not exist $(BASE_DIR) mkdir $(BASE_DIR)
515 $(CARES_DIR): $(BASE_DIR)
516 @if not exist $(CARES_DIR) mkdir $(CARES_DIR)
518 $(PROG1_DIR): $(BASE_DIR)
519 @if not exist $(PROG1_DIR) mkdir $(PROG1_DIR)
521 $(PROG2_DIR): $(BASE_DIR)
522 @if not exist $(PROG2_DIR) mkdir $(PROG2_DIR)
524 $(PROG3_DIR): $(BASE_DIR)
525 @if not exist $(PROG3_DIR) mkdir $(PROG3_DIR)
527 # End of Makefile.msvc