blob: 00de60823b56ee5cd07a41fbc3bf6738f937813d [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
14 $(error $(error_message))
15 endif
16 include framework/exported.make
17endif
Gilles Peskine469f7812024-02-29 18:19:56 +010018
Paul Bakker5121ce52009-01-03 21:22:43 +000019.SILENT:
20
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +010021.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean
Paul Bakker5121ce52009-01-03 21:22:43 +000022
Andres AG7aa5fa12016-08-25 16:36:16 +010023all: programs tests
24 $(MAKE) post_build
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020025
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020026no_test: programs
27
Ronald Cronddaf99c2020-06-19 11:27:26 +020028programs: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020029 $(MAKE) -C programs
Paul Bakkerf9964ab2012-04-05 12:07:50 +000030
Gilles Peskineb35ed452024-09-14 13:05:51 +020031ssl-opt: lib mbedtls_test
32 $(MAKE) -C programs ssl-opt
33
Paul Bakkerf9964ab2012-04-05 12:07:50 +000034lib:
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020035 $(MAKE) -C library
36
Ronald Cronddaf99c2020-06-19 11:27:26 +020037tests: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020038 $(MAKE) -C tests
Paul Bakkerf9964ab2012-04-05 12:07:50 +000039
Ronald Cronddaf99c2020-06-19 11:27:26 +020040mbedtls_test:
41 $(MAKE) -C tests mbedtls_test
42
Gilles Peskine687d1ab2021-04-22 01:01:56 +020043library/%:
44 $(MAKE) -C library $*
45programs/%:
46 $(MAKE) -C programs $*
47tests/%:
48 $(MAKE) -C tests $*
49
50.PHONY: generated_files
51generated_files: library/generated_files
52generated_files: programs/generated_files
53generated_files: tests/generated_files
54generated_files: visualc_files
55
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020056# Set GEN_FILES to the empty string to disable dependencies on generated
57# source files. Then `make generated_files` will only build files that
58# are missing, it will not rebuilt files that are present but out of date.
59# This is useful, for example, if you have a source tree where
60# `make generated_files` has already run and file timestamps reflect the
61# time the files were copied or extracted, and you are now in an environment
62# that lacks some of the necessary tools to re-generate the files.
63# If $(GEN_FILES) is non-empty, the generated source files' dependencies
64# are treated ordinarily, based on file timestamps.
65GEN_FILES ?= yes
66
67# In dependencies where the target is a configuration-independent generated
68# file, use `TARGET: $(gen_file_dep) DEPENDENCY1 DEPENDENCY2 ...`
69# rather than directly `TARGET: DEPENDENCY1 DEPENDENCY2 ...`. This
70# enables the re-generation to be turned off when GEN_FILES is disabled.
71ifdef GEN_FILES
72gen_file_dep =
73else
Gilles Peskine1bfc09b2023-09-09 21:26:05 +020074# Order-only dependency: generate the target if it's absent, but don't
75# re-generate it if it's present but older than its dependencies.
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020076gen_file_dep = |
77endif
78
Gilles Peskine687d1ab2021-04-22 01:01:56 +020079.PHONY: visualc_files
Bence Szépkútifac11222024-03-12 16:38:23 +010080VISUALC_FILES = visualc/VS2017/mbedTLS.sln visualc/VS2017/mbedTLS.vcxproj
Gilles Peskine687d1ab2021-04-22 01:01:56 +020081# TODO: $(app).vcxproj for each $(app) in programs/
82visualc_files: $(VISUALC_FILES)
Gilles Peskine94230ea2021-05-18 15:48:56 +020083
84# Ensure that the .c files that generate_visualc_files.pl enumerates are
Gilles Peskinea13deaf2021-05-19 14:26:37 +020085# present before it runs. It doesn't matter if the files aren't up-to-date,
86# they just need to be present.
87$(VISUALC_FILES): | library/generated_files
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020088$(VISUALC_FILES): $(gen_file_dep) scripts/generate_visualc_files.pl
Bence Szépkútifac11222024-03-12 16:38:23 +010089$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-app-template.vcxproj
90$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-main-template.vcxproj
91$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-sln-template.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +020092# TODO: also the list of .c and .h source files, but not their content
93$(VISUALC_FILES):
94 echo " Gen $@ ..."
95 $(PERL) scripts/generate_visualc_files.pl
96
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020097ifndef WINDOWS
Manuel Pégourié-Gonnard99839932015-08-03 10:34:09 +020098install: no_test
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000099 mkdir -p $(DESTDIR)/include/mbedtls
Ruini Xue5a9cb612018-06-28 23:21:26 +0800100 cp -rp include/mbedtls $(DESTDIR)/include
Jaeden Amero3c7cc5e2018-11-15 17:38:58 +0000101 mkdir -p $(DESTDIR)/include/psa
102 cp -rp include/psa $(DESTDIR)/include
Darryl Green11999bb2018-03-13 15:22:58 +0000103
Paul Bakker5121ce52009-01-03 21:22:43 +0000104 mkdir -p $(DESTDIR)/lib
Gilles Peskine722a7e62020-02-26 19:05:19 +0100105 cp -RP library/libmbedtls.* $(DESTDIR)/lib
106 cp -RP library/libmbedx509.* $(DESTDIR)/lib
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200107 cp -RP library/libmbedcrypto.* $(DESTDIR)/lib
Darryl Green11999bb2018-03-13 15:22:58 +0000108
Paul Bakker5121ce52009-01-03 21:22:43 +0000109 mkdir -p $(DESTDIR)/bin
110 for p in programs/*/* ; do \
111 if [ -x $$p ] && [ ! -d $$p ] ; \
112 then \
113 f=$(PREFIX)`basename $$p` ; \
114 cp $$p $(DESTDIR)/bin/$$f ; \
115 fi \
116 done
117
Paul Bakker9a736322012-11-14 12:39:52 +0000118uninstall:
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000119 rm -rf $(DESTDIR)/include/mbedtls
Wu, Jheng-Jhong89b98142020-11-26 09:27:17 +0800120 rm -rf $(DESTDIR)/include/psa
Gilles Peskine722a7e62020-02-26 19:05:19 +0100121 rm -f $(DESTDIR)/lib/libmbedtls.*
122 rm -f $(DESTDIR)/lib/libmbedx509.*
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200123 rm -f $(DESTDIR)/lib/libmbedcrypto.*
Darryl Green11999bb2018-03-13 15:22:58 +0000124
Paul Bakker9a736322012-11-14 12:39:52 +0000125 for p in programs/*/* ; do \
126 if [ -x $$p ] && [ ! -d $$p ] ; \
127 then \
128 f=$(PREFIX)`basename $$p` ; \
129 rm -f $(DESTDIR)/bin/$$f ; \
130 fi \
131 done
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200132endif
Paul Bakker9a736322012-11-14 12:39:52 +0000133
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100134
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300135WARNING_BORDER_LONG =**********************************************************************************\n
136CTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n
137CTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n
138CTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n
139
140CTR_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)
141
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100142# Post build steps
143post_build:
Simon Butchercff625f2016-06-27 15:15:11 +0100144ifndef WINDOWS
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300145
146 # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200147 -scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300148 echo '$(CTR_DRBG_128_BIT_KEY_WARNING)'
149
Simon Butchercff625f2016-06-27 15:15:11 +0100150endif
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100151
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200152clean: clean_more_on_top
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200153 $(MAKE) -C library clean
154 $(MAKE) -C programs clean
155 $(MAKE) -C tests clean
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200156
157clean_more_on_top:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200158ifndef WINDOWS
Paul Bakkerbd3b3592016-07-13 16:37:32 +0100159 find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} +
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200160endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000161
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200162neat: clean_more_on_top
163 $(MAKE) -C library neat
164 $(MAKE) -C programs neat
165 $(MAKE) -C tests neat
166ifndef WINDOWS
Bence Szépkútifac11222024-03-12 16:38:23 +0100167 rm -f visualc/VS2017/*.vcxproj visualc/VS2017/mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200168else
Bence Szépkútifac11222024-03-12 16:38:23 +0100169 if exist visualc\VS2017\*.vcxproj del /Q /F visualc\VS2017\*.vcxproj
170 if exist visualc\VS2017\mbedTLS.sln del /Q /F visualc\VS2017\mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200171endif
172
Andres AGc49b8082016-08-31 16:10:45 +0100173check: lib tests
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200174 $(MAKE) -C tests check
Paul Bakker37ca75d2011-01-06 12:28:03 +0000175
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200176test: check
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +0100177
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100178ifndef WINDOWS
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +0100179# For coverage testing:
180# 1. Build with:
181# make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage'
182# 2. Run the relevant tests for the part of the code you're interested in.
183# For the reference coverage measurement, see
184# tests/scripts/basic-build-test.sh
185# 3. Run scripts/lcov.sh to generate an HTML report.
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100186lcov:
Gilles Peskine3d4ea542022-11-30 17:35:44 +0100187 scripts/lcov.sh
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100188
Paul Bakker37ca75d2011-01-06 12:28:03 +0000189apidoc:
190 mkdir -p apidoc
Krzysztof Stachowiak744a4ac2018-01-22 13:38:31 +0100191 cd doxygen && doxygen mbedtls.doxyfile
Paul Bakker37ca75d2011-01-06 12:28:03 +0000192
193apidoc_clean:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200194 rm -rf apidoc
195endif
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100196
197## Editor navigation files
Gilles Peskine646ad222020-11-09 21:20:16 +0100198C_SOURCE_FILES = $(wildcard \
199 3rdparty/*/include/*/*.h 3rdparty/*/include/*/*/*.h 3rdparty/*/include/*/*/*/*.h \
200 3rdparty/*/*.c 3rdparty/*/*/*.c 3rdparty/*/*/*/*.c 3rdparty/*/*/*/*/*.c \
201 include/*/*.h \
202 library/*.[hc] \
203 programs/*/*.[hc] \
204 tests/include/*/*.h tests/include/*/*/*.h \
205 tests/src/*.c tests/src/*/*.c \
206 tests/suites/*.function \
207)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200208# Exuberant-ctags invocation. Other ctags implementations may require different options.
Gilles Peskineb305b002021-01-13 13:45:30 +0100209CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100210tags: $(C_SOURCE_FILES)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200211 $(CTAGS) $@ $(C_SOURCE_FILES)
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100212TAGS: $(C_SOURCE_FILES)
Gilles Peskineb305b002021-01-13 13:45:30 +0100213 etags --no-line-directive -o $@ $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100214global: GPATH GRTAGS GSYMS GTAGS
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100215GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
216 ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100217cscope: cscope.in.out cscope.po.out cscope.out
Gilles Peskined0c78012020-11-09 21:21:31 +0100218cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES)
219 cscope -bq -u -Iinclude -Ilibrary $(patsubst %,-I%,$(wildcard 3rdparty/*/include)) -Itests/include $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100220.PHONY: cscope global