From 8408841cebcff6b7b696e075317ab4f1fe9674c2 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Fri, 22 Aug 2025 14:51:56 +0200 Subject: [PATCH 1/4] Prepare all-core.sh and all-helpers.sh for the deprecation of Make The deprecation of Make will involve moving and renaming the root Makefile as "scripts/legacy.make". See https://github.com/Mbed-TLS/mbedtls/issues/10316. If "scripts/legacy.make" exists, we use it and call `make -f scripts/legacy.make` instead of just `make` to build with Make in all.sh. In 3.6, there will be no "scripts/legacy.make" and the root Makefile will remain. The scripts must continue to work in that case. Signed-off-by: Ronald Cron --- scripts/all-core.sh | 21 +++++++++++++++------ scripts/all-helpers.sh | 6 +++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/scripts/all-core.sh b/scripts/all-core.sh index 36776a24c..a9070a8e2 100644 --- a/scripts/all-core.sh +++ b/scripts/all-core.sh @@ -188,7 +188,10 @@ pre_initialize_variables () { files_to_back_up="$config_files" if in_mbedtls_repo; then # Files clobbered by in-tree cmake - files_to_back_up="$files_to_back_up Makefile library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile" + if [ -e Makefile ]; then + files_to_back_up="$files_to_back_up Makefile" + fi + files_to_back_up="$files_to_back_up library/Makefile programs/Makefile tests/Makefile programs/fuzz/Makefile" fi append_outcome=0 @@ -228,6 +231,12 @@ pre_initialize_variables () { : ${CLANG_EARLIEST:="clang-earliest"} : ${GCC_LATEST:="gcc-latest"} : ${GCC_EARLIEST:="gcc-earliest"} + : ${MAKE_COMMAND:="make"} + + if [ -e "scripts/legacy.make" ]; then + MAKE_COMMAND="${MAKE_COMMAND} -f ./scripts/legacy.make" + fi + # if MAKEFLAGS is not set add the -j option to speed up invocations of make if [ -z "${MAKEFLAGS+set}" ]; then export MAKEFLAGS="-j$(all_sh_nproc)" @@ -366,7 +375,7 @@ EOF cleanup() { if in_mbedtls_repo; then - command make clean + command $MAKE_COMMAND clean fi # Remove CMake artefacts @@ -877,11 +886,11 @@ pre_check_tools () { pre_generate_files() { # since make doesn't have proper dependencies, remove any possibly outdate # file that might be around before generating fresh ones - make neat + $MAKE_COMMAND neat if [ $QUIET -eq 1 ]; then - make generated_files >/dev/null + $MAKE_COMMAND generated_files >/dev/null else - make generated_files + $MAKE_COMMAND generated_files fi } @@ -920,7 +929,7 @@ pseudo_component_error_test () { # Expected error: '! grep -q . tests/scripts/all.sh -> 1' not grep -q . "$0" # Expected error: 'make unknown_target -> 2' - make unknown_target + $MAKE_COMMAND unknown_target false "this should not be executed" } diff --git a/scripts/all-helpers.sh b/scripts/all-helpers.sh index 28d5395dd..28e2f33c9 100644 --- a/scripts/all-helpers.sh +++ b/scripts/all-helpers.sh @@ -122,7 +122,7 @@ helper_libtestdriver1_make_main() { # we need flags both with and without the LIBTESTDRIVER1_ prefix loc_accel_flags=$( echo "$loc_accel_list" | sed 's/[^ ]* */-DLIBTESTDRIVER1_MBEDTLS_PSA_ACCEL_&/g' ) loc_accel_flags="$loc_accel_flags $( echo "$loc_accel_list" | sed 's/[^ ]* */-DMBEDTLS_PSA_ACCEL_&/g' )" - make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include -I../framework/tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS" "$@" + $MAKE_COMMAND CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -I../tests/include -I../framework/tests/include -I../tests -I../../tests -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_TEST_LIBTESTDRIVER1 $loc_accel_flags" LDFLAGS="-ltestdriver1 $ASAN_CFLAGS" "$@" } ################################################################ @@ -263,9 +263,9 @@ helper_armc6_build_test() msg "build: ARM Compiler 6 ($FLAGS)" - make clean + $MAKE_COMMAND clean ARM_TOOL_VARIANT="ult" CC="$ARMC6_CC" AR="$ARMC6_AR" CFLAGS="$FLAGS" \ - WARNING_CFLAGS='-Werror -xc -std=c99' make lib + WARNING_CFLAGS='-Werror -xc -std=c99' $MAKE_COMMAND lib msg "size: ARM Compiler 6 ($FLAGS)" "$ARMC6_FROMELF" -z library/*.o From f98ac77470f638a405a1b5dabb478f052415a2dc Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Thu, 28 Aug 2025 08:50:44 +0200 Subject: [PATCH 2/4] Prepare Doxygen scripts for the deprecation of Make We now use CMake to build the documentation in the Mbed-TLS development branch. Signed-off-by: Ronald Cron --- scripts/apidoc_full.sh | 28 +++++++++++++++++++--------- scripts/doxygen.sh | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/scripts/apidoc_full.sh b/scripts/apidoc_full.sh index 902a515c6..a2eae052a 100755 --- a/scripts/apidoc_full.sh +++ b/scripts/apidoc_full.sh @@ -22,6 +22,8 @@ if in_mbedtls_repo; then if ! in_3_6_branch; then CRYPTO_CONFIG_H='tf-psa-crypto/include/psa/crypto_config.h' fi + CONFIG_BAK=${CONFIG_H}.bak + cp -p $CONFIG_H $CONFIG_BAK fi if in_tf_psa_crypto_repo; then @@ -37,21 +39,29 @@ if in_tf_psa_crypto_repo || (in_mbedtls_repo && ! in_3_6_branch); then cp -p $CRYPTO_CONFIG_H $CRYPTO_CONFIG_BAK fi -if in_mbedtls_repo; then - CONFIG_BAK=${CONFIG_H}.bak - cp -p $CONFIG_H $CONFIG_BAK +if in_mbedtls_repo && in_3_6_branch; then scripts/config.py realfull make apidoc - mv $CONFIG_BAK $CONFIG_H -elif in_tf_psa_crypto_repo; then +else scripts/config.py realfull - TF_PSA_CRYPTO_ROOT_DIR=$PWD + ROOT_DIR=$PWD rm -rf doxygen/build-apidoc-full mkdir doxygen/build-apidoc-full cd doxygen/build-apidoc-full - cmake -DCMAKE_BUILD_TYPE:String=Check -DGEN_FILES=ON $TF_PSA_CRYPTO_ROOT_DIR - make tfpsacrypto-apidoc - cd $TF_PSA_CRYPTO_ROOT_DIR + cmake -DCMAKE_BUILD_TYPE:String=Check -DGEN_FILES=ON $ROOT_DIR + if in_mbedtls_repo; then + make mbedtls-apidoc + else + make tfpsacrypto-apidoc + fi + cd $ROOT_DIR + # The documentation is built in the source tree thus we can delete the + # build tree. + rm -rf doxygen/build-apidoc-full +fi + +if in_mbedtls_repo; then + mv $CONFIG_BAK $CONFIG_H fi if in_tf_psa_crypto_repo || (in_mbedtls_repo && ! in_3_6_branch); then diff --git a/scripts/doxygen.sh b/scripts/doxygen.sh index 7d051ed1e..c7c465c99 100755 --- a/scripts/doxygen.sh +++ b/scripts/doxygen.sh @@ -30,7 +30,7 @@ if grep -E "(warning|error):" doc.filtered; then exit 1; fi -if in_mbedtls_repo; then +if in_mbedtls_repo && in_3_6_branch; then make apidoc_clean fi From c07d90a2efc067d2e1003a48f07e23bb53d81193 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Thu, 28 Aug 2025 09:25:03 +0200 Subject: [PATCH 3/4] Prepare check_names.py for the deprecation of Make We now use CMake to build the Mbed TLS libraries in both the development and 3.6 cases. This change aligns with what is already done for TF-PSA-Crypto. Signed-off-by: Ronald Cron --- scripts/check_names.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/check_names.py b/scripts/check_names.py index e2b6b8a73..f1f1ee412 100755 --- a/scripts/check_names.py +++ b/scripts/check_names.py @@ -971,15 +971,17 @@ class MBEDTLSCodeParser(CodeParser): ) my_environment = os.environ.copy() my_environment["CFLAGS"] = "-fno-asynchronous-unwind-tables" - # Run make clean separately to lib to prevent unwanted behavior when - # make is invoked with parallelism. + + source_dir = os.getcwd() + build_dir = tempfile.mkdtemp() + os.chdir(build_dir) subprocess.run( - ["make", "clean"], + ["cmake", "-DGEN_FILES=ON", source_dir], universal_newlines=True, check=True ) subprocess.run( - ["make", "lib"], + ["make"], env=my_environment, universal_newlines=True, stdout=subprocess.PIPE, @@ -988,17 +990,21 @@ class MBEDTLSCodeParser(CodeParser): ) # Perform object file analysis using nm - symbols = self.parse_symbols_from_nm([ - "library/libmbedcrypto.a", - "library/libmbedtls.a", - "library/libmbedx509.a" - ]) + if build_tree.is_mbedtls_3_6(): + symbols = self.parse_symbols_from_nm([ + "library/libmbedcrypto.a", + "library/libmbedtls.a", + "library/libmbedx509.a" + ]) + else: + symbols = self.parse_symbols_from_nm([ + "library/libtfpsacrypto.a", + "library/libmbedtls.a", + "library/libmbedx509.a" + ]) - subprocess.run( - ["make", "clean"], - universal_newlines=True, - check=True - ) + os.chdir(source_dir) + shutil.rmtree(build_dir) except subprocess.CalledProcessError as error: self.log.debug(error.output) raise error From b5a1095c2557413106ef91cf678ddab2005dbba9 Mon Sep 17 00:00:00 2001 From: Ronald Cron Date: Wed, 10 Sep 2025 16:30:49 +0200 Subject: [PATCH 4/4] Use cmake --build instead of make Signed-off-by: Ronald Cron --- scripts/apidoc_full.sh | 4 ++-- scripts/check_names.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/apidoc_full.sh b/scripts/apidoc_full.sh index a2eae052a..d16f55c7b 100755 --- a/scripts/apidoc_full.sh +++ b/scripts/apidoc_full.sh @@ -50,9 +50,9 @@ else cd doxygen/build-apidoc-full cmake -DCMAKE_BUILD_TYPE:String=Check -DGEN_FILES=ON $ROOT_DIR if in_mbedtls_repo; then - make mbedtls-apidoc + cmake --build . --target mbedtls-apidoc else - make tfpsacrypto-apidoc + cmake --build . --target tfpsacrypto-apidoc fi cd $ROOT_DIR # The documentation is built in the source tree thus we can delete the diff --git a/scripts/check_names.py b/scripts/check_names.py index f1f1ee412..d8605f689 100755 --- a/scripts/check_names.py +++ b/scripts/check_names.py @@ -810,7 +810,7 @@ class TFPSACryptoCodeParser(CodeParser): check=True ) subprocess.run( - ["make"], + ["cmake", "--build", "."], env=my_environment, universal_newlines=True, stdout=subprocess.PIPE, @@ -981,7 +981,7 @@ class MBEDTLSCodeParser(CodeParser): check=True ) subprocess.run( - ["make"], + ["cmake", "--build", "."], env=my_environment, universal_newlines=True, stdout=subprocess.PIPE,