1DESTDIR=/usr/local
2PREFIX=mbedtls_
3PERL ?= perl
4
5.SILENT:
6
7.PHONY: all no_test programs lib tests install uninstall clean test check lcov apidoc apidoc_clean
8
9all: programs tests
10	$(MAKE) post_build
11
12no_test: programs
13
14programs: lib mbedtls_test
15	$(MAKE) -C programs
16
17lib:
18	$(MAKE) -C library
19
20tests: lib mbedtls_test
21	$(MAKE) -C tests
22
23mbedtls_test:
24	$(MAKE) -C tests mbedtls_test
25
26library/%:
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
39.PHONY: visualc_files
40VISUALC_FILES = visualc/VS2013/mbedTLS.sln visualc/VS2013/mbedTLS.vcxproj
41# TODO: $(app).vcxproj for each $(app) in programs/
42visualc_files: $(VISUALC_FILES)
43
44# Ensure that the .c files that generate_visualc_files.pl enumerates are
45# present before it runs. It doesn't matter if the files aren't up-to-date,
46# they just need to be present.
47$(VISUALC_FILES): | library/generated_files
48$(VISUALC_FILES): scripts/generate_visualc_files.pl
49$(VISUALC_FILES): scripts/data_files/vs2013-app-template.vcxproj
50$(VISUALC_FILES): scripts/data_files/vs2013-main-template.vcxproj
51$(VISUALC_FILES): scripts/data_files/vs2013-sln-template.sln
52# TODO: also the list of .c and .h source files, but not their content
53$(VISUALC_FILES):
54	echo "  Gen   $@ ..."
55	$(PERL) scripts/generate_visualc_files.pl
56
57ifndef WINDOWS
58install: no_test
59	mkdir -p $(DESTDIR)/include/mbedtls
60	cp -rp include/mbedtls $(DESTDIR)/include
61	mkdir -p $(DESTDIR)/include/psa
62	cp -rp include/psa $(DESTDIR)/include
63
64	mkdir -p $(DESTDIR)/lib
65	cp -RP library/libmbedtls.*    $(DESTDIR)/lib
66	cp -RP library/libmbedx509.*   $(DESTDIR)/lib
67	cp -RP library/libmbedcrypto.* $(DESTDIR)/lib
68
69	mkdir -p $(DESTDIR)/bin
70	for p in programs/*/* ; do              \
71	    if [ -x $$p ] && [ ! -d $$p ] ;     \
72	    then                                \
73	        f=$(PREFIX)`basename $$p` ;     \
74	        cp $$p $(DESTDIR)/bin/$$f ;     \
75	    fi                                  \
76	done
77
78uninstall:
79	rm -rf $(DESTDIR)/include/mbedtls
80	rm -rf $(DESTDIR)/include/psa
81	rm -f $(DESTDIR)/lib/libmbedtls.*
82	rm -f $(DESTDIR)/lib/libmbedx509.*
83	rm -f $(DESTDIR)/lib/libmbedcrypto.*
84
85	for p in programs/*/* ; do              \
86	    if [ -x $$p ] && [ ! -d $$p ] ;     \
87	    then                                \
88	        f=$(PREFIX)`basename $$p` ;     \
89	        rm -f $(DESTDIR)/bin/$$f ;      \
90	    fi                                  \
91	done
92endif
93
94
95WARNING_BORDER_LONG      =**********************************************************************************\n
96CTR_DRBG_128_BIT_KEY_WARN_L1=****  WARNING!  MBEDTLS_CTR_DRBG_USE_128_BIT_KEY defined!                      ****\n
97CTR_DRBG_128_BIT_KEY_WARN_L2=****  Using 128-bit keys for CTR_DRBG limits the security of generated         ****\n
98CTR_DRBG_128_BIT_KEY_WARN_L3=****  keys and operations that use random values generated to 128-bit security ****\n
99
100CTR_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)
101
102# Post build steps
103post_build:
104ifndef WINDOWS
105
106	# If 128-bit keys are configured for CTR_DRBG, display an appropriate warning
107	-scripts/config.py get MBEDTLS_CTR_DRBG_USE_128_BIT_KEY && ([ $$? -eq 0 ]) && \
108	    echo '$(CTR_DRBG_128_BIT_KEY_WARNING)'
109
110endif
111
112clean: clean_more_on_top
113	$(MAKE) -C library clean
114	$(MAKE) -C programs clean
115	$(MAKE) -C tests clean
116
117clean_more_on_top:
118ifndef WINDOWS
119	find . \( -name \*.gcno -o -name \*.gcda -o -name \*.info \) -exec rm {} +
120endif
121
122neat: clean_more_on_top
123	$(MAKE) -C library neat
124	$(MAKE) -C programs neat
125	$(MAKE) -C tests neat
126ifndef WINDOWS
127	rm -f visualc/VS2013/*.vcxproj visualc/VS2013/mbedTLS.sln
128else
129	if exist visualc\VS2013\*.vcxproj del /Q /F visualc\VS2013\*.vcxproj
130	if exist visualc\VS2013\mbedTLS.sln del /Q /F visualc\VS2013\mbedTLS.sln
131endif
132
133check: lib tests
134	$(MAKE) -C tests check
135
136test: check
137
138ifndef WINDOWS
139# For coverage testing:
140# 1. Build with:
141#         make CFLAGS='--coverage -g3 -O0' LDFLAGS='--coverage'
142# 2. Run the relevant tests for the part of the code you're interested in.
143#    For the reference coverage measurement, see
144#    tests/scripts/basic-build-test.sh
145# 3. Run scripts/lcov.sh to generate an HTML report.
146lcov:
147	scripts/lcov.sh
148
149apidoc:
150	mkdir -p apidoc
151	cd doxygen && doxygen mbedtls.doxyfile
152
153apidoc_clean:
154	rm -rf apidoc
155endif
156
157## Editor navigation files
158C_SOURCE_FILES = $(wildcard \
159	3rdparty/*/include/*/*.h 3rdparty/*/include/*/*/*.h 3rdparty/*/include/*/*/*/*.h \
160	3rdparty/*/*.c 3rdparty/*/*/*.c 3rdparty/*/*/*/*.c 3rdparty/*/*/*/*/*.c \
161	include/*/*.h \
162	library/*.[hc] \
163	programs/*/*.[hc] \
164	tests/include/*/*.h tests/include/*/*/*.h \
165	tests/src/*.c tests/src/*/*.c \
166	tests/suites/*.function \
167)
168# Exuberant-ctags invocation. Other ctags implementations may require different options.
169CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
170tags: $(C_SOURCE_FILES)
171	$(CTAGS) $@ $(C_SOURCE_FILES)
172TAGS: $(C_SOURCE_FILES)
173	etags --no-line-directive -o $@ $(C_SOURCE_FILES)
174global: GPATH GRTAGS GSYMS GTAGS
175GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
176	ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
177cscope: cscope.in.out cscope.po.out cscope.out
178cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES)
179	cscope -bq -u -Iinclude -Ilibrary $(patsubst %,-I%,$(wildcard 3rdparty/*/include)) -Itests/include $(C_SOURCE_FILES)
180.PHONY: cscope global
181