configure

Mon, 18 Dec 2023 14:05:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 18 Dec 2023 14:05:12 +0100
changeset 758
6cd62ce7e353
parent 757
49ceea78fce7
child 759
475335643af4
permissions
-rwxr-xr-x

fix #318 - incorrect link to ucx 3 docs

#!/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
# also define standard prefix (this is where we will search for config.site)
prefix=/usr
exec_prefix=
bindir=
sbindir=
libdir=
libexecdir=
datarootdir=
datadir=
sysconfdir=
sharedstatedir=
localstatedir=
runstatedir=
includedir=
infodir=
localedir=
mandir=

# custom variables
src_dir=`pwd`
DOXYGEN=`command -v doxygen`
PANDOC=`command -v pandoc`
CMAKE=`command -v cmake`

# features

# 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]
  --runstatedir=DIR       run-time variable data [LOCALSTATEDIR/run]
  --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]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]

Options:
  --debug                 add extra compile flags for debug builds
  --release               add extra compile flags for release builds
  --with-tests=(yes|no)
  --with-docs=(all|html|api|none)

__EOF__
}

#
# parse arguments
#
BUILD_TYPE="default"
for ARG in "$@"
do
    case "$ARG" in
        "--prefix="*)         prefix=${ARG#--prefix=} ;;
        "--exec-prefix="*)    exec_prefix=${ARG#--exec-prefix=} ;;
        "--bindir="*)         bindir=${ARG#----bindir=} ;;
        "--sbindir="*)        sbindir=${ARG#--sbindir=} ;;
        "--libdir="*)         libdir=${ARG#--libdir=} ;;
        "--libexecdir="*)     libexecdir=${ARG#--libexecdir=} ;;
        "--datarootdir="*)    datarootdir=${ARG#--datarootdir=} ;;
        "--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} ;;
        "--localedir"*)       localedir=${ARG#--localedir} ;;
        "--help"*) printhelp; abort_configure ;;
        "--debug")           BUILD_TYPE="debug" ;;
        "--release")         BUILD_TYPE="release" ;;
        "--with-tests="*) OPT_WITH_TESTS=${ARG#--with-tests=} ;;
        "--with-docs="*) OPT_WITH_DOCS=${ARG#--with-docs=} ;;
        "-"*) echo "unknown option: $ARG"; abort_configure ;;
    esac
done



# set defaults for dir variables
: ${exec_prefix:="$prefix"}
: ${bindir:='${exec_prefix}/bin'}
: ${sbindir:='${exec_prefix}/sbin'}
: ${libdir:='${exec_prefix}/lib'}
: ${libexecdir:='${exec_prefix}/libexec'}
: ${datarootdir:='${prefix}/share'}
: ${datadir:='${datarootdir}'}
: ${sysconfdir:='${prefix}/etc'}
: ${sharedstatedir:='${prefix}/com'}
: ${localstatedir:='${prefix}/var'}
: ${runstatedir:='${localstatedir}/run'}
: ${includedir:='${prefix}/include'}
: ${infodir:='${datarootdir}/info'}
: ${mandir:='${datarootdir}/man'}
: ${localedir:='${datarootdir}/locale'}

# check if a config.site exists and load it
if [ -n "$CONFIG_SITE" ]; then
    # CONFIG_SITE may contain space separated file names
    for cs in $CONFIG_SITE; do
        printf "loading defaults from $cs... "
        . "$cs"
        echo ok
    done
elif [ -f "$prefix/share/config.site" ]; then
    printf "loading site defaults... "
    . "$prefix/share/config.site"
    echo ok
elif [ -f "$prefix/etc/config.site" ]; then
    printf "loading site defaults... "
    . "$prefix/etc/config.site"
    echo ok
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"
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:="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
}
notisplatform()
{
    for p in $PLATFORM
    do
        if [ "$p" = "$1" ]; then
            return 1
        fi
    done
    return 0
}


