blob: e05e317fe5d947051423846f634ee9bd5d09f6a9 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001
2# Copyright (C) 2009-2013 by Daniel Stenberg
3#
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.
15
16# ------------------------------------------------------------------------------
17#
18# Makefile for building c-ares libraries and sample programs with MSVC.
19#
20# Usage: nmake /f makefile.msvc CFG=<config> <target>
21#
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 }
24#
25# If a <target> other than ALL or clean is given, <config> becomes mandatory.
26#
27# If neither <config> nor <target> are specified this results in
28# all targets being built for all <config> c-ares library types.
29#
30# This makefile must be processed from the subdir where it is located.
31#
32# All results are generated below a subdirectory named msvcXXX.
33#
34# ------------------------------------------------------------------------------
35
36NAME = cares
37
38# ------------------------------------------------
39# c-ares static and dynamic libraries common base
40# file names for release and debug configurations
41# ------------------------------------------------
42
43STA_LIB_REL = lib$(NAME)
44DYN_LIB_REL = $(NAME)
45STA_LIB_DBG = $(STA_LIB_REL)d
46DYN_LIB_DBG = $(DYN_LIB_REL)d
47
48# -------------------------------------------
49# Base names for c-ares DLL import libraries
50# -------------------------------------------
51
52IMP_LIB_REL = $(DYN_LIB_REL)
53IMP_LIB_DBG = $(DYN_LIB_DBG)
54
55# --------------------------
56# Runtime library selection
57# --------------------------
58
59RTLIB = /MD
60RTLIBD = /MDd
61
62!IF "$(RTLIBCFG)" == "static"
63RTLIB = /MT
64RTLIBD = /MTd
65!ENDIF
66
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# --------------------------------------------------------
71
72USE_WATT32 = 0
73
74# --------------------------------------------------------
75# Detect compiler version.
76# --------------------------------------------------------
77!INCLUDE .\msvc_ver.inc
78
79# ----------------------------------------------------
80# Verify that current subdir is the c-ares source one
81# ----------------------------------------------------
82
83!IF ! EXIST(.\ares_init.c)
84! MESSAGE Can not process Makefile.msvc from outside of c-ares source subdirectory.
85! MESSAGE Change to the subdirectory where Makefile.msvc is found, and try again.
86! ERROR See previous message.
87!ENDIF
88
89# ------------------------------------------------------------------
90# Base subdir is the common root from which other subdirs will hang,
91# the name depends on MSVC version being used when building c-ares.
92# ------------------------------------------------------------------
93
94BASE_DIR = .\$(CC_VERS_STR)
95
96# ----------------------------------------
97# Subdir holding sources for all projects
98# ----------------------------------------
99
100SRCDIR = .
101
102# -----------------------------
103# Default installation subdirs
104# -----------------------------
105
106!IFNDEF INSTALL_DIR
107INSTALL_DIR = .
108!ENDIF
109
110!IFNDEF INSTALL_DIR_LIB
111INSTALL_DIR_LIB = $(INSTALL_DIR)\lib
112!ENDIF
113
114!IFNDEF INSTALL_DIR_INC
115INSTALL_DIR_INC = $(INSTALL_DIR)\include
116!ENDIF
117
118# -------------------------
119# Configuration validation
120# -------------------------
121
122VALID_CFGSET = FALSE
123!IF "$(CFG)" == "lib-release" || "$(CFG)" == "lib-debug" || \
124 "$(CFG)" == "dll-release" || "$(CFG)" == "dll-debug"
125VALID_CFGSET = TRUE
126!ENDIF
127
128!IF "$(VALID_CFGSET)" == "FALSE" && "$(CFG)" != ""
129! MESSAGE MSVC c-ares makefile
130! MESSAGE
131! MESSAGE Usage: nmake /f makefile.msvc CFG=<config> <target>
132! MESSAGE
133! MESSAGE <config> must be one of: [ lib-release | lib-debug | dll-release | dll-debug }
134! MESSAGE <target> must be one of: [ ALL | c-ares | acountry | adig | ahost | clean }
135! MESSAGE
136! MESSAGE If a <target> other than ALL or clean is given, <config> becomes mandatory.
137! MESSAGE
138! MESSAGE If neither <config> nor <target> are specified this results in
139! MESSAGE all targets being built for all <config> c-ares library types.
140! MESSAGE
141! ERROR Choose a valid configuration.
142!ENDIF
143
144# --------------------------------------------------------
145# Project subdirs independent of configuration being used
146# --------------------------------------------------------
147
148CARES_DIR = $(BASE_DIR)\cares
149PROG1_DIR = $(BASE_DIR)\acountry
150PROG2_DIR = $(BASE_DIR)\adig
151PROG3_DIR = $(BASE_DIR)\ahost
152
153# ---------------------------------------------------
154# Subdirs which are configuration dependent are only
155# defined when a valid configuration has been given.
156# ---------------------------------------------------
157
158!IF "$(VALID_CFGSET)" == "TRUE"
159CARES_OUTDIR = $(CARES_DIR)\$(CFG)
160PROG1_OUTDIR = $(PROG1_DIR)\$(CFG)
161PROG2_OUTDIR = $(PROG2_DIR)\$(CFG)
162PROG3_OUTDIR = $(PROG3_DIR)\$(CFG)
163CARES_OBJDIR = $(CARES_OUTDIR)\obj
164PROG1_OBJDIR = $(PROG1_OUTDIR)\obj
165PROG2_OBJDIR = $(PROG2_OUTDIR)\obj
166PROG3_OBJDIR = $(PROG3_OUTDIR)\obj
167!ELSE
168!UNDEF CARES_OUTDIR
169!UNDEF PROG1_OUTDIR
170!UNDEF PROG2_OUTDIR
171!UNDEF PROG3_OUTDIR
172!UNDEF CARES_OBJDIR
173!UNDEF PROG1_OBJDIR
174!UNDEF PROG2_OBJDIR
175!UNDEF PROG3_OBJDIR
176!ENDIF
177
178# -------------------------------------
179# Settings that depend on tcp/ip stack
180# -------------------------------------
181
182!IF "$(USE_WATT32)" == "1"
183CFLAGS = /UWIN32 /DWATT32 /I$(WATT_ROOT)\inc
184EX_LIBS_REL = $(WATT_ROOT)\lib\wattcpvc_imp.lib
185EX_LIBS_DBG = $(WATT_ROOT)\lib\wattcpvc_imp_d.lib
186!ELSE
187CFLAGS = /DWIN32
188EX_LIBS_REL = ws2_32.lib advapi32.lib kernel32.lib
189EX_LIBS_DBG = ws2_32.lib advapi32.lib kernel32.lib
190!ENDIF
191
192# -----------------------------------------
193# Switches that depend on compiler version
194# -----------------------------------------
195
196!IF $(CC_VERS_NUM) == 60
197PDB_NONE = /pdb:none
198PDBTYPE_CONSOLIDATE = /pdbtype:consolidate
199!ELSE
200!UNDEF PDB_NONE
201!UNDEF PDBTYPE_CONSOLIDATE
202!ENDIF
203
204!IF $(CC_VERS_NUM) <= 70
205RT_ERROR_CHECKING = /GZ
206!ELSE
207RT_ERROR_CHECKING = /RTCsu
208!ENDIF
209
210# ----------------------------
211# Assorted commands and flags
212# ----------------------------
213
214CC_CMD_REL = cl.exe /nologo $(RTLIB) /DNDEBUG /O2
215CC_CMD_DBG = cl.exe /nologo $(RTLIBD) /D_DEBUG /Od /Zi $(RT_ERROR_CHECKING)
216CC_CFLAGS = $(CFLAGS) /I. /W3 /EHsc /FD
217
218RC_CMD_REL = rc.exe /l 0x409 /d "NDEBUG"
219RC_CMD_DBG = rc.exe /l 0x409 /d "_DEBUG"
220
221LINK_CMD_LIB = link.exe /lib /nologo
222LINK_CMD_DLL = link.exe /dll /nologo /incremental:no /fixed:no
223LINK_CMD_EXE = link.exe /nologo /incremental:no /fixed:no /subsystem:console
224
225LINK_CMD_EXE_REL = $(LINK_CMD_EXE) /release $(PDB_NONE)
226LINK_CMD_EXE_DBG = $(LINK_CMD_EXE) /debug $(PDBTYPE_CONSOLIDATE)
227
228# ---------------------------------
229# Configuration dependent settings
230# ---------------------------------
231
232!IF "$(CFG)" == "lib-release"
233CARES_TARGET = $(STA_LIB_REL).lib
234CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB
235CARES_LFLAGS =
236SPROG_CFLAGS = /DCARES_STATICLIB
237SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(STA_LIB_REL).lib
238CARES_LINK = $(LINK_CMD_LIB)
239SPROG_LINK = $(LINK_CMD_EXE_REL)
240CC_CMD = $(CC_CMD_REL)
241!ENDIF
242
243!IF "$(CFG)" == "lib-debug"
244CARES_TARGET = $(STA_LIB_DBG).lib
245CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DCARES_STATICLIB /DDEBUGBUILD
246CARES_LFLAGS =
247SPROG_CFLAGS = /DCARES_STATICLIB
248SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(STA_LIB_DBG).lib
249CARES_LINK = $(LINK_CMD_LIB)
250SPROG_LINK = $(LINK_CMD_EXE_DBG)
251CC_CMD = $(CC_CMD_DBG)
252!ENDIF
253
254!IF "$(CFG)" == "dll-release"
255CARES_TARGET = $(DYN_LIB_REL).dll
256CARES_CFLAGS = /DCARES_BUILDING_LIBRARY
257CARES_LFLAGS = /release $(EX_LIBS_REL) /implib:$(CARES_OUTDIR)\$(IMP_LIB_REL).lib $(PDB_NONE)
258SPROG_CFLAGS =
259SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_REL) $(IMP_LIB_REL).lib
260CARES_LINK = $(LINK_CMD_DLL)
261SPROG_LINK = $(LINK_CMD_EXE_REL)
262CC_CMD = $(CC_CMD_REL)
263USE_RES_FILE = TRUE
264RC_CMD = $(RC_CMD_REL)
265!ENDIF
266
267!IF "$(CFG)" == "dll-debug"
268CARES_TARGET = $(DYN_LIB_DBG).dll
269CARES_CFLAGS = /DCARES_BUILDING_LIBRARY /DDEBUGBUILD
270CARES_LFLAGS = /debug $(EX_LIBS_DBG) /implib:$(CARES_OUTDIR)\$(IMP_LIB_DBG).lib /pdb:$(CARES_OUTDIR)\$(DYN_LIB_DBG).pdb $(PDBTYPE_CONSOLIDATE)
271SPROG_CFLAGS =
272SPROG_LFLAGS = /libpath:$(CARES_OUTDIR) $(EX_LIBS_DBG) $(IMP_LIB_DBG).lib
273CARES_LINK = $(LINK_CMD_DLL)
274SPROG_LINK = $(LINK_CMD_EXE_DBG)
275CC_CMD = $(CC_CMD_DBG)
276USE_RES_FILE = TRUE
277RC_CMD = $(RC_CMD_DBG)
278!ENDIF
279
280# --------------------------------------------
281# Makefile.inc provides lists of source files
282# --------------------------------------------
283
284!INCLUDE .\Makefile.inc
285
286# ----------------------------
287# Build lists of object files
288# ----------------------------
289
290!IF "$(VALID_CFGSET)" == "TRUE"
291
292!IF [ECHO CARES_OBJS=^$(CARES_OBJDIR)\$(CSOURCES: = $(CARES_OBJDIR^)\) > .\cares_objs.inc] == 0
293!INCLUDE .\cares_objs.inc
294!IF [DEL .\cares_objs.inc]
295!ENDIF
296!ELSE
297!ERROR Problem generating CARES_OBJS list.
298!ENDIF
299CARES_OBJS = $(CARES_OBJS:.c=.obj)
300!IF "$(USE_RES_FILE)" == "TRUE"
301CARES_OBJS = $(CARES_OBJS) $(CARES_OBJDIR)\cares.res
302!ENDIF
303
304!IF [ECHO PROG1_OBJS=^$(PROG1_OBJDIR)\$(SAMPLESOURCES: = $(PROG1_OBJDIR^)\) > .\prog1_objs.inc] == 0
305!INCLUDE .\prog1_objs.inc
306!IF [DEL .\prog1_objs.inc]
307!ENDIF
308!ELSE
309!ERROR Problem generating PROG1_OBJS list.
310!ENDIF
311PROG1_OBJS = $(PROG1_OBJS:.c=.obj)
312PROG1_OBJS = $(PROG1_OBJS) $(PROG1_OBJDIR)\acountry.obj
313
314!IF [ECHO PROG2_OBJS=^$(PROG2_OBJDIR)\$(SAMPLESOURCES: = $(PROG2_OBJDIR^)\) > .\prog2_objs.inc] == 0
315!INCLUDE .\prog2_objs.inc
316!IF [DEL .\prog2_objs.inc]
317!ENDIF
318!ELSE
319!ERROR Problem generating PROG2_OBJS list.
320!ENDIF
321PROG2_OBJS = $(PROG2_OBJS:.c=.obj)
322PROG2_OBJS = $(PROG2_OBJS) $(PROG2_OBJDIR)\adig.obj
323
324!IF [ECHO PROG3_OBJS=^$(PROG3_OBJDIR)\$(SAMPLESOURCES: = $(PROG3_OBJDIR^)\) > .\prog3_objs.inc] == 0
325!INCLUDE .\prog3_objs.inc
326!IF [DEL .\prog3_objs.inc]
327!ENDIF
328!ELSE
329!ERROR Problem generating PROG3_OBJS list.
330!ENDIF
331PROG3_OBJS = $(PROG3_OBJS:.c=.obj)
332PROG3_OBJS = $(PROG3_OBJS) $(PROG3_OBJDIR)\ahost.obj
333
334!ENDIF
335
336# --------------------------------
337# Only our custom inference rules
338# --------------------------------
339
340.SUFFIXES:
341.SUFFIXES: .c .rc
342
343{$(SRCDIR)}.rc{$(CARES_OBJDIR)}.res:
344 $(RC_CMD) /Fo $@ $<
345
346{$(SRCDIR)}.c{$(CARES_OBJDIR)}.obj:
347 $(CC_CMD) $(CC_CFLAGS) $(CARES_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
348
349{$(SRCDIR)}.c{$(PROG1_OBJDIR)}.obj:
350 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
351
352{$(SRCDIR)}.c{$(PROG2_OBJDIR)}.obj:
353 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
354
355{$(SRCDIR)}.c{$(PROG3_OBJDIR)}.obj:
356 $(CC_CMD) $(CC_CFLAGS) $(SPROG_CFLAGS) /Fo$@ /Fd$(@D)\ /c $<
357
358# ------------------------------------------------------------- #
359# ------------------------------------------------------------- #
360# Default target when no CFG library type has been specified, #
361# results in building target ALL for all c-ares library types. #
362# ------------------------------------------------------------- #
363# ------------------------------------------------------------- #
364
365!IF "$(VALID_CFGSET)" == "FALSE"
366
367ALL:
368 $(MAKE) /f .\Makefile.msvc CFG=lib-release ALL
369 $(MAKE) /f .\Makefile.msvc CFG=lib-debug ALL
370 $(MAKE) /f .\Makefile.msvc CFG=dll-release ALL
371 $(MAKE) /f .\Makefile.msvc CFG=dll-debug ALL
372
373clean:
374 @-RMDIR /S /Q $(BASE_DIR) >NUL 2>&1
375
376install:
377 @$(MAKE) /nologo /f .\Makefile.msvc CFG=lib-release install
378 @$(MAKE) /nologo /f .\Makefile.msvc CFG=lib-debug install
379 @$(MAKE) /nologo /f .\Makefile.msvc CFG=dll-release install
380 @$(MAKE) /nologo /f .\Makefile.msvc CFG=dll-debug install
381
382!ENDIF
383
384# ---------------------------------------------------------------------
385# Targets only available when a proper CFG library type has been given
386# ---------------------------------------------------------------------
387
388!IF "$(VALID_CFGSET)" == "TRUE"
389
390ALL: c-ares acountry adig ahost
391 @
392
393c-ares: $(HHEADERS) $(CSOURCES) $(CARES_OBJDIR) $(CARES_OBJS) $(CARES_OUTDIR)
394 $(CARES_LINK) $(CARES_LFLAGS) /out:$(CARES_OUTDIR)\$(CARES_TARGET) $(CARES_OBJS)
395! IF "$(USE_RES_FILE)" == "TRUE"
396 @if exist $(CARES_OUTDIR)\$(CARES_TARGET).manifest mt -nologo -manifest $(CARES_OUTDIR)\$(CARES_TARGET).manifest -outputresource:$(CARES_OUTDIR)\$(CARES_TARGET);2
397! ENDIF
398
399acountry: c-ares acountry.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG1_OBJDIR) $(PROG1_OBJS) $(PROG1_OUTDIR)
400 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG1_OUTDIR)\acountry.exe $(PROG1_OBJS)
401 @if exist $(PROG1_OUTDIR)\acountry.exe.manifest mt -nologo -manifest $(PROG1_OUTDIR)\acountry.exe.manifest -outputresource:$(PROG1_OUTDIR)\acountry.exe;1
402
403adig: c-ares adig.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG2_OBJDIR) $(PROG2_OBJS) $(PROG2_OUTDIR)
404 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG2_OUTDIR)\adig.exe $(PROG2_OBJS)
405 @if exist $(PROG2_OUTDIR)\adig.exe.manifest mt -nologo -manifest $(PROG2_OUTDIR)\adig.exe.manifest -outputresource:$(PROG2_OUTDIR)\adig.exe;1
406
407ahost: c-ares ahost.c $(SAMPLESOURCES) $(SAMPLEHEADERS) $(PROG3_OBJDIR) $(PROG3_OBJS) $(PROG3_OUTDIR)
408 $(SPROG_LINK) $(SPROG_LFLAGS) /out:$(PROG3_OUTDIR)\ahost.exe $(PROG3_OBJS)
409 @if exist $(PROG3_OUTDIR)\ahost.exe.manifest mt -nologo -manifest $(PROG3_OUTDIR)\ahost.exe.manifest -outputresource:$(PROG3_OUTDIR)\ahost.exe;1
410
411$(CARES_OUTDIR): $(CARES_DIR)
412 @if not exist $(CARES_OUTDIR) mkdir $(CARES_OUTDIR)
413
414$(PROG1_OUTDIR): $(PROG1_DIR)
415 @if not exist $(PROG1_OUTDIR) mkdir $(PROG1_OUTDIR)
416
417$(PROG2_OUTDIR): $(PROG2_DIR)
418 @if not exist $(PROG2_OUTDIR) mkdir $(PROG2_OUTDIR)
419
420$(PROG3_OUTDIR): $(PROG3_DIR)
421 @if not exist $(PROG3_OUTDIR) mkdir $(PROG3_OUTDIR)
422
423$(CARES_OBJDIR): $(CARES_OUTDIR)
424 @if not exist $(CARES_OBJDIR) mkdir $(CARES_OBJDIR)
425
426$(PROG1_OBJDIR): $(PROG1_OUTDIR)
427 @if not exist $(PROG1_OBJDIR) mkdir $(PROG1_OBJDIR)
428
429$(PROG2_OBJDIR): $(PROG2_OUTDIR)
430 @if not exist $(PROG2_OBJDIR) mkdir $(PROG2_OBJDIR)
431
432$(PROG3_OBJDIR): $(PROG3_OUTDIR)
433 @if not exist $(PROG3_OBJDIR) mkdir $(PROG3_OBJDIR)
434
435clean:
436 @-RMDIR /S /Q $(CARES_OUTDIR) >NUL 2>&1
437 @-RMDIR /S /Q $(PROG1_OUTDIR) >NUL 2>&1
438 @-RMDIR /S /Q $(PROG2_OUTDIR) >NUL 2>&1
439 @-RMDIR /S /Q $(PROG3_OUTDIR) >NUL 2>&1
440
441install:
442 @if not exist $(CARES_OUTDIR)\$(CARES_TARGET) \
443 $(MAKE) /f .\Makefile.msvc CFG=$(CFG) c-ares
444 @if not exist "$(INSTALL_DIR)" mkdir "$(INSTALL_DIR)"
445 @if not exist "$(INSTALL_DIR_LIB)" mkdir "$(INSTALL_DIR_LIB)"
446 @if not exist "$(INSTALL_DIR_INC)" mkdir "$(INSTALL_DIR_INC)"
447 @copy /y $(CARES_OUTDIR)\*.* "$(INSTALL_DIR_LIB)" >NUL
448 @copy /y $(SRCDIR)\ares.h "$(INSTALL_DIR_INC)" >NUL
449 @copy /y $(SRCDIR)\ares_build.h "$(INSTALL_DIR_INC)" >NUL
450 @copy /y $(SRCDIR)\ares_rules.h "$(INSTALL_DIR_INC)" >NUL
451 @copy /y $(SRCDIR)\ares_version.h "$(INSTALL_DIR_INC)" >NUL
452 @echo Installed c-ares $(CFG)
453
454!ENDIF
455
456$(BASE_DIR):
457 @if not exist $(BASE_DIR) mkdir $(BASE_DIR)
458
459$(CARES_DIR): $(BASE_DIR)
460 @if not exist $(CARES_DIR) mkdir $(CARES_DIR)
461
462$(PROG1_DIR): $(BASE_DIR)
463 @if not exist $(PROG1_DIR) mkdir $(PROG1_DIR)
464
465$(PROG2_DIR): $(BASE_DIR)
466 @if not exist $(PROG2_DIR) mkdir $(PROG2_DIR)
467
468$(PROG3_DIR): $(BASE_DIR)
469 @if not exist $(PROG3_DIR) mkdir $(PROG3_DIR)
470
471# End of Makefile.msvc