common.make (4159B)
1 # To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS 2 3 ifndef MBEDTLS_PATH 4 MBEDTLS_PATH := .. 5 endif 6 7 ifeq (,$(wildcard $(MBEDTLS_PATH)/framework/exported.make)) 8 # Use the define keyword to get a multi-line message. 9 # GNU make appends ". Stop.", so tweak the ending of our message accordingly. 10 define error_message 11 $(MBEDTLS_PATH)/framework/exported.make not found. 12 Run `git submodule update --init` to fetch the submodule contents. 13 This is a fatal error 14 endef 15 $(error $(error_message)) 16 endif 17 include $(MBEDTLS_PATH)/framework/exported.make 18 19 CFLAGS ?= -O2 20 WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral 21 WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -std=c++11 -pedantic 22 LDFLAGS ?= 23 24 LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include \ 25 -I$(MBEDTLS_PATH)/framework/tests/include \ 26 -I$(MBEDTLS_PATH)/include \ 27 -D_FILE_OFFSET_BITS=64 28 LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) $(LOCAL_CFLAGS) 29 30 LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \ 31 -L$(MBEDTLS_PATH)/library \ 32 -lmbedtls$(SHARED_SUFFIX) \ 33 -lmbedx509$(SHARED_SUFFIX) \ 34 -lmbedcrypto$(SHARED_SUFFIX) 35 36 include $(MBEDTLS_PATH)/3rdparty/Makefile.inc 37 LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES) 38 39 ifndef SHARED 40 MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a $(MBEDTLS_PATH)/library/libmbedx509.a $(MBEDTLS_PATH)/library/libmbedtls.a 41 else 42 MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) $(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT) 43 endif 44 45 ifdef DEBUG 46 LOCAL_CFLAGS += -g3 47 endif 48 49 # if we're running on Windows, build for Windows 50 ifdef WINDOWS 51 WINDOWS_BUILD=1 52 endif 53 54 ## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT) 55 ## Remove the preprocessor symbols that are set in the current configuration 56 ## from PREPROCESSOR_INPUT. Also normalize whitespace. 57 ## Example: 58 ## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR) 59 ## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both 60 ## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is 61 ## disabled, etc. 62 ## 63 ## This only works with a Unix-like shell environment (Bourne/POSIX-style shell 64 ## and standard commands) and a Unix-like compiler (supporting -E). In 65 ## other environments, the output is likely to be empty. 66 define remove_enabled_options 67 $(strip $(shell 68 exec 2>/dev/null; 69 { echo '#include <mbedtls/build_info.h>'; echo $(1); } | 70 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - | 71 tail -n 1 72 )) 73 endef 74 75 ifdef WINDOWS_BUILD 76 DLEXT=dll 77 EXEXT=.exe 78 LOCAL_LDFLAGS += -lws2_32 -lbcrypt 79 ifdef SHARED 80 SHARED_SUFFIX=.$(DLEXT) 81 endif 82 83 else # Not building for Windows 84 DLEXT ?= so 85 EXEXT= 86 SHARED_SUFFIX= 87 ifndef THREADING 88 # Auto-detect configurations with pthread. 89 # If the call to remove_enabled_options returns "control", the symbols 90 # are confirmed set and we link with pthread. 91 # If the auto-detection fails, the result of the call is empty and 92 # we keep THREADING undefined. 93 ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD)) 94 THREADING := pthread 95 endif 96 endif 97 98 ifeq ($(THREADING),pthread) 99 LOCAL_LDFLAGS += -lpthread 100 endif 101 endif 102 103 ifdef WINDOWS 104 PYTHON ?= python 105 else 106 PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi) 107 endif 108 109 # See root Makefile 110 GEN_FILES ?= yes 111 ifdef GEN_FILES 112 gen_file_dep = 113 else 114 gen_file_dep = | 115 endif 116 117 default: all 118 119 $(MBEDLIBS): 120 $(MAKE) -C $(MBEDTLS_PATH)/library 121 122 neat: clean 123 ifndef WINDOWS 124 rm -f $(GENERATED_FILES) 125 else 126 for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f 127 endif 128 129 # Auxiliary modules used by tests and some sample programs 130 MBEDTLS_CORE_TEST_OBJS := $(patsubst %.c,%.o,$(wildcard \ 131 ${MBEDTLS_PATH}/framework/tests/src/*.c \ 132 ${MBEDTLS_PATH}/framework/tests/src/drivers/*.c \ 133 )) 134 # Additional auxiliary modules for TLS testing 135 MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \ 136 ${MBEDTLS_TEST_PATH}/src/*.c \ 137 ${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \ 138 )) 139 140 MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)