JFLAGS = -g JC = javac SRCDIR = src/main/java DESTDIR = out # Use find to locate all .java files recursively SOURCES := $(shell find $(SRCDIR) -name '*.java') RELATIVE_SOURCES := $(patsubst $(SRCDIR)/%,%,$(SOURCES)) # Convert .java files to .class files with the same directory structure CLASSES := $(patsubst $(SRCDIR)/%.java,$(DESTDIR)/%.class,$(SOURCES)) # Create a list of directories that need to be created in the destination directory DIRS := $(sort $(dir $(CLASSES))) all: @echo "$(RELATIVE_SOURCES)" default: classes # Rule for creating directories $(DIRS): @mkdir -p $@ # Rule for compiling Java files $(DESTDIR)/%.class: $(SRCDIR)/%.java | $(DIRS) $(JC) -nowarn -d $(DESTDIR) -cp "src/main/java:target/dependencies/*" $(JFLAGS) $< classes: $(CLASSES) clean: $(RM) -r $(DESTDIR)