-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathMakefile
96 lines (79 loc) · 1.8 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
CC ?= gcc
CFLAGS = -std=c99 -Os -Wall -Wextra
BIN = jvm
OBJS = \
jvm.o \
stack.o \
constant-pool.o \
classfile.o \
class-heap.o \
object-heap.o
deps := $(OBJS:%.o=.%.o.d)
include mk/common.mk
include mk/jdk.mk
# Build PitifulVM
all: $(BIN)
$(BIN): $(OBJS)
$(VECHO) " CC+LD\t$@\n"
$(Q)$(CC) -o $@ $^
%.o: %.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) $(CFLAGS) -c -MMD -MF [email protected] $<
TESTS = \
Factorial \
Return \
Constants \
MoreLocals \
PrintLargeNumbers \
Collatz \
PythagoreanTriplet \
Arithmetic \
CoinSums \
DigitPermutations \
FunctionCall \
Goldbach \
IntegerTypes \
Jumps \
PalindromeProduct \
Primes \
Recursion \
Long \
Caller \
Constructor \
Field \
Static \
Invokevirtual \
Inherit \
Initializer \
Strings \
Array
check: $(addprefix tests/,$(TESTS:=-result.out))
ifneq (, $(shell which valgrind))
leak: $(addprefix tests/,$(TESTS:=-leak.out))
endif
tests/%.class: tests/%.java
$(Q)$(JAVAC) $^
tests/%-expected.out: tests/%.class
$(Q)$(JAVA) -cp tests $(*F) > $@
tests/%-actual.out: tests/%.class $(BIN)
$(Q)./$(BIN) $< > $@
tests/%-result.out: tests/%-expected.out tests/%-actual.out
$(Q)diff -u $^ | tee $@; \
name='test $(@F:-result.out=)'; \
$(PRINTF) "Running $$name..."; \
if [ -s $@ ]; then $(PRINTF) FAILED $$name. Aborting.; false; \
else $(call pass); fi
tests/%-leak.out: tests/%.class $(BIN)
$(Q)valgrind ./$(BIN) $< > $@ 2>&1; \
name='test $(@F:-leak.out=)'; \
$(PRINTF) "Running $$name..."; \
if grep -q 'All heap blocks were freed' $@; \
then $(call pass); \
else $(PRINTF) FAILED $$name. Aborting.; false; fi
clean:
$(Q)$(RM) $(OBJS) $(deps) *~ $(BIN) tests/*.out tests/*.class $(REDIR)
.PRECIOUS: %.o tests/%.class tests/%-expected.out tests/%-actual.out tests/%-result.out tests/%-leak.out
indent:
clang-format -i *.[ch]
cloc *.[ch]
-include $(deps)