source: mainline/tools/toolchain.sh@ c222816

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c222816 was e38ff16, checked in by Vojtech Horky <vojtech.horky@…>, 7 years ago

toolchain.sh —no-install shall not remove PKG

Without this modification, toolchain was installed to target/PKG and
promptly removed. Now, everything is installed into tools/PKG.

  • Property mode set to 100755
File size: 12.4 KB
RevLine 
[9d5bb4e]1#! /bin/bash
[ff211d2]2
3#
[04c3a21f]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.
[ff211d2]29#
30
[232ec3a1]31BINUTILS_GDB_GIT="https://github.com/HelenOS/binutils-gdb.git"
32
33BINUTILS_BRANCH="binutils-2_30-helenos"
[105fcf0]34BINUTILS_VERSION="2.30"
[232ec3a1]35
36GDB_BRANCH="gdb-8_1-helenos"
[105fcf0]37GDB_VERSION="8.1"
[603c8740]38
[232ec3a1]39GCC_GIT="https://github.com/HelenOS/gcc.git"
[c92dfed]40GCC_BRANCH="8_2_0-helenos"
41GCC_VERSION="8.2.0"
[232ec3a1]42
[603c8740]43BASEDIR="`pwd`"
[12735849]44SRCDIR="$(readlink -f $(dirname "$0"))"
[603c8740]45
[322ac35c]46REAL_INSTALL=true
[bbe5e34]47USE_HELENOS_TARGET=true
[3f7efa79]48
[ff211d2]49check_error() {
[75b24cd]50 if [ "$1" -ne "0" ] ; then
[ff211d2]51 echo
52 echo "Script failed: $2"
[a35b458]53
[ff211d2]54 exit 1
55 fi
56}
57
58show_usage() {
59 echo "Cross-compiler toolchain build script"
60 echo
61 echo "Syntax:"
[bbe5e34]62 echo " $0 [--no-install] [--non-helenos-target] <platform>"
[ff211d2]63 echo
64 echo "Possible target platforms are:"
[f2f89315]65 echo " amd64 AMD64 (x86-64, x64)"
[d2bd00f0]66 echo " arm32 ARM 32b"
[ff211d2]67 echo " ia32 IA-32 (x86, i386)"
68 echo " ia64 IA-64 (Itanium)"
[71e3289]69 echo " mips32 MIPS little-endian 32b"
70 echo " mips32eb MIPS big-endian 32b"
[d2bd00f0]71 echo " ppc32 PowerPC 32b"
72 echo " riscv64 RISC-V 64b"
[f2f89315]73 echo " sparc64 SPARC V9"
[ff211d2]74 echo " all build all targets"
[951f6b9e]75 echo " essential build only targets currently needed for HelenOS development"
[6abb346]76 echo " parallel same as 'all', but all in parallel"
77 echo " 2-way same as 'all', but 2-way parallel"
[ff211d2]78 echo
[322ac35c]79 echo "The toolchain is installed into directory specified by the"
80 echo "CROSS_PREFIX environment variable. If the variable is not"
81 echo "defined, /usr/local/cross/ is used as default."
[5a65d29]82 echo
[322ac35c]83 echo "If --no-install is present, the toolchain still uses the"
84 echo "CROSS_PREFIX as the target directory but the installation"
85 echo "copies the files into PKG/ subdirectory without affecting"
86 echo "the actual root file system. That is only useful if you do"
87 echo "not want to run the script under the super user."
[38eaf41]88 echo
[bbe5e34]89 echo "The --non-helenos-target will build non-HelenOS-specific toolchain"
90 echo "(i.e. it will use *-linux-* triplet instead of *-helenos)."
91 echo "Using this toolchain for building HelenOS is not supported."
[38eaf41]92 echo
[a35b458]93
[ff211d2]94 exit 3
95}
96
[3fe57ea7]97change_title() {
98 echo -en "\e]0;$1\a"
99}
100
101show_countdown() {
102 TM="$1"
[a35b458]103
[3fe57ea7]104 if [ "${TM}" -eq 0 ] ; then
105 echo
106 return 0
107 fi
[a35b458]108
[3fe57ea7]109 echo -n "${TM} "
110 change_title "${TM}"
111 sleep 1
[a35b458]112
[3fe57ea7]113 TM="`expr "${TM}" - 1`"
114 show_countdown "${TM}"
115}
116
117show_dependencies() {
118 echo "IMPORTANT NOTICE:"
119 echo
120 echo "For a successful compilation and use of the cross-compiler"
121 echo "toolchain you need at least the following dependencies."
122 echo
123 echo "Please make sure that the dependencies are present in your"
124 echo "system. Otherwise the compilation process might fail after"
125 echo "a few seconds or minutes."
126 echo
127 echo " - SED, AWK, Flex, Bison, gzip, bzip2, Bourne Shell"
128 echo " - gettext, zlib, Texinfo, libelf, libgomp"
[f6017ee]129 echo " - GNU Make, Coreutils, Sharutils, tar"
130 echo " - native C and C++ compiler, assembler and linker"
131 echo " - native C and C++ standard library with headers"
[3fe57ea7]132 echo
133}
134
[ff211d2]135cleanup_dir() {
136 DIR="$1"
[a35b458]137
[75b24cd]138 if [ -d "${DIR}" ] ; then
[3fe57ea7]139 change_title "Removing ${DIR}"
[ff211d2]140 echo " >>> Removing ${DIR}"
141 rm -fr "${DIR}"
142 fi
143}
144
145create_dir() {
146 DIR="$1"
147 DESC="$2"
[a35b458]148
[3fe57ea7]149 change_title "Creating ${DESC}"
[ff211d2]150 echo ">>> Creating ${DESC}"
[a35b458]151
[ff211d2]152 mkdir -p "${DIR}"
153 test -d "${DIR}"
154 check_error $? "Unable to create ${DIR}."
155}
156
[285589b]157check_dirs() {
158 OUTSIDE="$1"
159 BASE="$2"
160 ORIGINAL="`pwd`"
[a35b458]161
[0f28387]162 mkdir -p "${OUTSIDE}"
[a35b458]163
[285589b]164 cd "${OUTSIDE}"
165 check_error $? "Unable to change directory to ${OUTSIDE}."
166 ABS_OUTSIDE="`pwd`"
[a35b458]167
[285589b]168 cd "${BASE}"
169 check_error $? "Unable to change directory to ${BASE}."
170 ABS_BASE="`pwd`"
[a35b458]171
[285589b]172 cd "${ORIGINAL}"
173 check_error $? "Unable to change directory to ${ORIGINAL}."
[a35b458]174
[285589b]175 BASE_LEN="${#ABS_BASE}"
176 OUTSIDE_TRIM="${ABS_OUTSIDE:0:${BASE_LEN}}"
[a35b458]177
[285589b]178 if [ "${OUTSIDE_TRIM}" == "${ABS_BASE}" ] ; then
179 echo
180 echo "CROSS_PREFIX cannot reside within the working directory."
[a35b458]181
[285589b]182 exit 5
183 fi
184}
185
[603c8740]186prepare() {
187 show_dependencies
188 show_countdown 10
[a35b458]189
[530f2de]190 mkdir -p "${BASEDIR}/downloads"
191 cd "${BASEDIR}/downloads"
192 check_error $? "Change directory failed."
193
[232ec3a1]194 echo ">>> Downloading sources"
195 git clone --depth 1 -b "$BINUTILS_BRANCH" "$BINUTILS_GDB_GIT" "binutils-$BINUTILS_VERSION"
196 git clone --depth 1 -b "$GDB_BRANCH" "$BINUTILS_GDB_GIT" "gdb-$GDB_VERSION"
197 git clone --depth 1 -b "$GCC_BRANCH" "$GCC_GIT" "gcc-$GCC_VERSION"
[a35b458]198
[232ec3a1]199 # If the directory already existed, pull upstream changes.
200 git -C "binutils-$BINUTILS_VERSION" pull
201 git -C "gdb-$GDB_VERSION" pull
202 git -C "gcc-$GCC_VERSION" pull
[530f2de]203
204 echo ">>> Downloading GCC prerequisites"
205 cd "gcc-${GCC_VERSION}"
206 ./contrib/download_prerequisites
207 cd ..
[fd8bf6a]208}
209
[6c9f1a6]210set_target_from_platform() {
211 case "$1" in
212 "arm32")
[232ec3a1]213 GNU_ARCH="arm"
[6c9f1a6]214 ;;
215 "ia32")
[232ec3a1]216 GNU_ARCH="i686"
[6c9f1a6]217 ;;
218 "mips32")
[232ec3a1]219 GNU_ARCH="mipsel"
[6c9f1a6]220 ;;
221 "mips32eb")
[232ec3a1]222 GNU_ARCH="mips"
[6c9f1a6]223 ;;
224 "ppc32")
[232ec3a1]225 GNU_ARCH="ppc"
[6c9f1a6]226 ;;
[232ec3a1]227 *)
228 GNU_ARCH="$1"
[6c9f1a6]229 ;;
[232ec3a1]230 esac
231
232 HELENOS_TARGET="${GNU_ARCH}-helenos"
233
234 case "$1" in
235 "arm32")
236 LINUX_TARGET="${GNU_ARCH}-linux-gnueabi"
[6c9f1a6]237 ;;
238 *)
[232ec3a1]239 LINUX_TARGET="${GNU_ARCH}-linux-gnu"
[6c9f1a6]240 ;;
241 esac
[fd8bf6a]242}
243
[ff211d2]244build_target() {
245 PLATFORM="$1"
[a35b458]246
[5a65d29]247 # This sets the *_TARGET variables
[6c9f1a6]248 set_target_from_platform "$PLATFORM"
[75b24cd]249 if $USE_HELENOS_TARGET ; then
[5a65d29]250 TARGET="$HELENOS_TARGET"
251 else
252 TARGET="$LINUX_TARGET"
253 fi
[a35b458]254
[591b989]255 WORKDIR="${BASEDIR}/${TARGET}"
[e38ff16]256 INSTALL_DIR="${BASEDIR}/PKG"
[ff211d2]257 BINUTILSDIR="${WORKDIR}/binutils-${BINUTILS_VERSION}"
258 GCCDIR="${WORKDIR}/gcc-${GCC_VERSION}"
[2a922c8]259 GDBDIR="${WORKDIR}/gdb-${GDB_VERSION}"
[a35b458]260
[ff211d2]261 if [ -z "${CROSS_PREFIX}" ] ; then
[603c8740]262 CROSS_PREFIX="/usr/local/cross"
[ff211d2]263 fi
[a35b458]264
[232ec3a1]265 if [ -z "$JOBS" ] ; then
266 JOBS=`nproc`
267 fi
268
[bbe5e34]269 PREFIX="${CROSS_PREFIX}"
[a35b458]270
[ff211d2]271 echo ">>> Removing previous content"
[603c8740]272 cleanup_dir "${WORKDIR}"
[530f2de]273 mkdir -p "${WORKDIR}"
[285589b]274 check_dirs "${PREFIX}" "${WORKDIR}"
[a35b458]275
[232ec3a1]276 if $USE_HELENOS_TARGET ; then
277 echo ">>> Creating build sysroot"
278 mkdir -p "${WORKDIR}/sysroot/include"
279 mkdir "${WORKDIR}/sysroot/lib"
280 cp -r -L -t "${WORKDIR}/sysroot/include" \
281 ${SRCDIR}/../abi/include/* \
282 ${SRCDIR}/../uspace/lib/c/arch/${PLATFORM}/include/* \
283 ${SRCDIR}/../uspace/lib/c/include/*
284 check_error $? "Failed to create build sysroot."
285 fi
286
[3fe57ea7]287 echo ">>> Processing binutils (${PLATFORM})"
[530f2de]288 mkdir -p "${BINUTILSDIR}"
[ff211d2]289 cd "${BINUTILSDIR}"
290 check_error $? "Change directory failed."
[a35b458]291
[3fe57ea7]292 change_title "binutils: configure (${PLATFORM})"
[530f2de]293 CFLAGS=-Wno-error "${BASEDIR}/downloads/binutils-${BINUTILS_VERSION}/configure" \
[322ac35c]294 "--target=${TARGET}" \
[232ec3a1]295 "--prefix=${PREFIX}" \
296 "--program-prefix=${TARGET}-" \
297 --disable-nls \
298 --disable-werror \
299 --enable-gold \
300 --enable-deterministic-archives \
301 --disable-gdb \
302 --with-sysroot
[ff211d2]303 check_error $? "Error configuring binutils."
[a35b458]304
[3fe57ea7]305 change_title "binutils: make (${PLATFORM})"
[232ec3a1]306 make all -j$JOBS
[322ac35c]307 check_error $? "Error compiling binutils."
[a35b458]308
[322ac35c]309 change_title "binutils: install (${PLATFORM})"
[0f28387]310 make install "DESTDIR=${INSTALL_DIR}"
[322ac35c]311 check_error $? "Error installing binutils."
[a35b458]312
313
[3fe57ea7]314 echo ">>> Processing GCC (${PLATFORM})"
[530f2de]315 mkdir -p "${GCCDIR}"
316 cd "${GCCDIR}"
[ff211d2]317 check_error $? "Change directory failed."
[a35b458]318
[232ec3a1]319 if $USE_HELENOS_TARGET ; then
320 SYSROOT=--with-sysroot --with-build-sysroot="${WORKDIR}/sysroot"
321 else
322 SYSROOT=--without-headers
323 fi
324
[3fe57ea7]325 change_title "GCC: configure (${PLATFORM})"
[530f2de]326 PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gcc-${GCC_VERSION}/configure" \
[322ac35c]327 "--target=${TARGET}" \
[232ec3a1]328 "--prefix=${PREFIX}" \
329 "--program-prefix=${TARGET}-" \
330 --with-gnu-as \
331 --with-gnu-ld \
332 --disable-nls \
333 --enable-languages=c,c++,go \
334 --enable-lto \
335 --disable-shared \
336 --disable-werror \
337 $SYSROOT
[ff211d2]338 check_error $? "Error configuring GCC."
[a35b458]339
[3fe57ea7]340 change_title "GCC: make (${PLATFORM})"
[232ec3a1]341 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gcc -j$JOBS
[322ac35c]342 check_error $? "Error compiling GCC."
[a35b458]343
[232ec3a1]344 if $USE_HELENOS_TARGET ; then
345 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libgcc -j$JOBS
346 check_error $? "Error compiling libgcc."
347 # TODO: needs some extra care
348 #PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libatomic -j$JOBS
349 #check_error $? "Error compiling libatomic."
350 #PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-target-libstdc++-v3 -j$JOBS
351 #check_error $? "Error compiling libstdc++."
352 fi
353
[322ac35c]354 change_title "GCC: install (${PLATFORM})"
[0f28387]355 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gcc "DESTDIR=${INSTALL_DIR}"
[232ec3a1]356 if $USE_HELENOS_TARGET ; then
357 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libgcc "DESTDIR=${INSTALL_DIR}"
358 #PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libatomic "DESTDIR=${INSTALL_DIR}"
359 #PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-target-libstdc++-v3 "DESTDIR=${INSTALL_DIR}"
360 fi
[322ac35c]361 check_error $? "Error installing GCC."
[a35b458]362
363
[105fcf0]364 echo ">>> Processing GDB (${PLATFORM})"
365 mkdir -p "${GDBDIR}"
366 cd "${GDBDIR}"
367 check_error $? "Change directory failed."
[a35b458]368
[105fcf0]369 change_title "GDB: configure (${PLATFORM})"
370 PATH="$PATH:${INSTALL_DIR}/${PREFIX}/bin" "${BASEDIR}/downloads/gdb-${GDB_VERSION}/configure" \
371 "--target=${TARGET}" \
[232ec3a1]372 "--prefix=${PREFIX}" \
373 "--program-prefix=${TARGET}-" \
374 --enable-werror=no
[105fcf0]375 check_error $? "Error configuring GDB."
[a35b458]376
[105fcf0]377 change_title "GDB: make (${PLATFORM})"
[232ec3a1]378 PATH="${PATH}:${PREFIX}/bin:${INSTALL_DIR}/${PREFIX}/bin" make all-gdb -j$JOBS
[105fcf0]379 check_error $? "Error compiling GDB."
[a35b458]380
[105fcf0]381 change_title "GDB: make (${PLATFORM})"
[232ec3a1]382 PATH="${PATH}:${INSTALL_DIR}/${PREFIX}/bin" make install-gdb "DESTDIR=${INSTALL_DIR}"
[105fcf0]383 check_error $? "Error installing GDB."
[a35b458]384
[0f28387]385 # Symlink clang and lld to the install path.
[8192d8a]386 CLANG="`which clang 2> /dev/null || echo "/usr/bin/clang"`"
387 LLD="`which ld.lld 2> /dev/null || echo "/usr/bin/ld.lld"`"
[a35b458]388
[0f28387]389 ln -s $CLANG "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-clang"
390 ln -s $LLD "${INSTALL_DIR}/${PREFIX}/bin/${TARGET}-ld.lld"
[a35b458]391
[0f28387]392 if $REAL_INSTALL ; then
393 echo ">>> Moving to the destination directory."
[bbe5e34]394 echo cp -r -t "${PREFIX}" "${INSTALL_DIR}/${PREFIX}/"*
395 cp -r -t "${PREFIX}" "${INSTALL_DIR}/${PREFIX}/"*
[0f28387]396 fi
[a35b458]397
[603c8740]398 cd "${BASEDIR}"
[ff211d2]399 check_error $? "Change directory failed."
[a35b458]400
[ff211d2]401 echo ">>> Cleaning up"
[603c8740]402 cleanup_dir "${WORKDIR}"
[a35b458]403
[ff211d2]404 echo
405 echo ">>> Cross-compiler for ${TARGET} installed."
406}
407
[75b24cd]408while [ "$#" -gt 1 ] ; do
[5a65d29]409 case "$1" in
410 --no-install)
411 REAL_INSTALL=false
412 shift
413 ;;
[bbe5e34]414 --non-helenos-target)
415 USE_HELENOS_TARGET=false
[5a65d29]416 shift
417 ;;
418 *)
419 show_usage
420 ;;
421 esac
422done
[322ac35c]423
[75b24cd]424if [ "$#" -lt "1" ] ; then
[ff211d2]425 show_usage
426fi
427
428case "$1" in
[1b12042]429 amd64|arm32|ia32|ia64|mips32|mips32eb|ppc32|riscv64|sparc64)
[603c8740]430 prepare
[6c9f1a6]431 build_target "$1"
[b886b60]432 ;;
[ff211d2]433 "all")
[603c8740]434 prepare
[6c9f1a6]435 build_target "amd64"
436 build_target "arm32"
437 build_target "ia32"
438 build_target "ia64"
439 build_target "mips32"
440 build_target "mips32eb"
441 build_target "ppc32"
[d2bd00f0]442 build_target "riscv64"
[6c9f1a6]443 build_target "sparc64"
[ff211d2]444 ;;
[951f6b9e]445 "essential")
446 prepare
447 build_target "amd64"
448 build_target "arm32"
449 build_target "ia32"
450 build_target "ia64"
451 build_target "mips32"
452 build_target "mips32eb"
453 build_target "ppc32"
454 build_target "sparc64"
455 ;;
[603c8740]456 "parallel")
457 prepare
[6c9f1a6]458 build_target "amd64" &
459 build_target "arm32" &
460 build_target "ia32" &
461 build_target "ia64" &
462 build_target "mips32" &
463 build_target "mips32eb" &
464 build_target "ppc32" &
[d2bd00f0]465 build_target "riscv64" &
[6c9f1a6]466 build_target "sparc64" &
[6abb346]467 wait
468 ;;
469 "2-way")
470 prepare
[6c9f1a6]471 build_target "amd64" &
472 build_target "arm32" &
[6abb346]473 wait
[a35b458]474
[6c9f1a6]475 build_target "ia32" &
476 build_target "ia64" &
[6abb346]477 wait
[a35b458]478
[6c9f1a6]479 build_target "mips32" &
480 build_target "mips32eb" &
[6abb346]481 wait
[a35b458]482
[6c9f1a6]483 build_target "ppc32" &
[d2bd00f0]484 build_target "riscv64" &
485 wait
[a35b458]486
[6c9f1a6]487 build_target "sparc64" &
[b886b60]488 wait
[603c8740]489 ;;
[ff211d2]490 *)
491 show_usage
492 ;;
493esac
Note: See TracBrowser for help on using the repository browser.