-# Note: this are my paths to cc65 as there is no gentoo ebuild, sorry for that.
-# Please use the path below if you've installed cc65 system-wide
-CC=~/customSoftware/cc65-2.11.0/src/cc65/cc65 -I ~/customSoftware/cc65-2.11.0/include
-CA=~/customSoftware/cc65-2.11.0/src/ca65/ca65
-CL=~/customSoftware/cc65-2.11.0/src/cl65/cl65
-# CC=cc65
-# CA=ca65
-# CL=cl65
-
-src/%.o: src/%.c include/%.h
- ${CC} -I include -t c128 $<
- ${CA} -I include -t c128 src/$$(basename $< .c).s
-
-all: src/config.o src/kasse.o src/general.o src/credit_manager.o src/time.o
- # See above, please just kill the PATH-definition
- cp /tmp/cc65/lib/c128* .
- PATH=${PATH}:~/customSoftware/cc65-2.11.0/src/ld65:/tmp/cc65/lib ${CL} -t c128 -O src/*.o -o kasse
+CC=cc65
+AS=ca65
+LD=cl65
+INCLUDES:=$(wildcard include/*.h) include/version.h include/charset_umlauts.h
+GV:=$(shell git describe --tags --always)
+CFLAGS= -I include -t c128 -g
+
+.PHONY: include/version.h include/charset_umlauts.h clean dist-clean format
+
+all: kasse itemz cat
+
+build/%.o: src/%.c ${INCLUDES}
+ ${CC} ${CFLAGS} -O $< -o build/$(addsuffix .s,$(shell basename $< .c))
+ ${AS} ${CFLAGS} build/$(addsuffix .s,$(shell basename $< .c)) -o $@
+
+build/%.o: src/%.s
+ ${AS} ${CFLAGS} $< -o $@
+
+include/version.h:
+ mkdir -p build
+ echo "#define GV \"${GV}\"" > $@
+
+include/charset_umlauts.h:
+ ./util/mkfont assets/umlauts.pbm chars_umlauts > $@
+
+kasse: build/config.o build/kasse.o build/general.o build/credit_manager.o build/c128time.o build/print.o build/vdc_patch_charset.o build/vdc_util.o build/globals.o
+ ${LD} -Ln $@.lbl -t c128 $^ -o $@
+
+itemz: build/config.o build/itemz.o build/general.o build/credit_manager.o build/c128time.o build/print.o build/globals.o
+ ${LD} -Ln $@.lbl -t c128 $^ -o $@
+
+cat: build/general.o build/cat.o
+ ${LD} -Ln $@.lbl -t c128 $^ -o $@
+
+charmap: build/print_charmap.o build/vdc_util.o build/vdc_patch_charset.o
+ ${LD} -Ln $@.lbl -t c128 $^ -o $@
+
+ascii: build/print_ascii.o
+ ${LD} -Ln $@.lbl -t c128 $^ -o $@