2 # Build a cross-compiler
4 # Copyright (C) 2012 Gregor Richards
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.
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" ]
20 MUSL_CC_BASE
=`dirname "$0"`
23 # Fail on any command failing, show commands:
27 GCC_BOOTSTRAP_CONFFLAGS
=
30 .
"$MUSL_CC_BASE"/defs.sh
32 # Switch to the CC prefix for all of this
35 # make the sysroot usr directory
36 if [ ! -e "$PREFIX"/"$TRIPLE"/usr
]
38 mkdir
-p "$PREFIX"/"$TRIPLE"
39 ln -sf .
"$PREFIX"/"$TRIPLE"/usr
43 if [ "$BINUTILS_VERSION" = "2.17" ]
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
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" \
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
63 # If GCC_STAGE1_NOOPT is set, we build it without optimization and debug info,
64 # which reduces overall build time considerably.
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"
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
]
87 cd linux-
$LINUX_HEADERS_VERSION
88 make $LINUX_DEFCONFIG ARCH
=$LINUX_ARCH
92 if [ ! -e linux-
$LINUX_HEADERS_VERSION/installedheaders
]
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" ]
104 PREFIX
="$CC_PREFIX/$TRIPLE"
106 buildinstall
'' musl-
$MUSL_VERSION \
107 --enable-debug CC
="$TRIPLE-gcc" $MUSL_CONFFLAGS
111 # if it didn't build libc.so, disable dynamic linking
112 if [ ! -e "$CC_PREFIX/$TRIPLE/lib/libc.so" ]
114 GCC_CONFFLAGS
="--disable-shared $GCC_CONFFLAGS"
118 buildinstall
2 gcc-
$GCC_VERSION --target=$TRIPLE \
119 --with-sysroot="$PREFIX"/"$TRIPLE" \
120 --enable-languages=$LANGUAGES --disable-multilib --disable-libmudflap \
121 --disable-libsanitizer \
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
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