mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-03-20 11:11:08 +01:00
Move THREADING autodetection to crypto-common.make
Note that `THREADING` detection must be done after `TF_PSA_CRYPTO_LIBRARY_PUBLIC_INCLUDE` is defined. Otherwise it won't detect whether pthread is needed, and will never link with `-lpthread`. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -79,37 +79,6 @@ ifdef WINDOWS
|
||||
WINDOWS_BUILD=1
|
||||
endif
|
||||
|
||||
## Usage: $(call remove_enabled_options_crypto,PREPROCESSOR_INPUT)
|
||||
## Remove the preprocessor symbols that are set in the current configuration
|
||||
## from PREPROCESSOR_INPUT. Also normalize whitespace.
|
||||
## Example:
|
||||
## $(call remove_enabled_options_crypto,MBEDTLS_FOO MBEDTLS_BAR)
|
||||
## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
|
||||
## enabled in the TF-PSA-Crypto configuration, to "MBEDTLS_FOO" if
|
||||
## MBEDTLS_BAR is enabled but MBEDTLS_FOO is 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.
|
||||
define remove_enabled_options_crypto
|
||||
$(strip $(shell
|
||||
exec 2>/dev/null;
|
||||
{ echo '#include <tf-psa-crypto/build_info.h>'; echo $(1); } |
|
||||
$(CC) $(TF_PSA_CRYPTO_LIBRARY_PUBLIC_INCLUDE) $(CFLAGS) -E - |
|
||||
tail -n 1
|
||||
))
|
||||
endef
|
||||
|
||||
# Ensure that `THREADING` is always defined. This lets us get a clean run
|
||||
# with `make --warn-undefined-variables` without making the conditionals
|
||||
# below more complex than they already are. At this stage, if `$(THREADING)`
|
||||
# is empty, it means we don't know yet whether the threading implementation
|
||||
# requires extra `LDFLAGS`. Once we've done the analysis, if `$(THREADING)`
|
||||
# is empty, it will mean that no extra `LDFLAGS` are required, either
|
||||
# because threading is disabled or because the threading implementation
|
||||
# doesn't require any extra `LDFLAGS`.
|
||||
THREADING ?=
|
||||
|
||||
ifdef WINDOWS_BUILD
|
||||
DLEXT=dll
|
||||
EXEXT=.exe
|
||||
@@ -123,24 +92,6 @@ else # Not building for Windows
|
||||
SHARED_SUFFIX=
|
||||
endif
|
||||
|
||||
ifndef WINDOWS_BUILD
|
||||
ifeq ($(THREADING),)
|
||||
# Auto-detect configurations with pthread.
|
||||
# If the call to remove_enabled_options returns "control", the symbols
|
||||
# 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.
|
||||
ifeq (control,$(call remove_enabled_options_crypto,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
|
||||
THREADING := pthread
|
||||
endif
|
||||
endif
|
||||
#$(info THREADING = $(THREADING))
|
||||
|
||||
ifeq ($(THREADING),pthread)
|
||||
LOCAL_LDFLAGS += -lpthread
|
||||
endif
|
||||
endif
|
||||
|
||||
# See root Makefile
|
||||
GEN_FILES ?= yes
|
||||
ifdef GEN_FILES
|
||||
|
||||
@@ -45,3 +45,52 @@ TF_PSA_CRYPTO_LIBRARY_PUBLIC_INCLUDE = \
|
||||
TF_PSA_CRYPTO_LIBRARY_PRIVATE_INCLUDE = \
|
||||
-I$(TF_PSA_CRYPTO_PATH)/core \
|
||||
-I$(TF_PSA_CRYPTO_PATH)/drivers/builtin/src
|
||||
|
||||
## Usage: $(call remove_enabled_options_crypto,PREPROCESSOR_INPUT)
|
||||
## Remove the preprocessor symbols that are set in the current configuration
|
||||
## from PREPROCESSOR_INPUT. Also normalize whitespace.
|
||||
## Example:
|
||||
## $(call remove_enabled_options_crypto,MBEDTLS_FOO MBEDTLS_BAR)
|
||||
## This expands to an empty string "" if MBEDTLS_FOO and MBEDTLS_BAR are both
|
||||
## enabled in the TF-PSA-Crypto configuration, to "MBEDTLS_FOO" if
|
||||
## MBEDTLS_BAR is enabled but MBEDTLS_FOO is 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.
|
||||
define remove_enabled_options_crypto
|
||||
$(strip $(shell
|
||||
exec 2>/dev/null;
|
||||
{ echo '#include <tf-psa-crypto/build_info.h>'; echo $(1); } |
|
||||
$(CC) $(TF_PSA_CRYPTO_LIBRARY_PUBLIC_INCLUDE) $(CFLAGS) -E - |
|
||||
tail -n 1
|
||||
))
|
||||
endef
|
||||
|
||||
# Ensure that `THREADING` is always defined. This lets us get a clean run
|
||||
# with `make --warn-undefined-variables` without making the conditionals
|
||||
# below more complex than they already are. At this stage, if `$(THREADING)`
|
||||
# is empty, it means we don't know yet whether the threading implementation
|
||||
# requires extra `LDFLAGS`. Once we've done the analysis, if `$(THREADING)`
|
||||
# is empty, it will mean that no extra `LDFLAGS` are required, either
|
||||
# because threading is disabled or because the threading implementation
|
||||
# doesn't require any extra `LDFLAGS`.
|
||||
THREADING ?=
|
||||
|
||||
ifndef WINDOWS_BUILD
|
||||
ifeq ($(THREADING),)
|
||||
# Auto-detect configurations with pthread.
|
||||
# If the call to remove_enabled_options returns "control", the symbols
|
||||
# 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.
|
||||
ifeq (control,$(call remove_enabled_options_crypto,control MBEDTLS_THREADING_C MBEDTLS_THREADING_PTHREAD))
|
||||
THREADING := pthread
|
||||
endif
|
||||
endif
|
||||
#$(info THREADING = $(THREADING))
|
||||
|
||||
ifeq ($(THREADING),pthread)
|
||||
LOCAL_LDFLAGS += -lpthread
|
||||
endif
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user