11cb0ef41Sopenharmony_ci# Copyright (C) The c-ares project and its contributors
21cb0ef41Sopenharmony_ci# SPDX-License-Identifier: MIT
31cb0ef41Sopenharmony_ci#
41cb0ef41Sopenharmony_ci#  Watcom / OpenWatcom / Win32 makefile for cares.
51cb0ef41Sopenharmony_ci#  Quick hack by Guenter; comments to: /dev/nul
61cb0ef41Sopenharmony_ci#  Updated by Douglas R. Reno, comments to: renodr2002@gmail.com. 2023
71cb0ef41Sopenharmony_ci#
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci!ifndef %watcom
101cb0ef41Sopenharmony_ci!error WATCOM environment variable not set!
111cb0ef41Sopenharmony_ci!else
121cb0ef41Sopenharmony_ciSYS_INCL = -I$(%watcom)\h\nt -I$(%watcom)\h
131cb0ef41Sopenharmony_ciSYS_LIBS = $(%watcom)\lib386\nt;$(%watcom)\lib386
141cb0ef41Sopenharmony_ci!endif
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci!ifdef %libname
171cb0ef41Sopenharmony_ciLIBNAME = $(%libname)
181cb0ef41Sopenharmony_ci!else
191cb0ef41Sopenharmony_ciLIBNAME	= cares
201cb0ef41Sopenharmony_ci!endif
211cb0ef41Sopenharmony_ciTARGETS = $(LIBNAME).dll $(LIBNAME)_imp.lib $(LIBNAME).lib
221cb0ef41Sopenharmony_ciDEMOS   = adig.exe ahost.exe
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciCC = wcc386
251cb0ef41Sopenharmony_ciLD = wlink
261cb0ef41Sopenharmony_ciAR = wlib
271cb0ef41Sopenharmony_ciRC = wrc
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci!ifdef __LOADDLL__
301cb0ef41Sopenharmony_ci!  loaddll wcc386  wccd386
311cb0ef41Sopenharmony_ci!  loaddll wpp386  wppd386
321cb0ef41Sopenharmony_ci!  loaddll wlib    wlibd
331cb0ef41Sopenharmony_ci!endif
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci!if $(__VERSION__) < 1250
361cb0ef41Sopenharmony_ciRM = del /q /f 2>NUL
371cb0ef41Sopenharmony_ci!else
381cb0ef41Sopenharmony_ciRM = rm -f
391cb0ef41Sopenharmony_ci!endif
401cb0ef41Sopenharmony_ciMD = mkdir
411cb0ef41Sopenharmony_ciRD = rmdir /q /s 2>NUL
421cb0ef41Sopenharmony_ciCP = copy
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciCFLAGS = -3r -mf -hc -zff -zgf -zq -zm -zc -s -fr=con -w2 -fpi -oilrtfm -aa   &
451cb0ef41Sopenharmony_ci         -wcd=201 -bt=nt -d+ -dWIN32 -dCARES_BUILDING_LIBRARY &
461cb0ef41Sopenharmony_ci         -dNTDDI_VERSION=0x06020000 -I. -I.\include -I.\src\lib $(SYS_INCL)
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciLFLAGS = option quiet, map, caseexact, eliminate
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci!ifdef %debug
511cb0ef41Sopenharmony_ciDEBUG  = -dDEBUG=1 -dDEBUGBUILD
521cb0ef41Sopenharmony_ciCFLAGS += -d3 $(DEBUG)
531cb0ef41Sopenharmony_ciLFLAGS += debug all
541cb0ef41Sopenharmony_ci!else
551cb0ef41Sopenharmony_ciCFLAGS += -d0
561cb0ef41Sopenharmony_ci!endif
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ciCFLAGS += -d_WIN32_WINNT=0x0602
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci#
611cb0ef41Sopenharmony_ci# Change to suite.
621cb0ef41Sopenharmony_ci#
631cb0ef41Sopenharmony_ci!ifdef %use_watt32
641cb0ef41Sopenharmony_ciCFLAGS += -dWATT32 -I$(%watt_root)\inc
651cb0ef41Sopenharmony_ci!endif
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciOBJ_BASE = WC_Win32.obj
681cb0ef41Sopenharmony_ciLINK_ARG = $(OBJ_BASE)\dyn\wlink.arg
691cb0ef41Sopenharmony_ciLIB_ARG  = $(OBJ_BASE)\stat\wlib.arg
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci# In order to process Makefile.inc wmake must be called with -u switch!
721cb0ef41Sopenharmony_ci!ifneq __MAKEOPTS__ -u
731cb0ef41Sopenharmony_ci!error You MUST call wmake with the -u switch!
741cb0ef41Sopenharmony_ci!else
751cb0ef41Sopenharmony_ci!include src\lib\Makefile.inc
761cb0ef41Sopenharmony_ci!endif
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ciOBJS = $(CSOURCES:.c=.obj)
791cb0ef41Sopenharmony_ciOBJS = $OBJ_DIR\$(OBJS: = $OBJ_DIR\)
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci#
821cb0ef41Sopenharmony_ci# Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN).
831cb0ef41Sopenharmony_ci#
841cb0ef41Sopenharmony_ciOBJ_DIR    = $(OBJ_BASE)\stat
851cb0ef41Sopenharmony_ciOBJS_STAT  = $+ $(OBJS) $-
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ciOBJ_DIR    = $(OBJ_BASE)\dyn
881cb0ef41Sopenharmony_ciOBJS_DYN   += $(OBJS) $-
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ciARESBUILDH = ares_build.h
911cb0ef41Sopenharmony_ciRESOURCE   = $(OBJ_BASE)\dyn\cares.res
921cb0ef41Sopenharmony_ciARESBUILDH = include\ares_build.h
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ciall: $(ARESBUILDH) $(OBJ_BASE) $(TARGETS) $(DEMOS) .SYMBOLIC
951cb0ef41Sopenharmony_ci	@echo Welcome to cares
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci$(OBJ_BASE):
981cb0ef41Sopenharmony_ci	-$(MD) $^@
991cb0ef41Sopenharmony_ci	-$(MD) $^@\stat
1001cb0ef41Sopenharmony_ci	-$(MD) $^@\dyn
1011cb0ef41Sopenharmony_ci	-$(MD) $^@\tools
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci$(ARESBUILDH): .EXISTSONLY
1041cb0ef41Sopenharmony_ci	@echo Make sure to run buildconf.bat!
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci$(LIBNAME).dll: $(OBJS_DYN) $(RESOURCE) $(LINK_ARG)
1071cb0ef41Sopenharmony_ci	$(LD) name $^@ @$]@
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci$(LIBNAME).lib: $(OBJS_STAT) $(LIB_ARG)
1101cb0ef41Sopenharmony_ci	$(AR) -q -b -c $^@ @$]@
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci$(OBJ_BASE)\tools\ares_getopt.obj:
1131cb0ef41Sopenharmony_ci	$(CC) $(CFLAGS) -DCARES_STATICLIB .\src\tools\ares_getopt.c -fo=$^@
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ciadig.exe: $(OBJ_BASE)\tools\ares_getopt.obj $(LIBNAME).lib
1161cb0ef41Sopenharmony_ci	$(CC) $(CFLAGS) src\tools\adig.c -fo=$(OBJ_BASE)\tools\adig.obj
1171cb0ef41Sopenharmony_ci	$(LD) name $^@ system nt $(LFLAGS) file { $(OBJ_BASE)\tools\adig.obj $[@ } library $]@, ws2_32.lib, iphlpapi.lib
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ciahost.exe: $(OBJ_BASE)\tools\ares_getopt.obj $(LIBNAME).lib
1201cb0ef41Sopenharmony_ci	$(CC) $(CFLAGS) src\tools\ahost.c -fo=$(OBJ_BASE)\tools\ahost.obj
1211cb0ef41Sopenharmony_ci	$(LD) name $^@ system nt $(LFLAGS) file { $(OBJ_BASE)\tools\ahost.obj $[@ } library $]@, ws2_32.lib, iphlpapi.lib
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ciclean: .SYMBOLIC
1241cb0ef41Sopenharmony_ci	-$(RM) $(OBJS_STAT)
1251cb0ef41Sopenharmony_ci	-$(RM) $(OBJS_DYN)
1261cb0ef41Sopenharmony_ci	-$(RM) $(RESOURCE) $(LINK_ARG) $(LIB_ARG)
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_civclean realclean: clean .SYMBOLIC
1291cb0ef41Sopenharmony_ci	-$(RM) $(TARGETS) $(LIBNAME).map
1301cb0ef41Sopenharmony_ci	-$(RM) $(DEMOS) $(DEMOS:.exe=.map)
1311cb0ef41Sopenharmony_ci	-$(RD) $(OBJ_BASE)\stat
1321cb0ef41Sopenharmony_ci	-$(RD) $(OBJ_BASE)\dyn
1331cb0ef41Sopenharmony_ci	-$(RD) $(OBJ_BASE)\tools
1341cb0ef41Sopenharmony_ci	-$(RD) $(OBJ_BASE)
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci.ERASE
1371cb0ef41Sopenharmony_ci.c: .\src\lib
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ci.ERASE
1401cb0ef41Sopenharmony_ci$(RESOURCE): src\lib\cares.rc .AUTODEPEND
1411cb0ef41Sopenharmony_ci	$(RC) $(DEBUG) -q -r -zm -I..\include $(SYS_INCL) $[@ -fo=$^@
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ci.ERASE
1441cb0ef41Sopenharmony_ci.c{$(OBJ_BASE)\dyn}.obj:
1451cb0ef41Sopenharmony_ci	$(CC) $(CFLAGS) -bd .\src\lib\$^& -fo=$^@
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_ci.ERASE
1481cb0ef41Sopenharmony_ci.c{$(OBJ_BASE)\stat}.obj:
1491cb0ef41Sopenharmony_ci	$(CC) $(CFLAGS) -DCARES_STATICLIB .\src\lib\$^& -fo=$^@
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci$(LINK_ARG): $(__MAKEFILES__)
1521cb0ef41Sopenharmony_ci	%create $^@
1531cb0ef41Sopenharmony_ci	@%append $^@ system nt dll
1541cb0ef41Sopenharmony_ci	@%append $^@ file { $(OBJS_DYN) }
1551cb0ef41Sopenharmony_ci	@%append $^@ option res=$(RESOURCE), implib=$(LIBNAME)_imp.lib 
1561cb0ef41Sopenharmony_ci	@%append $^@ $(LFLAGS)
1571cb0ef41Sopenharmony_ci	@%append $^@ libpath $(SYS_LIBS)
1581cb0ef41Sopenharmony_ci#	@%append $^@ library clib3r.lib
1591cb0ef41Sopenharmony_ci!ifdef %use_watt32
1601cb0ef41Sopenharmony_ci	@%append $^@ library $(%watt_root)\lib\wattcpw_imp.lib
1611cb0ef41Sopenharmony_ci!else
1621cb0ef41Sopenharmony_ci	@%append $^@ library ws2_32.lib
1631cb0ef41Sopenharmony_ci	@%append $^@ library iphlpapi.lib
1641cb0ef41Sopenharmony_ci!endif
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ci$(LIB_ARG): $(__MAKEFILES__)
1671cb0ef41Sopenharmony_ci	%create $^@
1681cb0ef41Sopenharmony_ci	@for %f in ($(OBJS_STAT)) do @%append $^@ +- %f
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ci
171