make/configure.vm

Sun, 30 Nov 2025 13:55:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 30 Nov 2025 13:55:12 +0100
changeset 1525
f675a4e99fb5
parent 1523
b5c32391802f
child 1526
047f8a19f7fa
permissions
-rw-r--r--

fix missing fallback for doxygen executable

#!/bin/sh

#set( $D = '$' )
#[[
# some utility functions
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
}
istoolchain()
{
    for t in $TOOLCHAIN
    do
        if [ "$t" = "$1" ]; then
            return 0
        fi
    done
    return 1
}
notistoolchain()
{
    for t in $TOOLCHAIN
    do
        if [ "$t" = "$1" ]; then
            return 1
        fi
    done
    return 0
}

# clean abort
abort_configure()
{
    rm -Rf "$TEMP_DIR"
    exit 1
}

# 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`
ARCH=`uname -m`
printf "detect platform... "
if [ "$OS" = "SunOS" ]; then
    PLATFORM="solaris sunos unix svr4"
elif [ "$OS" = "Linux" ]; then
    PLATFORM="linux unix"
elif [ "$OS" = "FreeBSD" ]; then
    PLATFORM="freebsd bsd unix"
elif [ "$OS" = "OpenBSD" ]; then
    PLATFORM="openbsd bsd unix"
elif [ "$OS" = "NetBSD" ]; then
    PLATFORM="netbsd bsd unix"
elif [ "$OS" = "Darwin" ]; then
    PLATFORM="macos osx bsd unix"
elif echo "$OS" | grep -i "MINGW" > /dev/null; then
    PLATFORM="windows mingw"
fi
: ${PLATFORM:="unix"}

PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
echo "$PLATFORM_NAME"
]]#

# help text
printhelp()
{
    echo "Usage: $0 [OPTIONS]..."
    echo 'Configuration:'
#foreach( $cfg in $config )
if true \
#if( $cfg.platform )
    && isplatform "${cfg.platform}" \
#end
#foreach( $np in $cfg.notList )
      && notisplatform "${np}" \
#end
      ; then
    :
    #foreach( $var in $cfg.vars )
    #if( $var.overridable )
    if test -z "${D}${var.varName}__described__"; then
        ${var.varName}__described__=1
        cat << '__EOF__'
${var.helpText}
__EOF__
    fi
    #end
    #end
fi
#end
    cat << '__EOF__'

Build Types:
  --debug                 add extra compile flags for debug builds
  --release               add extra compile flags for release builds
#if( $options.size() > 0 )

Options:
#foreach( $opt in $options )
${opt.helpText}
#end
#end
#if( $features.size() > 0 )

Optional Features:
#foreach( $feature in $features )
${feature.helpText}
#end
#end

__EOF__
    abort_configure
}

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

# config variables
#foreach( $cfg in $config )
if true \
#if( $cfg.platform )
    && isplatform "${cfg.platform}" \
#end
#foreach( $np in $cfg.notList )
      && notisplatform "${np}" \
#end
      ; then
    :
    #foreach( $var in $cfg.vars )
    if test -z "${D}${var.varName}__initialized__"; then
        ${var.varName}__initialized__=1
        #if( $var.exec )
        ${var.varName}=`${var.value}`
        #else
        ${var.varName}="${var.value}"
        #end
    fi
    #end
fi
#end

# features
#foreach( $feature in $features )
#if( ${feature.auto} )
${feature.varName}=auto
#end
#end

#
# parse arguments
#
BUILD_TYPE="default"
for ARG in "$@"
do
    case "$ARG" in
    #foreach( $var in $vars )
    #if ($var.overridable)
        "--${var.arg}="*) ${var.varName}=${D}{ARG#--${var.arg}=} ;;
    #end
    #end
        "--help"*) printhelp ;;
        "--debug") BUILD_TYPE="debug" ;;
        "--release") BUILD_TYPE="release" ;;
    #foreach( $opt in $options )
        "--${opt.arg}="*) ${opt.varName}=${D}{ARG#--${opt.arg}=} ;;
        "--${opt.arg}") echo "option '$ARG' needs a value:"; echo "  $ARG=${opt.valuesString}"; abort_configure ;;
    #end
    #foreach( $feature in $features )
        "--enable-${feature.arg}") ${feature.varName}=on ;;
        "--disable-${feature.arg}") unset ${feature.varName} ;;
    #end
        "-"*) echo "unknown option: $ARG"; abort_configure ;;
    esac
done

# toolchain detection utilities
. make/toolchain.sh

# check languages
lang_c=
lang_cpp=
#foreach( $lang in $languages )
if detect_${lang}_compiler ; then
    lang_${lang}=1
fi
#end

## Begin unparsed content. **
#[[

