Makefile.m32 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1999 - 2022, 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. # SPDX-License-Identifier: curl
  22. #
  23. #***************************************************************************
  24. # Makefile for building curl parts with MinGW and optional features.
  25. #
  26. # Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
  27. # Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
  28. #
  29. # Set component roots via envvar <feature>_PATH. Also available for
  30. # customization: CC, RC, AR, CPPFLAGS, LDFLAGS, LIBS, CFLAGS, RCFLAGS,
  31. # ARCH[=custom], CROSSPREFIX, CURL_LDFLAGS_BIN, CURL_LDFLAGS_LIB, CURL_DLL_SUFFIX,
  32. # and more for individual components (see below).
  33. # This script is reused by 'src' and 'docs/examples' Makefile.m32 scripts.
  34. # Skip lib-specific parts when called through them.
  35. ifndef PROOT
  36. PROOT := ..
  37. CPPFLAGS += -DBUILDING_LIBCURL
  38. ### Sources and targets
  39. # Provides CSOURCES, HHEADERS, LIB_RCFILES
  40. include Makefile.inc
  41. libcurl_dll_LIBRARY := libcurl$(CURL_DLL_SUFFIX).dll
  42. libcurl_dll_a_LIBRARY := libcurl.dll.a
  43. libcurl_a_LIBRARY := libcurl.a
  44. TARGETS := $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY)
  45. libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CSOURCES))))
  46. libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
  47. libcurl_dll_OBJECTS := $(libcurl_a_OBJECTS)
  48. libcurl_dll_OBJECTS += $(patsubst %.rc,%.res,$(strip $(LIB_RCFILES)))
  49. vpath %.c vauth vquic vssh vtls
  50. TOCLEAN := $(libcurl_dll_OBJECTS)
  51. TOVCLEAN := $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY)
  52. ### Local rules
  53. # Keep this at the top to act as the default target.
  54. all: $(TARGETS)
  55. $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
  56. @$(call DEL, $@)
  57. $(AR) rcs $@ $(libcurl_a_OBJECTS)
  58. $(libcurl_dll_LIBRARY): $(libcurl_dll_OBJECTS)
  59. $(CC) $(LDFLAGS) -shared $(CURL_LDFLAGS_LIB) -o $@ $(libcurl_dll_OBJECTS) $(LIBS) \
  60. -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY)
  61. endif
  62. CPPFLAGS += -I. -I$(PROOT)/include
  63. RCFLAGS += -I$(PROOT)/include
  64. CC := $(CROSSPREFIX)$(CC)
  65. AR := $(CROSSPREFIX)$(AR)
  66. RC ?= $(CROSSPREFIX)windres
  67. ifneq ($(ARCH),custom)
  68. # Set environment var ARCH to your architecture to override auto-detection.
  69. ifndef ARCH
  70. ifneq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),)
  71. ARCH := w64
  72. else
  73. ARCH := w32
  74. endif
  75. endif
  76. ifeq ($(ARCH),w64)
  77. CFLAGS += -m64
  78. LDFLAGS += -m64
  79. RCFLAGS += --target=pe-x86-64
  80. else
  81. CFLAGS += -m32
  82. LDFLAGS += -m32
  83. RCFLAGS += --target=pe-i386
  84. endif
  85. endif
  86. ### Optional features
  87. ifneq ($(findstring -unicode,$(CFG)),)
  88. CPPFLAGS += -DUNICODE -D_UNICODE
  89. CURL_LDFLAGS_BIN += -municode
  90. endif
  91. # CPPFLAGS below are only necessary when building libcurl via 'lib' (see
  92. # comments below about exceptions). Always include them anyway to match
  93. # behavior of other build systems.
  94. # Linker options to exclude for shared mode executables.
  95. _LDFLAGS :=
  96. _LIBS :=
  97. ifneq ($(findstring -sync,$(CFG)),)
  98. CPPFLAGS += -DUSE_SYNC_DNS
  99. else ifneq ($(findstring -ares,$(CFG)),)
  100. LIBCARES_PATH ?= $(PROOT)/../c-ares
  101. CPPFLAGS += -DUSE_ARES
  102. CPPFLAGS += -I"$(LIBCARES_PATH)/include"
  103. _LDFLAGS += -L"$(LIBCARES_PATH)/lib"
  104. _LIBS += -lcares
  105. endif
  106. ifneq ($(findstring -rtmp,$(CFG)),)
  107. LIBRTMP_PATH ?= $(PROOT)/../librtmp
  108. CPPFLAGS += -DUSE_LIBRTMP
  109. CPPFLAGS += -I"$(LIBRTMP_PATH)"
  110. _LDFLAGS += -L"$(LIBRTMP_PATH)/librtmp"
  111. _LIBS += -lrtmp -lwinmm
  112. ZLIB := 1
  113. endif
  114. ifneq ($(findstring -ssh2,$(CFG)),)
  115. LIBSSH2_PATH ?= $(PROOT)/../libssh2
  116. CPPFLAGS += -DUSE_LIBSSH2
  117. CPPFLAGS += -I"$(LIBSSH2_PATH)/include"
  118. _LDFLAGS += -L"$(LIBSSH2_PATH)/lib"
  119. _LDFLAGS += -L"$(LIBSSH2_PATH)/win32"
  120. _LIBS += -lssh2
  121. else ifneq ($(findstring -libssh,$(CFG)),)
  122. LIBSSH_PATH ?= $(PROOT)/../libssh
  123. CPPFLAGS += -DUSE_LIBSSH
  124. CPPFLAGS += -I"$(LIBSSH_PATH)/include"
  125. _LDFLAGS += -L"$(LIBSSH_PATH)/lib"
  126. _LIBS += -lssh
  127. else ifneq ($(findstring -wolfssh,$(CFG)),)
  128. WOLFSSH_PATH ?= $(PROOT)/../wolfssh
  129. CPPFLAGS += -DUSE_WOLFSSH
  130. CPPFLAGS += -I"$(WOLFSSH_PATH)/include"
  131. _LDFLAGS += -L"$(WOLFSSH_PATH)/lib"
  132. _LIBS += -lwolfssh
  133. endif
  134. ifneq ($(findstring -ssl,$(CFG)),)
  135. OPENSSL_PATH ?= $(PROOT)/../openssl
  136. CPPFLAGS += -DUSE_OPENSSL
  137. CPPFLAGS += -DCURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG
  138. OPENSSL_INCLUDE ?= $(OPENSSL_PATH)/include
  139. OPENSSL_LIBPATH ?= $(OPENSSL_PATH)/lib
  140. CPPFLAGS += -I"$(OPENSSL_INCLUDE)"
  141. _LDFLAGS += -L"$(OPENSSL_LIBPATH)"
  142. OPENSSL_LIBS ?= -lssl -lcrypto
  143. _LIBS += $(OPENSSL_LIBS)
  144. ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/aead.h),)
  145. OPENSSL := boringssl
  146. else
  147. # including libressl
  148. OPENSSL := openssl
  149. endif
  150. ifneq ($(findstring -srp,$(CFG)),)
  151. ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h),)
  152. # OpenSSL 1.0.1 and later.
  153. CPPFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP
  154. endif
  155. endif
  156. SSLLIBS += 1
  157. else ifneq ($(findstring -wolfssl,$(CFG)),)
  158. WOLFSSL_PATH ?= $(PROOT)/../zlib
  159. CPPFLAGS += -DUSE_WOLFSSL
  160. CPPFLAGS += -DSIZEOF_LONG_LONG=8
  161. CPPFLAGS += -I"$(WOLFSSL_PATH)/include"
  162. _LDFLAGS += -L"$(WOLFSSL_PATH)/lib"
  163. _LIBS += -lwolfssl
  164. OPENSSL := wolfssl
  165. SSLLIBS += 1
  166. endif
  167. ifneq ($(findstring -mbedtls,$(CFG)),)
  168. MBEDTLS_PATH ?= $(PROOT)/../zlib
  169. CPPFLAGS += -DUSE_MBEDTLS
  170. CPPFLAGS += -I"$(MBEDTLS_PATH)/include"
  171. _LDFLAGS += -L"$(MBEDTLS_PATH)/lib"
  172. _LIBS += -lmbedtls -lmbedx509 -lmbedcrypto
  173. SSLLIBS += 1
  174. endif
  175. ifneq ($(findstring -schannel,$(CFG)),)
  176. CPPFLAGS += -DUSE_SCHANNEL
  177. SSLLIBS += 1
  178. endif
  179. ifneq ($(findstring -nghttp2,$(CFG)),)
  180. NGHTTP2_PATH ?= $(PROOT)/../nghttp2
  181. CPPFLAGS += -DUSE_NGHTTP2
  182. CPPFLAGS += -I"$(NGHTTP2_PATH)/include"
  183. _LDFLAGS += -L"$(NGHTTP2_PATH)/lib"
  184. _LIBS += -lnghttp2
  185. endif
  186. ifeq ($(findstring -nghttp3,$(CFG))$(findstring -ngtcp2,$(CFG)),-nghttp3-ngtcp2)
  187. NGHTTP3_PATH ?= $(PROOT)/../nghttp3
  188. CPPFLAGS += -DUSE_NGHTTP3
  189. CPPFLAGS += -I"$(NGHTTP3_PATH)/include"
  190. _LDFLAGS += -L"$(NGHTTP3_PATH)/lib"
  191. _LIBS += -lnghttp3
  192. NGTCP2_PATH ?= $(PROOT)/../ngtcp2
  193. CPPFLAGS += -DUSE_NGTCP2
  194. CPPFLAGS += -I"$(NGTCP2_PATH)/include"
  195. _LDFLAGS += -L"$(NGTCP2_PATH)/lib"
  196. ifneq ($(OPENSSL),)
  197. NGTCP2_LIBS ?= -lngtcp2_crypto_$(OPENSSL)
  198. endif
  199. _LIBS += -lngtcp2 $(NGTCP2_LIBS)
  200. endif
  201. ifneq ($(findstring -zlib,$(CFG))$(ZLIB),)
  202. ZLIB_PATH ?= $(PROOT)/../zlib
  203. # These CPPFLAGS are also required when compiling the curl tool via 'src'.
  204. CPPFLAGS += -DHAVE_LIBZ
  205. CPPFLAGS += -I"$(ZLIB_PATH)"
  206. _LDFLAGS += -L"$(ZLIB_PATH)"
  207. _LIBS += -lz
  208. endif
  209. ifneq ($(findstring -zstd,$(CFG)),)
  210. ZSTD_PATH ?= $(PROOT)/../zstd
  211. CPPFLAGS += -DHAVE_ZSTD
  212. CPPFLAGS += -I"$(ZSTD_PATH)/include"
  213. _LDFLAGS += -L"$(ZSTD_PATH)/lib"
  214. ZSTD_LIBS ?= -lzstd
  215. _LIBS += $(ZSTD_LIBS)
  216. endif
  217. ifneq ($(findstring -brotli,$(CFG)),)
  218. BROTLI_PATH ?= $(PROOT)/../brotli
  219. CPPFLAGS += -DHAVE_BROTLI
  220. CPPFLAGS += -I"$(BROTLI_PATH)/include"
  221. _LDFLAGS += -L"$(BROTLI_PATH)/lib"
  222. BROTLI_LIBS ?= -lbrotlidec -lbrotlicommon
  223. _LIBS += $(BROTLI_LIBS)
  224. endif
  225. ifneq ($(findstring -gsasl,$(CFG)),)
  226. LIBGSASL_PATH ?= $(PROOT)/../gsasl
  227. CPPFLAGS += -DUSE_GSASL
  228. CPPFLAGS += -I"$(LIBGSASL_PATH)/include"
  229. _LDFLAGS += -L"$(LIBGSASL_PATH)/lib"
  230. _LIBS += -lgsasl
  231. endif
  232. ifneq ($(findstring -idn2,$(CFG)),)
  233. LIBIDN2_PATH ?= $(PROOT)/../libidn2
  234. CPPFLAGS += -DUSE_LIBIDN2
  235. CPPFLAGS += -I"$(LIBIDN2_PATH)/include"
  236. _LDFLAGS += -L"$(LIBIDN2_PATH)/lib"
  237. _LIBS += -lidn2
  238. ifneq ($(findstring -psl,$(CFG)),)
  239. LIBPSL_PATH ?= $(PROOT)/../libpsl
  240. CPPFLAGS += -DUSE_LIBPSL
  241. CPPFLAGS += -I"$(LIBPSL_PATH)/include"
  242. _LDFLAGS += -L"$(LIBPSL_PATH)/lib"
  243. _LIBS += -lpsl
  244. endif
  245. else ifneq ($(findstring -winidn,$(CFG)),)
  246. CPPFLAGS += -DUSE_WIN32_IDN
  247. _LIBS += -lnormaliz
  248. endif
  249. ifneq ($(findstring -sspi,$(CFG)),)
  250. CPPFLAGS += -DUSE_WINDOWS_SSPI
  251. endif
  252. ifneq ($(findstring -ipv6,$(CFG)),)
  253. CPPFLAGS += -DENABLE_IPV6
  254. endif
  255. ifneq ($(findstring -ldaps,$(CFG)),)
  256. CPPFLAGS += -DHAVE_LDAP_SSL
  257. endif
  258. ifeq ($(findstring -lldap,$(LIBS)),)
  259. _LIBS += -lwldap32
  260. endif
  261. _LIBS += -lws2_32 -lcrypt32 -lbcrypt
  262. ifneq ($(findstring 11,$(subst $() ,,$(SSLLIBS))),)
  263. CPPFLAGS += -DCURL_WITH_MULTI_SSL
  264. endif
  265. ifndef DYN
  266. LDFLAGS += $(_LDFLAGS)
  267. LIBS += $(_LIBS)
  268. endif
  269. ### Global rules
  270. ifneq ($(findstring /sh,$(SHELL)),)
  271. DEL = rm -f $1
  272. COPY = -cp -afv $1 $2
  273. else
  274. DEL = -del 2>NUL /q /f $(subst /,\,$1)
  275. COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
  276. endif
  277. all: $(TARGETS)
  278. %.o: %.c
  279. $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $<
  280. %.res: %.rc
  281. $(RC) -O coff $(RCFLAGS) -i $< -o $@
  282. clean:
  283. @$(call DEL, $(TOCLEAN))
  284. distclean vclean: clean
  285. @$(call DEL, $(TARGETS) $(TOVCLEAN))