blob: bbe28139d5ba4bfa96237c9b8dc45d5ae413aa02 [file] [log] [blame]
Minos Galanakis2c824b42025-03-20 09:28:45 +00001# project-detection.sh
2#
3# Copyright The Mbed TLS Contributors
4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5#
6# Purpose
7#
8# This script contains functions for shell scripts to
9# help detect which project (Mbed TLS, TF-PSA-Crypto)
10# or which Mbed TLS branch they are in.
11
12# Project detection
13read_project_name_file () {
14 SCRIPT_DIR=$(pwd)
15
16 PROJECT_NAME_FILE="scripts/project_name.txt"
17
18 if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else
19 echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2
20 exit 1
21 fi
22}
23
24in_mbedtls_repo () {
25 read_project_name_file
26 test "$PROJECT_NAME" = "Mbed TLS"
27}
28
29in_tf_psa_crypto_repo () {
30 read_project_name_file
31 test "$PROJECT_NAME" = "TF-PSA-Crypto"
32}
33
34#Branch detection
35read_build_info () {
36 SCRIPT_DIR=$(pwd)
37
38 BUILD_INFO_FILE="include/mbedtls/build_info.h"
39
40 if [ ! -f "$BUILD_INFO_FILE" ]; then
41 echo "File $BUILD_INFO_FILE not found."
42 exit 1
43 fi
44
45 MBEDTLS_VERSION_MAJOR=$(grep "^#define MBEDTLS_VERSION_MAJOR" "$BUILD_INFO_FILE" | awk '{print $3}')
46 MBEDTLS_VERSION_MINOR=$(grep "^#define MBEDTLS_VERSION_MINOR" "$BUILD_INFO_FILE" | awk '{print $3}')
47
48 if [ -z "$MBEDTLS_VERSION_MAJOR" ]; then
49 echo "MBEDTLS_VERSION_MAJOR not found in $BUILD_INFO_FILE."
50 exit 1
51 fi
52
53 if [ -z "$MBEDTLS_VERSION_MINOR" ]; then
54 echo "MBEDTLS_VERSION_MINOR not found in $BUILD_INFO_FILE."
55 exit 1
56 fi
57}
58
59in_3_6_branch () {
60 read_build_info
61 test $MBEDTLS_VERSION_MAJOR = "3" && test $MBEDTLS_VERSION_MINOR = "6"
62}
63
64in_4_x_branch () {
65 read_build_info
66 test $MBEDTLS_VERSION_MAJOR = "4"
67}