-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
149 lines (119 loc) · 4.03 KB
/
Makefile
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
APPNAME=Stork
VERSION=3.0a
PROJECT=stork
CMDS=info ls q raw rm server status submit user cred
JARFILE=$(LIB)/$(PROJECT)-$(VERSION).jar
CLASSPATH=$(call classpathify,$(LIBJARS)):$(BUILD)
DBGFLAG=-g
JMEM=-J-Xmx512m
JFLAGS=$(DBGFLAG) $(JMEM) -classpath $(CLASSPATH)
JCFLAGS=$(JFLAGS) $(DBGFLAG) -sourcepath $(PROJECT) -nowarn
# Commands
JAVA=java
JC=javac
JAR=jar
JAVADOC=javadoc
LN=ln
# Directories
BIN=bin
BUILD=build
DOC=doc
LIB=lib
# Installation locations.
INSTALLDIR=/usr/share/$(PROJECT)
BINDIR=/usr/local/bin
.PHONY: all install classes clean discover fetchdeps pkglist \
$(PROJECT)_cmds doc help buildtest install
.SUFFIXES: .java .class
# Recursive wildcard function from jgc.org.
rwildcard=$(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2) \
$(filter $(subst *,%,$2),$d))
rdirs=$1 $(patsubst %/.,%,$(wildcard $(addsuffix /.,$(call rwildcard,$1,*))))
# Used to join space-delimited lists with a string.
empty:=
space:=$(empty) $(empty)
classpathify=$(subst $(space),:,$(strip $1))
JAVASRCS=$(call rwildcard,$(PROJECT),*.java)
JAVASRCS:=$(patsubst %/package-info.java,,$(JAVASRCS))
CLASSES=$(JAVASRCS:%.java=$(BUILD)/%.class)
#CLASSNAMES=$(subst /,.,$(JAVASRCS:%.java=%))
LIBJARS=$(call rwildcard,lib,*.jar)
BUILDLIST= # Generated by "build/%.class" rule.
JC_CMD= # Set only if we need to compile something.
# Legacy underscore-named bins.
LEGACY_CMDS=$(patsubst %,bin/$(PROJECT)_%,$(CMDS))
all: $(JARFILE) $(LEGACY_CMDS) | $(BUILD)
$(BUILD):
@mkdir -p $(BUILD)
$(JARFILE): classes $(BUILD)/build_tag
@echo Generating $(JARFILE)...
@$(JAR) $(JMEM) cf $(JARFILE) -C $(BUILD) .
# Find changed classes and fill BUILDLIST.
discover: $(CLASSES)
# If the source has changed, add the class to BUILDLIST.
$(BUILD)/%.class: %.java | $(BUILD)
@echo Including for build: $<
$(eval BUILDLIST += $<)
$(eval JC_CMD=$(JC) $(JFLAGS) -d $(BUILD))
# Build everything in BUILDLIST.
classes: fetchdeps discover $(BUILDLIST)
@echo Building $(words $(BUILDLIST)) files...
@$(JC_CMD) $(BUILDLIST)
bin/$(PROJECT)_%: bin/$(PROJECT)
@$(LN) -s -f $(PROJECT) $@
fetchdeps:
@$(MAKE) -j4 --no-print-directory -C lib
$(BUILD)/build_tag: | $(BUILD)
@echo Generating build tag...
@echo appname=$(APPNAME) > $(BUILD)/build_tag
@echo version=$(VERSION) >> $(BUILD)/build_tag
@echo buildtime=$(shell date) >> $(BUILD)/build_tag
pkglist:
@echo $(subst /,.,$(call rdirs,$(PROJECT)))
doc: $(JAVASRCS)
@$(JAVADOC) -classpath $(CLASSPATH) -d $(DOC) \
-link http://docs.oracle.com/javase/7/docs/api \
-sourcepath $(PROJECT) $(JAVASRCS)
test: all
@echo Running tests...
$(JAVA) -classpath $(CLASSPATH) org.junit.runner.JUnitCore $(PROJECT).test.Tests
@echo Testing complete.
clean:
@echo Cleaning project build files...
@$(RM) -r $(BUILD) $(LIB)/$(PROJECT)-*.jar $(BIN)/$(PROJECT)_*
distclean: clean
@$(MAKE) --no-print-directory -C lib distclean
install: all
@echo Installing to $(INSTALLDIR)...
@install -d $(INSTALLDIR)/{bin,etc,lib}
@install -D -t $(INSTALLDIR)/etc $(PROJECT).conf
@install -D -t $(INSTALLDIR)/bin bin/$(PROJECT)
@$(LN) -s -f $(INSTALLDIR)/bin/$(PROJECT) $(BINDIR)/$(PROJECT)
@install -D -t $(BINDIR) bin/$(PROJECT)_*
@install -D -t $(INSTALLDIR)/lib lib/*.jar
uninstall:
@echo Uninstalling $(INSTALLDIR)...
@$(RM) -r $(INSTALLDIR)
@$(RM) $(BINDIR)/$(PROJECT) $(BINDIR)/$(PROJECT)_*
buildtest: distclean
$(MAKE) help
$(MAKE)
$(MAKE) test
$(MAKE) clean
$(MAKE) distclean
help:
@echo 'Possible targets:'
@echo
@echo ' all Build everything. This is the default target.'
@echo ' buildtest Test the whole build system.'
@echo ' clean Clean up after a build.'
@echo ' discover Find changed sources.'
@echo ' distclean Clean after build and also clean dependencies.'
@echo ' doc Build documentation.'
@echo ' fetchdeps Fetch external libraries.'
@echo ' help Display this help information.'
@echo ' install Install $(APPNAME) to this system.'
@echo ' pkglist List all Java packages in the project.'
@echo ' test Run test cases.'
@echo ' uninstall Remove $(APPNAME) from this system.'
@echo