Update version after release of v0.6.6.1
[olsrd.git] / lib / pud / wireformat-java / Makefile
1 include ../wireformat/Makefile.inc
2 WIREFORMAT_PROJECT := $(PROJECT)
3
4 include Makefile.inc
5
6 include ../Makefile.inc
7 OLSRD_PLUGIN = false
8
9 TOPDIR = ../../..
10 include $(TOPDIR)/Makefile.inc
11
12 LDFLAGS = -shared -Wl,--warn-common -fPIC
13
14 # 32/64 cross compilation
15 ifdef M32
16 CFLAGS +=       -m32
17 LDFLAGS +=      -m32
18 endif
19 ifdef M64
20 CFLAGS +=       -m64
21 LDFLAGS +=      -m64
22 endif
23
24 ######################
25 #
26 # Settings
27 #
28 ######################
29
30 ifeq ($(DEBUG),1)
31 DEBUGBOOLEAN = true
32 else
33 DEBUGBOOLEAN = false
34 endif
35
36
37 DESTDIR ?=
38 USRDIR ?= $(DESTDIR)/usr
39 LIBDIR ?= $(USRDIR)/lib
40 SHAREDIR ?= $(USRDIR)/share
41 SHAREJAVADIR ?= $(SHAREDIR)/java/$(EXENAME)
42
43
44 MACHINE=$(shell uname -m)
45 ARCH=
46 ifeq ($(strip $(MACHINE)),x86_64)
47   ARCH=.$(MACHINE)
48 endif
49
50
51 RESOURCES_DIR = resources
52 BUILD_DIR = build
53 LIBDIR_BUILD = lib
54
55 INC_DIR_WIREFORMAT = ../wireformat/include
56 INC_DIR_WIREFORMAT_FULL = $(INC_DIR_WIREFORMAT)/$(WIREFORMAT_PROJECT)
57
58 ifneq ($(wildcard /usr/lib/jvm/java),)
59   INC_DIR_JVM = /usr/lib/jvm/java/include
60 else
61   ifneq ($(wildcard /usr/lib/jvm/default-java),)
62     INC_DIR_JVM = /usr/lib/jvm/default-java/include
63   else
64     ifneq ($(wildcard /usr/lib/jvm/java-1.7.0-openjdk$(ARCH)),)
65       INC_DIR_JVM = /usr/lib/jvm/java-1.7.0-openjdk$(ARCH)/include
66     else
67       ifneq ($(wildcard /usr/lib/jvm/java-1.7.0-openjdk),)
68         INC_DIR_JVM = /usr/lib/jvm/java-1.7.0-openjdk/include
69       else
70         ifneq ($(wildcard /usr/lib/jvm/java-1.6.0-openjdk$(ARCH)),)
71           INC_DIR_JVM = /usr/lib/jvm/java-1.6.0-openjdk$(ARCH)/include
72         else
73           ifneq ($(wildcard /usr/lib/jvm/java-1.6.0-openjdk),)
74             INC_DIR_JVM = /usr/lib/jvm/java-1.6.0-openjdk/include
75           else
76             $(error No java detected)
77           endif
78         endif
79       endif
80     endif
81   endif
82 endif
83
84 INC_DIR_JVM_OS = $(INC_DIR_JVM)/$(OS)
85
86
87 SRC_DIR_C = src/main/c
88
89 INCLUDES = -I "$(INC_DIR_WIREFORMAT)" -I "$(INC_DIR_JVM)" -I "$(INC_DIR_JVM_OS)"
90 LIBRARIES = -L ../wireformat/lib -l$(WIREFORMAT_PROJECT)
91
92
93 BUILD_DIR_JNI = $(BUILD_DIR)/jni
94
95 JAVASRC = src/main/java
96 JAVAVERSIONSRC = 1.6
97 JAVAVERSIONDST = 1.6
98 JAVABOOTCLASSPATH = resources/ee.j2se/$(JAVAVERSIONSRC)/ee.j2se.jar
99 JAVA_PKG = org.olsr.plugin.pud
100 JAVA_PKG_DIR = $(subst .,/,$(JAVA_PKG))
101 JAVA_PKG_UNDER = $(subst .,_,$(JAVA_PKG))
102
103
104 ifneq ($(OS),linux)
105
106 .PHONY: all default_target install clean
107
108 all: default_target
109
110 default_target install clean:
111         @echo "*** only supported on Linux"
112
113 else
114
115 GIT_SHA = $(shell git describe 2> /dev/null || echo "Unknown")
116
117 .PHONY: all default_target java prepare clean doc doc-clean install uninstall
118
119 #
120 # Targets
121 #
122
123 all: default_target
124
125 default_target: prepare $(LIBDIR_BUILD)/$(SONAME) java
126
127 .gitignore:
128 ifeq ($(VERBOSE),0)
129         @echo "[$@]"
130 endif
131         $(MAKECMDPREFIX)echo "/$(BUILD_DIR)/" > $@
132         $(MAKECMDPREFIX)echo "/$(LIBDIR_BUILD)/" >> $@
133         $(MAKECMDPREFIX)echo "/build.xml" >> $@
134         $(MAKECMDPREFIX)echo "/$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h" >> $@
135         $(MAKECMDPREFIX)echo "/$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.h" >> $@
136         $(MAKECMDPREFIX)echo "/$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.h" >> $@
137         $(MAKECMDPREFIX)echo "/$(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java" >> $@
138         $(MAKECMDPREFIX)$(MAKE) -C doc $@
139
140 $(LIBDIR_BUILD)/$(SONAME): $(BUILD_DIR)/$(JAVA_PKG_UNDER)_UplinkMessage.o \
141                            $(BUILD_DIR)/$(JAVA_PKG_UNDER)_ClusterLeader.o \
142                            $(BUILD_DIR)/$(JAVA_PKG_UNDER)_PositionUpdate.o
143 ifeq ($(VERBOSE),0)
144         @echo "[LD] $@"
145 endif
146         $(MAKECMDPREFIX)$(CC) $(LDFLAGS) -Wl,-soname=$(SONAME) $(LIBRARIES) -o "$@" \
147       $(BUILD_DIR)/$(JAVA_PKG_UNDER)_UplinkMessage.o \
148       $(BUILD_DIR)/$(JAVA_PKG_UNDER)_ClusterLeader.o \
149       $(BUILD_DIR)/$(JAVA_PKG_UNDER)_PositionUpdate.o
150
151 # PositionUpdate
152 $(BUILD_DIR)/$(JAVA_PKG_UNDER)_PositionUpdate.o: $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.c \
153                                                  $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h \
154                                                  $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h \
155                                                  $(INC_DIR_WIREFORMAT_FULL)/nodeIdConversion.h
156 ifeq ($(VERBOSE),0)
157         @echo "[CC] $<"
158 endif
159         $(MAKECMDPREFIX)$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o "$@" "$<"
160
161 $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h: $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/PositionUpdate.class
162 ifeq ($(VERBOSE),0)
163         @echo "[JavaH] $<"
164 endif
165         $(MAKECMDPREFIX)rm -f "$@"
166         $(MAKECMDPREFIX)javah -jni -classpath "$(BUILD_DIR_JNI)" -o "$@" "$(JAVA_PKG).PositionUpdate"
167
168 $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/PositionUpdate.class: $(JAVASRC)/$(JAVA_PKG_DIR)/PositionUpdate.java \
169                                                        $(JAVASRC)/$(JAVA_PKG_DIR)/LibraryLoader.java \
170                                                        $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
171 ifeq ($(VERBOSE),0)
172         @echo "[JavaC] $<"
173 endif
174         $(MAKECMDPREFIX)javac -bootclasspath $(JAVABOOTCLASSPATH) -classpath $(JAVASRC) -source 1.6 -target 1.6 -Xlint -d "$(BUILD_DIR_JNI)" "$<"
175
176 # ClusterLeader
177 $(BUILD_DIR)/$(JAVA_PKG_UNDER)_ClusterLeader.o: $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.c \
178                                                  $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.h \
179                                                  $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h \
180                                                  $(INC_DIR_WIREFORMAT_FULL)/nodeIdConversion.h
181 ifeq ($(VERBOSE),0)
182         @echo "[CC] $<"
183 endif
184         $(MAKECMDPREFIX)$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o "$@" "$<"
185
186 $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.h: $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/ClusterLeader.class
187 ifeq ($(VERBOSE),0)
188         @echo "[JavaH] $<"
189 endif
190         $(MAKECMDPREFIX)rm -f "$@"
191         $(MAKECMDPREFIX)javah -jni -classpath "$(BUILD_DIR_JNI)" -o "$@" "$(JAVA_PKG).ClusterLeader"
192
193 $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/ClusterLeader.class: $(JAVASRC)/$(JAVA_PKG_DIR)/ClusterLeader.java \
194                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/LibraryLoader.java \
195                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
196 ifeq ($(VERBOSE),0)
197         @echo "[JavaC] $<"
198 endif
199         $(MAKECMDPREFIX)javac -bootclasspath $(JAVABOOTCLASSPATH) -classpath $(JAVASRC) -source 1.6 -target 1.6 -Xlint -d "$(BUILD_DIR_JNI)" "$<"
200
201 # UplinkMessage
202 $(BUILD_DIR)/$(JAVA_PKG_UNDER)_UplinkMessage.o: $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.c \
203                                                  $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.h \
204                                                  $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h \
205                                                  $(INC_DIR_WIREFORMAT_FULL)/nodeIdConversion.h
206 ifeq ($(VERBOSE),0)
207         @echo "[CC] $<"
208 endif
209         $(MAKECMDPREFIX)$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o "$@" "$<"
210
211 $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.h: $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/UplinkMessage.class
212 ifeq ($(VERBOSE),0)
213         @echo "[JavaH] $<"
214 endif
215         $(MAKECMDPREFIX)rm -f "$@"
216         $(MAKECMDPREFIX)javah -jni -classpath "$(BUILD_DIR_JNI)" -o "$@" "$(JAVA_PKG).UplinkMessage"
217
218 $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/UplinkMessage.class: $(JAVASRC)/$(JAVA_PKG_DIR)/UplinkMessage.java \
219                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/LibraryLoader.java \
220                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
221 ifeq ($(VERBOSE),0)
222         @echo "[JavaC] $<"
223 endif
224         $(MAKECMDPREFIX)javac -bootclasspath $(JAVABOOTCLASSPATH) -classpath $(JAVASRC) -source 1.6 -target 1.6 -Xlint -d "$(BUILD_DIR_JNI)" "$<"
225
226
227 #
228 # java
229 #
230
231 java: prepare \
232      build.xml \
233      $(JAVASRC)/$(JAVA_PKG_DIR)/PositionUpdate.java \
234      $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
235         $(MAKECMDPREFIX)ant -f build.xml release
236
237 build.xml: $(RESOURCES_DIR)/build.xml
238 ifeq ($(VERBOSE),0)
239         @echo "[generate] $@"
240 endif
241         $(MAKECMDPREFIX)sed -r -e "s#PLUGIN_VER#$(PLUGIN_VER)#g" \
242                 -e "s#PROJECT#$(PROJECT)#g" \
243                 -e "s#BUILD_DIR#$(BUILD_DIR)#g" \
244                 -e "s#LIBDIR_BUILD#$(LIBDIR_BUILD)#g" \
245                 -e "s#JAVASRC#$(JAVASRC)#g" \
246                 -e "s#JAVAVERSIONSRC#$(JAVAVERSIONSRC)#g" \
247                 -e "s#JAVAVERSIONDST#$(JAVAVERSIONDST)#g" \
248                 -e "s#DEBUG#$(DEBUGBOOLEAN)#g" \
249                 "$<" > "$@"
250
251
252 #
253 # generate java classes
254 #
255
256 $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java: \
257       $(RESOURCES_DIR)/WireFormatConstants.java.h \
258       $(BUILD_DIR_JNI)/c/library.h \
259       $(BUILD_DIR_JNI)/c/wireFormat.h
260 ifeq ($(VERBOSE),0)
261         @echo "[generate] $@"
262 endif
263         $(MAKECMDPREFIX)$(CPP) -I "$(BUILD_DIR_JNI)/c" -DPLUGIN_VER=\"$(PLUGIN_VER)\" -DGIT_SHA=\"$(GIT_SHA)\" "$<" | \
264           sed -r -e '/^[[:space:]]*#.*$$/ d' \
265                  -e '/^[[:space:]]*$$/ d' \
266                  > "$@"
267
268
269 #
270 # generate jni includes
271 #
272
273 $(BUILD_DIR_JNI)/c/library.h: Makefile.inc
274 ifeq ($(VERBOSE),0)
275         @echo "[generate] $@"
276 endif
277         $(MAKECMDPREFIX)echo "#define PUD_WIRE_FORMAT_LIBRARYNAME \"$(PROJECT)\"" > "$@"
278
279 $(BUILD_DIR_JNI)/c/wireFormat.h: $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h
280 ifeq ($(VERBOSE),0)
281         @echo "[generate] $@"
282 endif
283         $(MAKECMDPREFIX)grep -E '^[[:space:]]*#define[[:space:]]+' "$<" > "$@"
284
285
286 #
287 # Phony Targets
288 #
289
290 prepare:
291         $(MAKECMDPREFIX)mkdir -p "$(BUILD_DIR)" \
292                   "$(LIBDIR_BUILD)" \
293                   "$(BUILD_DIR_JNI)/c"
294
295
296 clean: doc-clean
297 ifeq ($(VERBOSE),0)
298         @echo "[$@]"
299 endif
300         $(MAKECMDPREFIX)rm -fr "$(BUILD_DIR)" "$(LIBDIR_BUILD)" \
301                 build.xml \
302                 "$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h" \
303                 "$(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java"
304
305 doc: build.xml
306         $(MAKECMDPREFIX)$(MAKE) -C doc all
307         $(MAKECMDPREFIX)ant -f build.xml javadoc
308
309 doc-clean:
310         $(MAKECMDPREFIX)$(MAKE) -C doc clean
311
312 install: all
313         mkdir -v -p "$(LIBDIR)"
314         cp "$(LIBDIR_BUILD)/$(SONAME)" "$(LIBDIR)/$(SONAME).$(PLUGIN_VER)"
315         $(STRIP) "$(LIBDIR)/$(SONAME).$(PLUGIN_VER)"
316         /sbin/ldconfig -n "$(LIBDIR)"
317         mkdir -v -p "$(SHAREJAVADIR)"
318         cp -t "$(SHAREJAVADIR)" \
319       "$(LIBDIR_BUILD)/$(PROJECT).jar" \
320       "$(LIBDIR_BUILD)/$(PROJECT)-src.zip" \
321       "$(LIBDIR_BUILD)/$(PROJECT)-doc.zip"
322
323 uninstall:
324         rm -f "$(LIBDIR)/$(SONAME)" \
325               "$(LIBDIR)/$(SONAME).$(PLUGIN_VER)"
326         /sbin/ldconfig -n "$(LIBDIR)"
327         rmdir -v -p --ignore-fail-on-non-empty "$(LIBDIR)"
328         rm -f "$(SHAREJAVADIR)/$(PROJECT).jar" \
329           "$(SHAREJAVADIR)/$(PROJECT)-src.zip" \
330           "$(SHAREJAVADIR)/$(PROJECT)-doc.zip"
331         rmdir -v -p --ignore-fail-on-non-empty "$(SHAREJAVADIR)"
332
333 endif