Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | RESULT_BUF=`echo -e ------------------------------------------------------------` |
| 4 | RESULT_PASS_COUNT=0 |
| 5 | RESULT_FAIL_COUNT=0 |
| 6 | |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 7 | function result_log |
| 8 | { |
| 9 | if [ $1 -eq 0 ]; then |
| 10 | RESULT_BUF="`printf \"%s\n%55s\tpass\" \"$RESULT_BUF\" \"$2\"`" |
| 11 | RESULT_PASS_COUNT=$(($RESULT_PASS_COUNT + 1)) |
| 12 | else |
| 13 | RESULT_BUF="`printf \"%s\n%55s\tfail\" \"$RESULT_BUF\" \"$2\"`" |
| 14 | RESULT_FAIL_COUNT=$(($RESULT_FAIL_COUNT + 1)) |
| 15 | fi |
| 16 | } |
| 17 | |
| 18 | function result_print |
| 19 | { |
| 20 | printf "%s" "$RESULT_BUF" |
| 21 | echo -e "\n------------------------------------------------------------" |
| 22 | printf "pass\t$RESULT_PASS_COUNT\n" |
| 23 | printf "fail\t$RESULT_FAIL_COUNT\n" |
| 24 | |
| 25 | exit $RESULT_FAIL_COUNT |
| 26 | } |
| 27 | |
| 28 | function get_build_arch |
| 29 | { |
| 30 | case `uname -m` in |
| 31 | arm*) |
| 32 | BUILD_ARCH=ARM;; |
| 33 | aarch64*) |
| 34 | BUILD_ARCH=AARCH64;; |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 35 | i?86*) |
| 36 | BUILD_ARCH=IA32;; |
| 37 | x86_64*) |
| 38 | BUILD_ARCH=X64;; |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 39 | *) |
| 40 | BUILD_ARCH=other;; |
| 41 | esac |
| 42 | } |
| 43 | |
| 44 | function set_cross_compile |
| 45 | { |
| 46 | get_build_arch |
| 47 | |
| 48 | echo "Target: $PLATFORM_ARCH" |
| 49 | echo "Build: $BUILD_ARCH" |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 50 | if [ "$PLATFORM_ARCH" = "$BUILD_ARCH" ]; then |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 51 | TEMP_CROSS_COMPILE= |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 52 | else |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 53 | case "$PLATFORM_ARCH" in |
| 54 | AARCH64) |
| 55 | if [ X"$CROSS_COMPILE_64" != X"" ]; then |
| 56 | TEMP_CROSS_COMPILE="$CROSS_COMPILE_64" |
| 57 | else |
| 58 | TEMP_CROSS_COMPILE=aarch64-linux-gnu- |
| 59 | fi |
| 60 | ;; |
| 61 | ARM) |
| 62 | TEMP_CROSS_COMPILE=arm-linux-gnueabihf- ;; |
| 63 | IA32) |
| 64 | TEMP_CROSS_COMPILE=x86_64-linux-gnu- |
| 65 | for family in 6 5 4 3; do |
| 66 | if i$family86-linux-gnu-as -version >/dev/null 2>&1;then |
| 67 | TEMP_CROSS_COMPILE=i$family86-linux-gnu- |
| 68 | break |
| 69 | fi |
| 70 | done |
| 71 | ;; |
| 72 | X64) |
| 73 | TEMP_CROSS_COMPILE=x86_64-linux-gnu- ;; |
| 74 | *) |
| 75 | echo "Unsupported target architecture '$PLATFORM_ARCH'!" >&2 |
| 76 | ;; |
| 77 | esac |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 78 | fi |
| 79 | } |
| 80 | |
| 81 | function get_gcc_version |
| 82 | { |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 83 | $1 -v >/dev/null 2>&1 || return 1 |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 84 | gcc_version=$($1 -dumpversion) |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 85 | MAJVER=`echo $gcc_version | cut -d. -f1` |
| 86 | |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 87 | case $gcc_version in |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 88 | 4*) |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 89 | echo GCC$(echo ${gcc_version} | awk -F. '{print $1$2}') |
| 90 | ;; |
| 91 | *) |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 92 | if [ "$MAJVER" -ge 5 ]; then |
| 93 | # We only have a GCC5 build profile for now, so... |
| 94 | # echo GCC$MAJVER |
| 95 | echo GCC5 |
| 96 | else |
| 97 | echo "Unknown toolchain version '$gcc_version'" >&2 |
| 98 | echo "Attempting to build using GCC49 profile." >&2 |
| 99 | echo GCC49 |
| 100 | fi |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 101 | ;; |
| 102 | esac |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 103 | |
| 104 | return 0 |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | function get_clang_version |
| 108 | { |
| 109 | clang_version=`$1 --version | head -1 | sed 's/^.*version\s*\([0-9]*\).\([0-9]*\).*/\1\2/g'` |
John Stultz | accad87 | 2017-07-06 13:56:07 -0700 | [diff] [blame^] | 110 | case $clang_version in |
| 111 | 35*) |
| 112 | echo "CLANG$clang_version" |
| 113 | ;; |
| 114 | *) |
| 115 | echo "Unknown toolchain version '$clang_version'" >&2 |
| 116 | echo "Attempting to build using CLANG35 profile." >&2 |
| 117 | echo CLANG35 |
| 118 | ;; |
| 119 | esac |
| 120 | } |
| 121 | |
| 122 | function download_patch_openssl |
| 123 | { |
| 124 | OPENSSL_VER=`ls EDKII_openssl-*.patch | sed 's/^.*-\([0-9.a-z]*\).patch/\1/'` |
| 125 | OPENSSL_TAR=openssl-${OPENSSL_VER}.tar.gz |
| 126 | OPENSSL_URL=http://www.openssl.org/source/${OPENSSL_TAR} |
| 127 | OPENSSL_DIR=openssl-${OPENSSL_VER} |
| 128 | OPENSSL_PATCH=EDKII_openssl-${OPENSSL_VER}.patch |
| 129 | |
| 130 | if [ -e "$WORKSPACE"/CryptoPkg/Include/openssl/opensslconf.h ]; then |
| 131 | echo "OpenSSL already imported!" |
| 132 | return 0 |
| 133 | fi |
| 134 | |
| 135 | # Use cached copy if available |
| 136 | if [ -f "$WORKSPACE"/LinaroPkg/"$OPENSSL_TAR" ]; then |
| 137 | tar xzf "$WORKSPACE"/LinaroPkg/"$OPENSSL_TAR" |
| 138 | else |
| 139 | wget -O - -q ${OPENSSL_URL} | tar xzf - |
| 140 | fi |
| 141 | |
| 142 | echo "Importing OpenSSL $OPENSSL_VER" |
| 143 | ( cd ${OPENSSL_DIR}; patch -p1 -i ../${OPENSSL_PATCH} ) |
| 144 | ./Install.sh |
| 145 | |
| 146 | if [ $? -eq 0 ]; then |
| 147 | OPENSSL_CONFIGURED=TRUE |
| 148 | else |
| 149 | echo "OpenSSL $OPENSSL_VER import failed!" >&2 |
| 150 | rm -rf $OPENSSL_TAR $OPENSSL_DIR |
| 151 | return 1 |
| 152 | fi |
| 153 | } |
| 154 | |
| 155 | function clone_process_openssl |
| 156 | { |
| 157 | if [ -e openssl/include/openssl/opensslconf.h ]; then |
| 158 | echo "OpenSSL already imported!" |
| 159 | return 0 |
| 160 | fi |
| 161 | |
| 162 | OPENSSL_VER=`git ls-remote --tags git://github.com/openssl/openssl.git | awk '{print $2;}' | sed 's-^refs/tags/--g' | grep -v '\^{}$' | grep '^OpenSSL' | grep -v '^OpenSSL_FIPS' | tail -1 | sed -n 's/^OpenSSL_\([0-9]*\)_\([0-9]*\)_\([0-9.a-z]*\)$/openssl-\1.\2.\3\n/p'` |
| 163 | OPENSSL_TAR="$OPENSSL_VER.tar.gz" |
| 164 | if [ -z "$OPENSSL_TAR" ]; then |
| 165 | return 1 |
| 166 | fi |
| 167 | OPENSSL_URL=http://www.openssl.org/source/${OPENSSL_TAR} |
| 168 | if [ ! -f "$OPENSSL_TAR" ]; then |
| 169 | wget -q ${OPENSSL_URL} |
| 170 | else |
| 171 | rm -rf openssl |
| 172 | fi |
| 173 | tar xzf "$OPENSSL_TAR" |
| 174 | mv "$OPENSSL_VER" openssl |
| 175 | # perl process_files.pl # not needed and not currently working |
| 176 | return $? |
| 177 | } |
| 178 | |
| 179 | function import_openssl |
| 180 | { |
| 181 | # Don't re-import if already done |
| 182 | if [ "$OPENSSL_CONFIGURED" = "TRUE" ]; then |
| 183 | echo "Using existing OpenSSL $OPENSSL_VER" |
| 184 | return 0 |
| 185 | fi |
| 186 | |
| 187 | cd CryptoPkg/Library/OpensslLib/ |
| 188 | if [ -f EDKII_openssl-*.patch ]; then |
| 189 | download_patch_openssl |
| 190 | else |
| 191 | clone_process_openssl |
| 192 | fi |
| 193 | RET=$? |
| 194 | cd - >/dev/null |
| 195 | return $RET |
| 196 | } |
| 197 | |
| 198 | function search_packages_path |
| 199 | { |
| 200 | file="$1" |
| 201 | |
| 202 | IFS=: |
| 203 | for dir in $PACKAGES_PATH; do |
| 204 | if [ -e "$dir/$file" ]; then |
| 205 | echo "$dir/$file" |
| 206 | unset IFS |
| 207 | return 0 |
| 208 | fi |
| 209 | done |
| 210 | |
| 211 | echo "$file not found in any directory on PACKAGES_PATH!" >&2 |
| 212 | unset IFS |
| 213 | return 1 |
Vishal Bhoj | 9a67d91 | 2016-06-09 10:02:07 +0100 | [diff] [blame] | 214 | } |