forked from GregorR/musl-cross
-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.sh
executable file
·152 lines (132 loc) · 4.35 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
# Build a cross-compiler
#
# Copyright (C) 2012 Gregor Richards
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
if [ ! "$MUSL_CC_BASE" ]
then
MUSL_CC_BASE=`dirname "$0"`
fi
# Fail on any command failing, show commands:
set -ex
BINUTILS_CONFFLAGS=
GCC_BOOTSTRAP_CONFFLAGS=
MUSL_CONFFLAGS=
GCC_CONFFLAGS=
WITH_SYSROOT=no
. "$MUSL_CC_BASE"/defs.sh
# Switch to the CC prefix for all of this
PREFIX="$CC_PREFIX"
# make the sysroot usr directory
if [ ! -e "$PREFIX"/"$TRIPLE"/usr ]
then
mkdir -p "$PREFIX"/"$TRIPLE"
ln -sf . "$PREFIX"/"$TRIPLE"/usr
fi
if [ "$WITH_SYSROOT" = "yes" ]
then
SYSROOT_FLAGS="--with-sysroot=""$PREFIX"/"$TRIPLE"
fi
# binutils
fetchextract "$BINUTILS_URL"
BINUTILS_DIR=$(stripfileext $(basename $BINUTILS_URL))
sed -i -e 's,MAKEINFO="$MISSING makeinfo",MAKEINFO=true,g' \
$BINUTILS_DIR/configure
buildinstall 1 $BINUTILS_DIR --target=$TRIPLE --disable-werror $SYSROOT_FLAGS \
$BINUTILS_CONFFLAGS
# gcc 1
if [ -z $GCC_URL ];
then
fetchextract http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/ gcc-$GCC_VERSION .tar.bz2
else
fetchextract "$GCC_URL"
if [ -e $GCC_EXTRACT_DIR ]; then
mv $GCC_EXTRACT_DIR gcc-$GCC_VERSION
fi
fi
[ "$GCC_BUILTIN_PREREQS" = "yes" ] && gccprereqs
# gcc 1 is only used to bootstrap musl and gcc 2, so it is pointless to
# optimize it.
# If GCC_STAGE1_NOOPT is set, we build it without optimization and debug info,
# which reduces overall build time considerably.
SAVE_CFLAGS="$CFLAGS"
SAVE_CXXFLAGS="$CXXFLAGS"
if [ -z "$GCC_STAGE1_NOOPT" ]; then GCC_STAGE1_NOOPT=0; fi
if [ "$GCC_STAGE1_NOOPT" -ne 0 ]
then
export CFLAGS="-O0 -g0"
export CXXFLAGS="-O0 -g0"
fi
buildinstall 1 gcc-$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
--enable-languages=c --with-newlib --disable-libssp --disable-nls \
--disable-libquadmath --disable-threads --disable-decimal-float \
--disable-shared --disable-libmudflap --disable-libgomp --disable-libatomic \
$GCC_MULTILIB_CONFFLAGS \
$GCC_BOOTSTRAP_CONFFLAGS
export CFLAGS="$SAVE_CFLAGS"
export CXXFLAGS="$SAVE_CXXFLAGS"
# linux headers
fetchextract $LINUX_HEADERS_URL
LINUX_HEADERS_DIR=$(stripfileext $(basename $LINUX_HEADERS_URL))
if [ ! -e $LINUX_HEADERS_DIR/configured ]
then
(
cd $LINUX_HEADERS_DIR
make $LINUX_DEFCONFIG ARCH=$LINUX_ARCH
touch configured
)
fi
if [ ! -e $LINUX_HEADERS_DIR/installedheaders ]
then
(
cd $LINUX_HEADERS_DIR
make headers_install ARCH=$LINUX_ARCH INSTALL_HDR_PATH="$CC_PREFIX/$TRIPLE"
touch installedheaders
)
fi
if [ "$MUSL_VERSION" != "no" ]
then
# musl in CC prefix
PREFIX="$CC_PREFIX/$TRIPLE"
muslfetchextract
# We set both CROSS_COMPILE and CC because CC in the environment overrides
# and CROSS_COMPILE setting
buildinstall '' musl-$MUSL_VERSION \
--enable-debug --enable-optimize CROSS_COMPILE="$TRIPLE-" CC="$TRIPLE-gcc" $MUSL_CONFFLAGS
unset PREFIX
PREFIX="$CC_PREFIX"
# if it didn't build libc.so, disable dynamic linking
if [ ! -e "$CC_PREFIX/$TRIPLE/lib/libc.so" ]
then
GCC_CONFFLAGS="--disable-shared $GCC_CONFFLAGS"
fi
# gcc 2
buildinstall 2 gcc-$GCC_VERSION --target=$TRIPLE $SYSROOT_FLAGS \
--enable-languages=$LANGUAGES --disable-libmudflap \
--disable-libsanitizer --disable-nls \
$GCC_MULTILIB_CONFFLAGS \
$GCC_CONFFLAGS
fi
# un"fix" headers
rm -rf "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include-fixed/ "$CC_PREFIX/lib/gcc/$TRIPLE"/*/include/stddef.h
# make backwards-named compilers for easier cross-compiling
(
cd "$CC_PREFIX/bin"
for tool in $TRIPLE-*
do
btool=`echo "$tool" | sed 's/-linux-musl/-musl-linux/'`
[ "$tool" != "$btool" -a ! -e "$btool" ] && ln -s $tool $btool
done
)
exit 0