--- a/build.template Mon Dec 15 10:59:58 2025 +0100 +++ b/build.template Mon Dec 15 19:18:04 2025 +0100 @@ -1,7 +1,133 @@ #!/bin/sh -pwd +# 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 +} + +# 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" + +mkdir result +result_dir=`pwd`/result + +configure_log=configure.log +compile_log=compile.log +check_log=check.log + +result_file=`pwd`/result.json + + +echo "[" > $result_file -echo {{ .Path }} -echo TODO +# repo source is always expected to be in src/ +cd src +{{ $nbuild := len .Build }} +{{ range $i, $build := .Build}} +# Build isplatform="{{ .IsPlatform }}" not="{{ .NotPlatform }}" +while true +do + log_dir=$result_dir/build{{$i}} + mkdir -p $log_dir + if [ $? -ne 0 ]; then + echo "failed to create log dir $log_dir" + echo "abort" + exit 1 + fi + + {{- if .IsPlatform}} + if notisplatform "{{ $build.IsPlatform }}"; then + break + fi + {{- end}} + {{- range $build.NotList}} + if isplatform "{{.}}"; then + break + fi + {{- end}} + + # configure + configure= + {{- if $build.Configure}} + {{ $build.Configure }} > $log_dir/$configure_log 2>&1 + configure=$? + {{- end}} + # compile + compile= + {{- if $build.Compile}} + {{ $build.Compile }} > $log_dir/$compile_log 2>&1 + compile=$? + {{- end}} + + # check + check= + {{- if $build.Check}} + {{ $build.Check }} > $log_dir/$check_log 2>&1 + check=$? + {{- end}} + + # write result + echo "write result to $result_file" + echo "{ \"build\":\"{{$i}}\", " >> $result_file + if [ -n "$configure" ]; then + echo " \"configure\":\"$configure\"," >> $result_file + fi + if [ -n "compile" ]; then + echo " \"compile\":\"$compile\"," >> $result_file + fi + if [ -n "check" ]; then + echo " \"check\":\"$check\"" >> $result_file + fi + {{- if eq $i (sub $nbuild 1) }} + echo '}' >> $result_file + {{ else }} + echo '},' >> $result_file + {{- end }} + break +done +# End Build +{{ end}} + +echo "]" >> $result_file +