# HG changeset patch # User Mike Becker # Date 1697390441 -7200 # Node ID a13789dd1cfb20dc3649ed4f749ffa3cf88f1613 # Parent 9817c08f96379cfea61e03ce9015d4ffa2934085 add --init and --update options fixes #308 fixes #307 diff -r 9817c08f9637 -r a13789dd1cfb dist.src/bin/uwproj --- a/dist.src/bin/uwproj Wed Oct 11 20:41:26 2023 +0200 +++ b/dist.src/bin/uwproj Sun Oct 15 19:20:41 2023 +0200 @@ -1,8 +1,4 @@ #!/bin/sh PREFIX=%%PREFIX%% - -java -jar $PREFIX/lib/uwproj/uwproj-${project.version}.jar "$@" -if [ $? -eq 0 ]; then - chmod +x configure -fi +java -jar "$PREFIX/lib/uwproj/uwproj-${project.version}.jar" "$@" diff -r 9817c08f9637 -r a13789dd1cfb pom.xml --- a/pom.xml Wed Oct 11 20:41:26 2023 +0200 +++ b/pom.xml Sun Oct 15 19:20:41 2023 +0200 @@ -38,6 +38,9 @@ true ../../dist + + src/main/resources + diff -r 9817c08f9637 -r a13789dd1cfb src/main/java/de/unixwork/uwproj/Main.java --- a/src/main/java/de/unixwork/uwproj/Main.java Wed Oct 11 20:41:26 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/Main.java Sun Oct 15 19:20:41 2023 +0200 @@ -5,6 +5,12 @@ import org.slf4j.LoggerFactory; import java.io.*; +import java.nio.file.*; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.Arrays; +import java.util.Objects; +import java.util.Set; public class Main { @@ -33,17 +39,73 @@ new VelocityEngine().getTemplate(tplFileName).merge(context, out); } + private static void abort() { + System.err.println("Abort."); + System.exit(1); + } + private static void printUsage() { System.err.println("Usage: uwproj [OPTIONS]"); System.err.println(); System.err.println("OPTIONS:"); System.err.println(" -h --help Print help text and exit"); + System.err.println(" --init Creates default files in directory 'make'"); System.err.println(" -o --output Path to the output file"); System.err.printf(" (default: %s)\n", OUT_FILE_DEFAULT); System.err.println(" -p --project Path to the project.xml file"); System.err.printf(" (default: %s)\n", IN_FILE_DEFAULT); System.err.println(" -t --template Path to the velocity template"); System.err.printf(" (default: %s)\n", TPL_FILE_DEFAULT); + System.err.println(" --update Same as --init, but overwrites existing files"); + } + + private static void extract(Path path) { + try (final var res = Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream(path.toString()))) { + Files.copy(res, path, StandardCopyOption.REPLACE_EXISTING); + } catch (Throwable t) { + System.err.printf("Cannot extract '%s': %s\n", path, t.getMessage()); + abort(); + } + } + + private static void init(boolean force) { + final var files = new String[]{ + "cc.mk", "gcc.mk", "clang.mk", "suncc.mk", + "configure.vm", "toolchain.sh", "uwproj.xsd" + }; + + // (1) create the make dir if it does not exist + final var make = Paths.get("make"); + if (Files.exists(make)) { + if (!Files.isDirectory(make)) { + System.err.println("A file with name 'make' already exists, but it's not a directory."); + abort(); + } + if (!force) { + System.err.println("uwproj files already exist. You can use --update instead."); + abort(); + } + } else { + try { + Files.createDirectory(make); + } catch (Throwable t) { + System.err.printf("Creating directory failed: %s\n", t.getMessage()); + abort(); + } + } + + // (2) create project.xml ONLY if it does not exist + final var project = make.resolve("project.xml"); + if (Files.notExists(project)) { + extract(project); + } + + // (3) create or update remaining uwproj files + Arrays.stream(files).map(make::resolve).forEach(Main::extract); + + // (4) stop + System.out.printf("uwproj files %s.\n", force ? "updated" : "created"); + System.exit(0); } private static void checkOneMoreArg(int i, int length) { @@ -57,6 +119,9 @@ var inFileName = IN_FILE_DEFAULT; var tplFileName = TPL_FILE_DEFAULT; var outFileName = OUT_FILE_DEFAULT; + boolean opsOptionsUsed = false; + boolean doInit = false; + boolean forceInit = false; for (int i = 0 ; i < args.length ; i++) { switch (args[i]) { @@ -64,17 +129,27 @@ case "--output": checkOneMoreArg(i, args.length); outFileName = args[++i]; + opsOptionsUsed = true; break; case "-p": case "--project": checkOneMoreArg(i, args.length); inFileName = args[++i]; + opsOptionsUsed = true; break; case "-t": case "--template": checkOneMoreArg(i, args.length); tplFileName = args[++i]; + opsOptionsUsed = true; + break; + case "--init": + doInit = true; + break; + case "--update": + doInit = true; + forceInit = true; break; case "--help": case "-h": @@ -86,18 +161,30 @@ } } + if (opsOptionsUsed && doInit) { + System.err.println("Cannot use --init or --update with other options."); + abort(); + } + + if (doInit) { + init(forceInit); + } + System.out.println("In: " + inFileName); System.out.println("Tpl: " + tplFileName); try (var out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFileName)))) { writeConfigureScript(out, tplFileName, loadProjectFile(inFileName)); - } catch (Exception ex) { - LoggerFactory.getLogger(Main.class).error( - "Uncaught Exception", - ex - ); + } catch (Throwable t) { + System.err.printf("Unexpected error: %s\n", t.getMessage()); + abort(); } System.out.println("Out: " + outFileName); + try { + Files.setPosixFilePermissions(Path.of(outFileName), PosixFilePermissions.fromString("rwxr-xr-x")); + } catch (Throwable t) { + System.err.printf("WARN: Setting file permissions failed: %s\n", t.getMessage()); + } } } diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/cc.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/cc.mk Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,14 @@ +# +# cc toolchain config +# + +CFLAGS = +CXXFLAGS = +DEBUG_CC_FLAGS = -g +DEBUG_CXX_FLAGS = -g +RELEASE_CC_FLAGS = -O3 -DNDEBUG +RELEASE_CXX_FLAGS = -O3 -DNDEBUG +LDFLAGS = + +SHLIB_CFLAGS = -fPIC +SHLIB_LDFLAGS = -shared \ No newline at end of file diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/clang.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/clang.mk Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,14 @@ +# +# clang toolchain config +# + +CFLAGS = +CXXFLAGS = +DEBUG_CC_FLAGS = -g +DEBUG_CXX_FLAGS = -g +RELEASE_CC_FLAGS = -O3 -DNDEBUG +RELEASE_CXX_FLAGS = -O3 -DNDEBUG +LDFLAGS = + +SHLIB_CFLAGS = -fPIC +SHLIB_LDFLAGS = -shared diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/configure.vm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/configure.vm Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,640 @@ +#!/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 +#foreach( $var in $vars ) +#if( $var.exec ) +${var.varName}=`${var.value}` +#else +${var.varName}="${var.value}" +#end +#end + +# features +#foreach( $feature in $features ) +#if( ${feature.auto} ) +${feature.varName}=auto +#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 + "--prefix="*) prefix=${D}{ARG#--prefix=} ;; + "--exec-prefix="*) exec_prefix=${D}{ARG#--exec-prefix=} ;; + "--bindir="*) bindir=${D}{ARG#----bindir=} ;; + "--sbindir="*) sbindir=${D}{ARG#--sbindir=} ;; + "--libdir="*) libdir=${D}{ARG#--libdir=} ;; + "--libexecdir="*) libexecdir=${D}{ARG#--libexecdir=} ;; + "--datarootdir="*) datarootdir=${D}{ARG#--datarootdir=} ;; + "--datadir="*) datadir=${D}{ARG#--datadir=} ;; + "--sysconfdir="*) sysconfdir=${D}{ARG#--sysconfdir=} ;; + "--sharedstatedir="*) sharedstatedir=${D}{ARG#--sharedstatedir=} ;; + "--localstatedir="*) localstatedir=${D}{ARG#--localstatedir=} ;; + "--includedir="*) includedir=${D}{ARG#--includedir=} ;; + "--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" ;; + #foreach( $opt in $options ) + "--${opt.argument}="*) ${opt.varName}=${D}{ARG#--${opt.argument}=} ;; + #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 + +## 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}'} +: ${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 +} +]]# +## 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" +#foreach( $var in $vars ) +${var.varName}="${D}${var.varName}" +#end +__EOF__ + +# toolchain detection utilities +. make/toolchain.sh + +# +# DEPENDENCIES +# + +# check languages +lang_c= +lang_cpp= +#foreach( $lang in $languages ) +if detect_${lang}_compiler ; then + lang_${lang}=1 +fi +#end + +# 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 +} + +#foreach( $dependency in $namedDependencies ) +dependency_error_${dependency.id}() +{ + printf "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 + #foreach( $np in $sub.notList ) + if isplatform "${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 ; 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 + echo yes + return 1 + done + + #end + echo no + return 0 +} +#end + + + + +# start collecting dependency information +echo > "$TEMP_DIR/flags.mk" + +DEPENDENCIES_FAILED= +ERROR=0 +#if( $dependencies.size() > 0 ) +# unnamed dependencies +TEMP_CFLAGS= +TEMP_CXXFLAGS= +TEMP_LDFLAGS= +#foreach( $dependency in $dependencies ) +while true +do + #if( $dependency.platform ) + if notisplatform "${dependency.platform}"; then + break + fi + #end + #foreach( $np in $dependency.notList ) + if isplatform "${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 ) + printf "checking for pkg-config package $pkg.name... " + if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then + echo yes + TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`" + TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`" + else + echo no + ERROR=1 + break + fi + #end + + #foreach( $flags in $dependency.flags ) + #if( $flags.exec ) + $flags.value > /dev/null + 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 + +# 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 +#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 +#end + +#foreach( $opt in $target.options ) +# Option: --${opt.argument} +if [ -z "${D}${opt.varName}" ]; then + echo "auto-detecting option '${opt.argument}'" + 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.argument}: ${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.argument}' $SAVED_DEPENDENCIES_FAILED" + fi + ERROR="$SAVED_ERROR" + DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED" +else + echo "checking option ${opt.argument} = ${D}${opt.varName}" + if false; then + false + #foreach( $optval in $opt.values ) + elif [ "${D}${opt.varName}" = "${optval.value}" ]; then + echo " ${opt.argument}: ${D}${opt.varName}" >> $TEMP_DIR/options + if $optval.func ; then + : + else + ERROR=1 + DEPENDENCIES_FAILED="option '${opt.argument}' $DEPENDENCIES_FAILED" + fi + #end + fi +fi +#end + +if [ -n "${TEMP_CFLAGS}" -a -n "$lang_c" ]; then + echo "${target.cFlags} += $TEMP_CFLAGS" >> "$TEMP_DIR/flags.mk" +fi +if [ -n "${TEMP_CXXFLAGS}" -a -n "$lang_cpp" ]; then + echo "${target.cxxFlags} += $TEMP_CXXFLAGS" >> "$TEMP_DIR/flags.mk" +fi +if [ "$BUILD_TYPE" = "debug" ]; then + if [ -n "$lang_c" ]; then + echo '${target.cFlags} += ${DEBUG_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi + if [ -n "$lang_cpp" ]; then + echo '${target.cxxFlags} += ${DEBUG_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi +fi +if [ "$BUILD_TYPE" = "release" ]; then + if [ -n "$lang_c" ]; then + echo '${target.cFlags} += ${RELEASE_CC_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi + if [ -n "$lang_cpp" ]; then + echo '${target.cxxFlags} += ${RELEASE_CXX_FLAGS}' >> "$TEMP_DIR/flags.mk" + fi +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 "Build Config:" +echo " PREFIX: $prefix" +echo " TOOLCHAIN: $TOOLCHAIN_NAME" +#if ( $options.size() > 0 ) +echo "Options:" +cat "$TEMP_DIR/options" +#end +#if ( $features.size() > 0 ) +echo "Features:" +#foreach( $feature in $features ) +if [ -n "${D}${feature.varName}" ]; then +echo " $feature.name: on" +else +echo " $feature.name: off" +fi +#end +#end +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" + + diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/gcc.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/gcc.mk Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,15 @@ +# +# gcc toolchain config +# + +CFLAGS = +CXXFLAGS = +DEBUG_CC_FLAGS = -g +DEBUG_CXX_FLAGS = -g +RELEASE_CC_FLAGS = -O3 -DNDEBUG +RELEASE_CXX_FLAGS = -O3 -DNDEBUG +LDFLAGS = + +SHLIB_CFLAGS = -fPIC +SHLIB_LDFLAGS = -shared + diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/project.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/project.xml Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,4 @@ + + + + diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/suncc.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/suncc.mk Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,15 @@ +# +# suncc toolchain +# + +CFLAGS = +CXXFLAGS = +DEBUG_CC_FLAGS = -g +DEBUG_CXX_FLAGS = -g +RELEASE_CC_FLAGS = -O3 -DNDEBUG +RELEASE_CXX_FLAGS = -O3 -DNDEBUG +LDFLAGS = + +SHLIB_CFLAGS = -Kpic +SHLIB_LDFLAGS = -G + diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/toolchain.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/toolchain.sh Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,186 @@ +#!/bin/sh +# +# toolchain detection +# + +C_COMPILERS="gcc clang suncc cc" +CPP_COMPILERS="g++ clang++ sunCC CC" +unset TOOLCHAIN_NAME +unset TOOLCHAIN_CC +unset TOOLCHAIN_CXX + +check_c_compiler() +{ + cat > "$TEMP_DIR/test.c" << __EOF__ +/* test file */ +#include +int main(int argc, char **argv) { +#if defined(__clang__) + printf("clang\n"); +#elif defined(__GNUC__) + printf("gcc\n"); +#elif defined(__sun) + printf("suncc\n"); +#else + printf("unknown\n"); +#endif + return 0; +} +__EOF__ + rm -f "$TEMP_DIR/checkcc" + $1 -o "$TEMP_DIR/checkcc" $CFLAGS $LDFLAGS "$TEMP_DIR/test.c" 2> /dev/null +} + +check_cpp_compiler() +{ + cat > "$TEMP_DIR/test.cpp" << __EOF__ +/* test file */ +#include +int main(int argc, char **argv) { +#if defined(__clang__) + std::cout << "clang" << std::endl; +#elif defined(__GNUC__) + std::cout << "gcc" << std::endl; +#elif defined(__sun) + std::cout << "suncc" << std::endl; +#else + std::cout << "cc" << std::endl; +#endif + return 0; +} +__EOF__ + rm -f "$TEMP_DIR/checkcc" + $1 -o "$TEMP_DIR/checkcc" $CXXFLAGS $LDFLAGS "$TEMP_DIR/test.cpp" 2> /dev/null +} + +create_libtest_source() +{ + # $1: filename + # $2: optional include + cat > "$TEMP_DIR/$1" << __EOF__ +/* libtest file */ +int main(int argc, char **argv) { + return 0; +} +__EOF__ + if [ -n "$2" ]; then + echo "#include <$2>" >> "$TEMP_DIR/$1" + fi +} + +check_c_lib() +{ + # $1: libname + # $2: optional include + if [ -z "$TOOLCHAIN_CC" ]; then + return 1 + fi + create_libtest_source "test.c" "$2" + rm -f "$TEMP_DIR/checklib" + $TOOLCHAIN_CC -o "$TEMP_DIR/checklib" $CFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.c" 2> /dev/null +} + +check_cpp_lib() +{ + # $1: libname + # $2: optional include + if [ -z "$TOOLCHAIN_CXX" ]; then + return 1 + fi + create_libtest_source "test.cpp" "$2" + rm -f "$TEMP_DIR/checklib" + $TOOLCHAIN_CXX -o "$TEMP_DIR/checklib" $CXXFLAGS $LDFLAGS "-l$1" "$TEMP_DIR/test.cpp" 2> /dev/null +} + +check_lib() +{ + # $1: libname + # $2: optional include + if [ -n "$TOOLCHAIN_CC" ]; then + check_c_lib "$1" "$2" + elif [ -n "$TOOLCHAIN_CXX" ]; then + check_cpp_lib "$1" "$2" + fi +} + +detect_c_compiler() +{ + if [ -n "$TOOLCHAIN_CC" ]; then + return 0 + fi + printf "detect C compiler... " + if [ -n "$CC" ]; then + if check_c_compiler "$CC"; then + TOOLCHAIN_CC=$CC + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` + echo "$CC" + return 0 + else + echo "$CC is not a working C compiler" + return 1 + fi + else + for COMP in $C_COMPILERS + do + if check_c_compiler "$COMP"; then + TOOLCHAIN_CC=$COMP + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` + echo "$COMP" + return 0 + fi + done + echo "not found" + return 1 + fi +} + +detect_cpp_compiler() +{ + if [ -n "$TOOLCHAIN_CXX" ]; then + return 0 + fi + printf "detect C++ compiler... " + + if [ -n "$CXX" ]; then + if check_cpp_compiler "$CXX"; then + TOOLCHAIN_CXX=$CXX + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` + echo "$CXX" + return 0 + else + echo "$CXX is not a working C++ compiler" + return 1 + fi + else + for COMP in $CPP_COMPILERS + do + if check_cpp_compiler "$COMP"; then + TOOLCHAIN_CXX=$COMP + TOOLCHAIN_NAME=`"$TEMP_DIR/checkcc"` + echo "$COMP" + return 0 + fi + done + echo "${TOOLCHAIN_CXX:-"not found"}" + return 1 + fi +} + +write_toolchain_defaults() +{ + echo "# toolchain" >> "$1" + if [ -n "$TOOLCHAIN_CC" ]; then + echo "CC = ${TOOLCHAIN_CC}" >> "$1" + fi + if [ -n "$TOOLCHAIN_CXX" ]; then + echo "CXX = ${TOOLCHAIN_CXX}" >> "$1" + fi + echo >> "$1" + if [ -f "make/${TOOLCHAIN_NAME}.mk" ]; then + cat "make/${TOOLCHAIN_NAME}.mk" >> "$1" + elif [ -f "make/cc.mk" ]; then + cat "make/cc.mk" >> "$1" + else + echo "!!! WARNING !!! Default toolchain flags not found. Configuration might be incomplete." + fi +} diff -r 9817c08f9637 -r a13789dd1cfb src/main/resources/make/uwproj.xsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/resources/make/uwproj.xsd Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,281 @@ + + + + + + + + The root element of an uwproj project. + Consists of an optional config element + and an arbitrary number of dependency + and target elements. + + + + + + + + + + + + + The configuration section. + Consists of an arbitrary number of var elements. + + + + + + + + + + + The definition of a configuration variable. +

