forked from GregorR/musl-cross
-
Notifications
You must be signed in to change notification settings - Fork 9
/
defs.sh
333 lines (283 loc) · 8.11 KB
/
defs.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# Definitions for build scripts
#
# Copyright (C) 2012-2014 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.
ORIGPWD="$PWD"
cd "$MUSL_CC_BASE"
MUSL_CC_BASE="$PWD"
export MUSL_CC_BASE
cd "$ORIGPWD"
unset ORIGPWD
if [ ! -e config.sh ]
then
echo 'Create a config.sh file.'
exit 1
fi
# Versions of things (do this before config.sh so they can be config'd)
BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.25.1.tar.bz2
#BINUTILS_URL=ftp://sourceware.org/pub/binutils/snapshots/binutils-2.24.90.tar.bz2
#last GPL2 release is 2.17, with backported -Bsymbolic support
#BINUTILS_URL=http://landley.net/aboriginal/mirror/binutils-2.17.tar.bz2
GCC_VERSION=5.3.0
GDB_VERSION=7.9.1
GMP_VERSION=6.1.0
MPC_VERSION=1.0.3
MPFR_VERSION=3.1.4
LIBELF_VERSION=master
# use kernel headers from vanilla linux kernel - may be necessary for porting to a bleeding-edge arch
# LINUX_HEADERS_URL=http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.12.6.tar.xz
# use patched sabotage-linux kernel-headers package (fixes userspace clashes of some kernel structs)
# from upstream repo https://github.com/sabotage-linux/kernel-headers
LINUX_HEADERS_URL=http://ftp.barfooze.de/pub/sabotage/tarballs/kernel-headers-3.12.6-5.tar.xz
# musl can optionally be checked out from GIT, in which case MUSL_VERSION must
# be set to a git tag and MUSL_GIT set to yes in config.sh
MUSL_DEFAULT_VERSION=1.1.12
MUSL_GIT_VERSION=615629bd6fcd6ddb69ad762e679f088c7bd878e2
MUSL_GIT_REPO='git://repo.or.cz/musl.git'
MUSL_VERSION="$MUSL_DEFAULT_VERSION"
MUSL_GIT=no
# You can choose languages
LANG_CXX=yes
LANG_OBJC=no
LANG_FORTRAN=no
. ./config.sh
# Auto-deteect an ARCH if not specified
if [ -z "$ARCH" ]
then
for MAYBECC in cc gcc clang
do
$MAYBECC -dumpmachine > /dev/null 2> /dev/null &&
ARCH=`$MAYBECC -dumpmachine | sed 's/-.*//'` &&
break
done
unset MAYBECC
[ -z "$ARCH" ] && ARCH=`uname -m`
fi
# Auto-detect a TRIPLE if not specified
if [ -z "$TRIPLE" ]
then
case "$ARCH" in
armhf)
ARCH="arm"
TRIPLE="$ARCH-linux-musleabihf"
;;
arm*)
TRIPLE="$ARCH-linux-musleabi"
;;
x32)
TRIPLE="x86_64-x32-linux-musl"
;;
*)
TRIPLE="$ARCH-linux-musl"
;;
esac
fi
# Choose our languages
LANGUAGES=c
[ "$LANG_CXX" = "yes" ] && LANGUAGES="$LANGUAGES,c++"
[ "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,objc"
[ "$LANG_CXX" = "yes" -a "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,obj-c++"
[ "$LANG_FORTRAN" = "yes" ] && LANGUAGES="$LANGUAGES,fortran"
# Use gmake if it exists
if [ -z "$MAKE" ]
then
MAKE=make
gmake --help > /dev/null 2>&1 && MAKE=gmake
fi
# Generate CC_PREFIX from CC_BASE_PREFIX and TRIPLE if not specified
[ -n "$CC_BASE_PREFIX" -a -z "$CC_PREFIX" ] && CC_PREFIX="$CC_BASE_PREFIX/$TRIPLE"
[ -z "$CC_PREFIX" ] && die 'Failed to determine a CC_PREFIX.'
PATH="$CC_PREFIX/bin:$PATH"
export PATH
# Get our Linux arch and defconfig
LINUX_ARCH=`echo "$ARCH" | sed 's/-.*//'`
LINUX_DEFCONFIG=defconfig
case "$LINUX_ARCH" in
i*86) LINUX_ARCH=i386 ;;
x32) LINUX_ARCH=x86_64 ;;
arm*) LINUX_ARCH=arm ;;
aarch64*) LINUX_ARCH=arm64 ;;
mips*) LINUX_ARCH=mips ;;
or1k*) LINUX_ARCH=openrisc ;;
sh*) LINUX_ARCH=sh ;;
powerpc* | ppc*)
LINUX_ARCH=powerpc
LINUX_DEFCONFIG=g5_defconfig
;;
microblaze)
LINUX_DEFCONFIG=mmu_defconfig
;;
esac
export LINUX_ARCH
# Get the target-specific multilib option, if applicable
GCC_MULTILIB_CONFFLAGS="--disable-multilib --with-multilib-list="
if [ "$ARCH" = "x32" ]
then
GCC_MULTILIB_CONFFLAGS="--with-multilib-list=mx32"
fi
die() {
echo "$@"
exit 1
}
fetch() {
if [ ! -e "$MUSL_CC_BASE/tarballs/$2" ]
then
wget -O "$MUSL_CC_BASE/tarballs/$2.part" -c "$1""$2"
mv "$MUSL_CC_BASE/tarballs/$2.part" "$MUSL_CC_BASE/tarballs/$2"
fi
return 0
}
extract() {
if [ ! -e "$2/extracted" ]
then
tar xf "$MUSL_CC_BASE/tarballs/$1" ||
tar Jxf "$MUSL_CC_BASE/tarballs/$1" ||
tar jxf "$MUSL_CC_BASE/tarballs/$1" ||
tar zxf "$MUSL_CC_BASE/tarballs/$1"
mkdir -p "$2"
touch "$2/extracted"
fi
}
stripfileext() {
case "$1" in
*.tar.*) printf "%s" "$1"| sed 's/\.tar\.[0-9a-z]*$//' ;;
*) basename "$1" | sed 's/\..*//' ;;
esac
}
fetchextract() {
baseurl="$1"
[ -z "$2" ] && baseurl=$(printf "%s" "$1" | sed 's/\(.*\/\).*/\1/')
dir="$2"
[ -z "$dir" ] && dir=$(stripfileext $(basename "$1"))
fn="$2""$3"
[ -z "$fn" ] && fn=$(basename "$1")
fetch "$baseurl" "$fn"
extract "$fn" "$dir"
}
gitfetchextract() {
if [ ! -e "$MUSL_CC_BASE/tarballs/$3".tar.gz ]
then
git archive --format=tar --remote="$1" "$2" | \
gzip -c > "$MUSL_CC_BASE/tarballs/$3".tar.gz || die "Failed to fetch $3-$2"
fi
if [ ! -e "$3/extracted" ]
then
mkdir -p "$3"
(
cd "$3" || die "Failed to cd $3"
extract "$3".tar.gz extracted
touch extracted
)
fi
}
muslfetchextract() {
if [ "$MUSL_GIT" = "yes" ]
then
gitfetchextract "$MUSL_GIT_REPO" $MUSL_VERSION musl-$MUSL_VERSION
else
fetchextract http://www.musl-libc.org/releases/ musl-$MUSL_VERSION .tar.gz
fi
}
gccprereqs() {
if [ ! -e gcc-$GCC_VERSION/gmp ]
then
fetchextract http://gmplib.org/download/gmp/ gmp-$GMP_VERSION .tar.bz2
mv gmp-$GMP_VERSION gcc-$GCC_VERSION/gmp
fi
if [ ! -e gcc-$GCC_VERSION/mpfr ]
then
fetchextract http://ftp.gnu.org/gnu/mpfr/ mpfr-$MPFR_VERSION .tar.bz2
mv mpfr-$MPFR_VERSION gcc-$GCC_VERSION/mpfr
fi
if [ ! -e gcc-$GCC_VERSION/mpc ]
then
fetchextract http://www.multiprecision.org/mpc/download/ mpc-$MPC_VERSION .tar.gz
mv mpc-$MPC_VERSION gcc-$GCC_VERSION/mpc
fi
}
patch_source() {
BD="$1"
(
cd "$BD" || die "Failed to cd $BD"
if [ ! -e patched ]
then
for f in "$MUSL_CC_BASE/patches/$BD"-*.diff ; do
if [ -e "$f" ] ; then patch -p1 < "$f" || die "Failed to apply patch $f to $BD" ; fi
done
touch patched
fi
)
}
build() {
BP="$1"
BD="$2"
CF="./configure"
BUILT="$PWD/$BD/built$BP"
shift; shift
if [ ! -e "$BUILT" ]
then
patch_source "$BD"
(
cd "$BD" || die "Failed to cd $BD"
if [ "$BP" ]
then
mkdir -p build"$BP"
cd build"$BP" || die "Failed to cd to build dir for $BD $BP"
CF="../configure"
fi
( $CF --prefix="$PREFIX" "$@" &&
$MAKE $MAKEFLAGS &&
touch "$BUILT" ) ||
die "Failed to build $BD"
)
fi
}
buildmake() {
BD="$1"
BUILT="$PWD/$BD/built"
shift
if [ ! -e "$BUILT" ]
then
patch_source "$BD"
(
cd "$BD" || die "Failed to cd $BD"
( $MAKE "$@" $MAKEFLAGS &&
touch "$BUILT" ) ||
die "Failed to build $BD"
)
fi
}
doinstall() {
BP="$1"
BD="$2"
INSTALLED="$PWD/$BD/installed$BP"
shift; shift
if [ ! -e "$INSTALLED" ]
then
(
cd "$BD" || die "Failed to cd $BD"
if [ "$BP" ]
then
cd build"$BP" || die "Failed to cd build$BP"
fi
( $MAKE install "$@" $MAKEINSTALLFLAGS &&
touch "$INSTALLED" ) ||
die "Failed to install $BP"
)
fi
}
buildinstall() {
build "$@"
doinstall "$1" "$2"
}