# generate vars.mk
cat > "$TEMP_DIR/vars.mk" << __EOF__
prefix="$prefix"
exec_prefix="$exec_prefix"
bindir="$bindir"
sbindir="$sbindir"
libdir="$libdir"
libexecdir="$libexecdir"
datarootdir="$datarootdir"
datadir="$datadir"
sysconfdir="$sysconfdir"
sharedstatedir="$sharedstatedir"
localstatedir="$localstatedir"
runstatedir="$runstatedir"
includedir="$includedir"
infodir="$infodir"
mandir="$mandir"
localedir="$localedir"
src_dir="$src_dir"
DOXYGEN="$DOXYGEN"
PANDOC="$PANDOC"
CMAKE="$CMAKE"
__EOF__

# toolchain detection utilities
. make/toolchain.sh

#
# DEPENDENCIES
#

# check languages
lang_c=
lang_cpp=
if detect_cpp_compiler ; then
    lang_cpp=1
fi
if detect_c_compiler ; then
    lang_c=1
fi

# create buffer for make variables required by dependencies
echo > "$TEMP_DIR/make.mk"

test_pkg_config()
{
    if "$PKG_CONFIG" --exists "$1" ; then :
    else return 1 ; fi
    if [ -z "$2" ] || "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
    else return 1 ; fi
    if [ -z "$3" ] || "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
    else return 1 ; fi
    if [ -z "$4" ] || "$PKG_CONFIG" --max-version="$4" "$1" ; then :
    else return 1 ; fi
    return 0
}

dependency_error_pandoc()
{
    printf "checking for pandoc... "
    # dependency pandoc
    while true
    do
        if test -n "$PANDOC" > /dev/null ; then
            :
        else
            break
        fi
        echo yes
        return 1
    done

    echo no
    return 0
}
dependency_error_cpp()
{
    printf "checking for cpp... "
    # dependency cpp
    while true
    do
        if [ -z "$lang_cpp" ] ; then
            break
        fi
        echo yes
        return 1
    done

    echo no
    return 0
}
dependency_error_c()
{
    printf "checking for c... "
    # dependency c platform="mingw"
    while true
    do
        if notisplatform "mingw"; then
            break
        fi
        if [ -z "$lang_c" ] ; then
            break
        fi
        cat >> $TEMP_DIR/make.mk << __EOF__
# Dependency: c
AR=ar
ARFLAGS=r
STLIB_EXT=.lib
SHLIB_EXT=.dll

__EOF__
        echo yes
        return 1
    done

    # dependency c platform="macos"
    while true
    do
        if notisplatform "macos"; then
            break
        fi
        if [ -z "$lang_c" ] ; then
            break
        fi
        cat >> $TEMP_DIR/make.mk << __EOF__
# Dependency: c
AR=ar
ARFLAGS=r
STLIB_EXT=.a
SHLIB_EXT=.dylib

__EOF__
        echo yes
        return 1
    done

    # dependency c platform="unix"
    while true
    do
        if notisplatform "unix"; then
            break
        fi
        if [ -z "$lang_c" ] ; then
            break
        fi
        cat >> $TEMP_DIR/make.mk << __EOF__
# Dependency: c
AR=ar
ARFLAGS=r
STLIB_EXT=.a
SHLIB_EXT=.so

__EOF__
        echo yes
        return 1
    done

    echo no
    return 0
}
dependency_error_file_tools()
{
    printf "checking for file-tools... "
    # dependency file-tools
    while true
    do
        cat >> $TEMP_DIR/make.mk << __EOF__
# Dependency: file-tools
MKDIR=/bin/mkdir -p
RMFILE=/bin/rm -f
RMDIR=/bin/rm -f -R
COPYFILE=/bin/cp -f
COPYALL=/bin/cp -f -R
SYMLINK=/bin/ln -s

__EOF__
        echo yes
        return 1
    done

    echo no
    return 0
}
dependency_error_cmake()
{
    printf "checking for cmake... "
    # dependency cmake
    while true
    do
        if test -n "$CMAKE" > /dev/null ; then
            :
        else
            break
        fi
        echo yes
        return 1
    done

    echo no
    return 0
}
dependency_error_doxygen()
{
    printf "checking for doxygen... "
    # dependency doxygen
    while true
    do
        if test -n "$DOXYGEN" > /dev/null ; then
            :
        else
            break
        fi
        echo yes
        return 1
    done

    echo no
    return 0
}




