Debian Codegraph @

others/mbedtls/library/Makefile

raw
1 CFLAGS ?= -O2
2 WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
3 LDFLAGS ?=
4
5 # MicroBlaze specific options:
6 # CFLAGS += -mno-xl-soft-mul -mxl-barrel-shift
7
8 # To compile on Plan9:
9 # CFLAGS += -D_BSD_EXTENSION
10
11 PERL ?= perl
12
13 ifdef WINDOWS
14 PYTHON ?= python
15 else
16 PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
17 endif
18
19 # Set AR_DASH= (empty string) to use an ar implementation that does not accept
20 # the - prefix for command line options (e.g. llvm-ar)
21 AR_DASH ?= -
22
23 ifndef MBEDTLS_PATH
24 MBEDTLS_PATH := ..
25 endif
26
27 ifeq (,$(wildcard $(MBEDTLS_PATH)/framework/exported.make))
28 # Use the define keyword to get a multi-line message.
29 # GNU make appends ". Stop.", so tweak the ending of our message accordingly.
30 define error_message
31 $(MBEDTLS_PATH)/framework/exported.make not found.
32 Run `git submodule update --init` to fetch the submodule contents.
33 This is a fatal error
34 endef
35 $(error $(error_message))
36 endif
37 include $(MBEDTLS_PATH)/framework/exported.make
38
39 include $(MBEDTLS_PATH)/tf-psa-crypto/scripts/crypto-common.make
40
41 # For the time being, Mbed TLS uses non-public interfaces of TF-PSA-Crypto,
42 # so we include both public and internal headers.
43 LOCAL_CFLAGS = $(WARNING_CFLAGS) -I. \
44 $(TF_PSA_CRYPTO_LIBRARY_PRIVATE_INCLUDE) \
45 -I../include \
46 $(TF_PSA_CRYPTO_LIBRARY_PUBLIC_INCLUDE) \
47 -D_FILE_OFFSET_BITS=64
48 LOCAL_LDFLAGS =
49
50 ifdef DEBUG
51 LOCAL_CFLAGS += -g3
52 endif
53
54 # if were running on Windows build for Windows
55 ifdef WINDOWS
56 WINDOWS_BUILD=1
57 else ifeq ($(shell uname -s),Darwin)
58 ifeq ($(AR),ar)
59 APPLE_BUILD ?= 1
60 endif
61 endif
62
63 ifdef WINDOWS_BUILD
64 LOCAL_LDFLAGS += -lbcrypt
65 endif
66
67 # To compile as a shared library:
68 ifdef SHARED
69 # all code is position-indep with mingw, avoid warning about useless flag
70 ifndef WINDOWS_BUILD
71 LOCAL_CFLAGS += -fPIC -fpic
72 endif
73 endif
74
75 SOEXT_TLS?=so.23
76 SOEXT_X509?=so.9
77 SOEXT_CRYPTO?=so.18
78
79 ARFLAGS = $(AR_DASH)src
80 ifdef APPLE_BUILD
81 ifneq ($(APPLE_BUILD),0)
82 ARFLAGS = $(AR_DASH)Src
83 RLFLAGS = -no_warning_for_no_symbols -c
84 RL ?= ranlib
85 endif
86 endif
87
88 DLEXT ?= so
89 ifdef WINDOWS_BUILD
90 # Windows shared library extension:
91 DLEXT = dll
92 else ifdef APPLE_BUILD
93 ifneq ($(APPLE_BUILD),0)
94 # Mac OS X shared library extension:
95 DLEXT = dylib
96 endif
97 endif
98
99 # See root Makefile
100 GEN_FILES ?= yes
101 ifdef GEN_FILES
102 gen_file_dep =
103 else
104 gen_file_dep = |
105 endif
106
107 OBJS_CRYPTO = $(TF_PSA_CRYPTO_LIBRARY_OBJS)
108
109 OBJS_X509= \
110 mbedtls_config.o \
111 x509.o \
112 x509_create.o \
113 x509_crl.o \
114 x509_crt.o \
115 x509_csr.o \
116 x509_oid.o \
117 x509write.o \
118 x509write_crt.o \
119 x509write_csr.o \
120 pkcs7.o \
121 error.o \
122 # This line is intentionally left blank
123
124 OBJS_TLS= \
125 debug.o \
126 mps_reader.o \
127 mps_trace.o \
128 net_sockets.o \
129 ssl_cache.o \
130 ssl_ciphersuites.o \
131 ssl_client.o \
132 ssl_cookie.o \
133 ssl_debug_helpers_generated.o \
134 ssl_msg.o \
135 ssl_ticket.o \
136 ssl_tls.o \
137 ssl_tls12_client.o \
138 ssl_tls12_server.o \
139 ssl_tls13_keys.o \
140 ssl_tls13_client.o \
141 ssl_tls13_server.o \
142 ssl_tls13_generic.o \
143 timing.o \
144 version.o \
145 version_features.o \
146 # This line is intentionally left blank
147
148 .SILENT:
149
150 .PHONY: all static shared clean
151
152 ifndef SHARED
153 all: static
154 else
155 all: shared static
156 endif
157
158 include $(TF_PSA_CRYPTO_CORE_PATH)/crypto-library.make
159
160 static: libmbedcrypto.a libmbedx509.a libmbedtls.a
161 cd ../tests && echo "This is a seedfile that contains 64 bytes (65 on Windows)......" > seedfile
162 cd ../tf-psa-crypto/tests && echo "This is a seedfile that contains 64 bytes (65 on Windows)......" > seedfile
163
164 shared: libmbedcrypto.$(DLEXT) libmbedx509.$(DLEXT) libmbedtls.$(DLEXT)
165
166 # Windows builds under Mingw can fail if make tries to create archives in the same
167 # directory at the same time - see https://bugs.launchpad.net/gcc-arm-embedded/+bug/1848002.
168 # This forces builds of the .a files to be serialised.
169 ifdef WINDOWS
170 libmbedtls.a: | libmbedx509.a
171 libmbedx509.a: | libmbedcrypto.a
172 endif
173
174 # tls
175 libmbedtls.a: $(OBJS_TLS)
176 echo " AR $@"
177 $(AR) $(ARFLAGS) $@ $(OBJS_TLS)
178 ifdef APPLE_BUILD
179 ifneq ($(APPLE_BUILD),0)
180 echo " RL $@"
181 $(RL) $(RLFLAGS) $@
182 endif
183 endif
184
185 libmbedtls.$(SOEXT_TLS): $(OBJS_TLS) libmbedx509.so
186 echo " LD $@"
187 $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS_TLS) -L. -lmbedx509 -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
188
189 ifneq ($(SOEXT_TLS),so)
190 libmbedtls.so: libmbedtls.$(SOEXT_TLS)
191 echo " LN $@ -> $<"
192 ln -sf $< $@
193 endif
194
195 libmbedtls.dylib: $(OBJS_TLS) libmbedx509.dylib
196 echo " LD $@"
197 $(CC) -dynamiclib -o $@ $(OBJS_TLS) -L. -lmbedx509 -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
198
199 libmbedtls.dll: $(OBJS_TLS) libmbedx509.dll
200 echo " LD $@"
201 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,[email protected] -o $@ $(OBJS_TLS) -lws2_32 -lwinmm -lgdi32 -L. -lmbedx509 -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
202
203 # x509
204 libmbedx509.a: $(OBJS_X509)
205 echo " AR $@"
206 $(AR) $(ARFLAGS) $@ $(OBJS_X509)
207 ifdef APPLE_BUILD
208 ifneq ($(APPLE_BUILD),0)
209 echo " RL $@"
210 $(RL) $(RLFLAGS) $@
211 endif
212 endif
213
214 libmbedx509.$(SOEXT_X509): $(OBJS_X509) libmbedcrypto.so
215 echo " LD $@"
216 $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS_X509) -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
217
218 ifneq ($(SOEXT_X509),so)
219 libmbedx509.so: libmbedx509.$(SOEXT_X509)
220 echo " LN $@ -> $<"
221 ln -sf $< $@
222 endif
223
224 libmbedx509.dylib: $(OBJS_X509) libmbedcrypto.dylib
225 echo " LD $@"
226 $(CC) -dynamiclib -o $@ $(OBJS_X509) -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS)
227
228 libmbedx509.dll: $(OBJS_X509) libmbedcrypto.dll
229 echo " LD $@"
230 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,[email protected] -o $@ $(OBJS_X509) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
231
232 # crypto
233 libmbedcrypto.a: $(OBJS_CRYPTO)
234 echo " AR $@"
235 $(AR) $(ARFLAGS) $@ $(OBJS_CRYPTO)
236 ifdef APPLE_BUILD
237 ifneq ($(APPLE_BUILD),0)
238 echo " RL $@"
239 $(RL) $(RLFLAGS) $@
240 endif
241 endif
242
243 libmbedcrypto.$(SOEXT_CRYPTO): $(OBJS_CRYPTO)
244 echo " LD $@"
245 $(CC) -shared -Wl,-soname,$@ -o $@ $(OBJS_CRYPTO) $(LOCAL_LDFLAGS) $(LDFLAGS)
246
247 ifneq ($(SOEXT_CRYPTO),so)
248 libmbedcrypto.so: libmbedcrypto.$(SOEXT_CRYPTO)
249 echo " LN $@ -> $<"
250 ln -sf $< $@
251 endif
252
253 libmbedcrypto.dylib: $(OBJS_CRYPTO)
254 echo " LD $@"
255 $(CC) -dynamiclib -o $@ $(OBJS_CRYPTO) $(LOCAL_LDFLAGS) $(LDFLAGS)
256
257 libmbedcrypto.dll: $(OBJS_CRYPTO)
258 echo " LD $@"
259 $(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,[email protected] -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
260
261 .c.o:
262 echo " CC $<"
263 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
264
265 .c.s:
266 echo " CC $<"
267 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -S -o $@ -c $<
268
269 # List the generated files without running a script, so that this
270 # works with no tooling dependencies when GEN_FILES is disabled.
271 GENERATED_FILES := \
272 mbedtls_config_check_before.h \
273 mbedtls_config_check_final.h \
274 mbedtls_config_check_user.h \
275 error.c \
276 version_features.c \
277 ssl_debug_helpers_generated.c \
278 $(TF_PSA_CRYPTO_LIBRARY_GENERATED_FILES)
279
280 .PHONY: generated_files
281 generated_files: $(GENERATED_FILES)
282
283 error.c: $(gen_file_dep) ../scripts/generate_errors.pl
284 error.c: $(gen_file_dep) ../scripts/data_files/error.fmt
285 error.c: $(gen_file_dep) $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
286 error.c:
287 echo " Gen $@"
288 $(PERL) ../scripts/generate_errors.pl
289
290 ssl_debug_helpers_generated.c: $(gen_file_dep) ../framework/scripts/generate_ssl_debug_helpers.py
291 ssl_debug_helpers_generated.c: $(gen_file_dep) $(filter-out %config%,$(wildcard ../include/mbedtls/*.h))
292 ssl_debug_helpers_generated.c:
293 echo " Gen $@"
294 $(PYTHON) ../framework/scripts/generate_ssl_debug_helpers.py --mbedtls-root .. .
295
296 version_features.c: $(gen_file_dep) ../scripts/generate_features.pl
297 version_features.c: $(gen_file_dep) ../scripts/data_files/version_features.fmt
298 ## The generated file only depends on the options that are present in mbedtls_config.h,
299 ## not on which options are set. To avoid regenerating this file all the time
300 ## when switching between configurations, don't declare mbedtls_config.h as a
301 ## dependency. Remove this file from your working tree if you've just added or
302 ## removed an option in mbedtls_config.h.
303 #version_features.c: ../include/mbedtls/mbedtls_config.h
304 version_features.c:
305 echo " Gen $@"
306 $(PERL) ../scripts/generate_features.pl
307
308 GENERATED_CONFIG_CHECK_FILES = $(shell $(PYTHON) ../scripts/generate_config_checks.py --list .)
309 $(GENERATED_CONFIG_CHECK_FILES): $(gen_file_dep) \
310 ../scripts/generate_config_checks.py \
311 ../framework/scripts/mbedtls_framework/config_checks_generator.py
312 $(GENERATED_CONFIG_CHECK_FILES):
313 echo " Gen $(GENERATED_CONFIG_CHECK_FILES)"
314 $(PYTHON) ../scripts/generate_config_checks.py
315
316 mbedtls_config.o: $(GENERATED_CONFIG_CHECK_FILES)
317
318 clean:
319 ifndef WINDOWS
320 rm -f *.o *.s libmbed*
321 rm -f $(OBJS_CRYPTO) $(OBJS_CRYPTO:.o=.s)
322 else
323 if exist *.o del /Q /F *.o
324 if exist *.s del /Q /F *.s
325 if exist libmbed* del /Q /F libmbed*
326 del /Q /F del_errors_out_if_the_file_list_is_empty_but_not_if_a_file_does_not_exist $(subst /,\,$(OBJS_CRYPTO))
327 endif
328
329 neat: clean
330 ifndef WINDOWS
331 rm -f $(GENERATED_FILES)
332 else
333 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
334 endif