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 | |
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>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | README | 37 | ||||
-rw-r--r-- | docs/sb2.1 | 22 | ||||
-rwxr-xr-x | utils/sb2 | 56 | ||||
-rwxr-xr-x | utils/sb2-build-libtool | 21 | ||||
-rw-r--r-- | utils/sb2-config | 60 | ||||
-rwxr-xr-x | utils/sb2-init | 195 |
7 files changed, 252 insertions, 140 deletions
@@ -88,6 +88,7 @@ install-noarch: $(BUILD_TARGET) echo "$(PACKAGE_VERSION)" > $(prefix)/share/scratchbox2/version install -c -m 755 $(SRCDIR)/utils/sb2 $(prefix)/bin/sb2 install -c -m 755 $(SRCDIR)/utils/sb2-init $(prefix)/bin/sb2-init + install -c -m 755 $(SRCDIR)/utils/sb2-config $(prefix)/bin/sb2-config install -c -m 755 $(SRCDIR)/utils/sb2-build-libtool $(prefix)/bin/sb2-build-libtool install -c -m 755 $(SRCDIR)/utils/dpkg-checkbuilddeps $(prefix)/share/scratchbox2/scripts/dpkg-checkbuilddeps install -c -m 644 $(SRCDIR)/redir_scripts/main.lua $(prefix)/share/scratchbox2/redir_scripts/main.lua @@ -1,7 +1,7 @@ SCRATCHBOX 2 README author: Lauri Leukkunen <lle@rahina.org> -date: 2007-08-19 +date: 2007-09-11 @@ -42,15 +42,9 @@ $ ./configure --prefix=$HOME/scratchbox $ make install -You need Qemu for cpu-transparency. Current (2007-06-18) CVS version -of Qemu works fine, earlier versions lack the -drop-ld-preload option. -Here are basic instructions for installing qemu: - -1. Get a CVS snapshot from http://qemu-forum.ipi.fi/qemu-snapshots/ -2. Extract that somewhere, change into the created directory -3. ./configure --prefix=$HOME/qemu --target-list=arm-linux-user -4. make && make install -5. Add $HOME/qemu/bin to your PATH +You need Qemu for cpu-transparency. As of 2007-09-11 it's recommended to use +debian/unstable's qemu-0.9.0+20070816-1 (or newer), it's by far the best that +can be used with sb2. Qemu has many issues on amd64 host systems, at least when trying to do user-space emulation of ARM. Better results can be achieved on 32bit @@ -74,9 +68,9 @@ To complete sb2 target setup: $ mkdir $HOME/buildroot $ cd $HOME/buildroot [extract or copy your rootfs contents into place] -$ $HOME/scratchbox/bin/sb2-init /path/to/compiler/bin/arm-linux-gcc +$ $HOME/scratchbox/bin/sb2-init my_target /path/to/compiler/bin/arm-linux-gcc -That will automatically generate a working sb2.config for the compiler +That will automatically generate a working target config for the compiler given on the command line and run sb2-build-libtool script to get you a nice working libtool for your compiler. If the sb2-build-libtool part fails for some reason (incorrect http proxy or something similar), you @@ -86,11 +80,8 @@ At this point you can simply run sb2: $ $HOME/scratchbox/bin/sb2 -To make sb2 default to the $HOME/buildroot sandbox, you can put this in -your $HOME/.sb2rc: --- snip -- -SBOX_TARGET_ROOT=~/buildroot --- snip -- +sb2-init made this target your default if you had no prior sb2 targets +configured. To change the default use sb2-config -d your_target. Perhaps adding $HOME/scratchbox/bin to your PATH is also a good idea, put this in your $HOME/.bashrc: @@ -111,9 +102,9 @@ Download the latest rootstrap from: http://repository.maemo.org/stable/3.1/armel/maemo-sdk-rootstrap_3.1_armel.tgz -Extract that to $HOME/buildroot +Extract that to $HOME/maemo-root -Edit $HOME/buildroot/etc/apt/apt.conf so that it looks like this: +Edit $HOME/maemo-root/etc/apt/apt.conf so that it looks like this: -- snip -- APT { Architecture armel; @@ -122,12 +113,10 @@ Architecture armel; Then get a nice toolchain from the locations mentioned above. -Edit $HOME/.sb2rc as described earlier in this README. - After that you can setup sb2 by running: -$ cd $HOME/buildroot -$ sb2-init /path/to/compiler/bin/arm-none-linux-gnueabi-gcc +$ cd $HOME/maemo-root +$ sb2-init maemo /path/to/compiler/bin/arm-none-linux-gnueabi-gcc Now you should have a fully functioning development environment. To try it out you can build for example fontconfig like this: @@ -136,7 +125,7 @@ $ sb2 apt-get source fontconfig $ cd fontconfig-2.4.1 $ sb2 dpkg-buildpackage -rfakeroot -You don't need to be in $HOME/buildroot to do that, I typically do all +You don't need to be in $HOME/maemo-root to do that, I typically do all development work in $HOME/src. @@ -1,9 +1,9 @@ -.TH sb2 1 "12 April 2007" "2.0" "sb2 man page" +.TH sb2 1 "11 September 2007" "2.0" "sb2 man page" .SH NAME sb2 \- crosscompiling environment .SH SYNOPSIS .B sb2 -[ \-v ] [ \-d ] [ \-h ] [ \-t DIRECTORY ] [ \-e ] [ \-m MODE ] [ -s DIRECTORY] [command] [arguments] [...] +[ \-v ] [ \-d ] [ \-h ] [ \-t TARGET ] [ \-e ] [ \-m MODE ] [ -s DIRECTORY] [command] [arguments] [...] .SH DESCRIPTION .B sb2 Runs command in scratchbox2. If no command is given, a bash shell @@ -20,8 +20,7 @@ Output all path mappings to $HOME/sb2_mapping.log. Print help. .TP \-t -Define target root location in argument. Scratchbox2 tries to find the -right target root location automatically, but this overrides that. +Define target to use. Use sb2-config -d TARGET to set a default. .TP \-e Use emulation mode, avoid executing ANY host binaries except qemu. @@ -33,10 +32,8 @@ Use mapping mode given in argument. Use redirection rules from the directory given in argument. .SH ENVIRONMENT -There is a LOT environment variables being used. Since sb2 is still -very volatile, the best documentation is in the source of sb2. -.IP SBOX_TARGET_ROOT -Target location. If not defined, .sb2rc file is searched for. +There are quite many environment variables being used. Since sb2 is still +very volatile, the best documentation is in the source of sb2 script itself. .SH CONFIGURATION To configure sb2, do something like this: @@ -48,14 +45,13 @@ cd $HOME/buildroot sb2-init /path/to/cross-compiler/bin/arm-linux-gcc .fi -Put this in $HOME/.sb2rc to default to using $HOME/buildroot: -.PP -SBOX_TARGET_ROOT=~/buildroot +To change default scratchbox2 target: + +sb2-config -d another_target .SH FILES .P -.I sb2.config -.I ~/.sb2rc +.I ~/.scratchbox2/config .SH SEE ALSO .BR gcc (1), .BR ld (1), @@ -21,8 +21,7 @@ Options: -v display version -d debug mode: log all redirections -h print this help - -t DIRECTORY target directory, else search up in directory - structure for a .sb2rc + -t TARGET target to use, use sb2-config -d TARGET to set a default -e emulation mode -m MODE use mapping mode MODE -s DIRECTORY load mapping scripts from alternative location @@ -50,32 +49,28 @@ function sanity_check() # check that most important host and target files exist } -find_target_root() -{ -( - while [ "$PWD" != "/" ]; do - if [ -r sb2.config ]; then - echo "$(readlink -f -n $PWD)" - return 0 - else - cd .. - fi - done - return 1 -) -} - function sboxify_environment() { + if [ -r ~/.scratchbox2/config ]; then + . ~/.scratchbox2/config + fi - if [ -r ~/.sb2rc ]; then - . ~/.sb2rc + if [ -z "$SBOX_TARGET" ]; then + SBOX_TARGET=$DEFAULT_TARGET fi - if [ -z "$SBOX_TARGET_ROOT" ]; then - SBOX_TARGET_ROOT=`find_target_root` || exit_error "Cannot find target root!" + if [ -z "$SBOX_TARGET" ]; then + echo "No target specified and none set as default, aborting." + exit 2 fi + if [ ! -e ~/.scratchbox2/$SBOX_TARGET/sb2.config ]; then + echo "Invalid target specified, aborting." + exit 2 + fi + export SBOX_TARGET + . ~/.scratchbox2/$SBOX_TARGET/sb2.config + if [ -n "$SBOX_DIR" ]; then LD_LIBRARY_PATH=$SBOX_DIR/lib/libsb2:$SBOX_DIR/lib64/libsb2:$SBOX_DIR/lib32/libsb2 SBOX_LIBSB2="libsb2.so.1" @@ -84,14 +79,7 @@ function sboxify_environment() fi SBOX_GCCWRAPPER="$SBOX_DIR/bin/sb_gcc_wrapper" else - exit_error "Something foul happeninged..." - fi - - if [ -n "$SBOX_TOOLS_ROOT" ]; then - REDIR_LD_SO="$SBOX_TOOLS_DIR/lib/ld-linux.so.2" - REDIR_LD_LIBRARY_PATH="$SBOX_TOOLS_DIR/lib:$SBOX_TOOLS_DIR/usr/lib:$SBOX_TOOLS_DIR/usr/local/lib" - - export REDIR_LD_SO REDIR_LD_LIBRARY_PATH SBOX_TOOLS_ROOT + exit_error "Incorrect target config in ~/.scratchbox2/$SBOX_TARGET/sb2.config" fi export LD_LIBRARY_PATH SBOX_LIBSB2 SBOX_REDIR_SCRIPTS SBOX_TARGET_ROOT SBOX_GCCWRAPPER SBOX_TARGET_COMPILER @@ -99,18 +87,16 @@ function sboxify_environment() # -Riku: I don't think we want to run this on every sb2 invocation.. HOST_GCC_INC_DIR=$(echo "#include <stdio.h>" | gcc -M -E - | perl -e 'while(<STDIN>) { $foo{$1} = 1 if m/\/usr([^[:space:]]*\/include)/;}; foreach my $k (keys %foo) {print " -isystem $ENV{SBOX_DIR}/share/scratchbox2/host_usr$k"};') - export PATH=$SBOX_TARGET_ROOT/sb_tools/bin:$SBOX_DIR/share/scratchbox2/scripts:$SBOX_DIR/bin:$PATH:$SBOX_TARGET_ROOT/bin:$SBOX_TARGET_ROOT/usr/bin:$SBOX_TARGET_ROOT/usr/local/bin:/sbin:/usr/sbin + export PATH=$HOME/.scratchbox2/$SBOX_TARGET/bin:$SBOX_DIR/share/scratchbox2/scripts:$SBOX_DIR/bin:$PATH:/sbin:/usr/sbin:$SBOX_TARGET_ROOT/bin:$SBOX_TARGET_ROOT/usr/bin:$SBOX_TARGET_ROOT/usr/local/bin export LD_PRELOAD=$SBOX_LIBSB2 export SBOX_EXTRA_HOST_COMPILER_ARGS="$HOST_GCC_INC_DIR" export SBOX_EXTRA_CROSS_COMPILER_ARGS="--sysroot=$SBOX_TARGET_ROOT" - export SBOX_SCRATCHBOX_CONFIG=$SBOX_TARGET_ROOT/sb2.config + export SBOX_SCRATCHBOX_CONFIG=$HOME/.scratchbox2/$SBOX_TARGET/sb2.config export PS1="[SB2] \u@\h \w \$ " - . $SBOX_SCRATCHBOX_CONFIG - # Debian exports REVISIT on dpkg 1.14 - if [ $SBOX_CPU = "arm" ]; then + if [ "$SBOX_CPU" = "arm" ]; then export DEB_BUILD_ARCH=armel else export DEB_BUILD_ARCH=$SBOX_CPU @@ -146,7 +132,7 @@ do (v) version ;; (d) export SBOX_MAPPING_DEBUG=1 ;; (h) usage ;; - (t) export SBOX_TARGET_ROOT=$OPTARG ;; + (t) export SBOX_TARGET=$OPTARG ;; (e) export SBOX_MAPMODE=emulate ;; (m) export SBOX_MAPMODE=$OPTARG ;; (s) export SBOX_REDIR_SCRIPTS=$OPTARG;; diff --git a/utils/sb2-build-libtool b/utils/sb2-build-libtool index 8992e3c..fc55187 100755 --- a/utils/sb2-build-libtool +++ b/utils/sb2-build-libtool @@ -3,12 +3,14 @@ # Licensed under GPL version 2 # test that we're inside sb2 -if [ -z "$SBOX_TARGET_ROOT" ]; then +if [ -z "$SBOX_TARGET" ]; then echo "Please run this script inside sb2, like this: $ sb2 $0" exit 1 fi +TARGET="$SBOX_TARGET" + set -e NAME=libtool @@ -16,18 +18,19 @@ VERSION=1.5.22 DLHOST="http://ftp.funet.fi/pub/mirrors/ftp.gnu.org/pub/gnu/libtool" SOURCEFILE=$NAME-$VERSION.tar.gz +LOCAL_SOURCEFILE=$HOME/.scratchbox2/$SOURCEFILE COMPILERDIR= WORKDIR=$(mktemp -d -t sb2_libtool_build.XXXXXXX) || exit 1 cd $WORKDIR -if [ ! -e ../$SOURCEFILE ]; then - wget $DLHOST/$SOURCEFILE -O ../$SOURCEFILE +if [ ! -e $LOCAL_SOURCEFILE ]; then + wget $DLHOST/$SOURCEFILE -O $LOCAL_SOURCEFILE fi -tar zxf ../$SOURCEFILE --strip-components=1 +tar zxf $LOCAL_SOURCEFILE --strip-components=1 -./configure --prefix=$SBOX_TARGET_ROOT/sb_tools --build=$(uname -m)-unknown-linux-gnu +./configure --prefix=$HOME/.scratchbox2/$TARGET --build=$(uname -m)-unknown-linux-gnu # The system libtool script in Debian must be able to support # invoking gcc as cc (Debian specific) @@ -56,10 +59,10 @@ chmod 755 libtool make # create these directories to work around ppc host issues -mkdir -p $SBOX_TARGET_ROOT/sb_tools/share/aclocal -mkdir -p $SBOX_TARGET_ROOT/sb_tools/share/libtool/libltdl -mkdir -p $SBOX_TARGET_ROOT/sb_tools/lib -mkdir -p $SBOX_TARGET_ROOT/sb_tools/include +mkdir -p $HOME/.scratchbox2/$TARGET/share/aclocal +mkdir -p $HOME/.scratchbox2/$TARGET/share/libtool/libltdl +mkdir -p $HOME/.scratchbox2/$TARGET/lib +mkdir -p $HOME/.scratchbox2/$TARGET/include make install cd .. # cleanup diff --git a/utils/sb2-config b/utils/sb2-config new file mode 100644 index 0000000..9c79fc3 --- /dev/null +++ b/utils/sb2-config @@ -0,0 +1,60 @@ +#!/bin/bash +# Copyright (C) 2006,2007 Lauri Leukkunen <lle@rahina.org> +# Licensed under GPL version 2 + +function usage() +{ + cat <<EOF +sb2-config - configure scratchbox2 +Usage: + sb2-config [OPTION]... [TARGETNAME] + +Options: + -d set default scratchbox2 target + -l list scratchbox2 targets + -h print this help + -v display version + +Examples: + sb2-config -d ARM +EOF + exit 2 +} + +function version() +{ + cat $SBOX_DIR/share/scratchbox2/version + exit 0 +} + +function list_targets() +{ + for f in $(find $HOME/.scratchbox2/ -maxdepth 1 -mindepth 1 -type d); do echo $(basename $f); done + exit 0 +} + +function write_config() +{ + echo " +DEFAULT_TARGET=$DEFAULT_TARGET +" > $HOME/.scratchbox2/config +} + +SBOX_DIR=$(readlink -f $(dirname $_)/..) + +while getopts d:hlv foo +do + case $foo in + (d) set_as_default=1 + DEFAULT_TARGET=$OPTARG + ;; + (h) usage ;; + (l) list_targets ;; + (v) version ;; + (*) usage ;; + esac +done +shift $(($OPTIND - 1)) + +write_config + 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 |