#!/bin/bash # sb2-config-gcc-toolchain - configure a cross-gcc compiler for SB2 # # Copyright (c) 2008 Nokia Corporation. # 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 function log_config_action() { tstamp=`/bin/date '+%Y-%m-%d %H:%M:%S'` echo "$tstamp $*" >>$SBOX_CONFIG_DIR/CONFIG-LOG } # Get the original arguments that were specified to sb2-init from function usage() { cat < $HOME/.scratchbox2/$TARGET/sb2.config.d/gcc$gcc_version_id.config.sh < $HOME/.scratchbox2/$TARGET/sb2.config.d/gcc.config$gcc_version_id.lua < /dev/null 2>&1 != 0 ]; then echo "Invalid compiler specified: $GCC" exit 1 fi # ---------- end of parameter checks case "$(basename $GCC)" in (*-*) # $GCC contains a prefix GCC_PREFIX=$(basename $GCC | sed 's/-gcc$/-/') ;; (*) # No embedded prefix GCC_PREFIX="" ;; esac SBOX_CROSS_GCC_VERSION=`$GCC -dumpversion` # Create a version string with two digits SBOX_CROSS_GCC_SHORTVERSION=`echo $SBOX_CROSS_GCC_VERSION | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\)\..*/\1/'` if [ -z "$ARCH" ]; then if [ -n "$verbose" ] ; then echo "Using $GCC to detect target architecture:" fi ARCH=$($GCC -dumpmachine | awk -F- '{ print $1 }') GCC_TARGET=$($GCC -dumpmachine) else if [ -n "$verbose" ] ; then echo "Target architecture set to $ARCH" fi fi # default for the cross-gcc prefix list: # these may be changed by sb2rc.$MAPPING_MODE 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 if [ -n "$verbose" ] ; then echo "Reading mode-specific settings.." fi . $SBOX_DIR/share/scratchbox2/modeconf/sb2rc.$MAPPING_MODE "initializing" 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-$SBOX_CROSS_GCC_VERSION-specs-$ARCH.$MAPPING_MODE ]; then SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modeconf/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH.$MAPPING_MODE" elif [ -f $SBOX_DIR/share/scratchbox2/modeconf/gcc-$SBOX_CROSS_GCC_VERSION-specs.$MAPPING_MODE ]; then SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modeconf/gcc-$SBOX_CROSS_GCC_VERSION-specs.$MAPPING_MODE" elif [ -f $SBOX_DIR/share/scratchbox2/modeconf/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs.$MAPPING_MODE ]; then SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modeconf/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs.$MAPPING_MODE" elif [ -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 # Note: "sb2" script will replace "@SBOX_TARGET_ROOT@" by the real # value when the session is created. 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"};') if [ -z "$SECONDARY_COMPILER" ] ; then write_gcc_config else write_gcc_config $SBOX_CROSS_GCC_VERSION fi if [ -n "$verbose" ] ; then echo "gcc configured." fi log_config_action "gcc configured ($SBOX_CROSS_GCC_VERSION)" if [ -n "$SBOX_CROSS_GCC_SPECS_FILE" ]; then log_config_action "(gcc specs from $SBOX_CROSS_GCC_SPECS_FILE)" fi exit 0