• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1998 - 2021, 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.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), zstd (1.4.5)
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 Zstandard sources.
43ifndef ZSTD_PATH
44ZSTD_PATH = ../../../zstd-1.4.5
45endif
46# Edit the path below to point to the base of your Brotli sources.
47ifndef BROTLI_PATH
48BROTLI_PATH = ../../../brotli-1.0.1
49endif
50# Edit the path below to point to the base of your OpenSSL package.
51ifndef OPENSSL_PATH
52OPENSSL_PATH = ../../../openssl-1.0.2a
53endif
54# Edit the path below to point to the base of your LibSSH2 package.
55ifndef LIBSSH2_PATH
56LIBSSH2_PATH = ../../../libssh2-1.5.0
57endif
58# Edit the path below to point to the base of your librtmp package.
59ifndef LIBRTMP_PATH
60LIBRTMP_PATH = ../../../librtmp-2.4
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 libgsasl package.
71ifndef LIBGSASL_PATH
72LIBGSASL_PATH = ../../../libgsasl-1.10.0
73endif
74# Edit the path below to point to the base of your libidn2 package.
75ifndef LIBIDN2_PATH
76LIBIDN2_PATH = ../../../libidn2-2.0.3
77endif
78# Edit the path below to point to the base of your MS IDN package.
79# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1
80# https://www.microsoft.com/en-us/download/details.aspx?id=734
81ifndef WINIDN_PATH
82WINIDN_PATH = ../../../Microsoft IDN Mitigation APIs
83endif
84# Edit the path below to point to the base of your Novell LDAP NDK.
85ifndef LDAP_SDK
86LDAP_SDK = c:/novell/ndk/cldapsdk/win32
87endif
88# Edit the path below to point to the base of your nghttp2 package.
89ifndef NGHTTP2_PATH
90NGHTTP2_PATH = ../../../nghttp2-1.0.0
91endif
92# Edit the path below to point to the base of your nghttp3 package.
93ifndef NGHTTP3_PATH
94NGHTTP3_PATH = ../../../nghttp3-1.0.0
95endif
96# Edit the path below to point to the base of your ngtcp2 package.
97ifndef NGTCP2_PATH
98NGTCP2_PATH = ../../../ngtcp2-1.0.0
99endif
100
101PROOT = ../..
102
103# Edit the path below to point to the base of your c-ares package.
104ifndef LIBCARES_PATH
105LIBCARES_PATH = $(PROOT)/ares
106endif
107
108ifeq ($(CURL_CC),)
109CURL_CC := $(CROSSPREFIX)gcc
110endif
111ifeq ($(CURL_AR),)
112CURL_AR := $(CROSSPREFIX)ar
113endif
114
115CC = $(CURL_CC)
116CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W
117CFLAGS += -fno-strict-aliasing
118# comment LDFLAGS below to keep debug info
119LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_EXE) -s
120RC = $(CROSSPREFIX)windres
121RCFLAGS = --include-dir=$(PROOT)/include -O coff
122
123# Set environment var ARCH to your architecture to override autodetection.
124ifndef ARCH
125ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
126ARCH = w64
127else
128ARCH = w32
129endif
130endif
131
132ifeq ($(ARCH),w64)
133CFLAGS  += -m64 -D_AMD64_
134LDFLAGS += -m64
135RCFLAGS += -F pe-x86-64
136else
137CFLAGS  += -m32
138LDFLAGS += -m32
139RCFLAGS += -F pe-i386
140endif
141
142# Platform-dependent helper tool macros
143ifeq ($(findstring /sh,$(SHELL)),/sh)
144DEL     = rm -f $1
145RMDIR   = rm -fr $1
146MKDIR   = mkdir -p $1
147COPY    = -cp -afv $1 $2
148#COPYR  = -cp -afr $1/* $2
149COPYR   = -rsync -aC $1/* $2
150TOUCH   = touch $1
151CAT     = cat
152ECHONL  = echo ""
153DL = '
154else
155ifeq "$(OS)" "Windows_NT"
156DEL     = -del 2>NUL /q /f $(subst /,\,$1)
157RMDIR   = -rd 2>NUL /q /s $(subst /,\,$1)
158else
159DEL     = -del 2>NUL $(subst /,\,$1)
160RMDIR   = -deltree 2>NUL /y $(subst /,\,$1)
161endif
162MKDIR   = -md 2>NUL $(subst /,\,$1)
163COPY    = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
164COPYR   = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
165TOUCH   = copy 2>&1>NUL /b $(subst /,\,$1) +,,
166CAT     = type
167ECHONL  = $(ComSpec) /c echo.
168endif
169
170########################################################
171## Nothing more to do below this line!
172
173ifeq ($(findstring -dyn,$(CFG)),-dyn)
174DYN = 1
175endif
176ifeq ($(findstring -ares,$(CFG)),-ares)
177ARES = 1
178endif
179ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
180RTMP = 1
181SSL = 1
182ZLIB = 1
183endif
184ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
185SSH2 = 1
186SSL = 1
187ZLIB = 1
188endif
189ifeq ($(findstring -ssl,$(CFG)),-ssl)
190SSL = 1
191endif
192ifeq ($(findstring -zlib,$(CFG)),-zlib)
193ZLIB = 1
194endif
195ifeq ($(findstring -zstd,$(CFG)),-zstd)
196ZSTD = 1
197endif
198ifeq ($(findstring -brotli,$(CFG)),-brotli)
199BROTLI = 1
200endif
201ifeq ($(findstring -gsasl,$(CFG)),-gsasl)
202GSASL = 1
203endif
204ifeq ($(findstring -idn2,$(CFG)),-idn2)
205IDN2 = 1
206endif
207ifeq ($(findstring -winidn,$(CFG)),-winidn)
208WINIDN = 1
209endif
210ifeq ($(findstring -sspi,$(CFG)),-sspi)
211SSPI = 1
212endif
213ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
214LDAPS = 1
215endif
216ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
217IPV6 = 1
218endif
219ifeq ($(findstring -winssl,$(CFG)),-winssl)
220WINSSL = 1
221SSPI = 1
222endif
223ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
224NGHTTP2 = 1
225endif
226ifeq ($(findstring -nghttp3,$(CFG)),-nghttp3)
227NGHTTP3 = 1
228endif
229ifeq ($(findstring -ngtcp2,$(CFG)),-ngtcp2)
230NGTCP2 = 1
231endif
232
233INCLUDES = -I. -I$(PROOT) -I$(PROOT)/include -I$(PROOT)/lib
234
235ifdef DYN
236  curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll
237  curl_LDADD = -L$(PROOT)/lib -lcurldll
238else
239  curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a
240  curl_LDADD = -L$(PROOT)/lib -lcurl
241  CFLAGS += -DCURL_STATICLIB
242  LDFLAGS += -static
243endif
244ifdef ARES
245  ifndef DYN
246    curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a
247  endif
248  CFLAGS += -DUSE_ARES
249  curl_LDADD += -L"$(LIBCARES_PATH)" -lcares
250endif
251ifdef RTMP
252  CFLAGS += -DUSE_LIBRTMP
253  curl_LDADD += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
254endif
255ifdef NGHTTP2
256  CFLAGS += -DUSE_NGHTTP2
257  curl_LDADD += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
258endif
259ifdef SSH2
260  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
261  curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2
262  ifdef WINSSL
263    ifndef DYN
264      curl_LDADD += -lbcrypt -lcrypt32
265    endif
266  endif
267endif
268ifdef SSL
269  ifdef NGHTTP3
270    CFLAGS += -DUSE_NGHTTP3
271    curl_LDADD += -L"$(NGHTTP3_PATH)/lib" -lnghttp3
272    ifdef NGTCP2
273      CFLAGS += -DUSE_NGTCP2
274      curl_LDADD += -L"$(NGTCP2_PATH)/lib" -lngtcp2 -lngtcp2_crypto_openssl
275    endif
276  endif
277
278  ifndef OPENSSL_INCLUDE
279    ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
280      OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
281    endif
282    ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
283      OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
284    endif
285  endif
286  ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
287  $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
288  endif
289  ifndef OPENSSL_LIBPATH
290    OPENSSL_LIBS = -lssl -lcrypto
291    ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
292      OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
293      ifdef DYN
294        OPENSSL_LIBS = -lssl32 -leay32
295      endif
296    endif
297    ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
298      OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
299    endif
300  endif
301  ifndef DYN
302    OPENSSL_LIBS += -lgdi32 -lcrypt32
303  endif
304  INCLUDES += -I"$(OPENSSL_INCLUDE)"
305  CFLAGS += -DUSE_OPENSSL
306  curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
307endif
308ifdef WINSSL
309  CFLAGS += -DUSE_SCHANNEL
310  curl_LDADD += -lcrypt32
311endif
312ifdef ZLIB
313  INCLUDES += -I"$(ZLIB_PATH)"
314  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
315  curl_LDADD += -L"$(ZLIB_PATH)" -lz
316endif
317ifdef ZSTD
318  INCLUDES += -I"$(ZSTD_PATH)/include"
319  CFLAGS += -DHAVE_ZSTD
320  curl_LDADD += -L"$(ZSTD_PATH)/lib"
321  ifdef ZSTD_LIBS
322    curl_LDADD += $(ZSTD_LIBS)
323  else
324    curl_LDADD += -lzstd
325  endif
326endif
327ifdef BROTLI
328  INCLUDES += -I"$(BROTLI_PATH)/include"
329  CFLAGS += -DHAVE_BROTLI
330  curl_LDADD += -L"$(BROTLI_PATH)/lib"
331  ifdef BROTLI_LIBS
332    curl_LDADD += $(BROTLI_LIBS)
333  else
334    curl_LDADD += -lbrotlidec
335  endif
336endif
337ifdef GSASL
338  CFLAGS += -DUSE_GSASL
339  curl_LDADD += -L"$(LIBGSASL_PATH)/lib" -lgsasl
340endif
341ifdef IDN2
342  CFLAGS += -DUSE_LIBIDN2
343  curl_LDADD += -L"$(LIBIDN2_PATH)/lib" -lidn2
344else
345ifdef WINIDN
346  CFLAGS += -DUSE_WIN32_IDN
347  curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz
348endif
349endif
350ifdef SSPI
351  CFLAGS += -DUSE_WINDOWS_SSPI
352endif
353ifdef IPV6
354  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
355endif
356ifdef LDAPS
357  CFLAGS += -DHAVE_LDAP_SSL
358endif
359ifdef USE_LDAP_NOVELL
360  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
361  curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
362endif
363ifdef USE_LDAP_OPENLDAP
364  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
365  curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber
366endif
367ifndef USE_LDAP_NOVELL
368ifndef USE_LDAP_OPENLDAP
369  curl_LDADD += -lwldap32
370endif
371endif
372curl_LDADD += -lws2_32
373
374# Makefile.inc provides the check_PROGRAMS and COMPLICATED_EXAMPLES defines
375include Makefile.inc
376
377check_PROGRAMS := $(patsubst %,%.exe,$(strip $(check_PROGRAMS)))
378check_PROGRAMS += ftpuploadresume.exe synctime.exe
379
380.PRECIOUS: %.o
381
382
383all: $(check_PROGRAMS)
384
385%.exe: %.o $(curl_DEPENDENCIES)
386	$(CC) $(LDFLAGS) -o $@ $< $(curl_LDADD)
387
388%.o: %.c
389	$(CC) $(INCLUDES) $(CFLAGS) -c $<
390
391%.res: %.rc
392	$(RC) $(RCFLAGS) -i $< -o $@
393
394clean:
395	@$(call DEL, $(check_PROGRAMS:.exe=.o))
396
397distclean vclean: clean
398	@$(call DEL, $(check_PROGRAMS))
399