Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / mbedtls / repo / tests / Makefile
1
2 # To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
3 # To compile with PKCS11: add "-lpkcs11-helper" to LDFLAGS
4
5 CFLAGS  ?= -O2
6 WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement -Wno-unused-function -Wno-unused-value
7 LDFLAGS ?=
8
9 LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
10 LOCAL_LDFLAGS = -L../library                    \
11                 -lmbedtls$(SHARED_SUFFIX)       \
12                 -lmbedx509$(SHARED_SUFFIX)      \
13                 -lmbedcrypto$(SHARED_SUFFIX)
14
15 LOCAL_LDFLAGS += -L../crypto/library
16 LOCAL_CFLAGS += -I../crypto/include
17 CRYPTO := ../crypto/library/
18
19 # Enable definition of various functions used throughout the testsuite
20 # (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
21 # on non-POSIX platforms.
22 LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
23
24 ifndef SHARED
25 DEP=$(CRYPTO)libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
26 else
27 DEP=$(CRYPTO)libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
28 endif
29
30 ifdef DEBUG
31 LOCAL_CFLAGS += -g3
32 endif
33
34 # if we're running on Windows, build for Windows
35 ifdef WINDOWS
36 WINDOWS_BUILD=1
37 endif
38
39 ifdef WINDOWS_BUILD
40 DLEXT=dll
41 EXEXT=.exe
42 LOCAL_LDFLAGS += -lws2_32
43 ifdef SHARED
44 SHARED_SUFFIX=.$(DLEXT)
45 endif
46 PYTHON ?= python
47 else
48 DLEXT ?= so
49 EXEXT=
50 SHARED_SUFFIX=
51 # python2 for POSIX since FreeBSD has only python2 as default.
52 PYTHON ?= python2
53 endif
54
55 # Zlib shared library extensions:
56 ifdef ZLIB
57 LOCAL_LDFLAGS += -lz
58 endif
59
60 # A test application is built for each suites/test_suite_*.data file.
61 # Application name is same as .data file's base name and can be
62 # constructed by stripping path 'suites/' and extension .data.
63 APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
64
65 APPS := $(filter-out \
66                 test_suite_aes.% \
67                 test_suite_arc4 \
68                 test_suite_aria \
69                 test_suite_asn1write \
70                 test_suite_base64 \
71                 test_suite_blowfish \
72                 test_suite_camellia \
73                 test_suite_ccm \
74                 test_suite_chacha20 \
75                 test_suite_chachapoly \
76                 test_suite_cipher.% \
77                 test_suite_cmac \
78                 test_suite_ctr_drbg \
79                 test_suite_des \
80                 test_suite_dhm \
81                 test_suite_ecdh \
82                 test_suite_ecdsa \
83                 test_suite_ecjpake \
84                 test_suite_ecp \
85                 test_suite_entropy \
86                 test_suite_error \
87                 test_suite_gcm.% \
88                 test_suite_hkdf \
89                 test_suite_hmac_drbg.% \
90                 test_suite_md \
91                 test_suite_mdx \
92                 test_suite_memory_buffer_alloc \
93                 test_suite_mpi \
94                 test_suite_nist_kw \
95                 test_suite_oid \
96                 test_suite_pem \
97                 test_suite_pk \
98                 test_suite_pkcs1_v15 \
99                 test_suite_pkcs1_v21 \
100                 test_suite_pkcs5 \
101                 test_suite_pkparse \
102                 test_suite_pkwrite \
103                 test_suite_poly1305 \
104                 test_suite_rsa \
105                 test_suite_shax \
106                 test_suite_timing \
107                 test_suite_xtea \
108                 ,$(APPS))
109
110 # Construct executable name by adding OS specific suffix $(EXEXT).
111 BINARIES := $(addsuffix $(EXEXT),$(APPS))
112
113 .SILENT:
114
115 .PHONY: all check test clean
116
117 all: $(BINARIES)
118
119 $(DEP):
120         $(MAKE) -C ../library
121
122 C_FILES := $(addsuffix .c,$(APPS))
123
124 # Wildcard target for test code generation:
125 # A .c file is generated for each .data file in the suites/ directory. Each .c
126 # file depends on a .data and .function file from suites/ directory. Following
127 # nameing convention is followed:
128 #
129 #     C file        |        Depends on
130 #-----------------------------------------------------------------------------
131 #  foo.c            | suites/foo.function suites/foo.data
132 #  foo.bar.c        | suites/foo.function suites/foo.bar.data
133 #
134 # Note above that .c and .data files have same base name.
135 # However, corresponding .function file's base name is the word before first
136 # dot in .c file's base name.
137 #
138 .SECONDEXPANSION:
139 %.c: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data scripts/generate_test_code.py suites/helpers.function suites/main_test.function suites/host_test.function
140         echo "  Gen   $@"
141         $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
142                 -d suites/$*.data \
143                 -t suites/main_test.function \
144                 -p suites/host_test.function \
145                 -s suites  \
146                 --helpers-file suites/helpers.function \
147                 -o .
148
149
150 $(BINARIES): %$(EXEXT): %.c $(DEP)
151         echo "  CC    $<"
152         $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $<      $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
153
154
155 clean:
156 ifndef WINDOWS
157         rm -rf $(BINARIES) *.c *.datax TESTS
158 else
159         del /Q /F *.c *.exe *.datax
160 ifneq ($(wildcard TESTS/.*),)
161         rmdir /Q /S TESTS
162 endif
163 endif
164
165 # Test suites caught by SKIP_TEST_SUITES are built but not executed.
166 check: $(BINARIES)
167         perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES)
168
169 test: check
170
171 # Create separate targets for generating embedded tests.
172 EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
173
174 # Generate test code for target.
175
176 .SECONDEXPANSION:
177 $(EMBEDDED_TESTS): embedded_%: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data scripts/generate_test_code.py suites/helpers.function suites/main_test.function suites/target_test.function
178         echo "  Gen  ./TESTS/mbedtls/$*/$*.c"
179         $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
180                 -d suites/$*.data \
181                 -t suites/main_test.function \
182                 -p suites/target_test.function \
183                 -s suites  \
184                 --helpers-file suites/helpers.function \
185                 -o ./TESTS/mbedtls/$*
186
187 generate-target-tests: $(EMBEDDED_TESTS)
188