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