forked from sezero/watt32
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile.Windows
343 lines (296 loc) · 10.8 KB
/
Makefile.Windows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#
# GNU-make Makefile for the `wget' utility (building on Windows).
#
# Targets:
# Watt-32 on Windows; USE_WATT32=1 -> wget-w32.exe
# or Winsock2; USE_WATT32=0 -> wget-win.exe
# or djgpp (MSDOS); USE_DJGPP=1 -> wget-dj.exe
#
# Target either MSVC (default), clang-cl, MinGW-w64, Cygwin or djgpp.
#
USE_DJGPP ?= 0
USE_MINGW ?= 0
USE_CLANG ?= 0
USE_CYGWIN ?= 0
USE_WATT32 ?= 1
#
# Use "Address Sanitizer"?
#
USE_ASAN ?= 0
#
# Use "Undefined Behavior Sanitizer (UBSan)"?
#
USE_UBSAN ?= 0
THIS_FILE = Makefile.Windows
MAKEFLAGS += --warn-undefined-variables
WATT_ROOT := $(realpath $(WATT_ROOT))
ifeq ($(CPU),x86)
BITS = 32
else
BITS = 64
endif
ifeq ($(USE_DJGPP),1)
ifneq ($(OS),Windows_NT)
$(error Use this makefile on Windows only)
endif
ifeq ($(DJGPP_PREFIX),)
$(error Define a DJGPP_PREFIX to invoke the djgpp cross compiler)
endif
USE_WATT32 = 1
CC = $(DJGPP_PREFIX)-gcc.exe
OBJ_DIR = djgpp_obj
O = o
IS_GCC = 1
CC_ARGS = gcc.args
select =
else ifeq ($(USE_MINGW),1)
#
# Change to suite
#
CC = $(realpath $(MINGW_TDM))/bin/gcc.exe
OBJ_DIR = mingw_obj
O = o
CC_ARGS = gcc.args
IS_GCC = 1
select = $(1)
else ifeq ($(USE_CYGWIN),1)
#
# Change to suite
#
CC = $(realpath $(CYGWIN_ROOT))/bin/gcc.exe
OBJ_DIR = cygwin_obj
O = o
CC_ARGS = gcc.args
IS_GCC = 1
select = $(2)
else ifeq ($(USE_CLANG),1)
#
# The 'clang-cl.bat' (on PATH) should look like this:
# @echo off
# setlocal
# set CLANG_32=c:\ProgramFiles\LLVM-15-32bit << install base of your 32-bit Clang
# set CLANG_64=c:\ProgramFiles\LLVM-15-64bit << ditto for 64-bit
# set CL=
# if %1. == -m32. (
# shift
# %CLANG_32%\bin\clang-cl.exe %*
# ) else if %1. == -m64. (
# shift
# %CLANG_64%\bin\clang-cl.exe %*
# ) else (
# clang-cl.exe %*
# )
#
CC = clang-cl.bat -m$(BITS)
OBJ_DIR = clang_obj
O = obj
CC_ARGS = clang-cl.args
IS_GCC = 0
select = $(3)
else
CC = cl.exe
OBJ_DIR = msvc_obj
O = obj
CC_ARGS = cl.args
IS_GCC = 0
select = $(4)
endif
c_to_obj = $(addprefix $(OBJ_DIR)/, \
$(notdir $(1:.c=.$(O))))
ifeq ($(IS_GCC),1)
os_lib = $(addprefix -l,$(strip $(1:.lib=)))
else
os_lib = $(1)
endif
SOURCES = cmpt.c connect.c cookies.c fnmatch.c ftp-basi.c ftp-ls.c \
ftp-opie.c ftp.c gen-md5.c gen_sslf.c getopt.c gnu-md5.c \
hash.c headers.c host.c html-par.c html-url.c http.c \
init.c log.c main.c netrc.c progress.c rbuf.c recur.c \
res.c retr.c safe-cty.c url.c utils.c version.c # snprintf.c
CFLAGS = -I. -DHAVE_CONFIG_H
ifeq ($(USE_DJGPP),0)
SOURCES += mswindow.c
CFLAGS += -D_WIN32_WINNT=0x0600 \
-D_WINSOCK_DEPRECATED_NO_WARNINGS
endif
OBJECTS = $(call c_to_obj, $(SOURCES))
ifeq ($(USE_DJGPP),1)
else ifeq ($(USE_MINGW),1)
CFLAGS += -m$(BITS)
LDFLAGS = -m$(BITS)
else ifeq ($(USE_CYGWIN),1)
ifeq ($(USE_WATT32),0)
CFLAGS += -DWINDOWS # -D__USE_W32_SOCKETS
endif
else
#
# MSVC or clang-cl:
#
CFLAGS += -nologo -MD -Ot -W3 -Zi \
-Gy -GS -RTCs \
-I./msvc-missing \
-D_CRT_SECURE_NO_WARNINGS \
-D_CRT_SECURE_NO_DEPRECATE \
-D_CRT_NONSTDC_NO_WARNINGS \
-wd4101 -wd4018 -wd4244 \
-wd4267 -wd4133
LDFLAGS = -nologo -manifest:no -debug -incremental:no -machine:$(CPU)
endif
ifeq ($(USE_CLANG),1)
CFLAGS += -fms-compatibility \
-ferror-limit=5 \
-Wno-format \
-Wno-unused-function \
-Wno-unused-variable \
-Wno-constant-conversion \
-Wno-deprecated-non-prototype \
-Wno-incompatible-pointer-types \
# -Wno-implicit-function-declaration
#
# Enable one of the above as e.g:
# make -f $(THIS_FILE) USE_CLANG=1 USE_ASAN=1 clean all
# make -f $(THIS_FILE) USE_CLANG=1 USE_ASAN=1 clean all
#
# Can be used with 'USE_UBSAN = 1' too.
#
# This works pretty good for bug reporting:
# c:\> set ASAN_OPTIONS=print_stats=1:windows_hook_legacy_allocators=1:color=always:halt_on_error=0
#
ifeq ($(USE_ASAN),1)
CFLAGS += -DUSE_ASAN \
-fsanitize=address \
-fsanitize-recover=address
endif
ifeq ($(USE_UBSAN),1)
CFLAGS += -DUSE_UBSAN \
-fsanitize=undefined
endif
ifneq ($(USE_ASAN)$(USE_UBSAN),00)
ifeq ($(CLANG_MAJOR_VER),)
$(error 'CLANG_MAJOR_VER' must be set in your environment.)
endif
#
# E.g. for 'CPU=x86', CLANG_ROOT -> 'c:/ProgramFiles/LLVM-15-32bit'
#
CLANG_ROOT = $(realpath $(CLANG_$(BITS)))
#
# The default for 'x86 / Release' is 'clang_rt.asan_dynamic_runtime_thunk-i386.lib'
# (and clang_rt.asan_dbg_dynamic_runtime_thunk-i386.lib for 'x86 / Debug')
#
# Let the linker select the ASAN libraries.
#
LDFLAGS += -inferasanlibs \
-libpath:"$(VCToolsInstallDir)\lib\$(CPU)" \
-libpath:"$(WindowsSdkDir)\lib\$(WindowsSdkVer)\ucrt\$(CPU)" \
-libpath:"$(WindowsSdkDir)\lib\$(WindowsSdkVer)\um\$(CPU)" \
-libpath:"$(CLANG_ROOT)/lib/clang/$(CLANG_MAJOR_VER)/lib/windows"
endif
endif
ifeq ($(USE_DJGPP),1)
EXE = wget-dj.exe
CFLAGS += -DWATT32 \
-DWATT32_NO_OLDIES \
-I$(WATT_ROOT)/inc
OS_LIBS =
WATT_LIB = $(WATT_ROOT)/lib/libwatt.a
else ifeq ($(USE_WATT32),1)
EXE = wget-w32.exe
CFLAGS += -DWATT32 \
-DWATT32_NO_OLDIES \
-DWATT32_STATIC \
-I$(WATT_ROOT)/inc \
-I$(WATT_ROOT)/inc/w32-fakes
OS_LIBS = $(call os_lib, advapi32.lib user32.lib)
WATT_LIB = $(call select, $(WATT_ROOT)/lib/$(CPU)/libwatt32.a, \
$(WATT_ROOT)/lib/$(CPU)/libwatt32-cygwin.a, \
$(WATT_ROOT)/lib/$(CPU)/wattcp_clang.lib, \
$(WATT_ROOT)/lib/$(CPU)/wattcpvc.lib)
else
#
# Let Cygwin use the Winsock2 API (not POSIX)
#
CFLAGS += -D__USE_W32_SOCKETS \
-D_CRT_NO_POSIX_ERROR_CODES
EXE = wget-win.exe
OS_LIBS = $(call select, -lws2_32, -lws2_32, ws2_32.lib, ws2_32.lib)
WATT_LIB =
endif
all: $(EXE)
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR) $(CC_ARGS)
$(CC) @$(CC_ARGS) -o $@ $<
@echo
$(OBJ_DIR)/%.obj: %.c | $(OBJ_DIR) $(CC_ARGS)
$(CC) @$(CC_ARGS) -Fo./$@ $<
@echo
ifeq ($(IS_GCC),1)
#
# The awful '$GCC_COLORS' messed up the console.
#
CFLAGS += -fdiagnostics-color=never
$(EXE): $(OBJECTS) $(WATT_LIB)
$(CC) -o $@ $(LDFLAGS) $^ $(OS_LIBS)
@echo
else
$(EXE): $(OBJECTS) $(WATT_LIB)
link -out:$@ $(LDFLAGS) $^ $(OS_LIBS)
rm -f $(@:.exe=.{exp,lib})
@echo
endif
$(OBJ_DIR):
mkdir $@
$(CC_ARGS): $(THIS_FILE)
$(call green_msg, All CFLAGS are in $@)
$(call create_resp_file, $@, -c $(CFLAGS))
clean:
rm -fr $(OBJ_DIR)
rm -f vc14*.pdb cl.args clang-cl.args gcc.args
vclean realclean: clean
rm -f wget-win.* wget-w32.*
rm -fr clang_obj mingw_obj msvc_obj
#
# Some GNU-make macros.
#
# The following assumes you have MSys/Cygwin's echo with colour support.
#
BRIGHT_GREEN = \e[1;32m
BRIGHT_WHITE = \e[1;37m
colour_msg = @echo -e "$(1)\e[0m"
green_msg = $(call colour_msg,$(BRIGHT_GREEN)$(strip $(1)))
white_msg = $(call colour_msg,$(BRIGHT_WHITE)$(strip $(1)))
define create_resp_file
$(file > $(1))
$(foreach w, $(2), $(file >> $(1),$(strip $(w))) )
endef
$(OBJ_DIR)/cmpt.$(O): cmpt.c config.h wget.h sysdep.h options.h safe-cty.h
$(OBJ_DIR)/connect.$(O): connect.c config.h wget.h sysdep.h options.h safe-cty.h connect.h host.h
$(OBJ_DIR)/cookies.$(O): cookies.c config.h wget.h sysdep.h options.h safe-cty.h utils.h hash.h url.h cookies.h
$(OBJ_DIR)/fnmatch.$(O): fnmatch.c config.h wget.h sysdep.h options.h safe-cty.h fnmatch.h
$(OBJ_DIR)/ftp-basi.$(O): ftp-basi.c config.h wget.h sysdep.h options.h safe-cty.h utils.h rbuf.h connect.h host.h ftp.h
$(OBJ_DIR)/ftp-ls.$(O): ftp-ls.c config.h wget.h sysdep.h options.h safe-cty.h utils.h ftp.h rbuf.h url.h
$(OBJ_DIR)/ftp-opie.$(O): ftp-opie.c config.h wget.h sysdep.h options.h safe-cty.h gen-md5.h
$(OBJ_DIR)/ftp.$(O): ftp.c config.h wget.h sysdep.h options.h safe-cty.h utils.h url.h rbuf.h retr.h ftp.h connect.h host.h fnmatch.h netrc.h
$(OBJ_DIR)/gen-md5.$(O): gen-md5.c config.h wget.h sysdep.h options.h safe-cty.h gen-md5.h gnu-md5.h
$(OBJ_DIR)/gen_sslf.$(O): gen_sslf.c config.h
$(OBJ_DIR)/getopt.$(O): getopt.c config.h wget.h sysdep.h options.h safe-cty.h getopt.h
$(OBJ_DIR)/gnu-md5.$(O): gnu-md5.c config.h wget.h sysdep.h options.h safe-cty.h gnu-md5.h
$(OBJ_DIR)/hash.$(O): hash.c config.h wget.h sysdep.h options.h safe-cty.h utils.h hash.h
$(OBJ_DIR)/headers.$(O): headers.c config.h wget.h sysdep.h options.h safe-cty.h connect.h rbuf.h headers.h
$(OBJ_DIR)/host.$(O): host.c config.h wget.h sysdep.h options.h safe-cty.h utils.h host.h url.h hash.h
$(OBJ_DIR)/html-par.$(O): html-par.c config.h wget.h sysdep.h options.h safe-cty.h html-par.h
$(OBJ_DIR)/html-url.$(O): html-url.c config.h wget.h sysdep.h options.h safe-cty.h html-par.h url.h utils.h
$(OBJ_DIR)/http.$(O): http.c config.h wget.h sysdep.h options.h safe-cty.h utils.h url.h host.h rbuf.h retr.h headers.h connect.h fnmatch.h netrc.h cookies.h gen-md5.h
$(OBJ_DIR)/init.$(O): init.c config.h wget.h sysdep.h options.h safe-cty.h utils.h init.h host.h recur.h netrc.h cookies.h progress.h
$(OBJ_DIR)/log.$(O): log.c config.h wget.h sysdep.h options.h safe-cty.h utils.h
$(OBJ_DIR)/main.$(O): main.c config.h wget.h sysdep.h options.h safe-cty.h utils.h init.h retr.h rbuf.h recur.h host.h cookies.h url.h progress.h getopt.h
$(OBJ_DIR)/netrc.$(O): netrc.c config.h wget.h sysdep.h options.h safe-cty.h utils.h netrc.h init.h
$(OBJ_DIR)/progress.$(O): progress.c config.h wget.h sysdep.h options.h safe-cty.h progress.h utils.h retr.h rbuf.h
$(OBJ_DIR)/rbuf.$(O): rbuf.c config.h wget.h sysdep.h options.h safe-cty.h rbuf.h connect.h
$(OBJ_DIR)/recur.$(O): recur.c config.h wget.h sysdep.h options.h safe-cty.h url.h recur.h utils.h retr.h rbuf.h ftp.h fnmatch.h host.h hash.h res.h
$(OBJ_DIR)/res.$(O): res.c config.h wget.h sysdep.h options.h safe-cty.h utils.h hash.h url.h retr.h rbuf.h res.h
$(OBJ_DIR)/retr.$(O): retr.c config.h wget.h sysdep.h options.h safe-cty.h utils.h retr.h rbuf.h progress.h url.h recur.h ftp.h host.h connect.h hash.h
$(OBJ_DIR)/safe-cty.$(O): safe-cty.c config.h safe-cty.h
$(OBJ_DIR)/snprintf.$(O): snprintf.c config.h safe-cty.h
$(OBJ_DIR)/url.$(O): url.c config.h wget.h sysdep.h options.h safe-cty.h utils.h url.h host.h hash.h
$(OBJ_DIR)/utils.$(O): utils.c config.h wget.h sysdep.h options.h safe-cty.h utils.h fnmatch.h hash.h
$(OBJ_DIR)/version.$(O): version.c
$(OBJ_DIR)/mswindow.$(O): mswindow.c