blob: 9c8585cd86146b583e59b862572526c545e40573 [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 Ramsey5d5f4712024-12-10 09:58:23 +00009 ifneq (,$(wildcard .git))
Harry Ramsey6d9c3892024-10-28 14:05:23 +000010 define error_message
Harry Ramsey0f07e762024-11-04 12:16:50 +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.
Harry Ramseye05cf2e2024-09-17 15:12:11 +010012This is a fatal error
Harry Ramsey66ce9862024-11-04 11:37:05 +000013 endef
Harry Ramseye05cf2e2024-09-17 15:12:11 +010014 else
Harry Ramsey66ce9862024-11-04 11:37:05 +000015 define error_message
Harry Ramsey0f07e762024-11-04 12:16:50 +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 Ramsey66ce9862024-11-04 11:37:05 +000017 endef
Harry Ramseye05cf2e2024-09-17 15:12:11 +010018 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
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020029
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020030no_test: programs
31
Ronald Cronddaf99c2020-06-19 11:27:26 +020032programs: lib mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020033 $(MAKE) -C programs
Paul Bakkerf9964ab2012-04-05 12:07:50 +000034
Gilles Peskined001f582024-09-14 13:05:51 +020035ssl-opt: lib mbedtls_test
36 $(MAKE) -C programs ssl-opt
Gilles Peskine870ed2a2024-09-25 10:27:47 +020037 $(MAKE) -C tests ssl-opt
Gilles Peskined001f582024-09-14 13:05:51 +020038
Paul Bakkerf9964ab2012-04-05 12:07:50 +000039lib:
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020040 $(MAKE) -C library
41
Valerio Setti09172652024-06-27 08:00:54 +020042ifndef PSASIM
43tests: lib
44endif
45tests: mbedtls_test
Alon Bar-Lev06f0d262015-02-18 17:18:28 +020046 $(MAKE) -C tests
Paul Bakkerf9964ab2012-04-05 12:07:50 +000047
Ronald Cronddaf99c2020-06-19 11:27:26 +020048mbedtls_test:
49 $(MAKE) -C tests mbedtls_test
50
Gilles Peskine1701c342024-11-21 22:06:39 +010051.PHONY: FORCE
52FORCE:
53
54library/%: FORCE
Gilles Peskine687d1ab2021-04-22 01:01:56 +020055 $(MAKE) -C library $*
Gilles Peskine1701c342024-11-21 22:06:39 +010056programs/%: FORCE
Gilles Peskine687d1ab2021-04-22 01:01:56 +020057 $(MAKE) -C programs $*
Gilles Peskine1701c342024-11-21 22:06:39 +010058tests/%: FORCE
Gilles Peskine687d1ab2021-04-22 01:01:56 +020059 $(MAKE) -C tests $*
60
61.PHONY: generated_files
62generated_files: library/generated_files
63generated_files: programs/generated_files
64generated_files: tests/generated_files
Gilles Peskine687d1ab2021-04-22 01:01:56 +020065
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020066# Set GEN_FILES to the empty string to disable dependencies on generated
67# source files. Then `make generated_files` will only build files that
68# are missing, it will not rebuilt files that are present but out of date.
69# This is useful, for example, if you have a source tree where
70# `make generated_files` has already run and file timestamps reflect the
71# time the files were copied or extracted, and you are now in an environment
72# that lacks some of the necessary tools to re-generate the files.
73# If $(GEN_FILES) is non-empty, the generated source files' dependencies
74# are treated ordinarily, based on file timestamps.
75GEN_FILES ?= yes
76
77# In dependencies where the target is a configuration-independent generated
78# file, use `TARGET: $(gen_file_dep) DEPENDENCY1 DEPENDENCY2 ...`
79# rather than directly `TARGET: DEPENDENCY1 DEPENDENCY2 ...`. This
80# enables the re-generation to be turned off when GEN_FILES is disabled.
81ifdef GEN_FILES
82gen_file_dep =
83else
Gilles Peskine1bfc09b2023-09-09 21:26:05 +020084# Order-only dependency: generate the target if it's absent, but don't
85# re-generate it if it's present but older than its dependencies.
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020086gen_file_dep = |
87endif
88
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020089ifndef WINDOWS
Manuel Pégourié-Gonnard99839932015-08-03 10:34:09 +020090install: no_test
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000091 mkdir -p $(DESTDIR)/include/mbedtls
Ruini Xue5a9cb612018-06-28 23:21:26 +080092 cp -rp include/mbedtls $(DESTDIR)/include
Ronald Cron05ba9122024-06-17 14:25:26 +020093 cp -rp tf-psa-crypto/drivers/builtin/include/mbedtls $(DESTDIR)/include
Jaeden Amero3c7cc5e2018-11-15 17:38:58 +000094 mkdir -p $(DESTDIR)/include/psa
Ronald Cron2581d912024-06-10 16:05:53 +020095 cp -rp tf-psa-crypto/include/psa $(DESTDIR)/include
Darryl Green11999bb2018-03-13 15:22:58 +000096
Paul Bakker5121ce52009-01-03 21:22:43 +000097 mkdir -p $(DESTDIR)/lib
Gilles Peskine722a7e62020-02-26 19:05:19 +010098 cp -RP library/libmbedtls.* $(DESTDIR)/lib
99 cp -RP library/libmbedx509.* $(DESTDIR)/lib
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200100 cp -RP library/libmbedcrypto.* $(DESTDIR)/lib
Darryl Green11999bb2018-03-13 15:22:58 +0000101
Paul Bakker5121ce52009-01-03 21:22:43 +0000102 mkdir -p $(DESTDIR)/bin
103 for p in programs/*/* ; do \
104 if [ -x $$p ] && [ ! -d $$p ] ; \
105 then \
106 f=$(PREFIX)`basename $$p` ; \
107 cp $$p $(DESTDIR)/bin/$$f ; \
108 fi \
109 done
110
Paul Bakker9a736322012-11-14 12:39:52 +0000111uninstall:
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000112 rm -rf $(DESTDIR)/include/mbedtls
Wu, Jheng-Jhong89b98142020-11-26 09:27:17 +0800113 rm -rf $(DESTDIR)/include/psa
Gilles Peskine722a7e62020-02-26 19:05:19 +0100114 rm -f $(DESTDIR)/lib/libmbedtls.*
115 rm -f $(DESTDIR)/lib/libmbedx509.*
Manuel Pégourié-Gonnard52a50792015-07-27 10:36:12 +0200116 rm -f $(DESTDIR)/lib/libmbedcrypto.*
Darryl Green11999bb2018-03-13 15:22:58 +0000117
Paul Bakker9a736322012-11-14 12:39:52 +0000118 for p in programs/*/* ; do \
119 if [ -x $$p ] && [ ! -d $$p ] ; \
120 then \
121 f=$(PREFIX)`basename $$p` ; \
122 rm -f $(DESTDIR)/bin/$$f ; \
123 fi \
124 done
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200125endif
Paul Bakker9a736322012-11-14 12:39:52 +0000126
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200127clean: clean_more_on_top
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200128 $(MAKE) -C library clean
129 $(MAKE) -C programs clean
130 $(MAKE) -C tests clean
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200131
132clean_more_on_top:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200133ifndef WINDOWS
Paul Bakkerbd3b3592016-07-13 16:37:32 +0100134 find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} +
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200135endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000136
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200137neat: clean_more_on_top
138 $(MAKE) -C library neat
139 $(MAKE) -C programs neat
140 $(MAKE) -C tests neat
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200141
Valerio Setti09172652024-06-27 08:00:54 +0200142ifndef PSASIM
143check: lib
144endif
145check: tests
Alon Bar-Lev06f0d262015-02-18 17:18:28 +0200146 $(MAKE) -C tests check
Paul Bakker37ca75d2011-01-06 12:28:03 +0000147
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200148test: check
Manuel Pégourié-Gonnard6529ff02014-01-31 13:41:07 +0100149
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100150ifndef WINDOWS
Gilles Peskine0ab6c8a2022-12-08 22:18:31 +0100151# For coverage testing:
152# 1. Build with:
153# make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage'
154# 2. Run the relevant tests for the part of the code you're interested in.
155# For the reference coverage measurement, see
156# tests/scripts/basic-build-test.sh
157# 3. Run scripts/lcov.sh to generate an HTML report.
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100158lcov:
Gilles Peskine3d4ea542022-11-30 17:35:44 +0100159 scripts/lcov.sh
Manuel Pégourié-Gonnard546d86c2014-01-31 16:19:43 +0100160
Paul Bakker37ca75d2011-01-06 12:28:03 +0000161apidoc:
162 mkdir -p apidoc
Krzysztof Stachowiak744a4ac2018-01-22 13:38:31 +0100163 cd doxygen && doxygen mbedtls.doxyfile
Paul Bakker37ca75d2011-01-06 12:28:03 +0000164
165apidoc_clean:
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200166 rm -rf apidoc
167endif
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100168
169## Editor navigation files
Gilles Peskine646ad222020-11-09 21:20:16 +0100170C_SOURCE_FILES = $(wildcard \
Gilles Peskine646ad222020-11-09 21:20:16 +0100171 include/*/*.h \
172 library/*.[hc] \
Ronald Cron52cd1082024-07-02 07:55:03 +0200173 tf-psa-crypto/core/*.[hc] \
Ronald Crondb9d5182024-06-10 15:58:23 +0200174 tf-psa-crypto/include/*/*.h \
Ronald Cron691f67f2024-07-02 08:50:56 +0200175 tf-psa-crypto/drivers/*/include/*/*.h \
176 tf-psa-crypto/drivers/*/include/*/*/*.h \
177 tf-psa-crypto/drivers/*/include/*/*/*/*.h \
Ronald Cron52cd1082024-07-02 07:55:03 +0200178 tf-psa-crypto/drivers/builtin/src/*.[hc] \
Ronald Cron691f67f2024-07-02 08:50:56 +0200179 tf-psa-crypto/drivers/*/*.c \
180 tf-psa-crypto/drivers/*/*/*.c \
181 tf-psa-crypto/drivers/*/*/*/*.c \
182 tf-psa-crypto/drivers/*/*/*/*/*.c \
Gilles Peskine646ad222020-11-09 21:20:16 +0100183 programs/*/*.[hc] \
David Horstmann5b93d972024-10-31 15:36:05 +0000184 framework/tests/include/*/*.h framework/tests/include/*/*/*.h \
185 framework/tests/src/*.c framework/tests/src/*/*.c \
Gilles Peskine646ad222020-11-09 21:20:16 +0100186 tests/suites/*.function \
Ronald Cronf3522792024-07-11 12:03:51 +0200187 tf-psa-crypto/tests/suites/*.function \
Gilles Peskine646ad222020-11-09 21:20:16 +0100188)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200189# Exuberant-ctags invocation. Other ctags implementations may require different options.
Gilles Peskineb305b002021-01-13 13:45:30 +0100190CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100191tags: $(C_SOURCE_FILES)
Manuel Pégourié-Gonnardc9f89562020-04-02 12:10:45 +0200192 $(CTAGS) $@ $(C_SOURCE_FILES)
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100193TAGS: $(C_SOURCE_FILES)
Gilles Peskineb305b002021-01-13 13:45:30 +0100194 etags --no-line-directive -o $@ $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100195global: GPATH GRTAGS GSYMS GTAGS
Gilles Peskine66c1e2c2018-01-16 14:04:05 +0100196GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
197 ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100198cscope: cscope.in.out cscope.po.out cscope.out
Gilles Peskined0c78012020-11-09 21:21:31 +0100199cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES)
Ronald Cron52cd1082024-07-02 07:55:03 +0200200 cscope -bq -u -Iinclude -Ilibrary -Itf-psa-crypto/core \
201 -Itf-psa-crypto/include \
Ronald Cron52cd1082024-07-02 07:55:03 +0200202 -Itf-psa-crypto/drivers/builtin/src \
David Horstmann5b93d972024-10-31 15:36:05 +0000203 $(patsubst %,-I%,$(wildcard tf-psa-crypto/drivers/*/include)) -Iframework/tests/include $(C_SOURCE_FILES)
Gilles Peskine8346c7a2020-11-20 11:50:08 +0100204.PHONY: cscope global