# start collecting dependency information
echo > "$TEMP_DIR/flags.mk"

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

        cat >> "$TEMP_DIR/make.mk" << __EOF__
# library version
VERSION=3.0.1
LIBVERSION=4.0.0
LIBVERSION_MAJOR=4

# build directory structure !! do not change or override !!
build_dir=${src_dir}/build
docs_dir=${src_dir}/build/docs
dist_dir=${src_dir}/dist

__EOF__
        break
    done
    break
done

# add general dependency flags to flags.mk
echo "# general flags" >> "$TEMP_DIR/flags.mk"
if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
    echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
fi
if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
    echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
fi
if [ -n "${TEMP_LDFLAGS}" ]; then
    echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
fi

#
# OPTION VALUES
#
checkopt_with_tests_yes()
{
    VERR=0
    if dependency_error_cpp ; then
        VERR=1
    fi
    if dependency_error_cmake ; then
        VERR=1
    fi
    if [ $VERR -ne 0 ]; then
        return 1
    fi
    cat >> "$TEMP_DIR/make.mk" << __EOF__
WITH_TESTS=yes

__EOF__
    return 0
}
checkopt_with_tests_no()
{
    VERR=0
    if [ $VERR -ne 0 ]; then
        return 1
    fi
    return 0
}
checkopt_with_docs_all()
{
    VERR=0
    if dependency_error_pandoc ; then
        VERR=1
    fi
    if dependency_error_doxygen ; then
        VERR=1
    fi
    if [ $VERR -ne 0 ]; then
        return 1
    fi
    cat >> "$TEMP_DIR/make.mk" << __EOF__
# Documentation
WITH_DOCS_API=yes
WITH_DOCS_HTML=yes

__EOF__
    return 0
}
checkopt_with_docs_html()
{
    VERR=0
    if dependency_error_pandoc ; then
        VERR=1
    fi
    if [ $VERR -ne 0 ]; then
        return 1
    fi
    cat >> "$TEMP_DIR/make.mk" << __EOF__
# Documentation
WITH_DOCS_HTML=yes

__EOF__
    return 0
}
checkopt_with_docs_api()
{
    VERR=0
    if dependency_error_doxygen ; then
        VERR=1
    fi
    if [ $VERR -ne 0 ]; then
        return 1
    fi
    cat >> "$TEMP_DIR/make.mk" << __EOF__
# Documentation
WITH_DOCS_API=yes

__EOF__
    return 0
}
checkopt_with_docs_none()
{
    VERR=0
    if [ $VERR -ne 0 ]; then
        return 1
    fi
    return 0
}

#
# TARGETS
#

echo >> "$TEMP_DIR/flags.mk"
echo "configuring global target"
echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk"
TEMP_CFLAGS=
TEMP_CXXFLAGS=
TEMP_LDFLAGS=

if dependency_error_c; then
    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED c "
    ERROR=1
fi
if dependency_error_file_tools; then
    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED file_tools "
    ERROR=1
fi

# Features

# Option: --with-tests
if [ -z "$OPT_WITH_TESTS" ]; then
    echo "auto-detecting option 'with-tests'"
    SAVED_ERROR="$ERROR"
    SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
    ERROR=1
    while true
    do
        if checkopt_with_tests_yes ; then
            echo "  with-tests: yes" >> "$TEMP_DIR/options"
            ERROR=0
            break
        fi
        if checkopt_with_tests_no ; then
            echo "  with-tests: no" >> "$TEMP_DIR/options"
            ERROR=0
            break
        fi
        break
    done
    if [ $ERROR -ne 0 ]; then
        SAVED_ERROR=1
        SAVED_DEPENDENCIES_FAILED="option 'with-tests' $SAVED_DEPENDENCIES_FAILED"
    fi
    ERROR="$SAVED_ERROR"
    DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
