1 | #***************************************************************************
|
---|
2 | # _ _ ____ _
|
---|
3 | # Project ___| | | | _ \| |
|
---|
4 | # / __| | | | |_) | |
|
---|
5 | # | (__| |_| | _ <| |___
|
---|
6 | # \___|\___/|_| \_\_____|
|
---|
7 | #
|
---|
8 | # Copyright (C) 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 | # 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 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 += -isystem "$(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 += -isystem "$(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 += -isystem "$(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 += -isystem "$(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 += -isystem "$(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 += -isystem "$(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 += -isystem "$(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 += -isystem "$(MBEDTLS_PATH)/include"
|
---|
165 | LDFLAGS += -L"$(MBEDTLS_PATH)/lib"
|
---|
166 | LIBS += -lmbedtls -lmbedx509 -lmbedcrypto
|
---|
167 | SSLLIBS += 1
|
---|
168 | endif
|
---|
169 | ifneq ($(findstring -bearssl,$(CFG)),)
|
---|
170 | BEARSSL_PATH ?= $(PROOT)/../bearssl
|
---|
171 | CPPFLAGS += -DUSE_BEARSSL
|
---|
172 | CPPFLAGS += -isystem "$(BEARSSL_PATH)/inc"
|
---|
173 | LDFLAGS += -L"$(BEARSSL_PATH)/build"
|
---|
174 | LIBS += -lbearssl
|
---|
175 | SSLLIBS += 1
|
---|
176 | endif
|
---|
177 |
|
---|
178 | ifneq ($(findstring -nghttp2,$(CFG)),)
|
---|
179 | NGHTTP2_PATH ?= $(PROOT)/../nghttp2
|
---|
180 | CPPFLAGS += -DUSE_NGHTTP2
|
---|
181 | CPPFLAGS += -isystem "$(NGHTTP2_PATH)/include"
|
---|
182 | LDFLAGS += -L"$(NGHTTP2_PATH)/lib"
|
---|
183 | LIBS += -lnghttp2
|
---|
184 | endif
|
---|
185 |
|
---|
186 | ifeq ($(findstring -nghttp3,$(CFG))$(findstring -ngtcp2,$(CFG)),-nghttp3-ngtcp2)
|
---|
187 | NGHTTP3_PATH ?= $(PROOT)/../nghttp3
|
---|
188 | CPPFLAGS += -DUSE_NGHTTP3
|
---|
189 | CPPFLAGS += -isystem "$(NGHTTP3_PATH)/include"
|
---|
190 | LDFLAGS += -L"$(NGHTTP3_PATH)/lib"
|
---|
191 | LIBS += -lnghttp3
|
---|
192 |
|
---|
193 | NGTCP2_PATH ?= $(PROOT)/../ngtcp2
|
---|
194 | CPPFLAGS += -DUSE_NGTCP2
|
---|
195 | CPPFLAGS += -isystem "$(NGTCP2_PATH)/include"
|
---|
196 | LDFLAGS += -L"$(NGTCP2_PATH)/lib"
|
---|
197 |
|
---|
198 | NGTCP2_LIBS ?=
|
---|
199 | ifeq ($(NGTCP2_LIBS),)
|
---|
200 | ifneq ($(findstring -ssl,$(CFG)),)
|
---|
201 | ifneq ($(wildcard $(OPENSSL_INCLUDE)/openssl/aead.h),)
|
---|
202 | NGTCP2_LIBS := -lngtcp2_crypto_boringssl
|
---|
203 | else # including libressl
|
---|
204 | NGTCP2_LIBS := -lngtcp2_crypto_quictls
|
---|
205 | endif
|
---|
206 | else ifneq ($(findstring -wolfssl,$(CFG)),)
|
---|
207 | NGTCP2_LIBS := -lngtcp2_crypto_wolfssl
|
---|
208 | endif
|
---|
209 | endif
|
---|
210 |
|
---|
211 | LIBS += -lngtcp2 $(NGTCP2_LIBS)
|
---|
212 | endif
|
---|
213 |
|
---|
214 | ifneq ($(findstring -zlib,$(CFG))$(ZLIB),)
|
---|
215 | ZLIB_PATH ?= $(PROOT)/../zlib
|
---|
216 | # These CPPFLAGS are also required when compiling the curl tool via 'src'.
|
---|
217 | CPPFLAGS += -DHAVE_LIBZ
|
---|
218 | CPPFLAGS += -isystem "$(ZLIB_PATH)/include"
|
---|
219 | LDFLAGS += -L"$(ZLIB_PATH)/lib"
|
---|
220 | ZLIB_LIBS ?= -lz
|
---|
221 | LIBS += $(ZLIB_LIBS)
|
---|
222 | ZLIB := 1
|
---|
223 | endif
|
---|
224 | ifneq ($(findstring -zstd,$(CFG)),)
|
---|
225 | ZSTD_PATH ?= $(PROOT)/../zstd
|
---|
226 | CPPFLAGS += -DHAVE_ZSTD
|
---|
227 | CPPFLAGS += -isystem "$(ZSTD_PATH)/include"
|
---|
228 | LDFLAGS += -L"$(ZSTD_PATH)/lib"
|
---|
229 | ZSTD_LIBS ?= -lzstd
|
---|
230 | LIBS += $(ZSTD_LIBS)
|
---|
231 | endif
|
---|
232 | ifneq ($(findstring -brotli,$(CFG)),)
|
---|
233 | BROTLI_PATH ?= $(PROOT)/../brotli
|
---|
234 | CPPFLAGS += -DHAVE_BROTLI
|
---|
235 | CPPFLAGS += -isystem "$(BROTLI_PATH)/include"
|
---|
236 | LDFLAGS += -L"$(BROTLI_PATH)/lib"
|
---|
237 | BROTLI_LIBS ?= -lbrotlidec -lbrotlicommon
|
---|
238 | LIBS += $(BROTLI_LIBS)
|
---|
239 | endif
|
---|
240 | ifneq ($(findstring -gsasl,$(CFG)),)
|
---|
241 | LIBGSASL_PATH ?= $(PROOT)/../gsasl
|
---|
242 | CPPFLAGS += -DUSE_GSASL
|
---|
243 | CPPFLAGS += -isystem "$(LIBGSASL_PATH)/include"
|
---|
244 | LDFLAGS += -L"$(LIBGSASL_PATH)/lib"
|
---|
245 | LIBS += -lgsasl
|
---|
246 | endif
|
---|
247 |
|
---|
248 | ifneq ($(findstring -idn2,$(CFG)),)
|
---|
249 | LIBIDN2_PATH ?= $(PROOT)/../libidn2
|
---|
250 | CPPFLAGS += -DHAVE_LIBIDN2 -DHAVE_IDN2_H
|
---|
251 | CPPFLAGS += -isystem "$(LIBIDN2_PATH)/include"
|
---|
252 | LDFLAGS += -L"$(LIBIDN2_PATH)/lib"
|
---|
253 | LIBS += -lidn2
|
---|
254 |
|
---|
255 | ifneq ($(findstring -psl,$(CFG)),)
|
---|
256 | LIBPSL_PATH ?= $(PROOT)/../libpsl
|
---|
257 | CPPFLAGS += -DUSE_LIBPSL
|
---|
258 | CPPFLAGS += -isystem "$(LIBPSL_PATH)/include"
|
---|
259 | LDFLAGS += -L"$(LIBPSL_PATH)/lib"
|
---|
260 | LIBS += -lpsl
|
---|
261 | endif
|
---|
262 | endif
|
---|
263 |
|
---|
264 | ifneq ($(findstring -ipv6,$(CFG)),)
|
---|
265 | CPPFLAGS += -DUSE_IPV6
|
---|
266 | endif
|
---|
267 |
|
---|
268 | ifneq ($(findstring -watt,$(CFG))$(MSDOS),)
|
---|
269 | WATT_PATH ?= $(PROOT)/../watt
|
---|
270 | CPPFLAGS += -isystem "$(WATT_PATH)/inc"
|
---|
271 | LDFLAGS += -L"$(WATT_PATH)/lib"
|
---|
272 | LIBS += -lwatt
|
---|
273 | endif
|
---|
274 |
|
---|
275 | ifneq ($(findstring 11,$(subst $(subst ,, ),,$(SSLLIBS))),)
|
---|
276 | CPPFLAGS += -DCURL_WITH_MULTI_SSL
|
---|
277 | endif
|
---|
278 |
|
---|
279 | ### Common rules
|
---|
280 |
|
---|
281 | OBJ_DIR := $(TRIPLET)
|
---|
282 |
|
---|
283 | ifneq ($(findstring /sh,$(SHELL)),)
|
---|
284 | DEL = rm -f $1
|
---|
285 | COPY = -cp -afv $1 $2
|
---|
286 | MKDIR = mkdir -p $1
|
---|
287 | RMDIR = rm -fr $1
|
---|
288 | else
|
---|
289 | DEL = -del 2>NUL /q /f $(subst /,\,$1)
|
---|
290 | COPY = -copy 2>NUL /y $(subst /,\,$1) $(subst /,\,$2)
|
---|
291 | MKDIR = -md 2>NUL $(subst /,\,$1)
|
---|
292 | RMDIR = -rd 2>NUL /q /s $(subst /,\,$1)
|
---|
293 | endif
|
---|
294 |
|
---|
295 | all: $(TARGETS)
|
---|
296 |
|
---|
297 | $(OBJ_DIR):
|
---|
298 | -$(call MKDIR, $(OBJ_DIR))
|
---|
299 |
|
---|
300 | $(OBJ_DIR)/%.o: %.c
|
---|
301 | $(CC) -W -Wall $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
---|
302 |
|
---|
303 | clean:
|
---|
304 | @$(call DEL, $(TOCLEAN))
|
---|
305 | @$(RMDIR) $(OBJ_DIR)
|
---|
306 |
|
---|
307 | distclean vclean: clean
|
---|
308 | @$(call DEL, $(TARGETS) $(TOVCLEAN))
|
---|
309 |
|
---|
310 | ### Local
|
---|
311 |
|
---|
312 | ifdef LOCAL
|
---|
313 |
|
---|
314 | CPPFLAGS += -DBUILDING_LIBCURL
|
---|
315 |
|
---|
316 | ### Sources and targets
|
---|
317 |
|
---|
318 | # Provides CSOURCES, HHEADERS
|
---|
319 | include Makefile.inc
|
---|
320 |
|
---|
321 | vpath %.c vauth vquic vssh vtls
|
---|
322 |
|
---|
323 | libcurl_a_LIBRARY := libcurl.a
|
---|
324 |
|
---|
325 | TARGETS := $(libcurl_a_LIBRARY)
|
---|
326 |
|
---|
327 | libcurl_a_OBJECTS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(strip $(CSOURCES))))
|
---|
328 | libcurl_a_DEPENDENCIES := $(strip $(CSOURCES) $(HHEADERS))
|
---|
329 |
|
---|
330 | TOCLEAN :=
|
---|
331 | TOVCLEAN :=
|
---|
332 |
|
---|
333 | ### Rules
|
---|
334 |
|
---|
335 | $(libcurl_a_LIBRARY): $(libcurl_a_OBJECTS) $(libcurl_a_DEPENDENCIES)
|
---|
336 | @$(call DEL, $@)
|
---|
337 | $(AR) rcs $@ $(libcurl_a_OBJECTS)
|
---|
338 |
|
---|
339 | all: $(OBJ_DIR) $(TARGETS)
|
---|
340 | endif
|
---|