+ Configuration variables are supposed to be used in the configure script and are also + written to the resulting config file (in contrast to make variables, which are only + written to the config file). + The name attribute is mandatory, the value is defined by the text body of the element. + The optional Boolean exec attribute (false by default) controls, whether the entire + definition is automatically executed under command substitution. +

+
+
+ + + + + + +
+ + + + + Instructs configure to invoke pkg-config, if present on the system, to determine + compiler and linker flags. The text body of this element defines the package name to search. + To constrain the allowed versions, use the attributes atleast, exact, max. + + + + + + + + + + + + + + + Requests a compiler for the specified language. Allowed values are + c, cpp. + + + + + + + + + + + + Declares a dependency. +

+ If the optional name attribute is omitted, the dependency is global + and must be satisfied, otherwise configuration shall fail. + A named dependency can be referenced by a target (or is implicitly referenced + by the default target, if no targets are specified). + Multiple declarations for the same named dependency may exist, in which case each declaration + is checked one after another, until one block is satisfied. The result of the first satisfied + dependency declaration is supposed to be applied to the config file. +

+

+ The optional platform attribute may specify a single platform identifier and + the optional not attribute may specify a comma-separated list of platform identifiers. + The configure script shall skip this dependency declaration if the detected platform is not + matching the filter specification of these attributes. +

