-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
93 lines (70 loc) · 2.4 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
# Configuration
# =============
# Build information
APPNAME=Stork
VERSION=0.0.5
# =============
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 # Uncomment to compile with debugging info.
JFLAGS=-J-Xmx512m $(DBGFLAG) \
-classpath $(CLASSPATH) -sourcepath $(PROJECT) -nowarn
JC=javac
JAR=jar -J-Xmx512m
JAVADOC=javadoc
TAR=tar
LN=ln
.PHONY: all install clean init release classes $(PROJECT)_cmds
.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) ,:,$1)
JAVASRCS=$(call rwildcard,$(PROJECT),*.java)
CLASSES=$(JAVASRCS:%.java=build/%.class)
LIBJARS=$(call rwildcard,lib,*.jar)
DOC=doc # Directory to output documentation into.
TO_BUILD= # Generated by "build/%.class" rule.
JC_CMD= # Set only if we need to compile something.
all: $(CLASSES) | build
$(JC_CMD) $(TO_BUILD)
@$(MAKE) --no-print-directory build/build_tag
@$(MAKE) --no-print-directory $(JARFILE)
@$(MAKE) --no-print-directory $(PROJECT)_cmds
build:
@mkdir -p build
$(JARFILE): $(CLASSES)
$(JAR) cf $(JARFILE) -C build .
build/%.class: %.java | build
$(eval TO_BUILD += $<)
$(eval JC_CMD=$(JC) $(JFLAGS) -d build)
classes: $(TO_BUILD) | build
# Legacy underscore-named bins.
$(PROJECT)_cmds: $(patsubst %,bin/$(PROJECT)_%,$(CMDS))
bin/$(PROJECT)_%: bin/$(PROJECT)
@[ -e $@ ] || $(LN) -s $(PROJECT) $@
release: $(PROJECT).tar.gz
src-release: $(PROJECT)-src.tar.gz
$(PROJECT).tar.gz: $(JARFILE)
$(TAR) czf $(PROJECT).tar.gz bin libexec --exclude='*/CVS' \
--transform 's,^,$(PROJECT)/,'
$(PROJECT)-src.tar.gz: dist-clean
$(TAR) czf $(PROJECT)-src.tar.gz * --exclude='*/CVS'
build/build_tag: $(CLASSES) | build
@echo Generating build tag...
@echo appname=$(APPNAME) > build/build_tag
@echo version=$(VERSION) >> build/build_tag
@echo buildtime=$(shell date) >> build/build_tag
list-packages:
@echo $(subst /,.,$(call rdirs,$(PROJECT)))
doc: $(JAVASRCS)
@$(JAVADOC) -classpath $(CLASSPATH) -d $(DOC) \
-sourcepath $(PROJECT) $(JAVASRCS)
clean:
$(RM) -rf build lib/$(PROJECT)-*.jar $(PROJECT).tar.gz bin/$(PROJECT)_* $(DOC)