-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (71 loc) · 2.64 KB
/
Copy pathMakefile
File metadata and controls
91 lines (71 loc) · 2.64 KB
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
### This is a makefile for compiling the Java project ColorFall ###
# Dependencies
LIB_GT := game-template
LIB_GT_DIR := ../$(LIB_GT)
include $(LIB_GT_DIR)/common.mk
### Helper functions ###
# Run a command in the $(LIB_GT) directory
run_lib_gt = (cd $(LIB_GT_DIR) && $1)
### Configuration for sources file and compilation artefacts ###
# The name of the project
PROJECT_NAME = ColorFall
# The name of the jar file to create
JAR_FILE := $(PROJECT_NAME).jar
# The name of the script which will run the jar
RUN_SCRIPT = $(PROJECT_NAME).$(SCRIPT_EXTENSION)
# The class containing `public static void main(String[] args)`
MAIN_CLASS := cf.main.ColorFallMain
# Resource files such as fonts
RESOURCE_DIR := res
RESOURCE_FILES := $(call filter_findall,$(RESOURCE_DIR))
# Dependencies
LIB_GT_JAR := $(LIB_GT_DIR)/$(LIB_GT).jar
LIB_GT_SOURCE_DIR := ../$(LIB_GT)/$(SOURCE_DIR)
LIB_GT_CLASS_DIR := ../$(LIB_GT)/$(CLASS_DIR)
LIB_GT_SOURCE_FILES := $(call filter_find,$(LIB_GT_SOURCE_DIR),.java)
### Rules ###
# Define phony targets
.PHONY: all clean cleanall
### Default rule ###
.DEFAULT_GOAL := all
all: $(RUN_SCRIPT)
### Create game-template.jar ###
$(LIB_GT_JAR) : $(LIB_GT_SOURCE_FILES)
$(call run_lib_gt,make)
### Compile `.java` files to `.class` files ###
# -cp - Specify classpath
# -d - Set output directory
# -g - Generate debugging information
JAVACFLAGS := \
-cp "$(SOURCE_DIR)$(CP_SEPARATOR)$(LIB_GT_JAR)" \
-d $(CLASS_DIR) \
-g:none
# javac [ options ] [ sourcefiles ] [ classes ] [ @argfiles ]
$(CLASS_DIR)/%.class: $(SOURCE_DIR)/%.java | $(LIB_GT_JAR) $(CLASS_DIR)
$(JAVAC) $(JAVACFLAGS) $<
### Copy `.class` files to the `.jar` archive ###
# c - Create a new archive
# u - Update an existing archive
# e - Set the application entry point
# f - Specify the file name
# v - Verbose output
JARFLAGS := cef
JARUPDATEFLAGS := uf
# jar c[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]
# jar u[efmMnv0] [entrypoint] [jarfile] [manifest] [-C dir] file ... [-Joption ...] [@arg-file ...]
$(JAR_FILE): $(LIB_GT_JAR) $(CLASS_FILES) $(RESOURCE_FILES)
$(JAR) $(JARFLAGS) $(MAIN_CLASS) $@ -C $(CLASS_DIR) . -C $(LIB_GT_CLASS_DIR) .
$(JAR) $(JARUPDATEFLAGS) $@ -C $(RESOURCE_DIR) .
### Create a script to run the jar ###
# java [options] -jar filename [args]
$(RUN_SCRIPT): $(JAR_FILE)
@echo $(JAVA) -jar $< > $@
chmod 775 $@
### Remove the jar archive, the run script, and the class files ###
clean:
$(call run_lib_gt,make clean)
$(RM) $(JAR_FILE) $(RUN_SCRIPT) $(CLASS_FILES)
### Remove the jar archive, the run script, and the bin directory ###
cleanall:
$(call run_lib_gt,make cleanall)
$(RM) $(JAR_FILE) $(RUN_SCRIPT) $(CLASS_DIR)