[x264-devel] [PATCH 4/4] configure: switch to POSIX sh

Ethan Sommer e5ten.arch at gmail.com
Tue Jan 14 18:18:17 CET 2020


remove use of test's -o and -a operators, they are poorly defined
switch shebange to #!/bin/sh now that script is fully POSIX
---
 configure | 128 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 71 insertions(+), 57 deletions(-)

diff --git a/configure b/configure
index 280e7d3b..13572d36 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/bin/sh
 
-if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
+if [ "$1" = -h ] || [ "$1" = --help ]; then
 cat <<EOF
 Usage: ./configure [options]
 
@@ -77,7 +77,7 @@ log_msg() {
 cc_cflags() {
     # several non gcc compilers issue an incredibly large number of warnings on high warning levels,
     # suppress them by reducing the warning level rather than having to use #pragmas
-    for arg in $*; do
+    for arg do
         [ "${arg#-falign-loops}" = "$arg" ] || arg=
         [ "$arg" = -fno-tree-vectorize ] && arg=
         [ "$arg" = -Wshadow ] && arg=
@@ -97,16 +97,16 @@ cc_cflags() {
             [ "$arg" = -Wall ] && arg=
             [ "$arg" = -Werror ] && arg="-w3 -Werror"
         fi
-        [ $compiler = CL -a "$arg" = -O3 ] && arg=-O2
+        [ "$compiler" = CL ] && [ "$arg" = -O3 ] && arg=-O2
 
         [ -n "$arg" ] && printf '%s ' "$arg"
     done
 }
 
 cl_ldflags() {
-    for arg in $*; do
-        arg=${arg/LIBPATH/libpath}
-        [ "${arg#-libpath:}" = "$arg" -a "${arg#-l}" != "$arg" ] && arg=${arg#-l}.lib
+    for arg do
+        [ "${arg#*LIBPATH}" = "$arg" ] || arg="${arg%%LIBPATH*}libpath${arg#*LIBPATH}"
+        [ "${arg#-libpath:}" = "$arg" ] && [ "${arg#-l}" != "$arg" ] && arg=${arg#-l}.lib
         [ "${arg#-L}" != "$arg" ] && arg=-libpath:${arg#-L}
         [ "$arg" = -Wl,--large-address-aware ] && arg=-largeaddressaware
         [ "$arg" = -s ] && arg=
@@ -117,7 +117,7 @@ cl_ldflags() {
         [ "$arg" = -Wmaybe-uninitialized ] && arg=
         [ "${arg#-Qdiag-error}" = "$arg" ] || arg=
 
-        arg=${arg/pthreadGC/pthreadVC}
+        [ "${arg#*pthreadGC}" = "$arg" ] || arg="${arg%%pthreadGC*}pthreadVC${arg#*pthreadGC}"
         [ "$arg" = avifil32.lib ] && arg=vfw32.lib
         [ "$arg" = gpac_static.lib ] && arg=libgpac_static.lib
         [ "$arg" = x264.lib ] && arg=libx264.lib
@@ -278,12 +278,12 @@ pkg_check() {
 }
 
 define() {
-    echo "#define $1$([ -n "$2" ] && echo " $2" || echo " 1")" >> config.h
+    printf '#define %s %s\n' "$1" "${2:-1}" >> config.h
 }
 
 die() {
-    log_msg "DIED: $@"
-    echo "$@"
+    log_msg "DIED: $*"
+    echo "$*"
     exit 1
 }
 
@@ -336,7 +336,7 @@ rm -rf conftest*
 # Construct a path to the specified directory relative to the working directory
 relative_path() {
     base="${PWD%/}"
-    path="$(cd "$1" >/dev/null; printf '%s/.' "${PWD%/}")"
+    path="$(cd "$1" >/dev/null || exit; printf '%s/.' "${PWD%/}")"
     up=''
 
     while [ "${path#$base/}" = "$path" ]; do
@@ -349,7 +349,9 @@ relative_path() {
 
 SRCPATH="$(relative_path "$(dirname "$0")")"
 echo "$SRCPATH" | grep -q ' ' && die "Out of tree builds are impossible with whitespace in source path."
-[ -e "$SRCPATH/config.h" -o -e "$SRCPATH/x264_config.h" ] && die "Out of tree builds are impossible with config.h/x264_config.h in source dir."
+if [ -e "$SRCPATH/config.h" ] || [ -e "$SRCPATH/x264_config.h" ]; then
+    die "Out of tree builds are impossible with config.h/x264_config.h in source dir."
+fi
 
 prefix='/usr/local'
 exec_prefix='${prefix}'
@@ -518,17 +520,23 @@ for opt do
             ;;
         --bit-depth=*)
             bit_depth="$optarg"
-            if [ "$bit_depth" != "8" -a "$bit_depth" != "10" -a "$bit_depth" != "all" ]; then
-                echo "Supplied bit depth must be 8, 10 or all."
-                exit 1
-            fi
+            case "$bit_depth" in
+                8|10|all) ;;
+                *)
+                    echo "Supplied bit depth must be 8, 10 or all."
+                    exit 1
+                    ;;
+            esac
             ;;
         --chroma-format=*)
             chroma_format="$optarg"
-            if [ $chroma_format != "400" -a $chroma_format != "420" -a $chroma_format != "422" -a $chroma_format != "444" -a $chroma_format != "all" ]; then
-                echo "Supplied chroma format must be 400, 420, 422, 444 or all."
-                exit 1
-            fi
+            case "$chroma_format" in
+                400|420|422|444|all) ;;
+                *)
+                    echo "Supplied chroma format must be 400, 420, 422, 444 or all."
+                    exit 1
+                    ;;
+            esac
             ;;
         *)
             echo "Unknown option $opt, ignored"
@@ -536,7 +544,8 @@ for opt do
     esac
 done
 
-[ "$cli" = "no" -a "$shared" = "no" -a "$static" = "no" ] && die "Nothing to build. Enable cli, shared or static."
+[ "$cli" = "no" ] && [ "$shared" = "no" ] && [ "$static" = "no" ] &&
+    die "Nothing to build. Enable cli, shared or static."
 
 CC="${CC-${cross_prefix}gcc}"
 STRIP="${STRIP-${cross_prefix}strip}"
@@ -555,7 +564,7 @@ else
     RANLIB="${RANLIB-${cross_prefix}ranlib}"
 fi
 
-if [ "x$host" = x ]; then
+if [ -z "$host" ]; then
     host="$(${SRCPATH}/config.guess)"
 fi
 # normalize a triplet into a quadruplet
@@ -564,7 +573,6 @@ host="$(${SRCPATH}/config.sub $host)"
 # split $host
 host_cpu="${host%%-*}"
 host="${host#*-}"
-host_vendor="${host%%-*}"
 host_os="${host#*-}"
 
 trap 'rm -rf conftest*' EXIT
@@ -736,7 +744,7 @@ case $host_cpu in
         fi
         if [ "$SYS" = MACOSX ]; then
             ASFLAGS="$ASFLAGS -f macho32 -DPREFIX"
-        elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
+        elif [ "$SYS" = WINDOWS ] || [ "$SYS" = CYGWIN ]; then
             ASFLAGS="$ASFLAGS -f win32 -DPREFIX"
             LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
             [ $compiler = GNU ] && LDFLAGS="$LDFLAGS -Wl,--dynamicbase,--nxcompat,--tsaware"
@@ -758,7 +766,7 @@ case $host_cpu in
                 CFLAGS="$CFLAGS -arch x86_64"
                 LDFLAGS="$LDFLAGS -arch x86_64"
             fi
-        elif [ "$SYS" = WINDOWS -o "$SYS" = CYGWIN ]; then
+        elif [ "$SYS" = WINDOWS ] || [ "$SYS" = CYGWIN ]; then
             ASFLAGS="$ASFLAGS -f win64"
             if [ $compiler = GNU ]; then
                 # only the GNU toolchain is inconsistent in prefixing function names with _
@@ -876,7 +884,7 @@ fi
 log_msg "x264 configure script"
 if [ -n "$*" ]; then
     msg="Command line options:"
-    for i in $@; do
+    for i do
         msg="$msg \"$i\""
     done
     log_msg "$msg"
@@ -897,12 +905,14 @@ if [ $compiler_style = GNU ]; then
     fi
 fi
 
-if [ $shared = yes -a \( $ARCH = "X86_64" -o $ARCH = "PPC" -o $ARCH = "ALPHA" -o $ARCH = "ARM" -o $ARCH = "IA64" -o $ARCH = "PARISC" -o $ARCH = "MIPS" -o $ARCH = "AARCH64" \) ] ; then
-    pic="yes"
+if [ "$shared" = yes ]; then
+    case "$ARCH" in
+        X86_64|PPC|ALPHA|ARM|IA64|PARISC|MIPS|AARCH64) pic=yes ;;
+    esac
 fi
 
 if cc_check '' '' '' '__attribute__((force_align_arg_pointer))' ; then
-    if [ $compiler = GNU -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
+    if [ "$compiler" = GNU ] && [ "${ARCH%_64}" = X86 ]; then
         if cc_check '' -mpreferred-stack-boundary=6 ; then
             CFLAGS="$CFLAGS -mpreferred-stack-boundary=6"
             stack_alignment=64
@@ -918,7 +928,7 @@ if cc_check '' '' '' '__attribute__((force_align_arg_pointer))' ; then
                 stack_alignment=16
             fi
         fi
-    elif [ $compiler = ICC -a $ARCH = X86 ]; then
+    elif [ "$compiler" = ICC ] && [ "$ARCH" = X86 ]; then
         # icc on linux has various degrees of mod16 stack support
         if [ $SYS = LINUX ]; then
             # >= 12 defaults to a mod16 stack
@@ -934,7 +944,7 @@ if cc_check '' '' '' '__attribute__((force_align_arg_pointer))' ; then
     fi
 fi
 
-if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
+if [ "$asm" = auto ] && [ "${ARCH%_64}" = X86 ]; then
     if ! as_check "vmovdqa32 [eax]{k1}{z}, zmm0" ; then
         VER="$( ($AS --version || echo no assembler) 2>/dev/null | head -n 1 )"
         echo "Found $VER"
@@ -946,7 +956,7 @@ if [ $asm = auto -a \( $ARCH = X86 -o $ARCH = X86_64 \) ] ; then
     define HAVE_MMX
 fi
 
-if [ $asm = auto -a $ARCH = ARM ] ; then
+if [ "$asm" = auto ] && [ "$ARCH" = ARM ]; then
     # set flags so neon is built by default
     [ $compiler = CL ] || echo $CFLAGS | grep -Eq '(-mcpu|-march|-mfpu)' || CFLAGS="$CFLAGS -mcpu=cortex-a8 -mfpu=neon"
 
@@ -966,7 +976,7 @@ if [ $asm = auto -a $ARCH = ARM ] ; then
     fi
 fi
 
-if [ $asm = auto -a $ARCH = AARCH64 ] ; then
+if [ "$asm" = auto ] && [ "$ARCH" = AARCH64 ] ; then
     if [ $compiler = CL ] && cpp_check '' '' 'defined(_M_ARM64)' ; then
         define HAVE_AARCH64
         define HAVE_NEON
@@ -981,12 +991,16 @@ if [ $asm = auto -a $ARCH = AARCH64 ] ; then
     fi
 fi
 
-if [ $asm = auto -a \( $ARCH = ARM -o $ARCH = AARCH64 \) ] ; then
-    # check if the assembler supports '.func' (clang 3.5 does not)
-    as_check ".func test${NL}.endfunc" && define HAVE_AS_FUNC 1
+if [ "$asm" = auto ]; then
+    case "$ARCH" in
+        ARM|AARCH64)
+            # check if the assembler supports '.func' (clang 3.5 does not)
+            as_check ".func test${NL}.endfunc" && define HAVE_AS_FUNC 1
+            ;;
+    esac
 fi
 
-if [ $asm = auto -a $ARCH = MIPS ] ; then
+if [ "$asm" = auto ] && [ "$ARCH" = MIPS ] ; then
     if ! echo $CFLAGS | grep -Eq '(-march|-mmsa|-mno-msa)' ; then
         cc_check '' '-mmsa -mfp64 -mhard-float' && CFLAGS="-mmsa -mfp64 -mhard-float $CFLAGS"
     fi
@@ -1001,7 +1015,7 @@ if [ $asm = auto -a $ARCH = MIPS ] ; then
 fi
 
 [ $asm = no ] && AS=""
-[ "x$AS" = x ] && asm="no" || asm="yes"
+[ -z "$AS" ] && asm="no" || asm="yes"
 
 define ARCH_$ARCH
 define SYS_$SYS
@@ -1013,7 +1027,7 @@ ASFLAGS="$ASFLAGS -DSTACK_ALIGNMENT=$stack_alignment"
 CPU_ENDIAN="little-endian"
 if [ $compiler = GNU ]; then
     echo "int i[2] = {0x42494745,0}; double f[2] = {0x1.0656e6469616ep+102,0};" > conftest.c
-    $CC $CFLAGS conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
+    $CC $CFLAGS -fno-lto conftest.c -c -o conftest.o 2>/dev/null || die "endian test failed"
     if (${cross_prefix}strings -a conftest.o | grep -q BIGE) && (${cross_prefix}strings -a conftest.o | grep -q FPendian) ; then
         define WORDS_BIGENDIAN
         CPU_ENDIAN="big-endian"
@@ -1022,7 +1036,7 @@ if [ $compiler = GNU ]; then
     fi
 fi
 
-if [ "$cli_libx264" = "system" -a "$shared" != "yes" ] ; then
+if [ "$cli_libx264" = "system" ] && [ "$shared" != "yes" ] ; then
     [ "$static" = "yes" ] && die "Option --system-libx264 can not be used together with --enable-static"
     if pkg_check x264 ; then
         X264_LIBS="$($PKGCONFIG --libs x264)"
@@ -1037,7 +1051,7 @@ fi
 # autodetect options that weren't forced nor disabled
 
 libpthread=""
-if [ "$SYS" = "WINDOWS" -a "$thread" = "posix" ] ; then
+if [ "$SYS" = "WINDOWS" ] && [ "$thread" = "posix" ] ; then
     if [ "$gpl" = "no" ] ; then
         echo "Warning: pthread-win32 is LGPL and is therefore not supported with --disable-gpl"
         thread="no"
@@ -1106,7 +1120,7 @@ if [ "$SYS" != "WINDOWS" ] && cpp_check "sys/mman.h unistd.h" "" "defined(MAP_PR
     define HAVE_MMAP
 fi
 
-if [ "$SYS" = "LINUX" -a \( "$ARCH" = "X86" -o "$ARCH" = "X86_64" \) ] && cc_check "sys/mman.h" "" "MADV_HUGEPAGE;" ; then
+if [ "$SYS" = "LINUX" ] && [ "${ARCH%_64}" = X86 ] && cc_check "sys/mman.h" "" "MADV_HUGEPAGE;" ; then
     define HAVE_THP
 fi
 
@@ -1157,7 +1171,7 @@ if [ "$lavf" = "auto" ] ; then
             echo "Warning: libavformat is too old"
         fi
     fi
-    if [ "$lavf" = "yes" -a "$swscale" = "no" ]; then
+    if [ "$lavf" = "yes" ] && [ "$swscale" = "no" ]; then
         echo "Warning: libavformat is not supported without swscale support"
         lavf="no"
     fi
@@ -1185,7 +1199,7 @@ if [ "$ffms" = "auto" ] ; then
        ffms="no"
        echo "Warning: $error"
     fi
-    if [ "$ffms" = "yes" -a "$swscale" = "no" ]; then
+    if [ "$ffms" = "yes" ] && [ "$swscale" = "no" ]; then
         echo "Warning: ffms is not supported without swscale support"
         ffms="no"
     fi
@@ -1224,7 +1238,7 @@ if [ "$lsmash" = "auto" ] ; then
     fi
 fi
 
-if [ "$gpac" = "auto" -a "$lsmash" != "yes" ] ; then
+if [ "$gpac" = "auto" ] && [ "$lsmash" != "yes" ] ; then
     gpac="no"
     GPAC_LIBS="-lgpac_static"
     cc_check "" -lz && GPAC_LIBS="$GPAC_LIBS -lz"
@@ -1259,7 +1273,7 @@ if [ "$avs" = "auto" ] ; then
         avs="avisynth"
         define HAVE_AVS
         define USE_AVXSYNTH 0
-    elif [ "$SYS" = "LINUX" -o "$SYS" = "MACOSX" ] ; then
+    elif [ "$SYS" = "LINUX" ] || [ "$SYS" = "MACOSX" ] ; then
     # AvxSynth currently only supports Linux and OSX
         avs="avxsynth"
         define HAVE_AVS
@@ -1272,14 +1286,14 @@ fi
 cc_check "stdint.h" "" "uint32_t test_vec __attribute__ ((vector_size (16))) = {0,1,2,3};" && define HAVE_VECTOREXT
 
 if [ "$pic" = "yes" ] ; then
-    [ "$SYS" != WINDOWS -a "$SYS" != CYGWIN ] && CFLAGS="$CFLAGS -fPIC"
+    [ "$SYS" != WINDOWS ] && [ "$SYS" != CYGWIN ] && CFLAGS="$CFLAGS -fPIC"
     [ "${ASFLAGS#*-DPIC}" = "$ASFLAGS" ] && ASFLAGS="$ASFLAGS -DPIC"
     # resolve textrels in the x86 asm
     cc_check stdio.h "-shared -Wl,-Bsymbolic" && SOFLAGS="$SOFLAGS -Wl,-Bsymbolic"
-    [ $SYS = SunOS -a "$ARCH" = "X86" ] && SOFLAGS="$SOFLAGS -mimpure-text"
+    [ $SYS = SunOS ] && [ "$ARCH" = "X86" ] && SOFLAGS="$SOFLAGS -mimpure-text"
 fi
 
-if [ "$debug" != "yes" -a "$gprof" != "yes" ]; then
+if [ "$debug" != "yes" ] && [ "$gprof" != "yes" ]; then
     CFLAGS="$CFLAGS -fomit-frame-pointer"
 fi
 
@@ -1304,7 +1318,7 @@ if cc_check '' -fno-tree-vectorize ; then
     CFLAGS="$CFLAGS -fno-tree-vectorize"
 fi
 
-if [ $SYS = WINDOWS -a $ARCH = X86 -a $compiler = GNU ] ; then
+if [ "$SYS" = WINDOWS ] && [ "$ARCH" = X86 ] && [ "$compiler" = GNU ] ; then
     # workaround gcc/ld bug with alignment of static variables/arrays that are initialized to zero
     cc_check '' -fno-zero-initialized-in-bss && CFLAGS="$CFLAGS -fno-zero-initialized-in-bss"
 fi
@@ -1332,7 +1346,7 @@ if [ $compiler = GNU ] && cc_check '' -fvisibility=hidden ; then
     CFLAGS="$CFLAGS -fvisibility=hidden"
 fi
 
-if [ $compiler = ICC -o $compiler = ICL ] ; then
+if [ $compiler = ICC ] || [ $compiler = ICL ] ; then
     if cc_check 'extras/intel_dispatcher.h' '' 'x264_intel_dispatcher_override();' ; then
         define HAVE_INTEL_DISPATCHER
     fi
@@ -1363,7 +1377,7 @@ if [ "$opencl" = "yes" ]; then
     if [ $SYS = WINDOWS ] || ([ $SYS = CYGWIN ] && cc_check windows.h "" "LoadLibraryW(0);") ; then
         opencl="yes"
         define HAVE_OPENCL "(BIT_DEPTH==8)"
-    elif [ "$SYS" = "LINUX" -o "$SYS" = "MACOSX" ] ; then
+    elif [ "$SYS" = "LINUX" ] || [ "$SYS" = "MACOSX" ] ; then
         opencl="yes"
         define HAVE_OPENCL "(BIT_DEPTH==8)"
         libdl="-ldl"
@@ -1395,7 +1409,7 @@ fi
 
 if [ "$cli_libx264" = "system" ] ; then
     if [ "$shared" = "yes" ]; then
-        if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
+        if [ "$SYS" = "WINDOWS" ] || [ "$SYS" = "CYGWIN" ]; then
             CLI_LIBX264='$(IMPLIBNAME)'
         else
             CLI_LIBX264='$(SONAME)'
@@ -1448,9 +1462,9 @@ if [ $compiler != GNU ]; then
     CFLAGSSO="$(cc_cflags $CFLAGSSO)"
     CFLAGSCLI="$(cc_cflags $CFLAGSCLI)"
 fi
-if [ $compiler = ICC -o $compiler = ICL ]; then
+if [ $compiler = ICC ] || [ $compiler = ICL ]; then
     # icc does not define __SSE__ until SSE2 optimization and icl never defines it or _M_IX86_FP
-    [ \( $ARCH = X86_64 -o $ARCH = X86 \) -a $asm = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__
+    [ "${ARCH%_64}" = X86 ] && [ "$asm" = yes ] && ! cpp_check "" "" "defined(__SSE__)" && define __SSE__
     PROF_GEN_CC="${QPRE}prof-gen ${QPRE}prof-dir."
     PROF_GEN_LD=
     PROF_USE_CC="${QPRE}prof-use ${QPRE}prof-dir."
@@ -1528,7 +1542,7 @@ fi
 
 if [ "$shared" = "yes" ]; then
     API=$(grep '#define X264_BUILD' < ${SRCPATH}/x264.h | cut -f 3 -d ' ')
-    if [ "$SYS" = "WINDOWS" -o "$SYS" = "CYGWIN" ]; then
+    if [ "$SYS" = "WINDOWS" ] || [ "$SYS" = "CYGWIN" ]; then
         echo "SONAME=libx264-$API.dll" >> config.mak
         if [ $compiler_style = MS ]; then
             echo 'IMPLIBNAME=libx264.dll.lib' >> config.mak
-- 
2.25.0



More information about the x264-devel mailing list