diff --git a/configure b/configure index 3d7edab6..f0a3044a 100755 --- a/configure +++ b/configure @@ -70,8 +70,26 @@ assign_opt() { eval ${1#--}=\$2 # no risk of IFS/glob in [OPT]NAME } +# succeed if $1 doesn't IFS-split funny (globs, spaces, ...) +good_split() { + set -- "$1" $1 + test $# = 2 && test "$1" = "$2" +} + +# $1: NAME[=VALUE] succeed if confvars has NAME or NAME=* element +confvars_has() { + ! case " $confvars " in *" ${1%%=*} "* | *" ${1%%=*}="*) + false + esac +} + +# [multiple] NAME or NAME=VAL confvars_set() { - confvars="$confvars $*" + for cv; do + good_split "$cv" || { echo "configure: ERROR: bad config '$cv'"; exit 1; } + confvars_has "$cv" && echo "configure: WARNING: duplicate config '$cv'" + confvars="$confvars $cv" + done } for opt do @@ -221,9 +239,9 @@ default() # set variable unless already set and not empty test -n "$2" && eval : \${$1:=\$2} # ': ${foo:=$2}' } -default_conf() # add to confvars unless already present +default_conf() # add one config to confvars unless already present { - test "${confvars%${1%=*}*}" = "${confvars}" && confvars_set "$1" + confvars_has "$1" || confvars_set "$1" } if test -z "${source_path#.}" ; then