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