blob: 885948c112ea0ca6126176e9583c881e330f828c [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
5.SILENT:
6
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +01007.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean
Paul Bakker5121ce52009-01-03 21:22:43 +00008
Andres AG7aa5fa12016-08-25 16:36:16 +01009all: programs tests
10 $(MAKE) post_build
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020011
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020012no_test: programs
13
Ronald Cronddaf99c2020-06-19 11:27:26 +020014programs: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020015 $(MAKE) -C programs
Paul Bakkerf9964ab2012-04-05 12:07:50 +000016
17lib:
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020018 $(MAKE) -C library
19
Ronald Cronddaf99c2020-06-19 11:27:26 +020020tests: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020021 $(MAKE) -C tests
Paul Bakkerf9964ab2012-04-05 12:07:50 +000022
Ronald Cronddaf99c2020-06-19 11:27:26 +020023mbedtls_test:
24 $(MAKE) -C tests mbedtls_test
25
Gilles Peskine687d1ab2021-04-22 01:01:56 +020026library/%:
27 $(MAKE) -C library $*
28programs/%:
29 $(MAKE) -C programs $*
30tests/%:
31 $(MAKE) -C tests $*
32
33.PHONY: generated_files
34generated_files: library/generated_files
35generated_files: programs/generated_files
36generated_files: tests/generated_files
37generated_files: visualc_files
38
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020039# Set GEN_FILES to the empty string to disable dependencies on generated
40# source files. Then `make generated_files` will only build files that
41# are missing, it will not rebuilt files that are present but out of date.
42# This is useful, for example, if you have a source tree where
43# `make generated_files` has already run and file timestamps reflect the
44# time the files were copied or extracted, and you are now in an environment
45# that lacks some of the necessary tools to re-generate the files.
46# If $(GEN_FILES) is non-empty, the generated source files' dependencies
47# are treated ordinarily, based on file timestamps.
48GEN_FILES ?= yes
49
50# In dependencies where the target is a configuration-independent generated
51# file, use `TARGET: $(gen_file_dep) DEPENDENCY1 DEPENDENCY2 ...`
52# rather than directly `TARGET: DEPENDENCY1 DEPENDENCY2 ...`. This
53# enables the re-generation to be turned off when GEN_FILES is disabled.
54ifdef GEN_FILES
55gen_file_dep =
56else
Gilles Peskine1bfc09b2023-09-09 21:26:05 +020057# Order-only dependency: generate the target if it's absent, but don't
58# re-generate it if it's present but older than its dependencies.
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020059gen_file_dep = |
60endif
61
Gilles Peskine687d1ab2021-04-22 01:01:56 +020062.PHONY: visualc_files
Dave Rodgman378ecdd2023-01-10 15:08:30 +000063VISUALC_FILES = visualc/VS2013/mbedTLS.sln visualc/VS2013/mbedTLS.vcxproj
Gilles Peskine687d1ab2021-04-22 01:01:56 +020064# TODO: $(app).vcxproj for each $(app) in programs/
65visualc_files: $(VISUALC_FILES)
Gilles Peskine94230ea2021-05-18 15:48:56 +020066
67# Ensure that the .c files that generate_visualc_files.pl enumerates are
Gilles Peskinea13deaf2021-05-19 14:26:37 +020068# present before it runs. It doesn't matter if the files aren't up-to-date,
69# they just need to be present.
70$(VISUALC_FILES): | library/generated_files
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020071$(VISUALC_FILES): $(gen_file_dep) scripts/generate_visualc_files.pl
72$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2013-app-template.vcxproj
73$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2013-main-template.vcxproj
74$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2013-sln-template.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +020075# TODO: also the list of .c and .h source files, but not their content
76$(VISUALC_FILES):
77 echo " Gen $@ ..."
78 $(PERL) scripts/generate_visualc_files.pl
79
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020080ifndef WINDOWS
Manuel Pégourié-Gonnard99839932015-08-03 10:34:09 +020081install: no_test
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000082 mkdir -p $(DESTDIR)/include/mbedtls
Ruini Xue5a9cb612018-06-28 23:21:26 +080083 cp -rp include/mbedtls $(DESTDIR)/include
Jaeden Amero3c7cc5e2018-11-15 17:38:58 +000084 mkdir -p $(DESTDIR)/include/psa
85 cp -rp include/psa $(DESTDIR)/include
Darryl Green11999bb2018-03-13 15:22:58 +000086
Paul Bakker5121ce52009-01-03 21:22:43 +000087 mkdir -p $(DESTDIR)/lib
Gilles Peskine722a7e62020-02-26 19:05:19 +010088 cp -RP library/libmbedtls.* $(DESTDIR)/lib
89 cp -RP library/libmbedx509.* $(DESTDIR)/lib
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +020090 cp -RP library/libmbedcrypto.* $(DESTDIR)/lib
Darryl Green11999bb2018-03-13 15:22:58 +000091
Paul Bakker5121ce52009-01-03 21:22:43 +000092 mkdir -p $(DESTDIR)/bin
93 for p in programs/*/* ; do \
94 if [ -x $$p ] && [ ! -d $$p ] ; \
95 then \
96 f=$(PREFIX)`basename $$p` ; \
97 cp $$p $(DESTDIR)/bin/$$f ; \
98 fi \
99 done
100
Paul Bakker9a736322012-11-14 12:39:52 +0000101uninstall:
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000102 rm -rf $(DESTDIR)/include/mbedtls
Wu, Jheng-Jhong89b98142020-11-26 09:27:17 +0800103 rm -rf $(DESTDIR)/include/psa
Gilles Peskine722a7e62020-02-26 19:05:19 +0100104 rm -f $(DESTDIR)/lib/libmbedtls.*
105 rm -f $(DESTDIR)/lib/libmbedx509.*
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200106 rm -f $(DESTDIR)/lib/libmbedcrypto.*
Darryl Green11999bb2018-03-13 15:22:58 +0000107
Paul Bakker9a736322012-11-14 12:39:52 +0000108 for p in programs/*/* ; do \
109 if [ -x $$p ] && [ ! -d $$p ] ; \
110 then \
111 f=$(PREFIX)`basename $$p` ; \
112 rm -f $(DESTDIR)/bin/$$f ; \
113 fi \
114 done
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200115endif
Paul Bakker9a736322012-11-14 12:39:52 +0000116
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100117
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300118WARNING_BORDER_LONG =**********************************************************************************\n
119CTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n
120CTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n
121CTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n
122
123CTR_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)
124
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100125# Post build steps
126post_build:
Simon Butchercff625f2016-06-27 15:15:11 +0100127ifndef WINDOWS
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300128
129 # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
Gilles Peskine3bdd4122019-07-27 23:52:53 +0200130 -scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
Nir Sonnenscheinb7ebbca2018-08-29 10:20:12 +0300131 echo '$(CTR_DRBG_128_BIT_KEY_WARNING)'
132
Simon Butchercff625f2016-06-27 15:15:11 +0100133endif
Simon Butcher1ceab6e2016-06-21 10:14:00 +0100134
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200135clean: clean_more_on_top
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200136 $(MAKE) -C library clean
137 $(MAKE) -C programs clean
138 $(MAKE) -C tests clean
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200139
140clean_more_on_top:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200141ifndef WINDOWS
Paul Bakkerbd3b3592016-07-13 16:37:32 +0100142 find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} +
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200143endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000144
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200145neat: clean_more_on_top
146 $(MAKE) -C library neat
147 $(MAKE) -C programs neat
148 $(MAKE) -C tests neat
149ifndef WINDOWS
Dave Rodgman378ecdd2023-01-10 15:08:30 +0000150 rm -f visualc/VS2013/*.vcxproj visualc/VS2013/mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200151else
Dave Rodgman378ecdd2023-01-10 15:08:30 +0000152 if exist visualc\VS2013\*.vcxproj del /Q /F visualc\VS2013\*.vcxproj
153 if exist visualc\VS2013\mbedTLS.sln del /Q /F visualc\VS2013\mbedTLS.sln
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200154endif
155
Andres AGc49b8082016-08-31 16:10:45 +0100156check: lib tests
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200157 $(MAKE) -C tests check
Paul Bakker37ca75d2011-01-06 12:28:03 +0000158
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200159test: check
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +0100160
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100161ifndef WINDOWS
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +0100162# For coverage testing:
163# 1. Build with:
164# make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage'
165# 2. Run the relevant tests for the part of the code you're interested in.
166# For the reference coverage measurement, see
167# tests/scripts/basic-build-test.sh
168# 3. Run scripts/lcov.sh to generate an HTML report.
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100169lcov:
Gilles Peskine3d4ea542022-11-30 17:35:44 +0100170 scripts/lcov.sh
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100171
Paul Bakker37ca75d2011-01-06 12:28:03 +0000172apidoc:
173 mkdir -p apidoc
Krzysztof Stachowiak744a4ac2018-01-22 13:38:31 +0100174 cd doxygen && doxygen mbedtls.doxyfile
Paul Bakker37ca75d2011-01-06 12:28:03 +0000175
176apidoc_clean:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200177 rm -rf apidoc
178endif
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100179
180## Editor navigation files
Gilles Peskine646ad222020-11-09 21:20:16 +0100181C_SOURCE_FILES = $(wildcard \
182 3rdparty/*/include/*/*.h 3rdparty/*/include/*/*/*.h 3rdparty/*/include/*/*/*/*.h \
183 3rdparty/*/*.c 3rdparty/*/*/*.c 3rdparty/*/*/*/*.c 3rdparty/*/*/*/*/*.c \
184 include/*/*.h \
185 library/*.[hc] \
186 programs/*/*.[hc] \
187 tests/include/*/*.h tests/include/*/*/*.h \
188 tests/src/*.c tests/src/*/*.c \
189 tests/suites/*.function \
190)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200191# Exuberant-ctags invocation. Other ctags implementations may require different options.
Gilles Peskineb305b002021-01-13 13:45:30 +0100192CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100193tags: $(C_SOURCE_FILES)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200194 $(CTAGS) $@ $(C_SOURCE_FILES)
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100195TAGS: $(C_SOURCE_FILES)
Gilles Peskineb305b002021-01-13 13:45:30 +0100196 etags --no-line-directive -o $@ $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100197global: GPATH GRTAGS GSYMS GTAGS
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100198GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
199 ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100200cscope: cscope.in.out cscope.po.out cscope.out
Gilles Peskined0c78012020-11-09 21:21:31 +0100201cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES)
202 cscope -bq -u -Iinclude -Ilibrary $(patsubst %,-I%,$(wildcard 3rdparty/*/include)) -Itests/include $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100203.PHONY: cscope global