bump musl default version to 1.1.20
[rofl0r-mmix-cross.git] / build.sh
blob0b6f8319bbf09628e02261df0065f94afd5f5cc1
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 WITH_SYSROOT=no
31 . "$MUSL_CC_BASE"/defs.sh
33 # Switch to the CC prefix for all of this
34 PREFIX="$CC_PREFIX"
36 # make the sysroot usr directory
37 if [ ! -e "$PREFIX"/"$TRIPLE"/usr ]
38 then
39 mkdir -p "$PREFIX"/"$TRIPLE"
40 ln -sf . "$PREFIX"/"$TRIPLE"/usr
42 if [ "$WITH_SYSROOT" = "yes" ]
43 then
44 SYSROOT_FLAGS="--with-sysroot=""$PREFIX"/"$TRIPLE"
47 # binutils
48 fetchextract "$BINUTILS_URL"
49 BINUTILS_DIR=$(stripfileext $(basename $BINUTILS_URL))
50 if printf "%s" "$BINUTILS_URL" | grep "2\.[2-9][0-9]" >/dev/null 2>&1 ; then
51 BINUTILS_CONFFLAGS="$BINUTILS_CONFFLAGS --enable-deterministic-archives"
54 sed -i -e 's,MAKEINFO="$MISSING makeinfo",MAKEINFO=true,g' \
55 $BINUTILS_DIR/configure
56 buildinstall 1 $BINUTILS_DIR --target=$TRIPLE --disable-werror $SYSROOT_FLAGS \
57 $BINUTILS_CONFFLAGS
59 # gcc 1
60 if [ -z $GCC_URL ];
61 then
62 fetchextract http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/ gcc-$GCC_VERSION .tar.bz2
63 else
64 fetchextract "$GCC_URL"
65 if [ -e $GCC_EXTRACT_DIR ]; then
66 mv $GCC_EXTRACT_DIR gcc-$GCC_VERSION
70 [ "$GCC_BUILTIN_PREREQS" = "yes" ] && gccprereqs
72 # gcc 1 is only used to bootstrap musl and gcc 2, so it is pointless to
73 # optimize it.
74 # If GCC_STAGE1_NOOPT is set, we build it without optimization and debug info,
75 # which reduces overall build time considerably.
76 SAVE_CFLAGS="$CFLAGS"
77 SAVE_CXXFLAGS="$CXXFLAGS"
78 if [ -z "$GCC_STAGE1_NOOPT" ]; then GCC_STAGE1_NOOPT=0; fi
79 if [ "$GCC_STAGE1_NOOPT" -ne 0 ]
80 then
81 export CFLAGS="-O0 -g0"
82 export CXXFLAGS="-O0 -g0"
85 buildinstall 1 gcc-$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
86 --enable-languages=c --with-newlib --disable-libssp --disable-nls \
87 --disable-libquadmath --disable-threads --disable-decimal-float \
88 --disable-shared --disable-libmudflap --disable-libgomp --disable-libatomic \
89 $GCC_MULTILIB_CONFFLAGS \
90 $GCC_BOOTSTRAP_CONFFLAGS
92 export CFLAGS="$SAVE_CFLAGS"
93 export CXXFLAGS="$SAVE_CXXFLAGS"
95 # linux headers
96 fetchextract $LINUX_HEADERS_URL
97 LINUX_HEADERS_DIR=$(stripfileext $(basename $LINUX_HEADERS_URL))
99 if [ ! -e $LINUX_HEADERS_DIR/configured ]
100 then
102 cd $LINUX_HEADERS_DIR
103 make $LINUX_DEFCONFIG ARCH=$LINUX_ARCH
104 touch configured
107 if [ ! -e $LINUX_HEADERS_DIR/installedheaders ]
108 then
110 cd $LINUX_HEADERS_DIR
111 make headers_install ARCH=$LINUX_ARCH INSTALL_HDR_PATH="$CC_PREFIX/$TRIPLE"
112 touch installedheaders
116 if [ "$MUSL_VERSION" != "no" ]
117 then
118 # musl in CC prefix
119 PREFIX="$CC_PREFIX/$TRIPLE"
120 muslfetchextract
121 # We set both CROSS_COMPILE and CC because CC in the environment overrides
122 # and CROSS_COMPILE setting
123 buildinstall '' musl-$MUSL_VERSION \
124 --enable-debug --enable-optimize CROSS_COMPILE="$TRIPLE-" CC="$TRIPLE-gcc" $MUSL_CONFFLAGS
125 unset PREFIX
126 PREFIX="$CC_PREFIX"
128 # if it didn't build libc.so, disable dynamic linking
129 if [ ! -e "$CC_PREFIX/$TRIPLE/lib/libc.so" ]
130 then
131 GCC_CONFFLAGS="--disable-shared $GCC_CONFFLAGS"
134 # gcc 2
135 buildinstall 2 gcc-$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
136 --enable-languages=$LANGUAGES --disable-libmudflap \
137 --disable-libsanitizer --disable-nls \
138 $GCC_MULTILIB_CONFFLAGS \
139 $GCC_CONFFLAGS
142 # un"fix" headers
143 rm -rf "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include-fixed/ "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include/stddef.h
145 # make backwards-named compilers for easier cross-compiling
147 cd "$CC_PREFIX/bin"
148 for tool in $TRIPLE-*
150 btool=`echo "$tool" | sed 's/-linux-musl/-musl-linux/'`
151 [ "$tool" != "$btool" -a ! -e "$btool" ] && ln -s $tool $btool
152 done
155 exit 0