test/make/configure.vm

changeset 61
2c68549dabef
parent 59
410e4f942ce7
child 63
ac47c2fb2c4a
--- a/test/make/configure.vm	Tue Sep 12 23:36:45 2023 +0200
+++ b/test/make/configure.vm	Sun Sep 17 12:40:12 2023 +0200
@@ -1,5 +1,34 @@
 #!/bin/sh
 
+# create temporary directory
+TEMP_DIR=".tmp-`uname -n`"
+rm -Rf "$TEMP_DIR"
+if mkdir -p "$TEMP_DIR"; then
+    :
+else
+    echo "Cannot create tmp dir $TEMP_DIR"
+    echo "Abort"
+    exit 1
+fi
+touch "$TEMP_DIR/options"
+touch "$TEMP_DIR/features"
+
+# define standard variables
+PREFIX=/usr
+EPREFIX=/usr
+BINDIR=
+SBINDIR=
+LIBDIR=
+LIBEXECDIR=
+DATADIR=
+SYSCONFDIR=
+SHAREDSTATEDIR=
+LOCALSTATEDIR=
+INCLUDEDIR=
+INFODIR=
+MANDIR=
+
+# custom variables
 #foreach( $var in $vars )
 #if( $var.exec )
 ${var.varName}=`${var.value}`
@@ -8,59 +37,6 @@
 #end
 #end
 
-#if ( ! $project.hasVar("PREFIX") )
-PREFIX=/usr
-#end
-#if ( ! $project.hasVar("EPREFIX") )
-EPREFIX=$PREFIX
-#end
-
-#if ( ! $project.hasVar("BINDIR") )
-BINDIR=
-#end
-#if ( ! $project.hasVar("SBINDIR") )
-SBINDIR=
-#end
-#if ( ! $project.hasVar("LIBDIR") )
-LIBDIR=
-#end
-#if ( ! $project.hasVar("LIBEXECDIR") )
-LIBEXECDIR=
-#end
-#if ( ! $project.hasVar("DATADIR") )
-DATADIR=
-#end
-#if ( ! $project.hasVar("SYSCONFDIR") )
-SYSCONFDIR=
-#end
-#if ( ! $project.hasVar("SHAREDSTATEDIR") )
-SHAREDSTATEDIR=
-#end
-#if ( ! $project.hasVar("LOCALSTATEDIR") )
-LOCALSTATEDIR=
-#end
-#if ( ! $project.hasVar("INCLUDEDIR") )
-INCLUDEDIR=
-#end
-#if ( ! $project.hasVar("INFODIR") )
-INFODIR=
-#end
-#if ( ! $project.hasVar("MANDIR") )
-MANDIR=
-#end
-
-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"
-
 # features
 #foreach( $feature in $features )
 #if( ${feature.isDefault()} )
@@ -68,6 +44,13 @@
 #end
 #end
 
+# clean abort
+abort_configure()
+{
+    rm -Rf "$TEMP_DIR"
+    exit 1
+}
+
 # help text
 printhelp()
 {
@@ -136,7 +119,7 @@
         "--includedir="*)     INCLUDEDIR=${D}{ARG#--includedir=} ;;
         "--infodir="*)        INFODIR=${D}{ARG#--infodir=} ;;
         "--mandir"*)          MANDIR=${D}{ARG#--mandir} ;;
-        "--help"*) printhelp; rm -Rf "$TEMP_DIR"; exit 1 ;;
+        "--help"*) printhelp; abort_configure ;;
         "--debug")           BUILD_TYPE="debug" ;;
         "--release")         BUILD_TYPE="release" ;;
     #foreach( $opt in $options )
@@ -146,54 +129,33 @@
         "--enable-${feature.arg}") ${feature.getVarName()}=on ;;
         "--disable-${feature.arg}") unset ${feature.getVarName()} ;;
     #end
