1DESTDIR=/usr/local
2PREFIX=mbedtls_
3PERL ?= perl
4
5.SILENT:
6
7.PHONY: all no_test programs lib tests install uninstall clean test check covtest 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/VS2010/mbedTLS.sln visualc/VS2010/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/vs2010-app-template.vcxproj
50$(VISUALC_FILES): scripts/data_files/vs2010-main-template.vcxproj
51$(VISUALC_FILES): scripts/data_files/vs2010-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/VS2010/*.vcxproj visualc/VS2010/mbedTLS.sln
128else
129	if exist visualc\VS2010\*.vcxproj del /Q /F visualc\VS2010\*.vcxproj
130	if exist visualc\VS2010\mbedTLS.sln del /Q /F visualc\VS2010\mbedTLS.sln
131endif
132
133check: lib tests
134	$(MAKE) -C tests check
135
136test: check
137
138ifndef WINDOWS
139# note: for coverage testing, build with:
140# make CFLAGS='--coverage -g3 -O0'
141covtest:
142	$(MAKE) check
143	programs/test/selftest
144	tests/compat.sh
145	tests/ssl-opt.sh
146
147lcov:
148	rm -rf Coverage
149	lcov --capture --initial --directory library -o files.info
150	lcov --rc lcov_branch_coverage=1 --capture --directory library -o tests.info
151	lcov --rc lcov_branch_coverage=1 --add-tracefile files.info --add-tracefile tests.info -o all.info
152	lcov --rc lcov_branch_coverage=1 --remove all.info -o final.info '*.h'
153	gendesc tests/Descriptions.txt -o descriptions
154	genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --branch-coverage -o Coverage final.info
155	rm -f files.info tests.info all.info final.info descriptions
156
157apidoc:
158	mkdir -p apidoc
159	cd doxygen && doxygen mbedtls.doxyfile
160
161apidoc_clean:
162	rm -rf apidoc
163endif
164
165## Editor navigation files
166C_SOURCE_FILES = $(wildcard \
167	3rdparty/*/include/*/*.h 3rdparty/*/include/*/*/*.h 3rdparty/*/include/*/*/*/*.h \
168	3rdparty/*/*.c 3rdparty/*/*/*.c 3rdparty/*/*/*/*.c 3rdparty/*/*/*/*/*.c \
169	include/*/*.h \
170	library/*.[hc] \
171	programs/*/*.[hc] \
172	tests/include/*/*.h tests/include/*/*/*.h \
173	tests/src/*.c tests/src/*/*.c \
174	tests/suites/*.function \
175)
176# Exuberant-ctags invocation. Other ctags implementations may require different options.
177CTAGS = ctags --langmap=c:+.h.function --line-directives=no -o
178tags: $(C_SOURCE_FILES)
179	$(CTAGS) $@ $(C_SOURCE_FILES)
180TAGS: $(C_SOURCE_FILES)
181	etags --no-line-directive -o $@ $(C_SOURCE_FILES)
182global: GPATH GRTAGS GSYMS GTAGS
183GPATH GRTAGS GSYMS GTAGS: $(C_SOURCE_FILES)
184	ls $(C_SOURCE_FILES) | gtags -f - --gtagsconf .globalrc
185cscope: cscope.in.out cscope.po.out cscope.out
186cscope.in.out cscope.po.out cscope.out: $(C_SOURCE_FILES)
187	cscope -bq -u -Iinclude -Ilibrary $(patsubst %,-I%,$(wildcard 3rdparty/*/include)) -Itests/include $(C_SOURCE_FILES)
188.PHONY: cscope global
189