aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-02-08 21:19:38 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2024-02-08 21:19:38 +0200
commitc035571d85e3d756804519d82de8b354f3910b29 (patch)
tree89714e13753d200d6e9a04f0d19d6dd1f7a55b2e /scripts
downloadposthaste-c035571d85e3d756804519d82de8b354f3910b29.tar.gz
posthaste-c035571d85e3d756804519d82de8b354f3910b29.zip
project work phase 1
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/gen-deps37
-rwxr-xr-xscripts/license16
-rw-r--r--scripts/makefile57
-rwxr-xr-xscripts/warn-undocumented7
4 files changed, 117 insertions, 0 deletions
diff --git a/scripts/gen-deps b/scripts/gen-deps
new file mode 100755
index 0000000..f45707c
--- /dev/null
+++ b/scripts/gen-deps
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+PREFIX=
+COMPILE=COMPILE
+LINT=LINT
+BUILD=build/
+
+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
+
+shift $((OPTIND - 1))
+
+# create all subdirectories
+mkdir -p $(echo "${@}" | tr ' ' '\n' | sed "s|[^/]*$||;s|^|${BUILD}/|" | uniq)
+
+for s in ${@}
+do
+ 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/license b/scripts/license
new file mode 100755
index 0000000..53bd5da
--- /dev/null
+++ b/scripts/license
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+SPDX="/* SPDX-License-Identifier: copyleft-next-0.3.1 */"
+
+for f in "$@"
+do
+ if [ "$(head -1 "$f")" != "${SPDX}" ]
+ then
+ sed -i "1i${SPDX}\n" "$f"
+ fi
+
+ if ! grep 'Copyright' "$f" > /dev/null
+ then
+ echo "Missing copyright info in $f"
+ fi
+done
diff --git a/scripts/makefile b/scripts/makefile
new file mode 100644
index 0000000..fc1eb58
--- /dev/null
+++ b/scripts/makefile
@@ -0,0 +1,57 @@
+# this could be done better
+RELEASE ?= 0
+OPTFLAGS != [ "$(RELEASE)" != "0" ] \
+ && echo "-O2 -flto" \
+ || echo "-O0"
+
+DEBUG ?= 1
+DEBUGFLAGS != [ "$(DEBUG)" != "0" ] \
+ && echo "-DDEBUG=1" \
+ || echo "-DNDEBUG=1"
+
+ASSERT ?= 1
+ASSERTFLAGS != [ "$(ASSERT)" != "0" ] \
+ && echo "-DASSERT=1" \
+ || echo
+
+DEPFLAGS = -MT $@ -MMD -MP -MF $@.d
+LINTFLAGS = -fsyntax-only
+PREPROCESS = -E
+
+BUILD = build
+
+all: posthaste
+
+
+OBFLAGS = -g
+WARNFLAGS = -Wall -Wextra -Wvla
+
+COMPILE_FLAGS = $(CFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(OBFLAGS) $(ASSERTFLAGS) \
+ $(DEBUGFLAGS)
+
+LINK_FLAGS = $(LDFLAGS)
+
+INCLUDE_FLAGS = -I include
+
+COMPILE = $(CC) \
+ $(COMPILE_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS)
+
+LINT = $(CC) \
+ $(COMPILE_FLAGS) $(LINTFLAGS) $(INCLUDE_FLAGS)
+
+COMPILE_POSTHASTE = $(COMPILE)
+
+-include deps.mk
+
+gen/gen_parser.c: src/parser.y gen/gen_lexer.inc
+ bison -Wcounterexamples -o gen/gen_parser.c src/parser.y
+
+gen/gen_lexer.inc: src/lexer.l
+ flex -o gen/gen_lexer.inc src/lexer.l
+
+posthaste: $(POSTHASTE_OBJS)
+ $(COMPILE_POSTHASTE) $(POSTHASTE_OBJS) -o $@
+
+# might lint some common things twice
+.PHONY:
+lint: $(POSTHASTE_LINTS)
diff --git a/scripts/warn-undocumented b/scripts/warn-undocumented
new file mode 100755
index 0000000..aa7d0f7
--- /dev/null
+++ b/scripts/warn-undocumented
@@ -0,0 +1,7 @@
+#!/bin/sh
+# look through all files for either @file or \file
+for file in $@
+do
+ grep -c '[@\]file' "$file" |\
+ awk -F':' "\$1 == 0 {print \"Undocumented file: $file\"}"
+done