# 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}'}
: ${sharedstatedir:='${prefix}/com'}
if [ -z "$sysconfdir" ]; then
    if [ "$prefix" = '/usr' ]; then
        sysconfdir='/etc'
    else
        sysconfdir='${prefix}/etc'
    fi
fi
if [ -z "$localstatedir" ]; then
    if [ "$prefix" = '/usr' ]; then
        localstatedir='/var'
    else
        localstatedir='${prefix}/var'
    fi
fi
if [ -z "$runstatedir" ]; then
    if [ "$prefix" = '/usr' ]; then
        runstatedir='/var/run'
    else
        runstatedir='${prefix}/var'
    fi
fi
: ${includedir:='${prefix}/include'}
: ${infodir:='${datarootdir}/info'}
: ${mandir:='${datarootdir}/man'}
: ${localedir:='${datarootdir}/locale'}


# check if a config.site exists and load it
CONFIG_SITE_OK=0
if [ -n "$CONFIG_SITE" ]; then
    # CONFIG_SITE may contain space separated file names
    for cs in $CONFIG_SITE; do
        printf "loading defaults from $cs... "
        if [ -f "$cs" ]; then
            . "$cs"
            echo ok
            CONFIG_SITE_OK=1
            break
        else
            echo "not found"
        fi
    done
elif [ -f "$prefix/share/config.site" ]; then
    printf "loading site defaults... "
    . "$prefix/share/config.site"
    echo ok
    CONFIG_SITE_OK=1
elif [ -f "$prefix/etc/config.site" ]; then
    printf "loading site defaults... "
    . "$prefix/etc/config.site"
    echo ok
    CONFIG_SITE_OK=1
fi

if [ $CONFIG_SITE_OK -eq 0 ]; then
    # try to detect the correct libdir on our own, except it was changed by the user
    if [ "$libdir" = '${exec_prefix}/lib' ] ; then
        if [ "$TOOLCHAIN_WSIZE" = "64" ] ; then
            if [ "$OS" = "SunOS" ]; then
                [ -d "${exec_prefix}/lib/64" ] && libdir='${exec_prefix}/lib/64'
            else
                [ -d "${exec_prefix}/lib64" ] && libdir='${exec_prefix}/lib64'
            fi
        elif [ "$TOOLCHAIN_WSIZE" = "32" ] ; then
            if [ "$OS" = "SunOS" ]; then
                [ -d "${exec_prefix}/lib/32" ] && libdir='${exec_prefix}/lib/32'
            else
                [ -d "${exec_prefix}/lib32" ] && libdir='${exec_prefix}/lib32'
            fi
        fi
    fi
fi
]]#
## End of unparsed content **

# generate vars.mk
cat > "$TEMP_DIR/vars.mk" << __EOF__
#foreach( $var in $vars )
${var.varName}=${D}${var.varName}
#end
__EOF__


#
# DEPENDENCIES
#



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

print_check_msg()
{
    if [ -z "$1" ]; then
        shift
        printf "$@"
    fi
}

#foreach( $dependency in $namedDependencies )
dependency_error_${dependency.id}()
{
    print_check_msg "${D}dep_checked_${dependency.id}" "checking for ${dependency.name}... "
    #foreach( $sub in $dependency.subdependencies )
    # dependency $sub.fullName
    while true
    do
        #if( $sub.platform )
        if notisplatform "${sub.platform}"; then
            break
        fi
        #end
        #if( $sub.toolchain )
        if notistoolchain "${sub.toolchain}"; then
            break
        fi
        #end
        #foreach( $np in $sub.notList )
        if isplatform "${np}" || istoolchain "${np}"; then
            break
        fi
        #end
        #foreach( $lang in $sub.lang )
        if [ -z "$lang_${lang}" ] ; then
            break
        fi
        #end
        #if( $sub.pkgconfig.size() > 0 )
        if [ -z "$PKG_CONFIG" ]; then
            break
        fi
        #end
        #foreach( $test in $sub.tests )
        if $test > /dev/null 2>&1 ; then
            :
        else
            break
        fi
        #end
        #foreach( $pkg in $sub.pkgconfig )
        if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then
            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"
        else
            break
        fi
        #end
        #foreach( $flags in $sub.flags )
        #if( $flags.exec )
        if tmp_flags=`$flags.value` ; then
            TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags"
        else
            break
        fi
        #else
        TEMP_$flags.varName="$TEMP_$flags.varName $flags.value"
        #end
        #end
        #if ( $sub.make.length() > 0 )
        cat >> $TEMP_DIR/make.mk << __EOF__
# Dependency: $dependency.name
$sub.make
__EOF__
        #end
        print_check_msg "${D}dep_checked_${dependency.id}" "yes\n"
        dep_checked_${dependency.id}=1
        return 1
    done

    #end
    print_check_msg "${D}dep_checked_${dependency.id}" "no\n"
    dep_checked_${dependency.id}=1
    return 0
}
#end

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

