configure: avoid non-POSIX: test ... -a/-o ...

Shells do support those, and typically simple forms do work, but
these were removed in POSIX 2024 because they are notoriously hard
to parse correctly, and shells don't always agree on the result.

Instead, use standard forms which all shells support identically.

Extreme high level overview of quotes in POSIX shell:
- WORDs without $... or glob don't need quotes (echo, =, no, x86, ...).
- a=  b=foo  c=$...  and  case $d in ...  all don't need quotes.
- IFS/glob affect command and arguments (not assignments or case..in):
  - IFS only splits direct result of $..., quotes will prevent that.
  - Glob then splits/matches *?[]      and quotes will prevent that.

POSIX "test" (see Application Usage), and shell language (quotes):
  https://pubs.opengroup.org/onlinepubs/9799919799/utilities/test.html
  https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html

My own quick guide:
  https://gist.github.com/avih/6752ad1e20b334b56fef120cd09c766e
This commit is contained in:
Avi Halachmi (:avih) 2024-12-03 02:04:46 +02:00
parent cea857bf73
commit 05ebe494dd

19
configure vendored
View file

@ -210,7 +210,7 @@ default() # set variable unless already set
{ {
local v local v
eval v=\"\$$1\" eval v=\"\$$1\"
test -z "$v" -a -n "$2" && eval $1=\"$2\" test -z "$v" && test -n "$2" && eval $1=\"$2\"
} }
default_conf() # add to confvars unless already present default_conf() # add to confvars unless already present
@ -219,7 +219,7 @@ default_conf() # add to confvars unless already present
test "${confvars%$v*}" = "${confvars}" && confvars="$confvars $1" test "${confvars%$v*}" = "${confvars}" && confvars="$confvars $1"
} }
if test -z "$source_path" -o "$source_path" = "." ; then if test -z "${source_path#.}" ; then
source_path=$(pwd) source_path=$(pwd)
source_path_used="no" source_path_used="no"
else else
@ -254,9 +254,10 @@ fi
default cpu "$cpu_sys" default cpu "$cpu_sys"
# check for crpss build # check for crpss build
if test "$cpu" != "$cpu_sys" \ if test "$cpu" != "$cpu_sys" ||
-o "$targetos" != "$buildos" \ test "$targetos" != "$buildos" ||
-o -n "$cross_prefix" ; then test -n "$cross_prefix"
then
build_cross="yes" build_cross="yes"
cc="${cross_prefix}${cc}" cc="${cross_prefix}${cc}"
ar="${cross_prefix}${ar}" ar="${cross_prefix}${ar}"
@ -337,7 +338,7 @@ case $targetos in
fi fi
fi fi
# on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
if test "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then if test "$cpu" = x86_64 && test "$cpu_sys" = arm64; then
CFLAGS="$CFLAGS -arch $cpu" CFLAGS="$CFLAGS -arch $cpu"
LDFLAGS="$LDFLAGS -arch $cpu" LDFLAGS="$LDFLAGS -arch $cpu"
fi fi
@ -422,17 +423,17 @@ if test -z "$build_cross"; then
_triplet="$($CONFTEST triplet)" _triplet="$($CONFTEST triplet)"
fi fi
if test "$mingw32" = "no" ; then if test "$mingw32" = "no" ; then
if test -z "$triplet" -a -n "$_triplet"; then if test -z "$triplet" && test -n "$_triplet"; then
if test -f "/usr/lib/$_triplet/crti.o"; then if test -f "/usr/lib/$_triplet/crti.o"; then
triplet="$_triplet" triplet="$_triplet"
fi fi
fi fi
if test -z "$triplet"; then if test -z "$triplet"; then
if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then case $cpu in x86_64|arm64|riscv64)
if test -f "/usr/lib64/crti.o" ; then if test -f "/usr/lib64/crti.o" ; then
tcc_lddir="lib64" tcc_lddir="lib64"
fi fi
fi esac
fi fi
if test "$suggest" = "yes"; then if test "$suggest" = "yes"; then
if test -f "/lib/ld-uClibc.so.0" ; then if test -f "/lib/ld-uClibc.so.0" ; then