diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-05-24 14:32:35 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-05-24 14:39:31 +0300 |
| commit | 123860bc029465ff88c3bf82165a89170fa41153 (patch) | |
| tree | 7218306027a61d5e9c1dc1107aeef09eb153ec1b /scripts | |
| parent | 9f261587a75d5fa21ef63fd9a38e0f7851180adf (diff) | |
| download | qbt-123860bc029465ff88c3bf82165a89170fa41153.tar.gz qbt-123860bc029465ff88c3bf82165a89170fa41153.zip | |
fix bmake compilation
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/gen-deps | 54 | ||||
| -rw-r--r-- | scripts/makefile | 68 |
2 files changed, 96 insertions, 26 deletions
diff --git a/scripts/gen-deps b/scripts/gen-deps index 0feed7e..f45707c 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/makefile b/scripts/makefile new file mode 100644 index 0000000..b416c35 --- /dev/null +++ b/scripts/makefile @@ -0,0 +1,68 @@ +# 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: qbt + +include gen/source.mk + +# 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 := -g +WARNFLAGS := -Wall -Wextra + +COMPILE_FLAGS := $(CFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(OBFLAGS) $(ASSERTFLAGS) \ + $(DEBUGFLAGS) + +INCLUDE_FLAGS := -I include + +COMPILE = $(COMPILER) \ + $(COMPILE_FLAGS) $(DEPFLAGS) $(INCLUDE_FLAGS) + +LINT = $(COMPILER) \ + $(COMPILE_FLAGS) $(LINTFLAGS) $(INCLUDE_FLAGS) + +UBSAN ?= 0 +TRISCV_FLAGS != [ "$(UBSAN)" != "0" ] \ + && echo -fsanitize=undefined \ + || echo + +COMPILE_QBT = $(COMPILE) $(QBT_FLAGS) + +-include deps.mk + +qbt: $(QBT_OBJS) + $(COMPILE_QBT) $(QBT_OBJS) -o $@ + +# might lint some common things twice +.PHONY: +lint: $(TRISCV_LINTS) |
