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
=
31 .
"$MUSL_CC_BASE"/defs.sh
33 # Switch to the CC prefix for all of this
36 # make the sysroot usr directory
37 if [ ! -e "$PREFIX"/"$TRIPLE"/usr
]
39 mkdir
-p "$PREFIX"/"$TRIPLE"
40 ln -sf .
"$PREFIX"/"$TRIPLE"/usr
42 if [ "$WITH_SYSROOT" = "yes" ]
44 SYSROOT_FLAGS
="--with-sysroot=""$PREFIX"/"$TRIPLE"
48 fetchextract binutils
"$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 \
62 fetchextract gcc http
://ftp.gnu.org
/gnu
/gcc
/gcc-
$GCC_VERSION/ gcc-
$GCC_VERSION .
tar.bz2
64 fetchextract gcc
"$GCC_URL"
65 if [ -e $GCC_EXTRACT_DIR ]; then
66 mv $GCC_EXTRACT_DIR gcc-
$GCC_VERSION
70 [ "$GCC_BUILTIN_PREREQS" = "yes" ] && gccprereqs
72 # If GCC_STAGE1_NOOPT is set, we build gcc without optimization and debug info,
73 # which reduces overall build time considerably.
75 SAVE_CXXFLAGS
="$CXXFLAGS"
76 if [ -z "$GCC_STAGE1_NOOPT" ]; then GCC_STAGE1_NOOPT
=0; fi
77 if [ "$GCC_STAGE1_NOOPT" -ne 0 ]
79 export CFLAGS
="-O0 -g0"
80 export CXXFLAGS
="-O0 -g0"
83 buildinstall
1 gcc-
$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
84 --enable-languages=c
--with-newlib --disable-libssp --disable-nls \
85 --disable-libquadmath --disable-threads --disable-decimal-float \
86 --disable-shared --disable-libmudflap --disable-libgomp --disable-libatomic \
87 $GCC_MULTILIB_CONFFLAGS \
88 $GCC_BOOTSTRAP_CONFFLAGS
90 export CFLAGS
="$SAVE_CFLAGS"
91 export CXXFLAGS
="$SAVE_CXXFLAGS"
93 if [ "$NEWLIB_VERSION" != "no" ]
97 NEWLIB_DIR
=newlib-
$NEWLIB_VERSION
98 sed -i -e 's,MAKEINFO="$MISSING makeinfo",MAKEINFO=true,g' \
101 # We set both CROSS_COMPILE and CC because CC in the environment overrides
102 # and CROSS_COMPILE setting
103 buildinstall
'' newlib-
$NEWLIB_VERSION \
104 --target=$TRIPLE CROSS_COMPILE
=${TRIPLE}- CC_FOR_TARGET
=$TRIPLE-gcc $NEWLIB_CONFFLAGS
106 # if it didn't build libc.so, disable dynamic linking
107 if [ ! -e "$CC_PREFIX/$TRIPLE/lib/libc.so" ]
109 GCC_CONFFLAGS
="--disable-shared $GCC_CONFFLAGS"
113 buildinstall
2 gcc-
$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
114 --enable-languages=$LANGUAGES --disable-libmudflap \
115 --disable-libsanitizer --disable-nls \
117 $GCC_MULTILIB_CONFFLAGS \
121 echo "looks as if it worked o.0"
123 test -z "$ENABLE_POST_BUILD_HOOK" || post_build_hook