1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1998 - 2018, 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 examples 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## brotli (1.0.1)
28##
29## Usage:   mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
30## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
31##
32## Hint: you can also set environment vars to control the build, f.e.:
33## set ZLIB_PATH=c:/zlib-1.2.8
34## set ZLIB=1
35#
36###########################################################################
37
38# Edit the path below to point to the base of your Zlib sources.
39ifndef ZLIB_PATH
40ZLIB_PATH = ../../../zlib-1.2.8
41endif
42# Edit the path below to point to the base of your Brotli sources.
43ifndef BROTLI_PATH
44BROTLI_PATH = ../../../brotli-1.0.1
45endif
46# Edit the path below to point to the base of your OpenSSL package.
47ifndef OPENSSL_PATH
48OPENSSL_PATH = ../../../openssl-1.0.2a
49endif
50# Edit the path below to point to the base of your LibSSH2 package.
51ifndef LIBSSH2_PATH
52LIBSSH2_PATH = ../../../libssh2-1.5.0
53endif
54# Edit the path below to point to the base of your librtmp package.
55ifndef LIBRTMP_PATH
56LIBRTMP_PATH = ../../../librtmp-2.4
57endif
58# Edit the path below to point to the base of your libmetalink package.
59ifndef LIBMETALINK_PATH
60LIBMETALINK_PATH = ../../../libmetalink-0.1.3
61endif
62# Edit the path below to point to the base of your libexpat package.
63ifndef LIBEXPAT_PATH
64LIBEXPAT_PATH = ../../../expat-2.1.0
65endif
66# Edit the path below to point to the base of your libxml2 package.
67ifndef LIBXML2_PATH
68LIBXML2_PATH = ../../../libxml2-2.9.2
69endif
70# Edit the path below to point to the base of your libidn2 package.
71ifndef LIBIDN2_PATH
72LIBIDN2_PATH = ../../../libidn2-2.0.3
73endif
74# Edit the path below to point to the base of your MS IDN package.
75# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
76# https://www.microsoft.com/en-us/download/details.aspx?id=734
77ifndef WINIDN_PATH
78WINIDN_PATH = ../../../Microsoft IDN Mitigation APIs
79endif
80# Edit the path below to point to the base of your Novell LDAP NDK.
81ifndef LDAP_SDK
82LDAP_SDK = c:/novell/ndk/cldapsdk/win32
83endif
84# Edit the path below to point to the base of your nghttp2 package.
85ifndef NGHTTP2_PATH
86NGHTTP2_PATH = ../../../nghttp2-1.0.0
87endif
88
89PROOT = ../..
90
91# Edit the path below to point to the base of your c-ares package.
92ifndef LIBCARES_PATH
93LIBCARES_PATH = $(PROOT)/ares
94endif
95
96ifeq ($(CURL_CC),)
97CURL_CC := $(CROSSPREFIX)gcc
98endif
99ifeq ($(CURL_AR),)
100CURL_AR := $(CROSSPREFIX)ar
101endif
102
103CC = $(CURL_CC)
104CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W
105CFLAGS += -fno-strict-aliasing
106# comment LDFLAGS below to keep debug info
107LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_EXE) -s
108RC = $(CROSSPREFIX)windres
109RCFLAGS = --include-dir=$(PROOT)/include -O COFF
110
111# Set environment var ARCH to your architecture to override autodetection.
112ifndef ARCH
113ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
114ARCH = w64
115else
116ARCH = w32
117endif
118endif
119
120ifeq ($(ARCH),w64)
121CFLAGS  += -m64 -D_AMD64_
122LDFLAGS += -m64
123RCFLAGS += -F pe-x86-64
124else
125CFLAGS  += -m32
126LDFLAGS += -m32
127RCFLAGS += -F pe-i386
128endif
129
130# Platform-dependent helper tool macros
131ifeq ($(findstring /sh,$(SHELL)),/sh)
132DEL     = rm -f $1
133RMDIR   = rm -fr $1
134MKDIR   = mkdir -p $1
135COPY    = -cp -afv $1 $2
136#COPYR  = -cp -afr $1/* $2
137COPYR   = -rsync -aC $1/* $2
138TOUCH   = touch $1
139CAT     = cat
140ECHONL  = echo ""
141DL = '
142else
143ifeq "$(OS)" "Windows_NT"
144DEL     = -del 2>NUL /q /f $(subst /,\,$1)
145RMDIR   = -rd 2>NUL /q /s $(subst /,\,$1)
146else
147DEL     = -del 2>NUL $(subst /,\,$1)
148RMDIR   = -deltree 2>NUL /y $(subst /,\,$1)
149endif
150MKDIR   = -md 2>NUL $(subst /,\,$1)
151COPY    = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
152COPYR   = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
153TOUCH   = copy 2>&1>NUL /b $(subst /,\,$1) +,,
154CAT     = type
155ECHONL  = $(ComSpec) /c echo.
156endif
157
158########################################################
159## Nothing more to do below this line!
160
161ifeq ($(findstring -dyn,$(CFG)),-dyn)
162DYN = 1
163endif
164ifeq ($(findstring -ares,$(CFG)),-ares)
165ARES = 1
166endif
167ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
168RTMP = 1
169SSL = 1
170ZLIB = 1
171endif
172ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
173SSH2 = 1
174SSL = 1
175ZLIB = 1
176endif
177ifeq ($(findstring -ssl,$(CFG)),-ssl)
178SSL = 1
179endif
180ifeq ($(findstring -zlib,$(CFG)),-zlib)
181ZLIB = 1
182endif
183ifeq ($(findstring -brotli,$(CFG)),-brotli)
184BROTLI = 1
185endif
186ifeq ($(findstring -idn2,$(CFG)),-idn2)
187IDN2 = 1
188endif
189ifeq ($(findstring -winidn,$(CFG)),-winidn)
190WINIDN = 1
191endif
192ifeq ($(findstring -sspi,$(CFG)),-sspi)
193SSPI = 1
194endif
195ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
196LDAPS = 1
197endif
198ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
199IPV6 = 1
200endif
201ifeq ($(findstring -metalink,$(CFG)),-metalink)
202METALINK = 1
203endif
204ifeq ($(findstring -winssl,$(CFG)),-winssl)
205WINSSL = 1
206SSPI = 1
207endif
208ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
209NGHTTP2 = 1
210endif
211
212INCLUDES = -I. -I$(PROOT) -I$(PROOT)/include -I$(PROOT)/lib
213
214ifdef DYN
215  curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll
216  curl_LDADD = -L$(PROOT)/lib -lcurldll
217else
218  curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a
219  curl_LDADD = -L$(PROOT)/lib -lcurl
220  CFLAGS += -DCURL_STATICLIB
221  LDFLAGS += -static
222endif
223ifdef ARES
224  ifndef DYN
225    curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a
226  endif
227  CFLAGS += -DUSE_ARES
228  curl_LDADD += -L"$(LIBCARES_PATH)" -lcares
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)
277endif
278ifdef WINSSL
279  CFLAGS += -DUSE_SCHANNEL
280  curl_LDADD += -lcrypt32
281endif
282ifdef ZLIB
283  INCLUDES += -I"$(ZLIB_PATH)"
284  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
285  curl_LDADD += -L"$(ZLIB_PATH)" -lz
286endif
287ifdef BROTLI
288  INCLUDES += -I"$(BROTLI_PATH)/include"
289  CFLAGS += -DHAVE_BROTLI
290  curl_LDADD += -L"$(BROTLI_PATH)/lib"
291  ifdef BROTLI_LIBS
292    curl_LDADD += $(BROTLI_LIBS)
293  else
294    curl_LDADD += -lbrotlidec
295  endif
296endif
297ifdef IDN2
298  CFLAGS += -DUSE_LIBIDN2
299  curl_LDADD += -L"$(LIBIDN2_PATH)/lib" -lidn2
300else
301ifdef WINIDN
302  CFLAGS += -DUSE_WIN32_IDN
303  curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz
304endif
305endif
306ifdef METALINK
307  INCLUDES += -I"$(LIBMETALINK_PATH)/include"
308  CFLAGS += -DUSE_METALINK
309  curl_LDADD += -L"$(LIBMETALINK_PATH)/lib" -lmetalink
310  ifndef DYN
311    ifeq ($(findstring libexpat_metalink_parser.o,$(shell $(AR) t "$(LIBMETALINK_PATH)/lib/libmetalink.a")),libexpat_metalink_parser.o)
312      curl_LDADD += -L"$(LIBEXPAT_PATH)/lib" -lexpat
313    else
314      curl_LDADD += -L"$(LIBXML2_PATH)/lib" -lxml2
315    endif
316  endif
317endif
318ifdef SSPI
319  CFLAGS += -DUSE_WINDOWS_SSPI
320endif
321ifdef IPV6
322  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
323endif
324ifdef LDAPS
325  CFLAGS += -DHAVE_LDAP_SSL
326endif
327ifdef USE_LDAP_NOVELL
328  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
329  curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
330endif
331ifdef USE_LDAP_OPENLDAP
332  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
333  curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber
334endif
335ifndef USE_LDAP_NOVELL
336ifndef USE_LDAP_OPENLDAP
337  curl_LDADD += -lwldap32
338endif
339endif
340curl_LDADD += -lws2_32
341
342# Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines
343include Makefile.inc
344
345check_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS)))
346check_PROGRAMS += ftpuploadresume.exe synctime.exe
347
348.PRECIOUS: %.o
349
350
351all: $(check_PROGRAMS)
352
353%.exe: %.o $(curl_DEPENDENCIES)
354	$(CC) $(LDFLAGS) -o $@ $< $(curl_LDADD)
355
356%.o: %.c
357	$(CC) $(INCLUDES) $(CFLAGS) -c $<
358
359%.res: %.rc
360	$(RC) $(RCFLAGS) -i $< -o $@
361
362clean:
363	@$(call DEL, $(check_PROGRAMS:.exe=.o))
364
365distclean vclean: clean
366	@$(call DEL, $(check_PROGRAMS))
367