• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1###########################################################################
2#
3## Makefile for building curl.exe 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-spi-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 libmetalink package.
32ifndef LIBMETALINK_PATH
33LIBMETALINK_PATH = ../../libmetalink-0.1.3
34endif
35# Edit the path below to point to the base of your libexpat package.
36ifndef LIBEXPAT_PATH
37LIBEXPAT_PATH = ../../expat-2.1.0
38endif
39# Edit the path below to point to the base of your libxml2 package.
40ifndef LIBXML2_PATH
41LIBXML2_PATH = ../../libxml2-2.9.2
42endif
43# Edit the path below to point to the base of your libidn package.
44ifndef LIBIDN_PATH
45LIBIDN_PATH = ../../libidn-1.30
46endif
47# Edit the path below to point to the base of your MS IDN package.
48# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
49# https://www.microsoft.com/en-us/download/details.aspx?id=734
50ifndef WINIDN_PATH
51WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
52endif
53# Edit the path below to point to the base of your Novell LDAP NDK.
54ifndef LDAP_SDK
55LDAP_SDK = c:/novell/ndk/cldapsdk/win32
56endif
57# Edit the path below to point to the base of your nghttp2 package.
58ifndef NGHTTP2_PATH
59NGHTTP2_PATH = ../../nghttp2-1.0.0
60endif
61
62PROOT = ..
63
64# Edit the path below to point to the base of your c-ares package.
65ifndef LIBCARES_PATH
66LIBCARES_PATH = $(PROOT)/ares
67endif
68
69CC	= $(CROSSPREFIX)gcc
70CFLAGS	= -g -O2 -Wall
71CFLAGS	+= -fno-strict-aliasing
72# comment LDFLAGS below to keep debug info
73LDFLAGS	= -s
74AR	= $(CROSSPREFIX)ar
75RC	= $(CROSSPREFIX)windres
76RCFLAGS	= --include-dir=$(PROOT)/include -O COFF
77STRIP   = $(CROSSPREFIX)strip -g
78
79# We may need these someday
80# PERL = perl
81# NROFF = nroff
82
83# Set environment var ARCH to your architecture to override autodetection.
84ifndef ARCH
85ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
86ARCH    = w64
87else
88ARCH    = w32
89endif
90endif
91
92ifeq ($(ARCH),w64)
93CFLAGS	+= -m64 -D_AMD64_
94LDFLAGS += -m64
95RCFLAGS += -F pe-x86-64
96else
97CFLAGS	+= -m32
98LDFLAGS += -m32
99RCFLAGS += -F pe-i386
100endif
101
102# Platform-dependent helper tool macros
103ifeq ($(findstring /sh,$(SHELL)),/sh)
104DEL	= rm -f $1
105RMDIR	= rm -fr $1
106MKDIR	= mkdir -p $1
107COPY	= -cp -afv $1 $2
108#COPYR	= -cp -afr $1/* $2
109COPYR	= -rsync -aC $1/* $2
110TOUCH	= touch $1
111CAT	= cat
112ECHONL	= echo ""
113DL	= '
114else
115ifeq "$(OS)" "Windows_NT"
116DEL	= -del 2>NUL /q /f $(subst /,\,$1)
117RMDIR	= -rd 2>NUL /q /s $(subst /,\,$1)
118else
119DEL	= -del 2>NUL $(subst /,\,$1)
120RMDIR	= -deltree 2>NUL /y $(subst /,\,$1)
121endif
122MKDIR	= -md 2>NUL $(subst /,\,$1)
123COPY	= -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
124COPYR	= -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
125TOUCH	= copy 2>&1>NUL /b $(subst /,\,$1) +,,
126CAT	= type
127ECHONL	= $(ComSpec) /c echo.
128endif
129
130########################################################
131## Nothing more to do below this line!
132
133ifeq ($(findstring -dyn,$(CFG)),-dyn)
134DYN = 1
135endif
136ifeq ($(findstring -ares,$(CFG)),-ares)
137ARES = 1
138endif
139ifeq ($(findstring -sync,$(CFG)),-sync)
140SYNC = 1
141endif
142ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
143RTMP = 1
144SSL = 1
145ZLIB = 1
146endif
147ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
148SSH2 = 1
149SSL = 1
150ZLIB = 1
151endif
152ifeq ($(findstring -ssl,$(CFG)),-ssl)
153SSL = 1
154endif
155ifeq ($(findstring -zlib,$(CFG)),-zlib)
156ZLIB = 1
157endif
158ifeq ($(findstring -idn,$(CFG)),-idn)
159IDN = 1
160endif
161ifeq ($(findstring -winidn,$(CFG)),-winidn)
162WINIDN = 1
163endif
164ifeq ($(findstring -sspi,$(CFG)),-sspi)
165SSPI = 1
166endif
167ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
168LDAPS = 1
169endif
170ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
171IPV6 = 1
172endif
173ifeq ($(findstring -metalink,$(CFG)),-metalink)
174METALINK = 1
175endif
176ifeq ($(findstring -winssl,$(CFG)),-winssl)
177WINSSL = 1
178SSPI = 1
179endif
180ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
181NGHTTP2 = 1
182endif
183
184INCLUDES = -I. -I../include -I../lib
185
186ifdef DYN
187  curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll
188  curl_LDADD = -L$(PROOT)/lib -lcurldll
189else
190  curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a
191  curl_LDADD = -L$(PROOT)/lib -lcurl
192  CFLAGS += -DCURL_STATICLIB
193  LDFLAGS += -static
194endif
195ifdef SYNC
196  CFLAGS += -DUSE_SYNC_DNS
197else
198  ifdef ARES
199    ifndef DYN
200      curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a
201    endif
202    CFLAGS += -DUSE_ARES -DCARES_STATICLIB
203    curl_LDADD += -L"$(LIBCARES_PATH)" -lcares
204  endif
205endif
206ifdef RTMP
207  CFLAGS += -DUSE_LIBRTMP
208  curl_LDADD += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
209endif
210ifdef NGHTTP2
211  CFLAGS += -DUSE_NGHTTP2
212  curl_LDADD += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
213endif
214ifdef SSH2
215  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
216  curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2
217endif
218ifdef SSL
219  ifndef OPENSSL_INCLUDE
220    ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
221      OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
222    endif
223    ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
224      OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
225    endif
226  endif
227  ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
228  $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
229  endif
230  ifndef OPENSSL_LIBPATH
231    OPENSSL_LIBS = -lssl -lcrypto
232    ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
233      OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
234      ifdef DYN
235        OPENSSL_LIBS = -lssl32 -leay32
236      endif
237    endif
238    ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
239      OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
240    endif
241  endif
242  ifndef DYN
243    OPENSSL_LIBS += -lgdi32 -lcrypt32
244  endif
245  INCLUDES += -I"$(OPENSSL_INCLUDE)"
246  CFLAGS += -DUSE_OPENSSL
247  curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
248endif
249ifdef ZLIB
250  INCLUDES += -I"$(ZLIB_PATH)"
251  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
252  curl_LDADD += -L"$(ZLIB_PATH)" -lz
253endif
254ifdef IDN
255  CFLAGS += -DUSE_LIBIDN
256  curl_LDADD += -L"$(LIBIDN_PATH)/lib" -lidn
257else
258ifdef WINIDN
259  CFLAGS += -DUSE_WIN32_IDN
260  curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz
261endif
262endif
263ifdef METALINK
264  INCLUDES += -I"$(LIBMETALINK_PATH)/include"
265  CFLAGS += -DUSE_METALINK
266  curl_LDADD += -L"$(LIBMETALINK_PATH)/lib" -lmetalink
267  ifndef DYN
268    ifeq ($(findstring libexpat_metalink_parser.o,$(shell $(AR) t "$(LIBMETALINK_PATH)/lib/libmetalink.a")),libexpat_metalink_parser.o)
269      curl_LDADD += -L"$(LIBEXPAT_PATH)/lib" -lexpat
270    else
271      curl_LDADD += -L"$(LIBXML2_PATH)/lib" -lxml2
272    endif
273  endif
274endif
275ifdef SSPI
276  CFLAGS += -DUSE_WINDOWS_SSPI
277  ifdef WINSSL
278    CFLAGS += -DUSE_SCHANNEL
279  endif
280endif
281ifdef IPV6
282  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
283endif
284ifdef LDAPS
285  CFLAGS += -DHAVE_LDAP_SSL
286endif
287ifdef USE_LDAP_NOVELL
288  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
289  curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
290endif
291ifdef USE_LDAP_OPENLDAP
292  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
293  curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber
294endif
295ifndef USE_LDAP_NOVELL
296ifndef USE_LDAP_OPENLDAP
297curl_LDADD += -lwldap32
298endif
299endif
300curl_LDADD += -lws2_32
301
302# Makefile.inc provides the CSOURCES and HHEADERS defines
303include Makefile.inc
304
305curl_PROGRAMS = curl.exe
306curl_OBJECTS := $(patsubst %.c,%.o,$(strip $(CURL_CFILES)))
307curlx_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CURLX_CFILES))))
308ifdef DYN
309curl_OBJECTS += $(curlx_OBJECTS)
310vpath %.c $(PROOT)/lib
311endif
312
313RESOURCE = curl.res
314
315
316all: $(curl_PROGRAMS)
317
318curl.exe: $(RESOURCE) $(curl_OBJECTS) $(curl_DEPENDENCIES)
319	$(call DEL, $@)
320	$(CC) $(LDFLAGS) -o $@ $< $(curl_OBJECTS) $(curl_LDADD)
321
322# We don't have nroff normally under win32
323# tool_hugehelp.c: $(PROOT)/docs/MANUAL $(PROOT)/docs/curl.1 mkhelp.pl
324#	@$(call DEL, tool_hugehelp.c)
325# 	$(NROFF) -man $(PROOT)/docs/curl.1 | $(PERL) mkhelp.pl $(PROOT)/docs/MANUAL > tool_hugehelp.c
326
327tool_hugehelp.c:
328	@echo Creating $@
329	@$(call COPY, $@.cvs, $@)
330
331%.o: %.c
332	$(CC) $(INCLUDES) $(CFLAGS) -c $<
333
334%.res: %.rc
335	$(RC) $(RCFLAGS) -i $< -o $@
336
337clean:
338ifeq "$(wildcard tool_hugehelp.c.cvs)" "tool_hugehelp.c.cvs"
339	@$(call DEL, tool_hugehelp.c)
340endif
341	@$(call DEL, $(curl_OBJECTS) $(curlx_OBJECTS) $(RESOURCE))
342
343distclean vclean: clean
344	@$(call DEL, $(curl_PROGRAMS))
345