• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1###########################################################################
2#
3## Makefile for building libcurl.a with MingW (GCC-3.2 or later)
4## and optionally OpenSSL (1.0.2a), libssh2 (1.5), zlib (1.2.8), librtmp (2.4)
5##
6## Usage:   mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
7## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
8##
9## Hint: you can also set environment vars to control the build, f.e.:
10## set ZLIB_PATH=c:/zlib-1.2.8
11## set ZLIB=1
12#
13###########################################################################
14
15# Edit the path below to point to the base of your Zlib sources.
16ifndef ZLIB_PATH
17ZLIB_PATH = ../../zlib-1.2.8
18endif
19# Edit the path below to point to the base of your OpenSSL package.
20ifndef OPENSSL_PATH
21OPENSSL_PATH = ../../openssl-1.0.2a
22endif
23# Edit the path below to point to the base of your LibSSH2 package.
24ifndef LIBSSH2_PATH
25LIBSSH2_PATH = ../../libssh2-1.5.0
26endif
27# Edit the path below to point to the base of your librtmp package.
28ifndef LIBRTMP_PATH
29LIBRTMP_PATH = ../../librtmp-2.4
30endif
31# Edit the path below to point to the base of your libidn package.
32ifndef LIBIDN_PATH
33LIBIDN_PATH = ../../libidn-1.30
34endif
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# https://www.microsoft.com/en-us/download/details.aspx?id=734
38ifndef WINIDN_PATH
39WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
40endif
41# Edit the path below to point to the base of your Novell LDAP NDK.
42ifndef LDAP_SDK
43LDAP_SDK = c:/novell/ndk/cldapsdk/win32
44endif
45# Edit the path below to point to the base of your nghttp2 package.
46ifndef NGHTTP2_PATH
47NGHTTP2_PATH = ../../nghttp2-1.0.0
48endif
49
50PROOT = ..
51
52# Edit the path below to point to the base of your c-ares package.
53ifndef LIBCARES_PATH
54LIBCARES_PATH = $(PROOT)/ares
55endif
56
57CC	= $(CROSSPREFIX)gcc
58CFLAGS	= $(CURL_CFLAG_EXTRAS) -g -O2 -Wall
59CFLAGS	+= -fno-strict-aliasing
60# comment LDFLAGS below to keep debug info
61LDFLAGS	= -s
62AR	= $(CROSSPREFIX)ar
63RANLIB	= $(CROSSPREFIX)ranlib
64RC	= $(CROSSPREFIX)windres
65RCFLAGS	= --include-dir=$(PROOT)/include -DDEBUGBUILD=0 -O COFF
66STRIP	= $(CROSSPREFIX)strip -g
67
68# Set environment var ARCH to your architecture to override autodetection.
69ifndef ARCH
70ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
71ARCH	= w64
72else
73ARCH	= w32
74endif
75endif
76
77ifeq ($(ARCH),w64)
78CFLAGS  += -m64 -D_AMD64_
79LDFLAGS += -m64
80RCFLAGS += -F pe-x86-64
81else
82CFLAGS  += -m32
83LDFLAGS += -m32
84RCFLAGS += -F pe-i386
85endif
86
87# Platform-dependent helper tool macros
88ifeq ($(findstring /sh,$(SHELL)),/sh)
89DEL	= rm -f $1
90RMDIR	= rm -fr $1
91MKDIR	= mkdir -p $1
92COPY	= -cp -afv $1 $2
93#COPYR	= -cp -afr $1/* $2
94COPYR	= -rsync -aC $1/* $2
95TOUCH	= touch $1
96CAT	= cat
97ECHONL	= echo ""
98DL	= '
99else
100ifeq "$(OS)" "Windows_NT"
101DEL	= -del 2>NUL /q /f $(subst /,\,$1)
102RMDIR	= -rd 2>NUL /q /s $(subst /,\,$1)
103else
104DEL	= -del 2>NUL $(subst /,\,$1)
105RMDIR	= -deltree 2>NUL /y $(subst /,\,$1)
106endif
107MKDIR	= -md 2>NUL $(subst /,\,$1)
108COPY	= -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
109COPYR	= -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
110TOUCH	= copy 2>&1>NUL /b $(subst /,\,$1) +,,
111CAT	= type
112ECHONL	= $(ComSpec) /c echo.
113endif
114
115########################################################
116## Nothing more to do below this line!
117
118ifeq ($(findstring -dyn,$(CFG)),-dyn)
119DYN = 1
120endif
121ifeq ($(findstring -ares,$(CFG)),-ares)
122ARES = 1
123endif
124ifeq ($(findstring -sync,$(CFG)),-sync)
125SYNC = 1
126endif
127ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
128RTMP = 1
129SSL = 1
130ZLIB = 1
131endif
132ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
133SSH2 = 1
134SSL = 1
135ZLIB = 1
136endif
137ifeq ($(findstring -ssl,$(CFG)),-ssl)
138SSL = 1
139endif
140ifeq ($(findstring -srp,$(CFG)),-srp)
141SRP = 1
142endif
143ifeq ($(findstring -zlib,$(CFG)),-zlib)
144ZLIB = 1
145endif
146ifeq ($(findstring -idn,$(CFG)),-idn)
147IDN = 1
148endif
149ifeq ($(findstring -winidn,$(CFG)),-winidn)
150WINIDN = 1
151endif
152ifeq ($(findstring -sspi,$(CFG)),-sspi)
153SSPI = 1
154endif
155ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
156LDAPS = 1
157endif
158ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
159IPV6 = 1
160endif
161ifeq ($(findstring -winssl,$(CFG)),-winssl)
162WINSSL = 1
163SSPI = 1
164endif
165ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
166NGHTTP2 = 1
167endif
168
169INCLUDES = -I. -I../include
170CFLAGS += -DBUILDING_LIBCURL
171
172ifdef SYNC
173  CFLAGS += -DUSE_SYNC_DNS
174else
175  ifdef ARES
176    INCLUDES += -I"$(LIBCARES_PATH)"
177    CFLAGS += -DUSE_ARES -DCARES_STATICLIB
178    DLL_LIBS += -L"$(LIBCARES_PATH)" -lcares
179    libcurl_dll_DEPENDENCIES = $(LIBCARES_PATH)/libcares.a
180  endif
181endif
182ifdef RTMP
183  INCLUDES += -I"$(LIBRTMP_PATH)"
184  CFLAGS += -DUSE_LIBRTMP
185  DLL_LIBS += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
186endif
187ifdef NGHTTP2
188  INCLUDES += -I"$(NGHTTP2_PATH)/include"
189  CFLAGS += -DUSE_NGHTTP2
190  DLL_LIBS += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
191endif
192ifdef SSH2
193  INCLUDES += -I"$(LIBSSH2_PATH)/include" -I"$(LIBSSH2_PATH)/win32"
194  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
195  DLL_LIBS += -L"$(LIBSSH2_PATH)/win32" -lssh2
196endif
197ifdef SSL
198  ifndef OPENSSL_INCLUDE
199    ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
200      OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
201    endif
202    ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
203      OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
204    endif
205  endif
206  ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
207  $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
208  endif
209  ifndef OPENSSL_LIBPATH
210    ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
211      OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
212      OPENSSL_LIBS = -leay32 -lssl32
213    endif
214    ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
215      OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
216      OPENSSL_LIBS = -lcrypto -lssl
217    endif
218  endif
219  ifndef DYN
220    OPENSSL_LIBS += -lgdi32 -lcrypt32
221  endif
222  INCLUDES += -I"$(OPENSSL_INCLUDE)"
223  CFLAGS += -DUSE_OPENSSL -DHAVE_OPENSSL_ENGINE_H -DHAVE_OPENSSL_PKCS12_H \
224            -DHAVE_ENGINE_LOAD_BUILTIN_ENGINES -DOPENSSL_NO_KRB5 \
225            -DCURL_WANTS_CA_BUNDLE_ENV
226  DLL_LIBS += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
227  ifdef SRP
228    ifeq "$(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h)" "$(OPENSSL_INCLUDE)/openssl/srp.h"
229      CFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP
230    endif
231  endif
232endif
233ifdef ZLIB
234  INCLUDES += -I"$(ZLIB_PATH)"
235  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
236  DLL_LIBS += -L"$(ZLIB_PATH)" -lz
237endif
238ifdef IDN
239  INCLUDES += -I"$(LIBIDN_PATH)/include"
240  CFLAGS += -DUSE_LIBIDN
241  DLL_LIBS += -L"$(LIBIDN_PATH)/lib" -lidn
242else
243ifdef WINIDN
244  CFLAGS += -DUSE_WIN32_IDN
245  CFLAGS += -DWANT_IDN_PROTOTYPES
246  DLL_LIBS += -L"$(WINIDN_PATH)" -lnormaliz
247endif
248endif
249ifdef SSPI
250  CFLAGS += -DUSE_WINDOWS_SSPI
251  ifdef WINSSL
252    CFLAGS += -DUSE_SCHANNEL
253  endif
254endif
255ifdef SPNEGO
256  CFLAGS += -DHAVE_SPNEGO
257endif
258ifdef IPV6
259  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
260endif
261ifdef LDAPS
262  CFLAGS += -DHAVE_LDAP_SSL
263endif
264ifdef USE_LDAP_NOVELL
265  INCLUDES += -I"$(LDAP_SDK)/inc"
266  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
267  DLL_LIBS += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
268endif
269ifdef USE_LDAP_OPENLDAP
270  INCLUDES += -I"$(LDAP_SDK)/include"
271  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
272  DLL_LIBS += -L"$(LDAP_SDK)/lib" -lldap -llber
273endif
274ifndef USE_LDAP_NOVELL
275ifndef USE_LDAP_OPENLDAP
276  DLL_LIBS += -lwldap32
277endif
278endif
279DLL_LIBS += -lws2_32
280
281# Makefile.inc provides the CSOURCES and HHEADERS defines
282include Makefile.inc
283
284libcurl_dll_LIBRARY = libcurl.dll
285libcurl_dll_a_LIBRARY = libcurldll.a
286libcurl_a_LIBRARY = libcurl.a
287
288libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES)))
289libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
290
291RESOURCE = libcurl.res
292
293
294all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY)
295
296$(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
297	@$(call DEL, $@)
298	$(AR) cru $@ $(libcurl_a_OBJECTS)
299	$(RANLIB) $@
300	$(STRIP) $@
301
302# remove the last line above to keep debug info
303
304$(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(libcurl_dll_DEPENDENCIES)
305	@$(call DEL, $@)
306	$(CC) $(LDFLAGS) -shared -o $@ \
307	  -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY) \
308	  $(libcurl_a_OBJECTS) $(RESOURCE) $(DLL_LIBS)
309
310%.o: %.c $(PROOT)/include/curl/curlbuild.h
311	$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
312
313%.res: %.rc
314	$(RC) $(RCFLAGS) -i $< -o $@
315
316clean:
317ifeq "$(wildcard $(PROOT)/include/curl/curlbuild.h.dist)" "$(PROOT)/include/curl/curlbuild.h.dist"
318	@$(call DEL, $(PROOT)/include/curl/curlbuild.h)
319endif
320	@$(call DEL, $(libcurl_a_OBJECTS) $(RESOURCE))
321
322distclean vclean: clean
323	@$(call DEL, $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY))
324
325$(PROOT)/include/curl/curlbuild.h:
326	@echo Creating $@
327	@$(call COPY, $@.dist, $@)
328
329$(LIBCARES_PATH)/libcares.a:
330	$(MAKE) -C $(LIBCARES_PATH) -f Makefile.m32
331