lambda-calc-1/makefile
2025-01-19 18:05:13 -06:00

88 lines
1.5 KiB
Makefile

# vim: noexpandtab tabstop=4 :
buildtype ?= release
optionset = buildtypes/${buildtype}.txt
prefix = bin/${buildtype}-buildtype
default: ${prefix}/13
on_error ?= do_nothing
ifeq ($(on_error), do_nothing)
on_error_command =
else ifeq ($(on_error), open_editor)
on_error_command += || ($$EDITOR $<; false)
else
$(error "invalid on_error option!");
endif
.PRECIOUS: %/
%/:
@mkdir -p $@
srclist.mk:
find -name '*.c' -! -path '*/bin/*'-! -path '*/junk/*' | sed "s/^/srcs += /" | sort -V > ${@}
include srclist.mk
#postsrcs = $(patsubst %,bin/%.c,${srcs})
.PRECIOUS: bin/%.c.c
bin/%.c.c: %.c zog.py | bin/%/
@echo "preprocessing ${<} ..."
@python3.10 ./zog.py -i $< -o $@
${prefix}/%.o ${prefix}/%.d: bin/%.c.c ${optionset} | ${prefix}/%/
@echo "compiling (${buildtype}) ${*}.c ..."
@gcc -c @${optionset} -I $(*D) $< -MD -MF ${prefix}/${*}.d -o ${prefix}/${*}.o
# $(on_error_command)
objs = $(patsubst %.c,${prefix}/%.o,${srcs})
${prefix}/13: ${objs} ${optionset} | ${prefix}/
@echo "linking (${buildtype})"
@gcc @${optionset} ${objs} -o ${@} -lm
args += --echo
args += --color
#args += --no-init
args += --custom-init-path ./examples/init.txt
args += -c '1'
#args += ./examples/sandbox.txt
run: ${prefix}/13
$< ${args}
valrun: ${prefix}/13
valgrind --exit-on-first-error=yes --error-exitcode=1 -- $< ${args}
valrun-leak: ${prefix}/13
valgrind --exit-on-first-error=yes --error-exitcode=1 --leak-check=full -- $< ${args}
include $(patsubst %.c,${prefix}/%.d,${srcs})