2023-12-22 10:40:58 +00:00
|
|
|
# To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
|
|
|
|
|
2024-01-05 18:10:44 +00:00
|
|
|
ifndef MBEDTLS_PATH
|
|
|
|
MBEDTLS_PATH := ..
|
|
|
|
endif
|
|
|
|
|
2024-06-27 06:00:54 +00:00
|
|
|
PSASIM_PATH=$(MBEDTLS_PATH)/tests/psa-client-server/psasim
|
|
|
|
|
2024-03-04 15:25:14 +00:00
|
|
|
ifeq (,$(wildcard $(MBEDTLS_PATH)/framework/exported.make))
|
|
|
|
# Use the define keyword to get a multi-line message.
|
|
|
|
# GNU make appends ". Stop.", so tweak the ending of our message accordingly.
|
|
|
|
define error_message
|
|
|
|
$(MBEDTLS_PATH)/framework/exported.make not found.
|
|
|
|
Run `git submodule update --init` to fetch the submodule contents.
|
|
|
|
This is a fatal error
|
|
|
|
endef
|
|
|
|
$(error $(error_message))
|
|
|
|
endif
|
2024-02-29 17:19:56 +00:00
|
|
|
include $(MBEDTLS_PATH)/framework/exported.make
|
|
|
|
|
2023-12-22 10:40:58 +00:00
|
|
|
CFLAGS ?= -O2
|
|
|
|
WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
|
2024-06-06 20:12:06 +00:00
|
|
|
WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -std=c++11 -pedantic
|
2023-12-22 10:40:58 +00:00
|
|
|
LDFLAGS ?=
|
|
|
|
|
2024-06-14 06:43:28 +00:00
|
|
|
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include \
|
2024-11-04 15:57:57 +00:00
|
|
|
-I$(MBEDTLS_PATH)/framework/tests/include \
|
2024-06-14 06:43:28 +00:00
|
|
|
-I$(MBEDTLS_PATH)/include -I$(MBEDTLS_PATH)/tf-psa-crypto/include \
|
|
|
|
-I$(MBEDTLS_PATH)/tf-psa-crypto/drivers/builtin/include \
|
|
|
|
-D_FILE_OFFSET_BITS=64
|
2024-08-01 14:11:09 +00:00
|
|
|
LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) $(LOCAL_CFLAGS)
|
2024-06-27 06:00:54 +00:00
|
|
|
|
|
|
|
ifdef PSASIM
|
|
|
|
LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
|
|
|
|
-L$(PSASIM_PATH)/client_libs \
|
|
|
|
-lpsaclient \
|
|
|
|
-lmbedtls$(SHARED_SUFFIX) \
|
|
|
|
-lmbedx509$(SHARED_SUFFIX) \
|
|
|
|
-lmbedcrypto$(SHARED_SUFFIX)
|
|
|
|
else
|
2023-12-22 10:40:58 +00:00
|
|
|
LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
|
2024-01-05 18:10:44 +00:00
|
|
|
-L$(MBEDTLS_PATH)/library \
|
2023-12-22 10:40:58 +00:00
|
|
|
-lmbedtls$(SHARED_SUFFIX) \
|
|
|
|
-lmbedx509$(SHARED_SUFFIX) \
|
|
|
|
-lmbedcrypto$(SHARED_SUFFIX)
|
2024-06-27 06:00:54 +00:00
|
|
|
endif
|
2023-12-22 10:45:53 +00:00
|
|
|
|
2024-07-01 16:33:24 +00:00
|
|
|
THIRDPARTY_DIR = $(MBEDTLS_PATH)/tf-psa-crypto/drivers
|
2024-07-04 07:43:13 +00:00
|
|
|
include $(THIRDPARTY_DIR)/everest/Makefile.inc
|
|
|
|
include $(THIRDPARTY_DIR)/p256-m/Makefile.inc
|
2023-12-22 10:45:53 +00:00
|
|
|
LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
|
|
|
|
|
2024-06-27 06:00:54 +00:00
|
|
|
ifdef PSASIM
|
|
|
|
MBEDLIBS=$(PSASIM_PATH)/client_libs/libmbedcrypto.a \
|
|
|
|
$(PSASIM_PATH)/client_libs/libmbedx509.a \
|
|
|
|
$(PSASIM_PATH)/client_libs/libmbedtls.a \
|
|
|
|
$(PSASIM_PATH)/client_libs/libpsaclient.a
|
|
|
|
else ifndef SHARED
|
|
|
|
MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.a \
|
|
|
|
$(MBEDTLS_PATH)/library/libmbedx509.a \
|
|
|
|
$(MBEDTLS_PATH)/library/libmbedtls.a
|
2023-12-22 10:45:53 +00:00
|
|
|
else
|
2024-06-27 06:00:54 +00:00
|
|
|
MBEDLIBS=$(MBEDTLS_PATH)/library/libmbedcrypto.$(DLEXT) \
|
|
|
|
$(MBEDTLS_PATH)/library/libmbedx509.$(DLEXT) \
|
|
|
|
$(MBEDTLS_PATH)/library/libmbedtls.$(DLEXT)
|
2023-12-22 10:45:53 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef DEBUG
|
|
|
|
LOCAL_CFLAGS += -g3
|
|
|
|
endif
|
|
|
|
|
|
|
|
# if we're running on Windows, build for Windows
|
|
|
|
ifdef WINDOWS
|
|
|
|
WINDOWS_BUILD=1
|
|
|
|
endif
|
|
|
|
|
2023-12-22 17:30:37 +00:00
|
|
|
## Usage: $(call remove_enabled_options,PREPROCESSOR_INPUT)
|
|
|
|
## Remove the preprocessor symbols that are set in the current configuration
|
2023-12-22 10:49:50 +00:00
|
|
|
## from PREPROCESSOR_INPUT. Also normalize whitespace.
|
|
|
|
## Example:
|
2024-01-02 17:14:40 +00:00
|
|
|
## $(call remove_enabled_options,MBEDTLS_FOO MBEDTLS_BAR)
|
2023-12-22 10:49:50 +00:00
|
|
|
## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
|
2023-12-22 17:30:37 +00:00
|
|
|
## enabled, to "MBEDTLS_FOO" if MBEDTLS_BAR is enabled but MBEDTLS_FOO is
|
2023-12-22 10:49:50 +00:00
|
|
|
## disabled, etc.
|
|
|
|
##
|
|
|
|
## This only works with a Unix-like shell environment (Bourne/POSIX-style shell
|
|
|
|
## and standard commands) and a Unix-like compiler (supporting -E). In
|
|
|
|
## other environments, the output is likely to be empty.
|
2023-12-22 17:30:37 +00:00
|
|
|
define remove_enabled_options
|
2023-12-22 10:49:50 +00:00
|
|
|
$(strip $(shell
|
|
|
|
exec 2>/dev/null;
|
|
|
|
{ echo '#include <mbedtls/build_info.h>'; echo $(1); } |
|
|
|
|
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -E - |
|
|
|
|
tail -n 1
|
|
|
|
))
|
|
|
|
endef
|
|
|
|
|
2023-12-22 10:45:53 +00:00
|
|
|
ifdef WINDOWS_BUILD
|
|
|
|
DLEXT=dll
|
|
|
|
EXEXT=.exe
|
|
|
|
LOCAL_LDFLAGS += -lws2_32 -lbcrypt
|
|
|
|
ifdef SHARED
|
|
|
|
SHARED_SUFFIX=.$(DLEXT)
|
|
|
|
endif
|
|
|
|
|
|
|
|
else # Not building for Windows
|
|
|
|
DLEXT ?= so
|
|
|
|
EXEXT=
|
|
|
|
SHARED_SUFFIX=
|
2023-12-22 10:49:50 +00:00
|
|
|
ifndef THREADING
|
|
|
|
# Auto-detect configurations with pthread.
|
2023-12-22 17:30:37 +00:00
|
|
|
# If the call to remove_enabled_options returns "control", the symbols
|
2023-12-22 12:25:18 +00:00
|
|
|
# are confirmed set and we link with pthread.
|
|
|
|
# If the auto-detection fails, the result of the call is empty and
|
|
|
|
# we keep THREADING undefined.
|
2023-12-22 17:30:37 +00:00
|
|
|
ifeq (control,$(call remove_enabled_options,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
|
2023-12-22 10:49:50 +00:00
|
|
|
THREADING := pthread
|
|
|
|
endif
|
|
|
|
endif
|
2023-12-22 10:45:53 +00:00
|
|
|
|
|
|
|
ifeq ($(THREADING),pthread)
|
|
|
|
LOCAL_LDFLAGS += -lpthread
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef WINDOWS
|
|
|
|
PYTHON ?= python
|
|
|
|
else
|
|
|
|
PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# See root Makefile
|
|
|
|
GEN_FILES ?= yes
|
|
|
|
ifdef GEN_FILES
|
|
|
|
gen_file_dep =
|
|
|
|
else
|
|
|
|
gen_file_dep = |
|
|
|
|
endif
|
2023-12-22 10:49:35 +00:00
|
|
|
|
|
|
|
default: all
|
|
|
|
|
|
|
|
$(MBEDLIBS):
|
2024-01-05 18:10:44 +00:00
|
|
|
$(MAKE) -C $(MBEDTLS_PATH)/library
|
2023-12-22 10:49:35 +00:00
|
|
|
|
|
|
|
neat: clean
|
|
|
|
ifndef WINDOWS
|
|
|
|
rm -f $(GENERATED_FILES)
|
|
|
|
else
|
|
|
|
for %f in ($(subst /,\,$(GENERATED_FILES))) if exist %f del /Q /F %f
|
|
|
|
endif
|
2024-01-02 22:11:24 +00:00
|
|
|
|
|
|
|
# Auxiliary modules used by tests and some sample programs
|
2024-06-27 06:00:54 +00:00
|
|
|
MBEDTLS_CORE_TEST_OBJS := $(patsubst %.c,%.o,$(wildcard \
|
2024-11-05 14:40:03 +00:00
|
|
|
${MBEDTLS_PATH}/framework/tests/src/*.c \
|
|
|
|
${MBEDTLS_PATH}/framework/tests/src/drivers/*.c \
|
2024-01-02 22:11:24 +00:00
|
|
|
))
|
2024-06-27 06:00:54 +00:00
|
|
|
# Ignore PSA stubs when building for the client side of PSASIM (i.e.
|
|
|
|
# CRYPTO_CLIENT && !CRYPTO_C) otherwise there will be functions duplicates.
|
|
|
|
ifdef PSASIM
|
|
|
|
MBEDTLS_CORE_TEST_OBJS := $(filter-out \
|
2024-11-05 14:40:03 +00:00
|
|
|
${MBEDTLS_PATH}/framework/tests/src/psa_crypto_stubs.o, $(MBEDTLS_CORE_TEST_OBJS)\
|
2024-06-27 06:00:54 +00:00
|
|
|
)
|
|
|
|
endif
|
2024-01-02 22:11:24 +00:00
|
|
|
# Additional auxiliary modules for TLS testing
|
|
|
|
MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
|
2024-11-05 14:40:03 +00:00
|
|
|
${MBEDTLS_TEST_PATH}/src/*.c \
|
2024-01-02 22:11:24 +00:00
|
|
|
${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
|
|
|
|
))
|
|
|
|
|
|
|
|
MBEDTLS_TEST_OBJS = $(MBEDTLS_CORE_TEST_OBJS) $(MBEDTLS_TLS_TEST_OBJS)
|