Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
Latest commit
59 lines (49 loc) · 1.66 KB
/
Copy pathMakefile
File metadata and controls
59 lines (49 loc) · 1.66 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
.PHONY: help clean compile package run run-jar
SRC_DIR := src
LIB_DIR := lib
CLS_DIR := bin
DES_DIR := dist
MAIN_CLASS := $(shell \
MAIN_FILE=$$(grep -rl "public class Main" $(SRC_DIR) | head -n1); \
if [ -z "$$MAIN_FILE" ]; then \
echo "[ERROR] Main.java not found" >&2; exit 1; \
fi; \
PKG=$$(grep "package " "$$MAIN_FILE" | awk '{print $$2}' | tr -d ';'); \
if [ -n "$$PKG" ]; then \
echo "$${PKG}.Main"; \
else \
echo "Main"; \
fi \
)
defineCHECK_DEPENDENCY
@for cmd in $(1); do \
if ! command -v $$cmd &>/dev/null; then \
echo "[ERROR] Couldn't find $$cmd!"; \
exit 1; \
fi; \
done
endef
.deps:
$(call CHECK_DEPENDENCY, java javac jar)
help: ## show this help message
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$'$(MAKEFILE_LIST)| awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s - %s\n", $$1, $$2}'
clean: ## clean build artifacts
@rm -rf $(CLS_DIR)$(DES_DIR)
@echo "[INFO] Cleaned build artifacts.";
compile: .deps ## compile app
@if [ -d"$(LIB_DIR)" ] && [ "$$(ls -A $(LIB_DIR))" ];then\
javac -d $(CLS_DIR) -cp "$(LIB_DIR)/*"$$(find $(SRC_DIR) -name "*.java");\
else\
javac -d $(CLS_DIR)$$(find $(SRC_DIR) -name "*.java");\
fi
@echo "[INFO] Compiled source files into '$(CLS_DIR)'."
package: compile ## package app into JAR
@jar --create --file $(DES_DIR)/app.jar --main-class=$(MAIN_CLASS) -C $(CLS_DIR).
@echo "[INFO] Packaged application into '$(DES_DIR)/app.jar'."
run: compile ## run the compiled app
@echo "[INFO] Running application..."
@java -cp "$(CLS_DIR):$(LIB_DIR)/*"$(MAIN_CLASS)
run-jar: package ## run the app JAR
@echo "[INFO] Running '$(DES_DIR)/app.jar'..."
@java -jar $(DES_DIR)/app.jar