src/test/resources/golden-sample/configure

Fri, 15 Sep 2023 14:06:50 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 15 Sep 2023 14:06:50 +0200
branch
configure-evo
changeset 54
2b8f40c58944
parent 52
afcb57893858
child 60
43d6680e6410
permissions
-rwxr-xr-x

make configure script svr4 compatible again

#!/bin/sh

# 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"

# define standard variables
PREFIX=/usr
EPREFIX=/usr
BINDIR=
SBINDIR=
LIBDIR=
LIBEXECDIR=
DATADIR=
SYSCONFDIR=
SHAREDSTATEDIR=
LOCALSTATEDIR=
INCLUDEDIR=
INFODIR=
MANDIR=

# 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()
{
    echo "Usage: $0 [OPTIONS]..."
    cat << __EOF__
Installation directories:
  --prefix=PREFIX         path prefix for architecture-independent files
                          [/usr]
  --exec-prefix=EPREFIX   path prefix for architecture-dependent files
                          [PREFIX]

  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        system configuration files [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --mandir=DIR            man documentation [DATAROOTDIR/man]

Optional Features:
  --disable-pg

__EOF__
}

#
# parse arguments
#
BUILD_TYPE="default"
for ARG in "$@"
do
    case "$ARG" in
        "--prefix="*)         PREFIX=${ARG#--prefix=} ;;
        "--exec-prefix="*)    EPREFIX=${ARG#--exec-prefix=} ;;
        "--bindir="*)         BINDIR=${ARG#----bindir=} ;;
        "--sbindir="*)        SBINDIR=${ARG#--sbindir=} ;;
        "--libdir="*)         LIBDIR=${ARG#--libdir=} ;;
        "--libexecdir="*)     LIBEXECDIR=${ARG#--libexecdir=} ;;
        "--datadir="*)        DATADIR=${ARG#--datadir=} ;;
        "--sysconfdir="*)     SYSCONFDIR=${ARG#--sysconfdir=} ;;
        "--sharedstatedir="*) SHAREDSTATEDIR=${ARG#--sharedstatedir=} ;;
        "--localstatedir="*)  LOCALSTATEDIR=${ARG#--localstatedir=} ;;
        "--includedir="*)     INCLUDEDIR=${ARG#--includedir=} ;;
        "--infodir="*)        INFODIR=${ARG#--infodir=} ;;
        "--mandir"*)          MANDIR=${ARG#--mandir} ;;
        "--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"; abort_configure ;;
    esac
done


# set dir variables
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"}

# 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"
fi
if [ "$OS" = "Linux" ]; then
    PLATFORM="linux unix"
fi
if [ "$OS" = "FreeBSD" ]; then
    PLATFORM="freebsd bsd unix"
fi
if [ "$OS" = "Darwin" ]; then
    PLATFORM="macos osx bsd unix"
fi
if echo "$OS" | grep -i "MINGW" > /dev/null; then
    PLATFORM="windows mingw"
fi
PLATFORM=${PLATFORM:-"unix"}

PLATFORM_NAME=$(echo "$PLATFORM" | cut -f1 -d' ' -)
echo "$PLATFORM_NAME"

isplatform()
{
    for p in $PLATFORM
    do
        if [ "$p" = "$1" ]; then
            return 0
        fi
    done
    return 1
}


# 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
HOST=$HOST
PREFIX=$PREFIX
INSTALL_DIR=$INSTALL_DIR
__EOF__
cat > "$TEMP_DIR/config.mk" << __EOF__
#
# config.mk generated by configure
#
__EOF__
sort -u "$TEMP_DIR/vars.mk" >> "$TEMP_DIR/config.mk"


# toolchain detection
# this will insert make vars to config.mk
. make/toolchain.sh
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... "
    # dependency libpq
    while true
    do
        if [ -z "$PKG_CONFIG" ]; then
            break
        fi
        if ! $PKG_CONFIG libpq ; then
            break
        fi
        TEMP_CFLAGS="$TEMP_CFLAGS $("$PKG_CONFIG" --cflags libpq)"
        TEMP_LDFLAGS="$TEMP_LDFLAGS $("$PKG_CONFIG" --libs libpq)"
        echo yes
        return 0
    done

    echo no
    return 1
}
dependency_openssl()
{
    printf "checking for openssl... "
    # dependency openssl
    while true
    do
        if [ -z "$PKG_CONFIG" ]; then
            break
        fi
        if ! $PKG_CONFIG openssl ; then
            break
        fi
        TEMP_CFLAGS="$TEMP_CFLAGS $("$PKG_CONFIG" --cflags openssl)"
        TEMP_LDFLAGS="$TEMP_LDFLAGS $("$PKG_CONFIG" --libs openssl)"
        echo yes
        return 0
    done

    # dependency openssl platform="bsd"
    while true
    do
        if ! isplatform "bsd"; then
            break
        fi
        TEMP_LDFLAGS="$TEMP_LDFLAGS -lssl -lcrypto"
        echo yes
        return 0
    done

    echo no
    return 1
}
dependency_libxml2()
{
    printf "checking for libxml2... "
    # dependency libxml2 platform="macos"
    while true
    do
        if ! isplatform "macos"; then
            break
        fi
        if tmp_flags=$(xml2-config --cflags) ; then
            TEMP_CFLAGS="$TEMP_CFLAGS $tmp_flags"
        else
            break
        fi
        if tmp_flags=$(xml2-config --libs) ; then
            TEMP_LDFLAGS="$TEMP_LDFLAGS $tmp_flags"
        else
            break
        fi
        echo yes
        return 0
    done

    # dependency libxml2
    while true
    do
        if [ -z "$PKG_CONFIG" ]; then
            break
        fi
        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)"
        echo yes
        return 0
    done

    echo no
    return 1
}

