--- a/make/configure.vm Sun Oct 06 20:49:43 2024 +0200 +++ b/make/configure.vm Sat Mar 01 22:55:30 2025 +0100 @@ -1,5 +1,133 @@ #!/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` +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]..." + cat << __EOF__ +Installation directories: + --prefix=PREFIX path prefix for architecture-independent files + [${D}prefix] + --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] + +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.argument}=${opt.valuesString} +#end +#end +#if( $features.size() > 0 ) + +Optional Features: +#foreach( $feature in $features ) +${feature.helpText} +#end +#end + +__EOF__ +} + # create temporary directory TEMP_DIR=".tmp-`uname -n`" rm -Rf "$TEMP_DIR" @@ -33,12 +161,23 @@ mandir= # custom variables -#foreach( $var in $vars ) -#if( $var.exec ) -${var.varName}=`${var.value}` -#else -${var.varName}="${var.value}" +#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.exec ) + ${var.varName}=`${var.value}` + #else + ${var.varName}="${var.value}" + #end + #end +fi #end # features @@ -48,67 +187,10 @@ #end #end -# 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] - -#if( $options.size() > 0 ) -Options: - --debug add extra compile flags for debug builds - --release add extra compile flags for release builds -#foreach( $opt in $options ) - --${opt.argument}=${opt.valuesString} -#end - -#end -#if( $features.size() > 0 ) -Optional Features: -#foreach( $feature in $features ) -#if( $feature.auto ) - --disable-${feature.arg} -#else - --enable-${feature.arg} -#end -#end - -#end -__EOF__ -} - # # parse arguments # BUILD_TYPE="default" -#set( $D = '$' ) for ARG in "$@" do case "$ARG" in @@ -127,11 +209,12 @@ "--infodir="*) infodir=${D}{ARG#--infodir=} ;; "--mandir"*) mandir=${D}{ARG#--mandir} ;; "--localedir"*) localedir=${D}{ARG#--localedir} ;; - "--help"*) printhelp; abort_configure ;; - "--debug") BUILD_TYPE="debug" ;; - "--release") BUILD_TYPE="release" ;; + "--help"*) printhelp; abort_configure ;; + "--debug") BUILD_TYPE="debug" ;; + "--release") BUILD_TYPE="release" ;; #foreach( $opt in $options ) "--${opt.argument}="*) ${opt.varName}=${D}{ARG#--${opt.argument}=} ;; + "--${opt.argument}") echo "option '$ARG' needs a value:"; echo " $ARG=${opt.valuesString}"; abort_configure ;; #end #foreach( $feature in $features ) "--enable-${feature.arg}") ${feature.varName}=on ;; @@ -178,79 +261,29 @@ . "$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 -} ]]# ## End of unparsed content ** # 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" +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 #foreach( $var in $vars ) -${var.varName}="${D}${var.varName}" +${var.varName}=${D}${var.varName} #end __EOF__ @@ -286,10 +319,18 @@ return 0 } +print_check_msg() +{ + if [ -z "$1" ]; then + shift + printf "$@" + fi +} + #foreach( $dependency in $namedDependencies ) dependency_error_${dependency.id}() { - printf "checking for ${dependency.name}... " + print_check_msg "${D}dep_checked_${dependency.id}" "checking for ${dependency.name}... " #foreach( $sub in $dependency.subdependencies ) # dependency $sub.fullName while true @@ -299,8 +340,13 @@ break fi #end + #if( $sub.toolchain ) + if notistoolchain "${sub.toolchain}"; then + break + fi + #end #foreach( $np in $sub.notList ) - if isplatform "${np}"; then + if isplatform "${np}" || istoolchain "${np}"; then break fi #end @@ -346,19 +392,18 @@ $sub.make __EOF__ #end - echo yes + print_check_msg "${D}dep_checked_${dependency.id}" "yes\n" + dep_checked_${dependency.id}=1 return 1 done #end - echo no + 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" @@ -366,9 +411,9 @@ ERROR=0 #if( $dependencies.size() > 0 ) # unnamed dependencies -TEMP_CFLAGS= -TEMP_CXXFLAGS= -TEMP_LDFLAGS= +TEMP_CFLAGS="$CFLAGS" +TEMP_CXXFLAGS="$CXXFLAGS" +TEMP_LDFLAGS="$LDFLAGS" #foreach( $dependency in $dependencies ) while true do @@ -377,8 +422,13 @@ break fi #end + #if( $dependency.toolchain ) + if notistoolchain "${dependency.toolchain}"; then + break + fi + #end #foreach( $np in $dependency.notList ) - if isplatform "${np}"; then + if isplatform "${np}" || istoolchain "${np}"; then break fi #end @@ -397,13 +447,15 @@ fi #end #foreach( $pkg in $dependency.pkgconfig ) - printf "checking for pkg-config package $pkg.name... " + 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 - echo yes + 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 - echo no + print_check_msg "${D}dep_pkgconfig_checked_${pkg.id}" "no\n" + dep_pkgconfig_checked_${pkg.id}=1 ERROR=1 break fi @@ -435,10 +487,10 @@ # add general dependency flags to flags.mk echo "# general flags" >> "$TEMP_DIR/flags.mk" -if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then +if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then echo "CFLAGS += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" fi -if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then +if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then echo "CXXFLAGS += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ -n "${TEMP_LDFLAGS}" ]; then @@ -519,6 +571,35 @@ 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 ) @@ -565,14 +646,19 @@ DEPENDENCIES_FAILED="option '${opt.argument}' $DEPENDENCIES_FAILED" fi #end + else + echo + echo "Invalid option value - usage:" + echo " --${opt.argument}=${opt.valuesString}" + abort_configure fi fi #end -if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then +if [ -n "${TEMP_CFLAGS}" ] && [ -n "$lang_c" ]; then echo "${target.cFlags} += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" fi -if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then +if [ -n "${TEMP_CXXFLAGS}" ] && [ -n "$lang_cpp" ]; then echo "${target.cxxFlags} += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" fi if [ "$BUILD_TYPE" = "debug" ]; then @@ -636,5 +722,3 @@ 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" - -