-        "-"*) echo "unknown option: $ARG"; rm -Rf "$TEMP_DIR"; exit 1 ;;
+        "-"*) echo "unknown option: $ARG"; abort_configure ;;
     esac
 done
 
+## Begin unparsed content. **
+#[[
 # 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:="$EPREFIX/bin"}
+: ${SBINDIR:="$EPREFIX/sbin"}
+: ${LIBDIR:="$EPREFIX/lib"}
+: ${LIBEXECDIR:="$EPREFIX/libexec"}
+: ${DATADIR:="$PREFIX/share"}
+: ${SYSCONFDIR:="$PREFIX/etc"}
+: ${SHAREDSTATEDIR:="$PREFIX/com"}
+: ${LOCALSTATEDIR:="$PREFIX/var"}
+: ${INCLUDEDIR:="$PREFIX/include"}
+: ${INFODIR:="$PREFIX/info"}
+: ${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:="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"
@@ -207,21 +169,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:="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()
 {
@@ -233,7 +187,7 @@
     done
     return 1
 }
-isnotplatform()
+notisplatform()
 {
     for p in $PLATFORM
     do
@@ -243,89 +197,54 @@
     done
     return 0
 }
+]]#
+## End of unparsed content **
 
-# generate config.mk and config.h
+# generate config.mk
+cat > "$TEMP_DIR/vars.mk" << __EOF__
+PREFIX=$PREFIX
+EPREFIX=$EPREFIX
+BINDIR=$BINDIR
+SBINDIR=$SBINDIR
+LIBDIR=$LIBDIR
+LIBEXECDIR=$LIBEXECDIR
+DATADIR=$DATADIR
+SYSCONFDIR=$SYSCONFDIR
+SHAREDSTATEDIR=$SHAREDSTATEDIR
+LOCALSTATEDIR=$LOCALSTATEDIR
+INCLUDEDIR=$INCLUDEDIR
+INFODIR=$INFODIR
+MANDIR=$MANDIR
+#foreach( $var in $vars )
+${var.varName}=$${var.varName}
+#end
+__EOF__
 cat > "$TEMP_DIR/config.mk" << __EOF__
 #
 # config.mk generated by configure
 #
-
-# general vars
-#foreach( $var in $vars )
-${var.varName}=$${var.varName}
-#end
-
-#if ( ! $project.hasVar("PREFIX") )
-PREFIX=$PREFIX
-#end
-#if ( ! $project.hasVar("EPREFIX") )
-EPREFIX=$EPREFIX
-#end
+__EOF__
+sort -u "$TEMP_DIR/vars.mk" >> "$TEMP_DIR/config.mk"
 
-#if ( ! $project.hasVar("BINDIR") )
-BINDIR=$BINDIR
-#end
-#if ( ! $project.hasVar("SBINDIR") )
-SBINDIR=$SBINDIR
-#end
-#if ( ! $project.hasVar("LIBDIR") )
-LIBDIR=$LIBDIR
-#end
-#if ( ! $project.hasVar("LIBEXECDIR") )
-LIBEXECDIR=$LIBEXECDIR
-#end
-#if ( ! $project.hasVar("DATADIR") )
-DATADIR=$DATADIR
-#end
-#if ( ! $project.hasVar("SYSCONFDIR") )
-SYSCONFDIR=$SYSCONFDIR
-#end
-#if ( ! $project.hasVar("SHAREDSTATEDIR") )
-SHAREDSTATEDIR=$SHAREDSTATEDIR
-#end
-#if ( ! $project.hasVar("LOCALSTATEDIR") )
-LOCALSTATEDIR=$LOCALSTATEDIR
-#end
-#if ( ! $project.hasVar("INCLUDEDIR") )
-INCLUDEDIR=$INCLUDEDIR
-#end
-#if ( ! $project.hasVar("INFODIR") )
-INFODIR=$INFODIR
-#end
-#if ( ! $project.hasVar("MANDIR") )
-MANDIR=$MANDIR
-#end
 
