Makefile.m32 12 KB

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