scripts: ext-toolchain: add option to overwrite config
[openwrt/staging/dedeckeh.git] / scripts / ext-toolchain.sh
index ee7d9532f5de79588900920e73046221679541b7..c9ceb150c1969683e146a5d38edea45a08a77c27 100755 (executable)
@@ -50,6 +50,7 @@ BIN_SPECS="
        gdbserver: gdbserver
 "
 
+OVERWRITE_CONFIG=""
 
 test_c() {
        cat <<-EOT | "${CC:-false}" $CFLAGS -o /dev/null -x c - 2>/dev/null
@@ -281,8 +282,11 @@ print_config() {
        local mksubtarget
 
        local target="$("$CC" $CFLAGS -dumpmachine)"
+       local version="$("$CC" $CFLAGS -dumpversion)"
        local cpuarch="${target%%-*}"
-       local prefix="${CC##*/}"; prefix="${prefix%-*}-"
+
+       # get CC; strip version; strip gcc and add - suffix
+       local prefix="${CC##*/}"; prefix="${prefix%-$version}"; prefix="${prefix%-*}-"
        local config="${0%/scripts/*}/.config"
 
        # if no target specified, print choice list and exit
@@ -317,9 +321,13 @@ print_config() {
        fi
 
        # bail out if there is a .config already
-       if [ -f "${0%/scripts/*}/.config" ]; then
-               echo "There already is a .config file, refusing to overwrite!" >&2
-               return 1
+       if [ -f "$config" ]; then
+               if [ "$OVERWRITE_CONFIG" == "" ]; then
+                       echo "There already is a .config file, refusing to overwrite!" >&2
+                       return 1
+               else
+                       echo "There already is a .config file, trying to overwrite!"
+               fi
        fi
 
        case "$mktarget" in */*)
@@ -327,8 +335,11 @@ print_config() {
                mktarget="${mktarget%/*}"
        ;; esac
 
+       if [ ! -f "$config" ]; then
+               touch "$config"
+       fi
 
-       echo "CONFIG_TARGET_${mktarget}=y" > "$config"
+       echo "CONFIG_TARGET_${mktarget}=y" >> "$config"
 
        if [ -n "$mksubtarget" ]; then
                echo "CONFIG_TARGET_${mktarget}_${mksubtarget}=y" >> "$config"
@@ -529,6 +540,10 @@ while [ -n "$1" ]; do
                        exit $?
                ;;
 
+               --overwrite-config)
+                       OVERWRITE_CONFIG=y
+               ;;
+
                --config)
                        if probe_cc; then
                                print_config "$1"
@@ -569,7 +584,9 @@ while [ -n "$1" ]; do
                        echo -e "  Most commands also take a --cflags parameter which " >&2
                        echo -e "  is used to specify C flags to be passed to the "     >&2
                        echo -e "  cross compiler when performing tests."               >&2
-                       echo -e "  This paremter may be repeated multiple times."       >&2
+                       echo -e "  This parameter may be repeated multiple times."      >&2
+                       echo -e "  Use --overwrite-config before --config to overwrite" >&2
+                       echo -e "  an already present config with the required changes.">&2
                        exit 1
                ;;