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