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 -W -Wdeclaration-after-statement
7LDFLAGS ?=
8
9LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
10LOCAL_LDFLAGS = -L../library 			\
11		-lmbedtls$(SHARED_SUFFIX)	\
12		-lmbedx509$(SHARED_SUFFIX)	\
13		-lmbedcrypto$(SHARED_SUFFIX)
14
15ifndef SHARED
16DEP=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
17else
18DEP=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
19endif
20
21ifdef DEBUG
22LOCAL_CFLAGS += -g3
23endif
24
25# if we're running on Windows, build for Windows
26ifdef WINDOWS
27WINDOWS_BUILD=1
28endif
29
30ifdef WINDOWS_BUILD
31DLEXT=dll
32EXEXT=.exe
33LOCAL_LDFLAGS += -lws2_32
34ifdef SHARED
35SHARED_SUFFIX=.$(DLEXT)
36endif
37else
38DLEXT=so
39EXEXT=
40SHARED_SUFFIX=
41endif
42
43# Zlib shared library extensions:
44ifdef ZLIB
45LOCAL_LDFLAGS += -lz
46endif
47
48APPS =	aes/aescrypt2$(EXEXT)		aes/crypt_and_hash$(EXEXT)	\
49	hash/hello$(EXEXT)		hash/generic_sum$(EXEXT)	\
50					pkey/dh_client$(EXEXT)		\
51	pkey/dh_genprime$(EXEXT)	pkey/dh_server$(EXEXT)		\
52	pkey/ecdh_curve25519$(EXEXT)					\
53	pkey/ecdsa$(EXEXT)		pkey/gen_key$(EXEXT)		\
54	pkey/key_app$(EXEXT)		pkey/key_app_writer$(EXEXT)	\
55	pkey/mpi_demo$(EXEXT)		pkey/pk_decrypt$(EXEXT)		\
56	pkey/pk_encrypt$(EXEXT)		pkey/pk_sign$(EXEXT)		\
57	pkey/pk_verify$(EXEXT)		pkey/rsa_genkey$(EXEXT)		\
58	pkey/rsa_decrypt$(EXEXT)	pkey/rsa_encrypt$(EXEXT)	\
59	pkey/rsa_sign$(EXEXT)		pkey/rsa_verify$(EXEXT)		\
60	pkey/rsa_sign_pss$(EXEXT)	pkey/rsa_verify_pss$(EXEXT)	\
61	ssl/dtls_client$(EXEXT)		ssl/dtls_server$(EXEXT)		\
62	ssl/ssl_client1$(EXEXT)		ssl/ssl_client2$(EXEXT)		\
63	ssl/ssl_server$(EXEXT)		ssl/ssl_server2$(EXEXT)		\
64	ssl/ssl_fork_server$(EXEXT)	ssl/mini_client$(EXEXT)		\
65	ssl/ssl_mail_client$(EXEXT)	random/gen_entropy$(EXEXT)	\
66	random/gen_random_havege$(EXEXT)				\
67	random/gen_random_ctr_drbg$(EXEXT)				\
68	test/ssl_cert_test$(EXEXT)	test/benchmark$(EXEXT)		\
69	test/selftest$(EXEXT)		test/udp_proxy$(EXEXT)		\
70	util/pem2der$(EXEXT)		util/strerror$(EXEXT)		\
71	x509/cert_app$(EXEXT)		x509/crl_app$(EXEXT)		\
72	x509/cert_req$(EXEXT)		x509/cert_write$(EXEXT)		\
73	x509/req_app$(EXEXT)
74
75ifdef PTHREAD
76APPS +=	ssl/ssl_pthread_server$(EXEXT)
77endif
78
79.SILENT:
80
81.PHONY: all clean list
82
83all: $(APPS)
84
85$(DEP):
86	$(MAKE) -C ../library
87
88aes/aescrypt2$(EXEXT): aes/aescrypt2.c $(DEP)
89	echo "  CC    aes/aescrypt2.c"
90	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) aes/aescrypt2.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
91
92aes/crypt_and_hash$(EXEXT): aes/crypt_and_hash.c $(DEP)
93	echo "  CC    aes/crypt_and_hash.c"
94	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) aes/crypt_and_hash.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
95
96hash/hello$(EXEXT): hash/hello.c $(DEP)
97	echo "  CC    hash/hello.c"
98	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) hash/hello.c       $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
99
100hash/generic_sum$(EXEXT): hash/generic_sum.c $(DEP)
101	echo "  CC    hash/generic_sum.c"
102	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) hash/generic_sum.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
103
104pkey/dh_client$(EXEXT): pkey/dh_client.c $(DEP)
105	echo "  CC    pkey/dh_client.c"
106	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/dh_client.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
107
108pkey/dh_genprime$(EXEXT): pkey/dh_genprime.c $(DEP)
109	echo "  CC    pkey/dh_genprime.c"
110	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/dh_genprime.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
111
112pkey/dh_server$(EXEXT): pkey/dh_server.c $(DEP)
113	echo "  CC    pkey/dh_server.c"
114	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/dh_server.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
115
116pkey/ecdh_curve25519$(EXEXT): pkey/ecdh_curve25519.c $(DEP)
117	echo "  CC    pkey/ecdh_curve25519.c"
118	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/ecdh_curve25519.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
119
120pkey/ecdsa$(EXEXT): pkey/ecdsa.c $(DEP)
121	echo "  CC    pkey/ecdsa.c"
122	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/ecdsa.c       $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
123
124pkey/gen_key$(EXEXT): pkey/gen_key.c $(DEP)
125	echo "  CC    pkey/gen_key.c"
126	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/gen_key.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
127
128pkey/key_app$(EXEXT): pkey/key_app.c $(DEP)
129	echo "  CC    pkey/key_app.c"
130	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/key_app.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
131
132pkey/key_app_writer$(EXEXT): pkey/key_app_writer.c $(DEP)
133	echo "  CC    pkey/key_app_writer.c"
134	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/key_app_writer.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
135
136pkey/mpi_demo$(EXEXT): pkey/mpi_demo.c $(DEP)
137	echo "  CC    pkey/mpi_demo.c"
138	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/mpi_demo.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
139
140pkey/pk_decrypt$(EXEXT): pkey/pk_decrypt.c $(DEP)
141	echo "  CC    pkey/pk_decrypt.c"
142	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_decrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
143
144pkey/pk_encrypt$(EXEXT): pkey/pk_encrypt.c $(DEP)
145	echo "  CC    pkey/pk_encrypt.c"
146	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_encrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
147
148pkey/pk_sign$(EXEXT): pkey/pk_sign.c $(DEP)
149	echo "  CC    pkey/pk_sign.c"
150	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_sign.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
151
152pkey/pk_verify$(EXEXT): pkey/pk_verify.c $(DEP)
153	echo "  CC    pkey/pk_verify.c"
154	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/pk_verify.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
155
156pkey/rsa_genkey$(EXEXT): pkey/rsa_genkey.c $(DEP)
157	echo "  CC    pkey/rsa_genkey.c"
158	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_genkey.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
159
160pkey/rsa_sign$(EXEXT): pkey/rsa_sign.c $(DEP)
161	echo "  CC    pkey/rsa_sign.c"
162	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_sign.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
163
164pkey/rsa_verify$(EXEXT): pkey/rsa_verify.c $(DEP)
165	echo "  CC    pkey/rsa_verify.c"
166	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_verify.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
167
168pkey/rsa_sign_pss$(EXEXT): pkey/rsa_sign_pss.c $(DEP)
169	echo "  CC    pkey/rsa_sign_pss.c"
170	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_sign_pss.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
171
172pkey/rsa_verify_pss$(EXEXT): pkey/rsa_verify_pss.c $(DEP)
173	echo "  CC    pkey/rsa_verify_pss.c"
174	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_verify_pss.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
175
176pkey/rsa_decrypt$(EXEXT): pkey/rsa_decrypt.c $(DEP)
177	echo "  CC    pkey/rsa_decrypt.c"
178	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_decrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
179
180pkey/rsa_encrypt$(EXEXT): pkey/rsa_encrypt.c $(DEP)
181	echo "  CC    pkey/rsa_encrypt.c"
182	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_encrypt.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
183
184random/gen_entropy$(EXEXT): random/gen_entropy.c $(DEP)
185	echo "  CC    random/gen_entropy.c"
186	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) random/gen_entropy.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
187
188random/gen_random_havege$(EXEXT): random/gen_random_havege.c $(DEP)
189	echo "  CC    random/gen_random_havege.c"
190	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) random/gen_random_havege.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
191
192random/gen_random_ctr_drbg$(EXEXT): random/gen_random_ctr_drbg.c $(DEP)
193	echo "  CC    random/gen_random_ctr_drbg.c"
194	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) random/gen_random_ctr_drbg.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
195
196ssl/dtls_client$(EXEXT): ssl/dtls_client.c $(DEP)
197	echo "  CC    ssl/dtls_client.c"
198	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/dtls_client.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
199
200ssl/dtls_server$(EXEXT): ssl/dtls_server.c $(DEP)
201	echo "  CC    ssl/dtls_server.c"
202	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/dtls_server.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
203
204ssl/ssl_client1$(EXEXT): ssl/ssl_client1.c $(DEP)
205	echo "  CC    ssl/ssl_client1.c"
206	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_client1.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
207
208ssl/ssl_client2$(EXEXT): ssl/ssl_client2.c $(DEP)
209	echo "  CC    ssl/ssl_client2.c"
210	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_client2.c  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
211
212ssl/ssl_server$(EXEXT): ssl/ssl_server.c $(DEP)
213	echo "  CC    ssl/ssl_server.c"
214	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_server.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
215
216ssl/ssl_server2$(EXEXT): ssl/ssl_server2.c $(DEP)
217	echo "  CC    ssl/ssl_server2.c"
218	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_server2.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
219
220ssl/ssl_fork_server$(EXEXT): ssl/ssl_fork_server.c $(DEP)
221	echo "  CC    ssl/ssl_fork_server.c"
222	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_fork_server.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
223
224ssl/ssl_pthread_server$(EXEXT): ssl/ssl_pthread_server.c $(DEP)
225	echo "  CC    ssl/ssl_pthread_server.c"
226	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_pthread_server.c   $(LOCAL_LDFLAGS) -lpthread  $(LDFLAGS) -o $@
227
228ssl/ssl_mail_client$(EXEXT): ssl/ssl_mail_client.c $(DEP)
229	echo "  CC    ssl/ssl_mail_client.c"
230	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_mail_client.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
231
232ssl/mini_client$(EXEXT): ssl/mini_client.c $(DEP)
233	echo "  CC    ssl/mini_client.c"
234	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/mini_client.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
235
236test/ssl_cert_test$(EXEXT): test/ssl_cert_test.c $(DEP)
237	echo "  CC    test/ssl_cert_test.c"
238	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/ssl_cert_test.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
239
240test/benchmark$(EXEXT): test/benchmark.c $(DEP)
241	echo "  CC    test/benchmark.c"
242	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/benchmark.c   $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
243
244test/selftest$(EXEXT): test/selftest.c $(DEP)
245	echo "  CC    test/selftest.c"
246	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/selftest.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
247
248test/udp_proxy$(EXEXT): test/udp_proxy.c $(DEP)
249	echo "  CC    test/udp_proxy.c"
250	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/udp_proxy.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
251
252util/pem2der$(EXEXT): util/pem2der.c $(DEP)
253	echo "  CC    util/pem2der.c"
254	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) util/pem2der.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
255
256util/strerror$(EXEXT): util/strerror.c $(DEP)
257	echo "  CC    util/strerror.c"
258	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) util/strerror.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
259
260x509/cert_app$(EXEXT): x509/cert_app.c $(DEP)
261	echo "  CC    x509/cert_app.c"
262	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/cert_app.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
263
264x509/cert_write$(EXEXT): x509/cert_write.c $(DEP)
265	echo "  CC    x509/cert_write.c"
266	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/cert_write.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
267
268x509/crl_app$(EXEXT): x509/crl_app.c $(DEP)
269	echo "  CC    x509/crl_app.c"
270	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/crl_app.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
271
272x509/cert_req$(EXEXT): x509/cert_req.c $(DEP)
273	echo "  CC    x509/cert_req.c"
274	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/cert_req.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
275
276x509/req_app$(EXEXT): x509/req_app.c $(DEP)
277	echo "  CC    x509/req_app.c"
278	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) x509/req_app.c    $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
279
280clean:
281ifndef WINDOWS
282	rm -f $(APPS)
283else
284	del /S /Q /F *.o *.exe
285endif
286
287list:
288	echo $(APPS)
289