Skip to content

Commit

Permalink
[sb2] Take directory variables from configure. JB#61868
Browse files Browse the repository at this point in the history
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 <bjorn.bidar@jolla.com>
  • Loading branch information
Thaodan committed Apr 26, 2024
1 parent 1b749d9 commit bbd5c5d
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 151 deletions.
11 changes: 11 additions & 0 deletions llbuild/Makefile.include
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion utils/Makefile
Expand Up @@ -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))
Expand Up @@ -5,14 +5,6 @@
# Copyright (C) 2007 Lauri Leukkunen <lle@rahina.org>
# 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')
Expand All @@ -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
Expand Down Expand Up @@ -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 ;;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions utils/sb2-config → utils/sb2-config.sh.in
Expand Up @@ -2,14 +2,7 @@
# Copyright (C) 2006,2007 Lauri Leukkunen <lle@rahina.org>
# 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
Expand Down Expand Up @@ -49,7 +42,7 @@ EOF

version()
{
cat $SBOX_DIR/share/scratchbox2/version
cat $SBOX_DATADIR/version
exit 0
}

Expand Down Expand Up @@ -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
Expand Down
52 changes: 23 additions & 29 deletions utils/sb2-init → utils/sb2-init.sh.in
Expand Up @@ -2,14 +2,6 @@
# sb2-init - Copyright (C) 2007 Lauri Leukkunen <lle@rahina.org>
# 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')
Expand Down Expand Up @@ -44,7 +36,7 @@ show_existing_config_info()
echo
fi
done
if [ has_targets = "no" ]; then
if [ $has_targets = "no" ]; then
echo "none."
fi
}
Expand Down Expand Up @@ -102,7 +94,7 @@ EOF

version()
{
cat $SBOX_DIR/share/scratchbox2/version
cat $SBOX_DATADIR/scratchbox2/version
exit 0
}

Expand Down Expand Up @@ -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" \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -469,7 +463,7 @@ fi

_host_gcc=$(which gcc)
if [ -n "$_host_gcc" ] && [ -e "$_host_gcc" ]; then
HOST_GCC_INC=$(echo "#include <stdio.h>" | gcc -M -E - | SBOX_DIR=$SBOX_DIR 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"};')
HOST_GCC_INC=$(echo "#include <stdio.h>" | gcc -M -E - | SBOX_DATADIR=$SBOX_DATADIR perl -e 'while(<STDIN>) { $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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 6 additions & 14 deletions utils/sb2-upgrade-config → utils/sb2-upgrade-config.sh.in
Expand Up @@ -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

Expand Down Expand Up @@ -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"
}
Expand All @@ -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" \
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bbd5c5d

Please sign in to comment.