1 # Definitions for build scripts
3 # Copyright (C) 2012 Gregor Richards
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.
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.
26 echo 'Create a config.sh file.'
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
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"
56 # You can choose languages
63 # Auto-deteect an ARCH if not specified
66 for MAYBECC
in cc gcc clang
68 $MAYBECC -dumpmachine > /dev
/null
2> /dev
/null
&&
69 ARCH
=`$MAYBECC -dumpmachine | sed 's/-.*//'` &&
74 [ -z "$ARCH" ] && ARCH
=`uname -m`
77 # Auto-detect a TRIPLE if not specified
83 TRIPLE
="$ARCH-linux-musleabihf"
87 TRIPLE
="$ARCH-linux-musleabi"
91 TRIPLE
="aarch64-linux-musl"
95 TRIPLE
="x86_64-x32-linux-musl"
99 TRIPLE
="$ARCH-linux-musl"
104 # Choose our languages
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
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"
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
;;
137 LINUX_DEFCONFIG
=g5_defconfig
141 LINUX_DEFCONFIG
=mmu_defconfig
146 # Get the target-specific multilib option, if applicable
147 GCC_MULTILIB_CONFFLAGS
="--disable-multilib"
148 if [ "$ARCH" = "x32" ]
150 GCC_MULTILIB_CONFFLAGS
="--with-multilib-list=mx32"
159 if [ ! -e "$MUSL_CC_BASE/tarballs/$2" ]
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"
168 if [ ! -e "$2/extracted" ]
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"
181 *.
tar.
*) printf "%s" "$1"|
sed 's/\.tar\.[0-9a-z]*$//' ;;
182 *) basename "$1" |
sed 's/\..*//' ;;
188 [ -z "$2" ] && baseurl
=$
(printf "%s" "$1" |
sed 's/\(.*\/\).*/\1/')
190 [ -z "$dir" ] && dir
=$
(stripfileext $
(basename "$1"))
192 [ -z "$fn" ] && fn
=$
(basename "$1")
194 fetch
"$baseurl" "$fn"
199 if [ ! -e "$MUSL_CC_BASE/tarballs/$3".
tar.gz
]
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" ]
208 cd "$3" || die
"Failed to cd $3"
209 extract
"$3".
tar.gz extracted
216 if [ "$MUSL_GIT" = "yes" ]
218 gitfetchextract
"$MUSL_GIT_REPO" $MUSL_VERSION musl-
$MUSL_VERSION
220 fetchextract http
://www.musl-libc.org
/releases
/ musl-
$MUSL_VERSION .
tar.gz
225 if [ ! -e gcc-
$GCC_VERSION/gmp
]
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
]
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
]
239 fetchextract http
://www.multiprecision.org
/mpc
/download
/ mpc-
$MPC_VERSION .
tar.gz
240 mv mpc-
$MPC_VERSION gcc-
$GCC_VERSION/mpc
248 cd "$BD" || die
"Failed to cd $BD"
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
264 BUILT
="$PWD/$BD/built$BP"
272 cd "$BD" || die
"Failed to cd $BD"
277 cd build
"$BP" || die
"Failed to cd to build dir for $BD $BP"
280 ( $CF --prefix="$PREFIX" "$@" &&
283 die
"Failed to build $BD"
291 BUILT
="$PWD/$BD/built"
299 cd "$BD" || die
"Failed to cd $BD"
301 ( $MAKE "$@" $MAKEFLAGS &&
303 die
"Failed to build $BD"
312 INSTALLED
="$PWD/$BD/installed$BP"
315 if [ ! -e "$INSTALLED" ]
318 cd "$BD" || die
"Failed to cd $BD"
322 cd build
"$BP" || die
"Failed to cd build$BP"
325 ( $MAKE install "$@" $MAKEINSTALLFLAGS &&
326 touch "$INSTALLED" ) ||
327 die
"Failed to install $BP"