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