+
+
+ + + + + + + + + + Specifies a custom command that shall be executed to test whether this dependency is satisfied. + + + + + + + + +
+ + + + + Instructs configure to append the contents of the element's body to the respective flags variable. + If the optional exec flag is set to true, the contents are supposed to be + executed under command substitution at configuration time before they are applied. + + + + + + + + + + + + + Declares a build target that is supposed to be configured. +

+ If no build target is declared explicitly, an implicit default + target is generated, which has the alldependencies + flag set. +

+

+ The optional name attribute is also used to generate a prefix + for the compiler and linker flags variables. + Furthermore, a target may consist of an arbitrary number of feature, + option, and define elements. + Named dependencies can be listed (separated by comma) in the dependencies + element. If this target shall use all available named dependencies, the empty + element alldependencies can be used as a shortcut. +

+
+
+ + + + + + + + + + +
+ + + + + Declares an optional feature, that can be enabled during configuration, if all + dependencies are satisfied. + If a feature is enabled, all define and make definitions are + supposed to be applied to the config file. + In case the optional default attribute is set to true, the feature is enabled by default + and is supposed to be automatically disabled (without error) when the dependencies are not satisfied. + The name that is supposed to be used for the --enable and --disable arguments can be optionally + specified with the arg attribute. Otherwise, the name is used by default. + + + + + + + + + + + + + + Declares a configuration option. + The option argument name is specified with the arg attribute. + Then, the children of this element specify possible values by defining the conditions + (in terms of dependencies) and effects (in terms of defines and make variables) of each value. + Finally, a set of defaults is specified which supposed to automagically select the most + appropriate value for a specific platform under the available dependencies (in case the option is not + explicitly specified by using the command line argument). + + + + + + + + + + + + + Declares a possible value for the option (in the str attribute) and + the conditions (dependencies) and effects, the value has. + + + + + + + + + + + + Specifies a default value for this option. Multiple default values can be specified, in which case + they are checked one after another for availability. With the optional platform attribute, + the default value can be constrained to a single specific platform and is supposed to be + skipped by configure, when this platform is not detected. + + + + + + + + + + + + + + + + + + Specifies C/C++ pre-processor definitions that are supposed to + be appended to the compiler flags, if supported. + (Note: for example, Fortran also supports C/C++ style pre-processor definitions under + certain circumstances) + + + + + + + + + A comma-separated list of named dependencies. + + + + + + + + The text contents in the body of this element are supposed to be appended literally + to the config file without prior processing. + + + + +
\ No newline at end of file diff -r 9817c08f9637 -r a13789dd1cfb test/make/uwproj.xsd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/make/uwproj.xsd Sun Oct 15 19:20:41 2023 +0200 @@ -0,0 +1,281 @@ + + + + + + + + The root element of an uwproj project. + Consists of an optional config element + and an arbitrary number of dependency + and target elements. + + + + + + + + + + + + + The configuration section. + Consists of an arbitrary number of var elements. + + + + + + + + + + + The definition of a configuration variable. +

