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
/fanfix
/Main
13 MORE
+= be
/nikiroo
/utils
/ui
/ImageUtilsAwt
14 TEST
= be
/nikiroo
/fanfix
/test/Test
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
)
22 # Makefile base template
25 # - 1.0.0: add a version comment
26 # - 1.1.0: add 'help', 'sjar'
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
37 JAVAC_FLAGS
+= -encoding UTF-8
-d .
/bin
/ -cp .
/src
/
39 JAVA_FLAGS
+= -cp .
/bin
/
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)"
65 .PHONY
: all clean mrproper mrpropre build run jrun jar sjar resources test-resources
install libs man love
72 sjar
: $(NAME
)-sources.jar
75 @echo Compiling program...
77 @
$(JAVAC
) $(JAVAC_FLAGS
) "src/$(MAIN).java"
78 @
[ "$(MORE)" = "" ] || for sup in
$(MORE
); do \
80 $(JAVAC
) $(JAVAC_FLAGS
) "src/$$sup.java" ; \
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 \
90 $(JAVAC
) $(JAVAC_FLAGS
) "src/$$sup.java" ; \
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' ]; \
101 jar tf
"$$lib" | while read
-r ln
; do \
102 [ -f
"src/$$ln" ] && rm "src/$$ln"; \
104 jar tf
"$$lib" | tac | while read
-r ln
; do \
105 if
[ -d
"src/$$ln" ]; then \
106 rmdir
"src/$$ln" 2>/dev
/null || true
; \
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"
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
; \
128 echo
> bin
/no-documentation.md
; \
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" ; \
139 @
[ ! -e VERSION
] || cp VERSION bin
/
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" ; \
153 @if
[ ! -e bin
/libs
-a
-d libs
]; then \
154 echo Extracting sources from libs...
; \
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' ]; \
166 @
[ ! -d libs
] || touch bin
/libs
168 $(NAME
)-sources.jar
: libs
169 @echo Making sources JAR file...
171 @if
[ "$(SJAR_FLAGS)" = "" ]; then \
172 echo No sources JAR file defined
, skipping
; \
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"; \
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
/; \
189 @echo
"Copying sources into 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"
199 @echo Running
"$(NAME)"...
200 $(JAVA
) $(JAVA_FLAGS
) $(MAIN
)
203 @echo Running
"$(NAME).jar"...
204 $(RJAR
) $(RJAR_FLAGS
) $(NAME
).jar
207 @echo Running tests for
"$(NAME)"...
208 @
[ "$(TEST)" != "" ] || echo No
test sources defined.
209 @if
[ "`whereis tput`" = "tput:" ]; then \
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`"'; \
218 [ "$(TEST)" = "" ] || \
219 ( clear
; $(JAVA
) $(JAVA_FLAGS
) $(TEST
) "$$cols" "$$ok" "$$ko" )
222 @
[ -e
$(NAME
).jar
] || echo You need to build the jar
224 mkdir
-p
"$(PREFIX)/lib" "$(PREFIX)/bin"
225 cp
$(NAME
).jar
"$(PREFIX)/lib/"
228 echo
"$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" \
229 ) > "$(PREFIX)/bin/$(NAME)"
230 chmod a
+rx
"$(PREFIX)/bin/$(NAME)"
233 rm "$(PREFIX)/bin/$(NAME)"
234 rm "$(PREFIX)/lib/$(NAME).jar"
235 rmdir
"$(PREFIX)/bin" 2>/dev
/null
238 @
$(MAKE
) -f man.d
$(MAKECMDGOALS
) NAME
=$(NAME
)