-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
50 lines (38 loc) · 1.14 KB
/
Makefile
File metadata and controls
50 lines (38 loc) · 1.14 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
###################################
# Makefile for Java Projects #
# ------------------------------- #
# Usage:
#
# make - Compile the project
# make setup - Create src and classes directories if they don't exist
# make run - Run the main class
# make clean - Clean compiled files
# ------------------------------- #
# Directories
SRC_DIR := src
BIN_DIR := classes
# Find all .java files in src/ (recursively)
SOURCES := $(shell find $(SRC_DIR) -name "*.java")
CLASSES := $(SOURCES:$(SRC_DIR)/%.java=$(BIN_DIR)/%.class)
# Main class (change according to your project)
MAIN_CLASS := Main
# Rule to create the BIN_DIR folder if it doesn't exist
$(BIN_DIR):
mkdir -p $(BIN_DIR)
# Default rule: compile everything
all: $(BIN_DIR) $(CLASSES)
# make a src directory if it doesn't exist
setup: $(BIN_DIR)
mkdir -p $(SRC_DIR)
# Create any other necessary directories here
touch $(SRC_DIR)/$(MAIN_CLASS).java
# Compilation
$(BIN_DIR)/%.class: $(SRC_DIR)/%.java
mkdir -p $(dir $@)
javac -d $(BIN_DIR) -cp $(SRC_DIR) $(SOURCES)
# Run the program
run: all
java -cp $(BIN_DIR) $(MAIN_CLASS)
# Cleaning
clean:
rm -rf $(BIN_DIR)