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 -Wunused 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 15# Enable definition of various functions used throughout the testsuite 16# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless 17# on non-POSIX platforms. 18LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L 19 20ifndef SHARED 21DEP=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a 22else 23DEP=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT) 24endif 25 26ifdef DEBUG 27LOCAL_CFLAGS += -g3 28endif 29 30# if we're running on Windows, build for Windows 31ifdef WINDOWS 32WINDOWS_BUILD=1 33endif 34 35ifdef WINDOWS_BUILD 36DLEXT=dll 37EXEXT=.exe 38LOCAL_LDFLAGS += -lws2_32 39ifdef SHARED 40SHARED_SUFFIX=.$(DLEXT) 41endif 42PYTHON ?= python 43else 44DLEXT ?= so 45EXEXT= 46SHARED_SUFFIX= 47PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi) 48endif 49 50# Zlib shared library extensions: 51ifdef ZLIB 52LOCAL_LDFLAGS += -lz 53endif 54 55# A test application is built for each suites/test_suite_*.data file. 56# Application name is same as .data file's base name and can be 57# constructed by stripping path 'suites/' and extension .data. 58APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data))) 59 60# Construct executable name by adding OS specific suffix $(EXEXT). 61BINARIES := $(addsuffix $(EXEXT),$(APPS)) 62 63.SILENT: 64 65.PHONY: all c_files check test clean 66 67all: $(BINARIES) 68 69$(DEP): 70 $(MAKE) -C ../library 71 72C_FILES := $(addsuffix .c,$(APPS)) 73c_files: $(C_FILES) 74 75# Wildcard target for test code generation: 76# A .c file is generated for each .data file in the suites/ directory. Each .c 77# file depends on a .data and .function file from suites/ directory. Following 78# nameing convention is followed: 79# 80# C file | Depends on 81#----------------------------------------------------------------------------- 82# foo.c | suites/foo.function suites/foo.data 83# foo.bar.c | suites/foo.function suites/foo.bar.data 84# 85# Note above that .c and .data files have same base name. 86# However, corresponding .function file's base name is the word before first 87# dot in .c file's base name. 88# 89.SECONDEXPANSION: 90%.c: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data scripts/generate_test_code.py suites/helpers.function suites/main_test.function suites/host_test.function 91 echo " Gen $@" 92 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \ 93 -d suites/$*.data \ 94 -t suites/main_test.function \ 95 -p suites/host_test.function \ 96 -s suites \ 97 --helpers-file suites/helpers.function \ 98 -o . 99 100 101$(BINARIES): %$(EXEXT): %.c $(DEP) 102 echo " CC $<" 103 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ 104 105 106clean: 107ifndef WINDOWS 108 rm -rf $(BINARIES) *.c *.datax TESTS 109else 110 del /Q /F *.c *.exe *.datax 111ifneq ($(wildcard TESTS/.*),) 112 rmdir /Q /S TESTS 113endif 114endif 115 116# Test suites caught by SKIP_TEST_SUITES are built but not executed. 117check: $(BINARIES) 118 perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES) 119 120test: check 121 122# Create separate targets for generating embedded tests. 123EMBEDDED_TESTS := $(addprefix embedded_,$(APPS)) 124 125# Generate test code for target. 126 127.SECONDEXPANSION: 128$(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 129 echo " Gen ./TESTS/mbedtls/$*/$*.c" 130 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \ 131 -d suites/$*.data \ 132 -t suites/main_test.function \ 133 -p suites/target_test.function \ 134 -s suites \ 135 --helpers-file suites/helpers.function \ 136 -o ./TESTS/mbedtls/$* 137 138generate-target-tests: $(EMBEDDED_TESTS) 139 140