Created
January 31, 2016 07:49
-
-
Save yuta-aoyagi/5cd124df4255730cceaa to your computer and use it in GitHub Desktop.
Makefile for Java projects using GNU make
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
# JavaプロジェクトのためのGNU make用Makefile | |
# usage: | |
# | |
# PROJECT_NAME = "Sample Project" | |
# MAIN_PACKAGES = org.example.proj.core org.example.proj.gui | |
# TEST_PACKAGES = org.example.proj.test | |
# JAVADOCLINKS = -link "http://docs.oracle.com/javase/jp/7/api" | |
# | |
# include some-directory/javamake.mk | |
# | |
# 上の例の変数4つは必須. | |
# 環境変数CLASSPATHにはJUnitへのパスが含まれている必要がある. | |
PATH_SEPARATOR ?= : | |
MAIN = src/main/java | |
TEST = src/test/java | |
TARGET = target | |
CP = -classpath "$(TARGET)$(PATH_SEPARATOR)$(CLASSPATH)" | |
ENCODING = -encoding UTF-8 | |
JAVAC = javac -d $(TARGET) $(ENCODING) $(JAVACFLAGS) | |
all: $(patsubst $(MAIN)/%.java, $(TARGET)/%.class, \ | |
$(foreach rel, \ | |
$(subst .,/, $(MAIN_PACKAGES)), \ | |
$(subst $(MAIN)/$(rel)/package-info.java, , \ | |
$(wildcard $(MAIN)/$(rel)/*.java)))) | |
TEST_SRCS = $(foreach rel, $(subst .,/, $(TEST_PACKAGES)), \ | |
$(wildcard $(TEST)/$(rel)/*Test.java)) | |
check: all $(patsubst $(TEST)/%.java, $(TARGET)/%.class, $(TEST_SRCS)) | |
java $(CP) org.junit.runner.JUnitCore \ | |
$(subst /,., $(patsubst $(TEST)/%.java, %, $(TEST_SRCS))) | |
javadoc: | |
javadoc -overview src/main/javadoc/overview.html \ | |
-sourcepath "$(TEST)$(PATH_SEPARATOR)$(MAIN)" $(CP) $(ENCODING) \ | |
-d $(TARGET)/apidocs -use -windowtitle $(PROJECT_NAME) \ | |
$(JAVADOCLINKS) -charset UTF-8 $(JAVADOCFLAGS) \ | |
$(MAIN_PACKAGES) $(TEST_PACKAGES) | |
$(TARGET)/%.class: $(MAIN)/%.java | |
$(JAVAC) -cp $(TARGET) -sourcepath $(MAIN) $< | |
$(TARGET)/%.class: $(TEST)/%.java | |
$(JAVAC) $(CP) -sourcepath $(TEST) $< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment