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