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