aboutsummaryrefslogtreecommitdiff
path: root/tests/scripts/gen-prog
diff options
context:
space:
mode:
Diffstat (limited to 'tests/scripts/gen-prog')
-rwxr-xr-xtests/scripts/gen-prog34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/scripts/gen-prog b/tests/scripts/gen-prog
new file mode 100755
index 0000000..e56ecc3
--- /dev/null
+++ b/tests/scripts/gen-prog
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+NAME=
+PROG=
+while getopts "n:p:" opt; do
+ case "$opt" in
+ n) NAME="$OPTARG";;
+ p) PROG="$OPTARG";;
+ *) echo "unrecognised options -$OPTARG" >&2; exit 1;
+ esac
+done
+
+shift $((OPTIND - 1))
+
+# create all subdirectories
+mkdir -p $(echo "${@}" | tr ' ' '\n' | sed "s|[^/]*$||;s|^|build/$NAME|" | uniq)
+
+for s in ${@}
+do
+ obj="build/${NAME}/${s%.*}.o"
+ dep="${obj}.d"
+
+ echo "${NAME}_OBJS += ${obj}" >> tests.mk
+ echo "${dep}:" >> tests.mk
+ echo "-include ${dep}" >> tests.mk
+ echo "${obj}: $NAME/${s}" >> tests.mk
+ echo " \$(COMPILE_TEST) -c $NAME/${s} -o ${obj}" >> tests.mk
+done
+
+echo "build/${NAME}/$PROG: \$(${NAME}_OBJS) \$(COMMON)" >> tests.mk
+echo " \$(COMPILE_TEST) \$(${NAME}_OBJS) \$(COMMON) \
+ -o build/${NAME}/$PROG" >> tests.mk
+
+echo "include ${NAME}/check.mk" >> tests.mk