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