source: mainline/tools/toolchain.sh@ c8c418cf

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

Bump GCC version to 8.2.0

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