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.
Unified · Split
| @@ -206,17 +206,14 @@ EOF · 205 unmodified lines | ||
| 206 | 206 | exit 1 |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | −default() # set variable unless already set | |
| 209 | +default() # set variable unless already set and not empty | |
| 210 | 210 | { |
| 211 | − local v | |
| 212 | − eval v=\"\$$1\" | |
| 213 | − test -z "$v" && test -n "$2" && eval $1=\"$2\" | |
| 211 | + test -n "$2" && eval : \${$1:=\$2} # ': ${foo:=$2}' | |
| 214 | 212 | } |
| 215 | 213 | |
| 216 | 214 | default_conf() # add to confvars unless already present |
| 217 | 215 | { |
| 218 | − local v=${1%=*} | |
| 219 | − test "${confvars%$v*}" = "${confvars}" && confvars="$confvars $1" | |
| 216 | + test "${confvars%${1%=*}*}" = "${confvars}" && confvars="$confvars $1" | |
| 220 | 217 | } |
| 221 | 218 | |
| 222 | 219 | if test -z "${source_path#.}" ; then |
| @@ -565,20 +562,20 @@ else · 342 unmodified lines | ||
| 565 | 562 | echo 'TOPSRC=$(TOP)' >>config.mak |
| 566 | 563 | fi |
| 567 | 564 | |
| 565 | +# $1: macro name, $2: val to set - quoted [, $3: non-empty for #ifndef] | |
| 568 | 566 | print_str() { |
| 569 | − local v="$2" | |
| 570 | − if test -n "$v"; then | |
| 567 | + if test -n "$2"; then | |
| 571 | 568 | test -n "$3" && echo "#ifndef $1" >> $TMPH |
| 572 | − echo "#define $1 \"$v\"" >> $TMPH | |
| 569 | + echo "#define $1 \"$2\"" >> $TMPH | |
| 573 | 570 | test -n "$3" && echo "#endif" >> $TMPH |
| 574 | 571 | fi |
| 575 | 572 | } |
| 576 | 573 | |
| 574 | +# $1: macro name, $2: val to set [, $3: non-empty for #ifndef] | |
| 577 | 575 | print_num() { |
| 578 | − local v="$2" | |
| 579 | − if test -n "$v"; then | |
| 576 | + if test -n "$2"; then | |
| 580 | 577 | test -n "$3" && echo "#ifndef $1" >> $TMPH |
| 581 | − echo "#define $1 $v" >> $TMPH | |
| 578 | + echo "#define $1 $2" >> $TMPH | |
| 582 | 579 | test -n "$3" && echo "#endif" >> $TMPH |
| 583 | 580 | fi |
| 584 | 581 | } |