uxncpp/Makefile
2025-02-22 17:40:06 +05:00

32 lines
898 B
Makefile

.SUFFIXES: .cc .bc
CLANG ?= clang
LLVM_CBE ?= llvm-cbe
LLVM ?= llvm
UXNASM ?= uxnasm
SED ?= sed
OPT ?= opt
CHIBICC_UXN ?= uxn-chibicc
SRCS = src/main.cc
.cc.bc:
$(CLANG) -Os $< -o $*.bc -emit-llvm -c --target=avr -Wno-avr-rtlib-linking-quirks -std=c++20
result.rom: $(SRCS:.cc=.bc) symbols.bc
mkdir -p tmp/
$(LLVM)-link $(SRCS:.cc=.bc) -o tmp/unopt.bc
$(OPT) -Os tmp/unopt.bc -o tmp/unclean.bc
$(LLVM)-link --only-needed symbols.bc tmp/unclean.bc -o tmp/linked.bc
$(LLVM_CBE) -O2 tmp/linked.bc -o tmp/linked.cbe.c
$(CLANG) -x c -P -E -include ./on_link.h tmp/linked.cbe.c -o tmp/linked.i
$(CHIBICC_UXN) -O tmp/linked.i > tmp/linked.tal
$(SED) -e 's/;_/;U_/g' -e 's/@_/@U_/g' -e 's/ _/ U_/g' -e '/\( bss \)/,/\( data \)/d' tmp/linked.tal > tmp/result.tal
$(UXNASM) tmp/result.tal result.rom
all: result.rom
clean:
rm -rf src/main.bc $(SRCS:.cc=.bc) tmp/ result.rom result.rom.sym