diff options
author | Lauri Leukkunen <lle@rahina.org> | 2007-09-11 21:52:54 +0300 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2007-09-11 21:52:54 +0300 |
commit | 63583e6ff03c89dac03a8179d0df5a0afde827bb (patch) | |
tree | ba5276003de05afa4b88213a5b64ab4d65bb9a4f /utils/sb2-init | |
parent | 0e2b6ef6f37169d692bd3b47ab44a947af014319 (diff) |
Add sb2-config, rework target setup
Targets no longer have any extra files in them, everything
lives under ~/.scratchbox2.
Per-target sb2 files go to ~/.scratchbox2/TARGETNAME
sb2-config can be used to list the available targets and to set
the default target.
Signed-off-by: Lauri Leukkunen <lle@rahina.org>
Diffstat (limited to 'utils/sb2-init')
-rwxr-xr-x | utils/sb2-init | 195 |
1 files changed, 136 insertions, 59 deletions
diff --git a/utils/sb2-init b/utils/sb2-init index a976d30..41d01ef 100755 --- a/utils/sb2-init +++ b/utils/sb2-init @@ -3,61 +3,48 @@ # Licensed under GPL version 2 -SBOX_DIR=$(readlink -f $(dirname $_)/..) +function usage() +{ + cat <<EOF +sb2-init - initialize a target root for scratchbox2 +Usage: + sb2-init [OPTION]... [TARGETNAME] [COMPILER] -if [[ "$1" = "" || "$1" = "--help" ]]; then - echo "Usage: sb2-init [compiler]" - echo "example: sb2-init arm-linux-gcc" - exit 0 -fi +sb2-init is expected to be run in the directory you want +to use as scratchbox 2 target root. -GCC=$1 +TARGETNAME is what you want to call this target +COMPILER is of the form $HOME/arm-2006q3/bin/arm-linux-gcc -GCC_FULLPATH=$(which $GCC) -# test that gcc exists and can be executed -if [ $? != 0 ]; then - echo "$GCC doesn't exist" - exit 1 -fi -GCC_PATH=$(dirname $(which $GCC)) -if [ $GCC -v > /dev/null 2>&1 != 0 ]; then - echo "Invalid compiler specified: $GCC" - exit 1 -fi -GCC_PREFIX=$(basename $GCC | sed 's/-gcc$/-/') -ARCH=$($GCC -dumpmachine | awk -F- '{ print $1 }') +Options: + -c [qemu | sbrsh] select cpu transparency method, qemu is default + -d set target as default scratchbox2 target + -h print this help + -n don't build libtool for the target + -s skip checks for target root's /usr/include etc. + -v display version -case "$ARCH" in - arm*) - SBOX_OS=none-linux-gnueabi - ;; - ppc*) - SBOX_OS=none-linux-gnu - ;; - mips*) - SBOX_OS=none-linux-gnu - ;; - *) - echo "Unsupported target architecture: $ARCH" - echo "You must add support for it into preload/sb_exec.c" - echo "and utils/sb2-init" - exit 1 - ;; +Examples: + sb2-init ARM arm-linux-gcc + sb2-init -sn -c sbrsh armel-debian /path/to/arm-linux-gcc +EOF + exit 2 +} -esac +function version() +{ + cat $SBOX_DIR/share/scratchbox2/version + exit 0 +} -QEMU=$(which qemu-$ARCH) -if [ $? != 0 ]; then - echo "You don't have qemu-$ARCH installed." - exit 1 -fi -function write_sb2config() +function write_target_config() { - cat - > sb2.config <<EOF + cat - > $HOME/.scratchbox2/$TARGET/sb2.config <<EOF # Scratchbox2 configuration file generated by sb2-init. +SBOX_TARGET_ROOT=$SBOX_TARGET_ROOT SBOX_CPU=$ARCH SBOX_OS=$SBOX_OS SBOX_CPUTRANSPARENCY_METHOD=$QEMU @@ -103,30 +90,120 @@ function check_buildroot_sanity() if [ $a_ok == 1 ]; then true else - false + echo "Your buildroot seems to lack basic essentials like headers +or c-library. You should probably get either a ready rootfs tarball or +copy the necessary files from your toolchain into place. After doing that +you can re-run this script." + exit 1 fi } -check_buildroot_sanity +SBOX_DIR=$(readlink -f $(dirname $_)/..) + +set_as_default=0 +cputransparency=qemu +with_libtool=1 +skip_checks=false + +if [ -z "$*" ]; then + usage +fi + +while getopts c:dhnsv foo +do + case $foo in + (c) cputransparency=$OPTARG ;; + (d) set_as_default=1 ;; + (h) usage ;; + (n) with_libtool=0 ;; + (s) skip_checks=true ;; + (v) version ;; + (*) usage ;; + esac +done +shift $(($OPTIND - 1)) + +TARGET=$1 +SBOX_TARGET_ROOT=$PWD +GCC=$2 + + +GCC_FULLPATH=$(which $GCC) +# test that gcc exists and can be executed if [ $? != 0 ]; then - echo "Your buildroot seems to lack basic essentials like headers -or c-library. You should probably get either a ready rootfs tarball or -copy the necessary files from your toolchain into place. After doing that -you can re-run this script." + echo "$GCC doesn't exist" + exit 1 +fi +GCC_PATH=$(dirname $(which $GCC)) +if [ $GCC -v > /dev/null 2>&1 != 0 ]; then + echo "Invalid compiler specified: $GCC" exit 1 fi -mkdir -p sb_tools/bin -write_sb2config +GCC_PREFIX=$(basename $GCC | sed 's/-gcc$/-/') +ARCH=$($GCC -dumpmachine | awk -F- '{ print $1 }') -$SBOX_DIR/bin/sb2 -t $PWD $SBOX_DIR/bin/sb2-build-libtool +case "$ARCH" in + arm*) + SBOX_OS=none-linux-gnueabi + ;; + ppc*) + SBOX_OS=none-linux-gnu + ;; + mips*) + SBOX_OS=none-linux-gnu + ;; + *) + echo "Unsupported target architecture: $ARCH" + echo "You must add support for it into preload/sb_exec.c" + echo "and utils/sb2-init" + exit 1 + ;; + +esac + + +QEMU=$(which qemu-$ARCH) +if [ ! $skip_checks -a $? != 0 ]; then + echo "You don't have qemu-$ARCH installed." + exit 1 +fi + +if [ -z "$GCC" -o -z "$TARGET" ]; then + usage + exit 1 +fi + +if [ ! $skip_checks ]; then + check_buildroot_sanity +fi + + + + +mkdir -p $HOME/.scratchbox2 -if [ $? == 0 ]; then - echo "sb2-init completed successfully, have fun!" -else - echo "Running $SBOX_DIR/bin/sb2-build-libtool failed" - echo "You can run this manually later, otherwise your" - echo "sb2 environment is correctly setup and ready to use" +if [ -z "$(sb2-config -l)" ]; then +# force this as default anyway as there are no +# other existing targets + set_as_default=1 fi +mkdir -p $HOME/.scratchbox2/$TARGET/bin +write_target_config +if [ $set_as_default == 1 ]; then + sb2-config -d $TARGET +fi + +if [ $with_libtool == 1 ]; then + $SBOX_DIR/bin/sb2 -t $TARGET $SBOX_DIR/bin/sb2-build-libtool + + if [ $? == 0 ]; then + echo "sb2-init completed successfully, have fun!" + else + echo "Running $SBOX_DIR/bin/sb2-build-libtool failed" + echo "You can run this manually later, otherwise your" + echo "sb2 environment is correctly setup and ready to use" + fi +fi |