• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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), 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 libgsasl package.
63ifndef LIBGSASL_PATH
64LIBGSASL_PATH = ../../libgsasl-1.10.0
65endif
66# Edit the path below to point to the base of your libidn2 package.
67ifndef LIBIDN2_PATH
68LIBIDN2_PATH = ../../libidn2-2.0.3
69endif
70# Edit the path below to point to the base of your MS IDN package.
71# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
72# https://www.microsoft.com/en-us/download/details.aspx?id=734
73ifndef WINIDN_PATH
74WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
75endif
76# Edit the path below to point to the base of your Novell LDAP NDK.
77ifndef LDAP_SDK
78LDAP_SDK = c:/novell/ndk/cldapsdk/win32
79endif
80# Edit the path below to point to the base of your nghttp2 package.
81ifndef NGHTTP2_PATH
82NGHTTP2_PATH = ../../nghttp2-1.0.0
83endif
84# Edit the path below to point to the base of your nghttp3 package.
85ifndef NGHTTP3_PATH
86NGHTTP3_PATH = ../../nghttp3-1.0.0
87endif
88# Edit the path below to point to the base of your ngtcp2 package.
89ifndef NGTCP2_PATH
90NGTCP2_PATH = ../../ngtcp2-1.0.0
91endif
92
93PROOT = ..
94
95# Edit the path below to point to the base of your c-ares package.
96ifndef LIBCARES_PATH
97LIBCARES_PATH = $(PROOT)/ares
98endif
99
100ifeq ($(CURL_CC),)
101CURL_CC := $(CROSSPREFIX)gcc
102endif
103ifeq ($(CURL_AR),)
104CURL_AR := $(CROSSPREFIX)ar
105endif
106ifeq ($(CURL_RANLIB),)
107CURL_RANLIB := $(CROSSPREFIX)ranlib
108endif
109
110CC = $(CURL_CC)
111CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W
112CFLAGS += -fno-strict-aliasing
113# comment LDFLAGS below to keep debug info
114LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_DLL) -s
115AR = $(CURL_AR)
116RANLIB = $(CURL_RANLIB)
117RC = $(CROSSPREFIX)windres
118RCFLAGS = --include-dir=$(PROOT)/include -DDEBUGBUILD=0 -O coff
119STRIP   = $(CROSSPREFIX)strip -g
120
121# Set environment var ARCH to your architecture to override autodetection.
122ifndef ARCH
123ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
124ARCH = w64
125else
126ARCH = w32
127endif
128endif
129
130ifeq ($(ARCH),w64)
131CFLAGS  += -m64 -D_AMD64_
132LDFLAGS += -m64
133RCFLAGS += -F pe-x86-64
134else
135CFLAGS  += -m32
136LDFLAGS += -m32
137RCFLAGS += -F pe-i386
138endif
139
140# Platform-dependent helper tool macros
141ifeq ($(findstring /sh,$(SHELL)),/sh)
142DEL     = rm -f $1
143RMDIR   = rm -fr $1
144MKDIR   = mkdir -p $1
145COPY    = -cp -afv $1 $2
146#COPYR  = -cp -afr $1/* $2
147COPYR   = -rsync -aC $1/* $2
148TOUCH   = touch $1
149CAT     = cat
150ECHONL  = echo ""
151DL = '
152else
153ifeq "$(OS)" "Windows_NT"
154DEL     = -del 2>NUL /q /f $(subst /,\,$1)
155RMDIR   = -rd 2>NUL /q /s $(subst /,\,$1)
156else
157DEL     = -del 2>NUL $(subst /,\,$1)
158RMDIR   = -deltree 2>NUL /y $(subst /,\,$1)
159endif
160MKDIR   = -md 2>NUL $(subst /,\,$1)
161COPY    = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
162COPYR   = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
163TOUCH   = copy 2>&1>NUL /b $(subst /,\,$1) +,,
164CAT     = type
165ECHONL  = $(ComSpec) /c echo.
166endif
167
168########################################################
169## Nothing more to do below this line!
170
171ifeq ($(findstring -dyn,$(CFG)),-dyn)
172DYN = 1
173endif
174ifeq ($(findstring -ares,$(CFG)),-ares)
175ARES = 1
176endif
177ifeq ($(findstring -sync,$(CFG)),-sync)
178SYNC = 1
179endif
180ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
181RTMP = 1
182SSL = 1
183ZLIB = 1
184endif
185ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
186SSH2 = 1
187SSL = 1
188ZLIB = 1
189endif
190ifeq ($(findstring -ssl,$(CFG)),-ssl)
191SSL = 1
192endif
193ifeq ($(findstring -srp,$(CFG)),-srp)
194SRP = 1
195endif
196ifeq ($(findstring -zlib,$(CFG)),-zlib)
197ZLIB = 1
198endif
199ifeq ($(findstring -zstd,$(CFG)),-zstd)
200ZSTD = 1
201endif
202ifeq ($(findstring -brotli,$(CFG)),-brotli)
203BROTLI = 1
204endif
205ifeq ($(findstring -gsasl,$(CFG)),-gsasl)
206GSASL = 1
207endif
208ifeq ($(findstring -idn2,$(CFG)),-idn2)
209IDN2 = 1
210endif
211ifeq ($(findstring -winidn,$(CFG)),-winidn)
212WINIDN = 1
213endif
214ifeq ($(findstring -sspi,$(CFG)),-sspi)
215SSPI = 1
216endif
217ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
218LDAPS = 1
219endif
220ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
221IPV6 = 1
222endif
223ifeq ($(findstring -winssl,$(CFG)),-winssl)
224WINSSL = 1
225SSPI = 1
226endif
227ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
228NGHTTP2 = 1
229endif
230ifeq ($(findstring -nghttp3,$(CFG)),-nghttp3)
231NGHTTP3 = 1
232endif
233ifeq ($(findstring -ngtcp2,$(CFG)),-ngtcp2)
234NGTCP2 = 1
235endif
236ifeq ($(findstring -unicode,$(CFG)),-unicode)
237UNICODE = 1
238endif
239
240INCLUDES = -I. -I../include
241CFLAGS += -DBUILDING_LIBCURL
242ifdef SSL
243  ifdef WINSSL
244    CFLAGS += -DCURL_WITH_MULTI_SSL
245  endif
246endif
247ifdef UNICODE
248  CFLAGS += -DUNICODE -D_UNICODE
249endif
250
251ifdef SYNC
252  CFLAGS += -DUSE_SYNC_DNS
253else
254  ifdef ARES
255    INCLUDES += -I"$(LIBCARES_PATH)"
256    CFLAGS += -DUSE_ARES -DCARES_STATICLIB
257    DLL_LIBS += -L"$(LIBCARES_PATH)" -lcares
258    libcurl_dll_DEPENDENCIES = $(LIBCARES_PATH)/libcares.a
259  endif
260endif
261ifdef RTMP
262  INCLUDES += -I"$(LIBRTMP_PATH)"
263  CFLAGS += -DUSE_LIBRTMP
264  DLL_LIBS += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
265endif
266ifdef NGHTTP2
267  INCLUDES += -I"$(NGHTTP2_PATH)/include"
268  CFLAGS += -DUSE_NGHTTP2
269  DLL_LIBS += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
270endif
271ifdef SSH2
272  INCLUDES += -I"$(LIBSSH2_PATH)/include" -I"$(LIBSSH2_PATH)/win32"
273  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
274  DLL_LIBS += -L"$(LIBSSH2_PATH)/win32" -lssh2
275  ifdef WINSSL
276    ifndef DYN
277      DLL_LIBS += -lbcrypt -lcrypt32
278    endif
279  endif
280endif
281ifdef SSL
282  ifdef NGHTTP3
283    INCLUDES += -I"$(NGHTTP3_PATH)/include"
284    CFLAGS += -DUSE_NGHTTP3
285    DLL_LIBS += -L"$(NGHTTP3_PATH)/lib" -lnghttp3
286    ifdef NGTCP2
287      INCLUDES += -I"$(NGTCP2_PATH)/include"
288      CFLAGS += -DUSE_NGTCP2
289      DLL_LIBS += -L"$(NGTCP2_PATH)/lib" -lngtcp2 -lngtcp2_crypto_openssl
290    endif
291  endif
292
293  ifndef OPENSSL_INCLUDE
294    ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
295      OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
296    endif
297    ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
298      OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
299    endif
300  endif
301  ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
302  $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
303  endif
304  ifndef OPENSSL_LIBPATH
305    ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
306      OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
307      OPENSSL_LIBS = -leay32 -lssl32
308    endif
309    ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
310      OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
311      OPENSSL_LIBS = -lcrypto -lssl
312    endif
313  endif
314  ifndef DYN
315    OPENSSL_LIBS += -lgdi32 -lcrypt32
316  endif
317  INCLUDES += -I"$(OPENSSL_INCLUDE)"
318  CFLAGS += -DUSE_OPENSSL -DHAVE_OPENSSL_PKCS12_H \
319            -DOPENSSL_NO_KRB5
320  DLL_LIBS += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
321  ifdef SRP
322    ifeq "$(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h)" "$(OPENSSL_INCLUDE)/openssl/srp.h"
323      CFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP
324    endif
325  endif
326endif
327ifdef WINSSL
328  CFLAGS += -DUSE_SCHANNEL
329  DLL_LIBS += -lcrypt32
330endif
331ifdef ZLIB
332  INCLUDES += -I"$(ZLIB_PATH)"
333  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
334  DLL_LIBS += -L"$(ZLIB_PATH)" -lz
335endif
336ifdef ZSTD
337  INCLUDES += -I"$(ZSTD_PATH)/include"
338  CFLAGS += -DHAVE_ZSTD
339  DLL_LIBS += -L"$(ZSTD_PATH)/lib"
340  ifdef ZSTD_LIBS
341    DLL_LIBS += $(ZSTD_LIBS)
342  else
343    DLL_LIBS += -lzstd
344  endif
345endif
346ifdef BROTLI
347  INCLUDES += -I"$(BROTLI_PATH)/include"
348  CFLAGS += -DHAVE_BROTLI
349  DLL_LIBS += -L"$(BROTLI_PATH)/lib"
350  ifdef BROTLI_LIBS
351    DLL_LIBS += $(BROTLI_LIBS)
352  else
353    DLL_LIBS += -lbrotlidec
354  endif
355endif
356ifdef GSASL
357  INCLUDES += -I"$(LIBGSASL_PATH)/include"
358  CFLAGS += -DUSE_GSASL
359  DLL_LIBS += -L"$(LIBGSASL_PATH)/lib" -lgsasl
360endif
361ifdef IDN2
362  INCLUDES += -I"$(LIBIDN2_PATH)/include"
363  CFLAGS += -DUSE_LIBIDN2
364  DLL_LIBS += -L"$(LIBIDN2_PATH)/lib" -lidn2
365else
366ifdef WINIDN
367  CFLAGS += -DUSE_WIN32_IDN
368  CFLAGS += -DWANT_IDN_PROTOTYPES
369  DLL_LIBS += -L"$(WINIDN_PATH)" -lnormaliz
370endif
371endif
372ifdef SSPI
373  CFLAGS += -DUSE_WINDOWS_SSPI
374endif
375ifdef SPNEGO
376  CFLAGS += -DHAVE_SPNEGO
377endif
378ifdef IPV6
379  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
380endif
381ifdef LDAPS
382  CFLAGS += -DHAVE_LDAP_SSL
383endif
384ifdef USE_LDAP_NOVELL
385  INCLUDES += -I"$(LDAP_SDK)/inc"
386  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
387  DLL_LIBS += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
388endif
389ifdef USE_LDAP_OPENLDAP
390  INCLUDES += -I"$(LDAP_SDK)/include"
391  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
392  DLL_LIBS += -L"$(LDAP_SDK)/lib" -lldap -llber
393endif
394ifndef USE_LDAP_NOVELL
395ifndef USE_LDAP_OPENLDAP
396  DLL_LIBS += -lwldap32
397endif
398endif
399DLL_LIBS += -lws2_32
400
401# Makefile.inc provides the CSOURCES and HHEADERS defines
402include Makefile.inc
403
404ifeq ($(CURL_DLL_A_SUFFIX),)
405CURL_DLL_A_SUFFIX := dll
406endif
407
408libcurl_dll_LIBRARY = libcurl$(CURL_DLL_SUFFIX).dll
409libcurl_dll_a_LIBRARY = libcurl$(CURL_DLL_A_SUFFIX).a
410libcurl_a_LIBRARY = libcurl.a
411
412libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES)))
413libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
414
415RESOURCE = libcurl.res
416
417
418all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY)
419
420$(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
421	@$(call DEL, $@)
422	$(AR) cru $@ $(libcurl_a_OBJECTS)
423	$(RANLIB) $@
424	$(STRIP) $@
425
426# remove the last line above to keep debug info
427
428$(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(libcurl_dll_DEPENDENCIES)
429	@$(call DEL, $@)
430	$(CC) $(LDFLAGS) -shared -o $@ \
431	  -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY) \
432	  $(libcurl_a_OBJECTS) $(RESOURCE) $(DLL_LIBS)
433
434%.o: %.c
435	$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
436
437%.res: %.rc
438	$(RC) $(RCFLAGS) -i $< -o $@
439
440clean:
441	@$(call DEL, $(libcurl_a_OBJECTS) $(RESOURCE))
442
443distclean vclean: clean
444	@$(call DEL, $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY))
445
446$(LIBCARES_PATH)/libcares.a:
447	$(MAKE) -C $(LIBCARES_PATH) -f Makefile.m32
448