-__EOF__
-
-echo > "$TEMP_DIR/make.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"
+
 #foreach( $dependency in $namedDependencies )
-dependency_${dependency.name}()
+dependency_error_${dependency.name}()
 {
     printf "checking for ${dependency.name}... "
     #foreach( $sub in $dependency.getSubdependencies() )
@@ -333,12 +252,12 @@
     while true
     do
         #if( $sub.platform )
-        if isnotplatform "${sub.platform}"; then
+        if notisplatform "${sub.platform}"; then
             break
         fi
         #end
-        #foreach( $not in $sub.getNotList() )
-        if isplatform "${not}"; then
+        #foreach( $np in $sub.getNotList() )
+        if isplatform "${np}"; then
             break
         fi
         #end
@@ -348,24 +267,24 @@
         fi
         #end
         #foreach( $test in $sub.tests )
-        $test > /dev/null
-        if [ $? -ne 0 ]; then
-        break
+        if $test > /dev/null ; then
+            :
+        else
+            break
         fi
         #end
         #foreach( $pkg in $sub.pkgconfig )
-        $pkg.getPkgConfigTestQuery()
-        if [ $? -ne 0 ] ; then
+        if $pkg.getPkgConfigTestQuery() ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"
+        else
             break
         fi
-        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags $pkg.name`"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs $pkg.name`"
         #end
         #foreach( $flags in $sub.flags )
         #if( $flags.exec )
-        $flags.value > /dev/null
-        if [ $? -eq 0 ]; then
-            TEMP_$flags.varName="$TEMP_$flags.varName `$flags.value`"
+        if tmp_flags=`$flags.value` ; then
+            TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags"
         else
             break
         fi
@@ -380,31 +299,31 @@
 __EOF__
         #end
         echo yes
-        return 0
+        return 1
     done
 
     #end
     echo no
-    return 1
+    return 0
 }
 #end
 
 DEPENDENCIES_FAILED=
 ERROR=0
 #if( $dependencies.size() > 0 )
-# general dependencies
+# unnamed dependencies
 TEMP_CFLAGS=
 TEMP_LDFLAGS=
 #foreach( $dependency in $dependencies )
 while true
 do
     #if( $dependency.platform )
-    if isnotplatform "${dependency.platform}"; then
+    if notisplatform "${dependency.platform}"; then
         break
     fi
     #end
-    #foreach( $not in $dependency.getNotList() )
-    if isplatform "${not}"; then
+    #foreach( $np in $dependency.getNotList() )
+    if isplatform "${np}"; then
         break
     fi
     #end
@@ -418,22 +337,22 @@
         #end
         #foreach( $pkg in $dependency.pkgconfig )
         printf "checking for pkg-config package $pkg.name... "
-        $pkg.getPkgConfigTestQuery()
-        if [ $? -ne 0 ]; then
+        if $pkg.getPkgConfigTestQuery() ; then
+            echo yes
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"
+        else
             echo no
             ERROR=1
             break
         fi
-        echo yes
-        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags $pkg.name`"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs $pkg.name`"
         #end
 
         #foreach( $flags in $dependency.flags )
         #if( $flags.exec )
         $flags.value > /dev/null
-        if [ $? -ne 0 ]; then
-            TEMP_$flags.varName="$TEMP_$flags.varName `$flags.value`"
+        if tmp_flags=`$flags.value` ; then
+            TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags"
         else
             ERROR=1
             break
@@ -447,24 +366,19 @@
 $dependency.make
 __EOF__
         #end
-
         break
     done
-
     break
 done
 #end
 
-# 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
 #end
 
