-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
216 lines (178 loc) · 8.34 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
SHELL := /bin/bash
.DELETE_ON_ERROR:
DATE=`date +%Y%m%d`
# for printing variable values
# usage: make print-VARIABLE
# > VARIABLE = value_of_variable
print-% : ; @echo $* = $($*)
# literal space
space := $() $()
# Decide OS-specific questions
# jar-file seperator
ifeq ($(OS),Windows_NT)
SEP = ;
else
# linux
UNAME = $(shell uname)
ifeq ($(UNAME),Darwin)
SEP = :
endif
ifeq ($(UNAME),Linux)
SEP = :
endif
endif
# Find a reasonable ctags.
CTAGS = $(shell which ctags)
# Hack for MacOS: /usr/bin/ctags is unfriendly, so look for ctags from brew
ifeq ($(UNAME),Darwin)
CTAGS = $(shell brew list ctags 2> /dev/null | grep bin/ctags)
endif
# Fun Args to javac. Mostly limit to java8 source definitions, and fairly
# aggressive lint warnings.
JAVAC_ARGS = -XDignore.symbol.file -Xlint:-deprecation -Xlint:-unchecked
# Source code
# Note that BuildVersion is not forced to be rebuilt here - so incremental
# makes in this directory will endlessly use the same BuildVersion.
AA := com/cliffc/aa
SRC := src/main/java
TST := src/test/java
CLZDIR:= build/classes
main_javas := $(wildcard $(SRC)/$(AA)/*java $(SRC)/$(AA)/*/*java)
test_javas := $(wildcard $(TST)/$(AA)/*java $(TST)/$(AA)/*/*java)
main_classes := $(patsubst $(SRC)/%java,$(CLZDIR)/main/%class,$(main_javas))
test_classes := $(patsubst $(TST)/%java,$(CLZDIR)/test/%class,$(test_javas))
classes = $(main_classes) $(test_classes)
# All the libraries: see lib/README.md for more info
libs = $(wildcard lib/*jar)
jars = $(subst $(space),$(SEP),$(libs))
# Default to building java classes and not the jar
#default_targets := build/aa.jar
default_targets := $(main_classes)
# Optionally add ctags to the default target if a reasonable one was found.
ifneq ($(CTAGS),)
default_targets += TAGS_AGE
endif
default: $(default_targets)
# Just the classes, no jarring step
classes: $(classes)
# Compile just the out-of-date files
$(main_classes): build/classes/main/%class: $(SRC)/%java
@echo "compiling " $@ " because " $?
@[ -d $(CLZDIR)/main ] || mkdir -p $(CLZDIR)/main
@javac $(JAVAC_ARGS) -cp "$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(SRC) -d $(CLZDIR)/main $(main_javas)
$(test_classes): $(CLZDIR)/test/%class: $(TST)/%java $(main_classes)
@echo "compiling " $@ " because " $?
@[ -d $(CLZDIR)/test ] || mkdir -p $(CLZDIR)/test
@javac $(JAVAC_ARGS) -cp "$(CLZDIR)/test$(SEP)$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(TST) -d $(CLZDIR)/test $(test_javas)
# Note the tabs - not spaces - in the grep and cut commands
PROJECT_VERSION=0.0.1
BUILD_BRANCH= git branch | grep '*' | sed 's/* //'
BUILD_HASH= git log -1 --format="%H"
BUILD_DESCRIBE=git describe --always --dirty
BUILD_ON= (TZ=UCT date)
BUILD_BY= (whoami | cut -d\\ -f2-)
# Build the version file anytime anything would trigger the build/aa.jar.
# i.e., identical dependencies to aa.jar, except aa.jar also includes the test
# files and the BuildVersion file.
# Turn OFF build-all-the-time, to lower edit/debug/build cycle times.
#$(CLZDIR)/main/$(AA)/BuildVersion.java: $(main_classes) src/main/manifest.txt lib
$(CLZDIR)/main/$(AA)/BuildVersion.java: src/main/manifest.txt lib
@echo "vrsioning " $@ " because " $?
@rm -f $@
@mkdir -p $(dir $@)
@echo "package com.cliffc.aa;" > $@
@echo "public class BuildVersion extends AbstractBuildVersion {" >> $@
@echo " public String branchName() { return \"$(shell $(BUILD_BRANCH))\"; }" >> $@
@echo " public String lastCommitHash() { return \"$(shell $(BUILD_HASH))\"; }" >> $@
@echo " public String describe() { return \"$(shell $(BUILD_DESCRIBE))\"; }" >> $@
@echo " public String projectVersion() { return \"$(PROJECT_VERSION)\"; }" >> $@
@echo " public String compiledOn() { return \"$(shell $(BUILD_ON))\"; }" >> $@
@echo " public String compiledBy() { return \"$(shell $(BUILD_BY))\"; }" >> $@
@echo "}" >> $@
$(CLZDIR)/main/$(AA)/BuildVersion.class: $(CLZDIR)/main/$(AA)/BuildVersion.java
@javac $(JAVAC_ARGS) -cp "$(CLZDIR)/main$(SEP)$(jars)" -sourcepath $(SRC) -d $(CLZDIR)/main $(CLZDIR)/main/$(AA)/BuildVersion.java
# Other Resources in aa.jar:
JARBITS =
JARBITS += -C $(CLZDIR)/main . # The java class files
build/aa.jar: $(main_classes) $(test_classes) $(CLZDIR)/main/$(AA)/BuildVersion.class src/main/manifest.txt lib
@echo " jarring " $@ " because " $?
@[ -d build ] || mkdir -p build
# Build the aa.jar file. All included jars are unpacked into a flat structure,
# then repacked into One Jar. Name collisions amongst packages are quietly
# ignored. aa names win over all other names.
@jar -cfm build/aa.jar src/main/manifest.txt $(JARBITS)
# find all java in the src/test directory
# Cut the "./water/MRThrow.java" down to "water/MRThrow.java"
# Cut the "water/MRThrow.java" down to "water/MRThrow"
# Slash/dot "water/MRThrow" becomes "water.MRThrow"
# add 'sort' to get determinism on order of tests on different machines.
# '/usr/bin/sort' needed to avoid windows native sort when run in cygwin.
sandbox/tests.txt: $(test_classes)
@echo " finding " $@ " because " $?
@[ -d sandbox ] || mkdir -p sandbox
@(cd ${TST}; /usr/bin/find . -name '*.java' | cut -c3- | sed "s/.....$$//" | sed -e 's/\//./g') | grep -v TestUtil | /usr/bin/sort > sandbox/tests.txt
# Base launch line for JVM tests
JVM=java -ea -cp "build/aa.jar${SEP}${jars}${SEP}$(CLZDIR)/test"
# Build the AA-test jar and run the junit tests.
# Actually makes jvm_cmd.txt and status.0 along with out.0
sandbox/out.0: sandbox/tests.txt $(test_classes) build/aa.jar
@echo " testing " $@ " because " $?
@echo $(JVM) org.junit.runner.JUnitCore `cat sandbox/tests.txt` > sandbox/jvm_cmd.txt
@($(JVM) org.junit.runner.JUnitCore `cat sandbox/tests.txt` 2>&1 ; echo $$? > sandbox/status.0) 1> sandbox/out.0 2>&1
# Filter and sort test execution times
sandbox/timing.txt: sandbox/out.0
@grep EXECUTION $? | cut -d: -f5-8 | awk '{print $$6 " " $$3}' | /usr/bin/sort -gr > sandbox/timing.txt
# Report top n test times (for optimizing), and pass/fail on them all
check: sandbox/timing.txt sandbox/out.0
@head sandbox/timing.txt
@tail -n 4 sandbox/out.0
@[ `cat sandbox/status.0` -eq 0 ]
hm_tests: $(test_classes) build/aa.jar
$(JVM) org.junit.runner.JUnitCore com.cliffc.aa.HM.TestHM
# Run standard tests
test: build/aa.jar
@echo " testing"
@$(JVM) org.junit.runner.JUnitCore com.cliffc.aa.type.TestType com.cliffc.aa.TestTVar com.cliffc.aa.exe.TestEXE
# EXE, a standalone lambda calc interpreter
exec_javas := $(wildcard $(SRC)/$(AA)/exe/*java)
etst_javas := $(wildcard $(TST)/$(AA)/exe/*java)
exec_classes := $(patsubst $(SRC)/%java,$(CLZDIR)/main/%class,$(exec_javas))
etst_classes := $(patsubst $(TST)/%java,$(CLZDIR)/test/%class,$(etst_javas))
%.exe : %.aa $(main_classes) $(exec_classes) $(etst_classes)
@echo Running $<
@java -Xms1g -Xms1g -ea -cp "${CLZDIR}/main" com.cliffc.aa.exe.EXE $<
test_aas := $(wildcard $(TST)/$(AA)/exe/*aa)
exe: $(main_classes) $(exec_classes) $(etst_classes) build/aa.jar
@echo testing EXE
@$(JVM) org.junit.runner.JUnitCore com.cliffc.aa.exe.TestEXE
.PHONY: clean
clean:
rm -rf build
rm -rf out
rm -f TAGS
(find . -name "*~" -exec rm {} \; 2>/dev/null; exit 0)
# Called "conf" here, after auto-conf, but really just asks each sub-make to list tools
.PHONY: conf
conf:
@echo $(CURDIR) requires java, jar
java -version
which jar
# Download libs from maven
lib: lib/junit-4.12.jar lib/hamcrest-core-1.3.jar lib/system-rules-1.19.0.jar lib/annotations-16.0.2.jar
# Unit testing
lib/junit-4.12.jar lib/hamcrest-core-1.3.jar lib/system-rules-1.19.0.jar:
@[ -d lib ] || mkdir -p lib
@(cd lib; wget https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar)
@(cd lib; wget https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar)
@(cd lib; wget https://repo1.maven.org/maven2/com/github/stefanbirkner/system-rules/1.19.0/system-rules-1.19.0.jar)
# @NotNull annotations
lib/annotations-16.0.2.jar:
@[ -d lib ] || mkdir -p lib
@(cd lib; wget https://repo1.maven.org/maven2/org/jetbrains/annotations/16.0.2/annotations-16.0.2.jar)
# Build emacs tags (part of a tasty emacs ide experience)
tags: TAGS
TAGS: $(main_javas) $(test_javas) $(exec_javas)
echo building tags and tags_age
@rm -f TAGS
@$(CTAGS) -e --recurse=yes --extra=+q --fields=+fksaiS $(SRC) $(TST)
@touch "--date=next hour" TAGS_AGE