--- a/src/test/resources/golden-sample/configure2 Tue Sep 12 23:36:45 2023 +0200 +++ b/src/test/resources/golden-sample/configure2 Sun Sep 17 12:40:12 2023 +0200 @@ -1,9 +1,21 @@ #!/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=$PREFIX - +EPREFIX=/usr BINDIR= SBINDIR= LIBDIR= @@ -16,21 +28,18 @@ 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 # features FEATURE_DB=auto +# clean abort +abort_configure() +{ + rm -Rf "$TEMP_DIR" + exit 1 +} + # help text printhelp() { @@ -87,7 +96,7 @@ "--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" ;; "--toolkit="*) OPT_TOOLKIT=${ARG#--toolkit=} ;; @@ -95,54 +104,32 @@ "--disable-db") unset FEATURE_DB ;; "--enable-gui") FEATURE_GUI=on ;; "--disable-gui") unset FEATURE_GUI ;; - "-"*) 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:="$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" @@ -156,21 +143,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() { @@ -182,7 +161,7 @@ done return 1 } -isnotplatform() +notisplatform() { for p in $PLATFORM do @@ -193,17 +172,11 @@ return 0 } -# generate config.mk and config.h -cat > "$TEMP_DIR/config.mk" << __EOF__ -# -# config.mk generated by configure -# -# general vars - +# generate config.mk +cat > "$TEMP_DIR/vars.mk" << __EOF__ PREFIX=$PREFIX EPREFIX=$EPREFIX - BINDIR=$BINDIR SBINDIR=$SBINDIR LIBDIR=$LIBDIR @@ -215,87 +188,82 @@ INCLUDEDIR=$INCLUDEDIR INFODIR=$INFODIR MANDIR=$MANDIR - __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 # -dependency_qt4() +# create buffer for make variables required by dependencies +echo > "$TEMP_DIR/make.mk" + +dependency_error_qt4() { printf "checking for qt4... " # dependency qt4 while true do - which qmake-qt4 > /dev/null - if [ $? -ne 0 ]; then - break + if which qmake-qt4 > /dev/null ; then + : + else + break fi echo yes - return 0 + return 1 done echo no - return 1 + return 0 } -dependency_curl() +dependency_error_curl() { printf "checking for curl... " # dependency curl platform="windows" while true do - if isnotplatform "windows"; then + if notisplatform "windows"; then break fi TEMP_CFLAGS="$TEMP_CFLAGS -I/mingw/include" TEMP_LDFLAGS="$TEMP_LDFLAGS -lcurl" echo yes - return 0 + return 1 done # dependency curl platform="macos" while true do - if isnotplatform "macos"; then + if notisplatform "macos"; then break fi - curl-config --cflags > /dev/null - if [ $? -eq 0 ]; then - TEMP_CFLAGS="$TEMP_CFLAGS `curl-config --cflags`" + if tmp_flags=`curl-config --cflags` ; then + TEMP_CFLAGS="$TEMP_CFLAGS $tmp_flags" else break fi - curl-config --ldflags > /dev/null - if [ $? -eq 0 ]; then - TEMP_LDFLAGS="$TEMP_LDFLAGS `curl-config --ldflags`" + if tmp_flags=`curl-config --ldflags` ; then + TEMP_LDFLAGS="$TEMP_LDFLAGS $tmp_flags" else break fi echo yes - return 0 + return 1 done # dependency curl @@ -304,20 +272,20 @@ if [ -z "$PKG_CONFIG" ]; then break fi - $PKG_CONFIG libcurl - if [ $? -ne 0 ] ; then + if $PKG_CONFIG libcurl ; then + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libcurl`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libcurl`" + else break fi - TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags libcurl`" - TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs libcurl`" echo yes - return 0 + return 1 done echo no - return 1 + return 0 } -dependency_gtk2() +dependency_error_gtk2() { printf "checking for gtk2... " # dependency gtk2 @@ -326,20 +294,20 @@ if [ -z "$PKG_CONFIG" ]; then break fi - $PKG_CONFIG gtk+-2.0 - if [ $? -ne 0 ] ; then + if $PKG_CONFIG gtk+-2.0 ; then + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-2.0`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-2.0`" + else break fi - TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags gtk+-2.0`" - TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs gtk+-2.0`" echo yes - return 0 + return 1 done echo no - return 1 + return 0 } -dependency_sqlite() +dependency_error_sqlite() { printf "checking for sqlite... " # dependency sqlite @@ -348,26 +316,26 @@ if [ -z "$PKG_CONFIG" ]; then break fi - $PKG_CONFIG sqlite3 - if [ $? -ne 0 ] ; then + if $PKG_CONFIG sqlite3 ; then + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sqlite3`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sqlite3`" + else break fi - TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags sqlite3`" - TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs sqlite3`" echo yes - return 0 + return 1 done echo no - return 1 + return 0 } -dependency_test() +dependency_error_test() { printf "checking for test... " # dependency test platform="bsd" while true do - if isnotplatform "bsd"; then + if notisplatform "bsd"; then break fi if isplatform "macos"; then @@ -375,7 +343,7 @@ fi TEMP_CFLAGS="$TEMP_CFLAGS -DBSD" echo yes - return 0 + return 1 done # dependency test @@ -383,13 +351,13 @@ do TEMP_CFLAGS="$TEMP_CFLAGS -DTEST" echo yes - return 0 + return 1 done echo no - return 1 + return 0 } -dependency_gtk3() +dependency_error_gtk3() { printf "checking for gtk3... " # dependency gtk3 @@ -398,20 +366,20 @@ if [ -z "$PKG_CONFIG" ]; then break fi - $PKG_CONFIG gtk+-5.0 - if [ $? -ne 0 ] ; then + if $PKG_CONFIG gtk+-5.0 ; then + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-5.0`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-5.0`" + else break fi - TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags gtk+-5.0`" - TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs gtk+-5.0`" echo yes - return 0 + return 1 done echo no - return 1 + return 0 } -dependency_deptest() +dependency_error_deptest() { printf "checking for deptest... " # dependency deptest @@ -419,13 +387,13 @@ do TEMP_CFLAGS="$TEMP_CFLAGS -DDEPTEST" echo yes - return 0 + return 1 done echo no - return 1 + return 0 } -dependency_libxml2() +dependency_error_libxml2() { printf "checking for libxml2... " # dependency libxml2 @@ -434,28 +402,28 @@ if [ -z "$PKG_CONFIG" ]; then break fi - $PKG_CONFIG --atleast-version=2.8 libxml-2.0 - if [ $? -ne 0 ] ; then + if $PKG_CONFIG --atleast-version=2.8 libxml-2.0 ; then + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libxml-2.0`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libxml-2.0`" + else break fi - TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags libxml-2.0`" - TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs libxml-2.0`" cat >> $TEMP_DIR/make.mk << __EOF__ # Dependency: libxml2 xml = libxml2 __EOF__ echo yes - return 0 + return 1 done echo no - return 1 + return 0 } DEPENDENCIES_FAILED= ERROR=0 -# general dependencies +# unnamed dependencies TEMP_CFLAGS= TEMP_LDFLAGS= while true @@ -468,23 +436,18 @@ MVAR += 123 __EOF__ - 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 # @@ -493,8 +456,7 @@ checkopt_toolkit_gtk3() { VERR=0 - dependency_gtk3 - if [ $? -ne 0 ]; then + if dependency_error_gtk3 ; then VERR=1 fi if [ $VERR -ne 0 ]; then @@ -510,12 +472,10 @@ checkopt_toolkit_cli() { VERR=0 - dependency_curl - if [ $? -ne 0 ]; then + if dependency_error_curl ; then VERR=1 fi - dependency_test - if [ $? -ne 0 ]; then + if dependency_error_test ; then VERR=1 fi if [ $VERR -ne 0 ]; then @@ -526,8 +486,7 @@ checkopt_toolkit_gtk2() { VERR=0 - dependency_gtk2 - if [ $? -ne 0 ]; then + if dependency_error_gtk2 ; then VERR=1 fi if [ $VERR -ne 0 ]; then @@ -538,8 +497,7 @@ checkopt_toolkit_wpf() { VERR=0 - dependency_test - if [ $? -ne 0 ]; then + if dependency_error_test ; then VERR=1 fi if [ $VERR -ne 0 ]; then @@ -551,27 +509,20 @@ # # TARGETS # -TEMP_CFLAGS= -TEMP_CXXFLAGS= -TEMP_LDFLAGS= # Target: dav TEMP_CFLAGS= TEMP_LDFLAGS= -TEMP_CXXFLAGS= -dependency_curl -if [ $? -ne 0 ]; then +if dependency_error_curl; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED curl " ERROR=1 fi -dependency_libxml2 -if [ $? -ne 0 ]; then +if dependency_error_libxml2; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libxml2 " ERROR=1 fi -dependency_test -if [ $? -ne 0 ]; then +if dependency_error_test; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED test " ERROR=1 fi @@ -579,27 +530,25 @@ # Features if [ -n "$FEATURE_DB" ]; then # check dependency - dependency_sqlite - if [ $? -ne 0 ]; then + if dependency_error_sqlite ; then # "auto" features can fail and are just disabled in this case - if [ "$FEATURE_DB" != "auto" ]; then + if [ "$FEATURE_DB" = "auto" ]; then + unset FEATURE_DB + else DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sqlite " ERROR=1 - else - unset FEATURE_DB fi fi fi if [ -n "$FEATURE_GUI" ]; then # check dependency - dependency_gtk3 - if [ $? -ne 0 ]; then + if dependency_error_gtk3 ; then # "auto" features can fail and are just disabled in this case - if [ "$FEATURE_GUI" != "auto" ]; then + if [ "$FEATURE_GUI" = "auto" ]; then + unset FEATURE_GUI + else DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED gtk3 " ERROR=1 - else - unset FEATURE_GUI fi fi fi @@ -608,25 +557,22 @@ if [ -z $OPT_TOOLKIT ]; then SAVED_ERROR="$ERROR" SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED" - ERROR=0 + ERROR=1 while true do if isplatform "windows"; then - checkopt_toolkit_wpf - if [ $? -eq 0 ]; then + if checkopt_toolkit_wpf ; then echo " toolkit: wpf" >> "$TEMP_DIR/options" ERROR=0 break fi fi - checkopt_toolkit_gtk3 - if [ $? -eq 0 ]; then + if checkopt_toolkit_gtk3 ; then echo " toolkit: gtk3" >> "$TEMP_DIR/options" ERROR=0 break fi - checkopt_toolkit_gtk2 - if [ $? -eq 0 ]; then + if checkopt_toolkit_gtk2 ; then echo " toolkit: gtk2" >> "$TEMP_DIR/options" ERROR=0 break @@ -643,26 +589,30 @@ false elif [ "$OPT_TOOLKIT" = "gtk3" ]; then echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options - checkopt_toolkit_gtk3 - if [ $? -ne 0 ]; then + if checkopt_toolkit_gtk3 ; then + : + else ERROR=1 fi elif [ "$OPT_TOOLKIT" = "cli" ]; then echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options - checkopt_toolkit_cli - if [ $? -ne 0 ]; then + if checkopt_toolkit_cli ; then + : + else ERROR=1 fi elif [ "$OPT_TOOLKIT" = "gtk2" ]; then echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options - checkopt_toolkit_gtk2 - if [ $? -ne 0 ]; then + if checkopt_toolkit_gtk2 ; then + : + else ERROR=1 fi elif [ "$OPT_TOOLKIT" = "wpf" ]; then echo " toolkit: $OPT_TOOLKIT" >> $TEMP_DIR/options - checkopt_toolkit_wpf - if [ $? -ne 0 ]; then + if checkopt_toolkit_wpf ; then + : + else ERROR=1 fi fi @@ -672,16 +622,11 @@ if [ -n "${TEMP_CFLAGS}" ]; then echo "DAV_CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/config.mk" fi -if [ -n "${TEMP_CXXFLAGS}" ]; then - echo "DAV_CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/config.mk" -fi if [ "$BUILD_TYPE" = "debug" ]; then echo 'DAV_CFLAGS += ${DEBUG_FLAGS}' >> "$TEMP_DIR/config.mk" - echo 'DAV_CXXFLAGS += ${DEBUG_FLAGS}' >> "$TEMP_DIR/config.mk" fi if [ "$BUILD_TYPE" = "release" ]; then echo 'DAV_CFLAGS += ${RELEASE_FLAGS}' >> "$TEMP_DIR/config.mk" - echo 'DAV_CXXFLAGS += ${RELEASE_FLAGS}' >> "$TEMP_DIR/config.mk" fi if [ -n "${TEMP_LDFLAGS}" ]; then echo "DAV_LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/config.mk" @@ -690,10 +635,8 @@ # Target TEMP_CFLAGS= TEMP_LDFLAGS= -TEMP_CXXFLAGS= -dependency_deptest -if [ $? -ne 0 ]; then +if dependency_error_deptest; then DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED deptest " ERROR=1 fi @@ -705,16 +648,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" @@ -724,8 +662,7 @@ echo echo "Error: Unresolved dependencies" echo "$DEPENDENCIES_FAILED" - rm -Rf "$TEMP_DIR" - exit 1 + abort_configure fi echo "configure finished"