This repository was archived by the owner on Jul 12, 2023. It is now read-only.
forked from polyglot-compiler/JLang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
68 lines (53 loc) · 1.85 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
ifndef TOP_LEVEL_MAKEFILE_INVOKED
$(error Please invoke the top-level Makefile)
endif
SRC := src
OUT := out
CLASSES := $(OUT)/classes
# File indicating whether .class files have been produced.
CLS_STAMP := $(CLASSES)/cls_stamp
JAVA_SRC := $(shell find src -name "*.java")
JAVA_CLS := $(JAVA_SRC:$(SRC)/%.java=$(CLASSES)/%.class)
JAVA_LL := $(JAVA_SRC:$(SRC)/%.java=$(OUT)/%.ll)
JAVA_OBJ := $(JAVA_LL:%.ll=%.o)
NATIVE_SRC := $(shell find native -name "*.cpp")
NATIVE_OBJ := $(NATIVE_SRC:%.cpp=$(OUT)/%.o)
ALL_OBJ := $(JAVA_OBJ) $(NATIVE_OBJ)
PLC_FLAGS := -assert
ifdef DBUG
DEBUG_FLAGS := -dump-desugared
endif
JAVA_FLAGS := -g -Wno-override-module -fPIC
NATIVE_FLAGS := -g -std=c++14 $(JNI_INCLUDES) -fPIC -Wall -pthread
all: classes $(LIBJDK)
.PHONY: classes
classes: $(CLS_STAMP)
# Runtime Java code (.java --> .class)
$(CLS_STAMP): $(JAVA_SRC)
@echo "Compiling $(words $(JAVA_SRC)) Java files with javac (.java --> .class)"
@mkdir -p $(CLASSES)
@$(JAVAC) -d $(CLASSES) $(JAVA_SRC)
@date > $@
# Compile JDK Java code (.java --> .ll)
$(JAVA_LL): $(JAVA_SRC) $(PLC_SRC)
@echo "Compiling $(words $(JAVA_SRC)) Java files with JLang (.java --> .ll)"
@# We compile java.lang.Object separately, since otherwise
@# we get duplicate class errors from Polyglot. (TODO)
@$(PLC) -c -d $(OUT) $(DEBUG_FLAGS) $(filter %Object.java,$(JAVA_SRC)) > dump.txt
@$(PLC) -c -d $(OUT) $(DEBUG_FLAGS) $(filter-out %Object.java,$(JAVA_SRC)) >> dump.txt
# Compile LLVM IR (.ll --> .o).
$(JAVA_OBJ): %.o: %.ll
@echo "Compiling $<"
@$(CLANG) $(JAVA_FLAGS) -c -o $@ $<
# Native code (.cpp --> .o).
$(NATIVE_OBJ): $(OUT)/%.o: %.cpp
@mkdir -p $(dir $@)
@echo "Compiling $<"
@$(CLANG) $(NATIVE_FLAGS) -c -o $@ $<
# Create a shared library for compiled JDK classes.
$(LIBJDK): $(ALL_OBJ)
@echo "Creating libjdk"
@$(CLANG) $(LIBJVM) $(LIBJDK_FLAGS) -o $@ $^
clean:
rm -rf $(OUT)
.PHONY: all clean