aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gen-deps54
-rwxr-xr-xscripts/gen-report18
-rwxr-xr-xscripts/gen-rv64-fw23
-rw-r--r--scripts/makefile81
-rw-r--r--scripts/makefile.tests6
5 files changed, 156 insertions, 26 deletions
diff --git a/scripts/gen-deps b/scripts/gen-deps
index 0feed7e..1238a94 100755
--- a/scripts/gen-deps
+++ b/scripts/gen-deps
@@ -1,35 +1,37 @@
#!/bin/sh
-gencommon () {
- lint="build/${s%.*}${1}.l"
- dep="build/${s%.*}${1}.d"
- obj="build/${s%.*}${1}"
+PREFIX=
+COMPILE=COMPILE
+LINT=LINT
+BUILD=build
- echo "${dep}:" >> deps.mk
- echo "include ${dep}" >> deps.mk
- echo "${obj}: ${s}" >> deps.mk
-}
-
-genobjs () {
- gencommon ".o"
- echo "${obj}: ${s}" >> deps.mk
- echo " \$(COMPILE) -c $< -o \$@" >> deps.mk
-
- echo "${lint}: ${s}" >> deps.mk
- echo " \$(LINT) -c ${s} -o /dev/null" >> deps.mk
-}
+while getopts "p:c:b:l:" opt; do
+ case "$opt" in
+ p) PREFIX="$OPTARG"_;;
+ c) COMPILE="$OPTARG";;
+ l) LINT="$OPTARG";;
+ b) BUILD=build/"$OPTARG";;
+ *) echo "unrecognised option -$OPTARG" >&2; exit 1;;
+ esac
+done
-case "${1}" in
- --sources)
- func=genobjs
- ;;
-esac
+shift $((OPTIND - 1))
# create all subdirectories
-mkdir -p $(echo "${2}" | xargs dirname | uniq | sed 's|^|build/|g')
+mkdir -p $(echo "${@}" | tr ' ' '\n' | sed "s|[^/]*$||;s|^|${BUILD}/|" | uniq)
-for s in ${2}
+for s in ${@}
do
- ${func} ${suffix}
- echo ${obj}
+ obj="${BUILD}/${s%.*}.o"
+ lint="${obj}.l"
+ dep="${obj}.d"
+
+ echo "${PREFIX}OBJS += ${obj}" >> deps.mk
+ echo "${PREFIX}LINTS += ${lint}" >> deps.mk
+ echo "${dep}:" >> deps.mk
+ echo "-include ${dep}" >> deps.mk
+ echo "${obj}: ${s}" >> deps.mk
+ echo " \$(${COMPILE}) -c ${s} -o ${obj}" >> deps.mk
+ echo "${lint}: ${s}" >> deps.mk
+ echo " \$(${LINT}) -c ${s} -o /dev/null" >> deps.mk
done
diff --git a/scripts/gen-report b/scripts/gen-report
new file mode 100755
index 0000000..38e4a47
--- /dev/null
+++ b/scripts/gen-report
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+BUILD=build
+
+while getopts "d:" opt; do
+ case "$opt" in
+ d) BUILD="$OPTARG";;
+ *) echo "unregonised option -$OPTARG" >&2; exit 1;;
+ esac
+done
+
+shift $((OPTIND - 1))
+
+for p in "$@"; do
+ mkdir -p "reports/${p}"
+ timeout --foreground 30s valgrind -q --error-exitcode=1 \
+ "./${BUILD}/${p}" > "reports/${p}/log"
+done
diff --git a/scripts/gen-rv64-fw b/scripts/gen-rv64-fw
new file mode 100755
index 0000000..831071d
--- /dev/null
+++ b/scripts/gen-rv64-fw
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+BUILD=build
+NAME=
+
+while getopts "d:o:" opt; do
+ case "$opt" in
+ d) BUILD="$OPTARG";;
+ o) NAME="$OPTARG";;
+ *) echo "unrecognised option -$OPTARG" >&2; exit 1;
+ esac
+done
+
+shift $((OPTIND - 1))
+
+# might try to figure out how to support llvm as well in tests, but good enough
+# for now
+riscv64-unknown-elf-gcc -O2 -Wall -Wextra -ffreestanding -nostdlib \
+ -march=rv64i -mabi=lp64 -fno-delete-null-pointer-checks \
+ -o "${BUILD}/${NAME}.elf" "${@}"
+
+riscv64-unknown-elf-objcopy -Obinary "${BUILD}/${NAME}.elf" "${BUILD}/${NAME}.bin"
+xxd -i "${BUILD}/${NAME}.bin" > "${BUILD}/${NAME}"
diff --git a/scripts/makefile b/scripts/makefile
new file mode 100644
index 0000000..dc094fa
--- /dev/null
+++ b/scripts/makefile
@@ -0,0 +1,81 @@
+# this could be done better
+RELEASE ?= 0
+OPTFLAGS != [ "$(RELEASE)" != "0" ] \
+ && echo "-O2 -flto=auto" \
+ || echo "-O0"
+
+DEBUG ?= 1
+DEBUGFLAGS != [ "$(DEBUG)" != "0" ] \
+ && echo "-DDEBUG=1" \
+ || echo "-DNDEBUG=1"
+
+ASSERT ?= 1
+ASSERTFLAGS != [ "$(ASSERT)" != "0" ] \
+ && echo "-DASSERT=1" \
+ || echo
+
+DEP_FLAGS = -MT $@ -MMD -MP -MF $@.d
+LINT_FLAGS := -fsyntax-only
+PREPROCESS := -E
+
+LLVM ?= 0
+BUILD := build
+
+all: libgran.a
+
+# default values, overwrite if/when needed
+CROSS_COMPILE :=
+
+OBJCOPY != [ "$(LLVM)" != "0" ] \
+ && echo llvm-objcopy \
+ || echo $(CROSS_COMPILE)objcopy
+
+COMPILER != [ -n "$(CROSS_COMPILE)" ] \
+ && { \
+ [ "$(LLVM)" != "0" ] \
+ && echo clang --target="$(CROSS_COMPILE)" \
+ || echo $(CROSS_COMPILE)gcc \
+ ; \
+ } \
+ || echo $(CC)
+
+
+OBFLAGS := -g
+WARNFLAGS := -Wall -Wextra
+
+COMPILE_FLAGS := $(CFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(OBFLAGS) $(ASSERTFLAGS) \
+ $(DEBUGFLAGS)
+
+INCLUDE_FLAGS := -I include -I deps/conts/include
+
+LINT = $(COMPILER) \
+ $(COMPILE_FLAGS) $(LIN_TFLAGS) $(INCLUDE_FLAGS)
+
+UBSAN ?= 0
+SANITIZE_FLAGS != [ "$(UBSAN)" != "0" ] \
+ && echo -fsanitize=undefined \
+ || echo
+
+# don't use dep trick for tests
+COMPILE_TEST := $(COMPILER) $(COMPILE_FLAGS) \
+ $(INCLUDE_FLAGS) $(SANITIZE_FLAGS)
+
+# dep flags use delayed expansion trick so we can't use := here
+COMPILE_GRAN = $(COMPILER) $(COMPILE_FLAGS) \
+ $(DEP_FLAGS) $(INCLUDE_FLAGS) $(SANITIZE_FLAGS)
+
+TESTS != [ -n "$(CHECK)" ] && echo "$(CHECK)" || echo check
+
+-include deps.mk
+
+libgran.a: $(GRAN_OBJS)
+ $(AR) rcs $@ $(GRAN_OBJS)
+
+
+# might lint some common things twice
+.PHONY:
+lint: $(GRAN_LINTS)
+
+.PHONY: check
+check:
+ $(MAKE) -f scripts/makefile.tests -k $(TESTS) COMPILE_TEST="$(COMPILE_TEST)"
diff --git a/scripts/makefile.tests b/scripts/makefile.tests
new file mode 100644
index 0000000..600a819
--- /dev/null
+++ b/scripts/makefile.tests
@@ -0,0 +1,6 @@
+TESTS :=
+
+include tests/*/source.mk
+
+.PHONY: check
+check: $(TESTS)