1*cfb92d14SAndroid Build Coastguard WorkerDESTDIR=/usr/local 2*cfb92d14SAndroid Build Coastguard WorkerPREFIX=mbedtls_ 3*cfb92d14SAndroid Build Coastguard WorkerPERL ?= perl 4*cfb92d14SAndroid Build Coastguard Worker 5*cfb92d14SAndroid Build Coastguard Workerifneq (,$(filter-out lib library/%,$(or $(MAKECMDGOALS),all))) 6*cfb92d14SAndroid Build Coastguard Worker ifeq (,$(wildcard framework/exported.make)) 7*cfb92d14SAndroid Build Coastguard Worker # Use the define keyword to get a multi-line message. 8*cfb92d14SAndroid Build Coastguard Worker # GNU make appends ". Stop.", so tweak the ending of our message accordingly. 9*cfb92d14SAndroid Build Coastguard Worker define error_message 10*cfb92d14SAndroid Build Coastguard Worker$(MBEDTLS_PATH)/framework/exported.make not found. 11*cfb92d14SAndroid Build Coastguard WorkerRun `git submodule update --init` to fetch the submodule contents. 12*cfb92d14SAndroid Build Coastguard WorkerThis is a fatal error 13*cfb92d14SAndroid Build Coastguard Worker endef 14*cfb92d14SAndroid Build Coastguard Worker $(error $(error_message)) 15*cfb92d14SAndroid Build Coastguard Worker endif 16*cfb92d14SAndroid Build Coastguard Worker include framework/exported.make 17*cfb92d14SAndroid Build Coastguard Workerendif 18*cfb92d14SAndroid Build Coastguard Worker 19*cfb92d14SAndroid Build Coastguard Worker.SILENT: 20*cfb92d14SAndroid Build Coastguard Worker 21*cfb92d14SAndroid Build Coastguard Worker.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean 22*cfb92d14SAndroid Build Coastguard Worker 23*cfb92d14SAndroid Build Coastguard Workerall: programs tests 24*cfb92d14SAndroid Build Coastguard Worker $(MAKE) post_build 25*cfb92d14SAndroid Build Coastguard Worker 26*cfb92d14SAndroid Build Coastguard Workerno_test: programs 27*cfb92d14SAndroid Build Coastguard Worker 28*cfb92d14SAndroid Build Coastguard Workerprograms: lib mbedtls_test 29*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C programs 30*cfb92d14SAndroid Build Coastguard Worker 31*cfb92d14SAndroid Build Coastguard Workerlib: 32*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C library 33*cfb92d14SAndroid Build Coastguard Worker 34*cfb92d14SAndroid Build Coastguard Workertests: lib mbedtls_test 35*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C tests 36*cfb92d14SAndroid Build Coastguard Worker 37*cfb92d14SAndroid Build Coastguard Workermbedtls_test: 38*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C tests mbedtls_test 39*cfb92d14SAndroid Build Coastguard Worker 40*cfb92d14SAndroid Build Coastguard Workerlibrary/%: 41*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C library $* 42*cfb92d14SAndroid Build Coastguard Workerprograms/%: 43*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C programs $* 44*cfb92d14SAndroid Build Coastguard Workertests/%: 45*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C tests $* 46*cfb92d14SAndroid Build Coastguard Worker 47*cfb92d14SAndroid Build Coastguard Worker.PHONY: generated_files 48*cfb92d14SAndroid Build Coastguard Workergenerated_files: library/generated_files 49*cfb92d14SAndroid Build Coastguard Workergenerated_files: programs/generated_files 50*cfb92d14SAndroid Build Coastguard Workergenerated_files: tests/generated_files 51*cfb92d14SAndroid Build Coastguard Workergenerated_files: visualc_files 52*cfb92d14SAndroid Build Coastguard Worker 53*cfb92d14SAndroid Build Coastguard Worker# Set GEN_FILES to the empty string to disable dependencies on generated 54*cfb92d14SAndroid Build Coastguard Worker# source files. Then `make generated_files` will only build files that 55*cfb92d14SAndroid Build Coastguard Worker# are missing, it will not rebuilt files that are present but out of date. 56*cfb92d14SAndroid Build Coastguard Worker# This is useful, for example, if you have a source tree where 57*cfb92d14SAndroid Build Coastguard Worker# `make generated_files` has already run and file timestamps reflect the 58*cfb92d14SAndroid Build Coastguard Worker# time the files were copied or extracted, and you are now in an environment 59*cfb92d14SAndroid Build Coastguard Worker# that lacks some of the necessary tools to re-generate the files. 60*cfb92d14SAndroid Build Coastguard Worker# If $(GEN_FILES) is non-empty, the generated source files' dependencies 61*cfb92d14SAndroid Build Coastguard Worker# are treated ordinarily, based on file timestamps. 62*cfb92d14SAndroid Build Coastguard WorkerGEN_FILES ?= 63*cfb92d14SAndroid Build Coastguard Worker 64*cfb92d14SAndroid Build Coastguard Worker# In dependencies where the target is a configuration-independent generated 65*cfb92d14SAndroid Build Coastguard Worker# file, use `TARGET: $(gen_file_dep) DEPENDENCY1 DEPENDENCY2 ...` 66*cfb92d14SAndroid Build Coastguard Worker# rather than directly `TARGET: DEPENDENCY1 DEPENDENCY2 ...`. This 67*cfb92d14SAndroid Build Coastguard Worker# enables the re-generation to be turned off when GEN_FILES is disabled. 68*cfb92d14SAndroid Build Coastguard Workerifdef GEN_FILES 69*cfb92d14SAndroid Build Coastguard Workergen_file_dep = 70*cfb92d14SAndroid Build Coastguard Workerelse 71*cfb92d14SAndroid Build Coastguard Worker# Order-only dependency: generate the target if it's absent, but don't 72*cfb92d14SAndroid Build Coastguard Worker# re-generate it if it's present but older than its dependencies. 73*cfb92d14SAndroid Build Coastguard Workergen_file_dep = | 74*cfb92d14SAndroid Build Coastguard Workerendif 75*cfb92d14SAndroid Build Coastguard Worker 76*cfb92d14SAndroid Build Coastguard Worker.PHONY: visualc_files 77*cfb92d14SAndroid Build Coastguard WorkerVISUALC_FILES = visualc/VS2017/mbedTLS.sln visualc/VS2017/mbedTLS.vcxproj 78*cfb92d14SAndroid Build Coastguard Worker# TODO: $(app).vcxproj for each $(app) in programs/ 79*cfb92d14SAndroid Build Coastguard Workervisualc_files: $(VISUALC_FILES) 80*cfb92d14SAndroid Build Coastguard Worker 81*cfb92d14SAndroid Build Coastguard Worker# Ensure that the .c files that generate_visualc_files.pl enumerates are 82*cfb92d14SAndroid Build Coastguard Worker# present before it runs. It doesn't matter if the files aren't up-to-date, 83*cfb92d14SAndroid Build Coastguard Worker# they just need to be present. 84*cfb92d14SAndroid Build Coastguard Worker$(VISUALC_FILES): | library/generated_files 85*cfb92d14SAndroid Build Coastguard Worker$(VISUALC_FILES): $(gen_file_dep) scripts/generate_visualc_files.pl 86*cfb92d14SAndroid Build Coastguard Worker$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-app-template.vcxproj 87*cfb92d14SAndroid Build Coastguard Worker$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-main-template.vcxproj 88*cfb92d14SAndroid Build Coastguard Worker$(VISUALC_FILES): $(gen_file_dep) scripts/data_files/vs2017-sln-template.sln 89*cfb92d14SAndroid Build Coastguard Worker# TODO: also the list of .c and .h source files, but not their content 90*cfb92d14SAndroid Build Coastguard Worker$(VISUALC_FILES): 91*cfb92d14SAndroid Build Coastguard Worker echo " Gen $@ ..." 92*cfb92d14SAndroid Build Coastguard Worker $(PERL) scripts/generate_visualc_files.pl 93*cfb92d14SAndroid Build Coastguard Worker 94*cfb92d14SAndroid Build Coastguard Workerifndef WINDOWS 95*cfb92d14SAndroid Build Coastguard Workerinstall: no_test 96*cfb92d14SAndroid Build Coastguard Worker mkdir -p $(DESTDIR)/include/mbedtls 97*cfb92d14SAndroid Build Coastguard Worker cp -rp include/mbedtls $(DESTDIR)/include 98*cfb92d14SAndroid Build Coastguard Worker mkdir -p $(DESTDIR)/include/psa 99*cfb92d14SAndroid Build Coastguard Worker cp -rp include/psa $(DESTDIR)/include 100*cfb92d14SAndroid Build Coastguard Worker 101*cfb92d14SAndroid Build Coastguard Worker mkdir -p $(DESTDIR)/lib 102*cfb92d14SAndroid Build Coastguard Worker cp -RP library/libmbedtls.* $(DESTDIR)/lib 103*cfb92d14SAndroid Build Coastguard Worker cp -RP library/libmbedx509.* $(DESTDIR)/lib 104*cfb92d14SAndroid Build Coastguard Worker cp -RP library/libmbedcrypto.* $(DESTDIR)/lib 105*cfb92d14SAndroid Build Coastguard Worker 106*cfb92d14SAndroid Build Coastguard Worker mkdir -p $(DESTDIR)/bin 107*cfb92d14SAndroid Build Coastguard Worker for p in programs/*/* ; do \ 108*cfb92d14SAndroid Build Coastguard Worker if [ -x $$p ] && [ ! -d $$p ] ; \ 109*cfb92d14SAndroid Build Coastguard Worker then \ 110*cfb92d14SAndroid Build Coastguard Worker f=$(PREFIX)`basename $$p` ; \ 111*cfb92d14SAndroid Build Coastguard Worker cp $$p $(DESTDIR)/bin/$$f ; \ 112*cfb92d14SAndroid Build Coastguard Worker fi \ 113*cfb92d14SAndroid Build Coastguard Worker done 114*cfb92d14SAndroid Build Coastguard Worker 115*cfb92d14SAndroid Build Coastguard Workeruninstall: 116*cfb92d14SAndroid Build Coastguard Worker rm -rf $(DESTDIR)/include/mbedtls 117*cfb92d14SAndroid Build Coastguard Worker rm -rf $(DESTDIR)/include/psa 118*cfb92d14SAndroid Build Coastguard Worker rm -f $(DESTDIR)/lib/libmbedtls.* 119*cfb92d14SAndroid Build Coastguard Worker rm -f $(DESTDIR)/lib/libmbedx509.* 120*cfb92d14SAndroid Build Coastguard Worker rm -f $(DESTDIR)/lib/libmbedcrypto.* 121*cfb92d14SAndroid Build Coastguard Worker 122*cfb92d14SAndroid Build Coastguard Worker for p in programs/*/* ; do \ 123*cfb92d14SAndroid Build Coastguard Worker if [ -x $$p ] && [ ! -d $$p ] ; \ 124*cfb92d14SAndroid Build Coastguard Worker then \ 125*cfb92d14SAndroid Build Coastguard Worker f=$(PREFIX)`basename $$p` ; \ 126*cfb92d14SAndroid Build Coastguard Worker rm -f $(DESTDIR)/bin/$$f ; \ 127*cfb92d14SAndroid Build Coastguard Worker fi \ 128*cfb92d14SAndroid Build Coastguard Worker done 129*cfb92d14SAndroid Build Coastguard Workerendif 130*cfb92d14SAndroid Build Coastguard Worker 131*cfb92d14SAndroid Build Coastguard Worker 132*cfb92d14SAndroid Build Coastguard WorkerWARNING_BORDER_LONG =**********************************************************************************\n 133*cfb92d14SAndroid Build Coastguard WorkerCTR_DRBG_128_BIT_KEY_WARN_L1=**** WARNING! MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined! ****\n 134*cfb92d14SAndroid Build Coastguard WorkerCTR_DRBG_128_BIT_KEY_WARN_L2=**** Using 128-bit keys for CTR_DRBG limits the security of generated ****\n 135*cfb92d14SAndroid Build Coastguard WorkerCTR_DRBG_128_BIT_KEY_WARN_L3=**** keys and operations that use random values generated to 128-bit security ****\n 136*cfb92d14SAndroid Build Coastguard Worker 137*cfb92d14SAndroid Build Coastguard WorkerCTR_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) 138*cfb92d14SAndroid Build Coastguard Worker 139*cfb92d14SAndroid Build Coastguard Worker# Post build steps 140*cfb92d14SAndroid Build Coastguard Workerpost_build: 141*cfb92d14SAndroid Build Coastguard Workerifndef WINDOWS 142*cfb92d14SAndroid Build Coastguard Worker 143*cfb92d14SAndroid Build Coastguard Worker # If 128-bit keys are configured for CTR_DRBG, display an appropriate warning 144*cfb92d14SAndroid Build Coastguard Worker -scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \ 145*cfb92d14SAndroid Build Coastguard Worker echo '$(CTR_DRBG_128_BIT_KEY_WARNING)' 146*cfb92d14SAndroid Build Coastguard Worker 147*cfb92d14SAndroid Build Coastguard Workerendif 148*cfb92d14SAndroid Build Coastguard Worker 149*cfb92d14SAndroid Build Coastguard Workerclean: clean_more_on_top 150*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C library clean 151*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C programs clean 152*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C tests clean 153*cfb92d14SAndroid Build Coastguard Worker 154*cfb92d14SAndroid Build Coastguard Workerclean_more_on_top: 155*cfb92d14SAndroid Build Coastguard Workerifndef WINDOWS 156*cfb92d14SAndroid Build Coastguard Worker find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} + 157*cfb92d14SAndroid Build Coastguard Workerendif 158*cfb92d14SAndroid Build Coastguard Worker 159*cfb92d14SAndroid Build Coastguard Workerneat: clean_more_on_top 160*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C library neat 161*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C programs neat 162*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C tests neat 163*cfb92d14SAndroid Build Coastguard Workerifndef WINDOWS 164*cfb92d14SAndroid Build Coastguard Worker rm -f visualc/VS2017/*.vcxproj visualc/VS2017/mbedTLS.sln 165*cfb92d14SAndroid Build Coastguard Workerelse 166*cfb92d14SAndroid Build Coastguard Worker if exist visualc\VS2017\*.vcxproj del /Q /F visualc\VS2017\*.vcxproj 167*cfb92d14SAndroid Build Coastguard Worker if exist visualc\VS2017\mbedTLS.sln del /Q /F visualc\VS2017\mbedTLS.sln 168*cfb92d14SAndroid Build Coastguard Workerendif 169*cfb92d14SAndroid Build Coastguard Worker 170*cfb92d14SAndroid Build Coastguard Workercheck: lib tests 171*cfb92d14SAndroid Build Coastguard Worker $(MAKE) -C tests check 172*cfb92d14SAndroid Build Coastguard Worker 173*cfb92d14SAndroid Build Coastguard Workertest: check 174*cfb92d14SAndroid Build Coastguard Worker 175*cfb92d14SAndroid Build Coastguard Workerifndef WINDOWS 176*cfb92d14SAndroid Build Coastguard Worker# For coverage testing: 177*cfb92d14SAndroid Build Coastguard Worker# 1. Build with: 178*cfb92d14SAndroid Build Coastguard Worker# make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage' 179*cfb92d14SAndroid Build Coastguard Worker# 2. Run the relevant tests for the part of the code you're interested in. 180*cfb92d14SAndroid Build Coastguard Worker# For the reference coverage measurement, see 181*cfb92d14SAndroid Build Coastguard Worker# tests/scripts/basic-build-test.sh 182*cfb92d14SAndroid Build Coastguard Worker# 3. Run scripts/lcov.sh to generate an HTML report. 183*cfb92d14SAndroid Build Coastguard Workerlcov: 184*cfb92d14SAndroid Build Coastguard Worker scripts/lcov.sh 185*cfb92d14SAndroid Build Coastguard Worker 186*cfb92d14SAndroid Build Coastguard Workerapidoc: 187*cfb92d14SAndroid Build Coastguard Worker mkdir -p apidoc 188*cfb92d14SAndroid Build Coastguard Worker cd doxygen && doxygen mbedtls.doxyfile 189*cfb92d14SAndroid Build Coastguard Worker 190*cfb92d14SAndroid Build Coastguard Workerapidoc_clean: 191*cfb92d14SAndroid Build Coastguard Worker rm -rf apidoc 192*cfb92d14SAndroid Build Coastguard Workerendif 193*cfb92d14SAndroid Build Coastguard Worker 194*cfb92d14SAndroid Build Coastguard Worker## Editor navigation files 195*cfb92d14SAndroid Build Coastguard WorkerC_SOURCE_FILES = $(wildcard \ 196*cfb92d14SAndroid Build Coastguard Worker 3rdparty/*/include/*/*.h 3rdparty/*/include/*/*/*.h 3rdparty/*/include/*/*/*/*.h \ 197*cfb92d14SAndroid Build Coastguard Worker 3rdparty/*/*.c 3rdparty/*/*/*.c 3rdparty/*/*/*/*.c 3rdparty/*/*/*/*/*.c \ 198*cfb92d14SAndroid Build Coastguard Worker include/*/*.h \ 199*cfb92d14SAndroid Build Coastguard Worker library/*.[hc] \ 200*cfb92d14SAndroid Build Coastguard Worker programs/*/*.[hc] \ 201*cfb92d14SAndroid Build Coastguard Worker tests/include/*/*.h tests/include/*/*/*.h \ 202*cfb92d14SAndroid Build Coastguard Worker tests/src/*.c tests/src/*/*.c \ 203*cfb92d14SAndroid Build Coastguard Worker tests/suites/*.function \ 204*cfb92d14SAndroid Build Coastguard Worker) 205*cfb92d14SAndroid Build Coastguard Worker# Exuberant-ctags invocation. Other ctags implementations may require different options. 206*cfb92d14SAndroid Build Coastguard WorkerCTAGS = ctags --langmap=c:+.h.function --line-directives=no -o 207*cfb92d14SAndroid Build Coastguard Workertags: $(C_SOURCE_FILES) 208*cfb92d14SAndroid Build Coastguard Worker $(CTAGS) $@ $(C_SOURCE_FILES) 209*cfb92d14SAndroid Build Coastguard WorkerTAGS: $(C_SOURCE_FILES) 210*cfb92d14SAndroid Build Coastguard Worker etags --no-line-directive -o $@ $(C_SOURCE_FILES) 211*cfb92d14SAndroid Build Coastguard Workerglobal: GPATH GRTAGS GSYMS GTAGS 212*cfb92d14SAndroid Build Coastguard WorkerGPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES) 213*cfb92d14SAndroid Build Coastguard Worker ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc 214*cfb92d14SAndroid Build Coastguard Workercscope: cscope.in.out cscope.po.out cscope.out 215*cfb92d14SAndroid Build Coastguard Workercscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES) 216*cfb92d14SAndroid Build Coastguard Worker cscope -bq -u -Iinclude -Ilibrary $(patsubst %,-I%,$(wildcard 3rdparty/*/include)) -Itests/include $(C_SOURCE_FILES) 217*cfb92d14SAndroid Build Coastguard Worker.PHONY: cscope global 218