1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1999 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.haxx.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21#***************************************************************************
22
23###########################################################################
24#
25## Makefile for building curl.exe with MingW (GCC-3.2 or later)
26## and optionally OpenSSL (1.0.2a), libssh2 (1.5), zlib (1.2.8), librtmp (2.4)
27##
28## Usage:   mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
29## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
30##
31## Hint: you can also set environment vars to control the build, f.e.:
32## set ZLIB_PATH=c:/zlib-1.2.8
33## set ZLIB=1
34#
35###########################################################################
36
37# Edit the path below to point to the base of your Zlib sources.
38ifndef ZLIB_PATH
39ZLIB_PATH = ../../zlib-1.2.8
40endif
41# Edit the path below to point to the base of your OpenSSL package.
42ifndef OPENSSL_PATH
43OPENSSL_PATH = ../../openssl-1.0.2a
44endif
45# Edit the path below to point to the base of your LibSSH2 package.
46ifndef LIBSSH2_PATH
47LIBSSH2_PATH = ../../libssh2-1.5.0
48endif
49# Edit the path below to point to the base of your librtmp package.
50ifndef LIBRTMP_PATH
51LIBRTMP_PATH = ../../librtmp-2.4
52endif
53# Edit the path below to point to the base of your libmetalink package.
54ifndef LIBMETALINK_PATH
55LIBMETALINK_PATH = ../../libmetalink-0.1.3
56endif
57# Edit the path below to point to the base of your libexpat package.
58ifndef LIBEXPAT_PATH
59LIBEXPAT_PATH = ../../expat-2.1.0
60endif
61# Edit the path below to point to the base of your libxml2 package.
62ifndef LIBXML2_PATH
63LIBXML2_PATH = ../../libxml2-2.9.2
64endif
65# Edit the path below to point to the base of your libidn package.
66ifndef LIBIDN_PATH
67LIBIDN_PATH = ../../libidn-1.32
68endif
69# Edit the path below to point to the base of your MS IDN package.
70# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
71# https://www.microsoft.com/en-us/download/details.aspx?id=734
72ifndef WINIDN_PATH
73WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
74endif
75# Edit the path below to point to the base of your Novell LDAP NDK.
76ifndef LDAP_SDK
77LDAP_SDK = c:/novell/ndk/cldapsdk/win32
78endif
79# Edit the path below to point to the base of your nghttp2 package.
80ifndef NGHTTP2_PATH
81NGHTTP2_PATH = ../../nghttp2-1.0.0
82endif
83
84PROOT = ..
85
86# Edit the path below to point to the base of your c-ares package.
87ifndef LIBCARES_PATH
88LIBCARES_PATH = $(PROOT)/ares
89endif
90
91CC	= $(CROSSPREFIX)gcc
92CFLAGS	= $(CURL_CFLAG_EXTRAS) -g -O2 -Wall
93CFLAGS	+= -fno-strict-aliasing
94# comment LDFLAGS below to keep debug info
95LDFLAGS	= $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_EXE) -s
96AR	= $(CROSSPREFIX)ar
97RC	= $(CROSSPREFIX)windres
98RCFLAGS	= --include-dir=$(PROOT)/include -O COFF
99STRIP	= $(CROSSPREFIX)strip -g
100
101# We may need these someday
102# PERL = perl
103# NROFF = nroff
104
105# Set environment var ARCH to your architecture to override autodetection.
106ifndef ARCH
107ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
108ARCH	= w64
109else
110ARCH	= w32
111endif
112endif
113
114ifeq ($(ARCH),w64)
115CFLAGS  += -m64 -D_AMD64_
116LDFLAGS += -m64
117RCFLAGS += -F pe-x86-64
118else
119CFLAGS  += -m32
120LDFLAGS += -m32
121RCFLAGS += -F pe-i386
122endif
123
124# Platform-dependent helper tool macros
125ifeq ($(findstring /sh,$(SHELL)),/sh)
126DEL	= rm -f $1
127RMDIR	= rm -fr $1
128MKDIR	= mkdir -p $1
129COPY	= -cp -afv $1 $2
130#COPYR	= -cp -afr $1/* $2
131COPYR	= -rsync -aC $1/* $2
132TOUCH	= touch $1
133CAT	= cat
134ECHONL	= echo ""
135DL	= '
136else
137ifeq "$(OS)" "Windows_NT"
138DEL	= -del 2>NUL /q /f $(subst /,\,$1)
139RMDIR	= -rd 2>NUL /q /s $(subst /,\,$1)
140else
141DEL	= -del 2>NUL $(subst /,\,$1)
142RMDIR	= -deltree 2>NUL /y $(subst /,\,$1)
143endif
144MKDIR	= -md 2>NUL $(subst /,\,$1)
145COPY	= -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
146COPYR	= -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
147TOUCH	= copy 2>&1>NUL /b $(subst /,\,$1) +,,
148CAT	= type
149ECHONL	= $(ComSpec) /c echo.
150endif
151
152########################################################
153## Nothing more to do below this line!
154
155ifeq ($(findstring -dyn,$(CFG)),-dyn)
156DYN = 1
157endif
158ifeq ($(findstring -ares,$(CFG)),-ares)
159ARES = 1
160endif
161ifeq ($(findstring -sync,$(CFG)),-sync)
162SYNC = 1
163endif
164ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
165RTMP = 1
166SSL = 1
167ZLIB = 1
168endif
169ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
170SSH2 = 1
171ifneq ($(findstring -winssl,$(CFG)),-winssl)
172SSL = 1
173endif
174ZLIB = 1
175endif
176ifeq ($(findstring -ssl,$(CFG)),-ssl)
177SSL = 1
178endif
179ifeq ($(findstring -zlib,$(CFG)),-zlib)
180ZLIB = 1
181endif
182ifeq ($(findstring -idn,$(CFG)),-idn)
183IDN = 1
184endif
185ifeq ($(findstring -winidn,$(CFG)),-winidn)
186WINIDN = 1
187endif
188ifeq ($(findstring -sspi,$(CFG)),-sspi)
189SSPI = 1
190endif
191ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
192LDAPS = 1
193endif
194ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
195IPV6 = 1
196endif
197ifeq ($(findstring -metalink,$(CFG)),-metalink)
198METALINK = 1
199endif
200ifeq ($(findstring -winssl,$(CFG)),-winssl)
201WINSSL = 1
202SSPI = 1
203endif
204ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
205NGHTTP2 = 1
206endif
207
208INCLUDES = -I. -I../include -I../lib
209
210ifdef DYN
211  curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll
212  curl_LDADD = -L$(PROOT)/lib -lcurldll
213else
214  curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a
215  curl_LDADD = -L$(PROOT)/lib -lcurl
216  CFLAGS += -DCURL_STATICLIB
217  LDFLAGS += -static
218endif
219ifdef SYNC
220  CFLAGS += -DUSE_SYNC_DNS
221else
222  ifdef ARES
223    ifndef DYN
224      curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a
225    endif
226    CFLAGS += -DUSE_ARES -DCARES_STATICLIB
227    curl_LDADD += -L"$(LIBCARES_PATH)" -lcares
228  endif
229endif
230ifdef RTMP
231  CFLAGS += -DUSE_LIBRTMP
232  curl_LDADD += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
233endif
234ifdef NGHTTP2
235  CFLAGS += -DUSE_NGHTTP2
236  curl_LDADD += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
237endif
238ifdef SSH2
239  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
240  curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2
241  ifdef WINSSL
242    ifndef DYN
243      curl_LDADD += -lbcrypt -lcrypt32
244    endif
245  endif
246endif
247ifdef SSL
248  ifndef OPENSSL_INCLUDE
249    ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
250      OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
251    endif
252    ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
253      OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
254    endif
255  endif
256  ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
257  $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
258  endif
259  ifndef OPENSSL_LIBPATH
260    OPENSSL_LIBS = -lssl -lcrypto
261    ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
262      OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
263      ifdef DYN
264        OPENSSL_LIBS = -lssl32 -leay32
265      endif
266    endif
267    ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
268      OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
269    endif
270  endif
271  ifndef DYN
272    OPENSSL_LIBS += -lgdi32 -lcrypt32
273  endif
274  INCLUDES += -I"$(OPENSSL_INCLUDE)"
275  CFLAGS += -DUSE_OPENSSL
276  curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
277else
278ifdef WINSSL
279  curl_LDADD += -lcrypt32
280endif
281endif
282ifdef ZLIB
283  INCLUDES += -I"$(ZLIB_PATH)"
284  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
285  curl_LDADD += -L"$(ZLIB_PATH)" -lz
286endif
287ifdef IDN
288  CFLAGS += -DUSE_LIBIDN
289  curl_LDADD += -L"$(LIBIDN_PATH)/lib" -lidn
290else
291ifdef WINIDN
292  CFLAGS += -DUSE_WIN32_IDN
293  curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz
294endif
295endif
296ifdef METALINK
297  INCLUDES += -I"$(LIBMETALINK_PATH)/include"
298  CFLAGS += -DUSE_METALINK
299  curl_LDADD += -L"$(LIBMETALINK_PATH)/lib" -lmetalink
300  ifndef DYN
301    ifeq ($(findstring libexpat_metalink_parser.o,$(shell $(AR) t "$(LIBMETALINK_PATH)/lib/libmetalink.a")),libexpat_metalink_parser.o)
302      curl_LDADD += -L"$(LIBEXPAT_PATH)/lib" -lexpat
303    else
304      curl_LDADD += -L"$(LIBXML2_PATH)/lib" -lxml2
305    endif
306  endif
307endif
308ifdef SSPI
309  CFLAGS += -DUSE_WINDOWS_SSPI
310  ifdef WINSSL
311    CFLAGS += -DUSE_SCHANNEL
312  endif
313endif
314ifdef IPV6
315  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
316endif
317ifdef LDAPS
318  CFLAGS += -DHAVE_LDAP_SSL
319endif
320ifdef USE_LDAP_NOVELL
321  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
322  curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
323endif
324ifdef USE_LDAP_OPENLDAP
325  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
326  curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber
327endif
328ifndef USE_LDAP_NOVELL
329ifndef USE_LDAP_OPENLDAP
330curl_LDADD += -lwldap32
331endif
332endif
333curl_LDADD += -lws2_32
334
335# Makefile.inc provides the CSOURCES and HHEADERS defines
336include Makefile.inc
337
338curl_PROGRAMS = curl.exe
339curl_OBJECTS := $(patsubst %.c,%.o,$(strip $(CURL_CFILES)))
340curlx_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CURLX_CFILES))))
341ifdef DYN
342curl_OBJECTS += $(curlx_OBJECTS)
343vpath %.c $(PROOT)/lib
344endif
345
346RESOURCE = curl.res
347
348
349all: $(curl_PROGRAMS)
350
351curl.exe: $(RESOURCE) $(curl_OBJECTS) $(curl_DEPENDENCIES)
352	$(call DEL, $@)
353	$(CC) $(LDFLAGS) -o $@ $< $(curl_OBJECTS) $(curl_LDADD)
354
355# We don't have nroff normally under win32
356# tool_hugehelp.c: $(PROOT)/docs/MANUAL $(PROOT)/docs/curl.1 mkhelp.pl
357#	@$(call DEL, tool_hugehelp.c)
358# 	$(NROFF) -man $(PROOT)/docs/curl.1 | $(PERL) mkhelp.pl $(PROOT)/docs/MANUAL > tool_hugehelp.c
359
360tool_hugehelp.c:
361	@echo Creating $@
362	@$(call COPY, $@.cvs, $@)
363
364%.o: %.c
365	$(CC) $(INCLUDES) $(CFLAGS) -c $<
366
367%.res: %.rc
368	$(RC) $(RCFLAGS) -i $< -o $@
369
370clean:
371ifeq "$(wildcard tool_hugehelp.c.cvs)" "tool_hugehelp.c.cvs"
372	@$(call DEL, tool_hugehelp.c)
373endif
374	@$(call DEL, $(curl_OBJECTS) $(curlx_OBJECTS) $(RESOURCE))
375
376distclean vclean: clean
377	@$(call DEL, $(curl_PROGRAMS))
378