bump musl to 1.1.18
[rofl0r-mmix-cross.git] / defs.sh
blobf76a2ac24ce07a4a9106494782114ff303b6a248
1 # Definitions for build scripts
2 #
3 # Copyright (C) 2012-2014 Gregor Richards
4 #
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
17 ORIGPWD="$PWD"
18 cd "$MUSL_CC_BASE"
19 MUSL_CC_BASE="$PWD"
20 export MUSL_CC_BASE
21 cd "$ORIGPWD"
22 unset ORIGPWD
24 if [ ! -e config.sh ]
25 then
26 echo 'Create a config.sh file.'
27 exit 1
30 # Versions of things (do this before config.sh so they can be config'd)
31 BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.25.1.tar.bz2
32 #BINUTILS_URL=ftp://sourceware.org/pub/binutils/snapshots/binutils-2.24.90.tar.bz2
33 #last GPL2 release is 2.17, with backported -Bsymbolic support
34 #BINUTILS_URL=http://landley.net/aboriginal/mirror/binutils-2.17.tar.bz2
35 GCC_VERSION=5.3.0
36 GDB_VERSION=7.9.1
37 GMP_VERSION=6.1.0
38 MPC_VERSION=1.0.3
39 MPFR_VERSION=3.1.4
40 LIBELF_VERSION=master
41 # use kernel headers from vanilla linux kernel - may be necessary for porting to a bleeding-edge arch
42 # LINUX_HEADERS_URL=http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.12.6.tar.xz
43 # use patched sabotage-linux kernel-headers package (fixes userspace clashes of some kernel structs)
44 # from upstream repo https://github.com/sabotage-linux/kernel-headers
45 LINUX_HEADERS_URL=http://ftp.barfooze.de/pub/sabotage/tarballs/kernel-headers-3.12.6-5.tar.xz
47 # musl can optionally be checked out from GIT, in which case MUSL_VERSION must
48 # be set to a git tag and MUSL_GIT set to yes in config.sh
49 MUSL_DEFAULT_VERSION=1.1.18
50 MUSL_GIT_VERSION=eb03bde2f24582874cb72b56c7811bf51da0c817
51 MUSL_GIT_REPO='git://repo.or.cz/musl.git'
52 MUSL_VERSION="$MUSL_DEFAULT_VERSION"
53 MUSL_GIT=no
55 # You can choose languages
56 LANG_CXX=yes
57 LANG_OBJC=no
58 LANG_FORTRAN=no
60 . ./config.sh
62 # Auto-deteect an ARCH if not specified
63 if [ -z "$ARCH" ]
64 then
65 for MAYBECC in cc gcc clang
67 $MAYBECC -dumpmachine > /dev/null 2> /dev/null &&
68 ARCH=`$MAYBECC -dumpmachine | sed 's/-.*//'` &&
69 break
70 done
71 unset MAYBECC
73 [ -z "$ARCH" ] && ARCH=`uname -m`
76 # Auto-detect a TRIPLE if not specified
77 if [ -z "$TRIPLE" ]
78 then
79 case "$ARCH" in
80 armhf)
81 ARCH="arm"
82 TRIPLE="$ARCH-linux-musleabihf"
85 arm*)
86 TRIPLE="$ARCH-linux-musleabi"
89 x32)
90 TRIPLE="x86_64-x32-linux-musl"
94 TRIPLE="$ARCH-linux-musl"
96 esac
99 # Choose our languages
100 LANGUAGES=c
101 [ "$LANG_CXX" = "yes" ] && LANGUAGES="$LANGUAGES,c++"
102 [ "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,objc"
103 [ "$LANG_CXX" = "yes" -a "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,obj-c++"
104 [ "$LANG_FORTRAN" = "yes" ] && LANGUAGES="$LANGUAGES,fortran"
106 # Use gmake if it exists
107 if [ -z "$MAKE" ]
108 then
109 MAKE=make
110 gmake --help > /dev/null 2>&1 && MAKE=gmake
113 # Generate CC_PREFIX from CC_BASE_PREFIX and TRIPLE if not specified
114 [ -n "$CC_BASE_PREFIX" -a -z "$CC_PREFIX" ] && CC_PREFIX="$CC_BASE_PREFIX/$TRIPLE"
115 [ -z "$CC_PREFIX" ] && die 'Failed to determine a CC_PREFIX.'
117 PATH="$CC_PREFIX/bin:$PATH"
118 export PATH
120 # Get our Linux arch and defconfig
121 LINUX_ARCH=`echo "$ARCH" | sed 's/-.*//'`
122 LINUX_DEFCONFIG=defconfig
123 case "$LINUX_ARCH" in
124 i*86) LINUX_ARCH=i386 ;;
125 x32) LINUX_ARCH=x86_64 ;;
126 arm*) LINUX_ARCH=arm ;;
127 aarch64*) LINUX_ARCH=arm64 ;;
128 mips*) LINUX_ARCH=mips ;;
129 or1k*) LINUX_ARCH=openrisc ;;
130 sh*) LINUX_ARCH=sh ;;
132 powerpc* | ppc*)
133 LINUX_ARCH=powerpc
134 LINUX_DEFCONFIG=g5_defconfig
137 microblaze)
138 LINUX_DEFCONFIG=mmu_defconfig
140 esac
141 export LINUX_ARCH
143 # Get the target-specific multilib option, if applicable
144 GCC_MULTILIB_CONFFLAGS="--disable-multilib --with-multilib-list="
145 if [ "$ARCH" = "x32" ]
146 then
147 GCC_MULTILIB_CONFFLAGS="--with-multilib-list=mx32"
150 die() {
151 echo "$@"
152 exit 1
155 fetch() {
156 if [ ! -e "$MUSL_CC_BASE/tarballs/$2" ]
157 then
158 wget -O "$MUSL_CC_BASE/tarballs/$2.part" -c "$1""$2"
159 mv "$MUSL_CC_BASE/tarballs/$2.part" "$MUSL_CC_BASE/tarballs/$2"
161 return 0
164 extract() {
165 if [ ! -e "$2/extracted" ]
166 then
167 tar xf "$MUSL_CC_BASE/tarballs/$1" ||
168 tar Jxf "$MUSL_CC_BASE/tarballs/$1" ||
169 tar jxf "$MUSL_CC_BASE/tarballs/$1" ||
170 tar zxf "$MUSL_CC_BASE/tarballs/$1"
171 mkdir -p "$2"
172 touch "$2/extracted"
176 stripfileext() {
177 case "$1" in
178 *.tar.*) printf "%s" "$1"| sed 's/\.tar\.[0-9a-z]*$//' ;;
179 *) basename "$1" | sed 's/\..*//' ;;
180 esac
183 fetchextract() {
184 baseurl="$1"
185 [ -z "$2" ] && baseurl=$(printf "%s" "$1" | sed 's/\(.*\/\).*/\1/')
186 dir="$2"
187 [ -z "$dir" ] && dir=$(stripfileext $(basename "$1"))
188 fn="$2""$3"
189 [ -z "$fn" ] && fn=$(basename "$1")
191 fetch "$baseurl" "$fn"
192 extract "$fn" "$dir"
195 gitfetchextract() {
196 if [ ! -e "$MUSL_CC_BASE/tarballs/$3".tar.gz ]
197 then
198 git archive --format=tar --remote="$1" "$2" | \
199 gzip -c > "$MUSL_CC_BASE/tarballs/$3".tar.gz || die "Failed to fetch $3-$2"
201 if [ ! -e "$3/extracted" ]
202 then
203 mkdir -p "$3"
205 cd "$3" || die "Failed to cd $3"
206 extract "$3".tar.gz extracted
207 touch extracted
212 muslfetchextract() {
213 if [ "$MUSL_GIT" = "yes" ]
214 then
215 gitfetchextract "$MUSL_GIT_REPO" $MUSL_VERSION musl-$MUSL_VERSION
216 else
217 fetchextract http://www.musl-libc.org/releases/ musl-$MUSL_VERSION .tar.gz
221 gccprereqs() {
222 if [ ! -e gcc-$GCC_VERSION/gmp ]
223 then
224 fetchextract http://gmplib.org/download/gmp/ gmp-$GMP_VERSION .tar.bz2
225 mv gmp-$GMP_VERSION gcc-$GCC_VERSION/gmp
228 if [ ! -e gcc-$GCC_VERSION/mpfr ]
229 then
230 fetchextract http://ftp.gnu.org/gnu/mpfr/ mpfr-$MPFR_VERSION .tar.bz2
231 mv mpfr-$MPFR_VERSION gcc-$GCC_VERSION/mpfr
234 if [ ! -e gcc-$GCC_VERSION/mpc ]
235 then
236 fetchextract http://www.multiprecision.org/mpc/download/ mpc-$MPC_VERSION .tar.gz
237 mv mpc-$MPC_VERSION gcc-$GCC_VERSION/mpc
241 patch_source() {
242 BD="$1"
245 cd "$BD" || die "Failed to cd $BD"
247 if [ ! -e patched ]
248 then
249 for f in "$MUSL_CC_BASE/patches/$BD"-*.diff ; do
250 if [ -e "$f" ] ; then patch -p1 < "$f" || die "Failed to apply patch $f to $BD" ; fi
251 done
252 touch patched
257 build() {
258 BP="$1"
259 BD="$2"
260 CF="./configure"
261 BUILT="$PWD/$BD/built$BP"
262 shift; shift
264 if [ ! -e "$BUILT" ]
265 then
266 patch_source "$BD"
269 cd "$BD" || die "Failed to cd $BD"
271 if [ "$BP" ]
272 then
273 mkdir -p build"$BP"
274 cd build"$BP" || die "Failed to cd to build dir for $BD $BP"
275 CF="../configure"
277 ( $CF --prefix="$PREFIX" "$@" &&
278 $MAKE $MAKEFLAGS &&
279 touch "$BUILT" ) ||
280 die "Failed to build $BD"
286 buildmake() {
287 BD="$1"
288 BUILT="$PWD/$BD/built"
289 shift
291 if [ ! -e "$BUILT" ]
292 then
293 patch_source "$BD"
296 cd "$BD" || die "Failed to cd $BD"
298 ( $MAKE "$@" $MAKEFLAGS &&
299 touch "$BUILT" ) ||
300 die "Failed to build $BD"
306 doinstall() {
307 BP="$1"
308 BD="$2"
309 INSTALLED="$PWD/$BD/installed$BP"
310 shift; shift
312 if [ ! -e "$INSTALLED" ]
313 then
315 cd "$BD" || die "Failed to cd $BD"
317 if [ "$BP" ]
318 then
319 cd build"$BP" || die "Failed to cd build$BP"
322 ( $MAKE install "$@" $MAKEINSTALLFLAGS &&
323 touch "$INSTALLED" ) ||
324 die "Failed to install $BP"
330 buildinstall() {
331 build "$@"
332 doinstall "$1" "$2"