binutils: add patch that fixes build without bash
[rofl0r-mmix-cross.git] / defs.sh
blob2e9ffc1422ae6a013234f4f369246cac70e8459d
1 # Definitions for build scripts
2 #
3 # Copyright (C) 2012 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.24.tar.bz2
32 #BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.22.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 #BINUTILS_URL=ftp://sourceware.org/pub/binutils/snapshots/binutils-2.24.51.tar.bz2
36 GCC_VERSION=4.8.3
37 GDB_VERSION=7.4.1
38 GMP_VERSION=4.3.2
39 MPC_VERSION=0.8.1
40 MPFR_VERSION=2.4.2
41 LIBELF_VERSION=71bf774909fd654d8167a475333fa8f37fbbcb5d
42 # use kernel headers from vanilla linux kernel - may be necessary for porting to a bleeding-edge arch
43 # LINUX_HEADERS_URL=http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.12.6.tar.xz
44 # use patched sabotage-linux kernel-headers package (fixes userspace clashes of some kernel structs)
45 # from upstream repo https://github.com/sabotage-linux/kernel-headers
46 LINUX_HEADERS_URL=http://ftp.barfooze.de/pub/sabotage/tarballs/kernel-headers-3.12.6-5.tar.xz
48 # musl can optionally be checked out from GIT, in which case MUSL_VERSION must
49 # be set to a git tag and MUSL_GIT set to yes in config.sh
50 MUSL_DEFAULT_VERSION=1.1.4
51 MUSL_GIT_VERSION=00733dd1cf791d13ff6155509cf139a5f7b2eecb
52 MUSL_GIT_REPO='git://repo.or.cz/musl.git'
53 MUSL_VERSION="$MUSL_DEFAULT_VERSION"
54 MUSL_GIT=no
56 # You can choose languages
57 LANG_CXX=yes
58 LANG_OBJC=no
59 LANG_FORTRAN=no
61 . ./config.sh
63 # Auto-deteect an ARCH if not specified
64 if [ -z "$ARCH" ]
65 then
66 for MAYBECC in cc gcc clang
68 $MAYBECC -dumpmachine > /dev/null 2> /dev/null &&
69 ARCH=`$MAYBECC -dumpmachine | sed 's/-.*//'` &&
70 break
71 done
72 unset MAYBECC
74 [ -z "$ARCH" ] && ARCH=`uname -m`
77 # Auto-detect a TRIPLE if not specified
78 if [ -z "$TRIPLE" ]
79 then
80 case "$ARCH" in
81 armhf)
82 ARCH="arm"
83 TRIPLE="$ARCH-linux-musleabihf"
86 arm*)
87 TRIPLE="$ARCH-linux-musleabi"
90 aarch64)
91 TRIPLE="aarch64-linux-musl"
94 x32)
95 TRIPLE="x86_64-x32-linux-musl"
99 TRIPLE="$ARCH-linux-musl"
101 esac
104 # Choose our languages
105 LANGUAGES=c
106 [ "$LANG_CXX" = "yes" ] && LANGUAGES="$LANGUAGES,c++"
107 [ "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,objc"
108 [ "$LANG_CXX" = "yes" -a "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,obj-c++"
109 [ "$LANG_FORTRAN" = "yes" ] && LANGUAGES="$LANGUAGES,fortran"
111 # Use gmake if it exists
112 if [ -z "$MAKE" ]
113 then
114 MAKE=make
115 gmake --help > /dev/null 2>&1 && MAKE=gmake
118 # Generate CC_PREFIX from CC_BASE_PREFIX and TRIPLE if not specified
119 [ -n "$CC_BASE_PREFIX" -a -z "$CC_PREFIX" ] && CC_PREFIX="$CC_BASE_PREFIX/$TRIPLE"
120 [ -z "$CC_PREFIX" ] && die 'Failed to determine a CC_PREFIX.'
122 PATH="$CC_PREFIX/bin:$PATH"
123 export PATH
125 # Get our Linux arch and defconfig
126 LINUX_ARCH=`echo "$ARCH" | sed 's/-.*//'`
127 LINUX_DEFCONFIG=defconfig
128 case "$LINUX_ARCH" in
129 i*86) LINUX_ARCH=i386 ;;
130 arm*) LINUX_ARCH=arm ;;
131 aarch64*) LINUX_ARCH=arm64 ;;
132 mips*) LINUX_ARCH=mips ;;
133 x32) LINUX_ARCH=x86_64 ;;
135 powerpc* | ppc*)
136 LINUX_ARCH=powerpc
137 LINUX_DEFCONFIG=g5_defconfig
140 microblaze)
141 LINUX_DEFCONFIG=mmu_defconfig
143 esac
144 export LINUX_ARCH
146 # Get the target-specific multilib option, if applicable
147 GCC_MULTILIB_CONFFLAGS="--disable-multilib"
148 if [ "$ARCH" = "x32" ]
149 then
150 GCC_MULTILIB_CONFFLAGS="--with-multilib-list=mx32"
153 die() {
154 echo "$@"
155 exit 1
158 fetch() {
159 if [ ! -e "$MUSL_CC_BASE/tarballs/$2" ]
160 then
161 wget -O "$MUSL_CC_BASE/tarballs/$2.part" -c "$1""$2"
162 mv "$MUSL_CC_BASE/tarballs/$2.part" "$MUSL_CC_BASE/tarballs/$2"
164 return 0
167 extract() {
168 if [ ! -e "$2/extracted" ]
169 then
170 tar xf "$MUSL_CC_BASE/tarballs/$1" ||
171 tar Jxf "$MUSL_CC_BASE/tarballs/$1" ||
172 tar jxf "$MUSL_CC_BASE/tarballs/$1" ||
173 tar zxf "$MUSL_CC_BASE/tarballs/$1"
174 mkdir -p "$2"
175 touch "$2/extracted"
179 stripfileext() {
180 case "$1" in
181 *.tar.*) printf "%s" "$1"| sed 's/\.tar\.[0-9a-z]*$//' ;;
182 *) basename "$1" | sed 's/\..*//' ;;
183 esac
186 fetchextract() {
187 baseurl="$1"
188 [ -z "$2" ] && baseurl=$(printf "%s" "$1" | sed 's/\(.*\/\).*/\1/')
189 dir="$2"
190 [ -z "$dir" ] && dir=$(stripfileext $(basename "$1"))
191 fn="$2""$3"
192 [ -z "$fn" ] && fn=$(basename "$1")
194 fetch "$baseurl" "$fn"
195 extract "$fn" "$dir"
198 gitfetchextract() {
199 if [ ! -e "$MUSL_CC_BASE/tarballs/$3".tar.gz ]
200 then
201 git archive --format=tar --remote="$1" "$2" | \
202 gzip -c > "$MUSL_CC_BASE/tarballs/$3".tar.gz || die "Failed to fetch $3-$2"
204 if [ ! -e "$3/extracted" ]
205 then
206 mkdir -p "$3"
208 cd "$3" || die "Failed to cd $3"
209 extract "$3".tar.gz extracted
210 touch extracted
215 muslfetchextract() {
216 if [ "$MUSL_GIT" = "yes" ]
217 then
218 gitfetchextract "$MUSL_GIT_REPO" $MUSL_VERSION musl-$MUSL_VERSION
219 else
220 fetchextract http://www.musl-libc.org/releases/ musl-$MUSL_VERSION .tar.gz
224 gccprereqs() {
225 if [ ! -e gcc-$GCC_VERSION/gmp ]
226 then
227 fetchextract ftp://ftp.gmplib.org/pub/gmp-$GMP_VERSION/ gmp-$GMP_VERSION .tar.bz2
228 mv gmp-$GMP_VERSION gcc-$GCC_VERSION/gmp
231 if [ ! -e gcc-$GCC_VERSION/mpfr ]
232 then
233 fetchextract http://ftp.gnu.org/gnu/mpfr/ mpfr-$MPFR_VERSION .tar.bz2
234 mv mpfr-$MPFR_VERSION gcc-$GCC_VERSION/mpfr
237 if [ ! -e gcc-$GCC_VERSION/mpc ]
238 then
239 fetchextract http://www.multiprecision.org/mpc/download/ mpc-$MPC_VERSION .tar.gz
240 mv mpc-$MPC_VERSION gcc-$GCC_VERSION/mpc
244 patch_source() {
245 BD="$1"
248 cd "$BD" || die "Failed to cd $BD"
250 if [ ! -e patched ]
251 then
252 for f in "$MUSL_CC_BASE/patches/$BD"-*.diff ; do
253 if [ -e "$f" ] ; then patch -p1 < "$f" || die "Failed to apply patch $f to $BD" ; fi
254 done
255 touch patched
260 build() {
261 BP="$1"
262 BD="$2"
263 CF="./configure"
264 BUILT="$PWD/$BD/built$BP"
265 shift; shift
267 if [ ! -e "$BUILT" ]
268 then
269 patch_source "$BD"
272 cd "$BD" || die "Failed to cd $BD"
274 if [ "$BP" ]
275 then
276 mkdir -p build"$BP"
277 cd build"$BP" || die "Failed to cd to build dir for $BD $BP"
278 CF="../configure"
280 ( $CF --prefix="$PREFIX" "$@" &&
281 $MAKE $MAKEFLAGS &&
282 touch "$BUILT" ) ||
283 die "Failed to build $BD"
289 buildmake() {
290 BD="$1"
291 BUILT="$PWD/$BD/built"
292 shift
294 if [ ! -e "$BUILT" ]
295 then
296 patch_source "$BD"
299 cd "$BD" || die "Failed to cd $BD"
301 ( $MAKE "$@" $MAKEFLAGS &&
302 touch "$BUILT" ) ||
303 die "Failed to build $BD"
309 doinstall() {
310 BP="$1"
311 BD="$2"
312 INSTALLED="$PWD/$BD/installed$BP"
313 shift; shift
315 if [ ! -e "$INSTALLED" ]
316 then
318 cd "$BD" || die "Failed to cd $BD"
320 if [ "$BP" ]
321 then
322 cd build"$BP" || die "Failed to cd build$BP"
325 ( $MAKE install "$@" $MAKEINSTALLFLAGS &&
326 touch "$INSTALLED" ) ||
327 die "Failed to install $BP"
333 buildinstall() {
334 build "$@"
335 doinstall "$1" "$2"