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.5
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.5
18endif
19# Edit the path below to point to the base of your OpenSSL package.
20ifndef OPENSSL_PATH
21OPENSSL_PATH = ../../openssl-0.9.8r
22endif
23ifndef OPENSSL_INCLUDE
24OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
25endif
26ifndef OPENSSL_LIBPATH
27OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
28endif
29ifndef OPENSSL_LIBS
30OPENSSL_LIBS = -leay32 -lssl32
31endif
32# Edit the path below to point to the base of your LibSSH2 package.
33ifndef LIBSSH2_PATH
34LIBSSH2_PATH = ../../libssh2-1.3.0
35endif
36# Edit the path below to point to the base of your librtmp package.
37ifndef LIBRTMP_PATH
38LIBRTMP_PATH = ../../librtmp-2.3
39endif
40# Edit the path below to point to the base of your libidn package.
41ifndef LIBIDN_PATH
42LIBIDN_PATH = ../../libidn-1.18
43endif
44# Edit the path below to point to the base of your MS idndlpackage. 
45# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
46# http://www.microsoft.com/downloads/en/details.aspx?FamilyID=ad6158d7-ddba-416a-9109-07607425a815
47ifndef WINIDN_PATH
48WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
49endif
50# Edit the path below to point to the base of your Novell LDAP NDK.
51ifndef LDAP_SDK
52LDAP_SDK = c:/novell/ndk/cldapsdk/win32
53endif
54
55PROOT = ..
56
57# Edit the path below to point to the base of your c-ares package.
58ifndef LIBCARES_PATH
59LIBCARES_PATH = $(PROOT)/ares
60endif
61
62# Edit the var below to set to your architecture or set environment var.
63ifndef ARCH
64ARCH = w32
65endif
66
67CC = gcc
68CFLAGS = -g -O2 -Wall
69CFLAGS += -fno-strict-aliasing
70ifeq ($(ARCH),w64)
71CFLAGS += -D_AMD64_
72endif
73# comment LDFLAGS below to keep debug info
74LDFLAGS = -s
75AR = ar
76RANLIB = ranlib
77RC = windres
78RCFLAGS = --include-dir=$(PROOT)/include -DDEBUGBUILD=0 -O COFF -i
79STRIP = strip -g
80
81RM = del /q /f 2>NUL
82CP = copy
83
84########################################################
85## Nothing more to do below this line!
86
87ifeq ($(findstring -dyn,$(CFG)),-dyn)
88DYN = 1
89endif
90ifeq ($(findstring -ares,$(CFG)),-ares)
91ARES = 1
92endif
93ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
94RTMP = 1
95SSL = 1
96ZLIB = 1
97endif
98ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
99SSH2 = 1
100SSL = 1
101ZLIB = 1
102endif
103ifeq ($(findstring -ssl,$(CFG)),-ssl)
104SSL = 1
105endif
106ifeq ($(findstring -zlib,$(CFG)),-zlib)
107ZLIB = 1
108endif
109ifeq ($(findstring -idn,$(CFG)),-idn)
110IDN = 1
111endif
112ifeq ($(findstring -winidn,$(CFG)),-winidn)
113WINIDN = 1
114endif
115ifeq ($(findstring -sspi,$(CFG)),-sspi)
116SSPI = 1
117endif
118ifeq ($(findstring -spnego,$(CFG)),-spnego)
119SPNEGO = 1
120endif
121ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
122LDAPS = 1
123endif
124ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
125IPV6 = 1
126endif
127
128INCLUDES = -I. -I../include
129CFLAGS += -DBUILDING_LIBCURL
130
131ifdef ARES
132  INCLUDES += -I"$(LIBCARES_PATH)"
133  CFLAGS += -DUSE_ARES
134  DLL_LIBS += -L"$(LIBCARES_PATH)" -lcares
135  libcurl_dll_DEPENDENCIES = $(LIBCARES_PATH)/libcares.a
136endif
137ifdef RTMP
138  INCLUDES += -I"$(LIBRTMP_PATH)"
139  CFLAGS += -DUSE_LIBRTMP
140  DLL_LIBS += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
141endif
142ifdef SSH2
143  INCLUDES += -I"$(LIBSSH2_PATH)/include" -I"$(LIBSSH2_PATH)/win32"
144  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
145  DLL_LIBS += -L"$(LIBSSH2_PATH)/win32" -lssh2
146endif
147ifdef SSL
148  INCLUDES += -I"$(OPENSSL_INCLUDE)"
149  CFLAGS += -DUSE_SSLEAY -DUSE_OPENSSL -DHAVE_OPENSSL_ENGINE_H -DHAVE_OPENSSL_PKCS12_H \
150            -DHAVE_ENGINE_LOAD_BUILTIN_ENGINES -DOPENSSL_NO_KRB5 \
151            -DCURL_WANTS_CA_BUNDLE_ENV
152  DLL_LIBS += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
153endif
154ifdef ZLIB
155  INCLUDES += -I"$(ZLIB_PATH)"
156  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
157  DLL_LIBS += -L"$(ZLIB_PATH)" -lz
158endif
159ifdef IDN
160  INCLUDES += -I"$(LIBIDN_PATH)/include"
161  CFLAGS += -DUSE_LIBIDN
162  DLL_LIBS += -L"$(LIBIDN_PATH)/lib" -lidn
163else
164ifdef WINIDN
165  CFLAGS += -DUSE_WIN32_IDN
166  CFLAGS += -DWANT_IDN_PROTOTYPES
167  DLL_LIBS += -L"$(WINIDN_PATH)" -lnormaliz
168endif
169endif
170ifdef SSPI
171  CFLAGS += -DUSE_WINDOWS_SSPI
172endif
173ifdef SPNEGO
174  CFLAGS += -DHAVE_SPNEGO
175endif
176ifdef IPV6
177  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
178endif
179ifdef LDAPS
180  CFLAGS += -DHAVE_LDAP_SSL
181endif
182ifdef USE_LDAP_NOVELL
183  INCLUDES += -I"$(LDAP_SDK)/inc"
184  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
185  DLL_LIBS += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
186endif
187ifdef USE_LDAP_OPENLDAP
188  INCLUDES += -I"$(LDAP_SDK)/include"
189  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
190  DLL_LIBS += -L"$(LDAP_SDK)/lib" -lldap -llber
191endif
192ifndef USE_LDAP_NOVELL
193ifndef USE_LDAP_OPENLDAP
194  DLL_LIBS += -lwldap32
195endif
196endif
197DLL_LIBS += -lws2_32
198
199# Makefile.inc provides the CSOURCES and HHEADERS defines
200include Makefile.inc
201
202libcurl_dll_LIBRARY = libcurl.dll
203libcurl_dll_a_LIBRARY = libcurldll.a
204libcurl_a_LIBRARY = libcurl.a
205
206libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES)))
207libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
208
209RESOURCE = libcurl.res
210
211
212all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY)
213
214$(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
215	-$(RM) $@
216	$(AR) cru $@ $(libcurl_a_OBJECTS)
217	$(RANLIB) $@
218	$(STRIP) $@
219
220# remove the last line above to keep debug info
221
222$(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(libcurl_dll_DEPENDENCIES)
223	-$(RM) $@
224	$(CC) $(LDFLAGS) -shared -Wl,--out-implib,$(libcurl_dll_a_LIBRARY) \
225	  -o $@ $(libcurl_a_OBJECTS) $(RESOURCE) $(DLL_LIBS)
226
227%.o: %.c $(PROOT)/include/curl/curlbuild.h
228	$(CC) $(INCLUDES) $(CFLAGS) -c $<
229
230%.res: %.rc
231	$(RC) $(RCFLAGS) $< -o $@
232
233clean:
234ifeq "$(wildcard $(PROOT)/include/curl/curlbuild.h.dist)" "$(PROOT)/include/curl/curlbuild.h.dist"
235	-$(RM) $(subst /,\,$(PROOT)/include/curl/curlbuild.h)
236endif
237	-$(RM) $(libcurl_a_OBJECTS) $(RESOURCE)
238
239distclean vclean: clean
240	-$(RM) $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_a_LIBRARY)
241
242$(LIBCARES_PATH)/libcares.a:
243	$(MAKE) -C $(LIBCARES_PATH) -f Makefile.m32
244
245$(PROOT)/include/curl/curlbuild.h:
246	@echo Creating $@
247	@$(CP) $(subst /,\,$@).dist $(subst /,\,$@)
248
249