-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
55 lines (44 loc) · 1.53 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
BUILDDIR = build
WENDDIR = test-programs
TESTS = $(shell find $(WENDDIR) -name '*.wend' -not -path '*/gfx/*')
GFXDIR = $(WENDDIR)/gfx
GFXASM = $(patsubst $(GFXDIR)/%.wend, $(BUILDDIR)/%.s, $(wildcard $(GFXDIR)/*.wend))
GFXOBJ = $(patsubst $(GFXDIR)/%.wend, $(BUILDDIR)/%.o, $(wildcard $(GFXDIR)/*.wend))
GFXEXE = $(patsubst $(GFXDIR)/%.wend, $(BUILDDIR)/%.exe, $(wildcard $(GFXDIR)/*.wend))
.PHONY: all test clean
all: test gfx
$(BUILDDIR):
@mkdir -p $(BUILDDIR)
test: $(BUILDDIR)
@for WEND in $(TESTS) ; do \
SRCDIR=$$(dirname $$WEND) ; \
DSTDIR=$$(dirname $$WEND | sed s/$(WENDDIR)/$(BUILDDIR)/) ; \
mkdir -p $$DSTDIR ; \
echo -n Testing $$WEND... ;\
EXP=$$(echo $$WEND|sed s/\.wend/\.expected/) ; \
ASM=$$DSTDIR/$$(basename $$WEND|sed s/\.wend/\.s/) ; \
OBJ=$$DSTDIR/$$(basename $$WEND|sed s/\.wend/\.o/) ; \
ELF=$$DSTDIR/$$(basename $$WEND|sed s/\.wend//) ; \
python3 compiler.py $$WEND > $$ASM ; \
as --march=i386 --32 -gstabs -o $$OBJ $$ASM ; \
ld -m elf_i386 $$OBJ -o $$ELF ; \
$$ELF | diff $$EXP - ; \
echo ' ok' ; \
done
$(BUILDDIR)/%.exe: $(BUILDDIR)/%.o
ld -m elf_i386 $< -o $@
$(BUILDDIR)/%.o: $(BUILDDIR)/%.s
as --march=i386 --32 -o $@ $<
$(BUILDDIR)/%.s: $(GFXDIR)/%.wend
python3 compiler.py $< > $@
gfx: $(BUILDDIR) $(GFXASM) $(GFXOBJ) $(GFXEXE)
clean:
rm -rf $(BUILDDIR)
find . -type f -name *.pyc -delete
find . -type d -name __pycache__ -delete