1
2# Also see "include/mbedtls/config.h"
3
4CFLAGS	?= -O2
5WARNING_CFLAGS ?=  -Wall -W -Wdeclaration-after-statement
6LDFLAGS ?=
7
8LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
9LOCAL_LDFLAGS =
10
11ifdef DEBUG
12LOCAL_CFLAGS += -g3
13endif
14
15# MicroBlaze specific options:
16# CFLAGS += -mno-xl-soft-mul -mxl-barrel-shift
17
18# To compile on Plan9:
19# CFLAGS += -D_BSD_EXTENSION
20
21# if were running on Windows build for Windows
22ifdef WINDOWS
23WINDOWS_BUILD=1
24else ifeq ($(shell uname -s),Darwin)
25ifeq ($(AR),ar)
26APPLE_BUILD ?= 1
27endif
28endif
29
30# To compile as a shared library:
31ifdef SHARED
32# all code is position-indep with mingw, avoid warning about useless flag
33ifndef WINDOWS_BUILD
34LOCAL_CFLAGS += -fPIC -fpic
35endif
36endif
37
38SOEXT_TLS=so.12
39SOEXT_X509=so.0
40SOEXT_CRYPTO=so.3
41
42# Set AR_DASH= (empty string) to use an ar implentation that does not accept
43# the - prefix for command line options (e.g. llvm-ar)
44AR_DASH ?= -
45
46ARFLAGS = $(AR_DASH)src
47ifdef APPLE_BUILD
48ifneq ($(APPLE_BUILD),0)
49ARFLAGS = $(AR_DASH)Src
50RLFLAGS = -no_warning_for_no_symbols -c
51RL ?= ranlib
52endif
53endif
54
55DLEXT ?= so
56ifdef WINDOWS_BUILD
57# Windows shared library extension:
58DLEXT = dll
59else ifdef APPLE_BUILD
60ifneq ($(APPLE_BUILD),0)
61# Mac OS X shared library extension:
62DLEXT = dylib
63endif
64endif
65
66OBJS_CRYPTO=	aes.o		aesni.o		arc4.o		\
67		aria.o		asn1parse.o	asn1write.o	\
68		base64.o	bignum.o	blowfish.o	\
69		camellia.o	ccm.o		chacha20.o	\
70		chachapoly.o	cipher.o	cipher_wrap.o	\
71		cmac.o		ctr_drbg.o	des.o		\
72		dhm.o		ecdh.o		ecdsa.o		\
73		ecjpake.o	ecp.o				\
74		ecp_curves.o	entropy.o	entropy_poll.o	\
75		error.o		gcm.o		havege.o	\
76		hkdf.o						\
77		hmac_drbg.o	md.o		md2.o		\
78		md4.o		md5.o		md_wrap.o	\
79		memory_buffer_alloc.o		nist_kw.o	\
80		oid.o		padlock.o	pem.o		\
81		pk.o		pk_wrap.o	pkcs12.o	\
82		pkcs5.o		pkparse.o	pkwrite.o	\
83		platform.o	platform_util.o	poly1305.o	\
84		ripemd160.o	rsa_internal.o	rsa.o  		\
85		sha1.o		sha256.o	sha512.o	\
86		threading.o	timing.o	version.o	\
87		version_features.o		xtea.o
88
89OBJS_X509=	certs.o		pkcs11.o	x509.o		\
90		x509_create.o	x509_crl.o	x509_crt.o	\
91		x509_csr.o	x509write_crt.o	x509write_csr.o
92
93OBJS_TLS=	debug.o		net_sockets.o		\
94		ssl_cache.o	ssl_ciphersuites.o	\
95		ssl_cli.o	ssl_cookie.o		\
96		ssl_srv.o	ssl_ticket.o		\
97		ssl_tls.o
98
99.SILENT:
100
101.PHONY: all static shared clean
102
103ifndef SHARED
104all: static
105else
106all: shared static
107endif
108
109static: libmbedcrypto.a libmbedx509.a libmbedtls.a
110
111shared: libmbedcrypto.$(DLEXT) libmbedx509.$(DLEXT) libmbedtls.$(DLEXT)
112
113# tls
114libmbedtls.a: $(OBJS_TLS)
115	echo "  AR    $@"
116	$(AR) $(ARFLAGS) $@ $(OBJS_TLS)
117ifdef APPLE_BUILD
118ifneq ($(APPLE_BUILD),0)
119	echo "  RL    $@"
120	$(RL) $(RLFLAGS) $@
121endif
122endif
123
124libmbedtls.$(SOEXT_TLS): $(OBJS_TLS) libmbedx509.so
125	echo "  LD    $@"
126	$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto -lmbedx509 $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
127
128libmbedtls.so: libmbedtls.$(SOEXT_TLS)
129	echo "  LN    $@ -> $<"
130	ln -sf $< $@
131
132libmbedtls.dylib: $(OBJS_TLS) libmbedx509.dylib
133	echo "  LD    $@"
134	$(CC) -dynamiclib -L. -lmbedcrypto -lmbedx509 $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
135
136libmbedtls.dll: $(OBJS_TLS) libmbedx509.dll
137	echo "  LD    $@"
138	$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_TLS) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -lmbedx509 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
139
140# x509
141libmbedx509.a: $(OBJS_X509)
142	echo "  AR    $@"
143	$(AR) $(ARFLAGS) $@ $(OBJS_X509)
144ifdef APPLE_BUILD
145ifneq ($(APPLE_BUILD),0)
146	echo "  RL    $@"
147	$(RL) $(RLFLAGS) $@
148endif
149endif
150
151libmbedx509.$(SOEXT_X509): $(OBJS_X509) libmbedcrypto.so
152	echo "  LD    $@"
153	$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
154
155libmbedx509.so: libmbedx509.$(SOEXT_X509)
156	echo "  LN    $@ -> $<"
157	ln -sf $< $@
158
159libmbedx509.dylib: $(OBJS_X509) libmbedcrypto.dylib
160	echo "  LD    $@"
161	$(CC) -dynamiclib -L. -lmbedcrypto  $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
162
163libmbedx509.dll: $(OBJS_X509) libmbedcrypto.dll
164	echo "  LD    $@"
165	$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_X509) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
166
167# crypto
168libmbedcrypto.a: $(OBJS_CRYPTO)
169	echo "  AR    $@"
170	$(AR) $(ARFLAGS) $@ $(OBJS_CRYPTO)
171ifdef APPLE_BUILD
172ifneq ($(APPLE_BUILD),0)
173	echo "  RL    $@"
174	$(RL) $(RLFLAGS) $@
175endif
176endif
177
178libmbedcrypto.$(SOEXT_CRYPTO): $(OBJS_CRYPTO)
179	echo "  LD    $@"
180	$(CC) -shared -Wl,-soname,$@ $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
181
182libmbedcrypto.so: libmbedcrypto.$(SOEXT_CRYPTO)
183	echo "  LN    $@ -> $<"
184	ln -sf $< $@
185
186libmbedcrypto.dylib: $(OBJS_CRYPTO)
187	echo "  LD    $@"
188	$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
189
190libmbedcrypto.dll: $(OBJS_CRYPTO)
191	echo "  LD    $@"
192	$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
193
194.c.o:
195	echo "  CC    $<"
196	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
197
198clean:
199ifndef WINDOWS
200	rm -f *.o libmbed*
201else
202	del /Q /F *.o libmbed*
203endif
204