#*************************************************************************** # _ _ ____ _ # Project ___| | | | _ \| | # / __| | | | |_) | | # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # # Copyright (C) 1999 - 2022, Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at https://curl.se/docs/copyright.html. # # You may opt to use, copy, modify, merge, publish, distribute and/or sell # copies of the Software, and permit persons to whom the Software is # furnished to do so, under the terms of the COPYING file. # # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY # KIND, either express or implied. # # SPDX-License-Identifier: curl # #*************************************************************************** # Makefile for building libcurl with MinGW and optional features. # # Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...] # Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn # # Set component roots via envvar _PATH. CPPFLAGS, LDFLAGS, LIBS, # CFLAGS, RCFLAGS (and more) are also available for customization. PROOT := .. CPPFLAGS += -I. -I$(PROOT)/include -DBUILDING_LIBCURL RCFLAGS += -I$(PROOT)/include ifneq ($(ARCH),custom) # Set environment var ARCH to your architecture to override autodetection. ifndef ARCH ifneq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),) ARCH := w64 else ARCH := w32 endif endif ifeq ($(ARCH),w64) CFLAGS += -m64 LDFLAGS += -m64 RCFLAGS += --target=pe-x86-64 else CFLAGS += -m32 LDFLAGS += -m32 RCFLAGS += --target=pe-i386 endif endif ### Optional features ifneq ($(findstring -unicode,$(CFG)),) CPPFLAGS += -DUNICODE -D_UNICODE endif ifneq ($(findstring -sync,$(CFG)),) CPPFLAGS += -DUSE_SYNC_DNS else ifneq ($(findstring -ares,$(CFG)),) LIBCARES_PATH ?= $(PROOT)/../c-ares CPPFLAGS += -DUSE_ARES CPPFLAGS += -I"$(LIBCARES_PATH)/include" LDFLAGS += -L"$(LIBCARES_PATH)/lib" LIBS += -lcares endif endif ifneq ($(findstring -rtmp,$(CFG)),) LIBRTMP_PATH ?= $(PROOT)/../librtmp CPPFLAGS += -DUSE_LIBRTMP CPPFLAGS += -I"$(LIBRTMP_PATH)" LDFLAGS += -L"$(LIBRTMP_PATH)/librtmp" LIBS += -lrtmp -lwinmm ZLIB := 1 endif ifneq ($(findstring -ssh2,$(CFG)),) LIBSSH2_PATH ?= $(PROOT)/../libssh2 CPPFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H CPPFLAGS += -I"$(LIBSSH2_PATH)/include" LDFLAGS += -L"$(LIBSSH2_PATH)/lib" LDFLAGS += -L"$(LIBSSH2_PATH)/win32" LIBS += -lssh2 endif ifneq ($(findstring -nghttp2,$(CFG)),) NGHTTP2_PATH ?= $(PROOT)/../nghttp2 CPPFLAGS += -DUSE_NGHTTP2 CPPFLAGS += -I"$(NGHTTP2_PATH)/include" LDFLAGS += -L"$(NGHTTP2_PATH)/lib" LIBS += -lnghttp2 endif ifneq ($(findstring -nghttp3,$(CFG)),) ifneq ($(findstring -ngtcp2,$(CFG)),) NGHTTP3_PATH ?= $(PROOT)/../nghttp3 CPPFLAGS += -DUSE_NGHTTP3 CPPFLAGS += -I"$(NGHTTP3_PATH)/include" LDFLAGS += -L"$(NGHTTP3_PATH)/lib" LIBS += -lnghttp3 NGTCP2_PATH ?= $(PROOT)/../ngtcp2 CPPFLAGS += -DUSE_NGTCP2 CPPFLAGS += -I"$(NGTCP2_PATH)/include" LDFLAGS += -L"$(NGTCP2_PATH)/lib" NGTCP2_LIBS ?= -lngtcp2 -lngtcp2_crypto_openssl LIBS += $(NGTCP2_LIBS) endif endif ifneq ($(findstring -ssl,$(CFG)),) OPENSSL_PATH ?= $(PROOT)/../openssl CPPFLAGS += -DUSE_OPENSSL CPPFLAGS += -DCURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG OPENSSL_INCLUDE ?= $(OPENSSL_PATH)/include CPPFLAGS += -I"$(OPENSSL_INCLUDE)" OPENSSL_LIBPATH ?= $(OPENSSL_PATH)/lib LDFLAGS += -L"$(OPENSSL_LIBPATH)" OPENSSL_LIBS ?= -lssl -lcrypto LIBS += $(OPENSSL_LIBS) ifneq ($(findstring -srp,$(CFG)),) ifeq "$(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h)" "$(OPENSSL_INCLUDE)/openssl/srp.h" # OpenSSL 1.0.1 and later, except BoringSSL CPPFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP endif endif SSL := 1 endif ifneq ($(findstring -schannel,$(CFG)),) CPPFLAGS += -DUSE_SCHANNEL ifdef SSL CPPFLAGS += -DCURL_WITH_MULTI_SSL endif endif ifneq ($(findstring -zlib,$(CFG))$(ZLIB),) ZLIB_PATH ?= $(PROOT)/../zlib CPPFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H CPPFLAGS += -I"$(ZLIB_PATH)" LDFLAGS += -L"$(ZLIB_PATH)" LIBS += -lz endif ifneq ($(findstring -zstd,$(CFG)),) ZSTD_PATH ?= $(PROOT)/../zstd CPPFLAGS += -DHAVE_ZSTD CPPFLAGS += -I"$(ZSTD_PATH)/include" LDFLAGS += -L"$(ZSTD_PATH)/lib" ZSTD_LIBS ?= -lzstd LIBS += $(ZSTD_LIBS) endif ifneq ($(findstring -brotli,$(CFG)),) BROTLI_PATH ?= $(PROOT)/../brotli CPPFLAGS += -DHAVE_BROTLI CPPFLAGS += -I"$(BROTLI_PATH)/include" LDFLAGS += -L"$(BROTLI_PATH)/lib" BROTLI_LIBS ?= -lbrotlidec -lbrotlicommon LIBS += $(BROTLI_LIBS) endif ifneq ($(findstring -gsasl,$(CFG)),) LIBGSASL_PATH ?= $(PROOT)/../gsasl CPPFLAGS += -DUSE_GSASL CPPFLAGS += -I"$(LIBGSASL_PATH)/include" LDFLAGS += -L"$(LIBGSASL_PATH)/lib" LIBS += -lgsasl endif ifneq ($(findstring -idn2,$(CFG)),) LIBIDN2_PATH ?= $(PROOT)/../libidn2 CPPFLAGS += -DUSE_LIBIDN2 CPPFLAGS += -I"$(LIBIDN2_PATH)/include" LDFLAGS += -L"$(LIBIDN2_PATH)/lib" LIBS += -lidn2 else ifneq ($(findstring -winidn,$(CFG)),) CPPFLAGS += -DUSE_WIN32_IDN CPPFLAGS += -DWANT_IDN_PROTOTYPES LIBS += -lnormaliz endif endif ifneq ($(findstring -sspi,$(CFG)),) CPPFLAGS += -DUSE_WINDOWS_SSPI endif ifneq ($(findstring -ipv6,$(CFG)),) CPPFLAGS += -DENABLE_IPV6 endif ifneq ($(findstring -ldaps,$(CFG)),) CPPFLAGS += -DHAVE_LDAP_SSL endif ifeq ($(findstring -lldap,$(LIBS)),) LIBS += -lwldap32 endif LIBS += -lws2_32 -lcrypt32 -lbcrypt ### Sources and targets # Provides CSOURCES and HHEADERS include Makefile.inc libcurl_dll_LIBRARY := libcurl$(CURL_DLL_SUFFIX).dll libcurl_dll_a_LIBRARY := libcurl.dll.a libcurl_a_LIBRARY := libcurl.a libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES))) libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS)) RESOURCE := libcurl.res ### Rules CC ?= $(CROSSPREFIX)gcc RC ?= $(CROSSPREFIX)windres AR ?= $(CROSSPREFIX)ar ifneq ($(findstring /sh,$(SHELL)),) DEL = rm -f $1 else DEL = -del 2>NUL /q /f $(subst /,\,$1) endif all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES) @$(call DEL, $@) $(AR) rcs $@ $(libcurl_a_OBJECTS) $(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(CC) $(LDFLAGS) -shared $(CURL_LDFLAGS_LIB) -o $@ $(libcurl_a_OBJECTS) $(RESOURCE) $(LIBS) \ -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY) %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ %.res: %.rc $(RC) -O coff $(RCFLAGS) -i $< -o $@ clean: @$(call DEL, $(libcurl_a_OBJECTS) $(RESOURCE)) distclean vclean: clean @$(call DEL, $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY))