Last active
March 29, 2020 23:10
-
-
Save callemo/49b84e81005645b5fad22c8ee00a7690 to your computer and use it in GitHub Desktop.
Makefile for java projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
artifactId = a | |
directory = build | |
outputDirectory = $(directory)/classes/java/main | |
sourceDirectory = src/main/java | |
sources = $(shell find $(sourceDirectory) -name \*.java) | |
objects = $(sources:$(sourceDirectory)/%.java=$(outputDirectory)/%.class) | |
package = $(directory)/libs/$(artifactId).jar | |
JAR = jar | |
JAR_FLAGS = cvf | |
JAVA = java | |
JAVAC = javac | |
JAVAC_FLAGS = -g | |
COMPILE.java = $(JAVAC) -d $(outputDirectory) $(JAVAC_FLAGS) | |
.PHONY: all clean | |
all: $(package) | |
$(package): $(objects) | |
$(objects): $(outputDirectory)/%.class: $(sourceDirectory)/%.java | |
$(COMPILE.java) $< | |
%.jar: | |
mkdir -p `dirname $@` | |
$(JAR) $(JAR_FLAGS) $@ -C $(outputDirectory) $(^:$(outputDirectory)/%=%) | |
clean: | |
$(RM) -r $(directory) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment