Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
  2. # To compile with PKCS11: add "-lpkcs11-helper" to LDFLAGS
  3. CFLAGS ?= -O2
  4. WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement -Wunused
  5. LDFLAGS ?=
  6. LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
  7. LOCAL_LDFLAGS = -L../library \
  8. -lmbedtls$(SHARED_SUFFIX) \
  9. -lmbedx509$(SHARED_SUFFIX) \
  10. -lmbedcrypto$(SHARED_SUFFIX)
  11. # Enable definition of various functions used throughout the testsuite
  12. # (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
  13. # on non-POSIX platforms.
  14. LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
  15. ifndef SHARED
  16. DEP=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
  17. else
  18. DEP=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
  19. endif
  20. ifdef DEBUG
  21. LOCAL_CFLAGS += -g3
  22. endif
  23. # if we're running on Windows, build for Windows
  24. ifdef WINDOWS
  25. WINDOWS_BUILD=1
  26. endif
  27. ifdef WINDOWS_BUILD
  28. DLEXT=dll
  29. EXEXT=.exe
  30. LOCAL_LDFLAGS += -lws2_32
  31. ifdef SHARED
  32. SHARED_SUFFIX=.$(DLEXT)
  33. endif
  34. PYTHON ?= python
  35. else
  36. DLEXT ?= so
  37. EXEXT=
  38. SHARED_SUFFIX=
  39. # python2 for POSIX since FreeBSD has only python2 as default.
  40. PYTHON ?= python2
  41. endif
  42. # Zlib shared library extensions:
  43. ifdef ZLIB
  44. LOCAL_LDFLAGS += -lz
  45. endif
  46. # A test application is built for each suites/test_suite_*.data file.
  47. # Application name is same as .data file's base name and can be
  48. # constructed by stripping path 'suites/' and extension .data.
  49. APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
  50. # Construct executable name by adding OS specific suffix $(EXEXT).
  51. BINARIES := $(addsuffix $(EXEXT),$(APPS))
  52. .SILENT:
  53. .PHONY: all check test clean
  54. all: $(BINARIES)
  55. $(DEP):
  56. $(MAKE) -C ../library
  57. C_FILES := $(addsuffix .c,$(APPS))
  58. # Wildcard target for test code generation:
  59. # A .c file is generated for each .data file in the suites/ directory. Each .c
  60. # file depends on a .data and .function file from suites/ directory. Following
  61. # nameing convention is followed:
  62. #
  63. # C file | Depends on
  64. #-----------------------------------------------------------------------------
  65. # foo.c | suites/foo.function suites/foo.data
  66. # foo.bar.c | suites/foo.function suites/foo.bar.data
  67. #
  68. # Note above that .c and .data files have same base name.
  69. # However, corresponding .function file's base name is the word before first
  70. # dot in .c file's base name.
  71. #
  72. .SECONDEXPANSION:
  73. %.c: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data scripts/generate_test_code.py suites/helpers.function suites/main_test.function suites/host_test.function
  74. echo " Gen $@"
  75. $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
  76. -d suites/$*.data \
  77. -t suites/main_test.function \
  78. -p suites/host_test.function \
  79. -s suites \
  80. --helpers-file suites/helpers.function \
  81. -o .
  82. $(BINARIES): %$(EXEXT): %.c $(DEP)
  83. echo " CC $<"
  84. $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
  85. clean:
  86. ifndef WINDOWS
  87. rm -rf $(BINARIES) *.c *.datax TESTS
  88. else
  89. del /Q /F *.c *.exe *.datax
  90. ifneq ($(wildcard TESTS/.*),)
  91. rmdir /Q /S TESTS
  92. endif
  93. endif
  94. # Test suites caught by SKIP_TEST_SUITES are built but not executed.
  95. check: $(BINARIES)
  96. perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES)
  97. test: check
  98. # Create separate targets for generating embedded tests.
  99. EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
  100. # Generate test code for target.
  101. .SECONDEXPANSION:
  102. $(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
  103. echo " Gen ./TESTS/mbedtls/$*/$*.c"
  104. $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
  105. -d suites/$*.data \
  106. -t suites/main_test.function \
  107. -p suites/target_test.function \
  108. -s suites \
  109. --helpers-file suites/helpers.function \
  110. -o ./TESTS/mbedtls/$*
  111. generate-target-tests: $(EMBEDDED_TESTS)