README: remove note about forks
[rofl0r-mmix-cross.git] / build.sh
blob68b8fac4e179c3716979ecbe78c7c253fa4c8ab3
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))
51 sed -i -e 's,MAKEINFO="$MISSING makeinfo",MAKEINFO=true,g' \
52 $BINUTILS_DIR/configure
53 buildinstall 1 $BINUTILS_DIR --target=$TRIPLE --disable-werror $SYSROOT_FLAGS \
54 $BINUTILS_CONFFLAGS
56 # gcc 1
57 if [ -z $GCC_URL ];
58 then
59 fetchextract http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/ gcc-$GCC_VERSION .tar.bz2
60 else
61 fetchextract "$GCC_URL"
62 if [ -e $GCC_EXTRACT_DIR ]; then
63 mv $GCC_EXTRACT_DIR gcc-$GCC_VERSION
67 [ "$GCC_BUILTIN_PREREQS" = "yes" ] && gccprereqs
69 # gcc 1 is only used to bootstrap musl and gcc 2, so it is pointless to
70 # optimize it.
71 # If GCC_STAGE1_NOOPT is set, we build it without optimization and debug info,
72 # which reduces overall build time considerably.
73 SAVE_CFLAGS="$CFLAGS"
74 SAVE_CXXFLAGS="$CXXFLAGS"
75 if [ -z "$GCC_STAGE1_NOOPT" ]; then GCC_STAGE1_NOOPT=0; fi
76 if [ "$GCC_STAGE1_NOOPT" -ne 0 ]
77 then
78 export CFLAGS="-O0 -g0"
79 export CXXFLAGS="-O0 -g0"
82 buildinstall 1 gcc-$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
83 --enable-languages=c --with-newlib --disable-libssp --disable-nls \
84 --disable-libquadmath --disable-threads --disable-decimal-float \
85 --disable-shared --disable-libmudflap --disable-libgomp --disable-libatomic \
86 $GCC_MULTILIB_CONFFLAGS \
87 $GCC_BOOTSTRAP_CONFFLAGS
89 export CFLAGS="$SAVE_CFLAGS"
90 export CXXFLAGS="$SAVE_CXXFLAGS"
92 # linux headers
93 fetchextract $LINUX_HEADERS_URL
94 LINUX_HEADERS_DIR=$(stripfileext $(basename $LINUX_HEADERS_URL))
96 if [ ! -e $LINUX_HEADERS_DIR/configured ]
97 then
99 cd $LINUX_HEADERS_DIR
100 make $LINUX_DEFCONFIG ARCH=$LINUX_ARCH
101 touch configured
104 if [ ! -e $LINUX_HEADERS_DIR/installedheaders ]
105 then
107 cd $LINUX_HEADERS_DIR
108 make headers_install ARCH=$LINUX_ARCH INSTALL_HDR_PATH="$CC_PREFIX/$TRIPLE"
109 touch installedheaders
113 if [ "$MUSL_VERSION" != "no" ]
114 then
115 # musl in CC prefix
116 PREFIX="$CC_PREFIX/$TRIPLE"
117 muslfetchextract
118 # We set both CROSS_COMPILE and CC because CC in the environment overrides
119 # and CROSS_COMPILE setting
120 buildinstall '' musl-$MUSL_VERSION \
121 --enable-debug --enable-optimize CROSS_COMPILE="$TRIPLE-" CC="$TRIPLE-gcc" $MUSL_CONFFLAGS
122 unset PREFIX
123 PREFIX="$CC_PREFIX"
125 # if it didn't build libc.so, disable dynamic linking
126 if [ ! -e "$CC_PREFIX/$TRIPLE/lib/libc.so" ]
127 then
128 GCC_CONFFLAGS="--disable-shared $GCC_CONFFLAGS"
131 # gcc 2
132 buildinstall 2 gcc-$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
133 --enable-languages=$LANGUAGES --disable-libmudflap \
134 --disable-libsanitizer --disable-nls \
135 $GCC_MULTILIB_CONFFLAGS \
136 $GCC_CONFFLAGS
139 # un"fix" headers
140 rm -rf "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include-fixed/ "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include/stddef.h
142 # make backwards-named compilers for easier cross-compiling
144 cd "$CC_PREFIX/bin"
145 for tool in $TRIPLE-*
147 btool=`echo "$tool" | sed 's/-linux-musl/-musl-linux/'`
148 [ "$tool" != "$btool" -a ! -e "$btool" ] && ln -s $tool $btool
149 done
152 exit 0