set MAKETHREADS from the number of cores counted
[busybox-power] / build.sh
1 #!/bin/sh
2 # Helper script to build busybox-power
3 # Please run me from within Scratchbox
4 #
5 # Run `sh build.sh thumb` to enable the thumb ISA. Make sure your Scratchbox
6 # target is properly set up to compile thumb binaries.
7 # Instructions to set up a Fremantle thumb target in Scratchbox:
8 # http://talk.maemo.org/showpost.php?p=1223814&postcount=164
9
10 BBVERSION="1.20.1"
11 MAKETHREADS=`grep -i 'processor.:' /proc/cpuinfo |wc -l`
12 if [ -z "$MAKETHREADS" -o "$MAKETHREADS" -eq 0 ] ; then MAKETHREADS=1; fi
13 SCRIPTDIR=`dirname $(readlink -f $0)`
14 BUILDDIR="$SCRIPTDIR/../busybox-power-build"
15 VERSION_DEBIAN=`cat $SCRIPTDIR/debian/changelog | awk -F'[()]' '{if(NR==1) print $2}'`
16
17 BUILD_OPTIONS="parallel=$MAKETHREADS"
18 THUMB=false
19
20 if [ "$1" == "thumb" ]; then
21   THUMB=true; fi
22
23 hash wget 2>&- || { 
24   echo >&2 "this script requires wget, exiting now"
25   exit 1 
26 }
27
28 mkdir -p $BUILDDIR
29 cd $BUILDDIR
30
31 if ! test -e busybox-$BBVERSION.tar.bz2; then
32   wget http://busybox.net/downloads/busybox-$BBVERSION.tar.bz2; fi
33
34 if test -d busybox-$BBVERSION/; then
35   echo "`pwd`/busybox-$BBVERSION already exists,"
36   echo "please (re)move it before rerunning this script"
37   exit 1
38 fi
39
40 tar -jxf busybox-$BBVERSION.tar.bz2
41 cp -af $SCRIPTDIR/debian/ busybox-$BBVERSION/
42
43 if $THUMB; then
44   # Append "~thumb" to the package's Debian version string
45   # NB: we feed sed directly with $VERSION_DEBIAN, it is not escaped in any way
46   sed -i "s/$VERSION_DEBIAN/$VERSION_DEBIAN~thumb/" busybox-$BBVERSION/debian/changelog
47   BUILD_OPTIONS="$BUILD_OPTIONS,thumb,vfp"
48 fi
49
50 # Build
51 cd busybox-$BBVERSION/ && DEB_BUILD_OPTIONS="$BUILD_OPTIONS" dpkg-buildpackage -r"fakeroot -u" -uc -us -nc