Makefile.m32 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. ###########################################################################
  25. #
  26. ## Makefile for building libcurl.a with MingW (GCC-3.2 or later or LLVM/Clang)
  27. ## and optionally OpenSSL (1.0.2a), libssh2 (1.5), zlib (1.2.8), librtmp (2.4),
  28. ## brotli (1.0.1), zstd (1.4.5)
  29. ##
  30. ## Usage: mingw32-make -f Makefile.m32 CFG=-feature1[-feature2][-feature3][...]
  31. ## Example: mingw32-make -f Makefile.m32 CFG=-zlib-ssl-sspi-winidn
  32. ##
  33. ## Hint: you can also set environment vars to control the build, f.e.:
  34. ## set ZLIB_PATH=c:/zlib-1.2.8
  35. ## set ZLIB=1
  36. #
  37. ###########################################################################
  38. # Edit the path below to point to the base of your Zlib sources.
  39. ifndef ZLIB_PATH
  40. ZLIB_PATH = ../../zlib-1.2.8
  41. endif
  42. # Edit the path below to point to the base of your Zstandard sources.
  43. ifndef ZSTD_PATH
  44. ZSTD_PATH = ../../zstd-1.4.5
  45. endif
  46. # Edit the path below to point to the base of your Brotli sources.
  47. ifndef BROTLI_PATH
  48. BROTLI_PATH = ../../brotli-1.0.1
  49. endif
  50. # Edit the path below to point to the base of your OpenSSL package.
  51. ifndef OPENSSL_PATH
  52. OPENSSL_PATH = ../../openssl-1.0.2a
  53. endif
  54. # Edit the path below to point to the base of your LibSSH2 package.
  55. ifndef LIBSSH2_PATH
  56. LIBSSH2_PATH = ../../libssh2-1.5.0
  57. endif
  58. # Edit the path below to point to the base of your librtmp package.
  59. ifndef LIBRTMP_PATH
  60. LIBRTMP_PATH = ../../librtmp-2.4
  61. endif
  62. # Edit the path below to point to the base of your libgsasl package.
  63. ifndef LIBGSASL_PATH
  64. LIBGSASL_PATH = ../../libgsasl-1.10.0
  65. endif
  66. # Edit the path below to point to the base of your libidn2 package.
  67. ifndef LIBIDN2_PATH
  68. LIBIDN2_PATH = ../../libidn2-2.0.3
  69. endif
  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
  73. ifndef WINIDN_PATH
  74. WINIDN_PATH = ../../Microsoft IDN Mitigation APIs
  75. endif
  76. # Edit the path below to point to the base of your Novell LDAP NDK.
  77. ifndef LDAP_SDK
  78. LDAP_SDK = c:/novell/ndk/cldapsdk/win32
  79. endif
  80. # Edit the path below to point to the base of your nghttp2 package.
  81. ifndef NGHTTP2_PATH
  82. NGHTTP2_PATH = ../../nghttp2-1.0.0
  83. endif
  84. # Edit the path below to point to the base of your nghttp3 package.
  85. ifndef NGHTTP3_PATH
  86. NGHTTP3_PATH = ../../nghttp3-1.0.0
  87. endif
  88. # Edit the path below to point to the base of your ngtcp2 package.
  89. ifndef NGTCP2_PATH
  90. NGTCP2_PATH = ../../ngtcp2-1.0.0
  91. endif
  92. PROOT = ..
  93. # Edit the path below to point to the base of your c-ares package.
  94. ifndef LIBCARES_PATH
  95. LIBCARES_PATH = $(PROOT)/ares
  96. endif
  97. ifeq ($(CURL_CC),)
  98. CURL_CC := $(CROSSPREFIX)gcc
  99. endif
  100. ifeq ($(CURL_AR),)
  101. CURL_AR := $(CROSSPREFIX)ar
  102. endif
  103. ifeq ($(CURL_RANLIB),)
  104. CURL_RANLIB := $(CROSSPREFIX)ranlib
  105. endif
  106. ifeq ($(CURL_RC),)
  107. CURL_RC := $(CROSSPREFIX)windres
  108. endif
  109. ifeq ($(CURL_STRIP),)
  110. CURL_STRIP := $(CROSSPREFIX)strip
  111. endif
  112. CC = $(CURL_CC)
  113. CFLAGS = -O3 $(CURL_CFLAG_EXTRAS) -W -Wall
  114. LDFLAGS = $(CURL_LDFLAG_EXTRAS) $(CURL_LDFLAG_EXTRAS_DLL)
  115. AR = $(CURL_AR)
  116. RANLIB = $(CURL_RANLIB)
  117. RC = $(CURL_RC)
  118. RCFLAGS = --include-dir=$(PROOT)/include -O coff $(CURL_RCFLAG_EXTRAS)
  119. STRIP = $(CURL_STRIP) -g
  120. # Set environment var ARCH to your architecture to override autodetection.
  121. ifndef ARCH
  122. ifeq ($(findstring x86_64,$(shell $(CC) -dumpmachine)),x86_64)
  123. ARCH = w64
  124. else
  125. ARCH = w32
  126. endif
  127. endif
  128. ifneq ($(ARCH),custom)
  129. ifeq ($(ARCH),w64)
  130. CFLAGS += -m64
  131. LDFLAGS += -m64
  132. RCFLAGS += -F pe-x86-64
  133. else
  134. CFLAGS += -m32
  135. LDFLAGS += -m32
  136. RCFLAGS += -F pe-i386
  137. endif
  138. endif
  139. # Platform-dependent helper tool macros
  140. ifeq ($(findstring /sh,$(SHELL)),/sh)
  141. DEL = rm -f $1
  142. RMDIR = rm -fr $1
  143. MKDIR = mkdir -p $1
  144. COPY = -cp -afv $1 $2
  145. #COPYR = -cp -afr $1/* $2
  146. COPYR = -rsync -aC $1/* $2
  147. TOUCH = touch $1
  148. CAT = cat
  149. ECHONL = echo ""
  150. DL = '
  151. else
  152. ifeq "$(OS)" "Windows_NT"
  153. DEL = -del 2>NUL /q /f $(subst /,\,$1)
  154. RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
  155. else
  156. DEL = -del 2>NUL $(subst /,\,$1)
  157. RMDIR = -deltree 2>NUL /y $(subst /,\,$1)
  158. endif
  159. MKDIR = -md 2>NUL $(subst /,\,$1)
  160. COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
  161. COPYR = -xcopy 2>NUL /q /y /e $(subst /,\,$1) $(subst /,\,$2)
  162. TOUCH = copy 2>&1>NUL /b $(subst /,\,$1) +,,
  163. CAT = type
  164. ECHONL = $(ComSpec) /c echo.
  165. endif
  166. ########################################################
  167. ## Nothing more to do below this line!
  168. ifneq ($(findstring -dyn,$(CFG)),)
  169. DYN = 1
  170. endif
  171. ifneq ($(findstring -ares,$(CFG)),)
  172. ARES = 1
  173. endif
  174. ifneq ($(findstring -sync,$(CFG)),)
  175. SYNC = 1
  176. endif
  177. ifneq ($(findstring -rtmp,$(CFG)),)
  178. RTMP = 1
  179. ZLIB = 1
  180. endif
  181. ifneq ($(findstring -ssh2,$(CFG)),)
  182. SSH2 = 1
  183. ZLIB = 1
  184. endif
  185. ifneq ($(findstring -ssl,$(CFG)),)
  186. SSL = 1
  187. endif
  188. ifneq ($(findstring -srp,$(CFG)),)
  189. SRP = 1
  190. endif
  191. ifneq ($(findstring -zlib,$(CFG)),)
  192. ZLIB = 1
  193. endif
  194. ifneq ($(findstring -zstd,$(CFG)),)
  195. ZSTD = 1
  196. endif
  197. ifneq ($(findstring -brotli,$(CFG)),)
  198. BROTLI = 1
  199. endif
  200. ifneq ($(findstring -gsasl,$(CFG)),)
  201. GSASL = 1
  202. endif
  203. ifneq ($(findstring -idn2,$(CFG)),)
  204. IDN2 = 1
  205. endif
  206. ifneq ($(findstring -winidn,$(CFG)),)
  207. WINIDN = 1
  208. endif
  209. ifneq ($(findstring -sspi,$(CFG)),)
  210. SSPI = 1
  211. endif
  212. ifneq ($(findstring -ldaps,$(CFG)),)
  213. LDAPS = 1
  214. endif
  215. ifneq ($(findstring -ipv6,$(CFG)),)
  216. IPV6 = 1
  217. endif
  218. ifneq ($(findstring -schannel,$(CFG))$(findstring -winssl,$(CFG)),)
  219. SCHANNEL = 1
  220. SSPI = 1
  221. endif
  222. ifneq ($(findstring -nghttp2,$(CFG)),)
  223. NGHTTP2 = 1
  224. endif
  225. ifneq ($(findstring -nghttp3,$(CFG)),)
  226. NGHTTP3 = 1
  227. endif
  228. ifneq ($(findstring -ngtcp2,$(CFG)),)
  229. NGTCP2 = 1
  230. endif
  231. ifneq ($(findstring -unicode,$(CFG)),)
  232. UNICODE = 1
  233. endif
  234. # SSH2 and RTMP require an SSL library; assume OpenSSL if none specified
  235. ifneq ($(SSH2)$(RTMP),)
  236. ifeq ($(SSL)$(SCHANNEL),)
  237. SSL = 1
  238. endif
  239. endif
  240. INCLUDES = -I. -I../include
  241. CFLAGS += -DBUILDING_LIBCURL
  242. ifdef SSL
  243. ifdef SCHANNEL
  244. CFLAGS += -DCURL_WITH_MULTI_SSL
  245. endif
  246. endif
  247. ifdef UNICODE
  248. CFLAGS += -DUNICODE -D_UNICODE
  249. endif
  250. ifdef SYNC
  251. CFLAGS += -DUSE_SYNC_DNS
  252. else
  253. ifdef ARES
  254. INCLUDES += -I"$(LIBCARES_PATH)"
  255. CFLAGS += -DUSE_ARES -DCARES_STATICLIB
  256. DLL_LIBS += -L"$(LIBCARES_PATH)" -lcares
  257. libcurl_dll_DEPENDENCIES = $(LIBCARES_PATH)/libcares.a
  258. endif
  259. endif
  260. ifdef RTMP
  261. INCLUDES += -I"$(LIBRTMP_PATH)"
  262. CFLAGS += -DUSE_LIBRTMP
  263. DLL_LIBS += -L"$(LIBRTMP_PATH)/librtmp" -lrtmp -lwinmm
  264. endif
  265. ifdef NGHTTP2
  266. INCLUDES += -I"$(NGHTTP2_PATH)/include"
  267. CFLAGS += -DUSE_NGHTTP2
  268. DLL_LIBS += -L"$(NGHTTP2_PATH)/lib" -lnghttp2
  269. endif
  270. ifdef SSH2
  271. INCLUDES += -I"$(LIBSSH2_PATH)/include" -I"$(LIBSSH2_PATH)/win32"
  272. CFLAGS += -DUSE_LIBSSH2 -DHAVE_LIBSSH2_H
  273. DLL_LIBS += -L"$(LIBSSH2_PATH)/win32" -lssh2
  274. ifdef SCHANNEL
  275. ifndef DYN
  276. DLL_LIBS += -lcrypt32
  277. endif
  278. endif
  279. endif
  280. ifdef NGHTTP3
  281. INCLUDES += -I"$(NGHTTP3_PATH)/include"
  282. CFLAGS += -DUSE_NGHTTP3
  283. DLL_LIBS += -L"$(NGHTTP3_PATH)/lib" -lnghttp3
  284. ifdef NGTCP2
  285. INCLUDES += -I"$(NGTCP2_PATH)/include"
  286. CFLAGS += -DUSE_NGTCP2
  287. DLL_LIBS += -L"$(NGTCP2_PATH)/lib"
  288. ifdef NGTCP2_LIBS
  289. DLL_LIBS += $(NGTCP2_LIBS)
  290. else
  291. DLL_LIBS += -lngtcp2
  292. ifdef SSL
  293. DLL_LIBS += -lngtcp2_crypto_openssl
  294. endif
  295. endif
  296. endif
  297. endif
  298. ifdef SSL
  299. ifndef OPENSSL_INCLUDE
  300. ifeq "$(wildcard $(OPENSSL_PATH)/outinc)" "$(OPENSSL_PATH)/outinc"
  301. OPENSSL_INCLUDE = $(OPENSSL_PATH)/outinc
  302. endif
  303. ifeq "$(wildcard $(OPENSSL_PATH)/include)" "$(OPENSSL_PATH)/include"
  304. OPENSSL_INCLUDE = $(OPENSSL_PATH)/include
  305. endif
  306. endif
  307. ifneq "$(wildcard $(OPENSSL_INCLUDE)/openssl/opensslv.h)" "$(OPENSSL_INCLUDE)/openssl/opensslv.h"
  308. $(error Invalid path to OpenSSL package: $(OPENSSL_PATH))
  309. endif
  310. ifndef OPENSSL_LIBPATH
  311. ifeq "$(wildcard $(OPENSSL_PATH)/out)" "$(OPENSSL_PATH)/out"
  312. OPENSSL_LIBPATH = $(OPENSSL_PATH)/out
  313. OPENSSL_LIBS = -leay32 -lssl32
  314. endif
  315. ifeq "$(wildcard $(OPENSSL_PATH)/lib)" "$(OPENSSL_PATH)/lib"
  316. OPENSSL_LIBPATH = $(OPENSSL_PATH)/lib
  317. OPENSSL_LIBS = -lcrypto -lssl
  318. endif
  319. endif
  320. ifndef DYN
  321. OPENSSL_LIBS += -lgdi32 -lcrypt32
  322. endif
  323. INCLUDES += -I"$(OPENSSL_INCLUDE)"
  324. CFLAGS += -DUSE_OPENSSL
  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
  331. endif
  332. ifdef SCHANNEL
  333. CFLAGS += -DUSE_SCHANNEL
  334. DLL_LIBS += -lcrypt32
  335. endif
  336. ifdef ZLIB
  337. INCLUDES += -I"$(ZLIB_PATH)"
  338. CFLAGS += -DHAVE_LIBZ -DHAVE_ZLIB_H
  339. DLL_LIBS += -L"$(ZLIB_PATH)" -lz
  340. endif
  341. ifdef 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
  350. endif
  351. ifdef 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
  360. endif
  361. ifdef GSASL
  362. INCLUDES += -I"$(LIBGSASL_PATH)/include"
  363. CFLAGS += -DUSE_GSASL
  364. DLL_LIBS += -L"$(LIBGSASL_PATH)/lib" -lgsasl
  365. endif
  366. ifdef IDN2
  367. INCLUDES += -I"$(LIBIDN2_PATH)/include"
  368. CFLAGS += -DUSE_LIBIDN2
  369. DLL_LIBS += -L"$(LIBIDN2_PATH)/lib" -lidn2
  370. else
  371. ifdef WINIDN
  372. CFLAGS += -DUSE_WIN32_IDN
  373. CFLAGS += -DWANT_IDN_PROTOTYPES
  374. DLL_LIBS += -L"$(WINIDN_PATH)" -lnormaliz
  375. endif
  376. endif
  377. ifdef SSPI
  378. CFLAGS += -DUSE_WINDOWS_SSPI
  379. endif
  380. ifdef SPNEGO
  381. CFLAGS += -DHAVE_SPNEGO
  382. endif
  383. ifdef IPV6
  384. CFLAGS += -DENABLE_IPV6
  385. endif
  386. ifdef LDAPS
  387. CFLAGS += -DHAVE_LDAP_SSL
  388. endif
  389. ifdef 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
  393. endif
  394. ifdef USE_LDAP_OPENLDAP
  395. INCLUDES += -I"$(LDAP_SDK)/include"
  396. CFLAGS += -DCURL_HAS_OPENLDAP_LDAPSDK
  397. DLL_LIBS += -L"$(LDAP_SDK)/lib" -lldap -llber
  398. endif
  399. ifndef USE_LDAP_NOVELL
  400. ifndef USE_LDAP_OPENLDAP
  401. DLL_LIBS += -lwldap32
  402. endif
  403. endif
  404. DLL_LIBS += -lws2_32 -lbcrypt
  405. # Makefile.inc provides the CSOURCES and HHEADERS defines
  406. include Makefile.inc
  407. ifeq ($(CURL_DLL_A_SUFFIX),)
  408. CURL_DLL_A_SUFFIX := dll
  409. endif
  410. libcurl_dll_LIBRARY = libcurl$(CURL_DLL_SUFFIX).dll
  411. libcurl_dll_a_LIBRARY = libcurl$(CURL_DLL_A_SUFFIX).a
  412. libcurl_a_LIBRARY = libcurl.a
  413. libcurl_a_OBJECTS := $(patsubst %.c,%.o,$(strip $(CSOURCES)))
  414. libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
  415. RESOURCE = libcurl.res
  416. all: $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY)
  417. $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
  418. @$(call DEL, $@)
  419. $(AR) cru $@ $(libcurl_a_OBJECTS)
  420. $(RANLIB) $@
  421. $(STRIP) $@
  422. # remove the last line above to keep debug info
  423. $(libcurl_dll_LIBRARY): $(libcurl_a_OBJECTS) $(RESOURCE) $(libcurl_dll_DEPENDENCIES)
  424. @$(call DEL, $@)
  425. $(CC) $(LDFLAGS) -shared -o $@ \
  426. -Wl,--output-def,$(@:.dll=.def),--out-implib,$(libcurl_dll_a_LIBRARY) \
  427. $(libcurl_a_OBJECTS) $(RESOURCE) $(DLL_LIBS)
  428. %.o: %.c
  429. $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@
  430. %.res: %.rc
  431. $(RC) $(RCFLAGS) -i $< -o $@
  432. clean:
  433. @$(call DEL, $(libcurl_a_OBJECTS) $(RESOURCE))
  434. distclean vclean: clean
  435. @$(call DEL, $(libcurl_a_LIBRARY) $(libcurl_dll_LIBRARY) $(libcurl_dll_LIBRARY:.dll=.def) $(libcurl_dll_a_LIBRARY))