DEPENDENCIES_FAILED=
ERROR=0
#if( $dependencies.size() > 0 )
# unnamed dependencies
TEMP_CFLAGS="$CFLAGS"
TEMP_CXXFLAGS="$CXXFLAGS"
TEMP_LDFLAGS="$LDFLAGS"
#foreach( $dependency in $dependencies )
while true
do
    #if( $dependency.platform )
    if notisplatform "${dependency.platform}"; then
        break
    fi
    #end
    #if( $dependency.toolchain )
    if notistoolchain "${dependency.toolchain}"; then
        break
    fi
    #end
    #foreach( $np in $dependency.notList )
    if isplatform "${np}" || istoolchain "${np}"; then
        break
    fi
    #end
    while true
    do
        #foreach( $lang in $dependency.lang )
        if [ -z "$lang_${lang}" ] ; then
            ERROR=1
            break
        fi
        #end
        #if( $dependency.pkgconfig.size() > 0 )
        if [ -z "$PKG_CONFIG" ]; then
            ERROR=1
            break
        fi
        #end
        #foreach( $pkg in $dependency.pkgconfig )
        print_check_msg "${D}dep_pkgconfig_checked_${pkg.id}" "checking for pkg-config package $pkg.name... "
        if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then
            print_check_msg "${D}dep_pkgconfig_checked_${pkg.id}" "yes\n"
            dep_pkgconfig_checked_${pkg.id}=1
            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"
        else
            print_check_msg "${D}dep_pkgconfig_checked_${pkg.id}" "no\n"
            dep_pkgconfig_checked_${pkg.id}=1
            ERROR=1
            break
        fi
        #end

        #foreach( $flags in $dependency.flags )
        #if( $flags.exec )
        if tmp_flags=`$flags.value` ; then
            TEMP_$flags.varName="$TEMP_$flags.varName $tmp_flags"
        else
            ERROR=1
            break
        fi
        #else
        TEMP_$flags.varName="$TEMP_$flags.varName $flags.value"
        #end
        #end
        #if ( $dependency.make.length() > 0 )
        cat >> "$TEMP_DIR/make.mk" << __EOF__
$dependency.make
__EOF__
        #end
        break
    done
    break
done
#end

# build type
if [ "$BUILD_TYPE" = "debug" ]; then
    TEMP_CFLAGS="\${DEBUG_CFLAGS} $TEMP_CFLAGS"
    TEMP_CXXFLAGS="\${DEBUG_CXXFLAGS} $TEMP_CXXFLAGS"
fi
if [ "$BUILD_TYPE" = "release" ]; then
    TEMP_CFLAGS="\${RELEASE_CFLAGS} $TEMP_CFLAGS"
    TEMP_CXXFLAGS="\${RELEASE_CXXFLAGS} $TEMP_CXXFLAGS"
fi

# add general dependency flags to flags.mk
echo "# general flags" >> "$TEMP_DIR/flags.mk"
if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then
    echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
