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