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 MORE
+= be
/nikiroo
/utils
/ui
/test/TestUI
14 # MORE += be/nikiroo/utils/android/test/TestAndroid
15 TEST
= be
/nikiroo
/tests
/utils
/Test
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
)
23 # Makefile base template
26 # - 1.0.0: add a version comment
27 # - 1.1.0: add 'help', 'sjar'
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
38 JAVAC_FLAGS
+= -encoding UTF-8
-d .
/bin
/ -cp .
/src
/
40 JAVA_FLAGS
+= -cp .
/bin
/
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)"
66 .PHONY
: all clean mrproper mrpropre build run jrun jar sjar resources test-resources
install libs man love
73 sjar
: $(NAME
)-sources.jar
76 @echo Compiling program...
78 @
$(JAVAC
) $(JAVAC_FLAGS
) "src/$(MAIN).java"
79 @
[ "$(MORE)" = "" ] || for sup in
$(MORE
); do \
81 $(JAVAC
) $(JAVAC_FLAGS
) "src/$$sup.java" ; \
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 \
91 $(JAVAC
) $(JAVAC_FLAGS
) "src/$$sup.java" ; \
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' ]; \
102 jar tf
"$$lib" | while read
-r ln
; do \
103 [ -f
"src/$$ln" ] && rm "src/$$ln"; \
105 jar tf
"$$lib" | tac | while read
-r ln
; do \
106 if
[ -d
"src/$$ln" ]; then \
107 rmdir
"src/$$ln" 2>/dev
/null || true
; \
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"
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
; \
129 echo
> bin
/no-documentation.md
; \
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" ; \
140 @
[ ! -e VERSION
] || cp VERSION bin
/
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" ; \
154 @if
[ ! -e bin
/libs
-a
-d libs
]; then \
155 echo Extracting sources from libs...
; \
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' ]; \
167 @
[ ! -d libs
] || touch bin
/libs
169 $(NAME
)-sources.jar
: libs
170 @echo Making sources JAR file...
172 @if
[ "$(SJAR_FLAGS)" = "" ]; then \
173 echo No sources JAR file defined
, skipping
; \
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"; \
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
/; \
190 @echo
"Copying sources into 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"
200 @echo Running
"$(NAME)"...
201 $(JAVA
) $(JAVA_FLAGS
) $(MAIN
)
204 @echo Running
"$(NAME).jar"...
205 $(RJAR
) $(RJAR_FLAGS
) $(NAME
).jar
208 @echo Running tests for
"$(NAME)"...
209 @
[ "$(TEST)" != "" ] || echo No
test sources defined.
210 @if
[ "`whereis tput`" = "tput:" ]; then \
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`"'; \
219 [ "$(TEST)" = "" ] || \
220 ( clear
; $(JAVA
) $(JAVA_FLAGS
) $(TEST
) "$$cols" "$$ok" "$$ko" )
223 @
[ -e
$(NAME
).jar
] || echo You need to build the jar
225 mkdir
-p
"$(PREFIX)/lib" "$(PREFIX)/bin"
226 cp
$(NAME
).jar
"$(PREFIX)/lib/"
229 echo
"$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" \
230 ) > "$(PREFIX)/bin/$(NAME)"
231 chmod a
+rx
"$(PREFIX)/bin/$(NAME)"
234 rm "$(PREFIX)/bin/$(NAME)"
235 rm "$(PREFIX)/lib/$(NAME).jar"
236 rmdir
"$(PREFIX)/bin" 2>/dev
/null
239 @
$(MAKE
) -f man.d
$(MAKECMDGOALS
) NAME
=$(NAME
)