-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (102 loc) · 3.52 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
MAKEFLAGS += --warn-undefined-variables
# C/C++ compiler
CC = gcc
# Compiler and linker flags (warning levels, optimisation level,
# include debugging symbols, add include search path, add library search path)
CFLAGS = -Wall -std=gnu11
LDFLAGS = -L./src/libs
# Object files
#OBJS = obj1.o obj2.o obj3.o
# Executable name
srcdir=src
objdir=build
testdir=test
sources := $(wildcard $(srcdir)/*.c)
headers := $(wildcard $(srcdir)/*.h)
objects := $(patsubst $(srcdir)/%.c,$(objdir)/%.o,$(sources))
main_objs := $(filter %main.o, $(objects))
shared_objs := $(filter-out %main.o, $(objects))
bins := $(patsubst $(objdir)/%_main.o, %, $(main_objs))
.PHONY: all
all: $(bins)
.PHONY: debug_make
debug_make:
@echo $(shared_objs)
@echo $(bins)
$(bins): %:$(objdir)/%_main.o $(shared_objs)
$(CC) $(CFLAGS) $^ -o $@
$(objects): $(headers)
$(objdir)/%.o: $(srcdir)/%.c
@[ -d $(objdir) ] || mkdir $(objdir)
$(CC) $(CFLAGS) -c -o $(objdir)/$*.o $<
.PHONY: tower
tower: asm2.bin
asm2.bin: asm/asm2.asm1 asm1.bin
./sleqrun asm1.bin <$< >$@
asm1.bin: asm/asm1.asm1 asm1_bs.bin
./sleqrun asm1_bs.bin <$< >$@
asm1_bs.bin: asm/asm1.hex3 hex3.bin
./sleqrun hex3.bin <$< >$@
hex3.bin: asm/hex3.hex3 hex3_bs.bin
./sleqrun hex3_bs.bin <$< >$@
hex3_bs.bin: asm/hex3.hex2 hex2.bin
./sleqrun hex2.bin <$< >$@
hex2.bin: asm/hex2.hex2 hex2_bs.bin
./sleqrun hex2_bs.bin <$< >$@
hex2_bs.bin: asm/hex2.hex1 hex1.bin sleqrun
./sleqrun hex1.bin <$< >$@
hex1.bin: asm/hex1.hex1 hex1
./hex1 <$< >$@
# ===== Forth?
sforth_knl.bin: asm/sforth.asm2 asm2.bin
./sleqrun asm2.bin <$< >$@
# Interactively load sforth1
sforth1: fth/sforth1.fth sforth_knl.bin
@# cat: load the .fth source, then continue with stdin
@# tail: discard the first line so we're not silent/compiling
@# (need to force it line-buffered to prevent hangup)
@# stdbuf: more trying to keep it from buffering
cat $< - | stdbuf -oL tail -n+2 | stdbuf -i0 -o0 -e0 ./sleqrun sforth_knl.bin
.PHONY: sforth1
sforth1.bin: fth/sforth1.fth sforth_knl.bin
./sleqrun sforth_knl.bin <$< >$@
sforth: sforth1.bin
./sleqrun $<
.PHONY: sforth
sforth2: fth/sforth2.fth sforth1.bin
@#cat $< - | stdbuf -oL tail -n+2 | stdbuf -i0 -o0 -e0 ./sleqrun sforth1.bin
cat $< - | stdbuf -i0 -o0 -e0 ./sleqrun sforth1.bin
.PHONY: sforth2
#sforth.bin: asm/sforth.fth sforth_core.bin
# ========== TESTS
.PHONY: test
test: test_asm2_bin test_asm1_bin test_too_many_labels test_duplicate_labels
# Tests "quoted strings" by compiling hello.asm2
.PHONY: test_asm2_bin
test_asm2_bin: asm2.bin sleqrun
@./sleqrun $< <asm/hello.asm2 >$(testdir)/hello_asm2_bin.out 2>/dev/null
@diff -q $(testdir)/hello_asm2_bin.out $(testdir)/hello_asm2_bin.expected || \
echo "Test $@ failed"
.PHONY: test_asm1_bin
test_asm1_bin: asm1.bin sleqrun
@./sleqrun asm1.bin <asm/hello.asm1 >$(testdir)/hello_asm1_bin.out 2>/dev/null
@diff -q $(testdir)/hello_asm1_bin.out $(testdir)/hello_asm1_bin.expected || \
echo "Test $@ failed"
.PHONY: test_too_many_labels
test_too_many_labels: $(testdir)/test_too_many_labels.asm1 asm1.bin
@./sleqrun asm1.bin <$< 2>/dev/null >/dev/null ; exit_code="$$?"; \
if [ $$exit_code -ne 5 ]; then \
echo "Test $@ failed, expected to halt with code 5"; \
fi
.PHONY: test_duplicate_labels
test_duplicate_labels: $(testdir)/test_duplicate_labels.asm1 asm1.bin
@./sleqrun asm1.bin <$< 2>/dev/null >/dev/null ; exit_code="$$?"; \
if [ $$exit_code -ne 6 ]; then \
echo "Test $@ failed, expected to halt with code 6"; \
fi
.PHONY: clean
clean:
rm -f $(objdir)/*
rm -f $(bins)
rm -f *.bin
rm -f $(testdir)/*.out