else
    echo "checking option with-tests = $OPT_WITH_TESTS"
    if false; then
        false
    elif [ "$OPT_WITH_TESTS" = "yes" ]; then
        echo "  with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
        if checkopt_with_tests_yes ; then
            :
        else
            ERROR=1
            DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
        fi
    elif [ "$OPT_WITH_TESTS" = "no" ]; then
        echo "  with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
        if checkopt_with_tests_no ; then
            :
        else
            ERROR=1
            DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
        fi
    fi
fi
# Option: --with-docs
if [ -z "$OPT_WITH_DOCS" ]; then
    echo "auto-detecting option 'with-docs'"
    SAVED_ERROR="$ERROR"
    SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
    ERROR=1
    while true
    do
        if checkopt_with_docs_all ; then
            echo "  with-docs: all" >> "$TEMP_DIR/options"
            ERROR=0
            break
        fi
        if checkopt_with_docs_html ; then
            echo "  with-docs: html" >> "$TEMP_DIR/options"
            ERROR=0
            break
        fi
        if checkopt_with_docs_api ; then
            echo "  with-docs: api" >> "$TEMP_DIR/options"
            ERROR=0
            break
        fi
        if checkopt_with_docs_none ; then
            echo "  with-docs: none" >> "$TEMP_DIR/options"
            ERROR=0
            break
        fi
        break
    done
    if [ $ERROR -ne 0 ]; then
        SAVED_ERROR=1
        SAVED_DEPENDENCIES_FAILED="option 'with-docs' $SAVED_DEPENDENCIES_FAILED"
    fi
    ERROR="$SAVED_ERROR"
    DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
else
    echo "checking option with-docs = $OPT_WITH_DOCS"
    if false; then
        false
    elif [ "$OPT_WITH_DOCS" = "all" ]; then
        echo "  with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
        if checkopt_with_docs_all ; then
            :
        else
            ERROR=1
            DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
        fi
    elif [ "$OPT_WITH_DOCS" = "html" ]; then
        echo "  with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
        if checkopt_with_docs_html ; then
            :
        else
            ERROR=1
            DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
        fi
    elif [ "$OPT_WITH_DOCS" = "api" ]; then
        echo "  with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
        if checkopt_with_docs_api ; then
            :
        else
            ERROR=1
            DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
        fi
    elif [ "$OPT_WITH_DOCS" = "none" ]; then
        echo "  with-docs: $OPT_WITH_DOCS" >> $TEMP_DIR/options
        if checkopt_with_docs_none ; then
            :
        else
            ERROR=1
            DEPENDENCIES_FAILED="option 'with-docs' $DEPENDENCIES_FAILED"
        fi
    fi
fi

if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then
    echo "CFLAGS  += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
fi
if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then
    echo "CXXFLAGS  += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
fi
if [ "$BUILD_TYPE" = "debug" ]; then
    if [ -n "$lang_c" ]; then
        echo 'CFLAGS += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
    fi
    if [ -n "$lang_cpp" ]; then
        echo 'CXXFLAGS += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
    fi
fi
if [ "$BUILD_TYPE" = "release" ]; then
    if [ -n "$lang_c" ]; then
        echo 'CFLAGS += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk"
    fi
    if [ -n "$lang_cpp" ]; then
        echo 'CXXFLAGS += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk"
    fi
fi
if [ -n "${TEMP_LDFLAGS}" ]; then
    echo "LDFLAGS += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
fi


# final result
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 "Options:"
cat "$TEMP_DIR/options"
echo

# generate the config.mk file
cat > "$TEMP_DIR/config.mk" << __EOF__
#
# config.mk generated by configure
#

__EOF__
write_toolchain_defaults "$TEMP_DIR/toolchain.mk"
cat "$TEMP_DIR/vars.mk" "$TEMP_DIR/toolchain.mk" "$TEMP_DIR/flags.mk" "$TEMP_DIR/make.mk" > config.mk
rm -Rf "$TEMP_DIR"

mercurial