fi
if [ -n "${TEMP_CXXFLAGS}" ] && [ -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
#end

#
# OPTION VALUES
#
#foreach( $opt in $options )
#foreach( $val in $opt.values )
${val.func}()
{
    VERR=0
    #foreach( $dep in $val.dependencies )
    if dependency_error_$dep ; then
        VERR=1
    fi
    #end
    if [ $VERR -ne 0 ]; then
        return 1
    fi
    #foreach( $def in $val.defines )
        TEMP_CFLAGS="$TEMP_CFLAGS ${def.toFlags()}"
        TEMP_CXXFLAGS="$TEMP_CXXFLAGS ${def.toFlags()}"
    #end
    #if( $val.hasMake() )
    cat >> "$TEMP_DIR/make.mk" << __EOF__
$val.make
__EOF__
    #end
    return 0
}
#end
#end

#
# TARGETS
#

#foreach( $target in $targets )
echo >> "$TEMP_DIR/flags.mk"
#if ( $target.name )
echo "configuring target: $target.name"
echo "# flags for target $target.name" >> "$TEMP_DIR/flags.mk"
#else
echo "configuring global target"
echo "# flags for unnamed target" >> "$TEMP_DIR/flags.mk"
#end
TEMP_CFLAGS=
TEMP_CXXFLAGS=
TEMP_LDFLAGS=

#foreach( $dependency in $target.dependencies )
if dependency_error_$dependency; then
    DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
    ERROR=1
fi
#end

# Features
#foreach( $feature in $target.features )
if [ -n "${D}${feature.varName}" ]; then
#foreach( $dependency in $feature.dependencies )
    # check dependency
    if dependency_error_$dependency ; then
        # "auto" features can fail and are just disabled in this case
        if [ "${D}${feature.varName}" = "auto" ]; then
            DISABLE_${feature.varName}=1
        else
            DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
            ERROR=1
        fi
    fi
#end
    if [ -n "$DISABLE_${feature.varName}" ]; then
        unset ${feature.varName}
    fi
fi
if [ -n "${D}${feature.varName}" ]; then
    :
#foreach( $def in $feature.defines )
    TEMP_CFLAGS="$TEMP_CFLAGS ${def.toFlags()}"
    TEMP_CXXFLAGS="$TEMP_CXXFLAGS ${def.toFlags()}"
#end
#if( $feature.hasMake() )
    cat >> "$TEMP_DIR/make.mk" << __EOF__
$feature.make
__EOF__
#end
else
    :
#foreach( $def in $feature.disabled.defines )
    TEMP_CFLAGS="$TEMP_CFLAGS ${def.toFlags()}"
    TEMP_CXXFLAGS="$TEMP_CXXFLAGS ${def.toFlags()}"
#end
#if( $feature.disabled.hasMake() )
    cat >> "$TEMP_DIR/make.mk" << __EOF__
$feature.disabled.make
__EOF__
#end
#foreach( $dependency in $feature.disabled.dependencies )
    if dependency_error_$dependency ; then
        DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED ${dependency} "
        ERROR=1
    fi
#end
fi
#end

#foreach( $opt in $target.options )
# Option: --${opt.arg}
if [ -z "${D}${opt.varName}" ]; then
    echo "auto-detecting option '${opt.arg}'"
    SAVED_ERROR="$ERROR"
    SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
    ERROR=1
    while true
    do
        #foreach( $optdef in $opt.defaults )
        #if( $optdef.platform )
        if isplatform "$optdef.platform"; then
        #end
        if $optdef.func ; then
            echo "  ${opt.arg}: ${optdef.valueName}" >> "$TEMP_DIR/options"
            ERROR=0
            break
        fi
        #if( $optdef.platform )
        fi
        #end
        #end
        break
    done
    if [ $ERROR -ne 0 ]; then
        SAVED_ERROR=1
        SAVED_DEPENDENCIES_FAILED="option '${opt.arg}' $SAVED_DEPENDENCIES_FAILED"
    fi
    ERROR="$SAVED_ERROR"
    DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
else
    echo "checking option ${opt.arg} = ${D}${opt.varName}"
    if false; then
        false
    #foreach( $optval in $opt.values )
    elif [ "${D}${opt.varName}" = "${optval.value}" ]; then
        echo "  ${opt.arg}: ${D}${opt.varName}" >> $TEMP_DIR/options
        if $optval.func ; then
            :
        else
            ERROR=1
            DEPENDENCIES_FAILED="option '${opt.arg}' $DEPENDENCIES_FAILED"
        fi
    #end
    else
        echo
        echo "Invalid option value - usage:"
        echo "  --${opt.arg}=${opt.valuesString}"
        abort_configure
    fi
fi
#end

if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then
    echo "${target.cFlags}  += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk"
fi
if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then
    echo "${target.cxxFlags}  += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk"
fi
if [ -n "${TEMP_LDFLAGS}" ]; then
    echo "${target.ldFlags} += $TEMP_LDFLAGS" >> "$TEMP_DIR/flags.mk"
fi

#end

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

echo "configure finished"
echo
echo "Toolchain:"
echo "  name:           $TOOLCHAIN_NAME"
if [ -n "$TOOLCHAIN_CC" ]; then
    echo "  cc:             $TOOLCHAIN_CC"
fi
if [ -n "$TOOLCHAIN_CXX" ]; then
    echo "  cxx:            $TOOLCHAIN_CXX"
fi
if [ -n "$TOOLCHAIN_WSIZE" ]; then
    echo "  word size:      $TOOLCHAIN_WSIZE bit"
fi
if [ -n "$TOOLCHAIN_CSTD" ]; then
    echo "  default C std:  $TOOLCHAIN_CSTD"
fi
echo
echo "Config:"
#foreach( $var in $vars )
#if ($var.overridable)
    printf '  %-16s' '${var.arg}:'
    echo "${D}${var.varName}"
#end
#end
#if ( $options.size() > 0 )
echo
echo "Options:"
cat "$TEMP_DIR/options"
#end
#if ( $features.size() > 0 )
echo
echo "Features:"
#foreach( $feature in $features )
printf '  %-16s' '$feature.name:'
if [ -n "${D}${feature.varName}" ]; then
    echo 'on'
else
    echo 'off'
fi
#end
#end
echo

# generate the config.mk file
pwd=`pwd`
cat > "$TEMP_DIR/config.mk" << __EOF__
#
# config.mk generated by:
# pwd: $pwd
# $0 $@
#

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

mercurial