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)
12 MAIN
= be
/nikiroo
/tests
/utils
/Test
13 TEST
= be
/nikiroo
/tests
/utils
/Test
15 # Option for this program: UI=android (or UI=awt by default)
17 MORE
+= be
/nikiroo
/utils
/android
/test/TestAndroid
18 TEST
+= be
/nikiroo
/utils
/android
/ImageUtilsAndroid
20 MORE
+= be
/nikiroo
/utils
/ui
/ImageUtilsAwt
21 MORE
+= be
/nikiroo
/utils
/ui
/ImageTextAwt
22 TEST
+= be
/nikiroo
/utils
/ui
/test/TestUI
26 JAR_MISC
= -C .
/ LICENSE
-C .
/ VERSION
-C libs
/ licenses
27 JAR_FLAGS
+= -C bin
/ be
-C bin
/ org
$(JAR_MISC
)
28 SJAR_FLAGS
+= -C src
/ org
-C src
/ be
$(JAR_MISC
)
32 # Makefile base template
35 # - 1.0.0: add a version comment
36 # - 1.1.0: add 'help', 'sjar'
38 # - 1.2.1: improve 'apk' and add 'android'
39 # - 1.3.0: add 'man' for man(ual) pages
40 # - 1.4.0: remove android stuff (not working anyway)
41 # - 1.5.0: include sources and readme/changelog in jar
42 # - 1.5.1: include binaries from libs/bin/ into the jar
43 # - 1.6.0: rework the system without need of a ./configure.sh, add uninstall
47 JAVAC_FLAGS
+= -encoding UTF-8
-d .
/bin
/ -cp .
/src
/
49 JAVA_FLAGS
+= -cp .
/bin
/
57 @echo
"Usual options:"
58 @echo
"=============="
59 @echo
" make : to build the jar file and man pages IF possible"
60 @echo
" make help : to get this help screen"
61 @echo
" make libs : to update the libraries into src/"
62 @echo
" make build : to update the binaries (not the jar)"
63 @echo
" make test : to update the test binaries"
64 @echo
" make build jar : to update the binaries and jar file"
65 @echo
" make sjar : to create the sources jar file"
66 @echo
" make clean : to clean the directory of intermediate files"
67 @echo
" make mrpropre : to clean the directory of all outputs"
68 @echo
" make run : to run the program from the binaries"
69 @echo
" make run-test : to run the test program from the binaries"
70 @echo
" make jrun : to run the program from the jar file"
71 @echo
" make install : to install the application into $$PREFIX"
72 @echo
" make uninstall : to uninstall the application from $$PREFIX"
73 @echo
" make man : to make the manual pages (requires pandoc)"
75 .PHONY
: all clean mrproper mrpropre build run jrun jar sjar resources \
76 test-resources
install libs man love
83 sjar
: $(NAME
)-sources.jar
86 @echo Compiling program...
88 @
$(JAVAC
) $(JAVAC_FLAGS
) "src/$(MAIN).java"
89 @
[ "$(MORE)" = "" ] || for sup in
$(MORE
); do \
91 $(JAVAC
) $(JAVAC_FLAGS
) "src/$$sup.java" ; \
95 @
[ -e bin
/$(MAIN
).class
] || echo You need to build the sources
96 @
[ -e bin
/$(MAIN
).class
]
97 @echo Compiling
test program...
98 @
[ "$(TEST)" != "" ] || echo No
test sources defined.
99 @
[ "$(TEST)" = "" ] || for sup in
$(TEST
); do \
101 $(JAVAC
) $(JAVAC_FLAGS
) "src/$$sup.java" ; \
106 @echo Removing sources taken from libs...
107 @for lib in libs
/*-sources.jar libs
/*-sources.patch.jar
; do \
108 if
[ "$$lib" != 'libs/*-sources.jar' \
109 -a
"$$lib" != 'libs/*-sources.patch.jar' ]; \
112 jar tf
"$$lib" | while read
-r ln
; do \
113 [ -f
"src/$$ln" ] && rm "src/$$ln"; \
115 jar tf
"$$lib" | tac | while read
-r ln
; do \
116 if
[ -d
"src/$$ln" ]; then \
117 rmdir
"src/$$ln" 2>/dev
/null || true
; \
126 rm -f
$(NAME
)-sources.jar
127 [ ! -e VERSION
] ||
rm -f
"$(NAME)-`cat VERSION`.jar"
128 [ ! -e VERSION
] ||
rm -f
"$(NAME)-`cat VERSION`-sources.jar"
134 @echo Copying resources and documentation into bin
/...
135 @if
! cp
*.md bin
/ 2>/dev
/null
; then \
136 if
[ -e VERSION
]; then \
137 cp VERSION bin
/no-documentation.md
; \
139 echo
> bin
/no-documentation.md
; \
142 @cd src
&& find . | grep
-v
'\.java$$' \
143 | grep
-v
'/test/' | while read
-r ln
; do \
144 if
[ -f
"$$ln" ]; then \
145 dir="`dirname "$$ln"`"; \
146 mkdir
-p
"../bin/$$dir" ; \
147 cp
"$$ln" "../bin/$$ln" ; \
150 @
[ ! -e VERSION
] || cp VERSION bin
/
152 test-resources
: resources
153 @echo Copying
test resources into bin
/...
154 @cd src
&& find . | grep
-v
'\.java$$' \
155 | grep
'/test/' | while read
-r ln
; do \
156 if
[ -f
"$$ln" ]; then \
157 dir="`dirname "$$ln"`"; \
158 mkdir
-p
"../bin/$$dir" ; \
159 cp
"$$ln" "../bin/$$ln" ; \
164 @if
[ ! -e bin
/libs
-a
-d libs
]; then \
165 echo Extracting sources from libs...
; \
167 for lib in ..
/libs
/*-sources.jar \
168 ..
/libs
/*-sources.patch.jar
; do \
169 if
[ "$$lib" != '../libs/*-sources.jar' \
170 -a
"$$lib" != '../libs/*-sources.patch.jar' ]; \
177 @
[ ! -d libs
] || touch bin
/libs
179 $(NAME
)-sources.jar
: libs
180 @echo Making sources JAR file...
182 @if
[ "$(SJAR_FLAGS)" = "" ]; then \
183 echo No sources JAR file defined
, skipping
; \
185 echo Creating
$(NAME
)-sources.jar...
; \
186 $(JAR
) cfm
$(NAME
)-sources.jar \
187 bin
/manifest
-C .
/ *.md
$(SJAR_FLAGS
); \
188 if
[ -e VERSION
]; then \
189 echo Copying to
"$(NAME)-`cat VERSION`-sources.jar"...
;\
190 cp
$(NAME
)-sources.jar \
191 "$(NAME)-`cat VERSION`-sources.jar"; \
195 $(NAME
).jar
: resources
196 @if
[ -d libs
/bin
/ ]; then \
197 echo
"Copying additional binaries from libs/bin/ into bin/...";\
198 cp
-r libs
/bin
/* bin
/; \
200 @echo
"Copying sources into bin/..."
202 @echo
"Making jar..."
203 @echo
"Main-Class: `echo "$(MAIN
)" | sed 's:/:.:g'`" > bin
/manifest
204 @echo
>> bin
/manifest
205 $(JAR
) cfm
$(NAME
).jar bin
/manifest
-C .
/ *.md
$(JAR_FLAGS
)
206 @
[ ! -e VERSION
] || echo Copying to
"$(NAME)-`cat VERSION`.jar"...
207 @
[ ! -e VERSION
] || cp
$(NAME
).jar
"$(NAME)-`cat VERSION`.jar"
210 @echo Running
"$(NAME)"...
211 $(JAVA
) $(JAVA_FLAGS
) $(MAIN
)
214 @echo Running
"$(NAME).jar"...
215 $(RJAR
) $(RJAR_FLAGS
) $(NAME
).jar
218 @echo Running tests for
"$(NAME)"...
219 @
[ "$(TEST)" != "" ] || echo No
test sources defined.
220 @if
[ "`whereis tput`" = "tput:" ]; then \
225 ok
="`tput bold`[`tput setf 2` OK `tput init``tput bold`]`tput init`"; \
226 ko
="`tput bold`[`tput setf 4` !! `tput init``tput bold`]`tput init`"; \
227 cols
="`tput cols`"; \
229 [ "$(TEST)" = "" ] ||
( \
231 for
test in
$(TEST
); do \
232 $(JAVA
) $(JAVA_FLAGS
) "$$test" "$$cols" "$$ok" "$$ko"; \
238 @
[ -e
$(NAME
).jar
] || echo You need to build the jar
240 mkdir
-p
"$(PREFIX)/lib" "$(PREFIX)/bin"
241 cp
$(NAME
).jar
"$(PREFIX)/lib/"
244 echo
"$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" \
245 ) > "$(PREFIX)/bin/$(NAME)"
246 chmod a
+rx
"$(PREFIX)/bin/$(NAME)"
249 rm "$(PREFIX)/bin/$(NAME)"
250 rm "$(PREFIX)/lib/$(NAME).jar"
251 rmdir
"$(PREFIX)/bin" 2>/dev
/null
254 @
$(MAKE
) -f man.d
$(MAKECMDGOALS
) NAME
=$(NAME
)