• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) 1999 - 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.exe with MingW (GCC-3.2 or later or LLVM/Clang)
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
120AR = $(CURL_AR)
121RC = $(CROSSPREFIX)windres
122RCFLAGS = --include-dir=$(PROOT)/include -O coff -DCURL_EMBED_MANIFEST
123STRIP   = $(CROSSPREFIX)strip -g
124
125# We may need these someday
126# PERL = perl
127# NROFF = nroff
128
129# Set environment var ARCH to your architecture to override autodetection.
130ifndef ARCH
131ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
132ARCH = w64
133else
134ARCH = w32
135endif
136endif
137
138ifeq ($(ARCH),w64)
139CFLAGS  += -m64 -D_AMD64_
140LDFLAGS += -m64
141RCFLAGS += -F pe-x86-64
142else
143CFLAGS  += -m32
144LDFLAGS += -m32
145RCFLAGS += -F pe-i386
146endif
147
148# Platform-dependent helper tool macros
149ifeq ($(findstring /sh,$(SHELL)),/sh)
150DEL     = rm -f $1
151RMDIR   = rm -fr $1
152MKDIR   = mkdir -p $1
153COPY    = -cp -afv $1 $2
154#COPYR  = -cp -afr $1/* $2
155COPYR   = -rsync -aC $1/* $2
156TOUCH   = touch $1
157CAT     = cat
158ECHONL  = echo ""
159DL = '
160else
161ifeq "$(OS)" "Windows_NT"
162DEL     = -del 2>NUL /q /f $(subst /,\,$1)
163RMDIR   = -rd 2>NUL /q /s $(subst /,\,$1)
164else
165DEL     = -del 2>NUL $(subst /,\,$1)
166RMDIR   = -deltree 2>NUL /y $(subst /,\,$1)
167endif
168MKDIR   = -md 2>NUL $(subst /,\,$1)
169COPY    = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
170COPYR   = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
171TOUCH   = copy 2>&1>NUL /b $(subst /,\,$1) +,,
172CAT     = type
173ECHONL  = $(ComSpec) /c echo.
174endif
175
176########################################################
177## Nothing more to do below this line!
178
179ifeq ($(findstring -dyn,$(CFG)),-dyn)
180DYN = 1
181endif
182ifeq ($(findstring -ares,$(CFG)),-ares)
183ARES = 1
184endif
185ifeq ($(findstring -sync,$(CFG)),-sync)
186SYNC = 1
187endif
188ifeq ($(findstring -rtmp,$(CFG)),-rtmp)
189RTMP = 1
190SSL = 1
191ZLIB = 1
192endif
193ifeq ($(findstring -ssh2,$(CFG)),-ssh2)
194SSH2 = 1
195SSL = 1
196ZLIB = 1
197endif
198ifeq ($(findstring -ssl,$(CFG)),-ssl)
199SSL = 1
200endif
201ifeq ($(findstring -zlib,$(CFG)),-zlib)
202ZLIB = 1
203endif
204ifeq ($(findstring -zstd,$(CFG)),-zstd)
205ZSTD = 1
206endif
207ifeq ($(findstring -brotli,$(CFG)),-brotli)
208BROTLI = 1
209endif
210ifeq ($(findstring -gsasl,$(CFG)),-gsasl)
211GSASL = 1
212endif
213ifeq ($(findstring -idn2,$(CFG)),-idn2)
214IDN2 = 1
215endif
216ifeq ($(findstring -winidn,$(CFG)),-winidn)
217WINIDN = 1
218endif
219ifeq ($(findstring -sspi,$(CFG)),-sspi)
220SSPI = 1
221endif
222ifeq ($(findstring -ldaps,$(CFG)),-ldaps)
223LDAPS = 1
224endif
225ifeq ($(findstring -ipv6,$(CFG)),-ipv6)
226IPV6 = 1
227endif
228ifeq ($(findstring -winssl,$(CFG)),-winssl)
229WINSSL = 1
230SSPI = 1
231endif
232ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2)
233NGHTTP2 = 1
234endif
235ifeq ($(findstring -nghttp3,$(CFG)),-nghttp3)
236NGHTTP3 = 1
237endif
238ifeq ($(findstring -ngtcp2,$(CFG)),-ngtcp2)
239NGTCP2 = 1
240endif
241ifeq ($(findstring -unicode,$(CFG)),-unicode)
242UNICODE = 1
243endif
244
245INCLUDES = -I. -I../include -I../lib
246ifdef SSL
247  ifdef WINSSL
248    CFLAGS += -DCURL_WITH_MULTI_SSL
249  endif
250endif
251ifdef UNICODE
252  CFLAGS += -DUNICODE -D_UNICODE
253  LDFLAGS += -municode
254endif
255
256ifdef DYN
257  curl_DEPENDENCIES = $(PROOT)/lib/libcurldll.a $(PROOT)/lib/libcurl.dll
258  curl_LDADD = -L$(PROOT)/lib -lcurldll
259else
260  curl_DEPENDENCIES = $(PROOT)/lib/libcurl.a
261  curl_LDADD = -L$(PROOT)/lib -lcurl
262  CFLAGS += -DCURL_STATICLIB
263  LDFLAGS += -static
264endif
265ifdef SYNC
266  CFLAGS += -DUSE_SYNC_DNS
267else
268  ifdef ARES
269    ifndef DYN
270      curl_DEPENDENCIES += $(LIBCARES_PATH)/libcares.a
271    endif
272    CFLAGS += -DUSE_ARES -DCARES_STATICLIB
273    curl_LDADD += -L"$(LIBCARES_PATH)" -lcares
274  endif
275endif
276ifdef RTMP
277  CFLAGS += -DUSE_LIBRTMP
278  curl_LDADD += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
279endif
280ifdef NGHTTP2
281  CFLAGS += -DUSE_NGHTTP2
282  curl_LDADD += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
283endif
284ifdef SSH2
285  CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
286  curl_LDADD += -L"$(LIBSSH2_PATH)/win32" -lssh2
287  ifdef WINSSL
288    ifndef DYN
289      curl_LDADD += -lbcrypt -lcrypt32
290    endif
291  endif
292endif
293ifdef SSL
294  ifdef NGHTTP3
295    CFLAGS += -DUSE_NGHTTP3
296    curl_LDADD += -L"$(NGHTTP3_PATH)/lib" -lnghttp3
297    ifdef NGTCP2
298      CFLAGS += -DUSE_NGTCP2
299      curl_LDADD += -L"$(NGTCP2_PATH)/lib" -lngtcp2 -lngtcp2_crypto_openssl
300    endif
301  endif
302
303  ifndef OPENSSL_INCLUDE
304    ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
305      OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
306    endif
307    ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
308      OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
309    endif
310  endif
311  ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
312  $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
313  endif
314  ifndef OPENSSL_LIBPATH
315    OPENSSL_LIBS = -lssl -lcrypto
316    ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
317      OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
318      ifdef DYN
319        OPENSSL_LIBS = -lssl32 -leay32
320      endif
321    endif
322    ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
323      OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
324    endif
325  endif
326  ifndef DYN
327    OPENSSL_LIBS += -lgdi32 -lcrypt32
328  endif
329  INCLUDES += -I"$(OPENSSL_INCLUDE)"
330  CFLAGS += -DUSE_OPENSSL
331  curl_LDADD += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS)
332endif
333ifdef WINSSL
334  CFLAGS += -DUSE_SCHANNEL
335  curl_LDADD += -lcrypt32
336endif
337ifdef ZLIB
338  INCLUDES += -I"$(ZLIB_PATH)"
339  CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
340  curl_LDADD += -L"$(ZLIB_PATH)" -lz
341endif
342ifdef ZSTD
343  INCLUDES += -I"$(ZSTD_PATH)/include"
344  CFLAGS += -DHAVE_ZSTD
345  curl_LDADD += -L"$(ZSTD_PATH)/lib"
346  ifdef ZSTD_LIBS
347    curl_LDADD += $(ZSTD_LIBS)
348  else
349    curl_LDADD += -lzstd
350  endif
351endif
352ifdef BROTLI
353  INCLUDES += -I"$(BROTLI_PATH)/include"
354  CFLAGS += -DHAVE_BROTLI
355  curl_LDADD += -L"$(BROTLI_PATH)/lib"
356  ifdef BROTLI_LIBS
357    curl_LDADD += $(BROTLI_LIBS)
358  else
359    curl_LDADD += -lbrotlidec
360  endif
361endif
362ifdef GSASL
363  CFLAGS += -DUSE_GSASL
364  curl_LDADD += -L"$(LIBGSASL_PATH)/lib" -lgsasl
365endif
366ifdef IDN2
367  CFLAGS += -DUSE_LIBIDN2
368  curl_LDADD += -L"$(LIBIDN2_PATH)/lib" -lidn2
369else
370ifdef WINIDN
371  CFLAGS += -DUSE_WIN32_IDN
372  curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz
373endif
374endif
375ifdef SSPI
376  CFLAGS += -DUSE_WINDOWS_SSPI
377endif
378ifdef IPV6
379  CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501
380endif
381ifdef LDAPS
382  CFLAGS += -DHAVE_LDAP_SSL
383endif
384ifdef USE_LDAP_NOVELL
385  CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK
386  curl_LDADD += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx
387endif
388ifdef USE_LDAP_OPENLDAP
389  CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
390  curl_LDADD += -L"$(LDAP_SDK)/lib" -lldap -llber
391endif
392ifndef USE_LDAP_NOVELL
393ifndef USE_LDAP_OPENLDAP
394curl_LDADD += -lwldap32
395endif
396endif
397curl_LDADD += -lws2_32
398
399# Makefile.inc provides the CSOURCES and HHEADERS defines
400include Makefile.inc
401
402curl_PROGRAMS = curl.exe
403curl_OBJECTS := $(patsubst %.c,%.o,$(strip $(CURL_CFILES)))
404curlx_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CURLX_CFILES))))
405curl_OBJECTS += $(curlx_OBJECTS)
406vpath %.c $(PROOT)/lib
407
408RESOURCE = curl.res
409
410
411all: $(curl_PROGRAMS)
412
413curl.exe: $(RESOURCE) $(curl_OBJECTS) $(curl_DEPENDENCIES)
414	$(call DEL, $@)
415	$(CC) $(LDFLAGS) -o $@ $< $(curl_OBJECTS) $(curl_LDADD)
416
417# We don't have nroff normally under win32
418# tool_hugehelp.c: $(PROOT)/docs/MANUAL $(PROOT)/docs/curl.1 mkhelp.pl
419#	@$(call DEL, tool_hugehelp.c)
420# 	$(NROFF) -man $(PROOT)/docs/curl.1 | $(PERL) mkhelp.pl $(PROOT)/docs/MANUAL > tool_hugehelp.c
421
422tool_hugehelp.c:
423	@echo Creating $@
424	@$(call COPY, $@.cvs, $@)
425
426%.o: %.c
427	$(CC) $(INCLUDES) $(CFLAGS) -c $<
428
429%.res: %.rc
430	$(RC) $(RCFLAGS) -i $< -o $@
431
432clean:
433ifeq "$(wildcard tool_hugehelp.c.cvs)" "tool_hugehelp.c.cvs"
434	@$(call DEL, tool_hugehelp.c)
435endif
436	@$(call DEL, $(curl_OBJECTS) $(curlx_OBJECTS) $(RESOURCE))
437
438distclean vclean: clean
439	@$(call DEL, $(curl_PROGRAMS))
440