test/configure

branch
configure-evo
changeset 52
afcb57893858
parent 51
5c12e9e29733
child 53
704368f1bb23
--- a/test/configure	Tue Sep 12 23:36:45 2023 +0200
+++ b/test/configure	Thu Sep 14 22:59:05 2023 +0200
@@ -1,11 +1,19 @@
 #!/bin/sh
 
-HOST=`uname -n`
-PREFIX=`pwd`/work
-INSTALL_DIR=$PREFIX
+# create temporary directory
+TEMP_DIR=".tmp-$(uname -n)"
+rm -Rf "$TEMP_DIR"
+if ! mkdir -p "$TEMP_DIR"; then
+    echo "Cannot create tmp dir $TEMP_DIR"
+    echo "Abort"
+    exit 1
+fi
+touch "$TEMP_DIR/options"
+touch "$TEMP_DIR/features"
 
-EPREFIX=$PREFIX
-
+# define standard variables
+PREFIX=/usr
+EPREFIX=/usr
 BINDIR=
 SBINDIR=
 LIBDIR=
@@ -18,21 +26,21 @@
 INFODIR=
 MANDIR=
 
-OS=`uname -s`
-OS_VERSION=`uname -r`
-
-TEMP_DIR=".tmp-`uname -n`"
-mkdir -p "$TEMP_DIR"
-if [ $? -ne 0 ]; then
-    echo "Cannot create tmp dir"
-    echo "Abort"
-fi
-touch "$TEMP_DIR/options"
-touch "$TEMP_DIR/features"
+# custom variables
+HOST=$(uname -n)
+PREFIX=$(pwd)/work
+INSTALL_DIR=$PREFIX
 
 # features
 FEATURE_PG=auto
 
+# clean abort
+abort_configure()
+{
+    rm -Rf "$TEMP_DIR"
+    exit 1
+}
+
 # help text
 printhelp()
 {
@@ -83,59 +91,37 @@
         "--includedir="*)     INCLUDEDIR=${ARG#--includedir=} ;;
         "--infodir="*)        INFODIR=${ARG#--infodir=} ;;
         "--mandir"*)          MANDIR=${ARG#--mandir} ;;
-        "--help"*) printhelp; rm -Rf "$TEMP_DIR"; exit 1 ;;
+        "--help"*) printhelp; abort_configure ;;
         "--debug")           BUILD_TYPE="debug" ;;
         "--release")         BUILD_TYPE="release" ;;
         "--enable-pg") FEATURE_PG=on ;;
         "--disable-pg") unset FEATURE_PG ;;
-        "-"*) echo "unknown option: $ARG"; rm -Rf "$TEMP_DIR"; exit 1 ;;
+        "-"*) echo "unknown option: $ARG"; abort_configure ;;
     esac
 done
 
+
 # set dir variables
