blob: 07eb5567af1f0497033b6bea5c91e35bd7123e38 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001DESTDIR=/usr/local
Manuel Pégourié-Gonnard52859702015-01-27 14:05:16 +01002PREFIX=mbedtls_
Gilles Peskine687d1ab2021-04-22 01:01:56 +02003PERL ?= perl
Paul Bakker5121ce52009-01-03 21:22:43 +00004
Gilles Peskine48230e82024-03-04 16:42:54 +01005ifneq (,$(filter-out lib library/%,$(or $(MAKECMDGOALS),all)))
6 ifeq (,$(wildcard framework/exported.make))
7 # Use the define keyword to get a multi-line message.
8 # GNU make appends ". Stop.", so tweak the ending of our message accordingly.
9 define error_message
10$(MBEDTLS_PATH)/framework/exported.make not found.
11Run `git submodule update --init` to fetch the submodule contents.
12This is a fatal error
13 endef
Harry Ramseye05cf2e2024-09-17 15:12:11 +010014 ifeq (,$(wildcard .git))
15 define error_message
16$(MBEDTLS_PATH)/.git/ not found.
17Please ensure you have downloaded a release version of Mbed TLS from GitHub.
18This is a fatal error
19 endef
20 else
21 define error_message
22$(MBEDTLS_PATH)/framework/exported.make not found.
23Run `git submodule update --init` to fetch the submodule contents.
24This is a fatal error
25 endef
26 endif
Gilles Peskine48230e82024-03-04 16:42:54 +010027 $(error $(error_message))
28 endif
29 include framework/exported.make
30endif
Gilles Peskine469f7812024-02-29 18:19:56 +010031
Paul Bakker5121ce52009-01-03 21:22:43 +000032.SILENT:
33
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +010034.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean
Paul Bakker5121ce52009-01-03 21:22:43 +000035
Andres AG7aa5fa12016-08-25 16:36:16 +010036all: programs tests
37 $(MAKE) post_build
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020038
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020039no_test: programs
40
Ronald Cronddaf99c2020-06-19 11:27:26 +020041programs: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020042 $(MAKE) -C programs
Paul Bakkerf9964ab2012-04-05 12:07:50 +000043
Gilles Peskined001f582024-09-14 13:05:51 +020044ssl-opt: lib mbedtls_test
45 $(MAKE) -C programs ssl-opt
Gilles Peskine870ed2a2024-09-25 10:27:47 +020046 $(MAKE) -C tests ssl-opt
Gilles Peskined001f582024-09-14 13:05:51 +020047
Paul Bakkerf9964ab2012-04-05 12:07:50 +000048lib:
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020049 $(MAKE) -C library
50
Valerio Setti09172652024-06-27 08:00:54 +020051ifndef PSASIM
52tests: lib
53endif
54tests: mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020055 $(MAKE) -C tests
Paul Bakkerf9964ab2012-04-05 12:07:50 +000056
Ronald Cronddaf99c2020-06-19 11:27:26 +020057mbedtls_test:
58 $(MAKE) -C tests mbedtls_test
59
Gilles Peskine687d1ab2021-04-22 01:01:56 +020060library/%:
61 $(MAKE) -C library $*
62programs/%:
63 $(MAKE) -C programs $*
64tests/%:
65 $(MAKE) -C tests $*
66
67.PHONY: generated_files
68generated_files: library/generated_files
69generated_files: programs/generated_files
70generated_files: tests/generated_files
71generated_files: visualc_files
72
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020073# Set GEN_FILES to the empty string to disable dependencies on generated
74# source files. Then `make generated_files` will only build files that
75# are missing, it will not rebuilt files that are present but out of date.
76# This is useful, for example, if you have a source tree where
77# `make generated_files` has already run and file timestamps reflect the
78# time the files were copied or extracted, and you are now in an environment
79# that lacks some of the necessary tools to re-generate the files.
80# If $(GEN_FILES) is non-empty, the generated source files' dependencies
81# are treated ordinarily, based on file timestamps.
82GEN_FILES ?= yes
83
84# In dependencies where the target is a configuration-independent generated
85# file, use `TARGET: $(gen_file_dep) DEPENDENCY1 DEPENDENCY2 ...`
86# rather than directly `TARGET: DEPENDENCY1 DEPENDENCY2 ...`. This
87# enables the re-generation to be turned off when GEN_FILES is disabled.
88ifdef GEN_FILES
89gen_file_dep =
90else
Gilles Peskine1bfc09b2023-09-09 21:26:05 +020091# Order-only dependency: generate the target if it's absent, but don't
92# re-generate it if it's present but older than its dependencies.
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020093gen_file_dep = |
94endif
95
Gilles Peskine687d1ab2021-04-22 01:01:56 +020096.PHONY: visualc_files
Bence Szépkútifac11222024-03-12 16:38:23 +010097VISUALC_FILES = visualc/VS2017/mbedTLS.sln visualc/VS2017/mbedTLS.vcxproj
Gilles Peskine687d1ab2021-04-22 01:01:56 +020098# TODO: $(app).vcxproj for each $(app) in programs/
99visualc_files: $(VISUALC_FILES)
Gilles Peskine94230ea2021-05-18 15:48:56 +0200100
101# Ensure that the .c files that generate_visualc_files.pl enumerates are
Gilles Peskinea13deaf2021-05-19 14:26:37 +0200102# present before it runs. It doesn't matter if the files aren't up-to-date,
103# they just need to be present.
104$(VISUALC_FILES): | library/generated_files
Gilles Peskine0b62b7a2023-09-08 16:19:13 +0200105$(VISUALC_FILES): $(gen_file_dep) scripts/generate_visualc_files.pl
Bence Szépkútifac11222024-03-12 16:38:23 +0100106$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-app-template.vcxproj
107$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-main-template.vcxproj
108$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-sln-template.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200109# TODO: also the list of .c and .h source files, but not their content
110$(VISUALC_FILES):
111 echo " Gen $@ ..."
112 $(PERL) scripts/generate_visualc_files.pl
113
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200114ifndef WINDOWS
Manuel Pégourié-Gonnard99839932015-08-03 10:34:09 +0200115install: no_test
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000116 mkdir -p $(DESTDIR)/include/mbedtls
Ruini Xue5a9cb612018-06-28 23:21:26 +0800117 cp -rp include/mbedtls $(DESTDIR)/include
Ronald Cron05ba9122024-06-17 14:25:26 +0200118 cp -rp tf-psa-crypto/drivers/builtin/include/mbedtls $(DESTDIR)/include
Jaeden Amero3c7cc5e2018-11-15 17:38:58 +0000119 mkdir -p $(DESTDIR)/include/psa
Ronald Cron2581d912024-06-10 16:05:53 +0200120 cp -rp tf-psa-crypto/include/psa $(DESTDIR)/include
Darryl Green11999bb2018-03-13 15:22:58 +0000121
Paul Bakker5121ce52009-01-03 21:22:43 +0000122 mkdir -p $(DESTDIR)/lib
Gilles Peskine722a7e62020-02-26 19:05:19 +0100123 cp -RP library/libmbedtls.* $(DESTDIR)/lib
124 cp -RP library/libmbedx509.* $(DESTDIR)/lib
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200125 cp -RP library/libmbedcrypto.* $(DESTDIR)/lib
Darryl Green11999bb2018-03-13 15:22:58 +0000126
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 mkdir -p $(DESTDIR)/bin
128 for p in programs/*/* ; do \
129 if [ -x $$p ] && [ ! -d $$p ] ; \
130 then \
131 f=$(PREFIX)`basename $$p` ; \
132 cp $$p $(DESTDIR)/bin/$$f ; \
133 fi \
134 done
135
Paul Bakker9a736322012-11-14 12:39:52 +0000136uninstall:
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000137 rm -rf $(DESTDIR)/include/mbedtls
Wu, Jheng-Jhong89b98142020-11-26 09:27:17 +0800138 rm -rf $(DESTDIR)/include/psa
Gilles Peskine722a7e62020-02-26 19:05:19 +0100139 rm -f $(DESTDIR)/lib/libmbedtls.*
140 rm -f $(DESTDIR)/lib/libmbedx509.*
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200141 rm -f $(DESTDIR)/lib/libmbedcrypto.*
Darryl Green11999bb2018-03-13 15:22:58 +0000142
Paul Bakker9a736322012-11-14 12:39:52 +0000143 for p in programs/*/* ; do \
144 if [ -x $$p ] && [ ! -d $$p ] ; \
145 then \
146 f=$(PREFIX)`basename $$p` ; \
147 rm -f $(DESTDIR)/bin/$$f ; \
148 fi \
149 done
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200150endif
Paul Bakker9a736322012-11-14 12:39:52 +0000151
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100152
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300153WARNING_BORDER_LONG =**********************************************************************************\n
154CTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n
155CTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n
156CTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n
157
158CTR_DRBG_128_BIT_KEY_WARNING=\n$(WARNING_BORDER_LONG)$(CTR_DRBG_128_BIT_KEY_WARN_L1)$(CTR_DRBG_128_BIT_KEY_WARN_L2)$(CTR_DRBG_128_BIT_KEY_WARN_L3)$(WARNING_BORDER_LONG)
159
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100160# Post build steps
161post_build:
Simon Butchercff625f2016-06-27 15:15:11 +0100162ifndef WINDOWS
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300163
164 # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200165 -scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300166 echo '$(CTR_DRBG_128_BIT_KEY_WARNING)'
167
Simon Butchercff625f2016-06-27 15:15:11 +0100168endif
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100169
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200170clean: clean_more_on_top
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200171 $(MAKE) -C library clean
172 $(MAKE) -C programs clean
173 $(MAKE) -C tests clean
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200174
175clean_more_on_top:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200176ifndef WINDOWS
Paul Bakkerbd3b3592016-07-13 16:37:32 +0100177 find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} +
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200178endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000179
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200180neat: clean_more_on_top
181 $(MAKE) -C library neat
182 $(MAKE) -C programs neat
183 $(MAKE) -C tests neat
184ifndef WINDOWS
Bence Szépkútifac11222024-03-12 16:38:23 +0100185 rm -f visualc/VS2017/*.vcxproj visualc/VS2017/mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200186else
Bence Szépkútifac11222024-03-12 16:38:23 +0100187 if exist visualc\VS2017\*.vcxproj del /Q /F visualc\VS2017\*.vcxproj
188 if exist visualc\VS2017\mbedTLS.sln del /Q /F visualc\VS2017\mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200189endif
190
Valerio Setti09172652024-06-27 08:00:54 +0200191ifndef PSASIM
192check: lib
193endif
194check: tests
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200195 $(MAKE) -C tests check
Paul Bakker37ca75d2011-01-06 12:28:03 +0000196
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200197test: check
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +0100198
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100199ifndef WINDOWS
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +0100200# For coverage testing:
201# 1. Build with:
202# make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage'
203# 2. Run the relevant tests for the part of the code you're interested in.
204# For the reference coverage measurement, see
205# tests/scripts/basic-build-test.sh
206# 3. Run scripts/lcov.sh to generate an HTML report.
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100207lcov:
Gilles Peskine3d4ea542022-11-30 17:35:44 +0100208 scripts/lcov.sh
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100209
Paul Bakker37ca75d2011-01-06 12:28:03 +0000210apidoc:
211 mkdir -p apidoc
Krzysztof Stachowiak744a4ac2018-01-22 13:38:31 +0100212 cd doxygen && doxygen mbedtls.doxyfile
Paul Bakker37ca75d2011-01-06 12:28:03 +0000213
214apidoc_clean:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200215 rm -rf apidoc
216endif
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100217
218## Editor navigation files
Gilles Peskine646ad222020-11-09 21:20:16 +0100219C_SOURCE_FILES = $(wildcard \
Gilles Peskine646ad222020-11-09 21:20:16 +0100220 include/*/*.h \
221 library/*.[hc] \
Ronald Cron52cd1082024-07-02 07:55:03 +0200222 tf-psa-crypto/core/*.[hc] \
Ronald Crondb9d5182024-06-10 15:58:23 +0200223 tf-psa-crypto/include/*/*.h \
Ronald Cron691f67f2024-07-02 08:50:56 +0200224 tf-psa-crypto/drivers/*/include/*/*.h \
225 tf-psa-crypto/drivers/*/include/*/*/*.h \
226 tf-psa-crypto/drivers/*/include/*/*/*/*.h \
Ronald Cron52cd1082024-07-02 07:55:03 +0200227 tf-psa-crypto/drivers/builtin/src/*.[hc] \
Ronald Cron691f67f2024-07-02 08:50:56 +0200228 tf-psa-crypto/drivers/*/*.c \
229 tf-psa-crypto/drivers/*/*/*.c \
230 tf-psa-crypto/drivers/*/*/*/*.c \
231 tf-psa-crypto/drivers/*/*/*/*/*.c \
Gilles Peskine646ad222020-11-09 21:20:16 +0100232 programs/*/*.[hc] \
233 tests/include/*/*.h tests/include/*/*/*.h \
234 tests/src/*.c tests/src/*/*.c \
235 tests/suites/*.function \
Ronald Cronf3522792024-07-11 12:03:51 +0200236 tf-psa-crypto/tests/suites/*.function \
Gilles Peskine646ad222020-11-09 21:20:16 +0100237)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200238# Exuberant-ctags invocation. Other ctags implementations may require different options.
Gilles Peskineb305b002021-01-13 13:45:30 +0100239CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100240tags: $(C_SOURCE_FILES)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200241 $(CTAGS) $@ $(C_SOURCE_FILES)
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100242TAGS: $(C_SOURCE_FILES)
Gilles Peskineb305b002021-01-13 13:45:30 +0100243 etags --no-line-directive -o $@ $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100244global: GPATH GRTAGS GSYMS GTAGS
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100245GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
246 ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100247cscope: cscope.in.out cscope.po.out cscope.out
Gilles Peskined0c78012020-11-09 21:21:31 +0100248cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES)
Ronald Cron52cd1082024-07-02 07:55:03 +0200249 cscope -bq -u -Iinclude -Ilibrary -Itf-psa-crypto/core \
250 -Itf-psa-crypto/include \
Ronald Cron52cd1082024-07-02 07:55:03 +0200251 -Itf-psa-crypto/drivers/builtin/src \
Ronald Cron691f67f2024-07-02 08:50:56 +0200252 $(patsubst %,-I%,$(wildcard tf-psa-crypto/drivers/*/include)) -Itests/include $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100253.PHONY: cscope global