DEPENDENCIES_FAILED=
ERROR=0
# unnamed dependencies
TEMP_CFLAGS=
TEMP_LDFLAGS=
while true
do
    while true
    do

        break
    done
    break
done

# 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_LDFLAGS}" ]; then
    echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/config.mk"
fi

#
# OPTION VALUES
#

#
# TARGETS
#

# Target
TEMP_CFLAGS=
TEMP_LDFLAGS=

if ! dependency_libxml2; then
    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libxml2 "
    ERROR=1
fi
if ! dependency_openssl; then
    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED openssl "
    ERROR=1
fi

# Features
if [ -n "$FEATURE_PG" ]; then
    # check dependency
    if ! dependency_libpq ; then
        # "auto" features can fail and are just disabled in this case
        if [ "$FEATURE_PG" = "auto" ]; then
            unset FEATURE_PG
		else
            DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libpq "
            ERROR=1
        fi
    fi
fi


echo >> "$TEMP_DIR/config.mk"
if [ -n "${TEMP_CFLAGS}" ]; then
    echo "CFLAGS  += $TEMP_CFLAGS" >> "$TEMP_DIR/config.mk"
fi
if [ "$BUILD_TYPE" = "debug" ]; then
    echo 'CFLAGS += ${DEBUG_FLAGS}' >> "$TEMP_DIR/config.mk"
fi
if [ "$BUILD_TYPE" = "release" ]; then
    echo 'CFLAGS += ${RELEASE_FLAGS}' >> "$TEMP_DIR/config.mk"
fi
if [ -n "${TEMP_LDFLAGS}" ]; then
    echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/config.mk"
fi

if [ $ERROR -ne 0 ]; then
    echo
    echo "Error: Unresolved dependencies"
    echo "$DEPENDENCIES_FAILED"
    abort_configure
fi

echo "configure finished"
echo
echo "Build Config:"
echo "  PREFIX:    $PREFIX"
echo "  TOOLCHAIN: $TOOLCHAIN_NAME"
echo "Features:"
if [ -n "$FEATURE_PG" ]; then
echo "  pg: on"
else
echo "  pg: off"
fi
echo
cat "$TEMP_DIR/config.mk" "$TEMP_DIR/make.mk" > config.mk
rm -Rf "$TEMP_DIR"

mercurial