configure

changeset 0
593b60458157
child 1
e3113d4e2fc0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/configure	Fri Oct 06 21:21:10 2023 +0200
@@ -0,0 +1,423 @@
+#!/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=
+BINDIR=
+SBINDIR=
+LIBDIR=
+LIBEXECDIR=
+DATADIR=
+SYSCONFDIR=
+SHAREDSTATEDIR=
+LOCALSTATEDIR=
+INCLUDEDIR=
+INFODIR=
+MANDIR=
+
+# custom variables
+
+# 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]
+  --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]
+
+__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" ;;
+        "-"*) echo "unknown option: $ARG"; abort_configure ;;
+    esac
+done
+
+
+# set dir variables
+: ${EPREFIX:="$PREFIX"}
+: ${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"}
+
+# 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"
+EPREFIX="$EPREFIX"
+BINDIR="$BINDIR"
+SBINDIR="$SBINDIR"
+LIBDIR="$LIBDIR"
+LIBEXECDIR="$LIBEXECDIR"
+DATADIR="$DATADIR"
+SYSCONFDIR="$SYSCONFDIR"
+SHAREDSTATEDIR="$SHAREDSTATEDIR"
+LOCALSTATEDIR="$LOCALSTATEDIR"
+INCLUDEDIR="$INCLUDEDIR"
+INFODIR="$INFODIR"
+MANDIR="$MANDIR"
+__EOF__
+sort -u -o "$TEMP_DIR/vars.mk" "$TEMP_DIR/vars.mk"
+
+
+# toolchain detection utilities
+. make/toolchain.sh
+
+#
+# DEPENDENCIES
+#
+
+# check languages
+lang_c=
+lang_cpp=
+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_sdl2_ttf()
+{
+    printf "checking for sdl2_ttf... "
+    # dependency sdl2_ttf
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "SDL2_ttf" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags SDL2_ttf`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs SDL2_ttf`"
+        else
+            break
+        fi
+        echo yes
+        return 1
+    done
+
+    echo no
+    return 0
+}
+dependency_error_sdl2()
+{
+    printf "checking for sdl2... "
+    # dependency sdl2
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "sdl2" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sdl2`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sdl2`"
+        else
+            break
+        fi
+        echo yes
+        return 1
+    done
+
+    echo no
+    return 0
+}
+dependency_error_glew()
+{
+    printf "checking for glew... "
+    # dependency glew
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "glew" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags glew`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs glew`"
+        else
+            break
+        fi
+        echo yes
+        return 1
+    done
+
+    echo no
+    return 0
+}
+dependency_error_ucx()
+{
+    printf "checking for ucx... "
+    # dependency ucx
+    while true
+    do
+        if check_lib ucx cx/common.h > /dev/null ; then
+            :
+        else
+            break
+        fi
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lucx"
+        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
+        if [ -z "$lang_c" ] ; then
+            ERROR=1
+            break
+        fi
+
+        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
+#
+
+#
+# TARGETS
+#
+
+echo >> "$TEMP_DIR/flags.mk"
+echo "configuring target: default"
+echo "# flags for target default" >> "$TEMP_DIR/flags.mk"
+TEMP_CFLAGS=
+TEMP_CXXFLAGS=
+TEMP_LDFLAGS=
+
+if dependency_error_sdl2_ttf; then
+    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl2_ttf "
+    ERROR=1
+fi
+if dependency_error_sdl2; then
+    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED sdl2 "
+    ERROR=1
+fi
+if dependency_error_glew; then
+    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED glew "
+    ERROR=1
+fi
+if dependency_error_ucx; then
+    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ucx "
+    ERROR=1
+fi
+
+# Features
+
+
+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
+
+# 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