-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
51 lines (41 loc) · 1.86 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
OBJS = $(patsubst src/%.c, obj/%.o, $(wildcard src/*.c))
TESTS = $(patsubst test/%.c, bin/%, $(wildcard test/*.c))
LIB = lib/libvm.so
LIB_NAME = vm
COMPILER = BytecodeCompiler.jar
COMPILER_FOLDER = bytecode_compiler
COMPILER_SRCS = $(wildcard $(COMPILER_FOLDER)/src/*.java)
COMPILER_CLASS_FILES = $(patsubst $(COMPILER_FOLDER)/src/%.java, $(COMPILER_FOLDER)/class/%.class, $(COMPILER_SRCS))
COMPILER_CLASSES = $(patsubst $(COMPILER_FOLDER)/src/%.java, $(COMPILER_FOLDER)/class/%, $(COMPILER_SRCS))
$(LIB): $(OBJS)
gcc -shared -o $@ $^
.PHONY: run
run: build_test compiler
@echo "[Compiling...]"
@java -jar bytecode_compiler/BytecodeCompiler.jar bytecode_compiler/test/bytecode2.bc bytecode_compiler/test/bytecode2.bcc
@echo "[Running...]"
@bin/vm_test bytecode_compiler/test/bytecode2.bcc
.PHONY: compile
compile: compiler
@echo "[Compiling...]"
@java -jar bytecode_compiler/BytecodeCompiler.jar bytecode_compiler/test/bytecode2.bc bytecode_compiler/test/bytecode2.bcc
.PHONY: build_test
build_test: $(TESTS)
@export LD_LIBRARY_PATH=$(pwd)/lib
.PHONY: compiler
compiler: $(COMPILER_FOLDER)/$(COMPILER)
bin/%: test/%.c $(LIB)
@gcc -o $@ $< -Iinclude/ -Llib/ -l$(LIB_NAME)
obj/%.o: src/%.c
@gcc -fPIC -c -o $@ $< -I include/
$(COMPILER_FOLDER)/$(COMPILER): $(COMPILER_CLASS_FILES)
@echo "[Building compiler...]"
@echo "Main-Class: BytecodeCompiler" > $(COMPILER_FOLDER)/manifest.txt
@echo "Class-Path: class/" >> $(COMPILER_FOLDER)/manifest.txt
@jar -cvfm $(COMPILER_FOLDER)/$(COMPILER) $(COMPILER_FOLDER)/manifest.txt $(COMPILER_FOLDER)/class/*.class 1>/dev/null
$(COMPILER_FOLDER)/class/%.class: $(COMPILER_FOLDER)/src/%.java
@javac -d $(COMPILER_FOLDER)/class -classpath $(COMPILER_FOLDER)/src $<
.PHONY: clean
clean:
@echo "[Cleaning...]"
@rm $(OBJS) $(LIB) $(TESTS) $(COMPILER_FOLDER)/$(COMPILER) $(COMPILER_CLASS_FILES) $(COMPILER_FOLDER)/manifest.txt 2>/dev/null || true