Debian Codegraph @

util/crossgcc/buildgcc

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. sh
2 # shellcheck disable=SC2030,SC2031,SC2059
3 # The above line must be directly after the shebang line.
4 # Disables these warnings:
5 # 2030 - Modification of var is local (to subshell caused by pipeline).
6 # shell check 0.4.6 gets confused by the read -t 1 command and interprets
7 # the '1' as $1 getting modified.
8 # 2031 - var was modified in a subshell. That change might be lost.
9 # caused by shell check bug with SC2030? This causes any $1 from that
10 # point on to be flagged.
11 # 2059 - Don't use variables in the printf format string. Use printf "..%s.." "$foo".
12 # This is used for all of our color printing.
13
14 #
15 # SPDX-License-Identifier: GPL-2.0-only
16
17 cd "$(dirnamescip-shell system . . dirname. "$0")" || exit 1
18
19 if [scip-shell system . . `[`. -z "$CROSSGCC_VERSION" ]; then
20 CROSSGCC_VERSION="$(gitscip-shell system . . git. log -n 1 --pretty=%cd --date=short .)_$(gitscip-shell system . . git. log -n 1 --pretty=%h .)"
21 fi
22
23 # default settings
24 PACKAGE=GCC
25 TARGETDIR=$(pwdscip-shell system . . pwd.)/xgcc
26 TARGETARCH=i386-elf
27 DEFAULT_LANGUAGES=c
28 LANGUAGES=
29 DESTDIR=
30 SAVETEMPS=0
31 BOOTSTRAP=0
32 THREADS=1
33 FETCH_ONLY=0
34 USE_COREBOOT_MIRROR=0
35 COREBOOT_MIRROR_URL="https://www.coreboot.org/releases/crossgcc-sources"
36
37 # GCC Toolchain (built first)
38 # Math libraries (GCC dependencies)
39 GMP_VERSION=6.3.0
40 MPFR_VERSION=4.2.2
41 MPC_VERSION=1.3.1
42 # Core GCC components
43 GCC_VERSION=14.2.0
44 BINUTILS_VERSION=2.44
45 LIBSTDCXX_VERSION="${GCC_VERSION}" # GCC-specific C++ library
46
47 # Low-level Tools (built after GCC)
48 NASM_VERSION=2.16.03 # x86 assembly
49 IASL_VERSION=20250404 # ACPI compiler
50
51 # Clang/LLVM Toolchain (alternative to GCC, built separately)
52 CLANG_VERSION=18.1.8
53 CMAKE_VERSION=4.0.3 # Required for building Clang
54
55 # Architecture-specific options
56 RISCV_ISA_SPEC=20191213
57
58 # Filename for each package
59 GMP_ARCHIVE="gmp-${GMP_VERSION}.tar.xz"
60 MPFR_ARCHIVE="mpfr-${MPFR_VERSION}.tar.xz"
61 MPC_ARCHIVE="mpc-${MPC_VERSION}.tar.gz"
62 GCC_ARCHIVE="gcc-${GCC_VERSION}.tar.xz"
63 LIBSTDCXX_ARCHIVE="${GCC_ARCHIVE}"
64 BINUTILS_ARCHIVE="binutils-${BINUTILS_VERSION}.tar.xz"
65 IASL_ARCHIVE="acpica-unix-${IASL_VERSION}.tar.gz"
66 # CLANG toolchain FILE locations
67 LLD_ARCHIVE="lld-${CLANG_VERSION}.src.tar.xz"
68 LLVM_ARCHIVE="llvm-${CLANG_VERSION}.src.tar.xz"
69 CLANG_ARCHIVE="clang-${CLANG_VERSION}.src.tar.xz"
70 CRT_ARCHIVE="compiler-rt-${CLANG_VERSION}.src.tar.xz"
71 CTE_ARCHIVE="clang-tools-extra-${CLANG_VERSION}.src.tar.xz"
72 LLVMCMAKE_ARCHIVE="cmake-${CLANG_VERSION}.src.tar.xz"
73 LIBUNWIND_ARCHIVE="libunwind-${CLANG_VERSION}.src.tar.xz"
74 RUNTIMES_ARCHIVE="runtimes-${CLANG_VERSION}.src.tar.xz"
75 CMAKE_ARCHIVE="cmake-${CMAKE_VERSION}.tar.gz"
76 NASM_ARCHIVE="nasm-${NASM_VERSION}.tar.bz2"
77
78 # These URLs are sanitized by the jenkins toolchain test builder, so if
79 # a completely new URL is added here, it probably needs to be added
80 # to the jenkins build as well, or the builder won't download it.
81
82 # GCC toolchain archive locations
83 GMP_BASE_URL="https://ftpmirror.gnu.org/gmp"
84 MPFR_BASE_URL="https://ftpmirror.gnu.org/mpfr"
85 MPC_BASE_URL="https://ftpmirror.gnu.org/mpc"
86 GCC_BASE_URL="https://ftpmirror.gnu.org/gcc/gcc-${GCC_VERSION}"
87 LIBSTDCXX_BASE_URL="${GCC_BASE_URL}"
88 BINUTILS_BASE_URL="https://ftpmirror.gnu.org/binutils"
89 IASL_BASE_URL="https://downloadmirror.intel.com/852044"
90 # CLANG toolchain archive locations
91 LLVM_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
92 CLANG_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
93 CRT_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
94 CTE_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
95 LLVMCMAKE_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
96 LLD_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
97 LIBUNWIND_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
98 RUNTIMES_BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${CLANG_VERSION}"
99 CMAKE_BASE_URL="https://cmake.org/files/v${CMAKE_VERSION%.*}"
100 NASM_BASE_URL="https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}"
101
102 ALL_ARCHIVES="$GMP_BASE_URL/$GMP_ARCHIVE $MPFR_BASE_URL/$MPFR_ARCHIVE $MPC_BASE_URL/$MPC_ARCHIVE \
103 $GCC_BASE_URL/$GCC_ARCHIVE $BINUTILS_BASE_URL/$BINUTILS_ARCHIVE $IASL_BASE_URL/$IASL_ARCHIVE \
104 $LLD_BASE_URL/$LLD_ARCHIVE $LLVM_BASE_URL/$LLVM_ARCHIVE $CLANG_BASE_URL/$CLANG_ARCHIVE \
105 $LLVMCMAKE_BASE_URL/$LLVMCMAKE_ARCHIVE $CRT_BASE_URL/$CRT_ARCHIVE $CTE_BASE_URL/$CTE_ARCHIVE \
106 $LIBUNWIND_BASE_URL/$LIBUNWIND_ARCHIVE $RUNTIMES_BASE_URL/$RUNTIMES_ARCHIVE \
107 $CMAKE_BASE_URL/$CMAKE_ARCHIVE $NASM_BASE_URL/$NASM_ARCHIVE $LIBSTDCXX_BASE_URL/$LIBSTDCXX_ARCHIVE"
108
109 # GCC toolchain directories
110 GMP_DIR="gmp-${GMP_VERSION}"
111 MPFR_DIR="mpfr-${MPFR_VERSION}"
112 MPC_DIR="mpc-${MPC_VERSION}"
113 # shellcheck disable=SC2034
114 GCC_DIR="gcc-${GCC_VERSION}"
115 LIBSTDCXX_DIR="${GCC_DIR}"
116 # shellcheck disable=SC2034
117 BINUTILS_DIR="binutils-${BINUTILS_VERSION}"
118 IASL_DIR="acpica-unix-${IASL_VERSION}"
119 # CLANG toolchain directories
120 LLD_DIR="lld-${CLANG_VERSION}.src"
121 LLVM_DIR="llvm-${CLANG_VERSION}.src"
122 CLANG_DIR="clang-${CLANG_VERSION}.src"
123 CRT_DIR="compiler-rt-${CLANG_VERSION}.src"
124 CTE_DIR="clang-tools-extra-${CLANG_VERSION}.src"
125 LLVMCMAKE_DIR="cmake-${CLANG_VERSION}.src"
126 LIBUNWIND_DIR="libunwind-${CLANG_VERSION}.src"
127 RUNTIMES_DIR="runtimes-${CLANG_VERSION}.src"
128 CMAKE_DIR="cmake-${CMAKE_VERSION}"
129 NASM_DIR="nasm-${NASM_VERSION}"
130
131 unset MAKELEVEL MAKEFLAGS
132
133 red='\033[0;31m'
134 RED='\033[1;31m'
135 green='\033[0;32m'
136 GREEN='\033[1;32m'
137 blue='\033[0;34m'
138 CYAN='\033[1;36m'
139 NC='\033[0m' # No Color
140
141 UNAME=$(if unamescip-shell system . . uname. | grepscip-shell system . . grep. -iq cygwin; then echoscip-shell system . . echo. Cygwin; else unamescip-shell system . . uname.; fi)
142 HALT_FOR_TOOLS=0
143
144 hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc().()
145 {
146 # $1 "host" or "target"
147 if [scip-shell system . . `[`. "$BOOTSTRAP" = 1 ] && [scip-shell system . . `[`. "$1" = target ]; then
148 echoscip-shell system . . echo. "$DESTDIR$TARGETDIR/bin/gcc"
149 else
150 echoscip-shell system . . echo. "$CC"
151 fi
152 }
153
154 hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx().()
155 {
156 # $1 "host" or "target"
157 if [scip-shell system . . `[`. "$BOOTSTRAP" = 1 ] && [scip-shell system . . `[`. "$1" = target ]; then
158 echoscip-shell system . . echo. "$DESTDIR$TARGETDIR/bin/g++"
159 else
160 echoscip-shell system . . echo. "$CXX"
161 fi
162 }
163
164 normalize_dirsscip-shell shell coreboot 25.09+dfsg-1 normalize_dirs().()
165 {
166 mkdirscip-shell system . . mkdir. -p "$DESTDIR$TARGETDIR/lib"
167 testscip-shell system . . test. -d "$DESTDIR$TARGETDIR/lib32" && mvscip-shell system . . mv. "$DESTDIR$TARGETDIR"/lib32/* "$DESTDIR$TARGETDIR/lib"
168 testscip-shell system . . test. -d "$DESTDIR$TARGETDIR/lib64" && mvscip-shell system . . mv. "$DESTDIR$TARGETDIR"/lib64/* "$DESTDIR$TARGETDIR/lib"
169 rmscip-shell system . . rm. -rf "$DESTDIR$TARGETDIR/lib32" "$DESTDIR$TARGETDIR/lib64"
170
171 perlscip-shell system . . perl. -pi -e "s,/lib32,/lib," "$DESTDIR$TARGETDIR"/lib/*.la
172 perlscip-shell system . . perl. -pi -e "s,/lib64,/lib," "$DESTDIR$TARGETDIR"/lib/*.la
173 }
174
175 countdownscip-shell shell coreboot 25.09+dfsg-1 countdown().()
176 {
177 tout=${1:-10}
178
179 printfscip-shell system . . printf. "\nPress Ctrl-C to abort, Enter to continue... %2ds" "$tout"
180 while [scip-shell system . . `[`. "$tout" -gt 0 ]; do
181 sleepscip-shell system . . sleep. 1
182 tout=$((tout - 1))
183 printfscip-shell system . . printf. "\b\b\b%2ds" $tout
184 done
185 printfscip-shell system . . printf. "\n"
186 }
187
188 timeoutscip-shell shell coreboot 25.09+dfsg-1 timeout().()
189 {
190 tout=${1:-10}
191
192 # Ignore SIGUSR1, should interrupt `read` though.
193 trap false USR1
194 # Clean up in case the user aborts.
195 trap 'kill $counter > /dev/null 2>&1' EXIT
196
197 (countdownscip-shell shell coreboot 25.09+dfsg-1 countdown(). "$tout"; killscip-shell system . . kill. -USR1 $$)&
198 counter=$!
199
200 # Some shells with sh compatibility mode (e.g. zsh, mksh) only
201 # let us interrupt `read` if a non-standard -t parameter is given.
202 # shellcheck disable=SC2034,SC2039,SC2162
203 if echoscip-shell system . . echo. | read -t 1 foo 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
204 read -t $((tout + 1)) foo
205 else
206 read foo
207 fi
208
209 killscip-shell system . . kill. $counter > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
210 trap - USR1 EXIT
211 }
212
213 please_installscip-shell shell coreboot 25.09+dfsg-1 please_install().()
214 {
215 HALT_FOR_TOOLS=1
216 # shellcheck disable=SC1091
217 testscip-shell system . . test. -r /etc/os-releasescip-shell filesystem . . `/etc/os-release`. && . /etc/os-releasescip-shell source . . `/etc/os-release`.
218 # vanilla debian doesn't define `ID_LIKE`, just `ID`
219 if [scip-shell system . . `[`. -z "${ID_LIKE}" ] && [scip-shell system . . `[`. -n "${ID}" ]; then
220 ID_LIKE=${ID}
221 fi
222 case "$ID_LIKE" in
223 debian) solution="sudo apt-get install $1" ;;
224 suse) solution="sudo zypper install $1" ;;
225 *) solution="using your OS packaging system" ;;
226 esac
227
228 printfscip-shell system . . printf. "${RED}ERROR:${red} Missing tool: Please install '$1'. (eg $solution)${NC}\n" >&2
229 if [scip-shell system . . `[`. -n "$2" ]; then
230 printfscip-shell system . . printf. "${RED}ERROR:${red} or install '$2'.${NC}\n" >&2
231 fi
232 }
233
234 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool().()
235 {
236 # $1 short name
237 # $2 search string
238 # $3 soft fail if set
239 # $4 alternative package to install on failure
240 # result: file name of that tool on stdout
241 # or no output if nothing suitable was found
242 search=GNU
243 if [scip-shell system . . `[`. -n "$2" ]; then
244 search="$2"
245 fi
246 for i in "$1" "g$1" "gnu$1"; do
247 if [scip-shell system . . `[`. -x "$(command -v "$i" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
248 if [scip-shell system . . `[`. "$(catscip-shell system . . cat. /dev/nullscip-shell filesystem . . `/dev/null`. | $i --version 2>&1 | grepscip-shell system . . grep. -c "$search")" \
249 -gt 0 ]; then
250 echoscip-shell system . . echo. "$i"
251 return
252 fi
253 fi
254 done
255 # A workaround for OSX 10.9 and some BSDs, whose nongnu
256 # patch and tar also work.
257 if [scip-shell system . . `[`. "$UNAME" = "Darwin" ] || [scip-shell system . . `[`. "$UNAME" = "FreeBSD" ] || [scip-shell system . . `[`. "$UNAME" = "NetBSD" ] || [scip-shell system . . `[`. "$UNAME" = "OpenBSD" ]; then
258 if [scip-shell system . . `[`. "$1" = "patch" ] || [scip-shell system . . `[`. "$1" = "tar" ]; then
259 if [scip-shell system . . `[`. -x "$(command -v "$1" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
260 echoscip-shell system . . echo. "$1"
261 return
262 fi
263 fi
264 fi
265 if echoscip-shell system . . echo. "$1" | grepscip-shell system . . grep. -q "sum" ; then
266 algor=$(echoscip-shell system . . echo. "$1" | sedscip-shell system . . sed. -e 's,sum,,')
267 if [scip-shell system . . `[`. -x "$(command -v "$1" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
268 #xxxsum [file]
269 echoscip-shell system . . echo. "$1"
270 return
271 elif [scip-shell system . . `[`. -x "$(command -v "$algor" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
272 #xxx [file]
273 echoscip-shell system . . echo. "$algor"
274 return
275 elif [scip-shell system . . `[`. -x "$(command -v openssl 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
276 #openssl xxx [file]
277 echoscip-shell system . . echo. openssl "$algor"
278 return
279 elif [scip-shell system . . `[`. -x "$(command -v cksum 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
280 #cksum -a xxx [file]
281 #cksum has special options in NetBSD. Actually, NetBSD will use the second case above.
282 echoscip-shell system . . echo. "buildgcc" | cksumscip-shell system . . cksum. -a "$algor" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>/dev/nullscip-shell filesystem . . `/dev/null`. && \
283 echo cksum -a "$algor"
284 return
285 fi
286 fi
287
288 [scip-shell system . . `[`. -z "$3" ] && please_installscip-shell shell coreboot 25.09+dfsg-1 please_install(). "$1" "$4"
289 falsescip-shell system . . false.
290 }
291
292 # Run a compile check of the specified library option to see if it's installed
293 check_for_libraryscip-shell shell coreboot 25.09+dfsg-1 check_for_library().() {
294 LIBRARY_FLAGS="$1"
295 LIBRARY_PACKAGES="$2"
296 LIBTEST_FILE=.libtest
297
298 echoscip-shell system . . echo. "int main(int argc, char **argv) { (void) argc; (void) argv; return 0; }" > "${LIBTEST_FILE}.c"
299
300 # shellcheck disable=SC2086
301 "$CC" $CFLAGS $LIBRARY_FLAGS "${LIBTEST_FILE}.c" -o "${LIBTEST_FILE}" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || \
302 please_install "$LIBRARY_PACKAGES"
303 rmscip-shell system . . rm. -rf "${LIBTEST_FILE}.c" "${LIBTEST_FILE}"
304 }
305
306 buildcc_majorscip-shell shell coreboot 25.09+dfsg-1 buildcc_major().() {
307 echoscip-shell system . . echo. "${GCC_VERSION}" | cutscip-shell system . . cut. -d. -f1
308 }
309
310 buildcc_minorscip-shell shell coreboot 25.09+dfsg-1 buildcc_minor().() {
311 echoscip-shell system . . echo. "${GCC_VERSION}" | cutscip-shell system . . cut. -d. -f2
312 }
313
314 buildcc_versionscip-shell shell coreboot 25.09+dfsg-1 buildcc_version().() {
315 echoscip-shell system . . echo. "${GCC_VERSION}" | cutscip-shell system . . cut. -d. -f1-2
316 }
317
318 hostcc_majorscip-shell shell coreboot 25.09+dfsg-1 hostcc_major().() {
319 (echoscip-shell system . . echo. __GNUC__ | ${CC} -E - 2>/dev/nullscip-shell filesystem . . `/dev/null`. || echoscip-shell system . . echo. 0) | tailscip-shell system . . tail. -1
320 }
321
322 hostcc_minorscip-shell shell coreboot 25.09+dfsg-1 hostcc_minor().() {
323 (echoscip-shell system . . echo. __GNUC_MINOR__ | ${CC} -E - 2>/dev/nullscip-shell filesystem . . `/dev/null`. || echoscip-shell system . . echo. 0) | tailscip-shell system . . tail. -1
324 }
325
326 hostcc_versionscip-shell shell coreboot 25.09+dfsg-1 hostcc_version().() {
327 printfscip-shell system . . printf. "%d.%d" "$(hostcc_majorscip-shell shell coreboot 25.09+dfsg-1 hostcc_major().)" "$(hostcc_minorscip-shell shell coreboot 25.09+dfsg-1 hostcc_minor().)"
328 }
329
330 hostcc_has_gnat1scip-shell shell coreboot 25.09+dfsg-1 hostcc_has_gnat1().() {
331 [scip-shell system . . `[`. -x "$(${CC} -print-prog-name=gnat1)" ]
332 }
333
334 have_gnatscip-shell shell coreboot 25.09+dfsg-1 have_gnat().() {
335 hostcc_has_gnat1scip-shell shell coreboot 25.09+dfsg-1 hostcc_has_gnat1(). && \
336 searchtool gnatbind "Free Software Foundation" nofail > /dev/nullscip-shell filesystem . . `/dev/null`.
337 }
338
339 ada_requestedscip-shell shell coreboot 25.09+dfsg-1 ada_requested().() {
340 echoscip-shell system . . echo. "${LANGUAGES}" | grepscip-shell system . . grep. -q '\<ada\>'
341 }
342
343 downloadscip-shell shell coreboot 25.09+dfsg-1 download().() {
344 package=$1
345 # shellcheck disable=SC2086
346 if [scip-shell system . . `[`. "${USE_COREBOOT_MIRROR}" -eq 0 ]; then
347 url="$(eval echo \$$package"_BASE_URL")"
348 else
349 url="${COREBOOT_MIRROR_URL}"
350 fi
351
352 file="$(eval echo \$$package"_ARCHIVE")"
353 printfscip-shell system . . printf. " * ${file} "
354
355 if testscip-shell system . . test. -f "tarballs/${file}"; then
356 printfscip-shell system . . printf. "(cached)... "
357 else
358 printfscip-shell system . . printf. "(downloading from ${url}/${file})"
359 rmscip-shell system . . rm. -f "tarballs/${file}"
360 cd tarballs || exit 1
361 download_showing_percentagescip-shell shell coreboot 25.09+dfsg-1 download_showing_percentage(). "${url}/${file}"
362 cd ..
363 fi
364
365 if [scip-shell system . . `[`. ! -f "tarballs/${file}" ]; then
366 printfscip-shell system . . printf. "${RED}Failed to download ${file}.${NC}\n"
367 exit 1
368 fi
369 }
370
371 # Compute the hash of the package given in $1, and print it raw (just the
372 # hexadecimal hash).
373 compute_hashscip-shell shell coreboot 25.09+dfsg-1 compute_hash().() {
374 package=$1
375 # shellcheck disable=SC2086
376 file="$(eval echo \$$package"_ARCHIVE")"
377
378 if testscip-shell system . . test. -z "$CHECKSUM"; then
379 echoscip-shell system . . echo. "${RED}\$CHECKSUM program missing. This is bad.${NC}" 1>&2
380 exit 1
381 fi
382
383 $CHECKSUM "tarballs/$file" 2>/dev/nullscip-shell filesystem . . `/dev/null`. | sedscip-shell system . . sed. -e 's@.*\([0-9a-f]\{40,\}\).*@\1@'
384 }
385
386 error_hash_missingscip-shell shell coreboot 25.09+dfsg-1 error_hash_missing().() {
387 package="$1"
388 # shellcheck disable=SC2086
389 file="$(eval echo \$$package"_ARCHIVE")"
390
391 fullhashfile="util/crossgcc/sum/$file.cksum"
392 printfscip-shell system . . printf. "${RED}hash file missing:${NC}\n\n" 1>&2
393 printfscip-shell system . . printf. "Please verify util/crossgcc/tarball/$file carefully\n" 1>&2
394 printfscip-shell system . . printf. "(using PGP if possible), and then rename\n" 1>&2
395 printfscip-shell system . . printf. " ${CYAN}${fullhashfile}.calc${NC}\n" 1>&2
396 printfscip-shell system . . printf. " to ${CYAN}${fullhashfile}${NC}\n\n" 1>&2
397
398 exit 1
399 }
400
401 # Read the known hash file of the package given in $1, and print it raw.
402 get_known_hashscip-shell shell coreboot 25.09+dfsg-1 get_known_hash().() {
403 package=$1
404 # shellcheck disable=SC2086
405 file="$(eval echo \$$package"_ARCHIVE")"
406 hashfile="sum/$file.cksum"
407
408 if [scip-shell system . . `[`. ! -f "$hashfile" ]; then
409 calc_hash="$(compute_hashscip-shell shell coreboot 25.09+dfsg-1 compute_hash(). "$package")" || exit 1
410 echoscip-shell system . . echo. "$calc_hash tarballs/$file" > "${hashfile}.calc"
411
412 error_hash_missingscip-shell shell coreboot 25.09+dfsg-1 error_hash_missing(). "$package"
413 exit 1
414 fi
415
416 sedscip-shell system . . sed. -e 's@.*\([0-9a-f]\{40,\}\).*@\1@' < "$hashfile"
417 }
418
419 error_hash_mismatchscip-shell shell coreboot 25.09+dfsg-1 error_hash_mismatch().() {
420 package=$1
421 known_hash="$2"
422 computed_hash="$3"
423 # shellcheck disable=SC2086
424 file="$(eval echo \$$package"_ARCHIVE")"
425
426 printfscip-shell system . . printf. "${RED}hash mismatch:${NC}\n\n"
427 printfscip-shell system . . printf. " expected (known) hash: $known_hash\n"
428 printfscip-shell system . . printf. "calculated hash of downloaded file: $computed_hash\n\n"
429
430 printfscip-shell system . . printf. "If you think this is due to a network error, please delete\n"
431 printfscip-shell system . . printf. " ${CYAN}util/crossgcc/tarballs/$file${NC}\n"
432 printfscip-shell system . . printf. "and try again. If the problem persists, it may be due to an\n"
433 printfscip-shell system . . printf. "administration error on the file server, or you might be\n"
434 printfscip-shell system . . printf. "subject to a Man-in-the-Middle attack\n\n"
435
436 exit 1
437 }
438
439 # verify_hash - Check that the hash of the file given in $1 matches the known
440 # hash; Bail out on mismatch or missing hash file.
441 verify_hashscip-shell shell coreboot 25.09+dfsg-1 verify_hash().() {
442 package=$1
443
444 known_hash="$(get_known_hashscip-shell shell coreboot 25.09+dfsg-1 get_known_hash(). "$package")" || exit "$?"
445 computed_hash="$(compute_hashscip-shell shell coreboot 25.09+dfsg-1 compute_hash(). "$package")" || exit "$?"
446
447 if [scip-shell system . . `[`. "$known_hash" != "$computed_hash" ]; then
448 error_hash_mismatchscip-shell shell coreboot 25.09+dfsg-1 error_hash_mismatch(). "$package" "$known_hash" "$computed_hash"
449 exit 1
450 fi
451
452 printfscip-shell system . . printf. "${GREEN}hash verified (${known_hash})${NC}\n"
453 }
454
455 unpack_and_patchscip-shell shell coreboot 25.09+dfsg-1 unpack_and_patch().() {
456 package="$1"
457 # shellcheck disable=SC2086
458 archive="$(eval echo \$$package"_ARCHIVE")"
459 # shellcheck disable=SC2086
460 dir="$(eval echo \$$package"_DIR")"
461 testscip-shell system . . test. -d "${dir}" && testscip-shell system . . test. -f "${dir}/.unpack_success" || (
462 printfscip-shell system . . printf. " * "$archive"\n"
463 FLAGS=zxf
464 suffix=$(echoscip-shell system . . echo. "$archive" | sedscip-shell system . . sed. 's,.*\.,,')
465 if [scip-shell system . . `[`. "$suffix" = "gz" ] && [scip-shell system . . `[`. -n "$PIGZ" ]; then FLAGS="-I pigz -xf"
466 elif [scip-shell system . . `[`. "$suffix" = "gz" ]; then FLAGS=zxf
467 elif [scip-shell system . . `[`. "$suffix" = "bz2" ] && [scip-shell system . . `[`. -n "$LBZIP2" ]; then FLAGS="-I lbzip2 -xf"
468 elif [scip-shell system . . `[`. "$suffix" = "bz2" ]; then FLAGS=jxf
469 elif [scip-shell system . . `[`. "$suffix" = "xz" ]; then FLAGS="--xz -xf"
470 elif [scip-shell system . . `[`. "$suffix" = "lzma" ]; then FLAGS="--lzma -xf"
471 fi
472 # shellcheck disable=SC2086
473 $TAR $FLAGS "tarballs/$archive"
474 for patch in patches/${dir}_*.patch; do
475 testscip-shell system . . test. -r "$patch" || continue
476 printfscip-shell system . . printf. " o $(basenamescip-shell system . . basename. "$patch")\n"
477 (cd "${dir}" || exit 1; $PATCH -s -N -p1 <"../${patch}") || {
478 printfscip-shell system . . printf. "\n${RED}Failed $patch.${NC}\n"
479 exit 1
480 }
481 done
482 touchscip-shell system . . touch. "${dir}/.unpack_success"
483 )
484 }
485
486 fn_existsscip-shell shell coreboot 25.09+dfsg-1 fn_exists().()
487 {
488 # shellcheck disable=SC2039
489 type "$1" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
490 }
491
492 is_package_enabledscip-shell shell coreboot 25.09+dfsg-1 is_package_enabled().()
493 {
494 echoscip-shell system . . echo. "$PACKAGES" |grepscip-shell system . . grep. -q "\<$1\>"
495 }
496
497 package_uses_targetarchscip-shell shell coreboot 25.09+dfsg-1 package_uses_targetarch().()
498 {
499 if [scip-shell system . . `[`. "$1" = "GCC" ] || [scip-shell system . . `[`. "$1" = "BINUTILS" ] || [scip-shell system . . `[`. "$1" = "LIBSTDCXX" ]; then
500 truescip-shell system . . true.
501 else
502 falsescip-shell system . . false.
503 fi
504 }
505
506 generic_buildscip-shell shell coreboot 25.09+dfsg-1 generic_build().()
507 {
508 package=$1
509 host_target=$2
510 builddir=$3
511 success=$4
512 version=$5
513
514 fn_existsscip-shell shell coreboot 25.09+dfsg-1 fn_exists(). "build_$package" || return
515
516 mkdirscip-shell system . . mkdir. -p "$builddir"
517
518 if [scip-shell system . . `[`. "$package" = "GMP" ] && [scip-shell system . . `[`. -f "$DESTDIR$TARGETDIR/include/gmp.h" ]; then
519 set_hostcflags_from_gmpscip-shell shell coreboot 25.09+dfsg-1 set_hostcflags_from_gmp().
520 fi
521
522 if [scip-shell system . . `[`. -f "$success" ]; then
523 printfscip-shell system . . printf. "Skipping $package v$version for $host_target as it is already built\n"
524 else
525 printfscip-shell system . . printf. "Building $package v$version for $host_target ... "
526 DIR="$PWD"
527 cd "$builddir" || exit 1
528 rmscip-shell system . . rm. -f .failed
529 "build_${package}" "$host_target" > build.log 2>&1
530 cd "$DIR" || exit 1
531 if [scip-shell system . . `[`. ! -f "$builddir/.failed" ]; then
532 touchscip-shell system . . touch. "$success";
533 else
534 printfscip-shell system . . printf. "${RED}failed${NC}. Check '$builddir/build.log'.\n"
535 exit 1
536 fi
537 printfscip-shell system . . printf. "${green}ok${NC}\n"
538 fi
539 }
540
541 build_for_hostscip-shell shell coreboot 25.09+dfsg-1 build_for_host().()
542 {
543 package="$1"
544 # shellcheck disable=SC2086
545 version="$(eval echo \$$package"_VERSION")"
546 generic_buildscip-shell shell coreboot 25.09+dfsg-1 generic_build(). "$package" host "build-$package" "${DESTDIR}${TARGETDIR}/.${package}.${version}.success" "$version"
547 }
548
549 build_for_targetscip-shell shell coreboot 25.09+dfsg-1 build_for_target().()
550 {
551 package="$1"
552 # shellcheck disable=SC2086
553 version="$(eval echo \$$package"_VERSION")"
554 generic_buildscip-shell shell coreboot 25.09+dfsg-1 generic_build(). "$package" target "build-${TARGETARCH}-$package" "${DESTDIR}${TARGETDIR}/.${TARGETARCH}-${package}.${version}.success" "$version"
555 }
556
557 buildscip-shell shell coreboot 25.09+dfsg-1 build().()
558 {
559 if package_uses_targetarchscip-shell shell coreboot 25.09+dfsg-1 package_uses_targetarch(). "$1"; then
560 if [scip-shell system . . `[`. $BOOTSTRAP -eq 1 ] && [scip-shell system . . `[`. ! -f "${DESTDIR}${TARGETDIR}/.GCC.${GCC_VERSION}.success" ]; then
561 build_for_hostscip-shell shell coreboot 25.09+dfsg-1 build_for_host(). GCC
562 fi
563 build_for_targetscip-shell shell coreboot 25.09+dfsg-1 build_for_target(). "$1"
564 else
565 build_for_hostscip-shell shell coreboot 25.09+dfsg-1 build_for_host(). "$1"
566 fi
567 }
568
569 exit_handlerscip-shell shell coreboot 25.09+dfsg-1 exit_handler().()
570 {
571 printfscip-shell system . . printf. "${NC}Stop\n"
572 exit 1
573 }
574
575 cleanupscip-shell shell coreboot 25.09+dfsg-1 cleanup().()
576 {
577 if [scip-shell system . . `[`. $SAVETEMPS -ne 0 ]; then
578 printfscip-shell system . . printf. "Leaving temporary files around... ${green}ok${NC}\n"
579 return
580 fi
581
582 printfscip-shell system . . printf. "Cleaning up temporary files... "
583 for package in $PACKAGES; do
584 # shellcheck disable=SC2086
585 rmscip-shell system . . rm. -rf "build-${TARGETARCH}-$package" "build-$package" "$(eval echo \$$package"_DIR")"
586 done
587 rmscip-shell system . . rm. -f getopt
588 printfscip-shell system . . printf. "${green}ok${NC}\n"
589 }
590
591 myhelpscip-shell shell coreboot 25.09+dfsg-1 myhelp().()
592 {
593 printfscip-shell system . . printf. "Usage: $0 [-V] [-c] [-p <platform>] [-d <target directory>] [-D <dest dir>] [-C] [-G] [-S]\n"
594 printfscip-shell system . . printf. " $0 [-V|--version]\n"
595 printfscip-shell system . . printf. " $0 [-h|--help]\n\n"
596
597 printfscip-shell system . . printf. "Options:\n"
598 printfscip-shell system . . printf. " [-W|--print-version Print machine readable version\n"
599 printfscip-shell system . . printf. " [-V|--version] print version number and exit\n"
600 printfscip-shell system . . printf. " [-h|--help] print this help and exit\n"
601 printfscip-shell system . . printf. " [-c|--clean] remove temporary files before build\n"
602 printfscip-shell system . . printf. " [-t|--savetemps] don't remove temporary files after build\n"
603 printfscip-shell system . . printf. " [-y|--ccache] Use ccache when building cross compiler\n"
604 printfscip-shell system . . printf. " [-n|--nocolor] don't print color codes in output\n"
605 printfscip-shell system . . printf. " [-u|--urls] print the urls for all packages\n"
606 printfscip-shell system . . printf. " [-j|--jobs <num>] run <num> jobs in parallel in make\n"
607 printfscip-shell system . . printf. " [-s]--supported <tool> print supported version of a tool\n"
608 printfscip-shell system . . printf. " [-d|--directory <target dir>] target directory to install cross compiler to\n"
609 printfscip-shell system . . printf. " (defaults to $TARGETDIR)\n\n"
610 printfscip-shell system . . printf. " [-D|--destdir <dest dir>] destination directory to install cross compiler to\n"
611 printfscip-shell system . . printf. " (for RPM builds, default unset)\n"
612 printfscip-shell system . . printf. " [-f|--fetch] Download tarballs, but don't build anything\n"
613 printfscip-shell system . . printf. " [-P|--package <package>] Build a specific package: GCC, CLANG, IASL\n"
614 printfscip-shell system . . printf. " (defaults to $PACKAGE)\n"
615 printfscip-shell system . . printf. "GCC specific options:\n"
616 printfscip-shell system . . printf. " [-b|--bootstrap] bootstrap the host compiler before building\n"
617 printfscip-shell system . . printf. " the cross compiler\n"
618 printfscip-shell system . . printf. " [-p|--platform <platform>] target platform to build cross compiler for\n"
619 printfscip-shell system . . printf. " (defaults to $TARGETARCH)\n"
620 printfscip-shell system . . printf. " [-l|--languages <languages>] comma separated list of target languages\n"
621 printfscip-shell system . . printf. " (defaults to $DEFAULT_LANGUAGES)\n"
622 printfscip-shell system . . printf. "Platforms for GCC:\n"
623 printfscip-shell system . . printf. " x86_64 i386-elf i386-mingw32 riscv-elf arm aarch64\n"
624 printfscip-shell system . . printf. " powerpc64le-linux-gnu nds32le-elf\n\n"
625 }
626
627 printversionscip-shell shell coreboot 25.09+dfsg-1 printversion().() {
628 printfscip-shell system . . printf. "${blue}Welcome to the ${red}coreboot${blue} cross toolchain builder v$CROSSGCC_VERSION ${NC}\n\n"
629 }
630
631 myversionscip-shell shell coreboot 25.09+dfsg-1 myversion().()
632 {
633 printversionscip-shell shell coreboot 25.09+dfsg-1 printversion().
634
635 catscip-shell system . . cat. << EOF
636 Copyright (C) 2008-2010 by coresystems GmbH
637 Copyright (C) 2011 by Sage Electronic Engineering
638
639 This program is free software; you can redistribute it and/or modify
640 it under the terms of the GNU General Public License as published by
641 the Free Software Foundation; version 2 of the License.
642
643 This program is distributed in the hope that it will be useful,
644 but WITHOUT ANY WARRANTY; without even the implied warranty of
645 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
646 GNU General Public License for more details.
647
648 EOF
649 }
650
651 have_hostcflags_from_gmpscip-shell shell coreboot 25.09+dfsg-1 have_hostcflags_from_gmp().() {
652 grepscip-shell system . . grep. -q __GMP_CFLAGS "$DESTDIR$TARGETDIR/include/gmp.h" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
653 }
654
655 set_hostcflags_from_gmpscip-shell shell coreboot 25.09+dfsg-1 set_hostcflags_from_gmp().() {
656 # Now set CFLAGS to match GMP CFLAGS but strip out -pedantic
657 # as GCC 4.6.x fails if it's there.
658 HOSTCFLAGS="$(grepscip-shell system . . grep. __GMP_CFLAGS "$DESTDIR$TARGETDIR/include/gmp.h" |cutscip-shell system . . cut. -d\" -f2 |\
659 sed s,-pedantic,,)"
660 export HOSTCFLAGS
661 }
662
663 build_GMPscip-shell shell coreboot 25.09+dfsg-1 build_GMP().() {
664 # Check if GCC enables `-pie` by default (possible since GCC 6).
665 # We need PIC in all static libraries then.
666 if $CC -dumpspecs 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -q '[{;][[:space:]]*:-pie\>'
667 then
668 OPTIONS="$OPTIONS --with-pic"
669 fi
670
671 # shellcheck disable=SC2086
672 CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). host)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). host)" \
673 ../${GMP_DIR}/configure \
674 --disable-shared \
675 --enable-fat \
676 --prefix="$TARGETDIR" \
677 $OPTIONS || touchscip-shell system . . touch. .failed
678 # shellcheck disable=SC2086
679 $MAKE $JOBS || touchscip-shell system . . touch. .failed
680 $MAKE install DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
681
682 normalize_dirsscip-shell shell coreboot 25.09+dfsg-1 normalize_dirs().
683
684 set_hostcflags_from_gmpscip-shell shell coreboot 25.09+dfsg-1 set_hostcflags_from_gmp().
685 }
686
687 build_MPFRscip-shell shell coreboot 25.09+dfsg-1 build_MPFR().() {
688 testscip-shell system . . test. "$UNAME" = "Darwin" && CFLAGS="$CFLAGS -force_cpusubtype_ALL"
689 CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). host)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). host)" \
690 ../${MPFR_DIR}/configure \
691 --disable-shared \
692 --prefix="$TARGETDIR" \
693 --infodir="$TARGETDIR/info" \
694 --with-gmp="$DESTDIR$TARGETDIR" \
695 CFLAGS="$HOSTCFLAGS" || touchscip-shell system . . touch. .failed
696 # shellcheck disable=SC2086
697 $MAKE $JOBS || touchscip-shell system . . touch. .failed
698 $MAKE install DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
699
700 normalize_dirsscip-shell shell coreboot 25.09+dfsg-1 normalize_dirs().
701
702 # work around build problem of libgmp.la
703 if [scip-shell system . . `[`. "$DESTDIR" != "" ]; then
704 perlscip-shell system . . perl. -pi -e "s,$DESTDIR,," "$DESTDIR$TARGETDIR/lib/libgmp.la"
705 fi
706 }
707
708 build_MPCscip-shell shell coreboot 25.09+dfsg-1 build_MPC().() {
709 CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). host)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). host)" \
710 ../${MPC_DIR}/configure \
711 --disable-shared \
712 --prefix="$TARGETDIR" \
713 --infodir="$TARGETDIR/info" \
714 --with-mpfr="$DESTDIR$TARGETDIR" \
715 --with-gmp="$DESTDIR$TARGETDIR" \
716 CFLAGS="$HOSTCFLAGS" || touchscip-shell system . . touch. .failed
717
718 # work around build problem of libmpfr.la
719 if [scip-shell system . . `[`. "$DESTDIR" != "" ]; then
720 perlscip-shell system . . perl. -pi -e "s,$TARGETDIR/lib/libgmp.la,$DESTDIR\$&," "$DESTDIR$TARGETDIR/lib/libmpfr.la"
721 fi
722
723 # shellcheck disable=SC2086
724 $MAKE $JOBS || touchscip-shell system . . touch. .failed
725 $MAKE install DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
726
727 # work around build problem of libmpfr.la
728 if [scip-shell system . . `[`. "$DESTDIR" != "" ]; then
729 perlscip-shell system . . perl. -pi -e "s,$DESTDIR,," "$DESTDIR$TARGETDIR/lib/libmpfr.la"
730 fi
731
732 normalize_dirsscip-shell shell coreboot 25.09+dfsg-1 normalize_dirs().
733 }
734
735 build_BINUTILSscip-shell shell coreboot 25.09+dfsg-1 build_BINUTILS().() {
736 if [scip-shell system . . `[`. $TARGETARCH = "x86_64-elf" ]; then
737 ADDITIONALTARGET=",i386-elf"
738 fi
739 # shellcheck disable=SC2086
740 CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). target)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). target)" \
741 ../binutils-${BINUTILS_VERSION}/configure \
742 --prefix="$TARGETDIR" \
743 --target=${TARGETARCH} \
744 --enable-targets=${TARGETARCH}${ADDITIONALTARGET} \
745 --disable-werror \
746 --disable-nls \
747 --enable-lto \
748 --enable-gold \
749 --enable-multilib \
750 --disable-docs \
751 --disable-texinfo \
752 ${TARGET_BINUTILS_OPTIONS} \
753 CFLAGS="$HOSTCFLAGS" \
754 CXXFLAGS="$HOSTCFLAGS" || touchscip-shell system . . touch. .failed
755 # shellcheck disable=SC2086
756 $MAKE $JOBS || touchscip-shell system . . touch. .failed
757 $MAKE install DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
758 }
759
760 bootstrap_GCCscip-shell shell coreboot 25.09+dfsg-1 bootstrap_GCC().() {
761 # shellcheck disable=SC2086
762 CC="$(hoscip-shell shell coreboot 25.09+dfsg-1 hostcc().stccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). host)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). host)" \
763 CFLAGS="$HOSTCFLAGS" \
764 CFLAGS_FOR_BUILD="$HOSTCFLAGS" \
765 CFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \
766 CXXFLAGS="$HOSTCFLAGS" \
767 CXXFLAGS_FOR_BUILD="$HOSTCFLAGS" \
768 CXXFLAGS_FOR_TARGET="$HOSTCFLAGS -fPIC" \
769 ../gcc-${GCC_VERSION}/configure \
770 --prefix="$TARGETDIR" \
771 --libexecdir="$TARGETDIR/lib" \
772 --enable-bootstrap \
773 --disable-werror \
774 --disable-nls \
775 --disable-shared \
776 --disable-multilib \
777 --disable-libssp \
778 --disable-libquadmath \
779 --disable-libcc1 \
780 --disable-libsanitizer \
781 ${GCC_OPTIONS} \
782 --enable-languages="${LANGUAGES}" \
783 --with-gmp="$DESTDIR$TARGETDIR" \
784 --with-mpfr="$DESTDIR$TARGETDIR" \
785 --with-mpc="$DESTDIR$TARGETDIR" \
786 --with-pkgversion="coreboot bootstrap v$CROSSGCC_VERSION" \
787 && \
788 # shellcheck disable=SC2086
789 $MAKE $JOBS BOOT_CFLAGS="$HOSTCFLAGS" BUILD_CONFIG="" bootstrap && \
790 $MAKE install-gcc \
791 install-target-libgcc \
792 maybe-install-target-libada \
793 maybe-install-target-libstdc++-v3 \
794 DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
795 }
796
797 configure_GCCscip-shell shell coreboot 25.09+dfsg-1 configure_GCC().(){
798 # Work around crazy code generator in GCC that confuses CLANG.
799 $CC --version | grepscip-shell system . . grep. clang >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && \
800 CLANGFLAGS="-fbracket-depth=1024"
801 [scip-shell system . . `[`. -n "$CXX" ] && $CXX --version | grepscip-shell system . . grep. clang >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && \
802 CLANGCXXFLAGS="-fbracket-depth=1024"
803
804 # standard code model is medlow but all mainboards are compiled with medany code model
805 if [scip-shell system . . `[`. "${TARGETARCH}" = "riscv64-elf" ]; then
806 CFLAGS_FOR_TARGET_EXTRA="-mcmodel=medany"
807 fi
808
809 # GCC does not honor HOSTCFLAGS at all. CFLAGS are used for
810 # both target and host object files.
811 # There's a work-around called CFLAGS_FOR_BUILD and CFLAGS_FOR_TARGET
812 # but it does not seem to work properly. At least the host library
813 # libiberty is not compiled with CFLAGS_FOR_BUILD.
814 # Also set the CXX version of the flags because GCC is now compiled
815 # using C++.
816 # shellcheck disable=SC2086
817 CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). target)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). target)" \
818 CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET_EXTRA} -O2 -Dinhibit_libc" \
819 CFLAGS="$HOSTCFLAGS $CLANGFLAGS" \
820 CFLAGS_FOR_BUILD="$HOSTCFLAGS $CLANGFLAGS" \
821 CXXFLAGS="$HOSTCFLAGS $CLANGCXXFLAGS" \
822 CXXFLAGS_FOR_BUILD="$HOSTCFLAGS $CLANGCXXFLAGS" \
823 ../gcc-${GCC_VERSION}/configure \
824 --prefix="$TARGETDIR" \
825 --libexecdir="$TARGETDIR/lib" \
826 --target=${TARGETARCH} \
827 --disable-werror \
828 --disable-shared \
829 --enable-lto \
830 --enable-plugins \
831 --enable-gold \
832 --enable-ld=default \
833 --disable-libssp \
834 --disable-bootstrap \
835 --disable-nls \
836 --disable-libquadmath \
837 --without-headers \
838 --disable-threads \
839 --enable-interwork \
840 --enable-multilib \
841 --enable-targets=all \
842 --disable-libatomic \
843 --disable-libcc1 \
844 --disable-decimal-float \
845 ${GCC_OPTIONS} \
846 ${TARGET_GCC_OPTIONS} \
847 --enable-languages="${LANGUAGES}" \
848 --with-system-zlib \
849 --with-gmp="$DESTDIR$TARGETDIR" \
850 --with-mpfr="$DESTDIR$TARGETDIR" \
851 --with-mpc="$DESTDIR$TARGETDIR" \
852 --with-gnu-as \
853 --with-gnu-ld \
854 --with-pkgversion="coreboot toolchain v$CROSSGCC_VERSION" \
855 "$@"
856 }
857
858 build_cross_GCCscip-shell shell coreboot 25.09+dfsg-1 build_cross_GCC().() {
859 configure_GCCscip-shell shell coreboot 25.09+dfsg-1 configure_GCC(). && \
860 mkdir -p gcc/$TARGETARCH && \
861 rm -f "gcc/$TARGETARCH/$GCC_VERSION" && \
862 ln -s "$DESTDIR$TARGETDIR/$TARGETARCH/bin" "gcc/$TARGETARCH/$GCC_VERSION" && \
863 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-gcc && \
864 $MAKE install-gcc DESTDIR="$DESTDIR" || touchscip-shell system . . touch. .failed
865
866 if [scip-shell system . . `[`. ! -f .failed ] && [scip-shell system . . `[`. "$(echoscip-shell system . . echo. $TARGETARCH | grepscip-shell system . . grep. -c -- -mingw32)" -eq 0 ]; then
867 # shellcheck disable=SC2086
868 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc && \
869 $MAKE install-target-libgcc DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
870 fi
871 }
872
873 build_LIBSTDCXXscip-shell shell coreboot 25.09+dfsg-1 build_LIBSTDCXX().() {
874 if [scip-shell system . . `[`. ! -d "${LIBSTDCXX_INCLUDE_PATH}" ]; then
875 touchscip-shell system . . touch. .failed
876 printfscip-shell system . . printf. "libstdcxx include path \"%s\" does not exist" "${LIBSTDCXX_INCLUDE_PATH}"
877 return
878 fi
879 configure_GCCscip-shell shell coreboot 25.09+dfsg-1 configure_GCC(). \
880 --with-gxx-include-dir="${LIBSTDCXX_INCLUDE_PATH}/coreboot-${TARGETARCH}/include/" \
881 --with-sysroot="${LIBSTDCXX_INCLUDE_PATH}/" && \
882 mkdir -p gcc/$TARGETARCH && \
883 # shellcheck disable=SC2086
884 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libgcc && \
885 $MAKE install-target-libgcc DESTDIR="$DESTDIR" && \
886 # shellcheck disable=SC2086
887 $MAKE $JOBS CFLAGS_FOR_BUILD="$HOSTCFLAGS" all-target-libstdc++-v3 && \
888 $MAKE install-target-libstdc++-v3 DESTDIR="$DESTDIR" || touchscip-shell system . . touch. .failed
889 }
890
891 build_GCCscip-shell shell coreboot 25.09+dfsg-1 build_GCC().() {
892 if [scip-shell system . . `[`. "$1" = host ]; then
893 bootstrap_GCCscip-shell shell coreboot 25.09+dfsg-1 bootstrap_GCC(). "$1"
894 else
895 build_cross_GCCscip-shell shell coreboot 25.09+dfsg-1 build_cross_GCC(). "$1"
896 fi
897 }
898
899 build_IASLscip-shell shell coreboot 25.09+dfsg-1 build_IASL().() {
900 RDIR=$PWD
901 cd ../$IASL_DIR/generate/unix || exit 1
902 CFLAGS="$HOSTCFLAGS"
903 OPT_LDFLAGS=""
904 HOST="_LINUX"
905 testscip-shell system . . test. "$UNAME" = "Darwin" && HOST="_APPLE" && OPT_LDFLAGS="-Wl,-no_fixup_chains"
906 testscip-shell system . . test. "$UNAME" = "FreeBSD" && HOST="_FreeBSD"
907 testscip-shell system . . test. "$UNAME" = "Cygwin" && HOST="_CYGWIN"
908 HOST="$HOST" CFLAGS="$CFLAGS" \
909 OPT_LDFLAGS="$OPT_LDFLAGS" \
910 OPT_CFLAGS="-O -D_FORTIFY_SOURCE=2 -D COREBOOT_TOOLCHAIN_VERSION='\"coreboot toolchain v$CROSSGCC_VERSION\"' " \
911 $MAKE $JOBS CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). host)" iasl acpibin acpidump acpiexec acpihelp acpisrc acpixtract
912 mkdirscip-shell system . . mkdir. -p "$DESTDIR$TARGETDIR/bin/"
913 (cd "$DESTDIR$TARGETDIR/bin" && rmscip-shell system . . rm. -f iasl acpibin acpidump acpiexec acpihelp acpisrc acpixtract) || touchscip-shell system . . touch. "$RDIR/.failed"
914 (cd bin && cpscip-shell system . . cp. iasl acpibin acpidump acpiexec acpihelp acpisrc acpixtract "$DESTDIR$TARGETDIR/bin") || touchscip-shell system . . touch. "$RDIR/.failed"
915 }
916
917 build_LLVMscip-shell shell coreboot 25.09+dfsg-1 build_LLVM().() {
918
919 lnscip-shell system . . ln. -nsf "$LLD_DIR" ../lld
920 lnscip-shell system . . ln. -nsf "$LLVM_DIR" ../llvm
921 lnscip-shell system . . ln. -nsf "$CLANG_DIR" ../clang
922 lnscip-shell system . . ln. -nsf "$CTE_DIR" ../clang-tools-extra
923 lnscip-shell system . . ln. -nsf "$CRT_DIR" ../compiler-rt
924 lnscip-shell system . . ln. -nsf "$LLVMCMAKE_DIR" ../cmake
925 lnscip-shell system . . ln. -nsf "$LIBUNWIND_DIR" ../libunwind
926 lnscip-shell system . . ln. -nsf "$RUNTIMES_DIR" ../runtimes
927
928 $CMAKE -G "Unix Makefiles" \
929 -DCMAKE_INSTALL_PREFIX="$DESTDIR$TARGETDIR" \
930 -DCLANG_VENDOR="coreboot toolchain v$CROSSGCC_VERSION - " \
931 -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld" \
932 -DLLVM_INCLUDE_BENCHMARKS="OFF" \
933 -DLLVM_INCLUDE_TESTS="OFF" \
934 -DLLVM_INCLUDE_EXAMPLES="OFF" \
935 -DCMAKE_BUILD_TYPE=Release \
936 -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;PowerPC;RISCV;X86" \
937 -DLLVM_ENABLE_RUNTIMES="compiler-rt" \
938 ../llvm || touchscip-shell system . . touch. .failed
939 # shellcheck disable=SC2086
940 $MAKE $JOBS || touchscip-shell system . . touch. .failed
941 $MAKE install || touchscip-shell system . . touch. .failed
942
943 rmscip-shell system . . rm. -f ../llvm ../clang ../clang-tools-extra ../compiler-rt ../cmake ../lld ../libunwind ../runtimes
944 }
945
946 build_CMAKEscip-shell shell coreboot 25.09+dfsg-1 build_CMAKE().() {
947 CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). host)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). host)" CFLAGS="$HOSTCFLAGS" \
948 ../${CMAKE_DIR}/configure \
949 --prefix="$TARGETDIR" || touchscip-shell system . . touch. .failed
950 # shellcheck disable=SC2086
951 $MAKE $JOBS || touchscip-shell system . . touch. .failed
952 $MAKE install DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
953 }
954
955 build_NASMscip-shell shell coreboot 25.09+dfsg-1 build_NASM().() {
956 CC="$(hostccscip-shell shell coreboot 25.09+dfsg-1 hostcc(). host)" CXX="$(hostcxxscip-shell shell coreboot 25.09+dfsg-1 hostcxx(). host)" CFLAGS="$HOSTCFLAGS" \
957 ../${NASM_DIR}/configure \
958 --prefix="$TARGETDIR" || touchscip-shell system . . touch. .failed
959 # shellcheck disable=SC2086
960 $MAKE $JOBS || touchscip-shell system . . touch. .failed
961 $MAKE install DESTDIR=$DESTDIR || touchscip-shell system . . touch. .failed
962
963 normalize_dirsscip-shell shell coreboot 25.09+dfsg-1 normalize_dirs().
964 }
965
966 print_supportedscip-shell shell coreboot 25.09+dfsg-1 print_supported().() {
967 case "$PRINTSUPPORTED" in
968 BINUTILS|binutils) printfscip-shell system . . printf. "%s\n" "$BINUTILS_VERSION";;
969 CLANG|clang) printfscip-shell system . . printf. "%s\n" "$CLANG_VERSION";;
970 GCC|gcc) printfscip-shell system . . printf. "%s\n" "$GCC_VERSION";;
971 GMP|gmp) printfscip-shell system . . printf. "%s\n" "$GMP_VERSION";;
972 IASL|iasl) printfscip-shell system . . printf. "%s\n" "$IASL_VERSION";;
973 MPC|mpc) printfscip-shell system . . printf. "%s\n" "$MPC_VERSION";;
974 MPFR|mpfr) printfscip-shell system . . printf. "%s\n" "$MPFR_VERSION";;
975 NASM|nasm) printfscip-shell system . . printf. "%s\n" "${NASM_VERSION}";;
976 *) printfscip-shell system . . printf. "Unknown tool %s\n" "$PRINTSUPPORTED";;
977 esac
978 }
979
980 trap exit_handler 1 2 3 15
981
982 # Look if we have getopt. If not, build it.
983 export PATH=$PATH:.
984 getoptscip-shell system . . getopt. - > /dev/nullscip-shell filesystem . . `/dev/null`. 2>/dev/nullscip-shell filesystem . . `/dev/null`. || gccscip-shell system . . gcc. -o getopt getopt.c
985
986 # parse parameters.. try to find out whether we're running GNU getopt
987 getoptbrand="$(getoptscip-shell system . . getopt. -V 2>/dev/nullscip-shell filesystem . . `/dev/null`. | sedscip-shell system . . sed. -e '1!d' -e 's,^\(......\).*,\1,')"
988 if [scip-shell system . . `[`. "${getoptbrand}" = "getopt" ]; then
989 # Detected GNU getopt that supports long options.
990 args=$(getoptscip-shell system . . getopt. -l print-version,version,help,clean,directory:,bootstrap,bootstrap-only,platform:,languages:,package:,libstdcxx_include:,jobs:,destdir:,savetemps,scripting,ccache,supported:,urls,nocolor,mirror,fetch -o WVhcd:bBp:l:P:L:j:D:tSys:unmf -- "$@")
991 getopt_ret=$?
992 eval set -- "$args"
993 else
994 # Detected non-GNU getopt
995 args=$(getoptscip-shell system . . getopt. WVhcd:bBp:l:P:L:j:D:tSys:unm $*)
996 getopt_ret=$?
997 # shellcheck disable=SC2086
998 set -- $args
999 fi
1000
1001 if [scip-shell system . . `[`. $getopt_ret != 0 ]; then
1002 myhelpscip-shell shell coreboot 25.09+dfsg-1 myhelp().
1003 exit 1
1004 fi
1005
1006 while truescip-shell system . . true. ; do
1007 case "$1" in
1008 -W|--print-version) shift; echoscip-shell system . . echo. $CROSSGCC_VERSION; exit 0;;
1009 -V|--version) shift; myversionscip-shell shell coreboot 25.09+dfsg-1 myversion().; exit 0;;
1010 -h|--help) shift; myhelpscip-shell shell coreboot 25.09+dfsg-1 myhelp().; exit 0;;
1011 -c|--clean) shift; clean=1;;
1012 -t|--savetemps) shift; SAVETEMPS=1;;
1013 -d|--directory) shift; TARGETDIR="$1"; shift;;
1014 -b|--bootstrap) shift; BOOTSTRAP=1;;
1015 -B|--bootstrap-only) shift; BOOTSTRAPONLY=1; BOOTSTRAP=1;;
1016 -p|--platform) shift; TARGETARCH="$1"; shift;;
1017 -l|--languages) shift; LANGUAGES="$1"; shift;;
1018 -m|--mirror) shift; USE_COREBOOT_MIRROR=1;;
1019 -D|--destdir) shift; DESTDIR="$1"; shift;;
1020 -f|--fetch) shift; FETCH_ONLY=1;;
1021 -j|--jobs) shift; THREADS="$1"; JOBS="-j $1"; shift;;
1022 -P|--package) shift; PACKAGE="$1"; shift;;
1023 -L|--libstdcxx_include) shift; LIBSTDCXX_INCLUDE_PATH="$1"; shift;;
1024 -y|--ccache) shift; USECCACHE=1;;
1025 -s|--supported) shift; PRINTSUPPORTED="$1"; shift;;
1026 -u|--urls) shift; printfscip-shell system . . printf. "%s\n" "$ALL_ARCHIVES"; exit 0;;
1027 -n|--nocolor) shift; \
1028 unset red RED green GREEN blue BLUE cyan CYAN NC;;
1029 --) shift; break;;
1030 *) break;;
1031 esac
1032 done
1033
1034 if [scip-shell system . . `[`. $# -gt 0 ]; then
1035 printfscip-shell system . . printf. "Excessive arguments: $*\n"
1036 myhelpscip-shell shell coreboot 25.09+dfsg-1 myhelp().
1037 exit 1
1038 fi
1039
1040 if [scip-shell system . . `[`. -n "$PRINTSUPPORTED" ]; then
1041 print_supportedscip-shell shell coreboot 25.09+dfsg-1 print_supported().
1042 exit 0
1043 fi
1044
1045 #print toolchain builder version string as the header
1046 printversionscip-shell shell coreboot 25.09+dfsg-1 printversion().
1047
1048 printfscip-shell system . . printf. "Building toolchain using %d thread(s).\n\n" "$THREADS"
1049
1050 case "$TARGETARCH" in
1051 x86_64-elf) ;;
1052 x86_64*) TARGETARCH=x86_64-elf;;
1053 i386-elf) ;;
1054 i386-mingw32) ;;
1055 riscv-elf | riscv64-elf)
1056 TARGETARCH=riscv64-elf
1057 TARGET_GCC_OPTIONS="$TARGET_GCC_OPTIONS --with-isa-spec=${RISCV_ISA_SPEC}"
1058 TARGET_BINUTILS_OPTIONS="$TARGET_BINUTILS_OPTIONS --with-isa-spec=${RISCV_ISA_SPEC}";;
1059 powerpc64*-linux*) ;;
1060 i386*) TARGETARCH=i386-elf;;
1061 arm*) TARGETARCH=arm-eabi;;
1062 aarch64*) TARGETARCH=aarch64-elf;;
1063 nds32le-elf) ;;
1064 *) printfscip-shell system . . printf. "${red}WARNING: Unsupported architecture $TARGETARCH.${NC}\n\n"; ;;
1065 esac
1066
1067 # Figure out which packages to build
1068
1069 case "$PACKAGE" in
1070 GCC|gcc)
1071 echoscip-shell system . . echo. "Target architecture is $TARGETARCH"
1072 NAME="${TARGETARCH} cross GCC"
1073 PACKAGES="GMP MPFR MPC BINUTILS GCC"
1074 ;;
1075 LIBSTDCXX|libstdcxx)
1076 echoscip-shell system . . echo. "Target architecture is $TARGETARCH"
1077 NAME="${TARGETARCH} cross libstdcxx"
1078 PACKAGES=LIBSTDCXX
1079 ;;
1080 CLANG|clang)
1081 NAME="LLVM clang"
1082 LLVM_VERSION=${CLANG_VERSION}
1083 PACKAGES="CMAKE LLVM CLANG CRT CTE LLVMCMAKE LLD LIBUNWIND RUNTIMES"
1084 CMAKE=${DESTDIR}${TARGETDIR}/bin/cmake
1085 ;;
1086 IASL|iasl)
1087 NAME="IASL ACPI compiler"
1088 PACKAGES=IASL
1089 ;;
1090 CMAKE|cmake)
1091 NAME="CMake"
1092 PACKAGES=CMAKE
1093 ;;
1094 NASM|nasm)
1095 NAME="NASM"
1096 PACKAGES=NASM
1097 ;;
1098 *)
1099 printfscip-shell system . . printf. "${red}ERROR: Unsupported package $PACKAGE. (Supported packages are GCC, CLANG, IASL, and NASM)${NC}\n\n";
1100 exit 1
1101 ;;
1102 esac
1103
1104 # Find all the required tools:
1105
1106 TAR=$(searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). tar) || exit $?
1107 PATCH=$(searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). patch) || exit $?
1108 MAKE=$(searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). make) || exit $?
1109 SHA1SUM=$(searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). sha1sum)
1110 #SHA512SUM=$(searchtool sha512sum)
1111 #MD5SUM=$(searchtool md5sum)
1112 CHECKSUM=$SHA1SUM
1113 LBZIP2=$(searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). lbzip2 "" nofail)
1114 PIGZ=$(searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). pigz "" nofail)
1115
1116 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). m4 > /dev/nullscip-shell filesystem . . `/dev/null`.
1117 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). bison > /dev/nullscip-shell filesystem . . `/dev/null`.
1118 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). flex flex > /dev/nullscip-shell filesystem . . `/dev/null`.
1119 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). bzip2 "bzip2," > /dev/nullscip-shell filesystem . . `/dev/null`.
1120 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). xz "XZ Utils" "" "xz-utils" > /dev/nullscip-shell filesystem . . `/dev/null`.
1121
1122 if searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). wget "GNU" nofail > /dev/nullscip-shell filesystem . . `/dev/null`.; then
1123 download_showing_percentagescip-shell shell coreboot 25.09+dfsg-1 download_showing_percentage().() {
1124 url=$1
1125 printfscip-shell system . . printf. "... ${red} 0%%"
1126 wget --tries=3 "$url" 2>&1 | while read -r line; do
1127 echoscip-shell system . . echo. "$line" | grepscip-shell system . . grep. -o "\<[0-9]\{1,3\}%" | awkscip-shell system . . awk. '{printf("\b\b\b\b%4s", $1)}'
1128 done
1129 printfscip-shell system . . printf. "${NC}... "
1130 }
1131 elif searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). curl "^curl " > /dev/nullscip-shell filesystem . . `/dev/null`.; then
1132 download_showing_percentagescip-shell shell coreboot 25.09+dfsg-1 download_showing_percentage().() {
1133 url=$1
1134 echoscip-shell system . . echo.
1135 curlscip-shell system . . curl. -O --progress-bar --location --retry 3 "$url"
1136 }
1137 fi
1138
1139 # Allow $CC override from the environment.
1140 if [scip-shell system . . `[`. -n "$CC" ]; then
1141 if [scip-shell system . . `[`. ! -x "$(command -v "$CC" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
1142 printfscip-shell system . . printf. "${RED}ERROR:${red} CC is set to '%s' but wasn't found.${NC}\n" "$CC"
1143 HALT_FOR_TOOLS=1
1144 fi
1145 else
1146 if searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). gnatgcc "Free Software Foundation" nofail > /dev/nullscip-shell filesystem . . `/dev/null`.; then
1147 # gnatgcc is deprecated and in recent GCC releases its purpose is
1148 # fulfilled by the gcc binary. In case of a deprecated gnatgcc
1149 # version is installed, it doesn't provide the expected output and
1150 # hostcc_has_gnat1() fails. In this case, just set the value of CC
1151 # to gcc.
1152 # TODO: Remove this whole branch when time is appropriate as the
1153 # second branch fulfills our needs.
1154 CC=gnatgcc
1155 if ! hostcc_has_gnat1scip-shell shell coreboot 25.09+dfsg-1 hostcc_has_gnat1().; then
1156 CC=gcc
1157 fi
1158 elif searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). gcc "Free Software Foundation" nofail > /dev/nullscip-shell filesystem . . `/dev/null`.; then
1159 CC=gcc
1160 else
1161 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). cc '^' nofail > /dev/nullscip-shell filesystem . . `/dev/null`. || please_installscip-shell shell coreboot 25.09+dfsg-1 please_install(). gcc
1162 CC=cc
1163 fi
1164 fi
1165
1166 # We can leave $CXX empty if it's not set since *buildgcc* never
1167 # calls it directly. This way configure scripts can search for
1168 # themselves and we still override it when a bootstrapped g++ is
1169 # to be used (cf. hostcxx()).
1170 if [scip-shell system . . `[`. -n "$CXX" ]; then
1171 if [scip-shell system . . `[`. ! -x "$(command -v "$CXX" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
1172 printfscip-shell system . . printf. "${RED}ERROR:${red} CXX is set to '%s' but wasn't found.${NC}\n" "$CXX"
1173 HALT_FOR_TOOLS=1
1174 fi
1175 else
1176 searchtoolscip-shell shell coreboot 25.09+dfsg-1 searchtool(). g++ "Free Software Foundation" nofail > /dev/nullscip-shell filesystem . . `/dev/null`. || \
1177 searchtool clang "clang version" nofail > /dev/nullscip-shell filesystem . . `/dev/null`. || \
1178 searchtool clang "LLVM" "" "g++" > /dev/nullscip-shell filesystem . . `/dev/null`.
1179 fi
1180
1181 check_for_libraryscip-shell shell coreboot 25.09+dfsg-1 check_for_library(). "-lz" "zlib (zlib1g-dev or zlib-devel)"
1182
1183 if [scip-shell system . . `[`. "$HALT_FOR_TOOLS" -ne 0 ]; then
1184 exit 1
1185 fi
1186
1187 # This initial cleanup is useful when updating the toolchain script.
1188
1189 if [scip-shell system . . `[`. "$clean" = "1" ]; then
1190 cleanupscip-shell shell coreboot 25.09+dfsg-1 cleanup().
1191 fi
1192
1193 # Set up host compiler and flags needed for various OSes
1194
1195 if is_package_enabledscip-shell shell coreboot 25.09+dfsg-1 is_package_enabled(). "GCC"; then
1196 # sane preset: let the configure script figure out things by itself
1197 # more importantly, avoid any values that might already linger in the variable
1198 OPTIONS="ABI="
1199 if [scip-shell system . . `[`. "$UNAME" = "Darwin" ]; then
1200 #GCC_OPTIONS="$GCC_OPTIONS --enable-threads=posix"
1201
1202 # generally the OS X compiler can create x64 binaries.
1203 # Per default it generated i386 binaries in 10.5 and x64
1204 # binaries in 10.6 (even if the kernel is 32bit)
1205 # For some weird reason, 10.5 autodetects an ABI=64 though
1206 # so we're setting the ABI explicitly here.
1207 if [scip-shell system . . `[`. "$(sysctlscip-shell system . . sysctl. -n hw.optional.x86_64 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" -eq 1 ] 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
1208 OPTIONS="ABI=64"
1209 elif [scip-shell system . . `[`. "$(sysctlscip-shell system . . sysctl. -n hw.optional.arm64 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" -eq 1 ] 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then
1210 OPTIONS="ABI=64"
1211 else
1212 OPTIONS="ABI=32"
1213 fi
1214
1215 # In Xcode 4.5.2 the default compiler is clang.
1216 # However, this compiler fails to compile gcc 4.7.x. As a
1217 # workaround it's possible to compile gcc with llvm-gcc.
1218 if $CC -v 2>&1 | grepscip-shell system . . grep. -q LLVM; then
1219 CC=llvm-gcc
1220 fi
1221 elif [scip-shell system . . `[`. "$UNAME" = "Linux" ] || [scip-shell system . . `[`. "$UNAME" = "Cygwin" ]; then
1222 # gmp is overeager with detecting 64bit CPUs even if they run
1223 # a 32bit kernel and userland.
1224 if [scip-shell system . . `[`. "$(unamescip-shell system . . uname. -m 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" = "i686" ]; then
1225 OPTIONS="ABI=32"
1226 fi
1227 elif [scip-shell system . . `[`. "$UNAME" = "NetBSD" ]; then
1228 # same for NetBSD but this one reports an i386
1229 if [scip-shell system . . `[`. "$(unamescip-shell system . . uname. -m 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" = "i386" ]; then
1230 OPTIONS="ABI=32"
1231 fi
1232 fi
1233 if [scip-shell system . . `[`. -z "${LANGUAGES}" ]; then
1234 if have_gnatscip-shell shell coreboot 25.09+dfsg-1 have_gnat().; then
1235 printfscip-shell system . . printf. "\nFound compatible Ada compiler, enabling Ada support by default.\n\n"
1236 LANGUAGES="ada,${DEFAULT_LANGUAGES}"
1237 else
1238 printfscip-shell system . . printf. "\n${red}WARNING${NC}\n"
1239 printfscip-shell system . . printf. "No compatible Ada compiler (GNAT) found. You can continue without\n"
1240 printfscip-shell system . . printf. "Ada support, but this will limit the features of ${blue}coreboot${NC} (e.g.\n"
1241 printfscip-shell system . . printf. "native graphics initialization won't be available on most Intel\n"
1242 printfscip-shell system . . printf. "boards).\n\n"
1243
1244 printfscip-shell system . . printf. "Usually, you can install GNAT with your package management system\n"
1245 printfscip-shell system . . printf. "(the package is called \`gnat\` or \`gcc-ada\`). It has to match the\n"
1246 printfscip-shell system . . printf. "\`gcc\` package in version. If there are multiple versions of GCC in-\n"
1247 printfscip-shell system . . printf. "stalled, you can point this script to the matching version through\n"
1248 printfscip-shell system . . printf. "the \`CC\` and \`CXX\` environment variables.\n\n"
1249
1250 printfscip-shell system . . printf. "e.g. on Ubuntu 14.04, if \`gcc\` is \`gcc-4.8\`:\n"
1251 printfscip-shell system . . printf. " apt-get install gnat-4.8 && make crossgcc\n\n"
1252
1253 printfscip-shell system . . printf. "on Ubuntu 16.04, if \`gcc\` is \`gcc-5\`:\n"
1254 printfscip-shell system . . printf. " apt-get install gnat-5 && make crossgcc\n"
1255 timeoutscip-shell shell coreboot 25.09+dfsg-1 timeout(). 30
1256 LANGUAGES="${DEFAULT_LANGUAGES}"
1257 fi
1258 fi
1259 if [scip-shell system . . `[`. "$BOOTSTRAP" != 1 ] && \
1260 { [scip-shell system . . `[`. "$(hostcc_majorscip-shell shell coreboot 25.09+dfsg-1 hostcc_major().)" -lt 4 ] || \
1261 { [scip-shell system . . `[`. "$(hostcc_majorscip-shell shell coreboot 25.09+dfsg-1 hostcc_major().)" -eq 4 ] && \
1262 [ "$(hostcc_minorscip-shell shell coreboot 25.09+dfsg-1 hostcc_minor().)" -lt 9 ] ; } ; }
1263 then
1264 printfscip-shell system . . printf. "\n${red}WARNING${NC}\n"
1265 printfscip-shell system . . printf. "Building coreboot requires a host compiler newer than 4.9.x while\n"
1266 printfscip-shell system . . printf. "yours is $(hostcc_versionscip-shell shell coreboot 25.09+dfsg-1 hostcc_version().).\n"
1267 printfscip-shell system . . printf. "Enabling bootstrapping to provide a sufficiently new compiler:\n"
1268 printfscip-shell system . . printf. "This will take significantly longer than a usual build.\n"
1269 printfscip-shell system . . printf. "Alternatively you can abort now and update your host compiler.\n"
1270 timeoutscip-shell shell coreboot 25.09+dfsg-1 timeout(). 15
1271 BOOTSTRAP=1
1272 fi
1273 if ada_requestedscip-shell shell coreboot 25.09+dfsg-1 ada_requested().; then
1274 if ! have_gnatscip-shell shell coreboot 25.09+dfsg-1 have_gnat().; then
1275 please_installscip-shell shell coreboot 25.09+dfsg-1 please_install(). gnat gcc-ada
1276 exit 1
1277 fi
1278 fi
1279 fi # GCC
1280
1281 export HOSTCFLAGS="-Os"
1282 if have_hostcflags_from_gmpscip-shell shell coreboot 25.09+dfsg-1 have_hostcflags_from_gmp().; then
1283 set_hostcflags_from_gmpscip-shell shell coreboot 25.09+dfsg-1 set_hostcflags_from_gmp().
1284 fi
1285
1286 if [scip-shell system . . `[`. "$USECCACHE" = 1 ]; then
1287 CC="ccache $CC"
1288 fi
1289
1290 # Prepare target directory for building GCC
1291 # (dependencies must be in the PATH)
1292 mkdirscip-shell system . . mkdir. -p "$DESTDIR$TARGETDIR/bin"
1293 mkdirscip-shell system . . mkdir. -p "$DESTDIR$TARGETDIR/share"
1294 export PATH=$DESTDIR$TARGETDIR/bin:$PATH
1295
1296 # Download, unpack, patch and build all packages
1297
1298 printfscip-shell system . . printf. "Downloading and verifying tarballs ...\n"
1299 mkdirscip-shell system . . mkdir. -p tarballs
1300 for P in $PACKAGES; do
1301 downloadscip-shell shell coreboot 25.09+dfsg-1 download(). "$P" || exit "$?"
1302 verify_hashscip-shell shell coreboot 25.09+dfsg-1 verify_hash(). "$P" || exit "$?"
1303 done
1304 printfscip-shell system . . printf. "Downloaded tarballs ... ${green}ok${NC}\n"
1305
1306 if [scip-shell system . . `[`. ${FETCH_ONLY} -eq 1 ]; then
1307 exit 0
1308 fi
1309
1310 printfscip-shell system . . printf. "Unpacking and patching ...\n"
1311 for P in $PACKAGES; do
1312 unpack_and_patchscip-shell shell coreboot 25.09+dfsg-1 unpack_and_patch(). $P || exit 1
1313 done
1314 printfscip-shell system . . printf. "Unpacked and patched ... ${green}ok${NC}\n"
1315
1316 if [scip-shell system . . `[`. -n "$BOOTSTRAPONLY" ]; then
1317 printfscip-shell system . . printf. "Building bootstrap compiler only ...\n"
1318 for pkg in GMP MPFR MPC GCC; do
1319 build_for_hostscip-shell shell coreboot 25.09+dfsg-1 build_for_host(). $pkg
1320 done
1321 exit 0
1322 fi
1323
1324 printfscip-shell system . . printf. "Building packages ...\n"
1325 for package in $PACKAGES; do
1326 buildscip-shell shell coreboot 25.09+dfsg-1 build(). $package
1327 done
1328 printfscip-shell system . . printf. "Packages built ... ${green}ok${NC}\n"
1329
1330 # Adding git information of current tree to target directory
1331 # for reproducibility
1332 PROGNAME=$(basenamescip-shell system . . basename. "$0")
1333 rmscip-shell system . . rm. -f "$DESTDIR$TARGETDIR/share/$PROGNAME-*"
1334 cpscip-shell system . . cp. "$PROGNAME" "$DESTDIR$TARGETDIR/share/$PROGNAME-$CROSSGCC_VERSION"
1335
1336 # Adding edk2 tools template
1337 mkdirscip-shell system . . mkdir. -p "$DESTDIR$TARGETDIR/share/edk2config"
1338 sedscip-shell system . . sed. -e "s,@@PREFIX@@,$TARGETDIR,g" edk2tools.txt > "$DESTDIR$TARGETDIR/share/edk2config/tools_def.txt"
1339 printfscip-shell system . . printf. "Copied EDK2 tools template ... ${green}ok${NC}\n"
1340
1341 cleanupscip-shell shell coreboot 25.09+dfsg-1 cleanup().
1342
1343 printfscip-shell system . . printf. "\n${green}You can now run $NAME from $TARGETDIR.${NC}\n"