2
0

Makefile.mk 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 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 to build curl parts with GCC-like toolchains and optional features.
  25. #
  26. # Usage: make -f Makefile.mk CFG=-feat1[-feat2][-feat3][...]
  27. # Example: make -f Makefile.mk CFG=-zlib-ssl-libssh2-ipv6
  28. #
  29. # Look for ' ?=' to find accepted customization variables.
  30. # This script is reused by 'src' and 'docs/examples' Makefile.mk scripts.
  31. ifndef PROOT
  32. PROOT := ..
  33. LOCAL := 1
  34. endif
  35. ### Common
  36. CFLAGS ?=
  37. CPPFLAGS ?=
  38. LDFLAGS ?=
  39. LIBS ?=
  40. CROSSPREFIX ?=
  41. ifeq ($(CC),cc)
  42. CC := gcc
  43. endif
  44. CC := $(CROSSPREFIX)$(CC)
  45. AR := $(CROSSPREFIX)$(AR)
  46. TRIPLET ?= $(shell $(CC) -dumpmachine)
  47. BIN_EXT :=
  48. ifneq ($(findstring msdos,$(TRIPLET)),)
  49. # Cross-tools: https://github.com/andrewwutw/build-djgpp
  50. MSDOS := 1
  51. BIN_EXT := .exe
  52. else ifneq ($(findstring amigaos,$(TRIPLET)),)
  53. # Cross-tools: https://github.com/bebbo/amiga-gcc
  54. AMIGA := 1
  55. endif
  56. CPPFLAGS += -I. -I$(PROOT)/include
  57. ### Deprecated settings. For compatibility.
  58. ifdef WATT_ROOT
  59. WATT_PATH := $(realpath $(WATT_ROOT))
  60. endif
  61. ### Optional features
  62. ifneq ($(findstring -debug,$(CFG)),)
  63. CFLAGS += -g
  64. CPPFLAGS += -DDEBUGBUILD
  65. else
  66. CPPFLAGS += -DNDEBUG
  67. endif
  68. ifneq ($(findstring -trackmem,$(CFG)),)
  69. CPPFLAGS += -DCURLDEBUG
  70. endif
  71. ifneq ($(findstring -map,$(CFG)),)
  72. MAP := 1
  73. endif
  74. # CPPFLAGS below are only necessary when building libcurl via 'lib' (see
  75. # comments below about exceptions). Always include them anyway to match
  76. # behavior of other build systems.
  77. ifneq ($(findstring -sync,$(CFG)),)
  78. CPPFLAGS += -DUSE_SYNC_DNS
  79. else ifneq ($(findstring -ares,$(CFG)),)
  80. LIBCARES_PATH ?= $(PROOT)/../c-ares
  81. CPPFLAGS += -DUSE_ARES
  82. CPPFLAGS += -isystem "$(LIBCARES_PATH)/include"
  83. LDFLAGS += -L"$(LIBCARES_PATH)/lib"
  84. LIBS += -lcares
  85. endif
  86. ifneq ($(findstring -rtmp,$(CFG)),)
  87. LIBRTMP_PATH ?= $(PROOT)/../librtmp
  88. CPPFLAGS += -DUSE_LIBRTMP
  89. CPPFLAGS += -isystem "$(LIBRTMP_PATH)"
  90. LDFLAGS += -L"$(LIBRTMP_PATH)/librtmp"
  91. LIBS += -lrtmp
  92. ZLIB := 1
  93. endif
  94. ifneq ($(findstring -ssh2,$(CFG)),)
  95. LIBSSH2_PATH ?= $(PROOT)/../libssh2
  96. CPPFLAGS += -DUSE_LIBSSH2
  97. CPPFLAGS += -isystem "$(LIBSSH2_PATH)/include"
  98. LDFLAGS += -L"$(LIBSSH2_PATH)/lib"
  99. LIBS += -lssh2
  100. else ifneq ($(findstring -libssh,$(CFG)),)
  101. LIBSSH_PATH ?= $(PROOT)/../libssh
  102. CPPFLAGS += -DUSE_LIBSSH
  103. CPPFLAGS += -isystem "$(LIBSSH_PATH)/include"
  104. LDFLAGS += -L"$(LIBSSH_PATH)/lib"
  105. LIBS += -lssh
  106. else ifneq ($(findstring -wolfssh,$(CFG)),)
  107. WOLFSSH_PATH ?= $(PROOT)/../wolfssh
  108. CPPFLAGS += -DUSE_WOLFSSH
  109. CPPFLAGS += -isystem "$(WOLFSSH_PATH)/include"
  110. LDFLAGS += -L"$(WOLFSSH_PATH)/lib"
  111. LIBS += -lwolfssh
  112. endif
  113. ifneq ($(findstring -ssl,$(CFG)),)
  114. OPENSSL_PATH ?= $(PROOT)/../openssl
  115. CPPFLAGS += -DUSE_OPENSSL
  116. CPPFLAGS += -DCURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG
  117. OPENSSL_INCLUDE ?= $(OPENSSL_PATH)/include
  118. OPENSSL_LIBPATH ?= $(OPENSSL_PATH)/lib
  119. CPPFLAGS += -isystem "$(OPENSSL_INCLUDE)"
  120. LDFLAGS += -L"$(OPENSSL_LIBPATH)"
  121. OPENSSL_LIBS ?= -lssl -lcrypto
  122. LIBS += $(OPENSSL_LIBS)
  123. ifneq ($(findstring -srp,$(CFG)),)
  124. ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/srp.h),)
  125. # OpenSSL 1.0.1 and later.
  126. CPPFLAGS += -DHAVE_OPENSSL_SRP -DUSE_TLS_SRP
  127. endif
  128. endif
  129. SSLLIBS += 1
  130. endif
  131. ifneq ($(findstring -wolfssl,$(CFG)),)
  132. WOLFSSL_PATH ?= $(PROOT)/../wolfssl
  133. CPPFLAGS += -DUSE_WOLFSSL
  134. CPPFLAGS += -DSIZEOF_LONG_LONG=8
  135. CPPFLAGS += -isystem "$(WOLFSSL_PATH)/include"
  136. LDFLAGS += -L"$(WOLFSSL_PATH)/lib"
  137. LIBS += -lwolfssl
  138. SSLLIBS += 1
  139. endif
  140. ifneq ($(findstring -mbedtls,$(CFG)),)
  141. MBEDTLS_PATH ?= $(PROOT)/../mbedtls
  142. CPPFLAGS += -DUSE_MBEDTLS
  143. CPPFLAGS += -isystem "$(MBEDTLS_PATH)/include"
  144. LDFLAGS += -L"$(MBEDTLS_PATH)/lib"
  145. LIBS += -lmbedtls -lmbedx509 -lmbedcrypto
  146. SSLLIBS += 1
  147. endif
  148. ifneq ($(findstring -bearssl,$(CFG)),)
  149. BEARSSL_PATH ?= $(PROOT)/../bearssl
  150. CPPFLAGS += -DUSE_BEARSSL
  151. CPPFLAGS += -isystem "$(BEARSSL_PATH)/inc"
  152. LDFLAGS += -L"$(BEARSSL_PATH)/build"
  153. LIBS += -lbearssl
  154. SSLLIBS += 1
  155. endif
  156. ifneq ($(findstring -nghttp2,$(CFG)),)
  157. NGHTTP2_PATH ?= $(PROOT)/../nghttp2
  158. CPPFLAGS += -DUSE_NGHTTP2
  159. CPPFLAGS += -isystem "$(NGHTTP2_PATH)/include"
  160. LDFLAGS += -L"$(NGHTTP2_PATH)/lib"
  161. LIBS += -lnghttp2
  162. endif
  163. ifeq ($(findstring -nghttp3,$(CFG))$(findstring -ngtcp2,$(CFG)),-nghttp3-ngtcp2)
  164. NGHTTP3_PATH ?= $(PROOT)/../nghttp3
  165. CPPFLAGS += -DUSE_NGHTTP3
  166. CPPFLAGS += -isystem "$(NGHTTP3_PATH)/include"
  167. LDFLAGS += -L"$(NGHTTP3_PATH)/lib"
  168. LIBS += -lnghttp3
  169. NGTCP2_PATH ?= $(PROOT)/../ngtcp2
  170. CPPFLAGS += -DUSE_NGTCP2
  171. CPPFLAGS += -isystem "$(NGTCP2_PATH)/include"
  172. LDFLAGS += -L"$(NGTCP2_PATH)/lib"
  173. NGTCP2_LIBS ?=
  174. ifeq ($(NGTCP2_LIBS),)
  175. ifneq ($(findstring -ssl,$(CFG)),)
  176. ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/aead.h),)
  177. NGTCP2_LIBS := -lngtcp2_crypto_boringssl
  178. else # including libressl
  179. NGTCP2_LIBS := -lngtcp2_crypto_quictls
  180. endif
  181. else ifneq ($(findstring -wolfssl,$(CFG)),)
  182. NGTCP2_LIBS := -lngtcp2_crypto_wolfssl
  183. endif
  184. endif
  185. LIBS += -lngtcp2 $(NGTCP2_LIBS)
  186. endif
  187. ifneq ($(findstring -zlib,$(CFG))$(ZLIB),)
  188. ZLIB_PATH ?= $(PROOT)/../zlib
  189. # These CPPFLAGS are also required when compiling the curl tool via 'src'.
  190. CPPFLAGS += -DHAVE_LIBZ
  191. CPPFLAGS += -isystem "$(ZLIB_PATH)/include"
  192. LDFLAGS += -L"$(ZLIB_PATH)/lib"
  193. ZLIB_LIBS ?= -lz
  194. LIBS += $(ZLIB_LIBS)
  195. ZLIB := 1
  196. endif
  197. ifneq ($(findstring -zstd,$(CFG)),)
  198. ZSTD_PATH ?= $(PROOT)/../zstd
  199. CPPFLAGS += -DHAVE_ZSTD
  200. CPPFLAGS += -isystem "$(ZSTD_PATH)/include"
  201. LDFLAGS += -L"$(ZSTD_PATH)/lib"
  202. ZSTD_LIBS ?= -lzstd
  203. LIBS += $(ZSTD_LIBS)
  204. endif
  205. ifneq ($(findstring -brotli,$(CFG)),)
  206. BROTLI_PATH ?= $(PROOT)/../brotli
  207. CPPFLAGS += -DHAVE_BROTLI
  208. CPPFLAGS += -isystem "$(BROTLI_PATH)/include"
  209. LDFLAGS += -L"$(BROTLI_PATH)/lib"
  210. BROTLI_LIBS ?= -lbrotlidec -lbrotlicommon
  211. LIBS += $(BROTLI_LIBS)
  212. endif
  213. ifneq ($(findstring -gsasl,$(CFG)),)
  214. LIBGSASL_PATH ?= $(PROOT)/../gsasl
  215. CPPFLAGS += -DUSE_GSASL
  216. CPPFLAGS += -isystem "$(LIBGSASL_PATH)/include"
  217. LDFLAGS += -L"$(LIBGSASL_PATH)/lib"
  218. LIBS += -lgsasl
  219. endif
  220. ifneq ($(findstring -idn2,$(CFG)),)
  221. LIBIDN2_PATH ?= $(PROOT)/../libidn2
  222. CPPFLAGS += -DHAVE_LIBIDN2 -DHAVE_IDN2_H
  223. CPPFLAGS += -isystem "$(LIBIDN2_PATH)/include"
  224. LDFLAGS += -L"$(LIBIDN2_PATH)/lib"
  225. LIBS += -lidn2
  226. ifneq ($(findstring -psl,$(CFG)),)
  227. LIBPSL_PATH ?= $(PROOT)/../libpsl
  228. CPPFLAGS += -DUSE_LIBPSL
  229. CPPFLAGS += -isystem "$(LIBPSL_PATH)/include"
  230. LDFLAGS += -L"$(LIBPSL_PATH)/lib"
  231. LIBS += -lpsl
  232. endif
  233. endif
  234. ifneq ($(findstring -ipv6,$(CFG)),)
  235. CPPFLAGS += -DUSE_IPV6
  236. endif
  237. ifneq ($(findstring -watt,$(CFG))$(MSDOS),)
  238. WATT_PATH ?= $(PROOT)/../watt
  239. CPPFLAGS += -isystem "$(WATT_PATH)/inc"
  240. LDFLAGS += -L"$(WATT_PATH)/lib"
  241. LIBS += -lwatt
  242. endif
  243. ifneq ($(findstring 11,$(subst $(subst ,, ),,$(SSLLIBS))),)
  244. CPPFLAGS += -DCURL_WITH_MULTI_SSL
  245. endif
  246. ### Common rules
  247. OBJ_DIR := $(TRIPLET)
  248. ifneq ($(findstring /sh,$(SHELL)),)
  249. DEL = rm -f $1
  250. COPY = -cp -afv $1 $2
  251. MKDIR = mkdir -p $1
  252. RMDIR = rm -fr $1
  253. else
  254. DEL = -del 2>NUL /q /f $(subst /,\,$1)
  255. COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
  256. MKDIR = -md 2>NUL $(subst /,\,$1)
  257. RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
  258. endif
  259. all: $(TARGETS)
  260. $(OBJ_DIR):
  261. -$(call MKDIR, $(OBJ_DIR))
  262. $(OBJ_DIR)/%.o: %.c
  263. $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@
  264. clean:
  265. @$(call DEL, $(TOCLEAN))
  266. @$(RMDIR) $(OBJ_DIR)
  267. distclean vclean: clean
  268. @$(call DEL, $(TARGETS) $(TOVCLEAN))
  269. ### Local
  270. ifdef LOCAL
  271. CPPFLAGS += -DBUILDING_LIBCURL
  272. ### Sources and targets
  273. # Provides CSOURCES, HHEADERS
  274. include Makefile.inc
  275. vpath %.c vauth vquic vssh vtls
  276. libcurl_a_LIBRARY := libcurl.a
  277. TARGETS := $(libcurl_a_LIBRARY)
  278. libcurl_a_OBJECTS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(strip $(CSOURCES))))
  279. libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
  280. TOCLEAN :=
  281. TOVCLEAN :=
  282. ### Rules
  283. $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
  284. @$(call DEL, $@)
  285. $(AR) rcs $@ $(libcurl_a_OBJECTS)
  286. all: $(OBJ_DIR) $(TARGETS)
  287. endif