From 6f4b384e7967efc657c5b03c8ac31662fc4a08ac Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Mon, 2 Dec 2024 10:22:23 +0200 Subject: [PATCH] configure: avoid non-POSIX: local var=... The vast majority of shells do support "local", but not all, notably AT&T ksh (default sh in illumos-based distros and Solaris), but also some other POSIX-compliant shells, so remove "local". print_str(), print_num() are modified trivially. default() now uses standard "Assign Default Value" - same semantics, and works in all shells (and POSIX). default_conf() is identical to before, but it had and still has few minor issues, which will be addressed in a future commit. --- configure | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/configure b/configure index d8ef57c6..8e78cd9f 100755 --- a/configure +++ b/configure @@ -206,17 +206,14 @@ EOF exit 1 } -default() # set variable unless already set +default() # set variable unless already set and not empty { - local v - eval v=\"\$$1\" - test -z "$v" && test -n "$2" && eval $1=\"$2\" + test -n "$2" && eval : \${$1:=\$2} # ': ${foo:=$2}' } default_conf() # add to confvars unless already present { - local v=${1%=*} - test "${confvars%$v*}" = "${confvars}" && confvars="$confvars $1" + test "${confvars%${1%=*}*}" = "${confvars}" && confvars="$confvars $1" } if test -z "${source_path#.}" ; then @@ -565,20 +562,20 @@ else echo 'TOPSRC=$(TOP)' >>config.mak fi +# $1: macro name, $2: val to set - quoted [, $3: non-empty for #ifndef] print_str() { - local v="$2" - if test -n "$v"; then + if test -n "$2"; then test -n "$3" && echo "#ifndef $1" >> $TMPH - echo "#define $1 \"$v\"" >> $TMPH + echo "#define $1 \"$2\"" >> $TMPH test -n "$3" && echo "#endif" >> $TMPH fi } +# $1: macro name, $2: val to set [, $3: non-empty for #ifndef] print_num() { - local v="$2" - if test -n "$v"; then + if test -n "$2"; then test -n "$3" && echo "#ifndef $1" >> $TMPH - echo "#define $1 $v" >> $TMPH + echo "#define $1 $2" >> $TMPH test -n "$3" && echo "#endif" >> $TMPH fi }