M build_util.sh => build_util.sh +45 -0
@@ 24,6 24,12 @@ pecho()
printf '%s\n' "$*"
}
+# Return the value of variable named $1
+value()
+{
+ eval pecho "\"\$$1\""
+}
+
# Print all arguments to stderr and exits with status 1
die()
{
@@ 54,6 60,45 @@ lastarg()
eval pecho "\${$#}"
}
+# Check that type $1 is respected for the remaining argument variables
+typecheck()
+{
+ local type=$1 var= val= success=true
+ shift
+ for var
+ do
+ match "$var" '[0-9]+' && die "positional parameters can't be used with typecheck"
+ val=$(value "$var")
+ case "$type" in
+ bool)
+ [ "$val" != true ] && [ "$val" != false ] && {
+ pecho "$var is of type bool, must contain \"true\" or \"false\", not \"$val\"" >&2
+ success=false
+ }
+ ;;
+ int)
+ ! match "$val" '[+-]?[0-9]+' && {
+ pecho "$var is of type int, must contain an integer, not \"$val\"" >&2
+ success=false
+ }
+ ;;
+ uint)
+ ! match "$val" '\+?[0-9]+' && {
+ pecho "$var is of type uint, must contain a positive integer, not \"$val\"" >&2
+ success=false
+ }
+ ;;
+ float)
+ { ! match "$val" '[+-]?[0-9]*\.[0-9]*' || match "$val" '[+-]?\.'; } && {
+ pecho "$var is of type float, must contain a floating point value, not \"$val\"" >&2
+ success=false
+ }
+ ;;
+ esac
+ done
+ $success
+}
+
# Like atexit(3), a way to stack EXIT traps
# Caution: overwrite the traps for terminating signals
atexit()
M prog-c/build.sh => prog-c/build.sh +5 -2
@@ 19,7 19,10 @@ NATIVE=${NATIVE:-false}
CONFIG=${CONFIG:-release}
PREFIX=$(preadlinkf "${DESTDIR+${DESTDIR%/}}${PREFIX:-/usr/local}")
-# Override configuration with target specific values
+typecheck bool LTO PGO STATIC NATIVE
+typecheck uint JOBS
+
+# Target specific values
STD=c99
BIN=prog-c
[ -f ../VERSION ] && version=$(cat ../VERSION) || version=$(git_version ..)
@@ 31,7 34,7 @@ USE_FEATURE1=${USE_FEATURE1:-true}
USE_FEATURE2=${USE_FEATURE2:-false}
-# Prepare the source list
+# Prepare the source list (must be done before any cclean call)
SRC=$(printf '%s\n' *.c)
# gperf files detection