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