blob: 773187ad7f3d686e6f15ca478fcdc61b66e2500c [file] [log] [blame]
Alex Deymod15eaac2016-06-28 14:49:26 -07001#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
Elliott Hughes82be86d2017-09-20 17:00:17 -07008# Copyright (C) 1999 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
Alex Deymod15eaac2016-06-28 14:49:26 -07009#
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.haxx.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
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070023###########################################################################
Lucas Eckels9bd90e62012-08-06 15:07:02 -070024#
Alex Deymo486467e2017-12-19 19:04:07 +010025## Makefile for building libcurl.a 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)
Lucas Eckels9bd90e62012-08-06 15:07:02 -070028##
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070029## Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
30## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
Lucas Eckels9bd90e62012-08-06 15:07:02 -070031##
32## Hint: you can also set environment vars to control the build, f.e.:
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070033## set ZLIB_PATH=c:/zlib-1.2.8
Lucas Eckels9bd90e62012-08-06 15:07:02 -070034## set ZLIB=1
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070035#
36###########################################################################
Lucas Eckels9bd90e62012-08-06 15:07:02 -070037
38# Edit the path below to point to the base of your Zlib sources.
39ifndef ZLIB_PATH
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070040ZLIB_PATH = ../../zlib-1.2.8
Lucas Eckels9bd90e62012-08-06 15:07:02 -070041endif
Alex Deymo486467e2017-12-19 19:04:07 +010042# Edit the path below to point to the base of your Brotli sources.
43ifndef BROTLI_PATH
44BROTLI_PATH = ../../brotli-1.0.1
45endif
Lucas Eckels9bd90e62012-08-06 15:07:02 -070046# Edit the path below to point to the base of your OpenSSL package.
47ifndef OPENSSL_PATH
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070048OPENSSL_PATH = ../../openssl-1.0.2a
Lucas Eckels9bd90e62012-08-06 15:07:02 -070049endif
50# Edit the path below to point to the base of your LibSSH2 package.
51ifndef LIBSSH2_PATH
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070052LIBSSH2_PATH = ../../libssh2-1.5.0
Lucas Eckels9bd90e62012-08-06 15:07:02 -070053endif
54# Edit the path below to point to the base of your librtmp package.
55ifndef LIBRTMP_PATH
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070056LIBRTMP_PATH = ../../librtmp-2.4
57endif
Alex Deymo486467e2017-12-19 19:04:07 +010058# Edit the path below to point to the base of your libidn2 package.
59ifndef LIBIDN2_PATH
60LIBIDN2_PATH = ../../libidn2-2.0.3
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070061endif
62# Edit the path below to point to the base of your MS IDN package.
63# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
64# https://www.microsoft.com/en-us/download/details.aspx?id=734
65ifndef WINIDN_PATH
66WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
Lucas Eckels9bd90e62012-08-06 15:07:02 -070067endif
68# Edit the path below to point to the base of your Novell LDAP NDK.
69ifndef LDAP_SDK
70LDAP_SDK = c:/novell/ndk/cldapsdk/win32
71endif
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070072# Edit the path below to point to the base of your nghttp2 package.
73ifndef NGHTTP2_PATH
74NGHTTP2_PATH = ../../nghttp2-1.0.0
75endif
76
77PROOT = ..
Lucas Eckels9bd90e62012-08-06 15:07:02 -070078
79# Edit the path below to point to the base of your c-ares package.
80ifndef LIBCARES_PATH
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070081LIBCARES_PATH = $(PROOT)/ares
Lucas Eckels9bd90e62012-08-06 15:07:02 -070082endif
83
Alex Deymo486467e2017-12-19 19:04:07 +010084ifeq ($(CURL_CC),)
85CURL_CC := $(CROSSPREFIX)gcc
86endif
87ifeq ($(CURL_AR),)
88CURL_AR := $(CROSSPREFIX)ar
89endif
90ifeq ($(CURL_RANLIB),)
91CURL_RANLIB := $(CROSSPREFIX)ranlib
92endif
93
94CC = $(CURL_CC)
Elliott Hughes82be86d2017-09-20 17:00:17 -070095CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070096CFLAGS += -fno-strict-aliasing
Lucas Eckels9bd90e62012-08-06 15:07:02 -070097# comment LDFLAGS below to keep debug info
Alex Deymod15eaac2016-06-28 14:49:26 -070098LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_DLL) -s
Alex Deymo486467e2017-12-19 19:04:07 +010099AR = $(CURL_AR)
100RANLIB = $(CURL_RANLIB)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700101RC = $(CROSSPREFIX)windres
102RCFLAGS = --include-dir=$(PROOT)/include -DDEBUGBUILD=0 -O COFF
103STRIP = $(CROSSPREFIX)strip -g
104
105# Set environment var ARCH to your architecture to override autodetection.
106ifndef ARCH
107ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
108ARCH = w64
109else
110ARCH = w32
111endif
112endif
113
114ifeq ($(ARCH),w64)
115CFLAGS += -m64 -D_AMD64_
116LDFLAGS += -m64
117RCFLAGS += -F pe-x86-64
118else
119CFLAGS += -m32
120LDFLAGS += -m32
121RCFLAGS += -F pe-i386
122endif
123
124# Platform-dependent helper tool macros
125ifeq ($(findstring /sh,$(SHELL)),/sh)
126DEL = rm -f $1
127RMDIR = rm -fr $1
128MKDIR = mkdir -p $1
129COPY = -cp -afv $1 $2
130#COPYR = -cp -afr $1/* $2
131COPYR = -rsync -aC $1/* $2
132TOUCH = touch $1
133CAT = cat
134ECHONL = echo ""
135DL = '
136else
137ifeq "$(OS)" "Windows_NT"
138DEL = -del 2>NUL /q /f $(subst /,\,$1)
139RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
140else
141DEL = -del 2>NUL $(subst /,\,$1)
142RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
143endif
144MKDIR = -md 2>NUL $(subst /,\,$1)
145COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
146COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
147TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
148CAT = type
149ECHONL = $(ComSpec) /c echo.
150endif
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700151
152########################################################
153## Nothing more to do below this line!
154
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700155ifeq ($(findstring -dyn,$(CFG)),-dyn)
156DYN = 1
157endif
158ifeq ($(findstring -ares,$(CFG)),-ares)
159ARES = 1
160endif
161ifeq ($(findstring -sync,$(CFG)),-sync)
162SYNC = 1
163endif
164ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
165RTMP = 1
166SSL = 1
167ZLIB = 1
168endif
169ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
170SSH2 = 1
171SSL = 1
172ZLIB = 1
173endif
174ifeq ($(findstring -ssl,$(CFG)),-ssl)
175SSL = 1
176endif
177ifeq ($(findstring -srp,$(CFG)),-srp)
178SRP = 1
179endif
180ifeq ($(findstring -zlib,$(CFG)),-zlib)
181ZLIB = 1
182endif
Alex Deymo486467e2017-12-19 19:04:07 +0100183ifeq ($(findstring -brotli,$(CFG)),-brotli)
184BROTLI = 1
185endif
186ifeq ($(findstring -idn2,$(CFG)),-idn2)
187IDN2 = 1
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700188endif
189ifeq ($(findstring -winidn,$(CFG)),-winidn)
190WINIDN = 1
191endif
192ifeq ($(findstring -sspi,$(CFG)),-sspi)
193SSPI = 1
194endif
195ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
196LDAPS = 1
197endif
198ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
199IPV6 = 1
200endif
201ifeq ($(findstring -winssl,$(CFG)),-winssl)
202WINSSL = 1
203SSPI = 1
204endif
205ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
206NGHTTP2 = 1
207endif
208
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700209INCLUDES = -I. -I../include
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700210CFLAGS += -DBUILDING_LIBCURL
Alex Deymo486467e2017-12-19 19:04:07 +0100211ifdef SSL
212 ifdef WINSSL
213 CFLAGS += -DCURL_WITH_MULTI_SSL
214 endif
215endif
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700216
217ifdef SYNC
218 CFLAGS += -DUSE_SYNC_DNS
219else
220 ifdef ARES
221 INCLUDES += -I"$(LIBCARES_PATH)"
222 CFLAGS += -DUSE_ARES -DCARES_STATICLIB
223 DLL_LIBS += -L"$(LIBCARES_PATH)" -lcares
224 libcurl_dll_DEPENDENCIES = $(LIBCARES_PATH)/libcares.a
225 endif
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700226endif
227ifdef RTMP
228 INCLUDES += -I"$(LIBRTMP_PATH)"
229 CFLAGS += -DUSE_LIBRTMP
230 DLL_LIBS += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
231endif
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700232ifdef NGHTTP2
233 INCLUDES += -I"$(NGHTTP2_PATH)/include"
234 CFLAGS += -DUSE_NGHTTP2
235 DLL_LIBS += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
236endif
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700237ifdef SSH2
238 INCLUDES += -I"$(LIBSSH2_PATH)/include" -I"$(LIBSSH2_PATH)/win32"
239 CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700240 DLL_LIBS += -L"$(LIBSSH2_PATH)/win32" -lssh2
Alex Deymod15eaac2016-06-28 14:49:26 -0700241 ifdef WINSSL
242 ifndef DYN
243 DLL_LIBS += -lbcrypt -lcrypt32
244 endif
245 endif
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700246endif
247ifdef SSL
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700248 ifndef OPENSSL_INCLUDE
249 ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
250 OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
251 endif
252 ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
253 OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
254 endif
255 endif
256 ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
257 $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
258 endif
259 ifndef OPENSSL_LIBPATH
260 ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
261 OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
262 OPENSSL_LIBS = -leay32 -lssl32
263 endif
264 ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
265 OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
266 OPENSSL_LIBS = -lcrypto -lssl
267 endif
268 endif
269 ifndef DYN
270 OPENSSL_LIBS += -lgdi32 -lcrypt32
271 endif
272 INCLUDES += -I"$(OPENSSL_INCLUDE)"
273 CFLAGS += -DUSE_OPENSSL -DHAVE_OPENSSL_ENGINE_H -DHAVE_OPENSSL_PKCS12_H \
Elliott Hughes82be86d2017-09-20 17:00:17 -0700274 -DHAVE_ENGINE_LOAD_BUILTIN_ENGINES -DOPENSSL_NO_KRB5
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700275 DLL_LIBS += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
276 ifdef SRP
277 ifeq "$(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h)" "$(OPENSSL_INCLUDE)/openssl/srp.h"
278 CFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP
279 endif
280 endif
Alex Deymoe3149cc2016-10-05 11:18:42 -0700281endif
Alex Deymo486467e2017-12-19 19:04:07 +0100282ifdef WINSSL
283 CFLAGS += -DUSE_SCHANNEL
284 DLL_LIBS += -lcrypt32
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700285endif
286ifdef ZLIB
287 INCLUDES += -I"$(ZLIB_PATH)"
288 CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700289 DLL_LIBS += -L"$(ZLIB_PATH)" -lz
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700290endif
Alex Deymo486467e2017-12-19 19:04:07 +0100291ifdef BROTLI
292 INCLUDES += -I"$(BROTLI_PATH)/include"
293 CFLAGS += -DHAVE_BROTLI
294 DLL_LIBS += -L"$(BROTLI_PATH)/lib"
295 ifdef BROTLI_LIBS
296 DLL_LIBS += $(BROTLI_LIBS)
297 else
298 DLL_LIBS += -lbrotlidec
299 endif
300endif
301ifdef IDN2
302 INCLUDES += -I"$(LIBIDN2_PATH)/include"
303 CFLAGS += -DUSE_LIBIDN2
304 DLL_LIBS += -L"$(LIBIDN2_PATH)/lib" -lidn2
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700305else
306ifdef WINIDN
307 CFLAGS += -DUSE_WIN32_IDN
308 CFLAGS += -DWANT_IDN_PROTOTYPES
309 DLL_LIBS += -L"$(WINIDN_PATH)" -lnormaliz
310endif
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700311endif
312ifdef SSPI
313 CFLAGS += -DUSE_WINDOWS_SSPI
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700314endif
315ifdef SPNEGO
316 CFLAGS += -DHAVE_SPNEGO
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700317endif
318ifdef IPV6
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700319 CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700320endif
321ifdef LDAPS
322 CFLAGS += -DHAVE_LDAP_SSL
323endif
324ifdef USE_LDAP_NOVELL
325 INCLUDES += -I"$(LDAP_SDK)/inc"
326 CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
327 DLL_LIBS += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
328endif
329ifdef USE_LDAP_OPENLDAP
330 INCLUDES += -I"$(LDAP_SDK)/include"
331 CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
332 DLL_LIBS += -L"$(LDAP_SDK)/lib" -lldap -llber
333endif
334ifndef USE_LDAP_NOVELL
335ifndef USE_LDAP_OPENLDAP
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700336 DLL_LIBS += -lwldap32
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700337endif
338endif
339DLL_LIBS += -lws2_32
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700340
341# Makefile.inc provides the CSOURCES and HHEADERS defines
342include Makefile.inc
343
Alex Deymo486467e2017-12-19 19:04:07 +0100344ifeq ($(CURL_DLL_A_SUFFIX),)
345CURL_DLL_A_SUFFIX := dll
346endif
347
348libcurl_dll_LIBRARY = libcurl$(CURL_DLL_SUFFIX).dll
349libcurl_dll_a_LIBRARY = libcurl$(CURL_DLL_A_SUFFIX).a
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700350libcurl_a_LIBRARY = libcurl.a
351
352libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES)))
353libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
354
355RESOURCE = libcurl.res
356
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700357
358all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY)
359
360$(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700361 @$(call DEL, $@)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700362 $(AR) cru $@ $(libcurl_a_OBJECTS)
363 $(RANLIB) $@
364 $(STRIP) $@
365
366# remove the last line above to keep debug info
367
368$(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(libcurl_dll_DEPENDENCIES)
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700369 @$(call DEL, $@)
370 $(CC) $(LDFLAGS) -shared -o $@ \
371 -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY) \
372 $(libcurl_a_OBJECTS) $(RESOURCE) $(DLL_LIBS)
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700373
Elliott Hughes82be86d2017-09-20 17:00:17 -0700374%.o: %.c
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700375 $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700376
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700377%.res: %.rc
378 $(RC) $(RCFLAGS) -i $< -o $@
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700379
380clean:
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700381 @$(call DEL, $(libcurl_a_OBJECTS) $(RESOURCE))
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700382
383distclean vclean: clean
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -0700384 @$(call DEL, $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY))
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700385
Lucas Eckels9bd90e62012-08-06 15:07:02 -0700386$(LIBCARES_PATH)/libcares.a:
387 $(MAKE) -C $(LIBCARES_PATH) -f Makefile.m32