make it possible to use binutils tarball which is not from gnu.org (e.g. snapshots)
[rofl0r-mmix-cross.git] / extra / build-tarballs.sh
blob988c75224fbcd792923bc8e144ba0de12e4e0c3e
1 #!/bin/sh
2 # Build tarballs of various musl cross-compilers
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 set -ex
25 # Figure out our id
26 HG_ID=`cd "$MUSL_CC_BASE" ; hg id | sed 's/ .*//'`
28 cleanup() {
29 for pkg in binutils gcc linux musl gmp mpfr mpc
31 for bf in configured build built installed
33 rm -rf $pkg-*/$bf*
34 done
35 done
36 unset bf
38 for pkg in musl-*/ gmp-*/ mpfr-*/ mpc-*/
41 cd $pkg &&
42 make distclean || true
44 done
45 unset pkg
48 if [ -e config.sh ]
49 then
50 echo 'Please use a fresh directory.'
51 exit 1
53 touch extraconfig.sh
55 if [ ! "$4" ]
56 then
57 echo 'Use: .../build-tarballs.sh <install prefix> <tarball prefix> <tarball suffix> <native arch> [other archs]'
58 exit 1
61 PREFIX_BASE="$1"
62 shift
63 T_PRE="$1"
64 shift
65 T_SUFF="$1"
66 shift
67 NATIVE_ARCH="$1"
69 for ARCH in "$@"
71 case "$ARCH" in
72 armhf)
73 ARCH="arm"
74 TRIPLE="arm-linux-musleabihf"
76 arm*)
77 TRIPLE="$ARCH-linux-musleabi"
80 TRIPLE="$ARCH-linux-musl"
82 esac
84 if [ "$ARCH" = "$NATIVE_ARCH" ]
85 then
86 if [ ! -e "$PREFIX_BASE/bootstrap/bin/$TRIPLE-g++" ]
87 then
88 # Make the config.sh
89 echo 'ARCH='$ARCH'
90 TRIPLE='$TRIPLE'
91 CC_PREFIX="'"$PREFIX_BASE/bootstrap"'"
92 MAKEFLAGS="'"$MAKEFLAGS"'"
93 . ./extraconfig.sh' > config.sh
95 # Build the bootstrap one first
96 "$MUSL_CC_BASE"/build.sh
97 "$MUSL_CC_BASE"/extra/build-gcc-deps.sh
98 rm -f config.sh
99 cleanup
102 NATIVE_CROSS="$PREFIX_BASE/bootstrap/bin/$TRIPLE"
104 # Get rid of dlfcn.h as a cheap hack to disable building plugins
105 rm -f "$PREFIX_BASE/bootstrap/$TRIPLE/include/dlfcn.h"
108 if [ ! -e "$PREFIX_BASE/$TRIPLE/bin/$TRIPLE-g++" ]
109 then
110 # Make the config.sh
111 echo 'ARCH='$ARCH'
112 TRIPLE='$TRIPLE'
113 CC_PREFIX="'"$PREFIX_BASE/$TRIPLE"'"
114 MAKEFLAGS="'"$MAKEFLAGS"'"
115 CC="'"$NATIVE_CROSS-gcc"' -static -Wl,-Bstatic -static-libgcc"
116 CXX="'"$NATIVE_CROSS-g++"' -static -Wl,-Bstatic -static-libgcc"
117 export CC CXX
118 GCC_BOOTSTRAP_CONFFLAGS=--disable-lto-plugin
119 GCC_CONFFLAGS=--disable-lto-plugin
120 . ./extraconfig.sh' > config.sh
122 # And build
123 "$MUSL_CC_BASE"/build.sh
124 sed -E '/^C(C|XX)=/d ; /^export/d' -i config.sh
125 [ "$NO_GCC_DEPS" != "yes"] && "$MUSL_CC_BASE"/extra/build-gcc-deps.sh
127 # Clean up
128 rm -f config.sh
129 cleanup
131 # Make the tarball
132 cp -f extraconfig.sh "$PREFIX_BASE/$TRIPLE/extraconfig.sh"
134 cd "$PREFIX_BASE"
135 rm -rf "$TRIPLE/share"
136 find "$TRIPLE/bin" "$TRIPLE/libexec/gcc" -type f -exec "$NATIVE_CROSS-strip" --strip-unneeded '{}' ';'
137 echo 'Cross-compiler prefix built by musl-cross '"$HG_ID"': http://www.bitbucket.org/GregorR/musl-cross' > "$TRIPLE/info.txt"
138 tar -cf - "$TRIPLE/" | xz -c > "$T_PRE$TRIPLE$T_SUFF.tar.xz"
141 done