forked from mukel/llama2.java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (59 loc) · 2.06 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
ifdef JAVA_HOME
JAVAC ?= ${JAVA_HOME}/bin/javac
JAVA ?= ${JAVA_HOME}/bin/java
JAR ?= ${JAVA_HOME}/bin/jar
NATIVE_IMAGE ?= ${JAVA_HOME}/bin/native-image
endif
JAVAC ?= javac
JAVA ?= java
JAR ?= jar
NATIVE_IMAGE ?= native-image
JAVA_COMPILE_OPTIONS = --enable-preview -source 20 -g
JAVA_RUNTIME_OPTIONS += --enable-preview
NATIVE_IMAGE_OPTIONS += --enable-preview
JAVA_MAIN_CLASS = Llama2
JAR_FILE = llama2.jar
JAVA_SOURCES = $(wildcard *.java)
JAVA_CLASSES = $(patsubst %.java, target/classes/%.class, $(JAVA_SOURCES))
# Bundle all classes in a jar
$(JAR_FILE): $(JAVA_CLASSES) target/META-INF/MANIFEST.MF
$(JAR) -cvfm $(JAR_FILE) target/META-INF/MANIFEST.MF -C target/classes .
jar: $(JAR_FILE)
# Compile the Java source files
compile: $(JAVA_CLASSES)
$(info Java source files: $(JAVA_SOURCES))
$(info Java .class files: $(JAVA_CLASSES))
# Prints the command to run the Java main class
run-command:
@echo $(JAVA) $(JAVA_RUNTIME_OPTIONS) -cp target/classes $(JAVA_MAIN_CLASS)
# Prints the command to run the $(JAR_FILE)
run-jar-command:
@echo $(JAVA) $(JAVA_RUNTIME_OPTIONS) -jar $(JAR_FILE)
# Clean the target directory
clean:
rm -rf target
rm $(JAR_FILE)
rm default.iprof
rm llama2
# Creates the manifest for the .jar file
target/META-INF/MANIFEST.MF:
mkdir -p target/META-INF
@echo "Manifest-Version: 1.0" > target/META-INF/MANIFEST.MF
@echo "Class-Path: ." >> target/META-INF/MANIFEST.MF
@echo "Main-Class: $(JAVA_MAIN_CLASS)" >> target/META-INF/MANIFEST.MF
@echo "" >> target/META-INF/MANIFEST.MF
# Create a standalone executable of the llama2.jar using GraalVM
native-image: $(JAR_FILE)
$(NATIVE_IMAGE) $(NATIVE_IMAGE_OPTIONS) -jar $(JAR_FILE)
# Compile the Java source files
target/classes/%.class: %.java
$(JAVAC) $(JAVA_COMPILE_OPTIONS) -d target/classes $<
# Create the target directory
target/classes:
mkdir -p target/classes
# Make the target directory a dependency of the Java class files
$(JAVA_CLASSES): target/classes
compile: target/classes
default: target/classes
.PHONY: compile clean jar run-command run-jar-command
.SUFFIXES: .java .class .jar .MF