@@ -477,8 +391,7 @@
 {
     VERR=0
     #foreach( $dep in $val.dependencies )
-    dependency_$dep
-    if [ $? -ne 0 ]; then
+    if dependency_error_$dep ; then
         VERR=1
     fi
     #end
@@ -501,9 +414,6 @@
 #
 # TARGETS
 #
-TEMP_CFLAGS=
-TEMP_CXXFLAGS=
-TEMP_LDFLAGS=
 
 #foreach( $target in $targets )
 #if ( $target.name )
@@ -513,11 +423,9 @@
 #end
 TEMP_CFLAGS=
 TEMP_LDFLAGS=
-TEMP_CXXFLAGS=
 
 #foreach( $dependency in $target.dependencies )
-dependency_$dependency
-if [ $? -ne 0 ]; then
+if dependency_error_$dependency; then
     DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
     ERROR=1
 fi
@@ -528,14 +436,13 @@
 if [ -n "$${feature.getVarName()}" ]; then
 #foreach( $dependency in $feature.dependencies )
     # check dependency
-    dependency_$dependency
-    if [ $? -ne 0 ]; then
+    if dependency_error_$dependency ; then
         # "auto" features can fail and are just disabled in this case
-        if [ "$${feature.getVarName()}" != "auto" ]; then
+        if [ "$${feature.getVarName()}" = "auto" ]; then
+            unset ${feature.getVarName()}
+		else
             DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
             ERROR=1
-		else
-			unset ${feature.getVarName()}
         fi
     fi
 #end
@@ -547,15 +454,14 @@
 if [ -z ${D}${opt.getVarName()} ]; then
     SAVED_ERROR="$ERROR"
     SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
-    ERROR=0
+    ERROR=1
     while true
     do
         #foreach( $optdef in $opt.defaults )
         #if( $optdef.platform )
         if isplatform "$optdef.platform"; then
         #end
-        $optdef.func
-        if [ $? -eq 0 ]; then
+        if $optdef.func ; then
             echo "  ${opt.argument}: ${optdef.valueName}" >> "$TEMP_DIR/options"
             ERROR=0
             break
@@ -577,8 +483,9 @@
     #foreach( $optval in $opt.values )
     elif [ "${D}${opt.getVarName()}" = "${optval.value}" ]; then
         echo "  ${opt.argument}: ${D}${opt.getVarName()}" >> $TEMP_DIR/options
-        $optval.func
-        if [ $? -ne 0 ]; then
+        if $optval.func ; then
+            :
+        else
             ERROR=1
         fi
     #end
@@ -590,16 +497,11 @@
 if [ -n "${TEMP_CFLAGS}" ]; then
     echo "${target.getCFlags()}  += $TEMP_CFLAGS" >> "$TEMP_DIR/config.mk"
 fi
-if [ -n "${TEMP_CXXFLAGS}" ]; then
-    echo "${target.getCXXFlags()} += $TEMP_CXXFLAGS" >> "$TEMP_DIR/config.mk"
-fi
 if [ "$BUILD_TYPE" = "debug" ]; then
     echo '${target.getCFlags()} += ${DEBUG_FLAGS}' >> "$TEMP_DIR/config.mk"
-    echo '${target.getCXXFlags()} += ${DEBUG_FLAGS}' >> "$TEMP_DIR/config.mk"
 fi
 if [ "$BUILD_TYPE" = "release" ]; then
     echo '${target.getCFlags()} += ${RELEASE_FLAGS}' >> "$TEMP_DIR/config.mk"
-    echo '${target.getCXXFlags()} += ${RELEASE_FLAGS}' >> "$TEMP_DIR/config.mk"
 fi
 if [ -n "${TEMP_LDFLAGS}" ]; then
     echo "${target.getLDFlags()} += $TEMP_LDFLAGS" >> "$TEMP_DIR/config.mk"
@@ -610,8 +512,7 @@
     echo
     echo "Error: Unresolved dependencies"
     echo "$DEPENDENCIES_FAILED"
-    rm -Rf "$TEMP_DIR"
-    exit 1
+    abort_configure
 fi
 
 echo "configure finished"

mercurial