+ Configuration variables are supposed to be used in the configure script and are also + written to the resulting config file (in contrast to make variables, which are only + written to the config file). + The name attribute is mandatory, the value is defined by the text body of the element. + The optional Boolean exec attribute (false by default) controls, whether the entire + definition is automatically executed under command substitution. +

+
+
+ + + + + + +
+ + + + + Instructs configure to invoke pkg-config, if present on the system, to determine + compiler and linker flags. The text body of this element defines the package name to search. + To constrain the allowed versions, use the attributes atleast, exact, max. + + + + + + + + + + + + + + + Requests a compiler for the specified language. Allowed values are + c, cpp. + + + + + + + + + + + + Declares a dependency. +

+ If the optional name attribute is omitted, the dependency is global + and must be satisfied, otherwise configuration shall fail. + A named dependency can be referenced by a target (or is implicitly referenced + by the default target, if no targets are specified). + Multiple declarations for the same named dependency may exist, in which case each declaration + is checked one after another, until one block is satisfied. The result of the first satisfied + dependency declaration is supposed to be applied to the config file. +

+

+ The optional platform attribute may specify a single platform identifier and + the optional not attribute may specify a comma-separated list of platform identifiers. + The configure script shall skip this dependency declaration if the detected platform is not + matching the filter specification of these attributes. +

