Update nikiroo-utils (fix for e-hentai language)
[fanfix.git] / Makefile.base
CommitLineData
08fe2e33
NR
1# Required parameters (the commented out ones are supposed to change per project):
2
3#MAIN = path to main java source to compile
4#MORE = path to supplementary needed resources not linked from MAIN
5#NAME = name of project (used for jar output file)
6#PREFIX = usually /usr/local (where to install the program)
7#TEST = path to main test source to compile
8#JAR_FLAGS += a list of things to pack, each usually prefixed with "-C bin/"
dd56a893 9#SJAR_FLAGS += a list of things to pack, each usually prefixed with "-C src/", for *-sources.jar files
a6395bef 10#TEST_PARAMS = any parameter to pass to the test runnable when "test-run"
08fe2e33
NR
11
12JAVAC = javac
614574c4 13JAVAC_FLAGS += -encoding UTF-8 -d ./bin/ -cp ./src/
08fe2e33
NR
14JAVA = java
15JAVA_FLAGS += -cp ./bin/
16JAR = jar
17RJAR = java
18RJAR_FLAGS += -jar
19
20# Usual options:
21# make : to build the jar file
22# make libs : to update the libraries into src/
23# make build : to update the binaries (not the jar)
24# make test : to update the test binaries
25# make build jar : to update the binaries and jar file
26# make clean : to clean the directory of intermediate files
27# make mrpropre : to clean the directory of all outputs
28# make run : to run the program from the binaries
29# make run-test : to run the test program from the binaries
30# make jrun : to run the program from the jar file
31# make install : to install the application into $PREFIX
32
33# Note: build is actually slower than rebuild in most cases except when
34# small changes only are detected ; so we use rebuild by default
35
36all: build jar
37
a6395bef 38.PHONY: all clean mrproper mrpropre build run jrun jar resources test-resources install libs love
08fe2e33
NR
39
40bin:
41 @mkdir -p bin
42
43jar: $(NAME).jar
44
45build: resources
46 @echo Compiling program...
47 @echo " src/$(MAIN)"
48 @$(JAVAC) $(JAVAC_FLAGS) "src/$(MAIN).java"
49 @[ "$(MORE)" = "" ] || for sup in $(MORE); do \
50 echo " src/$$sup" ;\
51 $(JAVAC) $(JAVAC_FLAGS) "src/$$sup.java" ; \
52 done
53
a6395bef 54test: test-resources
08fe2e33
NR
55 @[ -e bin/$(MAIN).class ] || echo You need to build the sources
56 @[ -e bin/$(MAIN).class ]
57 @echo Compiling test program...
58 @[ "$(TEST)" != "" ] || echo No test sources defined.
59 @[ "$(TEST)" = "" ] || for sup in $(TEST); do \
60 echo " src/$$sup" ;\
61 $(JAVAC) $(JAVAC_FLAGS) "src/$$sup.java" ; \
62 done
63
64clean:
65 rm -rf bin/
66 @echo Removing sources taken from libs...
d3c15421 67 @for lib in libs/*-sources.jar; do \
08fe2e33
NR
68 basename "$$lib"; \
69 jar tf "$$lib" | while read -r ln; do \
70 [ -f "src/$$ln" ] && rm "src/$$ln"; \
71 done; \
72 jar tf "$$lib" | tac | while read -r ln; do \
73 [ -d "src/$$ln" ] && rmdir "src/$$ln" 2>/dev/null || true; \
74 done; \
75 done
76
77mrproper: mrpropre
78
79mrpropre: clean
80 rm -f $(NAME).jar
dd56a893
NR
81 rm -f $(NAME)-sources.jar
82 [ ! -e VERSION ] || rm -f "$(NAME)-`cat VERSION`.jar"
83 [ ! -e VERSION ] || rm -f "$(NAME)-`cat VERSION`-sources.jar"
08fe2e33
NR
84
85love:
86 @echo " ...not war."
87
88resources: libs
89 @echo Copying resources into bin/...
a6395bef
NR
90 @cd src && find . | grep -v '\.java$$' | grep -v '/test/' | while read -r ln; do \
91 if [ -f "$$ln" ]; then \
92 dir="`dirname "$$ln"`"; \
93 mkdir -p "../bin/$$dir" ; \
94 cp "$$ln" "../bin/$$ln" ; \
95 fi ; \
96 done
39c3c689 97 @cp VERSION bin/
a6395bef
NR
98
99test-resources: resources
100 @echo Copying test resources into bin/...
101 @cd src && find . | grep -v '\.java$$' | grep '/test/' | while read -r ln; do \
08fe2e33
NR
102 if [ -f "$$ln" ]; then \
103 dir="`dirname "$$ln"`"; \
104 mkdir -p "../bin/$$dir" ; \
105 cp "$$ln" "../bin/$$ln" ; \
106 fi ; \
107 done
108
109libs: bin
110 @[ -e bin/libs -o ! -d libs ] || echo Extracting sources from libs...
d3c15421 111 @[ -e bin/libs -o ! -d libs ] || (cd src && for lib in ../libs/*-sources.jar; do \
08fe2e33
NR
112 basename "$$lib"; \
113 jar xf "$$lib"; \
114 done )
115 @[ ! -d libs ] || touch bin/libs
116
117$(NAME).jar: resources
118 @[ -e bin/$(MAIN).class ] || echo You need to build the sources
119 @[ -e bin/$(MAIN).class ]
120 @echo Making JAR file...
dd56a893
NR
121 @echo > bin/manifest
122 @[ "$(SJAR_FLAGS)" = "" ] || echo Creating $(NAME)-sources.jar...
123 @[ "$(SJAR_FLAGS)" = "" ] || $(JAR) cfm $(NAME)-sources.jar bin/manifest $(SJAR_FLAGS)
124 @[ "$(SJAR_FLAGS)" = "" ] || [ ! -e VERSION ] || echo Copying to "$(NAME)-`cat VERSION`-sources.jar"...
125 @[ "$(SJAR_FLAGS)" = "" ] || [ ! -e VERSION ] || cp $(NAME)-sources.jar "$(NAME)-`cat VERSION`-sources.jar"
08fe2e33
NR
126 @echo "Main-Class: `echo "$(MAIN)" | sed 's:/:.:g'`" > bin/manifest
127 @echo >> bin/manifest
128 $(JAR) cfm $(NAME).jar bin/manifest $(JAR_FLAGS)
dd56a893 129 @[ ! -e VERSION ] || echo Copying to "$(NAME)-`cat VERSION`.jar"...
d3c15421 130 @[ ! -e VERSION ] || cp $(NAME).jar "$(NAME)-`cat VERSION`.jar"
08fe2e33
NR
131
132run:
133 @[ -e bin/$(MAIN).class ] || echo You need to build the sources
134 @[ -e bin/$(MAIN).class ]
135 @echo Running "$(NAME)"...
136 $(JAVA) $(JAVA_FLAGS) $(MAIN)
137
138jrun:
139 @[ -e $(NAME).jar ] || echo You need to build the jar
140 @[ -e $(NAME).jar ]
141 @echo Running "$(NAME).jar"...
142 $(RJAR) $(RJAR_FLAGS) $(NAME).jar
143
144run-test:
145 @[ "$(TEST)" = "" -o -e "bin/$(TEST).class" ] || echo You need to build the test sources
146 @[ "$(TEST)" = "" -o -e "bin/$(TEST).class" ]
147 @echo Running tests for "$(NAME)"...
148 @[ "$(TEST)" != "" ] || echo No test sources defined.
a6395bef 149 [ "$(TEST)" = "" ] || ( clear ; $(JAVA) $(JAVA_FLAGS) $(TEST) $(TEST_PARAMS) )
08fe2e33
NR
150
151install:
152 @[ -e $(NAME).jar ] || echo You need to build the jar
153 @[ -e $(NAME).jar ]
154 mkdir -p "$(PREFIX)/lib" "$(PREFIX)/bin"
155 cp $(NAME).jar "$(PREFIX)/lib/"
156 echo "#!/bin/sh" > "$(PREFIX)/bin/$(NAME)"
fe999aa4 157 echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" >> "$(PREFIX)/bin/$(NAME)"
08fe2e33
NR
158 chmod a+rx "$(PREFIX)/bin/$(NAME)"
159