From 2d657cb8b12477f741e755bf78c95af2eb269ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Fri, 29 Mar 2024 17:19:44 +0200 Subject: [PATCH] [sb2] Take directory variables from configure. JB#61868 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To make it easier to detect where Scratchbox2 helper scripts and binaries are found on the host and partially on the tooling/target. This is especially important for helper binaries such as sb2dctl. Signed-off-by: Björn Bidar --- llbuild/Makefile.include | 11 ++ utils/Makefile | 10 +- ...olchain => sb2-config-gcc-toolchain.sh.in} | 36 ++-- utils/{sb2-config => sb2-config.sh.in} | 13 +- utils/{sb2-init => sb2-init.sh.in} | 52 +++-- ...pgrade-config => sb2-upgrade-config.sh.in} | 20 +- utils/{sb2 => sb2.sh.in} | 183 +++++++++++------- 7 files changed, 174 insertions(+), 151 deletions(-) rename utils/{sb2-config-gcc-toolchain => sb2-config-gcc-toolchain.sh.in} (87%) rename utils/{sb2-config => sb2-config.sh.in} (95%) rename utils/{sb2-init => sb2-init.sh.in} (91%) rename utils/{sb2-upgrade-config => sb2-upgrade-config.sh.in} (93%) rename utils/{sb2 => sb2.sh.in} (92%) diff --git a/llbuild/Makefile.include b/llbuild/Makefile.include index 9c7dbc54..af97bb6c 100644 --- a/llbuild/Makefile.include +++ b/llbuild/Makefile.include @@ -29,6 +29,12 @@ __kicker_target: all TOPDIR := $(CURDIR) +edit := sed \ + -e 's|@prefix[@]|$(prefix)|g' \ + -e 's|@bindir[@]|$(bindir)|g' \ + -e 's|@libdir[@]|$(libdir)|g' \ + -e 's|@datadir[@]|$(datadir)|g' \ + -e 's|@configure_input[@]|Generated from $@.sh.in; do not edit by hand.|g' # a useful function to expand paths define O @@ -110,6 +116,11 @@ built-in.o:: %.o %:: %.o +%:: %.sh.in + $(Q)rm -f $(@) $(@).tmp + $(Q)$(edit) $(<) > $(OBJDIR)/$(@).tmp + $(Q)chmod +x,a-w $(@).tmp + $(Q)mv $(@).tmp $(@) define ll_clean $(Q)rm -rf $(CLEAN_FILES) diff --git a/utils/Makefile b/utils/Makefile index ccd56601..aff36416 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -59,5 +59,13 @@ $(D)/sb2-interp-wrapper: $(D)/sb2-interp-wrapper.o preload/libsb2.$(SHLIBEXT) $(P)LD $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -ldl +scripts = \ + sb2 \ + sb2-config \ + sb2-config-gcc-toolchain \ + sb2-init \ + sb2-upgrade-config -targets := $(targets) $(D)/sb2-show $(D)/sb2-monitor $(D)/sb2-ruletree + + +targets := $(targets) $(D)/sb2-show $(D)/sb2-monitor $(D)/sb2-ruletree $(call O,$(scripts)) diff --git a/utils/sb2-config-gcc-toolchain b/utils/sb2-config-gcc-toolchain.sh.in similarity index 87% rename from utils/sb2-config-gcc-toolchain rename to utils/sb2-config-gcc-toolchain.sh.in index 6733fe4c..c46d29e8 100755 --- a/utils/sb2-config-gcc-toolchain +++ b/utils/sb2-config-gcc-toolchain.sh.in @@ -5,14 +5,6 @@ # Copyright (C) 2007 Lauri Leukkunen # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - log_config_action() { tstamp=$(/bin/date '+%Y-%m-%d %H:%M:%S') @@ -39,7 +31,7 @@ Options: -A arch manually override target architecture -h print this help -m mapping_mode target uses mapping_mode as default mode - -S SBOX_DIR define value for SBOX_DIR + -S SBOX_DATADIR define value for SBOX_DIR -R TARGET_ROOT define value for SBOX_TARGET_ROOT -V this toolchain is a secondary toolchain, tools require version numbers in pathnames @@ -148,7 +140,7 @@ do (m) MAPPING_MODE=$OPTARG ;; (C) SBOX_EXTRA_CROSS_COMPILER_ARGS="$SBOX_EXTRA_CROSS_COMPILER_ARGS $OPTARG " ;; (L) SBOX_EXTRA_CROSS_LD_ARGS="$SBOX_EXTRA_CROSS_LD_ARGS $OPTARG " ;; - (S) SBOX_DIR=$OPTARG ;; + (S) SBOX_DATADIR=$OPTARG ;; (R) SBOX_TARGET_ROOT=$OPTARG ;; (V) SECONDARY_COMPILER=yes ;; (v) verbose=yes ;; @@ -169,8 +161,8 @@ esac # ---------- Check parameters -if [ -z "$SBOX_DIR" ]; then - SBOX_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) +if [ -z "$SBOX_DATADIR" ]; then + SBOX_DATADIR=@datadir@ fi if [ -z "$TARGET" ]; then @@ -195,7 +187,7 @@ if [ -z "$MAPPING_MODE" ]; then exit 1 fi -if [ ! -d $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE ]; then +if [ ! -d $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE ]; then echo "Invalid mapping mode: $MAPPING_MODE" exit 1 fi @@ -285,21 +277,21 @@ fi SBOX_CROSS_GCC_SPECS_FILE="" SBOX_EXTRA_CROSS_COMPILER_STDINC="" -# FIXME: SBOX_CROSS_GCC_SPECS_FILE may point to $SBOX_DIR/share/scratchbox2/modes +# FIXME: SBOX_CROSS_GCC_SPECS_FILE may point to $SBOX_DATADIR/scratchbox2/modes # after this. It should point to a session-specific location, but we don't have any # mechanism for that currently. if [ -n "$GCC_SPECS" ]; then # the file was specified on the command line SBOX_CROSS_GCC_SPECS_FILE="$GCC_SPECS" # else try to locate a specs file which was provided with gcc -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH" -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs" -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs" -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-specs ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-specs" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-specs ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-specs" else SBOX_EXTRA_CROSS_COMPILER_STDINC="-I/usr/include" fi diff --git a/utils/sb2-config b/utils/sb2-config.sh.in similarity index 95% rename from utils/sb2-config rename to utils/sb2-config.sh.in index a7dbfb5d..251de456 100755 --- a/utils/sb2-config +++ b/utils/sb2-config.sh.in @@ -2,14 +2,7 @@ # Copyright (C) 2006,2007 Lauri Leukkunen # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - + log_config_action() { mkdir -p $SBOX_CONFIG_DIR @@ -49,7 +42,7 @@ EOF version() { - cat $SBOX_DIR/share/scratchbox2/version + cat $SBOX_DATADIR/version exit 0 } @@ -183,7 +176,7 @@ showenv_vars() # else there are none. } -SBOX_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) +SBOX_DATADIR=@datadir@ WRITE_CONFIG=0 if [ $# = 0 ]; then diff --git a/utils/sb2-init b/utils/sb2-init.sh.in similarity index 91% rename from utils/sb2-init rename to utils/sb2-init.sh.in index 82581dfb..77d8cc48 100755 --- a/utils/sb2-init +++ b/utils/sb2-init.sh.in @@ -2,14 +2,6 @@ # sb2-init - Copyright (C) 2007 Lauri Leukkunen # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - log_config_action() { tstamp=$(/bin/date '+%Y-%m-%d %H:%M:%S') @@ -44,7 +36,7 @@ show_existing_config_info() echo fi done - if [ has_targets = "no" ]; then + if [ $has_targets = "no" ]; then echo "none." fi } @@ -102,7 +94,7 @@ EOF version() { - cat $SBOX_DIR/share/scratchbox2/version + cat $SBOX_DATADIR/scratchbox2/version exit 0 } @@ -208,15 +200,15 @@ configure_toolchains() else gccconfig_arch_option2="" fi - for compiler_path in $*; do + for compiler_path in "${@}"; do log_config_action "sb2-init: configuring toolchain, compiler $compiler_path" - if ! $SBOX_SHARE_DIR/scripts/sb2-config-gcc-toolchain \ + if ! $SBOX_DATADIR/scratchbox2/scripts/sb2-config-gcc-toolchain \ -v \ $secondary_compiler \ $gccconfig_arch_option \ $gccconfig_arch_option2 \ -R "$SBOX_TARGET_ROOT" \ - -S "$SBOX_DIR" \ + -S "$SBOX_DATADIR" \ -t "$TARGET" \ -m "$MAPPING_MODE" \ -C "$SB2INIT_SBOX_EXTRA_CROSS_COMPILER_ARGS" \ @@ -231,10 +223,12 @@ configure_toolchains() done } -if [ -z "$SBOX_DIR" ]; then - SBOX_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) +if [ -z "$SBOXDATA_DIR" ]; then + SBOX_DATADIR=@datadir@ +fi +if [ -z "$SBOXBIN_DIR" ]; then + SBOX_BINDIR=@bindir@ fi -SBOX_SHARE_DIR=$SBOX_DIR/share/scratchbox2 # Use an array to preserve spaces in original arguments: declare -a init_orig_args_array @@ -264,7 +258,7 @@ fi # because a) name of the target is currently unknown, b) there might be # errors in the parameters, or c) if the user is just requesting help or # version and we are not actually going to configure anything. -eval $($SBOX_SHARE_DIR/scripts/sb2-parse-sb2-init-args "${init_orig_args_array[@]}") +eval $($SBOX_DATADIR/scratchbox2/scripts/sb2-parse-sb2-init-args "${init_orig_args_array[@]}") TARGET=$SB2INIT_TARGET SBOX_TARGET_ROOT=$SB2INIT_TARGET_ROOT @@ -301,7 +295,7 @@ if [ -z "$MAPPING_MODE" ]; then echo "Info: Mapping mode not specified, using default ($MAPPING_MODE)" fi -if [ ! -d $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE ]; then +if [ ! -d $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE ]; then echo "Invalid mapping mode: $MAPPING_MODE" exit 1 fi @@ -319,7 +313,7 @@ log_config_action "sb2-init $SBOX_INIT_ORIG_ARGS" # Parse parameters (round 2); store parameters to the config directory. # "$SBOX_CONFIG_DIR/sb2-init-args" can be overwritten by sb2-init or # sb2-upgrade-config; the config log should identify who did what.. -$SBOX_SHARE_DIR/scripts/sb2-parse-sb2-init-args "${init_orig_args_array[@]}" \ +$SBOX_DATADIR/scratchbox2/scripts/sb2-parse-sb2-init-args "${init_orig_args_array[@]}" \ >$SBOX_CONFIG_DIR/sb2-init-args if [ -z "$SB2INIT_COMPILERS" ]; then @@ -452,7 +446,7 @@ fi mkdir -p $HOME/.scratchbox2 -if [ -z "$($SBOX_DIR/bin/sb2-config -l)" ]; then +if [ -z "$($SBOX_BINDIR/sb2-config -l)" ]; then # force this as default anyway as there are no # other existing targets SB2INIT_SET_AS_DEFAULT=1 @@ -469,7 +463,7 @@ fi _host_gcc=$(which gcc) if [ -n "$_host_gcc" ] && [ -e "$_host_gcc" ]; then - 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"};') + HOST_GCC_INC=$(echo "#include " | gcc -M -E - | SBOX_DATADIR=$SBOX_DATADIR perl -e 'while() { $foo{$1} = 1 if m/\/usr([^[:space:]]*\/include)/;}; foreach my $k (keys %foo) {print " -isystem $ENV{SBOX_DATADIR}/scratchbox2/host_usr$k"};') SB2INIT_SBOX_HOST_GCC_NAME=host-gcc SB2INIT_SBOX_HOST_GCC_PREFIX_LIST=host- else @@ -497,13 +491,13 @@ fi # finalize the configuration by running programs in the new environment. if [ $SB2INIT_SET_AS_DEFAULT = 1 ]; then - $SBOX_DIR/bin/sb2-config -d $TARGET + $SBOX_BINDIR/sb2-config -d $TARGET fi # if the target system is (based on) debian, # DEB_* environment variables are needed. We'll set them in any case: echo "sb2-init: Creating Debian build system settings for this target:" -if ! $SBOX_DIR/share/scratchbox2/scripts/sb2-config-debian -t $TARGET ;then +if ! $SBOX_DATADIR/scratchbox2/scripts/sb2-config-debian -t $TARGET ;then log_config_action "sb2-init: failed run sb2-config-debian" echo "sb2-init: sb2-config-debian failed." exit 1 @@ -519,23 +513,23 @@ fi # if [ $SB2INIT_WITH_LOCALES = 1 ]; then if [ -n "$SB2INIT_TOOLS_ROOT" ]; then - $SBOX_DIR/bin/sb2 -t $TARGET \ - $SBOX_DIR/share/scratchbox2/scripts/sb2-generate-locales -T + $SBOX_BINDIR/sb2 -t $TARGET \ + $SBOX_DATADIR/scratchbox2/scripts/sb2-generate-locales -T fi if [ -z "$SB2INIT_CPUTRANSP" ]; then - $SBOX_DIR/bin/sb2 -t $TARGET \ - $SBOX_DIR/share/scratchbox2/scripts/sb2-generate-locales + $SBOX_BINDIR/sb2 -t $TARGET \ + $SBOX_DATADIR/scratchbox2/scripts/sb2-generate-locales fi fi if [ $SB2INIT_WITH_LIBTOOL = 1 ]; then echo "sb2-init: configuring libtool for this target:" printf "\n\n" - if $SBOX_DIR/bin/sb2 -t $TARGET $SBOX_DIR/bin/sb2-build-libtool ; then + if $SBOX_BINDIR/sb2 -t $TARGET $SBOX_BINDIR/sb2-build-libtool ; then echo "sb2-init completed successfully, have fun!" else - echo "Running $SBOX_DIR/bin/sb2-build-libtool failed" + echo "Running $SBOX_BINDIR/sb2-build-libtool failed" echo "You can run this manually later, otherwise your" echo "sb2 environment is correctly setup and ready to use" fi diff --git a/utils/sb2-upgrade-config b/utils/sb2-upgrade-config.sh.in similarity index 93% rename from utils/sb2-upgrade-config rename to utils/sb2-upgrade-config.sh.in index b153aa19..62b67dad 100755 --- a/utils/sb2-upgrade-config +++ b/utils/sb2-upgrade-config.sh.in @@ -8,16 +8,8 @@ # Copyright (C) 2009 Nokia Corporation. # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - -SBOX_SHARE_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) -SBOX_DIR=$(readlink -f $SBOX_SHARE_DIR/../..) +SBOX_DATADIR=@datadir@ +SBOX_DIR=@prefix@ SBOX_TARGET=$1 SBOX_CONFIG_DIR=~/.scratchbox2/$SBOX_TARGET/sb2.config.d @@ -66,7 +58,7 @@ get_sb2_init_arguments_from_old_config_file() -n '/^SBOX_TARGET_ROOT/ s/^SBOX_TARGET_ROOT=(.*)/\1/ p' $OLD_CONFIG_FILE) export SB2INIT_TARGET_ROOT=$SBOX_TARGET_ROOT - $SBOX_SHARE_DIR/scripts/sb2-parse-sb2-init-args $SBOX_INIT_ORIG_ARGS \ + $SBOX_DATADIR/scratchbox2/scripts/sb2-parse-sb2-init-args $SBOX_INIT_ORIG_ARGS \ > $SBOX_CONFIG_DIR/sb2-init-args log_config_action "Config upgrade: arguments of original sb2-init restored from old config file" } @@ -88,12 +80,12 @@ update_toolchain_configs() for compiler_path in "$@"; do # echo "Updating compiler $compiler_path" log_config_action "Config upgrade: settings for compiler $compiler_path" - if ! $SBOX_SHARE_DIR/scripts/sb2-config-gcc-toolchain \ + if ! $SBOX_DATADIR/scratchbox2/scripts/sb2-config-gcc-toolchain \ $secondary_compiler \ $gccconfig_arch_option \ $gccconfig_arch_option2 \ -R "$SB2INIT_TARGET_ROOT" \ - -S "$SBOX_SHARE_DIR/../.." \ + -S "$SBOX_DATADIR" \ -t "$SB2INIT_TARGET" \ -m "$SB2INIT_MAPPING_MODE" \ -C "$SB2INIT_SBOX_EXTRA_CROSS_COMPILER_ARGS" \ @@ -159,7 +151,7 @@ update_host_ld_library_path() update_debian_config() { - $SBOX_DIR/share/scratchbox2/scripts/sb2-config-debian -t $SBOX_TARGET + $SBOX_DATADIR/scratchbox2/scripts/sb2-config-debian -t $SBOX_TARGET } if [ ! -d $SBOX_CONFIG_DIR ]; then diff --git a/utils/sb2 b/utils/sb2.sh.in similarity index 92% rename from utils/sb2 rename to utils/sb2.sh.in index b2d16313..de4bd656 100755 --- a/utils/sb2 +++ b/utils/sb2.sh.in @@ -5,23 +5,13 @@ # "sb2" script, the command-line interface to Scratchbox 2. # -# This *must* be the first thing in this file: -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - - SBOX_LIBSB2="libsb2.so.1" - + # Show version. # (called to process a command-line option) show_version() { - cat $SBOX_DIR/share/scratchbox2/version + cat $SBOX_DATADIR/scratchbox2/version } show_usage_and_exit() @@ -160,12 +150,12 @@ locate_target_nsswitch_conf() { __SB2_BINARYNAME="sb2:LocatingNsswitchConf" \ sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /etc/nsswitch.conf \ >$SBOX_SESSION_DIR/path_to_nsswitch.conf __SB2_BINARYNAME="sb2:LocatingNscdSocket" \ sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /var/run/nscd/socket \ >$SBOX_SESSION_DIR/path_to_nscd_socket.conf read -r NSSWITCH_CONF_PATH < $SBOX_SESSION_DIR/path_to_nsswitch.conf @@ -233,7 +223,7 @@ load_configuration() exit_error "Cannot access target root '$SBOX_TARGET_ROOT', aborting." fi - if [ ! -d "$SBOX_DIR/share/scratchbox2/modes/$SBOX_MAPMODE" ]; then + if [ ! -d "$SBOX_DATADIR/scratchbox2/modes/$SBOX_MAPMODE" ]; then exit_error "Configure mode doesn't '$SBOX_MAPMODE' for target doesn't exist, aborting." fi @@ -304,7 +294,7 @@ load_configuration() exit 1 fi if [ -e "$_cputransp" ]; then - SBOX_CPUTRANSPARENCY_CMD=$($SBOX_DIR/bin/sb2-show realpath $_cputransp) + SBOX_CPUTRANSPARENCY_CMD=$($SBOX_BINDIR/sb2-show realpath $_cputransp) fi fi @@ -322,7 +312,7 @@ load_configuration() exit 1 fi if [ -e "$_cputransp" ]; then - SBOX_CPUTRANSPARENCY_NATIVE_CMD=$($SBOX_DIR/bin/sb2-show realpath $_cputransp) + SBOX_CPUTRANSPARENCY_NATIVE_CMD=$($SBOX_BINDIR/sb2-show realpath $_cputransp) export SBOX_NATIVE_HAS_CPUTRANSP=1 fi fi @@ -451,7 +441,7 @@ sboxify_environment() if [ -z "$SBOX_MODE_PATH" ]; then new_PATH=$HOME/.scratchbox2/$SBOX_TARGET/bin - new_PATH+=:${CCACHE_TOOLS_PATH+$CCACHE_TOOLS_PATH:}$SBOX_DIR/bin:$PATH + new_PATH+=:${CCACHE_TOOLS_PATH+$CCACHE_TOOLS_PATH:}$SBOX_BINDIR:$PATH PATH=$new_PATH:/sbin:/usr/sbin:$SBOX_TARGET_ROOT/bin PATH+=:$SBOX_TARGET_ROOT/usr/bin:$SBOX_TARGET_ROOT/usr/local/bin else @@ -654,7 +644,7 @@ write_ld_library_path_replacement_to_exec_config() # ---- Step 2. Directories under $rootdir # First, make sure that libsb2 is searched - liblocations="$SBOX_DIR/lib/libsb2 /usr/lib/libsb2" + liblocations="$sbox_liblocations" # Include directories listed in ld.so.conf if [ -f $rootdir/etc/ld.so.conf ]; then @@ -718,7 +708,7 @@ write_ld_library_path_replacement_to_exec_config() # can be executed in the sb2'ed environment. check_qemu_features() { - qemu_path=$($SBOX_DIR/bin/sb2-show realpath $1) + qemu_path=$($SBOX_BINDIR/sb2-show realpath $1) shift qemu_options=$* @@ -727,7 +717,7 @@ check_qemu_features() # use ld.so and libraries from tools) if ! __SB2_BINARYNAME="sb2:CheckingQemuExec" \ sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ -- exec-cmdline \ $qemu_path $qemu_options \ >$SBOX_SESSION_DIR/qemu_cmdline @@ -888,7 +878,7 @@ check_ld_so_features() locate_shell() { __SB2_BINARYNAME="sb2:TestingBash" sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /bin/bash \ >$SBOX_SESSION_DIR/path_to_shell.conf read -r SHELL_PATH < $SBOX_SESSION_DIR/path_to_shell.conf @@ -897,7 +887,7 @@ locate_shell() SHELL=/bin/bash else __SB2_BINARYNAME="sb2:LocatingShell" sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /bin/sh \ >$SBOX_SESSION_DIR/path_to_shell.conf # Default to /bin/sh @@ -918,13 +908,18 @@ locate_shell() guess_ld_so() { local prefix="$1" - - if [ "$(uname -m)" = 'x86_64' ] && [ -r "$prefix/lib/ld-linux-x86-64.so.2" ] - then - printf "$prefix/lib/ld-linux-x86-64.so.2" - else - printf "$prefix/lib/ld-linux.so.2" - fi + local ld_so_conf=$prefix/lib/ld-linux.so.2 + if [ "$(getconf LONG_BIT)" -ge 64 ] ; then + # 64-bit architecture all append the name of the arch to the same of + # ld.so + ld_so_conf_base=ld-linux-$(uname -m).so.2 + for libdir in $sbox_libdirs; do + if [ -r $prefix/$libdir/$ld_so_conf ] ; then + ld_so_conf=$prefix/$libdir/$ld_so_conf_base + fi + done + fi + printf "$ld_so_conf" } # Locate libsb2.so.1 library which must be used; Several @@ -956,18 +951,21 @@ write_libsb2_and_ld_so_state_to_exec_config() # Check if ld.so can be used from $rootdir by # checking that libsb2 has been installed to tools - if [ -d $rootdir/$SBOX_DIR/lib/libsb2 ]; then - sbox_dir_2=$rootdir/$SBOX_DIR - elif [ -d $rootdir/usr/lib/libsb2 ]; then - sbox_dir_2=$rootdir/usr - else - sbox_dir_2="" - fi + sbox_dir_2="" + + for liblocation in $sbox_liblocations ; do + if [ -d $rootdir/$liblocation ]; then + # assume the prefix is under libdir: ../libdir + sbox_dir_2=$rootdir${liblocation%/*} + sbox_libdir=$rootdir$liblocation/ + if [ -z "$libsb2_path" ]; then + libsb2_path=$rootdir/$liblocation/$SBOX_LIBSB2 + libsb2_dirname="" + fi + break + fi + done - if [ -z "$libsb2_path" ]; then - libsb2_path=$sbox_dir_2/lib/libsb2/libsb2.so.1 - libsb2_dirname="" - fi if [ -f $libsb2_path ]; then libsb2_dir=$(dirname $libsb2_path) @@ -1008,7 +1006,7 @@ write_libsb2_and_ld_so_state_to_exec_config() fi if [ "$ld_so_argv_flag_works" != "true" ]; then - ld_so_candidate2=$SBOX_DIR/lib/libsb2/$ld_so_with_version + ld_so_candidate2=${sbox_libdir:-$SBOX_DIR/lib/libsb2}/$ld_so_with_version if [ -f "$ld_so_candidate2" ]; then check_ld_so_features $rootdir \ $ld_so_candidate2 @@ -1119,7 +1117,7 @@ write_locale_and_gconv_paths_to_exec_config() #------------ gconv: gconv_path="" - for rootdir_gconvs in "$rootdir/usr/lib/gconv" \ + for rootdir_gconvs in "$SBOX_LIBDIR $rootdir/usr/lib/gconv" \ "$rootdir/usr/share/gconv" do if [ -d "$rootdir_gconvs" ]; then @@ -1153,7 +1151,12 @@ END -- CPU transparency settings. Automatically generated file, do not edit. END - library_interface=$(LD_LIBRARY_PATH=$SBOX_DIR/lib/libsb2:$LD_LIBRARY_PATH $SBOX_DIR/bin/sb2-show libraryinterface) + for liblocation in $sbox_liblocations ; do + if [ -d $liblocation ] ; then + break + fi + done + library_interface=$(LD_LIBRARY_PATH=$liblocation:$LD_LIBRARY_PATH $SBOX_BINDIR/sb2-show libraryinterface) # 1. Exec settings for tools if [ -n "$SBOX_TOOLS_ROOT" ] && [ "$SBOX_TOOLS_ROOT" != "/" ]; then @@ -1206,7 +1209,7 @@ END fi # 2. Exec settings for rootstrap - if [ "$SBOX_CPUTRANSPARENCY_METHOD" == "" ]; then + if [ "$SBOX_CPUTRANSPARENCY_METHOD" = "" ]; then # CPU transparency method has not been set: # host CPU == target CPU if [ -n "$SBOX_CLONED_TARGET_ROOT" ]; then @@ -1346,7 +1349,7 @@ get_SBOX_SESSION_DIR_from_file() # (called to process a command-line option) add_map_mode() { - if [ ! -d "$SBOX_DIR/share/scratchbox2/modes/$1" ]; then + if [ ! -d "$SBOX_DATADIR/scratchbox2/modes/$1" ]; then exit_error "Invalid mode '$1', aborting." fi @@ -1442,12 +1445,12 @@ initialize_new_sb2_session() # For mknod() simulation in some modes: mkdir $SBOX_SESSION_DIR/dev - ln -s $SBOX_DIR/bin $SBOX_SESSION_DIR/bin - ln -s $SBOX_DIR/share $SBOX_SESSION_DIR/share + ln -s $SBOX_BINDIR $SBOX_SESSION_DIR/bin + ln -s $SBOX_DATADIR $SBOX_SESSION_DIR/share # FIXME: This should link only selected modes, not all: - ln -s $SBOX_DIR/share/scratchbox2/modes/* $SBOX_SESSION_DIR/modes + ln -s $SBOX_DATADIR/scratchbox2/modes/* $SBOX_SESSION_DIR/modes - ln -s $SBOX_DIR/share/scratchbox2/rule_lib $SBOX_SESSION_DIR + ln -s $SBOX_DATADIR/scratchbox2/rule_lib $SBOX_SESSION_DIR if [ -n "$SBOX_WRITE_SESSION_INFO_TO_FILE" ]; then cat >$SBOX_WRITE_SESSION_INFO_TO_FILE </dev/null - ln -s $SBOX_DIR/lib/libsb2/wrappers/* \ - $SBOX_SESSION_DIR/wrappers.$w_mode 2>/dev/null + if [ "$SBOX_WRAPPERS" = 'ALL' ]; then + for wrapper in $SBOX_DATADIR/scratchbox2/wrappers/* ; do + if [ -e $wrapper ]; then + ln -s $wrapper \ + $SBOX_SESSION_DIR/wrappers.$w_mode + fi + done + # Pick the first liblocation found any link wrappers + # to the session + for wrapper_dir in $sbox_liblocations ; do + if [ -e $wrapper_dir ] ; then + for wrapper in $wrapper_dir/* ; do + if [ -e $wrapper ] ; then + ln -s $wrapper \ + $SBOX_SESSION_DIR/wrappers.$w_mode + fi + done + break + fi + done else for ammw in $SBOX_WRAPPERS; do - if [ -f $SBOX_DIR/share/scratchbox2/wrappers/$ammw ]; then - ln -s $SBOX_DIR/share/scratchbox2/wrappers/$ammw \ - $SBOX_SESSION_DIR/wrappers.$w_mode - elif [ -f $SBOX_DIR/lib/libsb2/wrappers/$ammw ]; then - ln -s $SBOX_DIR/lib/libsb2/wrappers/$ammw \ - $SBOX_SESSION_DIR/wrappers.$w_mode - else + wrapper_found=nil + for wrapper_dir in $SBOX_DATADIR/scratchbox2 \ + $sbox_liblocations \ + ; do + if [ -f $wrapper_dir/wrappers/$ammw ]; then + ln -s $wrapper_dir/wrappers/$ammw \ + $SBOX_SESSION_DIR/wrappers.$w_mode + wrapper_found=t + break + fi + done + if [ $wrapper_found = nil ] ; then exit_error "There is no wrapper for $ammw" fi done @@ -1556,13 +1579,13 @@ write_configfiles_and_rules_for_new_session() SB2_ALL_NET_MODES="" # Create links to network rules - for netr in $SBOX_DIR/share/scratchbox2/net_rules/*; do + for netr in $SBOX_DATADIR/scratchbox2/net_rules/*; do ln -s $netr $SBOX_SESSION_DIR/net_rules netr_b=$(basename $netr) SB2_ALL_NET_MODES="$SB2_ALL_NET_MODES $netr_b" done # Create a link to the default mode - ln -s $SBOX_DIR/share/scratchbox2/net_rules/$SBOX_DEFAULT_NETWORK_MODE $SBOX_SESSION_DIR/net_rules/Default + ln -s $SBOX_DATADIR/scratchbox2/net_rules/$SBOX_DEFAULT_NETWORK_MODE $SBOX_SESSION_DIR/net_rules/Default ##if [ -n "$SB2_EXTERNAL_RULEFILES" ]; then ## for ammf in $SB2_EXTERNAL_RULEFILES; do @@ -1620,7 +1643,10 @@ SBOX_MAPMODE="" NUM_MAPMODES=0 SB2_INTERNAL_MAPMODES="" -SBOX_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) +SBOX_DIR=@prefix@ +SBOX_BINDIR=@bindir@ +SBOX_LIBDIR=@libdir@ +SBOX_DATADIR=@datadir@ SBOX_WORKDIR=$(readlink -f "$PWD") SBOX_ROOT_SIMULATION="" SBOX_MODE_SPECIFIC_OPTIONS="" @@ -1638,6 +1664,13 @@ VPERM_ROOT_PRIVILEGE_FLAG="" SB2D_OPTIONS="" OPT_DONT_DELETE_SESSION="" +# Only check use /lib and /lib64 as paths without $SBOX_DIR outside +# /usr as systems with UsrMove should have /usr/lib -> /lib +# symlinks +sbox_libdirs="$SBOX_DIR/lib /lib $SBOX_LIBDIR /lib64" +sbox_liblocations="$SBOX_DIR/lib/libsb2 /usr/lib/libsb2 $SBOX_LIBDIR/libsb2 $SBOX_DIR/lib64/libsb2 /usr/lib64/libsb2" + + while getopts vdht:em:n:s:L:Q:M:ZrRU:pS:J:D:P:W:O:cC:T:uf:gG:B:b:qx:N foo do case $foo in @@ -1715,7 +1748,7 @@ if [ -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then else exit_error "directory $SBOX_LOG_AND_GRAPH_DIR already exists" fi - SBOX_LOG_AND_GRAPH_DIR=$($SBOX_DIR/bin/sb2-show realpath $SBOX_LOG_AND_GRAPH_DIR) + SBOX_LOG_AND_GRAPH_DIR=$($SBOX_BINDIR/sb2-show realpath $SBOX_LOG_AND_GRAPH_DIR) export SBOX_LOG_AND_GRAPH_DIR export SBOX_COLLECT_ACCT_DATA @@ -1728,12 +1761,12 @@ if [ -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then if [ -n "$SBOX_COLLECT_ACCT_DATA" ]; then # First try to activate it directly touch $SBOX_LOG_AND_GRAPH_DIR/acct-data - if ! $SBOX_DIR/bin/sb2-show acct_on \ + if ! $SBOX_BINDIR/sb2-show acct_on \ $SBOX_LOG_AND_GRAPH_DIR/acct-data 2>/dev/null; then if [ -z "$SBOX_QUIET" ]; then echo "WARNING: Can't activate process accounting. Retrying with 'sudo', password may be needed." fi - if ! sudo $SBOX_DIR/bin/sb2-show acct_on \ + if ! sudo $SBOX_BINDIR/sb2-show acct_on \ $SBOX_LOG_AND_GRAPH_DIR/acct-data 2>/dev/null; then if [ -z "$SBOX_QUIET" ]; then echo "WARNING: Failed to activate process accounting. Acct data won't be included in the graphs." @@ -1756,7 +1789,7 @@ else fi if [ -n "$SBOX_NETWORK_MODE" ]; then - if [ ! -d "$SBOX_DIR/share/scratchbox2/net_rules/$SBOX_NETWORK_MODE" ]; then + if [ ! -d "$SBOX_DATADIR/scratchbox2/net_rules/$SBOX_NETWORK_MODE" ]; then exit_error "'$SBOX_NETWORK_MODE' is not a valid networking mode." fi fi @@ -1929,7 +1962,7 @@ if [ -z "$SBOX_JOIN_SESSION_FILE" ]; then # to the rule tree. # (this step needs to be syncronous; sb2dctl won't return # before init2.lua is completed) - ctl_result=$($SBOX_DIR/lib/libsb2/sb2dctl -n -s $SBOX_SESSION_DIR init2) + ctl_result=$($SBOX_LIBDIR/libsb2/sb2dctl -n -s $SBOX_SESSION_DIR init2) case "$ctl_result" in *OK*) # Startup OK @@ -2018,15 +2051,15 @@ if [ $# -gt 0 ] || [ "$STDIN" = true ]; then orig_args_array=("$@") exec sb2-monitor $OPTS_FOR_SB2_MONITOR \ -L $SBOX_LIBSB2 \ - -X $SBOX_DIR/share/scratchbox2/scripts/sb2-exitreport \ + -X $SBOX_DATADIR/scratchbox2/scripts/sb2-exitreport \ -e $SBOX_CONFIG_DIR/env_vars \ -- \ - $SBOX_DIR/bin/sb2-show start -- $binary "${orig_args_array[@]}" + $SBOX_BINDIR/sb2-show start -- $binary "${orig_args_array[@]}" else exec sb2-monitor $OPTS_FOR_SB2_MONITOR \ -L $SBOX_LIBSB2 \ - -X $SBOX_DIR/share/scratchbox2/scripts/sb2-exitreport \ + -X $SBOX_DATADIR/scratchbox2/scripts/sb2-exitreport \ -e $SBOX_CONFIG_DIR/env_vars \ -- \ - $SBOX_DIR/bin/sb2-show start -- $SHELL --noprofile --norc + $SBOX_BINDIR/sb2-show start -- $SHELL --noprofile --norc fi