blob: b0040df8b68562f303951ff7f42ed231a6186494 [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.
Harry Ramsey0fdb4042024-12-10 09:58:23 +00009 ifneq (,$(wildcard .git))
Harry Ramseyd532a662024-11-04 10:50:30 +000010 define error_message
Harry Ramsey0ad7cc22024-11-04 12:18:53 +000011${MBEDTLS_PATH}/framework/exported.make not found (and does appear to be a git checkout). Run `git submodule update --init` from the source tree to fetch the submodule contents.
Gilles Peskine48230e82024-03-04 16:42:54 +010012This is a fatal error
Harry Ramseybfd83ba2024-11-04 11:39:46 +000013 endef
Harry Ramseyd532a662024-11-04 10:50:30 +000014 else
Harry Ramseybfd83ba2024-11-04 11:39:46 +000015 define error_message
Harry Ramsey0ad7cc22024-11-04 12:18:53 +000016${MBEDTLS_PATH}/framework/exported.make not found (and does not appear to be a git checkout). Please ensure you have downloaded the right archive from the release page on GitHub.
Harry Ramseybfd83ba2024-11-04 11:39:46 +000017 endef
Harry Ramseyd532a662024-11-04 10:50:30 +000018 endif
Gilles Peskine48230e82024-03-04 16:42:54 +010019 $(error $(error_message))
20 endif
21 include framework/exported.make
22endif
Gilles Peskine469f7812024-02-29 18:19:56 +010023
Paul Bakker5121ce52009-01-03 21:22:43 +000024.SILENT:
25
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +010026.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean
Paul Bakker5121ce52009-01-03 21:22:43 +000027
Andres AG7aa5fa12016-08-25 16:36:16 +010028all: programs tests
29 $(MAKE) post_build
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020030
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020031no_test: programs
32
Ronald Cronddaf99c2020-06-19 11:27:26 +020033programs: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020034 $(MAKE) -C programs
Paul Bakkerf9964ab2012-04-05 12:07:50 +000035
Gilles Peskineb35ed452024-09-14 13:05:51 +020036ssl-opt: lib mbedtls_test
37 $(MAKE) -C programs ssl-opt
Gilles Peskineae7e1c72024-09-25 10:27:47 +020038 $(MAKE) -C tests ssl-opt
Gilles Peskineb35ed452024-09-14 13:05:51 +020039
Paul Bakkerf9964ab2012-04-05 12:07:50 +000040lib:
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020041 $(MAKE) -C library
42
Ronald Cronddaf99c2020-06-19 11:27:26 +020043tests: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020044 $(MAKE) -C tests
Paul Bakkerf9964ab2012-04-05 12:07:50 +000045
Ronald Cronddaf99c2020-06-19 11:27:26 +020046mbedtls_test:
47 $(MAKE) -C tests mbedtls_test
48
Gilles Peskine687d1ab2021-04-22 01:01:56 +020049library/%:
50 $(MAKE) -C library $*
51programs/%:
52 $(MAKE) -C programs $*
53tests/%:
54 $(MAKE) -C tests $*
55
56.PHONY: generated_files
57generated_files: library/generated_files
58generated_files: programs/generated_files
59generated_files: tests/generated_files
60generated_files: visualc_files
61
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020062# Set GEN_FILES to the empty string to disable dependencies on generated
63# source files. Then `make generated_files` will only build files that
64# are missing, it will not rebuilt files that are present but out of date.
65# This is useful, for example, if you have a source tree where
66# `make generated_files` has already run and file timestamps reflect the
67# time the files were copied or extracted, and you are now in an environment
68# that lacks some of the necessary tools to re-generate the files.
69# If $(GEN_FILES) is non-empty, the generated source files' dependencies
70# are treated ordinarily, based on file timestamps.
71GEN_FILES ?= yes
72
73# In dependencies where the target is a configuration-independent generated
74# file, use `TARGET: $(gen_file_dep) DEPENDENCY1 DEPENDENCY2 ...`
75# rather than directly `TARGET: DEPENDENCY1 DEPENDENCY2 ...`. This
76# enables the re-generation to be turned off when GEN_FILES is disabled.
77ifdef GEN_FILES
78gen_file_dep =
79else
Gilles Peskine1bfc09b2023-09-09 21:26:05 +020080# Order-only dependency: generate the target if it's absent, but don't
81# re-generate it if it's present but older than its dependencies.
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020082gen_file_dep = |
83endif
84
Gilles Peskine687d1ab2021-04-22 01:01:56 +020085.PHONY: visualc_files
Bence Szépkútifac11222024-03-12 16:38:23 +010086VISUALC_FILES = visualc/VS2017/mbedTLS.sln visualc/VS2017/mbedTLS.vcxproj
Gilles Peskine687d1ab2021-04-22 01:01:56 +020087# TODO: $(app).vcxproj for each $(app) in programs/
88visualc_files: $(VISUALC_FILES)
Gilles Peskine94230ea2021-05-18 15:48:56 +020089
90# Ensure that the .c files that generate_visualc_files.pl enumerates are
Gilles Peskinea13deaf2021-05-19 14:26:37 +020091# present before it runs. It doesn't matter if the files aren't up-to-date,
92# they just need to be present.
93$(VISUALC_FILES): | library/generated_files
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020094$(VISUALC_FILES): $(gen_file_dep) scripts/generate_visualc_files.pl
Bence Szépkútifac11222024-03-12 16:38:23 +010095$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-app-template.vcxproj
96$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-main-template.vcxproj
97$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-sln-template.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +020098# TODO: also the list of .c and .h source files, but not their content
99$(VISUALC_FILES):
100 echo " Gen $@ ..."
101 $(PERL) scripts/generate_visualc_files.pl
102
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200103ifndef WINDOWS
Manuel Pégourié-Gonnard99839932015-08-03 10:34:09 +0200104install: no_test
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000105 mkdir -p $(DESTDIR)/include/mbedtls
Ruini Xue5a9cb612018-06-28 23:21:26 +0800106 cp -rp include/mbedtls $(DESTDIR)/include
Jaeden Amero3c7cc5e2018-11-15 17:38:58 +0000107 mkdir -p $(DESTDIR)/include/psa
108 cp -rp include/psa $(DESTDIR)/include
Darryl Green11999bb2018-03-13 15:22:58 +0000109
Paul Bakker5121ce52009-01-03 21:22:43 +0000110 mkdir -p $(DESTDIR)/lib
Gilles Peskine722a7e62020-02-26 19:05:19 +0100111 cp -RP library/libmbedtls.* $(DESTDIR)/lib
112 cp -RP library/libmbedx509.* $(DESTDIR)/lib
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200113 cp -RP library/libmbedcrypto.* $(DESTDIR)/lib
Darryl Green11999bb2018-03-13 15:22:58 +0000114
Paul Bakker5121ce52009-01-03 21:22:43 +0000115 mkdir -p $(DESTDIR)/bin
116 for p in programs/*/* ; do \
117 if [ -x $$p ] && [ ! -d $$p ] ; \
118 then \
119 f=$(PREFIX)`basename $$p` ; \
120 cp $$p $(DESTDIR)/bin/$$f ; \
121 fi \
122 done
123
Paul Bakker9a736322012-11-14 12:39:52 +0000124uninstall:
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000125 rm -rf $(DESTDIR)/include/mbedtls
Wu, Jheng-Jhong89b98142020-11-26 09:27:17 +0800126 rm -rf $(DESTDIR)/include/psa
Gilles Peskine722a7e62020-02-26 19:05:19 +0100127 rm -f $(DESTDIR)/lib/libmbedtls.*
128 rm -f $(DESTDIR)/lib/libmbedx509.*
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200129 rm -f $(DESTDIR)/lib/libmbedcrypto.*
Darryl Green11999bb2018-03-13 15:22:58 +0000130
Paul Bakker9a736322012-11-14 12:39:52 +0000131 for p in programs/*/* ; do \
132 if [ -x $$p ] && [ ! -d $$p ] ; \
133 then \
134 f=$(PREFIX)`basename $$p` ; \
135 rm -f $(DESTDIR)/bin/$$f ; \
136 fi \
137 done
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200138endif
Paul Bakker9a736322012-11-14 12:39:52 +0000139
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100140
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300141WARNING_BORDER_LONG =**********************************************************************************\n
142CTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n
143CTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n
144CTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n
145
146CTR_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)
147
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100148# Post build steps
149post_build:
Simon Butchercff625f2016-06-27 15:15:11 +0100150ifndef WINDOWS
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300151
152 # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200153 -scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300154 echo '$(CTR_DRBG_128_BIT_KEY_WARNING)'
155
Simon Butchercff625f2016-06-27 15:15:11 +0100156endif
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100157
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200158clean: clean_more_on_top
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200159 $(MAKE) -C library clean
160 $(MAKE) -C programs clean
161 $(MAKE) -C tests clean
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200162
163clean_more_on_top:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200164ifndef WINDOWS
Paul Bakkerbd3b3592016-07-13 16:37:32 +0100165 find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} +
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200166endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000167
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200168neat: clean_more_on_top
169 $(MAKE) -C library neat
170 $(MAKE) -C programs neat
171 $(MAKE) -C tests neat
172ifndef WINDOWS
Bence Szépkútifac11222024-03-12 16:38:23 +0100173 rm -f visualc/VS2017/*.vcxproj visualc/VS2017/mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200174else
Bence Szépkútifac11222024-03-12 16:38:23 +0100175 if exist visualc\VS2017\*.vcxproj del /Q /F visualc\VS2017\*.vcxproj
176 if exist visualc\VS2017\mbedTLS.sln del /Q /F visualc\VS2017\mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200177endif
178
Andres AGc49b8082016-08-31 16:10:45 +0100179check: lib tests
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200180 $(MAKE) -C tests check
Paul Bakker37ca75d2011-01-06 12:28:03 +0000181
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200182test: check
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +0100183
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100184ifndef WINDOWS
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +0100185# For coverage testing:
186# 1. Build with:
187# make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage'
188# 2. Run the relevant tests for the part of the code you're interested in.
189# For the reference coverage measurement, see
190# tests/scripts/basic-build-test.sh
191# 3. Run scripts/lcov.sh to generate an HTML report.
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100192lcov:
Gilles Peskine3d4ea542022-11-30 17:35:44 +0100193 scripts/lcov.sh
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100194
Paul Bakker37ca75d2011-01-06 12:28:03 +0000195apidoc:
196 mkdir -p apidoc
Krzysztof Stachowiak744a4ac2018-01-22 13:38:31 +0100197 cd doxygen && doxygen mbedtls.doxyfile
Paul Bakker37ca75d2011-01-06 12:28:03 +0000198
199apidoc_clean:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200200 rm -rf apidoc
201endif
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100202
203## Editor navigation files
Gilles Peskine646ad222020-11-09 21:20:16 +0100204C_SOURCE_FILES = $(wildcard \
205 3rdparty/*/include/*/*.h 3rdparty/*/include/*/*/*.h 3rdparty/*/include/*/*/*/*.h \
206 3rdparty/*/*.c 3rdparty/*/*/*.c 3rdparty/*/*/*/*.c 3rdparty/*/*/*/*/*.c \
207 include/*/*.h \
208 library/*.[hc] \
209 programs/*/*.[hc] \
David Horstmanndcf42a02024-11-08 14:40:12 +0000210 framework/tests/include/*/*.h framework/tests/include/*/*/*.h \
211 framework/tests/src/*.c framework/tests/src/*/*.c \
Gilles Peskine646ad222020-11-09 21:20:16 +0100212 tests/suites/*.function \
213)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200214# Exuberant-ctags invocation. Other ctags implementations may require different options.
Gilles Peskineb305b002021-01-13 13:45:30 +0100215CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100216tags: $(C_SOURCE_FILES)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200217 $(CTAGS) $@ $(C_SOURCE_FILES)
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100218TAGS: $(C_SOURCE_FILES)
Gilles Peskineb305b002021-01-13 13:45:30 +0100219 etags --no-line-directive -o $@ $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100220global: GPATH GRTAGS GSYMS GTAGS
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100221GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
222 ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100223cscope: cscope.in.out cscope.po.out cscope.out
Gilles Peskined0c78012020-11-09 21:21:31 +0100224cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES)
David Horstmanndcf42a02024-11-08 14:40:12 +0000225 cscope -bq -u -Iinclude -Ilibrary $(patsubst %,-I%,$(wildcard 3rdparty/*/include)) -Iframework/tests/include $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100226.PHONY: cscope global