add psp gcc 11.2.0 patch
[rofl0r-mmix-cross.git] / extra / build-tarballs.sh
blob804631935908f24cb731589fda75626e8c519714
1 #!/bin/sh
2 # Build tarballs of various musl cross-compilers
4 # Example invocation:
5 # build-tarballs.sh /opt/cross/musl crossx86- -1.1 i486 x86_64 x32 arm \
6 # armeb armhf microblaze mips mipsel mips-sf mipsel-sf powerpc sh4 sh4eb
7 #
8 # Copyright (C) 2012-2014 Gregor Richards
9 #
10 # Permission to use, copy, modify, and/or distribute this software for any
11 # purpose with or without fee is hereby granted, provided that the above
12 # copyright notice and this permission notice appear in all copies.
14 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16 # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 # PERFORMANCE OF THIS SOFTWARE.
22 if [ ! "$MUSL_CC_BASE" ]
23 then
24 MUSL_CC_BASE=`dirname "$0"`/..
27 set -ex
29 # Figure out our id
30 HG_ID=`cd "$MUSL_CC_BASE" ; hg id | sed 's/ .*//'`
32 cleanup() {
33 for pkg in binutils gcc linux kernel-headers musl gmp mpfr mpc
35 for bf in configured build built installed
37 rm -rf $pkg-*/$bf*
38 done
39 done
40 unset bf
42 for pkg in musl-*/ gmp-*/ mpfr-*/ mpc-*/
45 cd $pkg &&
46 make distclean || true
48 done
49 unset pkg
52 if [ -e config.sh ]
53 then
54 echo 'Please use a fresh directory.'
55 exit 1
57 touch extraconfig.sh
59 if [ ! "$4" ]
60 then
61 echo 'Use: .../build-tarballs.sh <install prefix> <tarball prefix> <tarball suffix> <native arch> [other archs]'
62 exit 1
65 PREFIX_BASE="$1"
66 shift
67 T_PRE="$1"
68 shift
69 T_SUFF="$1"
70 shift
71 NATIVE_ARCH="$1"
73 for ARCH in "$@"
75 case "$ARCH" in
76 armhf)
77 TRIPLE="arm-linux-musleabihf"
79 arm*)
80 TRIPLE="$ARCH-linux-musleabi"
82 x32)
83 TRIPLE="x86_64-x32-linux-musl"
86 TRIPLE="$ARCH-linux-musl"
88 esac
90 if [ "$ARCH" = "$NATIVE_ARCH" ]
91 then
92 if [ ! -e "$PREFIX_BASE/bootstrap/bin/$TRIPLE-g++" ]
93 then
94 # Make the config.sh
95 echo 'ARCH='$ARCH'
96 TRIPLE='$TRIPLE'
97 CC_PREFIX="'"$PREFIX_BASE/bootstrap"'"
98 MAKEFLAGS="'"$MAKEFLAGS"'"
99 . ./extraconfig.sh' > config.sh
101 # Build the bootstrap one first
102 "$MUSL_CC_BASE"/build.sh
103 "$MUSL_CC_BASE"/extra/build-gcc-deps.sh
104 rm -f config.sh
105 cleanup
108 NATIVE_CROSS="$PREFIX_BASE/bootstrap/bin/$TRIPLE"
110 # Get rid of dlfcn.h as a cheap hack to disable building plugins
111 rm -f "$PREFIX_BASE/bootstrap/$TRIPLE/include/dlfcn.h"
114 if [ ! -e "$PREFIX_BASE/$TRIPLE/bin/$TRIPLE-g++" ]
115 then
116 # Make the config.sh
117 echo 'ARCH='$ARCH'
118 TRIPLE='$TRIPLE'
119 CC_PREFIX="'"$PREFIX_BASE/$TRIPLE"'"
120 MAKEFLAGS="'"$MAKEFLAGS"'"
121 CC="'"$NATIVE_CROSS-gcc"' -static -Wl,-Bstatic -static-libgcc"
122 CXX="'"$NATIVE_CROSS-g++"' -static -Wl,-Bstatic -static-libgcc"
123 export CC CXX
124 GCC_BOOTSTRAP_CONFFLAGS=--disable-lto-plugin
125 GCC_CONFFLAGS=--disable-lto-plugin
126 . ./extraconfig.sh' > config.sh
128 # And build
129 "$MUSL_CC_BASE"/build.sh
130 sed -E '/^C(C|XX)=/d ; /^export/d' -i config.sh
131 [ "$NO_GCC_DEPS" != "yes"] && "$MUSL_CC_BASE"/extra/build-gcc-deps.sh
133 # Clean up
134 rm -f config.sh
135 cleanup
137 # Make the tarball
138 cp -f extraconfig.sh "$PREFIX_BASE/$TRIPLE/extraconfig.sh"
140 cd "$PREFIX_BASE"
141 rm -rf "$TRIPLE/share"
142 find "$TRIPLE/bin" "$TRIPLE/libexec/gcc" -type f -exec "$NATIVE_CROSS-strip" --strip-unneeded '{}' ';'
143 echo 'Cross-compiler prefix built by musl-cross '"$HG_ID"': http://www.bitbucket.org/GregorR/musl-cross' > "$TRIPLE/info.txt"
144 tar -cf - "$TRIPLE/" | xz -c > "$T_PRE$TRIPLE$T_SUFF.tar.xz"
147 done