source: mainline/tools/toolchain.sh@ a9aafa1d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a9aafa1d was a9aafa1d, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

tools/toolchain.sh: Unbreak mips32eb

  • Property mode set to 100755
File size: 14.2 KB
Line 
1#! /bin/bash
2
3#
4# Copyright (c) 2009 Martin Decky
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10#
11# - Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# - Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# - The name of the author may not be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30
31BINUTILS_GDB_GIT="https://github.com/HelenOS/binutils-gdb.git"
32
33BINUTILS_BRANCH="binutils-2_31_1-helenos"
34BINUTILS_VERSION="2.31.1"
35
36GDB_BRANCH="gdb-8_2-helenos"
37GDB_VERSION="8.2"
38
39GCC_GIT="https://github.com/HelenOS/gcc.git"
40GCC_BRANCH="8_2_0-helenos"
41GCC_VERSION="8.2.0"
42
43BASEDIR="`pwd`"
44SRCDIR="$(readlink -f $(dirname "$0"))"
45
46REAL_INSTALL=true
47USE_HELENOS_TARGET=true
48
49check_error() {
50 if [ "$1" -ne "0" ] ; then
51 echo
52 echo "Script failed: $2"
53
54 exit 1
55 fi
56}
57
58show_usage() {
59 echo "Cross-compiler toolchain build script"
60 echo
61 echo "Syntax:"
62 echo " $0 [--no-install] [--non-helenos-target] <platform>"
63 echo " $0 --test-version [<platform>]"
64 echo
65 echo "Possible target platforms are:"
66 echo " amd64 AMD64 (x86-64, x64)"
67 echo " arm32 ARM 32b"
68 echo " arm64 AArch64"
69 echo " ia32 IA-32 (x86, i386)"
70 echo " ia64 IA-64 (Itanium)"
71 echo " mips32 MIPS little-endian 32b"
72 echo " mips32eb MIPS big-endian 32b"
73 echo " ppc32 PowerPC 32b"
74 echo " riscv64 RISC-V 64b"
75 echo " sparc64 SPARC V9"
76 echo " all build all targets"
77 echo " essential build only targets currently needed for HelenOS development"
78 echo " parallel same as 'all', but all in parallel"
79 echo " 2-way same as 'all', but 2-way parallel"
80 echo
81 echo "The toolchain is installed into directory specified by the"
82 echo "CROSS_PREFIX environment variable. If the variable is not"
83 echo "defined, /usr/local/cross/ is used as default."
84 echo
85 echo "If --no-install is present, the toolchain still uses the"
86 echo "CROSS_PREFIX as the target directory but the installation"
87 echo "copies the files into PKG/ subdirectory without affecting"
88 echo "the actual root file system. That is only useful if you do"
89 echo "not want to run the script under the super user."
90 echo
91 echo "The --non-helenos-target will build non-HelenOS-specific toolchain"
92 echo "(i.e. it will use *-linux-* triplet instead of *-helenos)."
93 echo "Using this toolchain for building HelenOS is not supported."
94 echo
95
96 exit 3
97}
98
99test_version() {
100 echo "Cross-compiler toolchain build script"
101 echo
102 echo "Start testing the version of the installed software"
103 echo
104
105 if [ -z "$1" ] || [ "$1" == "all" ] ; then
106 PLATFORMS=("amd64" "arm32" "arm64" "ia32" "ia64" "mips32" "mips32eb" "ppc32" "riscv64" "sparc64")
107 else
108 PLATFORMS=("$1")
109 fi
110
111
112 if [ -z "${CROSS_PREFIX}" ] ; then
113 CROSS_PREFIX="/usr/local/cross"
114 fi
115
116 for i in "${PLATFORMS[@]}"
117 do
118 PLATFORM="$i"
119 set_target_from_platform "$PLATFORM"
120 PREFIX="${CROSS_PREFIX}/bin/${HELENOS_TARGET}"
121
122 echo "== $PLATFORM =="
123 test_app_version "Binutils" "ld" "GNU\ ld\ \(GNU\ Binutils\)\ ((\.|[0-9])+)" "$BINUTILS_VERSION"
124 test_app_version "GCC" "gcc" "gcc\ version\ ((\.|[0-9])+)" "$GCC_VERSION"
125 test_app_version "GDB" "gdb" "GNU\ gdb\ \(GDB\)\s+((\.|[0-9])+)" "$GDB_VERSION"
126 done
127
128 exit
129}
130
131test_app_version() {
132 PKGNAME="$1"
133 APPNAME="$2"
134 REGEX="$3"
135 INS_VERSION="$4"
136
137
138 APP="${PREFIX}-${APPNAME}"
139 if [ ! -e $APP ]; then
140 echo "- $PKGNAME is missing"
141 else
142 {
143 OUT=$(${APP} -v 2>&1)
144 } &> /dev/null
145
146 if [[ "$OUT" =~ $REGEX ]]; then
147 VERSION="${BASH_REMATCH[1]}"
148 if [ "$INS_VERSION" = "$VERSION" ]; then
149 echo "+ $PKGNAME is uptodate ($INS_VERSION)"
150 else
151 echo "- $PKGNAME ($VERSION) is outdated ($INS_VERSION)"
152 fi
153 else
154 echo "- $PKGNAME Unexpected output"
155 fi
156 fi
157}
158
159
160
161change_title() {
162 echo -en "\e]0;$1\a"
163}
164
165show_countdown() {
166 TM="$1"
167
168 if [ "${TM}" -eq 0 ] ; then
169 echo
170 return 0
171 fi
172
173 echo -n "${TM} "
174 change_title "${TM}"
175 sleep 1
176
177 TM="`expr "${TM}" - 1`"
178 show_countdown "${TM}"
179}
180
181show_dependencies() {
182 echo "IMPORTANT NOTICE:"
183 echo
184 echo "For a successful compilation and use of the cross-compiler"
185 echo "toolchain you need at least the following dependencies."
186 echo
187 echo "Please make sure that the dependencies are present in your"
188 echo "system. Otherwise the compilation process might fail after"
189 echo "a few seconds or minutes."
190 echo
191 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
192 echo " - gettext, zlib, Texinfo, libelf, libgomp"
193 echo " - GNU Make, Coreutils, Sharutils, tar"
194 echo " - native C and C++ compiler, assembler and linker"
195 echo " - native C and C++ standard library with headers"
196 echo
197}
198
199cleanup_dir() {
200 DIR="$1"
201
202 if [ -d "${DIR}" ] ; then
203 change_title "Removing ${DIR}"
204 echo " >>> Removing ${DIR}"
205 rm -fr "${DIR}"
206 fi
207}
208
209create_dir() {
210 DIR="$1"
211 DESC="$2"
212
213 change_title "Creating ${DESC}"
214 echo ">>> Creating ${DESC}"
215
216 mkdir -p "${DIR}"
217 test -d "${DIR}"
218 check_error $? "Unable to create ${DIR}."
219}
220
221check_dirs() {
222 OUTSIDE="$1"
223 BASE="$2"
224 ORIGINAL="`pwd`"
225
226 mkdir -p "${OUTSIDE}"
227
228 cd "${OUTSIDE}"
229 check_error $? "Unable to change directory to ${OUTSIDE}."
230 ABS_OUTSIDE="`pwd`"
231
232 cd "${BASE}"
233 check_error $? "Unable to change directory to ${BASE}."
234 ABS_BASE="`pwd`"
235
236 cd "${ORIGINAL}"
237 check_error $? "Unable to change directory to ${ORIGINAL}."
238
239 BASE_LEN="${#ABS_BASE}"
240 OUTSIDE_TRIM="${ABS_OUTSIDE:0:${BASE_LEN}}"
241
242 if [ "${OUTSIDE_TRIM}" == "${ABS_BASE}" ] ; then
243 echo
244 echo "CROSS_PREFIX cannot reside within the working directory."
245
246 exit 5
247 fi
248}
249
250prepare() {
251 show_dependencies
252 show_countdown 10
253
254 mkdir -p "${BASEDIR}/downloads"
255 cd "${BASEDIR}/downloads"
256 check_error $? "Change directory failed."
257
258 echo ">>> Downloading sources"
259 git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION"
260 git clone --depth 1 -b "$GDB_BRANCH" "$BINUTILS_GDB_GIT" "gdb-$GDB_VERSION"
261 git clone --depth 1 -b "$GCC_BRANCH" "$GCC_GIT" "gcc-$GCC_VERSION"
262
263 # If the directory already existed, pull upstream changes.
264 git -C "binutils-$BINUTILS_VERSION" pull
265 git -C "gdb-$GDB_VERSION" pull
266 git -C "gcc-$GCC_VERSION" pull
267
268 echo ">>> Downloading GCC prerequisites"
269 cd "gcc-${GCC_VERSION}"
270 ./contrib/download_prerequisites
271 cd ..
272}
273
274set_target_from_platform() {
275 case "$1" in
276 "arm32")
277 GNU_ARCH="arm"
278 ;;
279 "arm64")
280 GNU_ARCH="aarch64"
281 ;;
282 "ia32")
283 GNU_ARCH="i686"
284 ;;
285 "mips32")
286 GNU_ARCH="mipsel"
287 ;;
288 "mips32eb")
289 GNU_ARCH="mips"
290 ;;
291 "ppc32")
292 GNU_ARCH="ppc"
293 ;;
294 *)
295 GNU_ARCH="$1"
296 ;;
297 esac
298
299 HELENOS_TARGET="${GNU_ARCH}-helenos"
300
301 case "$1" in
302 "arm32")
303 LINUX_TARGET="${GNU_ARCH}-linux-gnueabi"
304 ;;
305 *)
306 LINUX_TARGET="${GNU_ARCH}-linux-gnu"
307 ;;
308 esac
309}
310
311build_target() {
312 PLATFORM="$1"
313
314 # This sets the *_TARGET variables
315 set_target_from_platform "$PLATFORM"
316 if $USE_HELENOS_TARGET ; then
317 TARGET="$HELENOS_TARGET"
318 else
319 TARGET="$LINUX_TARGET"
320 fi
321
322 WORKDIR="${BASEDIR}/${TARGET}"
323 INSTALL_DIR="${BASEDIR}/PKG"
324 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
325 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
326 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
327
328 if [ -z "${CROSS_PREFIX}" ] ; then
329 CROSS_PREFIX="/usr/local/cross"
330 fi
331
332 if [ -z "$JOBS" ] ; then
333 JOBS=`nproc`
334 fi
335
336 PREFIX="${CROSS_PREFIX}"
337
338 echo ">>> Removing previous content"
339 cleanup_dir "${WORKDIR}"
340 mkdir -p "${WORKDIR}"
341 check_dirs "${PREFIX}" "${WORKDIR}"
342
343 if $USE_HELENOS_TARGET ; then
344 echo ">>> Creating build sysroot"
345 mkdir -p "${WORKDIR}/sysroot/include"
346 mkdir "${WORKDIR}/sysroot/lib"
347 ARCH="$PLATFORM"
348 if [ "$ARCH" = "mips32eb" ]; then
349 ARCH=mips32
350 fi
351
352 cp -r -L -t "${WORKDIR}/sysroot/include" \
353 ${SRCDIR}/../abi/include/* \
354 ${SRCDIR}/../uspace/lib/c/arch/${ARCH}/include/* \
355 ${SRCDIR}/../uspace/lib/c/include/*
356 check_error $? "Failed to create build sysroot."
357 fi
358
359 echo ">>> Processing binutils (${PLATFORM})"
360 mkdir -p "${BINUTILSDIR}"
361 cd "${BINUTILSDIR}"
362 check_error $? "Change directory failed."
363
364 change_title "binutils: configure (${PLATFORM})"
365 CFLAGS=-Wno-error "${BASEDIR}/downloads/binutils-${BINUTILS_VERSION}/configure" \
366 "--target=${TARGET}" \
367 "--prefix=${PREFIX}" \
368 "--program-prefix=${TARGET}-" \
369 --disable-nls \
370 --disable-werror \
371 --enable-gold \
372 --enable-deterministic-archives \
373 --disable-gdb \
374 --with-sysroot
375 check_error $? "Error configuring binutils."
376
377 change_title "binutils: make (${PLATFORM})"
378 make all -j$JOBS
379 check_error $? "Error compiling binutils."
380
381 change_title "binutils: install (${PLATFORM})"
382 make install "DESTDIR=${INSTALL_DIR}"
383 check_error $? "Error installing binutils."
384
385
386 echo ">>> Processing GCC (${PLATFORM})"
387 mkdir -p "${GCCDIR}"
388 cd "${GCCDIR}"
389 check_error $? "Change directory failed."
390
391 if $USE_HELENOS_TARGET ; then
392 SYSROOT=--with-sysroot --with-build-sysroot="${WORKDIR}/sysroot"
393 else
394 SYSROOT=--without-headers
395 fi
396
397 change_title "GCC: configure (${PLATFORM})"
398 PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \
399 "--target=${TARGET}" \
400 "--prefix=${PREFIX}" \
401 "--program-prefix=${TARGET}-" \
402 --with-gnu-as \
403 --with-gnu-ld \
404 --disable-nls \
405 --enable-languages=c,c++,go \
406 --enable-lto \
407 --disable-shared \
408 --disable-werror \
409 $SYSROOT
410 check_error $? "Error configuring GCC."
411
412 change_title "GCC: make (${PLATFORM})"
413 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc -j$JOBS
414 check_error $? "Error compiling GCC."
415
416 if $USE_HELENOS_TARGET ; then
417 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libgcc -j$JOBS
418 check_error $? "Error compiling libgcc."
419 # TODO: needs some extra care
420 #PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libatomic -j$JOBS
421 #check_error $? "Error compiling libatomic."
422 #PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libstdc++-v3 -j$JOBS
423 #check_error $? "Error compiling libstdc++."
424 fi
425
426 change_title "GCC: install (${PLATFORM})"
427 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
428 if $USE_HELENOS_TARGET ; then
429 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libgcc "DESTDIR=${INSTALL_DIR}"
430 #PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libatomic "DESTDIR=${INSTALL_DIR}"
431 #PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libstdc++-v3 "DESTDIR=${INSTALL_DIR}"
432 fi
433 check_error $? "Error installing GCC."
434
435
436 echo ">>> Processing GDB (${PLATFORM})"
437 mkdir -p "${GDBDIR}"
438 cd "${GDBDIR}"
439 check_error $? "Change directory failed."
440
441 change_title "GDB: configure (${PLATFORM})"
442 PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gdb-${GDB_VERSION}/configure" \
443 "--target=${TARGET}" \
444 "--prefix=${PREFIX}" \
445 "--program-prefix=${TARGET}-" \
446 --enable-werror=no
447 check_error $? "Error configuring GDB."
448
449 change_title "GDB: make (${PLATFORM})"
450 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gdb -j$JOBS
451 check_error $? "Error compiling GDB."
452
453 change_title "GDB: make (${PLATFORM})"
454 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gdb "DESTDIR=${INSTALL_DIR}"
455 check_error $? "Error installing GDB."
456
457 # Symlink clang and lld to the install path.
458 CLANG="`which clang 2> /dev/null || echo "/usr/bin/clang"`"
459 LLD="`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`"
460
461 ln -s $CLANG "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-clang"
462 ln -s $LLD "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-ld.lld"
463
464 if $REAL_INSTALL ; then
465 echo ">>> Moving to the destination directory."
466 echo cp -r -t "${PREFIX}" "${INSTALL_DIR}/${PREFIX}/"*
467 cp -r -t "${PREFIX}" "${INSTALL_DIR}/${PREFIX}/"*
468 fi
469
470 cd "${BASEDIR}"
471 check_error $? "Change directory failed."
472
473 echo ">>> Cleaning up"
474 cleanup_dir "${WORKDIR}"
475
476 echo
477 echo ">>> Cross-compiler for ${TARGET} installed."
478}
479
480while [ "$#" -gt 1 ] ; do
481 case "$1" in
482 --test-version)
483 test_version "$2"
484 exit
485 ;;
486 --no-install)
487 REAL_INSTALL=false
488 shift
489 ;;
490 --non-helenos-target)
491 USE_HELENOS_TARGET=false
492 shift
493 ;;
494 *)
495 show_usage
496 ;;
497 esac
498done
499
500if [ "$#" -lt "1" ] ; then
501 show_usage
502fi
503
504case "$1" in
505 --test-version)
506 test_version
507 ;;
508 amd64|arm32|arm64|ia32|ia64|mips32|mips32eb|ppc32|riscv64|sparc64)
509 prepare
510 build_target "$1"
511 ;;
512 "all")
513 prepare
514 build_target "amd64"
515 build_target "arm32"
516 build_target "arm64"
517 build_target "ia32"
518 build_target "ia64"
519 build_target "mips32"
520 build_target "mips32eb"
521 build_target "ppc32"
522 build_target "riscv64"
523 build_target "sparc64"
524 ;;
525 "essential")
526 prepare
527 build_target "amd64"
528 build_target "arm32"
529 build_target "arm64"
530 build_target "ia32"
531 build_target "ia64"
532 build_target "mips32"
533 build_target "mips32eb"
534 build_target "ppc32"
535 build_target "sparc64"
536 ;;
537 "parallel")
538 prepare
539 build_target "amd64" &
540 build_target "arm32" &
541 build_target "arm64" &
542 build_target "ia32" &
543 build_target "ia64" &
544 build_target "mips32" &
545 build_target "mips32eb" &
546 build_target "ppc32" &
547 build_target "riscv64" &
548 build_target "sparc64" &
549 wait
550 ;;
551 "2-way")
552 prepare
553 build_target "amd64" &
554 build_target "arm32" &
555 wait
556
557 build_target "arm64" &
558 build_target "ia32" &
559 wait
560
561 build_target "ia64" &
562 build_target "mips32" &
563 wait
564
565 build_target "mips32eb" &
566 build_target "ppc32" &
567 wait
568
569 build_target "riscv64" &
570 build_target "sparc64" &
571 wait
572 ;;
573 *)
574 show_usage
575 ;;
576esac
Note: See TracBrowser for help on using the repository browser.