• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# This file is part of the openHiTLS project.
4#
5# openHiTLS is licensed under the Mulan PSL v2.
6# You can use this software according to the terms and conditions of the Mulan PSL v2.
7# You may obtain a copy of Mulan PSL v2 at:
8#
9#     http://license.coscl.org.cn/MulanPSL2
10#
11# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14# See the Mulan PSL v2 for more details.
15set -e
16cd ../../
17HITLS_ROOT_DIR=`pwd`
18
19hitls_compile_option=()
20
21paramList=$@
22paramNum=$#
23add_options=""
24del_options=""
25dis_options=""
26get_arch=`arch`
27
28LIB_TYPE="static shared"
29enable_sctp="--enable-sctp"
30BITS=64
31
32usage()
33{
34    printf "%-50s %-30s\n" "Build openHiTLS Code"                      "sh build_hitls.sh"
35    printf "%-50s %-30s\n" "Build openHiTLS Code With Gcov"            "sh build_hitls.sh gcov"
36    printf "%-50s %-30s\n" "Build openHiTLS Code With Debug"           "sh build_hitls.sh debug"
37    printf "%-50s %-30s\n" "Build openHiTLS Code With Asan"            "sh build_hitls.sh asan"
38    printf "%-50s %-30s\n" "Build openHiTLS Code With Pure C"           "sh build_hitls.sh pure_c"
39    printf "%-50s %-30s\n" "Build openHiTLS Code With X86_64"            "sh build_hitls.sh x86_64"
40    printf "%-50s %-30s\n" "Build openHiTLS Code With Armv8_be"          "sh build_hitls.sh armv8_be"
41    printf "%-50s %-30s\n" "Build openHiTLS Code With Armv8_le"          "sh build_hitls.sh armv8_le"
42    printf "%-50s %-30s\n" "Build openHiTLS Code With Add Options"     "sh build_hitls.sh add-options=xxx"
43    printf "%-50s %-30s\n" "Build openHiTLS Code With No Provider"     "sh build_hitls.sh no-provider"
44    printf "%-50s %-30s\n" "Build openHiTLS Code With No Sctp"         "sh build_hitls.sh no_sctp"
45    printf "%-50s %-30s\n" "Build openHiTLS Code With Bits"            "sh build_hitls.sh bits=xxx"
46    printf "%-50s %-30s\n" "Build openHiTLS Code With Lib Type"        "sh build_hitls.sh shared"
47    printf "%-50s %-30s\n" "Build openHiTLS Code With Lib Fuzzer"      "sh build_hitls.sh libfuzzer"
48    printf "%-50s %-30s\n" "Build openHiTLS Code With Help"            "sh build_hitls.sh help"
49}
50
51clean()
52{
53    rm -rf ${HITLS_ROOT_DIR}/build
54    mkdir ${HITLS_ROOT_DIR}/build
55}
56
57down_depend_code()
58{
59    if [ ! -d "${HITLS_ROOT_DIR}/platform" ]; then
60        cd ${HITLS_ROOT_DIR}
61        mkdir platform
62    fi
63
64    if [ ! -d "${HITLS_ROOT_DIR}/platform/Secure_C/src" ]; then
65        cd ${HITLS_ROOT_DIR}/platform
66        git clone https://gitee.com/openeuler/libboundscheck.git  Secure_C
67    fi
68}
69
70build_depend_code()
71{
72    if [ ! -d "${HITLS_ROOT_DIR}/platform/Secure_C/lib" ]; then
73        mkdir -p ${HITLS_ROOT_DIR}/platform/Secure_C/lib
74        cd ${HITLS_ROOT_DIR}/platform/Secure_C
75        make -j
76    fi
77}
78
79build_hitls_code()
80{
81    # Compile openHiTLS
82    cd ${HITLS_ROOT_DIR}/build
83    add_options="${add_options} -DHITLS_CRYPTO_RAND_CB" # HITLS_CRYPTO_RAND_CB: add rand callback
84    add_options="${add_options} -DHITLS_EAL_INIT_OPTS=9 -DHITLS_CRYPTO_ASM_CHECK" # Get CPU capability
85    add_options="${add_options} -DHITLS_CRYPTO_ENTROPY -DHITLS_CRYPTO_ENTROPY_DEVRANDOM -DHITLS_CRYPTO_ENTROPY_GETENTROPY -DHITLS_CRYPTO_ENTROPY_SYS -DHITLS_CRYPTO_ENTROPY_HARDWARE" # add default entropy
86    add_options="${add_options} -DHITLS_CRYPTO_DRBG_GM" # enable GM DRBG
87    add_options="${add_options} ${test_options}"
88    if [[ $get_arch = "x86_64" ]]; then
89        echo "Compile: env=x86_64, c, little endian, 64bits"
90        del_options="${del_options} -DHITLS_CRYPTO_SM2_PRECOMPUTE_512K_TBL" # close the sm2 512k pre-table
91        python3 ../configure.py --lib_type ${LIB_TYPE} --enable all --asm_type x8664 --add_options="$add_options" --del_options="$del_options" --add_link_flags="-ldl" ${enable_sctp} ${dis_options}
92    elif [[ $get_arch = "armv8_be" ]]; then
93        echo "Compile: env=armv8, asm + c, big endian, 64bits"
94        python3 ../configure.py --lib_type ${LIB_TYPE} --enable all --endian big --asm_type armv8 --add_options="$add_options" --del_options="$del_options" --add_link_flags="-ldl" ${enable_sctp} ${dis_options}
95    elif [[ $get_arch = "armv8_le" ]]; then
96        echo "Compile: env=armv8, asm + c, little endian, 64bits"
97        python3 ../configure.py --lib_type ${LIB_TYPE} --enable all --asm_type armv8 --add_options="$add_options" --del_options="$del_options" --add_link_flags="-ldl" ${enable_sctp} ${dis_options}
98    else
99        echo "Compile: env=$get_arch, c, little endian, 64bits"
100        python3 ../configure.py --lib_type ${LIB_TYPE} --enable all --add_options="$add_options" --del_options="$del_options" --add_link_flags="-ldl" ${enable_sctp} ${dis_options}
101    fi
102    cmake ..
103    make -j
104}
105
106parse_option()
107{
108    for i in $paramList
109    do
110        key=${i%%=*}
111        value=${i#*=}
112        case "${key}" in
113            "add-options")
114                add_options="${add_options} ${value}"
115                ;;
116            "no-provider")
117                dis_options="--disable feature_provider provider codecs"
118                ;;
119            "gcov")
120                add_options="${add_options} -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage -fdump-rtl-expand"
121                ;;
122            "debug")
123                add_options="${add_options} -O0 -g3 -gdwarf-2"
124                del_options="${del_options} -O2 -D_FORTIFY_SOURCE=2"
125                ;;
126            "asan")
127                add_options="${add_options} -fsanitize=address -fsanitize-address-use-after-scope -O0 -g3 -fno-stack-protector -fno-omit-frame-pointer -fgnu89-inline"
128                del_options="${del_options} -fstack-protector-strong -fomit-frame-pointer -O2 -D_FORTIFY_SOURCE=2"
129                ;;
130            "x86_64")
131                get_arch="x86_64"
132                ;;
133            "armv8_be")
134                get_arch="armv8_be"
135                ;;
136            "armv8_le")
137                get_arch="armv8_le"
138                ;;
139            "pure_c")
140                get_arch="C"
141                ;;
142            "no_sctp")
143                enable_sctp=""
144                ;;
145            "bits")
146                BITS="$value"
147                ;;
148            "static")
149                LIB_TYPE="static"
150                ;;
151            "shared")
152                LIB_TYPE="shared"
153                ;;
154            "libfuzzer")
155                add_options="${add_options} -fsanitize=fuzzer-no-link -fsanitize=signed-integer-overflow -fsanitize-coverage=trace-cmp"
156                del_options="${del_options} -Wtrampolines -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fomit-frame-pointer -fdump-rtl-expand"
157                export ASAN_OPTIONS=detect_stack_use_after_return=1:strict_string_checks=1:detect_leaks=1:log_path=asan.log
158                export CC=clang
159                ;;
160            "help")
161                usage
162                exit 0
163                ;;
164            *)
165                echo "${i} option is not recognized, Please run <sh build_hitls.sh help> get supported options."
166                usage
167                exit 0
168                ;;
169        esac
170    done
171}
172
173clean
174parse_option
175down_depend_code
176build_depend_code
177build_hitls_code
178