This repository has been archived by the owner on Jul 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
129 lines (109 loc) · 4.07 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
CC ?= gcc
CXX ?= g++
CFLAGS ?= -Wall -Wextra -Werror -I$(SRCDIR) -Wconversion -g \
-Wno-unused-parameter
OBJDIR = objs
SRCDIR = src
TESTDIR = tests
CTESTDIR = ctests
BENCHDIR = bench
LDFLAGS = -lm $(shell llvm-config --libs jit core native) $(shell llvm-config --ldflags) -rdynamic
# Different flags for opt vs debug
ifeq ($(BUILD),opt)
ifeq ($(CC),clang)
CFLAGS += -O4 -DNDEBUG
else
CFLAGS += -O3 -DNDEBUG
endif
else
CFLAGS += -O1
endif
# Order matters in this list because object files listed first have their
# initializers run first, and destructors run last.
OBJS := gc.o lstring.o vm.o opcode.o util.o luav.o parse.o lhash.o debug.o \
lib/base.o lib/io.o lib/math.o lib/os.o lib/string.o error.o \
lib/coroutine.o arch.o lib/table.o llvm.o trace.o
OBJS := $(OBJS:%=$(OBJDIR)/%)
# Eventually this should be all tests, but it's a work in progres...
LUATESTS := tail factorial bool closure multipart bool2 math forint \
concat loop func fib select math2 bisect cf printf \
select smallfun nextvar os strings coroutine2 sieve \
load pcall metabasic calls noglobals fibfor readonly \
echo constructs errors len closure2 closure3 \
coroutine-gc locals pow not newtable c upvalues while \
vararg varsetlist var mult omg-fuck-you-gc small-bench \
segfault-in-compiled cache
# not passing: cor coroutine literals sort
LUATESTS := $(LUATESTS:%=$(TESTDIR)/%.lua)
BENCHTESTS := ackermann.lua-2 ary nbody nbody.lua-2 nbody.lua-4 hash fibo \
matrix nestedloop nsieve.lua-3 nsievebits random \
sieve sieve.lua-2 spectralnorm takfp threadring.lua-3 \
strcat.lua-2 recursive partialsums.lua-3 partialsums.lua-2 \
harmonic fannkuchredux fasta fannkuch \
fannkuch.lua-2 chameneos hash2 strcat lists \
objinst \
binarytrees.lua-2 binarytrees.lua-3
# not passing: prodcons message.lua-2 methcall except
BENCHTESTS := $(BENCHTESTS:%=$(BENCHDIR)/%.lua)
AVGTESTS := ackermann.lua-2 arith ary binarytrees.lua-2 binarytree.lua-3 \
chameneos fannkuch fannkuch.lua-2 fannkuchredux fib2 \
harmonic hash hash2 nbody nestedloop nsieve.lua-3 nsievebits \
partialsums.lua-2 partialsums.lua-3 random sieve recursive \
sieve.lua-2 strcat spectralnorm
AVGTESTS := $(AVGTESTS:%=$(BENCHDIR)/%.lua)
.PHONY: bench clean avg
all: joule
joule: $(OBJS) $(OBJDIR)/main.o
$(CXX) $^ $(CFLAGS) $(LDFLAGS) -o joule
# Run all lua tests
test: $(LUATESTS:=test)
@echo -- All lua tests passed --
btest: $(BENCHTESTS:=test)
@echo -- All benchmarks passed --
leaks: $(BENCHTESTS:=leak)
@echo -- All leak tests passed --
avg: joule avg.c
$(CC) -o avg avg.c
./avg ./joule $(AVGTESTS)
bench: benchmark
./benchmark $(sort $(BENCHTESTS))
benchmark: benchmark.c
$(CC) -Wall -Wextra -Werror -o $@ $<
lmissing:
@ruby -e 'puts `ls $(TESTDIR)/*.lua`.split("\n") - ARGV' $(LUATESTS)
bmissing:
@ruby -e 'puts `ls $(BENCHDIR)/*.lua`.split("\n") - ARGV' $(BENCHTESTS)
coverage: CFLAGS += --coverage
coverage: clean test
mkdir -p coverage
lcov --directory $(OBJDIR) --capture --output-file coverage/app.info -b .
genhtml --output-directory coverage coverage/app.info
@rm -f *.gcda *.gcno
# Generic targets
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: $(SRCDIR)/%.S
@mkdir -p $(@D)
$(CC) $(CFLAGS) -DASSEMBLER -c -o $@ $<
$(OBJDIR)/%.dep: $(SRCDIR)/%.c
@mkdir -p $(@D)
gcc $(CFLAGS) -MM -MT $(@:.dep=.o) -MF $@ $<
$(OBJDIR)/llvm.%: CFLAGS += $(shell llvm-config --cflags)
# Running a lua test
%.luatest: joule
@mkdir -p $(OBJDIR)/$(@D)
@echo $(@:.luatest=.lua)
@lua $(@:.luatest=.lua) > $(OBJDIR)/$(@:.luatest=.out)
@./joule $(@:.luatest=.lua) > $(OBJDIR)/$(@:.luatest=.log)
@diff -u $(OBJDIR)/$(@:.luatest=.out) $(OBJDIR)/$(@:.luatest=.log)
%.lualeak: joule
@echo $(@:.lualeak=.lua)
@grep -q coroutine $(@:.lualeak=.lua) || valgrind --error-exitcode=1 ./joule \
$(@:.lualeak=.lua)
# If we're cleaning, no need to regenerate all .dep files
ifeq (0,$(words $(filter %clean,$(MAKECMDGOALS))))
-include $(OBJS:.o=.dep)
endif
clean:
rm -rf $(OBJDIR) joule coverage benchmark