Commit | Line | Data |
---|---|---|
ae78e517 NR |
1 | # Makefile base template |
2 | # | |
3 | # Version: | |
4 | # - 1.0.0: add a version comment | |
53282dec NR |
5 | # - 1.1.0: add 'help', 'sjar' |
6 | # - 1.2.0: add 'apk' | |
7 | # - 1.2.1: improve 'apk' and add 'android' | |
bf70d1a2 | 8 | # - 1.3.0: add 'man' for man(ual) pages |
71d3a52c | 9 | # - 1.4.0: remove android stuff (not working anyway) |
cecce42e | 10 | # - 1.5.0: include sources and readme/changelog in jar |
5f74d0e7 | 11 | # - 1.5.1: include binaries from libs/bin/ into the jar |
ae78e517 | 12 | |
53282dec | 13 | # Required parameters (the commented out ones are supposed to be per project): |
08fe2e33 NR |
14 | |
15 | #MAIN = path to main java source to compile | |
16 | #MORE = path to supplementary needed resources not linked from MAIN | |
17 | #NAME = name of project (used for jar output file) | |
18 | #PREFIX = usually /usr/local (where to install the program) | |
19 | #TEST = path to main test source to compile | |
20 | #JAR_FLAGS += a list of things to pack, each usually prefixed with "-C bin/" | |
53282dec NR |
21 | #SJAR_FLAGS += a list of things to pack, each usually prefixed with "-C src/", |
22 | # for *-sources.jar files | |
a6395bef | 23 | #TEST_PARAMS = any parameter to pass to the test runnable when "test-run" |
08fe2e33 NR |
24 | |
25 | JAVAC = javac | |
614574c4 | 26 | JAVAC_FLAGS += -encoding UTF-8 -d ./bin/ -cp ./src/ |
08fe2e33 NR |
27 | JAVA = java |
28 | JAVA_FLAGS += -cp ./bin/ | |
29 | JAR = jar | |
30 | RJAR = java | |
31 | RJAR_FLAGS += -jar | |
32 | ||
bf70d1a2 | 33 | all: build jar man |
08fe2e33 | 34 | |
ae78e517 NR |
35 | help: |
36 | @echo "Usual options:" | |
37 | @echo "==============" | |
bf70d1a2 | 38 | @echo " make : to build the jar file and man pages IF possible" |
ae78e517 NR |
39 | @echo " make help : to get this help screen" |
40 | @echo " make libs : to update the libraries into src/" | |
41 | @echo " make build : to update the binaries (not the jar)" | |
42 | @echo " make test : to update the test binaries" | |
43 | @echo " make build jar : to update the binaries and jar file" | |
44 | @echo " make sjar : to create the sources jar file" | |
45 | @echo " make clean : to clean the directory of intermediate files" | |
46 | @echo " make mrpropre : to clean the directory of all outputs" | |
47 | @echo " make run : to run the program from the binaries" | |
48 | @echo " make run-test : to run the test program from the binaries" | |
49 | @echo " make jrun : to run the program from the jar file" | |
9b05b757 | 50 | @echo " make install : to install the application into $$PREFIX" |
bf70d1a2 NR |
51 | @echo " make ifman : to make the manual pages (if pandoc is found)" |
52 | @echo " make man : to make the manual pages (requires pandoc)" | |
ae78e517 | 53 | |
71d3a52c | 54 | .PHONY: all clean mrproper mrpropre build run jrun jar sjar resources test-resources install libs ifman man love |
08fe2e33 NR |
55 | |
56 | bin: | |
57 | @mkdir -p bin | |
58 | ||
59 | jar: $(NAME).jar | |
60 | ||
ae78e517 NR |
61 | sjar: $(NAME)-sources.jar |
62 | ||
08fe2e33 NR |
63 | build: resources |
64 | @echo Compiling program... | |
65 | @echo " src/$(MAIN)" | |
66 | @$(JAVAC) $(JAVAC_FLAGS) "src/$(MAIN).java" | |
67 | @[ "$(MORE)" = "" ] || for sup in $(MORE); do \ | |
68 | echo " src/$$sup" ;\ | |
69 | $(JAVAC) $(JAVAC_FLAGS) "src/$$sup.java" ; \ | |
70 | done | |
71 | ||
a6395bef | 72 | test: test-resources |
08fe2e33 NR |
73 | @[ -e bin/$(MAIN).class ] || echo You need to build the sources |
74 | @[ -e bin/$(MAIN).class ] | |
75 | @echo Compiling test program... | |
76 | @[ "$(TEST)" != "" ] || echo No test sources defined. | |
77 | @[ "$(TEST)" = "" ] || for sup in $(TEST); do \ | |
78 | echo " src/$$sup" ;\ | |
79 | $(JAVAC) $(JAVAC_FLAGS) "src/$$sup.java" ; \ | |
80 | done | |
81 | ||
82 | clean: | |
83 | rm -rf bin/ | |
84 | @echo Removing sources taken from libs... | |
3871aa4e NR |
85 | @for lib in libs/*-sources.jar libs/*-sources.patch.jar; do \ |
86 | if [ "$$lib" != 'libs/*-sources.jar' -a "$$lib" != 'libs/*-sources.patch.jar' ]; then \ | |
87 | basename "$$lib"; \ | |
88 | jar tf "$$lib" | while read -r ln; do \ | |
89 | [ -f "src/$$ln" ] && rm "src/$$ln"; \ | |
90 | done; \ | |
91 | jar tf "$$lib" | tac | while read -r ln; do \ | |
92 | [ -d "src/$$ln" ] && rmdir "src/$$ln" 2>/dev/null || true; \ | |
93 | done; \ | |
94 | fi \ | |
08fe2e33 NR |
95 | done |
96 | ||
97 | mrproper: mrpropre | |
98 | ||
99 | mrpropre: clean | |
100 | rm -f $(NAME).jar | |
dd56a893 | 101 | rm -f $(NAME)-sources.jar |
9b05b757 NR |
102 | rm -f $(NAME).apk |
103 | rm -f $(NAME)-debug.apk | |
dd56a893 NR |
104 | [ ! -e VERSION ] || rm -f "$(NAME)-`cat VERSION`.jar" |
105 | [ ! -e VERSION ] || rm -f "$(NAME)-`cat VERSION`-sources.jar" | |
08fe2e33 NR |
106 | |
107 | love: | |
108 | @echo " ...not war." | |
109 | ||
110 | resources: libs | |
111 | @echo Copying resources into bin/... | |
a6395bef NR |
112 | @cd src && find . | grep -v '\.java$$' | grep -v '/test/' | while read -r ln; do \ |
113 | if [ -f "$$ln" ]; then \ | |
114 | dir="`dirname "$$ln"`"; \ | |
115 | mkdir -p "../bin/$$dir" ; \ | |
116 | cp "$$ln" "../bin/$$ln" ; \ | |
117 | fi ; \ | |
118 | done | |
39c3c689 | 119 | @cp VERSION bin/ |
a6395bef NR |
120 | |
121 | test-resources: resources | |
122 | @echo Copying test resources into bin/... | |
123 | @cd src && find . | grep -v '\.java$$' | grep '/test/' | while read -r ln; do \ | |
08fe2e33 NR |
124 | if [ -f "$$ln" ]; then \ |
125 | dir="`dirname "$$ln"`"; \ | |
126 | mkdir -p "../bin/$$dir" ; \ | |
127 | cp "$$ln" "../bin/$$ln" ; \ | |
128 | fi ; \ | |
129 | done | |
130 | ||
131 | libs: bin | |
132 | @[ -e bin/libs -o ! -d libs ] || echo Extracting sources from libs... | |
c1873e56 | 133 | @[ -e bin/libs -o ! -d libs ] || (cd src && for lib in ../libs/*-sources.jar ../libs/*-sources.patch.jar; do \ |
9119671d NR |
134 | if [ "$$lib" != '../libs/*-sources.jar' -a "$$lib" != '../libs/*-sources.patch.jar' ]; then \ |
135 | basename "$$lib"; \ | |
136 | jar xf "$$lib"; \ | |
137 | fi \ | |
08fe2e33 NR |
138 | done ) |
139 | @[ ! -d libs ] || touch bin/libs | |
140 | ||
ae78e517 | 141 | $(NAME)-sources.jar: libs |
cecce42e | 142 | @ls *.md >/dev/null || cp VERSION README.md |
ae78e517 | 143 | @echo Making sources JAR file... |
dd56a893 | 144 | @echo > bin/manifest |
cecce42e NR |
145 | @[ "$(SJAR_FLAGS)" != "" ] || echo No sources JAR file defined, skipping |
146 | @[ "$(SJAR_FLAGS)" = "" ] || echo Creating $(NAME)-sources.jar... | |
147 | @[ "$(SJAR_FLAGS)" = "" ] || $(JAR) cfm $(NAME)-sources.jar bin/manifest -C ./ *.md $(SJAR_FLAGS) | |
148 | @[ "$(SJAR_FLAGS)" = "" ] || [ ! -e VERSION ] || echo Copying to "$(NAME)-`cat VERSION`-sources.jar"... | |
149 | @[ "$(SJAR_FLAGS)" = "" ] || [ ! -e VERSION ] || cp $(NAME)-sources.jar "$(NAME)-`cat VERSION`-sources.jar" | |
ae78e517 NR |
150 | |
151 | $(NAME).jar: resources | |
152 | @[ -e bin/$(MAIN).class ] || echo You need to build the sources | |
153 | @[ -e bin/$(MAIN).class ] | |
cecce42e NR |
154 | @ls *.md >/dev/null || cp VERSION README.md |
155 | @echo "Copying documentation into bin/..." | |
156 | @cp -r *.md bin/ || cp VERSION bin/no-documentation.md | |
5f74d0e7 NR |
157 | @[ ! -d libs/bin/ ] || echo "Copying additional binaries from libs/bin/ into bin/..." |
158 | @[ ! -d libs/bin/ ] || cp -r libs/bin/* bin/ | |
cecce42e NR |
159 | @echo "Copying sources into bin/..." |
160 | @cp -r src/* bin/ | |
161 | @echo "Making jar..." | |
08fe2e33 NR |
162 | @echo "Main-Class: `echo "$(MAIN)" | sed 's:/:.:g'`" > bin/manifest |
163 | @echo >> bin/manifest | |
cecce42e | 164 | $(JAR) cfm $(NAME).jar bin/manifest -C ./ *.md $(JAR_FLAGS) |
dd56a893 | 165 | @[ ! -e VERSION ] || echo Copying to "$(NAME)-`cat VERSION`.jar"... |
d3c15421 | 166 | @[ ! -e VERSION ] || cp $(NAME).jar "$(NAME)-`cat VERSION`.jar" |
08fe2e33 NR |
167 | |
168 | run: | |
169 | @[ -e bin/$(MAIN).class ] || echo You need to build the sources | |
170 | @[ -e bin/$(MAIN).class ] | |
171 | @echo Running "$(NAME)"... | |
172 | $(JAVA) $(JAVA_FLAGS) $(MAIN) | |
173 | ||
174 | jrun: | |
175 | @[ -e $(NAME).jar ] || echo You need to build the jar | |
176 | @[ -e $(NAME).jar ] | |
177 | @echo Running "$(NAME).jar"... | |
178 | $(RJAR) $(RJAR_FLAGS) $(NAME).jar | |
179 | ||
180 | run-test: | |
181 | @[ "$(TEST)" = "" -o -e "bin/$(TEST).class" ] || echo You need to build the test sources | |
182 | @[ "$(TEST)" = "" -o -e "bin/$(TEST).class" ] | |
183 | @echo Running tests for "$(NAME)"... | |
184 | @[ "$(TEST)" != "" ] || echo No test sources defined. | |
a6395bef | 185 | [ "$(TEST)" = "" ] || ( clear ; $(JAVA) $(JAVA_FLAGS) $(TEST) $(TEST_PARAMS) ) |
08fe2e33 NR |
186 | |
187 | install: | |
188 | @[ -e $(NAME).jar ] || echo You need to build the jar | |
189 | @[ -e $(NAME).jar ] | |
190 | mkdir -p "$(PREFIX)/lib" "$(PREFIX)/bin" | |
191 | cp $(NAME).jar "$(PREFIX)/lib/" | |
192 | echo "#!/bin/sh" > "$(PREFIX)/bin/$(NAME)" | |
fe999aa4 | 193 | echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" >> "$(PREFIX)/bin/$(NAME)" |
08fe2e33 | 194 | chmod a+rx "$(PREFIX)/bin/$(NAME)" |
a1a900a5 NR |
195 | if [ -e "man/man1/$(NAME).1" ]; then \ |
196 | cp -r man/ "$(PREFIX)"/share/; \ | |
197 | fi | |
08fe2e33 | 198 | |
bf70d1a2 NR |
199 | ifman: |
200 | @if pandoc -v >/dev/null 2>&1; then \ | |
201 | make man; \ | |
202 | else \ | |
203 | echo "man pages not generated: "'`'"pandoc' required"; \ | |
204 | fi | |
205 | ||
206 | man: | |
207 | @echo Checking for possible manual pages... | |
208 | @if [ -e README.md ]; then \ | |
209 | echo Sources found for man pages; \ | |
210 | if pandoc -v >/dev/null 2>&1; then \ | |
211 | ls README*.md 2>/dev/null \ | |
212 | | grep 'README\(-..\|\)\.md' \ | |
213 | | while read man; do \ | |
214 | echo " Processing page $$lang..."; \ | |
215 | lang="`echo "$$man" \ | |
216 | | sed 's:README\.md:en:' \ | |
217 | | sed 's:README-\(.*\)\.md:\1:'`"; \ | |
218 | mkdir -p man/"$$lang"/man1; \ | |
219 | ( \ | |
220 | echo ".TH \"${NAME}\" 1 `\ | |
221 | date +%Y-%m-%d\ | |
222 | ` \"version `cat VERSION`\""; \ | |
223 | echo; \ | |
224 | UNAME="`echo "${NAME}" \ | |
225 | | sed 's:\(.*\):\U\1:g'`"; \ | |
226 | ( \ | |
227 | cat "$$man" | head -n1 \ | |
228 | | sed 's:.*(README\(-fr\|\)\.md).*::g'; \ | |
229 | cat "$$man" | tail -n+2; \ | |
230 | ) | sed 's:^#\(#.*\):\1:g' \ | |
231 | | sed 's:^\(#.*\):\U\1:g;s:# *'"$$UNAME"':# NAME\n'"${NAME}"' \\- :g' \ | |
5783289e NR |
232 | | sed 's:--:——:g' \ |
233 | | pandoc -f markdown -t man | sed 's:——:--:g' ; \ | |
bf70d1a2 NR |
234 | ) > man/"$$lang"/man1/"${NAME}.1"; \ |
235 | done; \ | |
236 | mkdir -p "man/man1"; \ | |
237 | cp man/en/man1/"${NAME}".1 man/man1/; \ | |
238 | else \ | |
239 | echo "man pages generation: pandoc required" >&2; \ | |
240 | false; \ | |
241 | fi; \ | |
242 | fi; | |
243 |