diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-10-29 14:38:33 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-10-29 14:38:33 +0200 |
| commit | 5d29afb530ffdaab4b5032b7422da988b31c0867 (patch) | |
| tree | 0135976b951fa4c860a043f07e6d555e40c60d1f /tdump/scripts | |
| parent | 80d78c5589d42f81b04e671b28c103a2112458d1 (diff) | |
| download | tri-5d29afb530ffdaab4b5032b7422da988b31c0867.tar.gz tri-5d29afb530ffdaab4b5032b7422da988b31c0867.zip | |
initial working compiled program on simulator
Diffstat (limited to 'tdump/scripts')
| -rwxr-xr-x | tdump/scripts/gen-deps | 37 | ||||
| -rwxr-xr-x | tdump/scripts/license | 16 | ||||
| -rw-r--r-- | tdump/scripts/makefile | 72 | ||||
| -rwxr-xr-x | tdump/scripts/warn-undocumented | 7 |
4 files changed, 132 insertions, 0 deletions
diff --git a/tdump/scripts/gen-deps b/tdump/scripts/gen-deps new file mode 100755 index 0000000..f45707c --- /dev/null +++ b/tdump/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/tdump/scripts/license b/tdump/scripts/license new file mode 100755 index 0000000..53bd5da --- /dev/null +++ b/tdump/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/tdump/scripts/makefile b/tdump/scripts/makefile new file mode 100644 index 0000000..b782cd1 --- /dev/null +++ b/tdump/scripts/makefile @@ -0,0 +1,72 @@ +# this could be done better +RELEASE ?= 0 +OPTFLAGS != [ "$(RELEASE)" != "0" ] \ + && echo "-O3 -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 + +LLVM ?= 0 +BUILD = build + +all: tdump + +# default values, overwrite if/when needed +CROSS_COMPILE = + +OBJCOPY != [ "$(LLVM)" != "0" ] \ + && echo llvm-objcopy \ + || echo $(CROSS_COMPILE)objcopy + +COMPILER != [ "$(LLVM)" != "0" ] \ + && echo clang --target="$(CROSS_COMPILE)" \ + || echo $(CROSS_COMPILE)gcc + + +OBFLAGS = -std=gnu17 -g +WARNFLAGS = -Wall -Wextra + +COMPILE_FLAGS = $(CFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(OBFLAGS) $(ASSERTFLAGS) \ + $(DEBUGFLAGS) + +INCLUDE_FLAGS = -I include -I ../core + +# This makes sure .bss is loaded into the binary +OBJCOPY_FLAGS ?= -Obinary -R .garbage \ + --set-section-flags .bss=alloc,load,contents + +COMPILE = $(COMPILER) \ + $(COMPILE_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS) + +LINT = $(COMPILER) \ + $(COMPILE_FLAGS) $(LINTFLAGS) $(INCLUDE_FLAGS) + +UBSAN ?= 0 +TASM_FLAGS != [ "$(UBSAN)" != "0" ] \ + && echo -fsanitize=undefined \ + || echo + +COMPILE_TDUMP = $(COMPILE) $(TDUMP_FLAGS) + +-include deps.mk +-include src/source.mk + +tdump: $(TDUMP_OBJS) + $(COMPILE_TDUMP) $(TDUMP_OBJS) -o $@ + + +# might lint some common things twice +.PHONY: +lint: $(TDUMP_LINTS) diff --git a/tdump/scripts/warn-undocumented b/tdump/scripts/warn-undocumented new file mode 100755 index 0000000..aa7d0f7 --- /dev/null +++ b/tdump/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 |
