#!/bin/bash # sb2-init - Copyright (C) 2007 Lauri Leukkunen # Licensed under GPL version 2 my_path=$_ function show_existing_config_info() { has_targets="no" echo "Already initialized targets:" echo for f in $HOME/.scratchbox2/*/sb2.config do if [ -f $f ] then SBOX_CONFIG_VERSION=0 . $f has_targets="yes" targetdir=`dirname $f` targetname=`basename $targetdir` echo "Target $targetname:" if [ "$SBOX_CONFIG_VERSION" -lt 5 ] then echo "(configuration file version too old)" else echo "configured at $SBOX_INIT_TIME by $SBOX_INIT_ID, with command" echo "( cd $SBOX_TARGET_ROOT;" echo "sb2-init $SBOX_INIT_ORIG_ARGS )" fi echo fi done if [ has_targets = "no" ] then echo "none." fi } function usage() { cat < $HOME/.scratchbox2/$TARGET/sb2.config < $HOME/.scratchbox2/$TARGET/sbrsh.config < /dev/null 2>&1 != 0 ]; then echo "Invalid compiler specified: $GCC" exit 1 fi GCC_PREFIX=$(basename $GCC | sed 's/-gcc$/-/') if [ -z "$ARCH" ] then echo "Using $GCC to detect target architecture:" ARCH=$($GCC -dumpmachine | awk -F- '{ print $1 }') GCC_TARGET=$($GCC -dumpmachine) else echo "Target architecture set to $ARCH" fi fi DEBIAN_CPU=$ARCH HOST_ARCH="$(uname --machine)" if echo "$HOST_ARCH" | grep -q "^i.86*"; then HOST_ARCH="i[3456]86" fi case "$ARCH" in $HOST_ARCH*) ;; arm*) if [ -z "$GCC_TARGET" ] then DEBIAN_CPU=$ARCH else echo $GCC_TARGET | grep -q -i eabi if [ $? == 0 ]; then DEBIAN_CPU=armel fi fi ;; ppc*) ;; mips*) ;; sh*) ;; i386*) ;; i486*) ;; i586*) ;; i686*) ;; *) 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 # defaults for SB2_INIT_DEB_BUILD_GNU_TYPE, SB2_INIT_DEB_HOST_GNU_TYPE, etc, # and the cross-gcc prefix list: # these may be changed by sb2rc.$MAPPING_MODE SB2INIT_DEB_BUILD_ARCH=$DEBIAN_CPU SB2INIT_DEB_BUILD_ARCH_ABI="gnu" SB2INIT_DEB_BUILD_GNU_TYPE=$ARCH-linux-gnu SB2INIT_DEB_BUILD_GNU_SYSTEM="" SB2INIT_DEB_BUILD_ARCH_CPU=$DEBIAN_CPU SB2INIT_DEB_HOST_GNU_TYPE=$ARCH-linux-gnu SB2INIT_DEB_HOST_GNU_SYSTEM="" SB2INIT_DEB_HOST_ARCH_OS="linux" SB2INIT_DEB_HOST_ARCH_CPU=$DEBIAN_CPU SB2INIT_CROSS_GCC_PREFIX_LIST=$ARCH-linux- # $ARCH has been set, get mode-specific settings.. if [ -f $SBOX_DIR/share/scratchbox2/modeconf/sb2rc.$MAPPING_MODE ] then echo "Reading mode-specific settings.." . $SBOX_DIR/share/scratchbox2/modeconf/sb2rc.$MAPPING_MODE "initializing" fi if [ -z "$MAPPING_MODE" ]; then MAPPING_MODE="simple" fi if [ ! -d $SBOX_DIR/share/scratchbox2/lua_scripts/pathmaps/$MAPPING_MODE ]; then echo "Invalid mapping mode: $MAPPING_MODE" exit 1 fi if [ ! $skip_checks ]; then check_buildroot_sanity fi mkdir -p $HOME/.scratchbox2 if [ -z "$(sb2-config -l)" ]; then # force this as default anyway as there are no # other existing targets set_as_default=1 fi if [ -n "$TOOLS_ROOT" ]; then if [ -e "$TOOLS_ROOT/etc/scratchbox-version" ]; then # this is a scratchbox 1.x directory, tread carefully # sb1 is not FHS, *sigh* TOOLS_ROOT=$TOOLS_ROOT/tools fi # else assume standard FHS system fi # Use "specs" file for gcc if it exists, otherwise add -I/usr/include to params SBOX_CROSS_GCC_SPECS_FILE="" SBOX_EXTRA_CROSS_COMPILER_STDINC="" if [ -f $SBOX_DIR/share/scratchbox2/modeconf/gcc-specs.$MAPPING_MODE ]; then SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modeconf/gcc-specs.$MAPPING_MODE" else SBOX_EXTRA_CROSS_COMPILER_STDINC="-I/usr/include" fi SBOX_EXTRA_CROSS_COMPILER_ARGS="$SBOX_EXTRA_CROSS_COMPILER_ARGS -L$SBOX_TARGET_ROOT/usr/lib -L$SBOX_TARGET_ROOT/lib" # test if the cross compiler needs to be silenced about /usr/include # usage echo "" | $GCC_FULLPATH -E - -Wno-poison-system-directories > /dev/null 2>&1 if [ $? = 0 ] ; then SBOX_EXTRA_CROSS_COMPILER_ARGS="$SBOX_EXTRA_CROSS_COMPILER_ARGS -Wno-poison-system-directories" fi HOST_GCC_INC=$(echo "#include " | gcc -M -E - | SBOX_DIR=$SBOX_DIR perl -e 'while() { $foo{$1} = 1 if m/\/usr([^[:space:]]*\/include)/;}; foreach my $k (keys %foo) {print " -isystem $ENV{SBOX_DIR}/share/scratchbox2/host_usr$k"};') mkdir -p $HOME/.scratchbox2/$TARGET/bin write_target_config if [ -n "$REMOTEHOST" ]; then if [ -z "$LOCALHOST" ]; then LOCALHOST=$(ip -f inet -o addr \ | awk -- '/: eth[0-9]/ { print $4; exit }' \ | cut -d/ -f1) echo "Using NFS server address: $LOCALHOST" fi write_sbrsh_config fi 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 TEST=$? printf "\n\n" if [ $TEST == 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