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
24endif
25
26# To compile as a shared library:
27ifdef SHARED
28# all code is position-indep with mingw, avoid warning about useless flag
29ifndef WINDOWS_BUILD
30LOCAL_CFLAGS += -fPIC -fpic
31endif
32endif
33
34SOEXT_TLS=so.10
35SOEXT_X509=so.0
36SOEXT_CRYPTO=so.0
37
38DLEXT=so
39# OSX shared library extension:
40# DLEXT=dylib
41
42# Windows shared library extension:
43ifdef WINDOWS_BUILD
44DLEXT=dll
45endif
46
47OBJS_CRYPTO=	aes.o		aesni.o		arc4.o		\
48		asn1parse.o	asn1write.o	base64.o	\
49		bignum.o	blowfish.o	camellia.o	\
50		ccm.o		cipher.o	cipher_wrap.o	\
51		cmac.o		ctr_drbg.o	des.o		\
52		dhm.o		ecdh.o		ecdsa.o		\
53		ecjpake.o	ecp.o				\
54		ecp_curves.o	entropy.o	entropy_poll.o	\
55		error.o		gcm.o		havege.o	\
56		hmac_drbg.o	md.o		md2.o		\
57		md4.o		md5.o		md_wrap.o	\
58		memory_buffer_alloc.o		oid.o		\
59		padlock.o	pem.o		pk.o		\
60		pk_wrap.o	pkcs12.o	pkcs5.o		\
61		pkparse.o	pkwrite.o	platform.o	\
62		ripemd160.o	rsa.o		sha1.o		\
63		sha256.o	sha512.o	threading.o	\
64		timing.o	version.o			\
65		version_features.o		xtea.o
66
67OBJS_X509=	certs.o		pkcs11.o	x509.o		\
68		x509_create.o	x509_crl.o	x509_crt.o	\
69		x509_csr.o	x509write_crt.o	x509write_csr.o
70
71OBJS_TLS=	debug.o		net_sockets.o		\
72		ssl_cache.o	ssl_ciphersuites.o	\
73		ssl_cli.o	ssl_cookie.o		\
74		ssl_srv.o	ssl_ticket.o		\
75		ssl_tls.o
76
77.SILENT:
78
79.PHONY: all static shared clean
80
81ifndef SHARED
82all: static
83else
84all: shared static
85endif
86
87static: libmbedcrypto.a libmbedx509.a libmbedtls.a
88
89shared: libmbedcrypto.$(DLEXT) libmbedx509.$(DLEXT) libmbedtls.$(DLEXT)
90
91# tls
92libmbedtls.a: $(OBJS_TLS)
93	echo "  AR    $@"
94	$(AR) -rc $@ $(OBJS_TLS)
95	echo "  RL    $@"
96	$(AR) -s $@
97
98libmbedtls.$(SOEXT_TLS): $(OBJS_TLS) libmbedx509.so
99	echo "  LD    $@"
100	$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto -lmbedx509 $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
101
102libmbedtls.so: libmbedtls.$(SOEXT_TLS)
103	echo "  LN    $@ -> $<"
104	ln -sf $< $@
105
106libmbedtls.dylib: $(OBJS_TLS)
107	echo "  LD    $@"
108	$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_TLS)
109
110libmbedtls.dll: $(OBJS_TLS) libmbedx509.dll
111	echo "  LD    $@"
112	$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_TLS) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -lmbedx509 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
113
114# x509
115libmbedx509.a: $(OBJS_X509)
116	echo "  AR    $@"
117	$(AR) -rc $@ $(OBJS_X509)
118	echo "  RL    $@"
119	$(AR) -s $@
120
121libmbedx509.$(SOEXT_X509): $(OBJS_X509) libmbedcrypto.so
122	echo "  LD    $@"
123	$(CC) -shared -Wl,-soname,$@ -L. -lmbedcrypto $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
124
125libmbedx509.so: libmbedx509.$(SOEXT_X509)
126	echo "  LN    $@ -> $<"
127	ln -sf $< $@
128
129libmbedx509.dylib: $(OBJS_X509)
130	echo "  LD    $@"
131	$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_X509)
132
133libmbedx509.dll: $(OBJS_X509) libmbedcrypto.dll
134	echo "  LD    $@"
135	$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_X509) -lws2_32 -lwinmm -lgdi32 -L. -lmbedcrypto -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
136
137# crypto
138libmbedcrypto.a: $(OBJS_CRYPTO)
139	echo "  AR    $@"
140	$(AR) -rc $@ $(OBJS_CRYPTO)
141	echo "  RL    $@"
142	$(AR) -s $@
143
144libmbedcrypto.$(SOEXT_CRYPTO): $(OBJS_CRYPTO)
145	echo "  LD    $@"
146	$(CC) -shared -Wl,-soname,$@ $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
147
148libmbedcrypto.so: libmbedcrypto.$(SOEXT_CRYPTO)
149	echo "  LN    $@ -> $<"
150	ln -sf $< $@
151
152libmbedcrypto.dylib: $(OBJS_CRYPTO)
153	echo "  LD    $@"
154	$(CC) -dynamiclib $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ $(OBJS_CRYPTO)
155
156libmbedcrypto.dll: $(OBJS_CRYPTO)
157	echo "  LD    $@"
158	$(CC) -shared -Wl,-soname,$@ -Wl,--out-implib,$@.a -o $@ $(OBJS_CRYPTO) -lws2_32 -lwinmm -lgdi32 -static-libgcc $(LOCAL_LDFLAGS) $(LDFLAGS)
159
160.c.o:
161	echo "  CC    $<"
162	$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $<
163
164clean:
165ifndef WINDOWS
166	rm -f *.o libmbed*
167else
168	del /Q /F *.o libmbed*
169endif
170