+
+
+ + + + + + + + + + Specifies a custom command that shall be executed to test whether this dependency is satisfied. + + + + + + + + +
+ + + + + Instructs configure to append the contents of the element's body to the respective flags variable. + If the optional exec flag is set to true, the contents are supposed to be + executed under command substitution at configuration time before they are applied. + + + + + + + + + + + + + Declares a build target that is supposed to be configured. +

+ If no build target is declared explicitly, an implicit default + target is generated, which has the alldependencies + flag set. +

+

+ The optional name attribute is also used to generate a prefix + for the compiler and linker flags variables. + Furthermore, a target may consist of an arbitrary number of feature, + option, and define elements. + Named dependencies can be listed (separated by comma) in the dependencies + element. If this target shall use all available named dependencies, the empty + element alldependencies can be used as a shortcut. +

+
+
+ + + + + + + + + + +
+ + + + + Declares an optional feature, that can be enabled during configuration, if all + dependencies are satisfied. + If a feature is enabled, all define and make definitions are + supposed to be applied to the config file. + In case the optional default attribute is set to true, the feature is enabled by default + and is supposed to be automatically disabled (without error) when the dependencies are not satisfied. + The name that is supposed to be used for the --enable and --disable arguments can be optionally + specified with the arg attribute. Otherwise, the name is used by default. + + + + + + + + + + + + + + Declares a configuration option. + The option argument name is specified with the arg attribute. + Then, the children of this element specify possible values by defining the conditions + (in terms of dependencies) and effects (in terms of defines and make variables) of each value. + Finally, a set of defaults is specified which supposed to automagically select the most + appropriate value for a specific platform under the available dependencies (in case the option is not + explicitly specified by using the command line argument). + + + + + + + + + + + + + Declares a possible value for the option (in the str attribute) and + the conditions (dependencies) and effects, the value has. + + + + + + + + + + + + Specifies a default value for this option. Multiple default values can be specified, in which case + they are checked one after another for availability. With the optional platform attribute, + the default value can be constrained to a single specific platform and is supposed to be + skipped by configure, when this platform is not detected. + + + + + + + + + + + + + + + + + + Specifies C/C++ pre-processor definitions that are supposed to + be appended to the compiler flags, if supported. + (Note: for example, Fortran also supports C/C++ style pre-processor definitions under + certain circumstances) + + + + + + + + + A comma-separated list of named dependencies. + + + + + + + + The text contents in the body of this element are supposed to be appended literally + to the config file without prior processing. + + + + +
\ No newline at end of file diff -r 9817c08f9637 -r a13789dd1cfb uwproj.xsd --- a/uwproj.xsd Wed Oct 11 20:41:26 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,281 +0,0 @@ - - - - - - - - The root element of an uwproj project. - Consists of an optional config element - and an arbitrary number of dependency - and target elements. - - - - - - - - - - - - - The configuration section. - Consists of an arbitrary number of var elements. - - - - - - - - - - - The definition of a configuration variable. -

