2 # Copyright (C) 2009-2010 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"
119 ! MESSAGE Unknown value for _NMAKE_VER macro: "$(_NMAKE_VER)"
120 ! MESSAGE Please, report this condition on the c-ares development
121 ! MESSAGE mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
122 ! ERROR See previous message.
125 CC_VERS_STR = msvc$(CC_VERS_NUM)
127 # ----------------------------------------------------
128 # Verify that current subdir is the c-ares source one
129 # ----------------------------------------------------
131 !IF ! EXIST(.\ares_init.c)
132 ! MESSAGE Can not process Makefile.msvc from outside of c-ares source subdirectory.
133 ! MESSAGE Change to the subdirectory where Makefile.msvc is found, and try again.
134 ! ERROR See previous message.
137 # ------------------------------------------------------------------
138 # Base subdir is the common root from which other subdirs will hang,
139 # the name depends on MSVC version being used when building c-ares.
140 # ------------------------------------------------------------------
142 BASE_DIR = .\$(CC_VERS_STR)
144 # ----------------------------------------
145 # Subdir holding sources for all projects
146 # ----------------------------------------
150 # -----------------------------
151 # Default installation subdirs
152 # -----------------------------
158 !IFNDEF INSTALL_DIR_LIB
159 INSTALL_DIR_LIB = $(INSTALL_DIR)\lib
162 !IFNDEF INSTALL_DIR_INC
163 INSTALL_DIR_INC = $(INSTALL_DIR)\include
166 # -------------------------
167 # Configuration validation
168 # -------------------------
171 !IF "$(CFG)" == "lib-release" || "$(CFG)" == "lib-debug" || \
172 "$(CFG)" == "dll-release" || "$(CFG)" == "dll-debug"
176 !IF "$(VALID_CFGSET)" == "FALSE" && "$(CFG)" != ""
177 ! MESSAGE MSVC c-ares makefile
179 ! MESSAGE Usage: nmake /f makefile.msvc CFG=<config> <target>
181 ! MESSAGE <config> must be one of: [ lib-release | lib-debug | dll-release | dll-debug }
182 ! MESSAGE <target> must be one of: [ ALL | c-ares | acountry | adig | ahost | clean }
184 ! MESSAGE If a <target> other than ALL or clean is given, <config> becomes mandatory.
186 ! MESSAGE If neither <config> nor <target> are specified this results in
187 ! MESSAGE all targets being built for all <config> c-ares library types.
189 ! ERROR Choose a valid configuration.
192 # --------------------------------------------------------
193 # Project subdirs independent of configuration being used
194 # --------------------------------------------------------
196 CARES_DIR = $(BASE_DIR)\cares
197 PROG1_DIR = $(BASE_DIR)\acountry
198 PROG2_DIR = $(BASE_DIR)\adig
199 PROG3_DIR = $(BASE_DIR)\ahost
201 # ---------------------------------------------------
202 # Subdirs which are configuration dependent are only
203 # defined when a valid configuration has been given.
204 # ---------------------------------------------------
206 !IF "$(VALID_CFGSET)" == "TRUE"
207 CARES_OUTDIR = $(CARES_DIR)\$(CFG)
208 PROG1_OUTDIR = $(PROG1_DIR)\$(CFG)
209 PROG2_OUTDIR = $(PROG2_DIR)\$(CFG)
210 PROG3_OUTDIR = $(PROG3_DIR)\$(CFG)
211 CARES_OBJDIR = $(CARES_OUTDIR)\obj
212 PROG1_OBJDIR = $(PROG1_OUTDIR)\obj
213 PROG2_OBJDIR = $(PROG2_OUTDIR)\obj
214 PROG3_OBJDIR = $(PROG3_OUTDIR)\obj
226 # -------------------------------------
227 # Settings that depend on tcp/ip stack
228 # -------------------------------------
230 !IF "$(USE_WATT32)" == "1"
231 CFLAGS = /UWIN32 /DWATT32 /I$(WATT_ROOT)\inc
232 EX_LIBS_REL = $(WATT_ROOT)\lib\wattcpvc_imp.lib
233 EX_LIBS_DBG = $(WATT_ROOT)\lib\wattcpvc_imp_d.lib
236 EX_LIBS_REL = ws2_32.lib advapi32.lib kernel32.lib
237 EX_LIBS_DBG = ws2_32.lib advapi32.lib kernel32.lib
240 # -----------------------------------------
241 # Switches that depend on compiler version
242 # -----------------------------------------
244 !IF $(CC_VERS_NUM) == 60
246 PDBTYPE_CONSOLIDATE = /pdbtype:consolidate
249 !UNDEF PDBTYPE_CONSOLIDATE
252 !IF $(CC_VERS_NUM) <= 70
253 RT_ERROR_CHECKING = /GZ
255 RT_ERROR_CHECKING = /RTCsu
258 # ----------------------------
259 # Assorted commands and flags
260 # ----------------------------
262 CC_CMD_REL = cl.exe /nologo $(RTLIB) /DNDEBUG /O2
263 CC_CMD_DBG = cl.exe /nologo $(RTLIBD) /D_DEBUG /Od /Zi $(RT_ERROR_CHECKING)
264 CC_CFLAGS = $(CFLAGS) /I. /W3 /EHsc /FD
266 RC_CMD_REL = rc.exe /l 0x409 /d "NDEBUG"
267 RC_CMD_DBG = rc.exe /l 0x409 /d "_DEBUG"
269 LINK_CMD_LIB = link.exe /lib /nologo
270 LINK_CMD_DLL = link.exe /dll /nologo /incremental:no /fixed:no
271 LINK_CMD_EXE = link.exe /nologo /incremental:no /fixed:no /subsystem:console
273 LINK_CMD_EXE_REL = $(LINK_CMD_EXE) /release $(PDB_NONE)
274 LINK_CMD_EXE_DBG = $(LINK_CMD_EXE) /debug $(PDBTYPE_CONSOLIDATE)
276 # ---------------------------------
277 # Configuration dependent settings
278 # ---------------------------------
280 !IF "$(CFG)" == "lib-release"
281 CARES_TARGET = $(STA_LIB_REL).lib
282 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB
284 SPROG_CFLAGS = /DCARES_STATICLIB
285 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(STA_LIB_REL).lib
286 CARES_LINK = $(LINK_CMD_LIB)
287 SPROG_LINK = $(LINK_CMD_EXE_REL)
288 CC_CMD = $(CC_CMD_REL)
291 !IF "$(CFG)" == "lib-debug"
292 CARES_TARGET = $(STA_LIB_DBG).lib
293 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB /DDEBUGBUILD
295 SPROG_CFLAGS = /DCARES_STATICLIB
296 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(STA_LIB_DBG).lib
297 CARES_LINK = $(LINK_CMD_LIB)
298 SPROG_LINK = $(LINK_CMD_EXE_DBG)
299 CC_CMD = $(CC_CMD_DBG)
302 !IF "$(CFG)" == "dll-release"
303 CARES_TARGET = $(DYN_LIB_REL).dll
304 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY
305 CARES_LFLAGS = /release $(EX_LIBS_REL) /implib:$(CARES_OUTDIR)\$(IMP_LIB_REL).lib $(PDB_NONE)
307 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(IMP_LIB_REL).lib
308 CARES_LINK = $(LINK_CMD_DLL)
309 SPROG_LINK = $(LINK_CMD_EXE_REL)
310 CC_CMD = $(CC_CMD_REL)
312 RC_CMD = $(RC_CMD_REL)
315 !IF "$(CFG)" == "dll-debug"
316 CARES_TARGET = $(DYN_LIB_DBG).dll
317 CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DDEBUGBUILD
318 CARES_LFLAGS = /debug $(EX_LIBS_DBG) /implib:$(CARES_OUTDIR)\$(IMP_LIB_DBG).lib /pdb:$(CARES_OUTDIR)\$(DYN_LIB_DBG).pdb $(PDBTYPE_CONSOLIDATE)
320 SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(IMP_LIB_DBG).lib
321 CARES_LINK = $(LINK_CMD_DLL)
322 SPROG_LINK = $(LINK_CMD_EXE_DBG)
323 CC_CMD = $(CC_CMD_DBG)
325 RC_CMD = $(RC_CMD_DBG)
328 # --------------------------------------------
329 # Makefile.inc provides lists of source files
330 # --------------------------------------------
332 !INCLUDE .\Makefile.inc
334 # ----------------------------
335 # Build lists of object files
336 # ----------------------------
338 !IF "$(VALID_CFGSET)" == "TRUE"
340 !IF [ECHO CARES_OBJS=^$(CARES_OBJDIR)\$(CSOURCES: = $(CARES_OBJDIR^)\) > .\cares_objs.inc] == 0
341 !INCLUDE .\cares_objs.inc
342 !IF [DEL .\cares_objs.inc]
345 !ERROR Problem generating CARES_OBJS list.
347 CARES_OBJS = $(CARES_OBJS:.c=.obj)
348 !IF "$(USE_RES_FILE)" == "TRUE"
349 CARES_OBJS = $(CARES_OBJS) $(CARES_OBJDIR)\cares.res
352 !IF [ECHO PROG1_OBJS=^$(PROG1_OBJDIR)\$(SAMPLESOURCES: = $(PROG1_OBJDIR^)\) > .\prog1_objs.inc] == 0
353 !INCLUDE .\prog1_objs.inc
354 !IF [DEL .\prog1_objs.inc]
357 !ERROR Problem generating PROG1_OBJS list.
359 PROG1_OBJS = $(PROG1_OBJS:.c=.obj)
360 PROG1_OBJS = $(PROG1_OBJS) $(PROG1_OBJDIR)\acountry.obj
362 !IF [ECHO PROG2_OBJS=^$(PROG2_OBJDIR)\$(SAMPLESOURCES: = $(PROG2_OBJDIR^)\) > .\prog2_objs.inc] == 0
363 !INCLUDE .\prog2_objs.inc
364 !IF [DEL .\prog2_objs.inc]
367 !ERROR Problem generating PROG2_OBJS list.
369 PROG2_OBJS = $(PROG2_OBJS:.c=.obj)
370 PROG2_OBJS = $(PROG2_OBJS) $(PROG2_OBJDIR)\adig.obj
372 !IF [ECHO PROG3_OBJS=^$(PROG3_OBJDIR)\$(SAMPLESOURCES: = $(PROG3_OBJDIR^)\) > .\prog3_objs.inc] == 0
373 !INCLUDE .\prog3_objs.inc
374 !IF [DEL .\prog3_objs.inc]
377 !ERROR Problem generating PROG3_OBJS list.
379 PROG3_OBJS = $(PROG3_OBJS:.c=.obj)
380 PROG3_OBJS = $(PROG3_OBJS) $(PROG3_OBJDIR)\ahost.obj
384 # --------------------------------
385 # Only our custom inference rules
386 # --------------------------------
391 {$(SRCDIR)}.rc{$(CARES_OBJDIR)}.res:
394 {$(SRCDIR)}.c{$(CARES_OBJDIR)}.obj:
395 $(CC_CMD) $(CC_CFLAGS) $(CARES_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
397 {$(SRCDIR)}.c{$(PROG1_OBJDIR)}.obj:
398 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
400 {$(SRCDIR)}.c{$(PROG2_OBJDIR)}.obj:
401 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
403 {$(SRCDIR)}.c{$(PROG3_OBJDIR)}.obj:
404 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
406 # ------------------------------------------------------------- #
407 # ------------------------------------------------------------- #
408 # Default target when no CFG library type has been specified, #
409 # results in building target ALL for all c-ares library types. #
410 # ------------------------------------------------------------- #
411 # ------------------------------------------------------------- #
413 !IF "$(VALID_CFGSET)" == "FALSE"
416 $(MAKE) /f .\Makefile.msvc CFG=lib-release ALL
417 $(MAKE) /f .\Makefile.msvc CFG=lib-debug ALL
418 $(MAKE) /f .\Makefile.msvc CFG=dll-release ALL
419 $(MAKE) /f .\Makefile.msvc CFG=dll-debug ALL
422 @-RMDIR /S /Q $(BASE_DIR) >NUL 2>&1
425 @$(MAKE) /nologo /f .\Makefile.msvc CFG=lib-release install
426 @$(MAKE) /nologo /f .\Makefile.msvc CFG=lib-debug install
427 @$(MAKE) /nologo /f .\Makefile.msvc CFG=dll-release install
428 @$(MAKE) /nologo /f .\Makefile.msvc CFG=dll-debug install
432 # ---------------------------------------------------------------------
433 # Targets only available when a proper CFG library type has been given
434 # ---------------------------------------------------------------------
436 !IF "$(VALID_CFGSET)" == "TRUE"
438 ALL: c-ares acountry adig ahost
441 c-ares: $(HHEADERS) $(CSOURCES) $(CARES_OBJDIR) $(CARES_OBJS) $(CARES_OUTDIR)
442 $(CARES_LINK) $(CARES_LFLAGS) /out:$(CARES_OUTDIR)\$(CARES_TARGET) $(CARES_OBJS)
443 ! IF "$(USE_RES_FILE)" == "TRUE"
444 @if exist $(CARES_OUTDIR)\$(CARES_TARGET).manifest mt -nologo -manifest $(CARES_OUTDIR)\$(CARES_TARGET).manifest -outputresource:$(CARES_OUTDIR)\$(CARES_TARGET);2
447 acountry: c-ares acountry.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG1_OBJDIR) $(PROG1_OBJS) $(PROG1_OUTDIR)
448 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG1_OUTDIR)\acountry.exe $(PROG1_OBJS)
449 @if exist $(PROG1_OUTDIR)\acountry.exe.manifest mt -nologo -manifest $(PROG1_OUTDIR)\acountry.exe.manifest -outputresource:$(PROG1_OUTDIR)\acountry.exe;1
451 adig: c-ares adig.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG2_OBJDIR) $(PROG2_OBJS) $(PROG2_OUTDIR)
452 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG2_OUTDIR)\adig.exe $(PROG2_OBJS)
453 @if exist $(PROG2_OUTDIR)\adig.exe.manifest mt -nologo -manifest $(PROG2_OUTDIR)\adig.exe.manifest -outputresource:$(PROG2_OUTDIR)\adig.exe;1
455 ahost: c-ares ahost.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG3_OBJDIR) $(PROG3_OBJS) $(PROG3_OUTDIR)
456 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG3_OUTDIR)\ahost.exe $(PROG3_OBJS)
457 @if exist $(PROG3_OUTDIR)\ahost.exe.manifest mt -nologo -manifest $(PROG3_OUTDIR)\ahost.exe.manifest -outputresource:$(PROG3_OUTDIR)\ahost.exe;1
459 $(CARES_OUTDIR): $(CARES_DIR)
460 @if not exist $(CARES_OUTDIR) mkdir $(CARES_OUTDIR)
462 $(PROG1_OUTDIR): $(PROG1_DIR)
463 @if not exist $(PROG1_OUTDIR) mkdir $(PROG1_OUTDIR)
465 $(PROG2_OUTDIR): $(PROG2_DIR)
466 @if not exist $(PROG2_OUTDIR) mkdir $(PROG2_OUTDIR)
468 $(PROG3_OUTDIR): $(PROG3_DIR)
469 @if not exist $(PROG3_OUTDIR) mkdir $(PROG3_OUTDIR)
471 $(CARES_OBJDIR): $(CARES_OUTDIR)
472 @if not exist $(CARES_OBJDIR) mkdir $(CARES_OBJDIR)
474 $(PROG1_OBJDIR): $(PROG1_OUTDIR)
475 @if not exist $(PROG1_OBJDIR) mkdir $(PROG1_OBJDIR)
477 $(PROG2_OBJDIR): $(PROG2_OUTDIR)
478 @if not exist $(PROG2_OBJDIR) mkdir $(PROG2_OBJDIR)
480 $(PROG3_OBJDIR): $(PROG3_OUTDIR)
481 @if not exist $(PROG3_OBJDIR) mkdir $(PROG3_OBJDIR)
484 @-RMDIR /S /Q $(CARES_OUTDIR) >NUL 2>&1
485 @-RMDIR /S /Q $(PROG1_OUTDIR) >NUL 2>&1
486 @-RMDIR /S /Q $(PROG2_OUTDIR) >NUL 2>&1
487 @-RMDIR /S /Q $(PROG3_OUTDIR) >NUL 2>&1
490 @if not exist $(CARES_OUTDIR)\$(CARES_TARGET) \
491 $(MAKE) /f .\Makefile.msvc CFG=$(CFG) c-ares
492 @if not exist "$(INSTALL_DIR)" mkdir "$(INSTALL_DIR)"
493 @if not exist "$(INSTALL_DIR_LIB)" mkdir "$(INSTALL_DIR_LIB)"
494 @if not exist "$(INSTALL_DIR_INC)" mkdir "$(INSTALL_DIR_INC)"
495 @copy /y $(CARES_OUTDIR)\*.* "$(INSTALL_DIR_LIB)" >NUL
496 @copy /y $(SRCDIR)\ares.h "$(INSTALL_DIR_INC)" >NUL
497 @copy /y $(SRCDIR)\ares_build.h "$(INSTALL_DIR_INC)" >NUL
498 @copy /y $(SRCDIR)\ares_rules.h "$(INSTALL_DIR_INC)" >NUL
499 @copy /y $(SRCDIR)\ares_version.h "$(INSTALL_DIR_INC)" >NUL
500 @echo Installed c-ares $(CFG)
505 @if not exist $(BASE_DIR) mkdir $(BASE_DIR)
507 $(CARES_DIR): $(BASE_DIR)
508 @if not exist $(CARES_DIR) mkdir $(CARES_DIR)
510 $(PROG1_DIR): $(BASE_DIR)
511 @if not exist $(PROG1_DIR) mkdir $(PROG1_DIR)
513 $(PROG2_DIR): $(BASE_DIR)
514 @if not exist $(PROG2_DIR) mkdir $(PROG2_DIR)
516 $(PROG3_DIR): $(BASE_DIR)
517 @if not exist $(PROG3_DIR) mkdir $(PROG3_DIR)
519 # End of Makefile.msvc