Makefile.mk 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 all 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 += -I"$(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 += -I"$(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 += -I"$(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 += -I"$(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 += -I"$(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 += -I"$(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 += -I"$(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 += -I"$(MBEDTLS_PATH)/include"
  144. LDFLAGS += -L"$(MBEDTLS_PATH)/lib"
  145. LIBS += -lmbedtls -lmbedx509 -lmbedcrypto
  146. SSLLIBS += 1
  147. endif
  148. ifneq ($(findstring -nghttp2,$(CFG)),)
  149. NGHTTP2_PATH ?= $(PROOT)/../nghttp2
  150. CPPFLAGS += -DUSE_NGHTTP2
  151. CPPFLAGS += -I"$(NGHTTP2_PATH)/include"
  152. LDFLAGS += -L"$(NGHTTP2_PATH)/lib"
  153. LIBS += -lnghttp2
  154. endif
  155. ifeq ($(findstring -nghttp3,$(CFG))$(findstring -ngtcp2,$(CFG)),-nghttp3-ngtcp2)
  156. NGHTTP3_PATH ?= $(PROOT)/../nghttp3
  157. CPPFLAGS += -DUSE_NGHTTP3
  158. CPPFLAGS += -I"$(NGHTTP3_PATH)/include"
  159. LDFLAGS += -L"$(NGHTTP3_PATH)/lib"
  160. LIBS += -lnghttp3
  161. NGTCP2_PATH ?= $(PROOT)/../ngtcp2
  162. CPPFLAGS += -DUSE_NGTCP2
  163. CPPFLAGS += -I"$(NGTCP2_PATH)/include"
  164. LDFLAGS += -L"$(NGTCP2_PATH)/lib"
  165. NGTCP2_LIBS ?=
  166. ifeq ($(NGTCP2_LIBS),)
  167. ifneq ($(findstring -ssl,$(CFG)),)
  168. ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/aead.h),)
  169. NGTCP2_LIBS := -lngtcp2_crypto_boringssl
  170. else # including libressl
  171. NGTCP2_LIBS := -lngtcp2_crypto_quictls
  172. endif
  173. else ifneq ($(findstring -wolfssl,$(CFG)),)
  174. NGTCP2_LIBS := -lngtcp2_crypto_wolfssl
  175. endif
  176. endif
  177. LIBS += -lngtcp2 $(NGTCP2_LIBS)
  178. endif
  179. ifneq ($(findstring -zlib,$(CFG))$(ZLIB),)
  180. ZLIB_PATH ?= $(PROOT)/../zlib
  181. # These CPPFLAGS are also required when compiling the curl tool via 'src'.
  182. CPPFLAGS += -DHAVE_LIBZ
  183. CPPFLAGS += -I"$(ZLIB_PATH)/include"
  184. LDFLAGS += -L"$(ZLIB_PATH)/lib"
  185. ZLIB_LIBS ?= -lz
  186. LIBS += $(ZLIB_LIBS)
  187. ZLIB := 1
  188. endif
  189. ifneq ($(findstring -zstd,$(CFG)),)
  190. ZSTD_PATH ?= $(PROOT)/../zstd
  191. CPPFLAGS += -DHAVE_ZSTD
  192. CPPFLAGS += -I"$(ZSTD_PATH)/include"
  193. LDFLAGS += -L"$(ZSTD_PATH)/lib"
  194. ZSTD_LIBS ?= -lzstd
  195. LIBS += $(ZSTD_LIBS)
  196. endif
  197. ifneq ($(findstring -brotli,$(CFG)),)
  198. BROTLI_PATH ?= $(PROOT)/../brotli
  199. CPPFLAGS += -DHAVE_BROTLI
  200. CPPFLAGS += -I"$(BROTLI_PATH)/include"
  201. LDFLAGS += -L"$(BROTLI_PATH)/lib"
  202. BROTLI_LIBS ?= -lbrotlidec -lbrotlicommon
  203. LIBS += $(BROTLI_LIBS)
  204. endif
  205. ifneq ($(findstring -gsasl,$(CFG)),)
  206. LIBGSASL_PATH ?= $(PROOT)/../gsasl
  207. CPPFLAGS += -DUSE_GSASL
  208. CPPFLAGS += -I"$(LIBGSASL_PATH)/include"
  209. LDFLAGS += -L"$(LIBGSASL_PATH)/lib"
  210. LIBS += -lgsasl
  211. endif
  212. ifneq ($(findstring -idn2,$(CFG)),)
  213. LIBIDN2_PATH ?= $(PROOT)/../libidn2
  214. CPPFLAGS += -DUSE_LIBIDN2
  215. CPPFLAGS += -I"$(LIBIDN2_PATH)/include"
  216. LDFLAGS += -L"$(LIBIDN2_PATH)/lib"
  217. LIBS += -lidn2
  218. ifneq ($(findstring -psl,$(CFG)),)
  219. LIBPSL_PATH ?= $(PROOT)/../libpsl
  220. CPPFLAGS += -DUSE_LIBPSL
  221. CPPFLAGS += -I"$(LIBPSL_PATH)/include"
  222. LDFLAGS += -L"$(LIBPSL_PATH)/lib"
  223. LIBS += -lpsl
  224. endif
  225. endif
  226. ifneq ($(findstring -ipv6,$(CFG)),)
  227. CPPFLAGS += -DUSE_IPV6
  228. endif
  229. ifneq ($(findstring -watt,$(CFG))$(MSDOS),)
  230. WATT_PATH ?= $(PROOT)/../watt
  231. CPPFLAGS += -I"$(WATT_PATH)/inc"
  232. LDFLAGS += -L"$(WATT_PATH)/lib"
  233. LIBS += -lwatt
  234. endif
  235. ifneq ($(findstring 11,$(subst $(subst ,, ),,$(SSLLIBS))),)
  236. CPPFLAGS += -DCURL_WITH_MULTI_SSL
  237. endif
  238. ### Common rules
  239. OBJ_DIR := $(TRIPLET)
  240. ifneq ($(findstring /sh,$(SHELL)),)
  241. DEL = rm -f $1
  242. COPY = -cp -afv $1 $2
  243. MKDIR = mkdir -p $1
  244. RMDIR = rm -fr $1
  245. WHICH = $(SHELL) -c "command -v $1"
  246. else
  247. DEL = -del 2>NUL /q /f $(subst /,\,$1)
  248. COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
  249. MKDIR = -md 2>NUL $(subst /,\,$1)
  250. RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
  251. WHICH = where $1
  252. endif
  253. all: $(TARGETS)
  254. $(OBJ_DIR):
  255. -$(call MKDIR, $(OBJ_DIR))
  256. $(OBJ_DIR)/%.o: %.c
  257. $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@
  258. clean:
  259. @$(call DEL, $(TOCLEAN))
  260. @$(RMDIR) $(OBJ_DIR)
  261. distclean vclean: clean
  262. @$(call DEL, $(TARGETS) $(TOVCLEAN))
  263. ### Local
  264. ifdef LOCAL
  265. CPPFLAGS += -DBUILDING_LIBCURL
  266. ### Sources and targets
  267. # Provides CSOURCES, HHEADERS
  268. include Makefile.inc
  269. vpath %.c vauth vquic vssh vtls
  270. libcurl_a_LIBRARY := libcurl.a
  271. TARGETS := $(libcurl_a_LIBRARY)
  272. libcurl_a_OBJECTS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(strip $(CSOURCES))))
  273. libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
  274. TOCLEAN :=
  275. TOVCLEAN :=
  276. ### Rules
  277. $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
  278. @$(call DEL, $@)
  279. $(AR) rcs $@ $(libcurl_a_OBJECTS)
  280. all: $(OBJ_DIR) $(TARGETS)
  281. endif