build.sh: optionally reduce compilation time (build gcc1 w/o optimization)
[rofl0r-mmix-cross.git] / build.sh
blob4ab557e32bb3466d357a721ea848a2fc59eb230f
1 #!/bin/sh
2 # Build a cross-compiler
3 #
4 # Copyright (C) 2012 Gregor Richards
5 #
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 # PERFORMANCE OF THIS SOFTWARE.
18 if [ ! "$MUSL_CC_BASE" ]
19 then
20 MUSL_CC_BASE=`dirname "$0"`
23 # Fail on any command failing, show commands:
24 set -ex
26 BINUTILS_CONFFLAGS=
27 GCC_BOOTSTRAP_CONFFLAGS=
28 MUSL_CONFFLAGS=
29 GCC_CONFFLAGS=
30 . "$MUSL_CC_BASE"/defs.sh
32 # Switch to the CC prefix for all of this
33 PREFIX="$CC_PREFIX"
35 # make the sysroot usr directory
36 if [ ! -e "$PREFIX"/"$TRIPLE"/usr ]
37 then
38 mkdir -p "$PREFIX"/"$TRIPLE"
39 ln -sf . "$PREFIX"/"$TRIPLE"/usr
42 # binutils
43 if [ "$BINUTILS_VERSION" = "2.17" ]
44 then
45 # The version of the latest GPLv2 binutils on gnu.org is a lie...
46 fetchextract http://landley.net/aboriginal/mirror/ binutils-$BINUTILS_VERSION .tar.bz2
47 else
48 fetchextract http://ftp.gnu.org/gnu/binutils/ binutils-$BINUTILS_VERSION .tar.bz2
51 sed -i 's,MAKEINFO="$MISSING makeinfo",MAKEINFO=true,g' \
52 binutils-$BINUTILS_VERSION/configure
53 buildinstall 1 binutils-$BINUTILS_VERSION --target=$TRIPLE --disable-werror \
54 --with-sysroot="$PREFIX"/"$TRIPLE" \
55 $BINUTILS_CONFFLAGS
57 # gcc 1
58 fetchextract http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/ gcc-$GCC_VERSION .tar.bz2
59 [ "$GCC_BUILTIN_PREREQS" = "yes" ] && gccprereqs
61 # gcc 1 is only used to bootstrap musl and gcc 2, so it is pointless to
62 # optimize it.
63 # If GCC_STAGE1_NOOPT is set, we build it without optimization and debug info,
64 # which reduces overall build time considerably.
65 SAVE_CFLAGS="$CFLAGS"
66 SAVE_CXXFLAGS="$CXXFLAGS"
67 if [ -n "$GCC_STAGE1_NOOPT" ] ; then
68 export CFLAGS="-O0 -g0"
69 export CXXFLAGS="-O0 -g0"
72 buildinstall 1 gcc-$GCC_VERSION --target=$TRIPLE \
73 --with-sysroot="$PREFIX"/"$TRIPLE" \
74 --enable-languages=c --with-newlib --disable-multilib --disable-libssp \
75 --disable-libquadmath --disable-threads --disable-decimal-float \
76 --disable-shared --disable-libmudflap --disable-libgomp --disable-libatomic \
77 $GCC_BOOTSTRAP_CONFFLAGS
79 export CFLAGS="$SAVE_CFLAGS"
80 export CXXFLAGS="$SAVE_CXXFLAGS"
82 # linux headers
83 fetchextract http://www.kernel.org/pub/linux/kernel/v3.0/ linux-$LINUX_HEADERS_VERSION .tar.xz
84 if [ ! -e linux-$LINUX_HEADERS_VERSION/configured ]
85 then
87 cd linux-$LINUX_HEADERS_VERSION
88 make $LINUX_DEFCONFIG ARCH=$LINUX_ARCH
89 touch configured
92 if [ ! -e linux-$LINUX_HEADERS_VERSION/installedheaders ]
93 then
95 cd linux-$LINUX_HEADERS_VERSION
96 make headers_install ARCH=$LINUX_ARCH INSTALL_HDR_PATH="$CC_PREFIX/$TRIPLE"
97 touch installedheaders
101 if [ "$MUSL_VERSION" != "no" ]
102 then
103 # musl in CC prefix
104 PREFIX="$CC_PREFIX/$TRIPLE"
105 muslfetchextract
106 buildinstall '' musl-$MUSL_VERSION \
107 --enable-debug CC="$TRIPLE-gcc" $MUSL_CONFFLAGS
108 unset PREFIX
109 PREFIX="$CC_PREFIX"
111 # if it didn't build libc.so, disable dynamic linking
112 if [ ! -e "$CC_PREFIX/$TRIPLE/lib/libc.so" ]
113 then
114 GCC_CONFFLAGS="--disable-shared $GCC_CONFFLAGS"
117 # gcc 2
118 buildinstall 2 gcc-$GCC_VERSION --target=$TRIPLE \
119 --with-sysroot="$PREFIX"/"$TRIPLE" \
120 --enable-languages=$LANGUAGES --disable-multilib --disable-libmudflap \
121 --disable-libsanitizer \
122 $GCC_CONFFLAGS
125 # un"fix" headers
126 rm -rf "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include-fixed/ "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include/stddef.h
128 # make backwards-named compilers for easier cross-compiling
130 cd "$CC_PREFIX/bin"
131 for tool in $TRIPLE-*
133 btool=`echo "$tool" | sed 's/-linux-musl/-musl-linux/'`
134 [ "$tool" != "$btool" -a ! -e "$btool" ] && ln -s $tool $btool
135 done