- Configuration variables are supposed to be used in the configure script and are also - written to the resulting config file (in contrast to make variables, which are only - written to the config file). - The name attribute is mandatory, the value is defined by the text body of the element. - The optional Boolean exec attribute (false by default) controls, whether the entire - definition is automatically executed under command substitution. -

-
-
- - - - - - -
- - - - - Instructs configure to invoke pkg-config, if present on the system, to determine - compiler and linker flags. The text body of this element defines the package name to search. - To constrain the allowed versions, use the attributes atleast, exact, max. - - - - - - - - - - - - - - - Requests a compiler for the specified language. Allowed values are - c, cpp. - - - - - - - - - - - - Declares a dependency. -

- If the optional name attribute is omitted, the dependency is global - and must be satisfied, otherwise configuration shall fail. - A named dependency can be referenced by a target (or is implicitly referenced - by the default target, if no targets are specified). - Multiple declarations for the same named dependency may exist, in which case each declaration - is checked one after another, until one block is satisfied. The result of the first satisfied - dependency declaration is supposed to be applied to the config file. -

-

- The optional platform attribute may specify a single platform identifier and - the optional not attribute may specify a comma-separated list of platform identifiers. - The configure script shall skip this dependency declaration if the detected platform is not - matching the filter specification of these attributes. -

