1
2# To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
3# To compile with PKCS11: add "-lpkcs11-helper" to LDFLAGS
4
5CFLAGS	?= -O2
6WARNING_CFLAGS ?= -Wall -Wextra
7WARNING_CXXFLAGS ?= -Wall -Wextra
8LDFLAGS ?=
9
10MBEDTLS_TEST_PATH:=../tests/src
11MBEDTLS_TEST_OBJS:=$(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/*.c ${MBEDTLS_TEST_PATH}/drivers/*.c))
12
13LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../tests/include -I../include -D_FILE_OFFSET_BITS=64
14LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I../include -D_FILE_OFFSET_BITS=64
15LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} 		\
16		-L../library 			\
17		-lmbedtls$(SHARED_SUFFIX)	\
18		-lmbedx509$(SHARED_SUFFIX)	\
19		-lmbedcrypto$(SHARED_SUFFIX)
20
21include ../3rdparty/Makefile.inc
22LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
23
24ifndef SHARED
25MBEDLIBS=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
26else
27MBEDLIBS=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
28endif
29DEP=${MBEDLIBS} ${MBEDTLS_TEST_OBJS}
30
31ifdef DEBUG
32LOCAL_CFLAGS += -g3
33endif
34
35# if we're running on Windows, build for Windows
36ifdef WINDOWS
37WINDOWS_BUILD=1
38endif
39
40ifdef WINDOWS_BUILD
41DLEXT=dll
42EXEXT=.exe
43LOCAL_LDFLAGS += -lws2_32
44ifdef SHARED
45SHARED_SUFFIX=.$(DLEXT)
46endif
47else
48DLEXT ?= so
49EXEXT=
50SHARED_SUFFIX=
51endif
52
53# Zlib shared library extensions:
54ifdef ZLIB
55LOCAL_LDFLAGS += -lz
56endif
57
58APPS = \
59	aes/aescrypt2$(EXEXT) \
60	aes/crypt_and_hash$(EXEXT) \
61	hash/generic_sum$(EXEXT) \
62	hash/hello$(EXEXT) \
63	pkey/dh_client$(EXEXT) \
64	pkey/dh_genprime$(EXEXT) \
65	pkey/dh_server$(EXEXT) \
66	pkey/ecdh_curve25519$(EXEXT) \
67	pkey/ecdsa$(EXEXT) \
68	pkey/gen_key$(EXEXT) \
69	pkey/key_app$(EXEXT) \
70	pkey/key_app_writer$(EXEXT) \
71	pkey/mpi_demo$(EXEXT) \
72	pkey/pk_decrypt$(EXEXT) \
73	pkey/pk_encrypt$(EXEXT) \
74	pkey/pk_sign$(EXEXT) \
75	pkey/pk_verify$(EXEXT) \
76	pkey/rsa_decrypt$(EXEXT) \
77	pkey/rsa_encrypt$(EXEXT) \
78	pkey/rsa_genkey$(EXEXT) \
79	pkey/rsa_sign$(EXEXT) \
80	pkey/rsa_sign_pss$(EXEXT) \
81	pkey/rsa_verify$(EXEXT) \
82	pkey/rsa_verify_pss$(EXEXT) \
83	psa/crypto_examples$(EXEXT) \
84	psa/key_ladder_demo$(EXEXT) \
85	psa/psa_constant_names$(EXEXT) \
86	random/gen_entropy$(EXEXT) \
87	random/gen_random_ctr_drbg$(EXEXT) \
88	random/gen_random_havege$(EXEXT) \
89	ssl/dtls_client$(EXEXT) \
90	ssl/dtls_server$(EXEXT) \
91	ssl/mini_client$(EXEXT) \
92	ssl/ssl_client1$(EXEXT) \
93	ssl/ssl_client2$(EXEXT) \
94	ssl/ssl_context_info$(EXEXT) \
95	ssl/ssl_fork_server$(EXEXT) \
96	ssl/ssl_mail_client$(EXEXT) \
97	ssl/ssl_server$(EXEXT) \
98	ssl/ssl_server2$(EXEXT) \
99	test/benchmark$(EXEXT) \
100	test/query_compile_time_config$(EXEXT) \
101	test/selftest$(EXEXT) \
102	test/udp_proxy$(EXEXT) \
103	test/zeroize$(EXEXT) \
104	util/pem2der$(EXEXT) \
105	util/strerror$(EXEXT) \
106	x509/cert_app$(EXEXT) \
107	x509/cert_req$(EXEXT) \
108	x509/cert_write$(EXEXT) \
109	x509/crl_app$(EXEXT) \
110	x509/req_app$(EXEXT) \
111# End of APPS
112
113ifdef PTHREAD
114APPS +=	ssl/ssl_pthread_server$(EXEXT)
115endif
116
117ifdef TEST_CPP
118APPS += test/cpp_dummy_build$(EXEXT)
119endif
120
121.SILENT:
122
123.PHONY: all clean list fuzz
124
125all: $(APPS)
126ifndef WINDOWS
127# APPS doesn't include the fuzzing programs, which aren't "normal"
128# sample or test programs, and don't build with MSVC which is
129# warning about fopen
130all: fuzz
131endif
132
133fuzz: ${MBEDTLS_TEST_OBJS}
134	$(MAKE) -C fuzz THIRDPARTY_INCLUDES=$(THIRDPARTY_INCLUDES)
135
136$(MBEDLIBS):
137	$(MAKE) -C ../library
138
139${MBEDTLS_TEST_OBJS}:
140	$(MAKE) -C ../tests mbedtls_test
141
142aes/aescrypt2$(EXEXT): aes/aescrypt2.c $(DEP)
143	echo "  CC    aes/aescrypt2.c"
144	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) aes/aescrypt2.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
145
146aes/crypt_and_hash$(EXEXT): aes/crypt_and_hash.c $(DEP)
147	echo "  CC    aes/crypt_and_hash.c"
148	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) aes/crypt_and_hash.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
149
150hash/hello$(EXEXT): hash/hello.c $(DEP)
151	echo "  CC    hash/hello.c"
152	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) hash/hello.c       $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
153
154hash/generic_sum$(EXEXT): hash/generic_sum.c $(DEP)
155	echo "  CC    hash/generic_sum.c"
156	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) hash/generic_sum.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
157
158pkey/dh_client$(EXEXT): pkey/dh_client.c $(DEP)
159	echo "  CC    pkey/dh_client.c"
160	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/dh_client.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
161
162pkey/dh_genprime$(EXEXT): pkey/dh_genprime.c $(DEP)
163	echo "  CC    pkey/dh_genprime.c"
164	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/dh_genprime.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
165
166pkey/dh_server$(EXEXT): pkey/dh_server.c $(DEP)
167	echo "  CC    pkey/dh_server.c"
168	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/dh_server.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
169
170pkey/ecdh_curve25519$(EXEXT): pkey/ecdh_curve25519.c $(DEP)
171	echo "  CC    pkey/ecdh_curve25519.c"
172	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/ecdh_curve25519.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
173
174pkey/ecdsa$(EXEXT): pkey/ecdsa.c $(DEP)
175	echo "  CC    pkey/ecdsa.c"
176	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/ecdsa.c       $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
177
178pkey/gen_key$(EXEXT): pkey/gen_key.c $(DEP)
179	echo "  CC    pkey/gen_key.c"
180	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/gen_key.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
181
182pkey/key_app$(EXEXT): pkey/key_app.c $(DEP)
183	echo "  CC    pkey/key_app.c"
184	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/key_app.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
185
186pkey/key_app_writer$(EXEXT): pkey/key_app_writer.c $(DEP)
187	echo "  CC    pkey/key_app_writer.c"
188	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/key_app_writer.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
189
190pkey/mpi_demo$(EXEXT): pkey/mpi_demo.c $(DEP)
191	echo "  CC    pkey/mpi_demo.c"
192	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/mpi_demo.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
193
194pkey/pk_decrypt$(EXEXT): pkey/pk_decrypt.c $(DEP)
195	echo "  CC    pkey/pk_decrypt.c"
196	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_decrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
197
198pkey/pk_encrypt$(EXEXT): pkey/pk_encrypt.c $(DEP)
199	echo "  CC    pkey/pk_encrypt.c"
200	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_encrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
201
202pkey/pk_sign$(EXEXT): pkey/pk_sign.c $(DEP)
203	echo "  CC    pkey/pk_sign.c"
204	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_sign.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
205
206pkey/pk_verify$(EXEXT): pkey/pk_verify.c $(DEP)
207	echo "  CC    pkey/pk_verify.c"
208	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_verify.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
209
210pkey/rsa_genkey$(EXEXT): pkey/rsa_genkey.c $(DEP)
211	echo "  CC    pkey/rsa_genkey.c"
212	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_genkey.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
213
214pkey/rsa_sign$(EXEXT): pkey/rsa_sign.c $(DEP)
215	echo "  CC    pkey/rsa_sign.c"
216	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_sign.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
217
218pkey/rsa_verify$(EXEXT): pkey/rsa_verify.c $(DEP)
219	echo "  CC    pkey/rsa_verify.c"
220	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_verify.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
221
222pkey/rsa_sign_pss$(EXEXT): pkey/rsa_sign_pss.c $(DEP)
223	echo "  CC    pkey/rsa_sign_pss.c"
224	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_sign_pss.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
225
226pkey/rsa_verify_pss$(EXEXT): pkey/rsa_verify_pss.c $(DEP)
227	echo "  CC    pkey/rsa_verify_pss.c"
228	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_verify_pss.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
229
230pkey/rsa_decrypt$(EXEXT): pkey/rsa_decrypt.c $(DEP)
231	echo "  CC    pkey/rsa_decrypt.c"
232	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_decrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
233
234pkey/rsa_encrypt$(EXEXT): pkey/rsa_encrypt.c $(DEP)
235	echo "  CC    pkey/rsa_encrypt.c"
236	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_encrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
237
238psa/key_ladder_demo$(EXEXT): psa/key_ladder_demo.c $(DEP)
239	echo "  CC    psa/key_ladder_demo.c"
240	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/key_ladder_demo.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
241
242psa/psa_constant_names$(EXEXT): psa/psa_constant_names.c $(DEP)
243	echo "  CC    psa/psa_constant_names.c"
244	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/psa_constant_names.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
245
246random/gen_entropy$(EXEXT): random/gen_entropy.c $(DEP)
247	echo "  CC    random/gen_entropy.c"
248	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) random/gen_entropy.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
249
250random/gen_random_havege$(EXEXT): random/gen_random_havege.c $(DEP)
251	echo "  CC    random/gen_random_havege.c"
252	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) random/gen_random_havege.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
253
254random/gen_random_ctr_drbg$(EXEXT): random/gen_random_ctr_drbg.c $(DEP)
255	echo "  CC    random/gen_random_ctr_drbg.c"
256	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) random/gen_random_ctr_drbg.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
257
258ssl/dtls_client$(EXEXT): ssl/dtls_client.c $(DEP)
259	echo "  CC    ssl/dtls_client.c"
260	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/dtls_client.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
261
262ssl/dtls_server$(EXEXT): ssl/dtls_server.c $(DEP)
263	echo "  CC    ssl/dtls_server.c"
264	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/dtls_server.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
265
266ssl/ssl_client1$(EXEXT): ssl/ssl_client1.c $(DEP)
267	echo "  CC    ssl/ssl_client1.c"
268	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_client1.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
269
270ssl/ssl_client2$(EXEXT): ssl/ssl_client2.c test/query_config.c $(DEP)
271	echo "  CC    ssl/ssl_client2.c"
272	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_client2.c test/query_config.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
273
274ssl/ssl_server$(EXEXT): ssl/ssl_server.c $(DEP)
275	echo "  CC    ssl/ssl_server.c"
276	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_server.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
277
278ssl/ssl_server2$(EXEXT): ssl/ssl_server2.c test/query_config.c $(DEP)
279	echo "  CC    ssl/ssl_server2.c"
280	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_server2.c test/query_config.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
281
282ssl/ssl_context_info$(EXEXT): ssl/ssl_context_info.c test/query_config.c $(DEP)
283	echo "  CC    ssl/ssl_context_info.c"
284	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_context_info.c test/query_config.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
285
286ssl/ssl_fork_server$(EXEXT): ssl/ssl_fork_server.c $(DEP)
287	echo "  CC    ssl/ssl_fork_server.c"
288	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_fork_server.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
289
290ssl/ssl_pthread_server$(EXEXT): ssl/ssl_pthread_server.c $(DEP)
291	echo "  CC    ssl/ssl_pthread_server.c"
292	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_pthread_server.c   $(LOCAL_LDFLAGS) -lpthread  $(LDFLAGS) -o $@
293
294ssl/ssl_mail_client$(EXEXT): ssl/ssl_mail_client.c $(DEP)
295	echo "  CC    ssl/ssl_mail_client.c"
296	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_mail_client.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
297
298ssl/mini_client$(EXEXT): ssl/mini_client.c $(DEP)
299	echo "  CC    ssl/mini_client.c"
300	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/mini_client.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
301
302test/benchmark$(EXEXT): test/benchmark.c $(DEP)
303	echo "  CC    test/benchmark.c"
304	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/benchmark.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
305
306test/cpp_dummy_build$(EXEXT): test/cpp_dummy_build.cpp $(DEP)
307	echo "  CXX   test/cpp_dummy_build.cpp"
308	$(CXX) $(LOCAL_CXXFLAGS) $(CXXFLAGS) test/cpp_dummy_build.cpp   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
309
310test/selftest$(EXEXT): test/selftest.c $(DEP)
311	echo "  CC    test/selftest.c"
312	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/selftest.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
313
314test/udp_proxy$(EXEXT): test/udp_proxy.c $(DEP)
315	echo "  CC    test/udp_proxy.c"
316	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/udp_proxy.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
317
318test/zeroize$(EXEXT): test/zeroize.c $(DEP)
319	echo "  CC    test/zeroize.c"
320	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/zeroize.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
321
322test/query_compile_time_config$(EXEXT): test/query_compile_time_config.c test/query_config.c $(DEP)
323	echo "  CC    test/query_compile_time_config.c"
324	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/query_compile_time_config.c test/query_config.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
325
326util/pem2der$(EXEXT): util/pem2der.c $(DEP)
327	echo "  CC    util/pem2der.c"
328	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) util/pem2der.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
329
330util/strerror$(EXEXT): util/strerror.c $(DEP)
331	echo "  CC    util/strerror.c"
332	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) util/strerror.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
333
334x509/cert_app$(EXEXT): x509/cert_app.c $(DEP)
335	echo "  CC    x509/cert_app.c"
336	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/cert_app.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
337
338x509/cert_write$(EXEXT): x509/cert_write.c $(DEP)
339	echo "  CC    x509/cert_write.c"
340	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/cert_write.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
341
342x509/crl_app$(EXEXT): x509/crl_app.c $(DEP)
343	echo "  CC    x509/crl_app.c"
344	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/crl_app.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
345
346x509/cert_req$(EXEXT): x509/cert_req.c $(DEP)
347	echo "  CC    x509/cert_req.c"
348	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/cert_req.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
349
350x509/req_app$(EXEXT): x509/req_app.c $(DEP)
351	echo "  CC    x509/req_app.c"
352	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/req_app.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
353
354psa/crypto_examples$(EXEXT): psa/crypto_examples.c $(DEP)
355	echo "  CC    psa/crypto_examples.c"
356	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/crypto_examples.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
357
358clean:
359ifndef WINDOWS
360	rm -f $(APPS)
361	-rm -f ssl/ssl_pthread_server$(EXEXT)
362	-rm -f test/cpp_dummy_build$(EXEXT)
363else
364	if exist *.o del /Q /F *.o
365	if exist *.exe del /Q /F *.exe
366endif
367	$(MAKE) -C fuzz clean
368
369list:
370	echo $(APPS)
371