1 ###########################################################################
3 ## Makefile for building libcurl.a with MingW (GCC-3.2 or later)
4 ## and optionally OpenSSL (0.9.8), libssh2 (1.3), zlib (1.2.5), librtmp (2.3)
6 ## Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
7 ## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
9 ## Hint: you can also set environment vars to control the build, f.e.:
10 ## set ZLIB_PATH=c:/zlib-1.2.8
13 ###########################################################################
15 # Edit the path below to point to the base of your Zlib sources.
17 ZLIB_PATH = ../../zlib-1.2.8
19 # Edit the path below to point to the base of your OpenSSL package.
21 OPENSSL_PATH = ../../openssl-0.9.8zc
23 # Edit the path below to point to the base of your LibSSH2 package.
25 LIBSSH2_PATH = ../../libssh2-1.4.3
27 # Edit the path below to point to the base of your librtmp package.
29 LIBRTMP_PATH = ../../librtmp-2.3
31 # Edit the path below to point to the base of your libidn package.
33 LIBIDN_PATH = ../../libidn-1.18
35 # Edit the path below to point to the base of your MS IDN package.
36 # Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
37 # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ad6158d7-ddba-416a-9109-07607425a815
39 WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
41 # Edit the path below to point to the base of your Novell LDAP NDK.
43 LDAP_SDK = c:/novell/ndk/cldapsdk/win32
45 # Edit the path below to point to the base of your nghttp2 package.
47 NGHTTP2_PATH = ../../nghttp2-0.6.7
52 # Edit the path below to point to the base of your c-ares package.
54 LIBCARES_PATH = $(PROOT)/ares
57 CC = $(CROSSPREFIX)gcc
58 CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall
59 CFLAGS += -fno-strict-aliasing
60 # comment LDFLAGS below to keep debug info
63 RANLIB = $(CROSSPREFIX)ranlib
64 RC = $(CROSSPREFIX)windres
65 RCFLAGS = --include-dir=$(PROOT)/include -DDEBUGBUILD=0 -O COFF
66 STRIP = $(CROSSPREFIX)strip -g
68 # Set environment var ARCH to your architecture to override autodetection.
70 ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
78 CFLAGS += -m64 -D_AMD64_
79 RCFLAGS += -F pe-x86-64
85 # Platform-dependent helper tool macros
86 ifeq ($(findstring /sh,$(SHELL)),/sh)
91 #COPYR = -cp -afr $1/* $2
92 COPYR = -rsync -aC $1/* $2
98 ifeq "$(OS)" "Windows_NT"
99 DEL = -del 2>NUL /q /f $(subst /,\,$1)
100 RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
102 DEL = -del 2>NUL $(subst /,\,$1)
103 RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
105 MKDIR = -md 2>NUL $(subst /,\,$1)
106 COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
107 COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
108 TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
110 ECHONL = $(ComSpec) /c echo.
113 ########################################################
114 ## Nothing more to do below this line!
116 ifeq ($(findstring -dyn,$(CFG)),-dyn)
119 ifeq ($(findstring -ares,$(CFG)),-ares)
122 ifeq ($(findstring -sync,$(CFG)),-sync)
125 ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
130 ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
135 ifeq ($(findstring -ssl,$(CFG)),-ssl)
138 ifeq ($(findstring -srp,$(CFG)),-srp)
141 ifeq ($(findstring -zlib,$(CFG)),-zlib)
144 ifeq ($(findstring -idn,$(CFG)),-idn)
147 ifeq ($(findstring -winidn,$(CFG)),-winidn)
150 ifeq ($(findstring -sspi,$(CFG)),-sspi)
153 ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
156 ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
159 ifeq ($(findstring -winssl,$(CFG)),-winssl)
163 ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
167 INCLUDES = -I. -I../include
168 CFLAGS += -DBUILDING_LIBCURL
171 CFLAGS += -DUSE_SYNC_DNS
174 INCLUDES += -I"$(LIBCARES_PATH)"
175 CFLAGS += -DUSE_ARES -DCARES_STATICLIB
176 DLL_LIBS += -L"$(LIBCARES_PATH)" -lcares
177 libcurl_dll_DEPENDENCIES = $(LIBCARES_PATH)/libcares.a
181 INCLUDES += -I"$(LIBRTMP_PATH)"
182 CFLAGS += -DUSE_LIBRTMP
183 DLL_LIBS += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
186 INCLUDES += -I"$(NGHTTP2_PATH)/include"
187 CFLAGS += -DUSE_NGHTTP2
188 DLL_LIBS += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
191 INCLUDES += -I"$(LIBSSH2_PATH)/include" -I"$(LIBSSH2_PATH)/win32"
192 CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
193 DLL_LIBS += -L"$(LIBSSH2_PATH)/win32" -lssh2
196 ifndef OPENSSL_INCLUDE
197 ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
198 OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
200 ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
201 OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
204 ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
205 $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
207 ifndef OPENSSL_LIBPATH
208 ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
209 OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
210 OPENSSL_LIBS = -leay32 -lssl32
212 ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
213 OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
214 OPENSSL_LIBS = -lcrypto -lssl
217 INCLUDES += -I"$(OPENSSL_INCLUDE)"
218 CFLAGS += -DUSE_SSLEAY -DUSE_OPENSSL -DHAVE_OPENSSL_ENGINE_H -DHAVE_OPENSSL_PKCS12_H \
219 -DHAVE_ENGINE_LOAD_BUILTIN_ENGINES -DOPENSSL_NO_KRB5 \
220 -DCURL_WANTS_CA_BUNDLE_ENV
221 DLL_LIBS += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
223 ifeq "$(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h)" "$(OPENSSL_INCLUDE)/openssl/srp.h"
224 CFLAGS += -DHAVE_SSLEAY_SRP -DUSE_TLS_SRP
229 INCLUDES += -I"$(ZLIB_PATH)"
230 CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
231 DLL_LIBS += -L"$(ZLIB_PATH)" -lz
234 INCLUDES += -I"$(LIBIDN_PATH)/include"
235 CFLAGS += -DUSE_LIBIDN
236 DLL_LIBS += -L"$(LIBIDN_PATH)/lib" -lidn
239 CFLAGS += -DUSE_WIN32_IDN
240 CFLAGS += -DWANT_IDN_PROTOTYPES
241 DLL_LIBS += -L"$(WINIDN_PATH)" -lnormaliz
245 CFLAGS += -DUSE_WINDOWS_SSPI
247 CFLAGS += -DUSE_SCHANNEL
251 CFLAGS += -DHAVE_SPNEGO
254 CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
257 CFLAGS += -DHAVE_LDAP_SSL
259 ifdef USE_LDAP_NOVELL
260 INCLUDES += -I"$(LDAP_SDK)/inc"
261 CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
262 DLL_LIBS += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
264 ifdef USE_LDAP_OPENLDAP
265 INCLUDES += -I"$(LDAP_SDK)/include"
266 CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
267 DLL_LIBS += -L"$(LDAP_SDK)/lib" -lldap -llber
269 ifndef USE_LDAP_NOVELL
270 ifndef USE_LDAP_OPENLDAP
271 DLL_LIBS += -lwldap32
276 # Makefile.inc provides the CSOURCES and HHEADERS defines
279 libcurl_dll_LIBRARY = libcurl.dll
280 libcurl_dll_a_LIBRARY = libcurldll.a
281 libcurl_a_LIBRARY = libcurl.a
283 libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES)))
284 libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
286 RESOURCE = libcurl.res
289 all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY)
291 $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
293 $(AR) cru $@ $(libcurl_a_OBJECTS)
297 # remove the last line above to keep debug info
299 $(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(libcurl_dll_DEPENDENCIES)
301 $(CC) $(LDFLAGS) -shared -o $@ \
302 -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY) \
303 $(libcurl_a_OBJECTS) $(RESOURCE) $(DLL_LIBS)
305 %.o: %.c $(PROOT)/include/curl/curlbuild.h
306 $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
309 $(RC) $(RCFLAGS) -i $< -o $@
312 ifeq "$(wildcard $(PROOT)/include/curl/curlbuild.h.dist)" "$(PROOT)/include/curl/curlbuild.h.dist"
313 @$(call DEL, $(PROOT)/include/curl/curlbuild.h)
315 @$(call DEL, $(libcurl_a_OBJECTS) $(RESOURCE))
317 distclean vclean: clean
318 @$(call DEL, $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY))
320 $(PROOT)/include/curl/curlbuild.h:
322 @$(call COPY, $@.dist, $@)
324 $(LIBCARES_PATH)/libcares.a:
325 $(MAKE) -C $(LIBCARES_PATH) -f Makefile.m32