-if [ -z "$BINDIR" ]; then
-    BINDIR=$EPREFIX/bin
-fi
-if [ -z "$SBINDIR" ]; then
-    SBINDIR=$EPREFIX/sbin
-fi
-if [ -z "$LIBDIR" ]; then
-    LIBDIR=$EPREFIX/lib
-fi
-if [ -z "$LIBEXEC" ]; then
-    LIBEXECDIR=$EPREFIX/libexec
-fi
-if [ -z "$DATADIR" ]; then
-    DATADIR=$PREFIX/share
-fi
-if [ -z "$SYSCONFDIR" ]; then
-    SYSCONFDIR=$PREFIX/etc
-fi
-if [ -z "$SHAREDSTATEDIR" ]; then
-    SHAREDSTATEDIR=$PREFIX/com
-fi
-if [ -z "$LOCALSTATEDIR" ]; then
-    LOCALSTATEDIR=$PREFIX/var
-fi
-if [ -z "$INCLUDEDIR" ]; then
-    INCLUDEDIR=$PREFIX/include
-fi
-if [ -z "$INFODIR" ]; then
-    INFODIR=$PREFIX/info
-fi
-if [ -z "$MANDIR" ]; then
-    MANDIR=$PREFIX/man
-fi
+BINDIR=${BINDIR:-"$EPREFIX/bin"}
+SBINDIR=${SBINDIR:-"$EPREFIX/sbin"}
+LIBDIR=${LIBDIR:-"$EPREFIX/lib"}
+LIBEXECDIR=${LIBEXECDIR:-"$EPREFIX/libexec"}
+DATADIR=${DATADIR:-"$PREFIX/share"}
+SYSCONFDIR=${SYSCONFDIR:-"$PREFIX/etc"}
+SHAREDSTATEDIR=${SHAREDSTATEDIR:-"$PREFIX/com"}
+LOCALSTATEDIR=${LOCALSTATEDIR:-"$PREFIX/var"}
+INCLUDEDIR=${INCLUDEDIR:-"$PREFIX/include"}
+INFODIR=${INFODIR:-"$PREFIX/info"}
+MANDIR=${MANDIR:-"$PREFIX/man"}
 
-which pkg-config > /dev/null
-if [ $? -eq 0 ]; then
-    PKG_CONFIG=pkg-config
-else
-    PKG_CONFIG=false
-fi
+# Test for availability of pkg-config
+PKG_CONFIG=$(command -v pkg-config)
+PKG_CONFIG=${PKG_CONFIG:-"false"}
 
 # Simple uname based platform detection
 # $PLATFORM is used for platform dependent dependency selection
+OS=$(uname -s)
+OS_VERSION=$(uname -r)
 printf "detect platform... "
 if [ "$OS" = "SunOS" ]; then
     PLATFORM="solaris sunos unix svr4"
@@ -149,21 +135,13 @@
 if [ "$OS" = "Darwin" ]; then
     PLATFORM="macos osx bsd unix"
 fi
-echo "$OS" | grep -i "MINGW" > /dev/null
-if [ $? -eq 0 ]; then
+if echo "$OS" | grep -i "MINGW" > /dev/null; then
     PLATFORM="windows mingw"
 fi
-
-if [ -z "$PLATFORM" ]; then
-    PLATFORM="unix"
-fi
+PLATFORM=${PLATFORM:-"unix"}
 
-for p in $PLATFORM
-do
-    PLATFORM_NAME=$p
-    break
-done
-echo $PLATFORM_NAME
+PLATFORM_NAME=$(echo "$PLATFORM" | cut -f1 -d' ' -)
+echo "$PLATFORM_NAME"
 
 isplatform()
 {
@@ -175,30 +153,12 @@
     done
     return 1
 }
-isnotplatform()
-{
-    for p in $PLATFORM
-    do
-        if [ "$p" = "$1" ]; then
-            return 1
-        fi
-    done
-    return 0
-}
+
 
-# generate config.mk and config.h
-cat > "$TEMP_DIR/config.mk" << __EOF__
-#
-# config.mk generated by configure
-#
-
-# general vars
-HOST=$HOST
+# generate config.mk
+cat > "$TEMP_DIR/vars.mk" << __EOF__
 PREFIX=$PREFIX
-INSTALL_DIR=$INSTALL_DIR
-
 EPREFIX=$EPREFIX
-
 BINDIR=$BINDIR
 SBINDIR=$SBINDIR
 LIBDIR=$LIBDIR
@@ -210,35 +170,34 @@
 INCLUDEDIR=$INCLUDEDIR
 INFODIR=$INFODIR
 MANDIR=$MANDIR
-
+HOST=$HOST
+PREFIX=$PREFIX
+INSTALL_DIR=$INSTALL_DIR
 __EOF__
-
-echo > "$TEMP_DIR/make.mk"
+cat > "$TEMP_DIR/config.mk" << __EOF__
+#
+# config.mk generated by configure
+#
+__EOF__
+sort -u "$TEMP_DIR/vars.mk" >> "$TEMP_DIR/config.mk"
 
