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