blob: 9d01ae1692f493e5cfb053096cc48c71fdb648f3 [file] [log] [blame]
Vishal Bhoj9a67d912016-06-09 10:02:07 +01001#!/bin/bash
2
3RESULT_BUF=`echo -e ------------------------------------------------------------`
4RESULT_PASS_COUNT=0
5RESULT_FAIL_COUNT=0
6
Vishal Bhoj9a67d912016-06-09 10:02:07 +01007function 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
18function 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
28function get_build_arch
29{
30 case `uname -m` in
31 arm*)
32 BUILD_ARCH=ARM;;
33 aarch64*)
34 BUILD_ARCH=AARCH64;;
John Stultzaccad872017-07-06 13:56:07 -070035 i?86*)
36 BUILD_ARCH=IA32;;
37 x86_64*)
38 BUILD_ARCH=X64;;
Vishal Bhoj9a67d912016-06-09 10:02:07 +010039 *)
40 BUILD_ARCH=other;;
41 esac
42}
43
44function set_cross_compile
45{
46 get_build_arch
47
48 echo "Target: $PLATFORM_ARCH"
49 echo "Build: $BUILD_ARCH"
John Stultzaccad872017-07-06 13:56:07 -070050 if [ "$PLATFORM_ARCH" = "$BUILD_ARCH" ]; then
Vishal Bhoj9a67d912016-06-09 10:02:07 +010051 TEMP_CROSS_COMPILE=
Vishal Bhoj9a67d912016-06-09 10:02:07 +010052 else
John Stultzaccad872017-07-06 13:56:07 -070053 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 Bhoj9a67d912016-06-09 10:02:07 +010078 fi
79}
80
81function get_gcc_version
82{
John Stultzaccad872017-07-06 13:56:07 -070083 $1 -v >/dev/null 2>&1 || return 1
Vishal Bhoj9a67d912016-06-09 10:02:07 +010084 gcc_version=$($1 -dumpversion)
John Stultzaccad872017-07-06 13:56:07 -070085 MAJVER=`echo $gcc_version | cut -d. -f1`
86
Vishal Bhoj9a67d912016-06-09 10:02:07 +010087 case $gcc_version in
John Stultzaccad872017-07-06 13:56:07 -070088 4*)
Vishal Bhoj9a67d912016-06-09 10:02:07 +010089 echo GCC$(echo ${gcc_version} | awk -F. '{print $1$2}')
90 ;;
91 *)
John Stultzaccad872017-07-06 13:56:07 -070092 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 Bhoj9a67d912016-06-09 10:02:07 +0100101 ;;
102 esac
John Stultzaccad872017-07-06 13:56:07 -0700103
104 return 0
Vishal Bhoj9a67d912016-06-09 10:02:07 +0100105}
106
107function get_clang_version
108{
109 clang_version=`$1 --version | head -1 | sed 's/^.*version\s*\([0-9]*\).\([0-9]*\).*/\1\2/g'`
John Stultzaccad872017-07-06 13:56:07 -0700110 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
122function 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
155function 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
179function 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
198function 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 Bhoj9a67d912016-06-09 10:02:07 +0100214}