-ENV_CFLAGS=$CFLAGS
-ENV_LDFLAGS=$LDFLAGS
-ENV_CXXFLAGS=$CXXFLAGS
 
-# Toolchain detection
+# toolchain detection
 # this will insert make vars to config.mk
 . make/toolchain.sh
-
-# add user specified flags to config.mk
-echo "# project specific flags" >> "$TEMP_DIR/config.mk"
-if [ -n "${ENV_CFLAGS}" ]; then
-    echo "CFLAGS += $ENV_CFLAGS" >> "$TEMP_DIR/config.mk"
-fi
-if [ -n "${ENV_CXXFLAGS}" ]; then
-    echo "CXXFLAGS += $ENV_CXXFLAGS" >> "$TEMP_DIR/config.mk"
-fi
-if [ -n "${ENV_LDFLAGS}" ]; then
-    echo "LDFLAGS += $ENV_LDFLAGS" >> "$TEMP_DIR/config.mk"
+if [ -n "$TOOLCHAIN_ERROR" ]; then
+    echo "Toolchain error: $TOOLCHAIN_ERROR"
+    echo "Abort."
+    abort_configure
 fi
 
 #
 # DEPENDENCIES
 #
 
+# create buffer for make variables required by dependencies
+echo > "$TEMP_DIR/make.mk"
+
 dependency_libpq()
 {
     printf "checking for libpq... "
@@ -248,12 +207,11 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        $PKG_CONFIG libpq
-        if [ $? -ne 0 ] ; then
+        if ! $PKG_CONFIG libpq ; then
             break
         fi
-        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags libpq`"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs libpq`"
+        TEMP_CFLAGS="$TEMP_CFLAGS $("$PKG_CONFIG" --cflags libpq)"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS $("$PKG_CONFIG" --libs libpq)"
         echo yes
         return 0
     done
@@ -270,12 +228,11 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        $PKG_CONFIG openssl
-        if [ $? -ne 0 ] ; then
+        if ! $PKG_CONFIG openssl ; then
             break
         fi
-        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags openssl`"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs openssl`"
+        TEMP_CFLAGS="$TEMP_CFLAGS $("$PKG_CONFIG" --cflags openssl)"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS $("$PKG_CONFIG" --libs openssl)"
         echo yes
         return 0
     done
@@ -283,7 +240,7 @@
     # dependency openssl platform="bsd"
     while true
     do
-        if isnotplatform "bsd"; then
+        if ! isplatform "bsd"; then
             break
         fi
         TEMP_LDFLAGS="$TEMP_LDFLAGS -lssl -lcrypto"
@@ -300,18 +257,16 @@
     # dependency libxml2 platform="macos"
     while true
     do
-        if isnotplatform "macos"; then
+        if ! isplatform "macos"; then
             break
         fi
-        xml2-config --cflags > /dev/null
-        if [ $? -eq 0 ]; then
-            TEMP_CFLAGS="$TEMP_CFLAGS `xml2-config --cflags`"
+        if tmp_flags=$(xml2-config --cflags) ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS $tmp_flags"
         else
             break
         fi
-        xml2-config --libs > /dev/null
-        if [ $? -eq 0 ]; then
-            TEMP_LDFLAGS="$TEMP_LDFLAGS `xml2-config --libs`"
+        if tmp_flags=$(xml2-config --libs) ; then
+            TEMP_LDFLAGS="$TEMP_LDFLAGS $tmp_flags"
         else
             break
         fi
@@ -325,12 +280,11 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        $PKG_CONFIG libxml-2.0
-        if [ $? -ne 0 ] ; then
+        if ! $PKG_CONFIG libxml-2.0 ; then
             break
         fi
-        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags libxml-2.0`"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs libxml-2.0`"
+        TEMP_CFLAGS="$TEMP_CFLAGS $("$PKG_CONFIG" --cflags libxml-2.0)"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS $("$PKG_CONFIG" --libs libxml-2.0)"
         echo yes
         return 0
     done
@@ -341,7 +295,7 @@
 
 DEPENDENCIES_FAILED=
 ERROR=0
-# general dependencies
+# unnamed dependencies
 TEMP_CFLAGS=
 TEMP_LDFLAGS=
 while true
@@ -349,23 +303,18 @@
     while true
     do
 
-
         break
     done
-
     break
 done
 
-# add general dependency flags to config.mk
+# add unnamed dependency flags to config.mk
 echo >> "$TEMP_DIR/config.mk"
 if [ -n "${TEMP_CFLAGS}" ]; then
-    echo "CFLAGS += $TEMP_CFLAGS" >> $TEMP_DIR/config.mk
-fi
-if [ -n "${TEMP_CXXFLAGS}" ]; then
-    echo "CXXFLAGS += $TEMP_CXXFLAGS" >> $TEMP_DIR/config.mk
+    echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/config.mk"
 fi
 if [ -n "${TEMP_LDFLAGS}" ]; then
-    echo "LDFLAGS += $TEMP_LDFLAGS" >> $TEMP_DIR/config.mk
+    echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/config.mk"
 fi
 
 #
@@ -375,22 +324,16 @@
 #
 # TARGETS
 #
-TEMP_CFLAGS=
-TEMP_CXXFLAGS=
-TEMP_LDFLAGS=
 
 # Target
 TEMP_CFLAGS=
 TEMP_LDFLAGS=
-TEMP_CXXFLAGS=
 
-dependency_libxml2
-if [ $? -ne 0 ]; then
+if ! dependency_libxml2; then
     DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libxml2 "
     ERROR=1
 fi
-dependency_openssl
-if [ $? -ne 0 ]; then
+if ! dependency_openssl; then
     DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED openssl "
     ERROR=1
 fi
@@ -398,14 +341,13 @@
 # Features
 if [ -n "$FEATURE_PG" ]; then
     # check dependency
-    dependency_libpq
-    if [ $? -ne 0 ]; then
+    if ! dependency_libpq ; then
         # "auto" features can fail and are just disabled in this case
-        if [ "$FEATURE_PG" != "auto" ]; then
+        if [ "$FEATURE_PG" = "auto" ]; then
+            unset FEATURE_PG
+		else
             DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libpq "
             ERROR=1
-		else
-			unset FEATURE_PG
         fi
     fi
 fi
@@ -415,16 +357,11 @@
 if [ -n "${TEMP_CFLAGS}" ]; then
     echo "CFLAGS  += $TEMP_CFLAGS" >> "$TEMP_DIR/config.mk"
 fi
-if [ -n "${TEMP_CXXFLAGS}" ]; then
-    echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/config.mk"
-fi
 if [ "$BUILD_TYPE" = "debug" ]; then
     echo 'CFLAGS += ${DEBUG_FLAGS}' >> "$TEMP_DIR/config.mk"
-    echo 'CXXFLAGS += ${DEBUG_FLAGS}' >> "$TEMP_DIR/config.mk"
 fi
 if [ "$BUILD_TYPE" = "release" ]; then
     echo 'CFLAGS += ${RELEASE_FLAGS}' >> "$TEMP_DIR/config.mk"
-    echo 'CXXFLAGS += ${RELEASE_FLAGS}' >> "$TEMP_DIR/config.mk"
 fi
 if [ -n "${TEMP_LDFLAGS}" ]; then
     echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/config.mk"
@@ -434,8 +371,7 @@
     echo
     echo "Error: Unresolved dependencies"
     echo "$DEPENDENCIES_FAILED"
-    rm -Rf "$TEMP_DIR"
-    exit 1
+    abort_configure
 fi
 
 echo "configure finished"

mercurial