1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1999 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21#***************************************************************************
22
23###########################################################################
24#
25## Makefile for building curl.exe with MingW (GCC-3.2 or later or LLVM/Clang)
26## and optionally OpenSSL (1.0.2a), libssh2 (1.5), zlib (1.2.8), librtmp (2.4),
27## brotli (1.0.1), zstd (1.4.5)
28##
29## Usage:   mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
30## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
31##
32## Hint: you can also set environment vars to control the build, f.e.:
33## set ZLIB_PATH=c:/zlib-1.2.8
34## set ZLIB=1
35#
36###########################################################################
37
38# Edit the path below to point to the base of your Zlib sources.
39ifndef ZLIB_PATH
40ZLIB_PATH = ../../zlib-1.2.8
41endif
42# Edit the path below to point to the base of your Zstandard sources.
43ifndef ZSTD_PATH
44ZSTD_PATH = ../../zstd-1.4.5
45endif
46# Edit the path below to point to the base of your Brotli sources.
47ifndef BROTLI_PATH
48BROTLI_PATH = ../../brotli-1.0.1
49endif
50# Edit the path below to point to the base of your OpenSSL package.
51ifndef OPENSSL_PATH
52OPENSSL_PATH = ../../openssl-1.0.2a
53endif
54# Edit the path below to point to the base of your LibSSH2 package.
55ifndef LIBSSH2_PATH
56LIBSSH2_PATH = ../../libssh2-1.5.0
57endif
58# Edit the path below to point to the base of your librtmp package.
59ifndef LIBRTMP_PATH
60LIBRTMP_PATH = ../../librtmp-2.4
61endif
62# Edit the path below to point to the base of your libexpat package.
63ifndef LIBEXPAT_PATH
64LIBEXPAT_PATH = ../../expat-2.1.0
65endif
66# Edit the path below to point to the base of your libxml2 package.
67ifndef LIBXML2_PATH
68LIBXML2_PATH = ../../libxml2-2.9.2
69endif
70# Edit the path below to point to the base of your libgsasl package.
71ifndef LIBGSASL_PATH
72LIBGSASL_PATH = ../../libgsasl-1.10.0
73endif
74# Edit the path below to point to the base of your libidn2 package.
75ifndef LIBIDN2_PATH
76LIBIDN2_PATH = ../../libidn2-2.0.3
77endif
78# Edit the path below to point to the base of your MS IDN package.
79# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
80# https://www.microsoft.com/en-us/download/details.aspx?id=734
81ifndef WINIDN_PATH
82WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
83endif
84# Edit the path below to point to the base of your Novell LDAP NDK.
85ifndef LDAP_SDK
86LDAP_SDK = c:/novell/ndk/cldapsdk/win32
87endif
88# Edit the path below to point to the base of your nghttp2 package.
89ifndef NGHTTP2_PATH
90NGHTTP2_PATH = ../../nghttp2-1.0.0
91endif
92# Edit the path below to point to the base of your nghttp3 package.
93ifndef NGHTTP3_PATH
94NGHTTP3_PATH = ../../nghttp3-1.0.0
95endif
96# Edit the path below to point to the base of your ngtcp2 package.
97ifndef NGTCP2_PATH
98NGTCP2_PATH = ../../ngtcp2-1.0.0
99endif
100
101PROOT = ..
102
103# Edit the path below to point to the base of your c-ares package.
104ifndef LIBCARES_PATH
105LIBCARES_PATH = $(PROOT)/ares
106endif
107
108ifeq ($(CURL_CC),)
109CURL_CC := $(CROSSPREFIX)gcc
110endif
111ifeq ($(CURL_AR),)
112CURL_AR := $(CROSSPREFIX)ar
113endif
114
115CC = $(CURL_CC)
116CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W
117CFLAGS += -fno-strict-aliasing
118# comment LDFLAGS below to keep debug info
119LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_EXE) -s
120AR = $(CURL_AR)
121RC = $(CROSSPREFIX)windres
122RCFLAGS = --include-dir=$(PROOT)/include -O coff -DCURL_EMBED_MANIFEST
123STRIP   = $(CROSSPREFIX)strip -g
124
125# We may need these someday
126# PERL = perl
127# NROFF = nroff
128
129# Set environment var ARCH to your architecture to override autodetection.
130ifndef ARCH
131ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
132ARCH = w64
133else
134ARCH = w32
135endif
136endif
137
138ifeq ($(ARCH),w64)
139CFLAGS  += -m64 -D_AMD64_
140LDFLAGS += -m64
141RCFLAGS += -F pe-x86-64
142else
143CFLAGS  += -m32
144LDFLAGS += -m32
145RCFLAGS += -F pe-i386
146endif
147
148# Platform-dependent helper tool macros
149ifeq ($(findstring /sh,$(SHELL)),/sh)
150DEL     = rm -f $1
151RMDIR   = rm -fr $1
152MKDIR   = mkdir -p $1
153COPY    = -cp -afv $1 $2
154#COPYR  = -cp -afr $1/* $2
155COPYR   = -rsync -aC $1/* $2
156TOUCH   = touch $1
157CAT     = cat
158ECHONL  = echo ""
159DL = '
160else
161ifeq "$(OS)" "Windows_NT"
162DEL     = -del 2>NUL /q /f $(subst /,\,$1)
163RMDIR   = -rd 2>NUL /q /s $(subst /,\,$1)
164else
165DEL     = -del 2>NUL $(subst /,\,$1)
166RMDIR   = -deltree 2>NUL /y $(subst /,\,$1)
167endif
168MKDIR   = -md 2>NUL $(subst /,\,$1)
169COPY    = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
170COPYR   = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
171TOUCH   = copy 2>&1>NUL /b $(subst /,\,$1) +,,
172CAT     = type
173ECHONL  = $(ComSpec) /c echo.
174endif
175
176########################################################
177## Nothing more to do below this line!
178
179ifeq ($(findstring -dyn,$(CFG)),-dyn)
180DYN = 1
181endif
182ifeq ($(findstring -ares,$(CFG)),-ares)
183ARES = 1
184endif
185ifeq ($(findstring -sync,$(CFG)),-sync)
186SYNC = 1
187endif
188ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
189RTMP = 1
190ZLIB = 1
191endif
192ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
193SSH2 = 1
194ZLIB = 1
195endif
196ifeq ($(findstring -ssl,$(CFG)),-ssl)
197SSL = 1
198endif
199ifeq ($(findstring -zlib,$(CFG)),-zlib)
200ZLIB = 1
201endif
202ifeq ($(findstring -zstd,$(CFG)),-zstd)
203ZSTD = 1
204endif
205ifeq ($(findstring -brotli,$(CFG)),-brotli)
206BROTLI = 1
207endif
208ifeq ($(findstring -gsasl,$(CFG)),-gsasl)
209GSASL = 1
210endif
211ifeq ($(findstring -idn2,$(CFG)),-idn2)
212IDN2 = 1
213endif
214ifeq ($(findstring -winidn,$(CFG)),-winidn)
215WINIDN = 1
216endif
217ifeq ($(findstring -sspi,$(CFG)),-sspi)
218SSPI = 1
219endif
220ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
221LDAPS = 1
222endif
223ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
224IPV6 = 1
225endif
226ifeq ($(findstring -winssl,$(CFG)),-winssl)
227WINSSL = 1
228SSPI = 1
229endif
230ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
231NGHTTP2 = 1
232endif
233ifeq ($(findstring -nghttp3,$(CFG)),-nghttp3)
234NGHTTP3 = 1
235endif
236ifeq ($(findstring -ngtcp2,$(CFG)),-ngtcp2)
237NGTCP2 = 1
238endif
239ifeq ($(findstring -unicode,$(CFG)),-unicode)
240UNICODE = 1
241endif
242
243# SSH2 and RTMP require an SSL library; assume OpenSSL if none specified
244ifneq ($(SSH2)$(RTMP),)
245  ifeq ($(SSL)$(WINSSL),)
246    SSL = 1
247  endif
248endif
249
250INCLUDES = -I. -I../include -I../lib
251ifdef SSL
252  ifdef WINSSL
253    CFLAGS += -DCURL_WITH_MULTI_SSL
254  endif
255endif
256ifdef UNICODE
257  CFLAGS += -DUNICODE -D_UNICODE
258  LDFLAGS += -municode
259endif
260
261ifdef DYN
262  curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll
263  curl_LDADD = -L$(PROOT)/lib -lcurldll
264else
265  curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a
266  curl_LDADD = -L$(PROOT)/lib -lcurl
267  CFLAGS += -DCURL_STATICLIB
268  LDFLAGS += -static
269endif
270ifdef SYNC
271  CFLAGS += -DUSE_SYNC_DNS
272else
273  ifdef ARES
274    ifndef DYN
275      curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a
276    endif
277    CFLAGS += -DUSE_ARES -DCARES_STATICLIB
278    curl_LDADD += -L"$(LIBCARES_PATH)" -lcares
279  endif
280endif
281ifdef RTMP
282  CFLAGS += -DUSE_LIBRTMP
283  curl_LDADD += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
284endif
285ifdef NGHTTP2
286  CFLAGS += -DUSE_NGHTTP2
287  curl_LDADD += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
288endif
289ifdef SSH2
290  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
291  curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2
292  ifdef WINSSL
293    ifndef DYN
294      curl_LDADD += -lbcrypt -lcrypt32
295    endif
296  endif
297endif
298ifdef SSL
299  ifdef NGHTTP3
300    CFLAGS += -DUSE_NGHTTP3
301    curl_LDADD += -L"$(NGHTTP3_PATH)/lib" -lnghttp3
302    ifdef NGTCP2
303      CFLAGS += -DUSE_NGTCP2
304      curl_LDADD += -L"$(NGTCP2_PATH)/lib" -lngtcp2 -lngtcp2_crypto_openssl
305    endif
306  endif
307
308  ifndef OPENSSL_INCLUDE
309    ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
310      OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
311    endif
312    ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
313      OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
314    endif
315  endif
316  ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
317    $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
318  endif
319  ifndef OPENSSL_LIBPATH
320    OPENSSL_LIBS = -lssl -lcrypto
321    ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
322      OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
323      ifdef DYN
324        OPENSSL_LIBS = -lssl32 -leay32
325      endif
326    endif
327    ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
328      OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
329    endif
330  endif
331  ifndef DYN
332    OPENSSL_LIBS += -lgdi32 -lcrypt32
333  endif
334  INCLUDES += -I"$(OPENSSL_INCLUDE)"
335  CFLAGS += -DUSE_OPENSSL
336  curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
337endif
338ifdef WINSSL
339  CFLAGS += -DUSE_SCHANNEL
340  curl_LDADD += -lcrypt32
341endif
342ifdef ZLIB
343  INCLUDES += -I"$(ZLIB_PATH)"
344  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
345  curl_LDADD += -L"$(ZLIB_PATH)" -lz
346endif
347ifdef ZSTD
348  INCLUDES += -I"$(ZSTD_PATH)/include"
349  CFLAGS += -DHAVE_ZSTD
350  curl_LDADD += -L"$(ZSTD_PATH)/lib"
351  ifdef ZSTD_LIBS
352    curl_LDADD += $(ZSTD_LIBS)
353  else
354    curl_LDADD += -lzstd
355  endif
356endif
357ifdef BROTLI
358  INCLUDES += -I"$(BROTLI_PATH)/include"
359  CFLAGS += -DHAVE_BROTLI
360  curl_LDADD += -L"$(BROTLI_PATH)/lib"
361  ifdef BROTLI_LIBS
362    curl_LDADD += $(BROTLI_LIBS)
363  else
364    curl_LDADD += -lbrotlidec
365  endif
366endif
367ifdef GSASL
368  CFLAGS += -DUSE_GSASL
369  curl_LDADD += -L"$(LIBGSASL_PATH)/lib" -lgsasl
370endif
371ifdef IDN2
372  CFLAGS += -DUSE_LIBIDN2
373  curl_LDADD += -L"$(LIBIDN2_PATH)/lib" -lidn2
374else
375ifdef WINIDN
376  CFLAGS += -DUSE_WIN32_IDN
377  curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz
378endif
379endif
380ifdef SSPI
381  CFLAGS += -DUSE_WINDOWS_SSPI
382endif
383ifdef IPV6
384  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
385endif
386ifdef LDAPS
387  CFLAGS += -DHAVE_LDAP_SSL
388endif
389ifdef USE_LDAP_NOVELL
390  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
391  curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
392endif
393ifdef USE_LDAP_OPENLDAP
394  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
395  curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber
396endif
397ifndef USE_LDAP_NOVELL
398ifndef USE_LDAP_OPENLDAP
399curl_LDADD += -lwldap32
400endif
401endif
402curl_LDADD += -lws2_32
403
404# Makefile.inc provides the CSOURCES and HHEADERS defines
405include Makefile.inc
406
407curl_PROGRAMS = curl.exe
408curl_OBJECTS := $(patsubst %.c,%.o,$(strip $(CURL_CFILES)))
409curlx_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CURLX_CFILES))))
410curl_OBJECTS += $(curlx_OBJECTS)
411vpath %.c $(PROOT)/lib
412
413RESOURCE = curl.res
414
415
416all: $(curl_PROGRAMS)
417
418curl.exe: $(RESOURCE) $(curl_OBJECTS) $(curl_DEPENDENCIES)
419	$(call DEL, $@)
420	$(CC) $(LDFLAGS) -o $@ $< $(curl_OBJECTS) $(curl_LDADD)
421
422# We don't have nroff normally under win32
423# tool_hugehelp.c: $(PROOT)/docs/MANUAL $(PROOT)/docs/curl.1 mkhelp.pl
424#	@$(call DEL, tool_hugehelp.c)
425# 	$(NROFF) -man $(PROOT)/docs/curl.1 | $(PERL) mkhelp.pl $(PROOT)/docs/MANUAL > tool_hugehelp.c
426
427tool_hugehelp.c:
428	@echo Creating $@
429	@$(call COPY, $@.cvs, $@)
430
431%.o: %.c
432	$(CC) $(INCLUDES) $(CFLAGS) -c $<
433
434%.res: %.rc
435	$(RC) $(RCFLAGS) -i $< -o $@
436
437clean:
438ifeq "$(wildcard tool_hugehelp.c.cvs)" "tool_hugehelp.c.cvs"
439	@$(call DEL, tool_hugehelp.c)
440endif
441	@$(call DEL, $(curl_OBJECTS) $(curlx_OBJECTS) $(RESOURCE))
442
443distclean vclean: clean
444	@$(call DEL, $(curl_PROGRAMS))
445