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 libcurl.a 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 libgsasl package. 63ifndef LIBGSASL_PATH 64LIBGSASL_PATH = ../../libgsasl-1.10.0 65endif 66# Edit the path below to point to the base of your libidn2 package. 67ifndef LIBIDN2_PATH 68LIBIDN2_PATH = ../../libidn2-2.0.3 69endif 70# Edit the path below to point to the base of your MS IDN package. 71# Microsoft Internationalized Domain Names (IDN) Mitigation APIs 1.1 72# https://www.microsoft.com/en-us/download/details.aspx?id=734 73ifndef WINIDN_PATH 74WINIDN_PATH = ../../Microsoft IDN Mitigation APIs 75endif 76# Edit the path below to point to the base of your Novell LDAP NDK. 77ifndef LDAP_SDK 78LDAP_SDK = c:/novell/ndk/cldapsdk/win32 79endif 80# Edit the path below to point to the base of your nghttp2 package. 81ifndef NGHTTP2_PATH 82NGHTTP2_PATH = ../../nghttp2-1.0.0 83endif 84# Edit the path below to point to the base of your nghttp3 package. 85ifndef NGHTTP3_PATH 86NGHTTP3_PATH = ../../nghttp3-1.0.0 87endif 88# Edit the path below to point to the base of your ngtcp2 package. 89ifndef NGTCP2_PATH 90NGTCP2_PATH = ../../ngtcp2-1.0.0 91endif 92 93PROOT = .. 94 95# Edit the path below to point to the base of your c-ares package. 96ifndef LIBCARES_PATH 97LIBCARES_PATH = $(PROOT)/ares 98endif 99 100ifeq ($(CURL_CC),) 101CURL_CC := $(CROSSPREFIX)gcc 102endif 103ifeq ($(CURL_AR),) 104CURL_AR := $(CROSSPREFIX)ar 105endif 106ifeq ($(CURL_RANLIB),) 107CURL_RANLIB := $(CROSSPREFIX)ranlib 108endif 109 110CC = $(CURL_CC) 111CFLAGS = $(CURL_CFLAG_EXTRAS) -g -O2 -Wall -W 112CFLAGS += -fno-strict-aliasing 113# comment LDFLAGS below to keep debug info 114LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_DLL) -s 115AR = $(CURL_AR) 116RANLIB = $(CURL_RANLIB) 117RC = $(CROSSPREFIX)windres 118RCFLAGS = --include-dir=$(PROOT)/include -DDEBUGBUILD=0 -O coff 119STRIP = $(CROSSPREFIX)strip -g 120 121# Set environment var ARCH to your architecture to override autodetection. 122ifndef ARCH 123ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64) 124ARCH = w64 125else 126ARCH = w32 127endif 128endif 129 130ifeq ($(ARCH),w64) 131CFLAGS += -m64 -D_AMD64_ 132LDFLAGS += -m64 133RCFLAGS += -F pe-x86-64 134else 135CFLAGS += -m32 136LDFLAGS += -m32 137RCFLAGS += -F pe-i386 138endif 139 140# Platform-dependent helper tool macros 141ifeq ($(findstring /sh,$(SHELL)),/sh) 142DEL = rm -f $1 143RMDIR = rm -fr $1 144MKDIR = mkdir -p $1 145COPY = -cp -afv $1 $2 146#COPYR = -cp -afr $1/* $2 147COPYR = -rsync -aC $1/* $2 148TOUCH = touch $1 149CAT = cat 150ECHONL = echo "" 151DL = ' 152else 153ifeq "$(OS)" "Windows_NT" 154DEL = -del 2>NUL /q /f $(subst /,\,$1) 155RMDIR = -rd 2>NUL /q /s $(subst /,\,$1) 156else 157DEL = -del 2>NUL $(subst /,\,$1) 158RMDIR = -deltree 2>NUL /y $(subst /,\,$1) 159endif 160MKDIR = -md 2>NUL $(subst /,\,$1) 161COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2) 162COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2) 163TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,, 164CAT = type 165ECHONL = $(ComSpec) /c echo. 166endif 167 168######################################################## 169## Nothing more to do below this line! 170 171ifeq ($(findstring -dyn,$(CFG)),-dyn) 172DYN = 1 173endif 174ifeq ($(findstring -ares,$(CFG)),-ares) 175ARES = 1 176endif 177ifeq ($(findstring -sync,$(CFG)),-sync) 178SYNC = 1 179endif 180ifeq ($(findstring -rtmp,$(CFG)),-rtmp) 181RTMP = 1 182ZLIB = 1 183endif 184ifeq ($(findstring -ssh2,$(CFG)),-ssh2) 185SSH2 = 1 186ZLIB = 1 187endif 188ifeq ($(findstring -ssl,$(CFG)),-ssl) 189SSL = 1 190endif 191ifeq ($(findstring -srp,$(CFG)),-srp) 192SRP = 1 193endif 194ifeq ($(findstring -zlib,$(CFG)),-zlib) 195ZLIB = 1 196endif 197ifeq ($(findstring -zstd,$(CFG)),-zstd) 198ZSTD = 1 199endif 200ifeq ($(findstring -brotli,$(CFG)),-brotli) 201BROTLI = 1 202endif 203ifeq ($(findstring -gsasl,$(CFG)),-gsasl) 204GSASL = 1 205endif 206ifeq ($(findstring -idn2,$(CFG)),-idn2) 207IDN2 = 1 208endif 209ifeq ($(findstring -winidn,$(CFG)),-winidn) 210WINIDN = 1 211endif 212ifeq ($(findstring -sspi,$(CFG)),-sspi) 213SSPI = 1 214endif 215ifeq ($(findstring -ldaps,$(CFG)),-ldaps) 216LDAPS = 1 217endif 218ifeq ($(findstring -ipv6,$(CFG)),-ipv6) 219IPV6 = 1 220endif 221ifeq ($(findstring -winssl,$(CFG)),-winssl) 222WINSSL = 1 223SSPI = 1 224endif 225ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2) 226NGHTTP2 = 1 227endif 228ifeq ($(findstring -nghttp3,$(CFG)),-nghttp3) 229NGHTTP3 = 1 230endif 231ifeq ($(findstring -ngtcp2,$(CFG)),-ngtcp2) 232NGTCP2 = 1 233endif 234ifeq ($(findstring -unicode,$(CFG)),-unicode) 235UNICODE = 1 236endif 237 238# SSH2 and RTMP require an SSL library; assume OpenSSL if none specified 239ifneq ($(SSH2)$(RTMP),) 240 ifeq ($(SSL)$(WINSSL),) 241 SSL = 1 242 endif 243endif 244 245INCLUDES = -I. -I../include 246CFLAGS += -DBUILDING_LIBCURL 247ifdef SSL 248 ifdef WINSSL 249 CFLAGS += -DCURL_WITH_MULTI_SSL 250 endif 251endif 252ifdef UNICODE 253 CFLAGS += -DUNICODE -D_UNICODE 254endif 255 256ifdef SYNC 257 CFLAGS += -DUSE_SYNC_DNS 258else 259 ifdef ARES 260 INCLUDES += -I"$(LIBCARES_PATH)" 261 CFLAGS += -DUSE_ARES -DCARES_STATICLIB 262 DLL_LIBS += -L"$(LIBCARES_PATH)" -lcares 263 libcurl_dll_DEPENDENCIES = $(LIBCARES_PATH)/libcares.a 264 endif 265endif 266ifdef RTMP 267 INCLUDES += -I"$(LIBRTMP_PATH)" 268 CFLAGS += -DUSE_LIBRTMP 269 DLL_LIBS += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm 270endif 271ifdef NGHTTP2 272 INCLUDES += -I"$(NGHTTP2_PATH)/include" 273 CFLAGS += -DUSE_NGHTTP2 274 DLL_LIBS += -L"$(NGHTTP2_PATH)/lib" -lnghttp2 275endif 276ifdef SSH2 277 INCLUDES += -I"$(LIBSSH2_PATH)/include" -I"$(LIBSSH2_PATH)/win32" 278 CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H 279 DLL_LIBS += -L"$(LIBSSH2_PATH)/win32" -lssh2 280 ifdef WINSSL 281 ifndef DYN 282 DLL_LIBS += -lbcrypt -lcrypt32 283 endif 284 endif 285endif 286ifdef SSL 287 ifdef NGHTTP3 288 INCLUDES += -I"$(NGHTTP3_PATH)/include" 289 CFLAGS += -DUSE_NGHTTP3 290 DLL_LIBS += -L"$(NGHTTP3_PATH)/lib" -lnghttp3 291 ifdef NGTCP2 292 INCLUDES += -I"$(NGTCP2_PATH)/include" 293 CFLAGS += -DUSE_NGTCP2 294 DLL_LIBS += -L"$(NGTCP2_PATH)/lib" -lngtcp2 -lngtcp2_crypto_openssl 295 endif 296 endif 297 298 ifndef OPENSSL_INCLUDE 299 ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc" 300 OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc 301 endif 302 ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include" 303 OPENSSL_INCLUDE = $(OPENSSL_PATH)/include 304 endif 305 endif 306 ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h" 307 $(error Invalid path to OpenSSL package: $(OPENSSL_PATH)) 308 endif 309 ifndef OPENSSL_LIBPATH 310 ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out" 311 OPENSSL_LIBPATH = $(OPENSSL_PATH)/out 312 OPENSSL_LIBS = -leay32 -lssl32 313 endif 314 ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib" 315 OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib 316 OPENSSL_LIBS = -lcrypto -lssl 317 endif 318 endif 319 ifndef DYN 320 OPENSSL_LIBS += -lgdi32 -lcrypt32 321 endif 322 INCLUDES += -I"$(OPENSSL_INCLUDE)" 323 CFLAGS += -DUSE_OPENSSL -DHAVE_OPENSSL_PKCS12_H \ 324 -DOPENSSL_NO_KRB5 325 DLL_LIBS += -L"$(OPENSSL_LIBPATH)" $(OPENSSL_LIBS) 326 ifdef SRP 327 ifeq "$(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h)" "$(OPENSSL_INCLUDE)/openssl/srp.h" 328 CFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP 329 endif 330 endif 331endif 332ifdef WINSSL 333 CFLAGS += -DUSE_SCHANNEL 334 DLL_LIBS += -lcrypt32 335endif 336ifdef ZLIB 337 INCLUDES += -I"$(ZLIB_PATH)" 338 CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H 339 DLL_LIBS += -L"$(ZLIB_PATH)" -lz 340endif 341ifdef ZSTD 342 INCLUDES += -I"$(ZSTD_PATH)/include" 343 CFLAGS += -DHAVE_ZSTD 344 DLL_LIBS += -L"$(ZSTD_PATH)/lib" 345 ifdef ZSTD_LIBS 346 DLL_LIBS += $(ZSTD_LIBS) 347 else 348 DLL_LIBS += -lzstd 349 endif 350endif 351ifdef BROTLI 352 INCLUDES += -I"$(BROTLI_PATH)/include" 353 CFLAGS += -DHAVE_BROTLI 354 DLL_LIBS += -L"$(BROTLI_PATH)/lib" 355 ifdef BROTLI_LIBS 356 DLL_LIBS += $(BROTLI_LIBS) 357 else 358 DLL_LIBS += -lbrotlidec 359 endif 360endif 361ifdef GSASL 362 INCLUDES += -I"$(LIBGSASL_PATH)/include" 363 CFLAGS += -DUSE_GSASL 364 DLL_LIBS += -L"$(LIBGSASL_PATH)/lib" -lgsasl 365endif 366ifdef IDN2 367 INCLUDES += -I"$(LIBIDN2_PATH)/include" 368 CFLAGS += -DUSE_LIBIDN2 369 DLL_LIBS += -L"$(LIBIDN2_PATH)/lib" -lidn2 370else 371ifdef WINIDN 372 CFLAGS += -DUSE_WIN32_IDN 373 CFLAGS += -DWANT_IDN_PROTOTYPES 374 DLL_LIBS += -L"$(WINIDN_PATH)" -lnormaliz 375endif 376endif 377ifdef SSPI 378 CFLAGS += -DUSE_WINDOWS_SSPI 379endif 380ifdef SPNEGO 381 CFLAGS += -DHAVE_SPNEGO 382endif 383ifdef IPV6 384 CFLAGS += -DENABLE_IPV6 -D_WIN32_WINNT=0x0501 385endif 386ifdef LDAPS 387 CFLAGS += -DHAVE_LDAP_SSL 388endif 389ifdef USE_LDAP_NOVELL 390 INCLUDES += -I"$(LDAP_SDK)/inc" 391 CFLAGS += -DCURL_HAS_NOVELL_LDAPSDK 392 DLL_LIBS += -L"$(LDAP_SDK)/lib/mscvc" -lldapsdk -lldapssl -lldapx 393endif 394ifdef USE_LDAP_OPENLDAP 395 INCLUDES += -I"$(LDAP_SDK)/include" 396 CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK 397 DLL_LIBS += -L"$(LDAP_SDK)/lib" -lldap -llber 398endif 399ifndef USE_LDAP_NOVELL 400ifndef USE_LDAP_OPENLDAP 401 DLL_LIBS += -lwldap32 402endif 403endif 404DLL_LIBS += -lws2_32 405 406# Makefile.inc provides the CSOURCES and HHEADERS defines 407include Makefile.inc 408 409ifeq ($(CURL_DLL_A_SUFFIX),) 410CURL_DLL_A_SUFFIX := dll 411endif 412 413libcurl_dll_LIBRARY = libcurl$(CURL_DLL_SUFFIX).dll 414libcurl_dll_a_LIBRARY = libcurl$(CURL_DLL_A_SUFFIX).a 415libcurl_a_LIBRARY = libcurl.a 416 417libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES))) 418libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS)) 419 420RESOURCE = libcurl.res 421 422 423all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) 424 425$(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES) 426 @$(call DEL, $@) 427 $(AR) cru $@ $(libcurl_a_OBJECTS) 428 $(RANLIB) $@ 429 $(STRIP) $@ 430 431# remove the last line above to keep debug info 432 433$(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(libcurl_dll_DEPENDENCIES) 434 @$(call DEL, $@) 435 $(CC) $(LDFLAGS) -shared -o $@ \ 436 -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY) \ 437 $(libcurl_a_OBJECTS) $(RESOURCE) $(DLL_LIBS) 438 439%.o: %.c 440 $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ 441 442%.res: %.rc 443 $(RC) $(RCFLAGS) -i $< -o $@ 444 445clean: 446 @$(call DEL, $(libcurl_a_OBJECTS) $(RESOURCE)) 447 448distclean vclean: clean 449 @$(call DEL, $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY)) 450 451$(LIBCARES_PATH)/libcares.a: 452 $(MAKE) -C $(LIBCARES_PATH) -f Makefile.m32 453