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