-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathMakefile
95 lines (73 loc) · 2.47 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
# `make all` creates solution files, llvm ir, and output files. Add the -k flag
# to make all targets regardless of errors.
# `make <file>` to produce any individual generated file, such as .ll (LLVM IR),
# .binary (executable), etc.
# `make sol` to generate solution (.sol) files.
# `make ir` to compile all programs down to LLVM IR (.ll) files.
# `make output` to compile LLVM IR to executable files and produce program
# output (.output) files.
# Uses absolute paths to llvm commands, because Java's ProcessBuilder will
# otherwise not be able to find them.
BASE_DIR := ../..
RUNTIME := $(BASE_DIR)/runtime
ifndef TOP_LEVEL_MAKEFILE_INVOKED
JDK ?= jdk-lite
JDK := $(realpath $(BASE_DIR)/$(JDK))
JDK_CLASSES := $(realpath $(JDK)/out/classes)
JDK7 ?= /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
JDK7_LIB_PATH := $(JDK7)/jre/lib
endif
SRC := $(shell find * -name "*.java")
CLASSES := $(SRC:.java=.class)
SOL := $(SRC:.java=.sol)
LL := $(SRC:.java=.ll)
BINARY := $(SRC:.java=.binary)
OUTPUT := $(SRC:.java=.output)
ifndef CLANG
CLANG := clang++
endif
CLANG_FLAGS := \
-Wno-override-module -lgc -g \
-L$(RUNTIME)/out -ljvm \
-L$(JDK)/out -ljdk \
-Wl,-rpath,$(JDK7_LIB_PATH) \
-Wl,-rpath,$(JDK)/out -Wl,-rpath,$(RUNTIME)/out \
-rdynamic
all: check
check: sol output
@echo "******** CHECKING CORRECTNESS *********"
@./checkDiffs.sh $(realpath expected_fails)
sol: $(SOL)
ir: $(LL)
ll: $(LL)
binary: $(BINARY)
output: $(OUTPUT)
# Compiling Java with a Makefile is never ideal, but this is sufficient.
# Recall that $? expands to all dependencies newer than the target.
$(SOL): $(SRC)
@echo "Compiling $(words $?) test(s) with javac"
@javac $?
@echo "Generating solutions for $(words $?) test(s)"
@for f in $?; do \
java -ea -cp . $(subst /,.,$${f%.java}) > $${f%.java}.sol; \
done
@touch $(SOL)
$(LL): $(SRC)
@echo "Compiling $(words $?) Java file(s) down to LLVM IR"
@$(BASE_DIR)/bin/jlangc -cp $(JDK_CLASSES) -assert $?
@touch $(LL)
%.ll: %.java
@echo "Compiling file to LLVM IR"
@$(BASE_DIR)/bin/jlangc -cp $(JDK_CLASSES) -assert $?
%.binary: %.ll
@echo "Creating binary for $<"
@$(CLANG) $(CLANG_FLAGS) -o $@ $<
%.output: %.binary phony
@echo "Generating output for $*"
@JAVA_HOME=$(JDK7) bash -c './$<' | tee >/dev/null $@
%.debug: %.binary phony
@JAVA_HOME=$(JDK7) bash -c 'gdb $<'
clean: phony
@echo "Removing files generated for Unit Tests"
@rm -rf *.dSYM *.sol *.ll *.binary *.output *.class check
.PHONY: phony