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