-
-
- - - - - - - - - - Specifies a custom command that shall be executed to test whether this dependency is satisfied. - - - - - - - - -
- - - - - Instructs configure to append the contents of the element's body to the respective flags variable. - If the optional exec flag is set to true, the contents are supposed to be - executed under command substitution at configuration time before they are applied. - - - - - - - - - - - - - Declares a build target that is supposed to be configured. -

- If no build target is declared explicitly, an implicit default - target is generated, which has the alldependencies - flag set. -

-

- The optional name attribute is also used to generate a prefix - for the compiler and linker flags variables. - Furthermore, a target may consist of an arbitrary number of feature, - option, and define elements. - Named dependencies can be listed (separated by comma) in the dependencies - element. If this target shall use all available named dependencies, the empty - element alldependencies can be used as a shortcut. -

-
-
- - - - - - - - - - -
- - - - - Declares an optional feature, that can be enabled during configuration, if all - dependencies are satisfied. - If a feature is enabled, all define and make definitions are - supposed to be applied to the config file. - In case the optional default attribute is set to true, the feature is enabled by default - and is supposed to be automatically disabled (without error) when the dependencies are not satisfied. - The name that is supposed to be used for the --enable and --disable arguments can be optionally - specified with the arg attribute. Otherwise, the name is used by default. - - - - - - - - - - - - - - Declares a configuration option. - The option argument name is specified with the arg attribute. - Then, the children of this element specify possible values by defining the conditions - (in terms of dependencies) and effects (in terms of defines and make variables) of each value. - Finally, a set of defaults is specified which supposed to automagically select the most - appropriate value for a specific platform under the available dependencies (in case the option is not - explicitly specified by using the command line argument). - - - - - - - - - - - - - Declares a possible value for the option (in the str attribute) and - the conditions (dependencies) and effects, the value has. - - - - - - - - - - - - Specifies a default value for this option. Multiple default values can be specified, in which case - they are checked one after another for availability. With the optional platform attribute, - the default value can be constrained to a single specific platform and is supposed to be - skipped by configure, when this platform is not detected. - - - - - - - - - - - - - - - - - - Specifies C/C++ pre-processor definitions that are supposed to - be appended to the compiler flags, if supported. - (Note: for example, Fortran also supports C/C++ style pre-processor definitions under - certain circumstances) - - - - - - - - - A comma-separated list of named dependencies. - - - - - - - - The text contents in the body of this element are supposed to be appended literally - to the config file without prior processing. - - - - -
\ No newline at end of file