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