1b5d9cd9d194dcf53da34140743b8762f5a0cebc
[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-1.6.0-openjdk$(ARCH)/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         @echo "[$@]"
92         @echo "/$(BUILD_DIR)/" > $@
93         @echo "/$(LIBDIR_BUILD)/" >> $@
94         @echo "/build.xml" >> $@
95         @echo "/$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h" >> $@
96         @echo "/$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.h" >> $@
97         @echo "/$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.h" >> $@
98         @echo "/$(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java" >> $@
99         @$(MAKE) -C doc $@
100
101 $(LIBDIR_BUILD)/$(SONAME): $(BUILD_DIR)/$(JAVA_PKG_UNDER)_UplinkMessage.o \
102                            $(BUILD_DIR)/$(JAVA_PKG_UNDER)_ClusterLeader.o \
103                            $(BUILD_DIR)/$(JAVA_PKG_UNDER)_PositionUpdate.o
104         @echo "[LD] $@"
105         @$(CC) -shared -Wl,-soname=$(SONAME) $(LIBRARIES) -o "$@" \
106       $(BUILD_DIR)/$(JAVA_PKG_UNDER)_UplinkMessage.o \
107       $(BUILD_DIR)/$(JAVA_PKG_UNDER)_ClusterLeader.o \
108       $(BUILD_DIR)/$(JAVA_PKG_UNDER)_PositionUpdate.o
109
110 # PositionUpdate
111 $(BUILD_DIR)/$(JAVA_PKG_UNDER)_PositionUpdate.o: $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.c \
112                                                  $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h \
113                                                  $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h \
114                                                  $(INC_DIR_WIREFORMAT_FULL)/nodeIdConversion.h
115         @echo "[CC] $<"
116         @$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o "$@" "$<"
117
118 $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h: $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/PositionUpdate.class
119         @echo "[JavaH] $<"
120         @rm -f "$@"
121         @javah -jni -classpath "$(BUILD_DIR_JNI)" -o "$@" "$(JAVA_PKG).PositionUpdate"
122
123 $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/PositionUpdate.class: $(JAVASRC)/$(JAVA_PKG_DIR)/PositionUpdate.java \
124                                                        $(JAVASRC)/$(JAVA_PKG_DIR)/LibraryLoader.java \
125                                                        $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
126         @echo "[JavaC] $<"
127         @javac -bootclasspath $(JAVABOOTCLASSPATH) -classpath $(JAVASRC) -source 1.6 -target 1.6 -Xlint -d "$(BUILD_DIR_JNI)" "$<"
128
129 # ClusterLeader
130 $(BUILD_DIR)/$(JAVA_PKG_UNDER)_ClusterLeader.o: $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.c \
131                                                  $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.h \
132                                                  $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h \
133                                                  $(INC_DIR_WIREFORMAT_FULL)/nodeIdConversion.h
134         @echo "[CC] $<"
135         @$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o "$@" "$<"
136
137 $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_ClusterLeader.h: $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/ClusterLeader.class
138         @echo "[JavaH] $<"
139         @rm -f "$@"
140         @javah -jni -classpath "$(BUILD_DIR_JNI)" -o "$@" "$(JAVA_PKG).ClusterLeader"
141
142 $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/ClusterLeader.class: $(JAVASRC)/$(JAVA_PKG_DIR)/ClusterLeader.java \
143                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/LibraryLoader.java \
144                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
145         @echo "[JavaC] $<"
146         @javac -bootclasspath $(JAVABOOTCLASSPATH) -classpath $(JAVASRC) -source 1.6 -target 1.6 -Xlint -d "$(BUILD_DIR_JNI)" "$<"
147
148 # UplinkMessage
149 $(BUILD_DIR)/$(JAVA_PKG_UNDER)_UplinkMessage.o: $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.c \
150                                                  $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.h \
151                                                  $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h \
152                                                  $(INC_DIR_WIREFORMAT_FULL)/nodeIdConversion.h
153         @echo "[CC] $<"
154         @$(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -c -o "$@" "$<"
155
156 $(SRC_DIR_C)/$(JAVA_PKG_UNDER)_UplinkMessage.h: $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/UplinkMessage.class
157         @echo "[JavaH] $<"
158         @rm -f "$@"
159         @javah -jni -classpath "$(BUILD_DIR_JNI)" -o "$@" "$(JAVA_PKG).UplinkMessage"
160
161 $(BUILD_DIR_JNI)/$(JAVA_PKG_DIR)/UplinkMessage.class: $(JAVASRC)/$(JAVA_PKG_DIR)/UplinkMessage.java \
162                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/LibraryLoader.java \
163                                                       $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
164         @echo "[JavaC] $<"
165         @javac -bootclasspath $(JAVABOOTCLASSPATH) -classpath $(JAVASRC) -source 1.6 -target 1.6 -Xlint -d "$(BUILD_DIR_JNI)" "$<"
166
167
168 #
169 # java
170 #
171
172 java: prepare \
173      build.xml \
174      $(JAVASRC)/$(JAVA_PKG_DIR)/PositionUpdate.java \
175      $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java
176         @ant -f build.xml release
177
178 build.xml: $(RESOURCES_DIR)/build.xml
179         @echo "[generate] $@"
180         @sed -r -e "s#PLUGIN_VER#$(PLUGIN_VER)#g" \
181                 -e "s#PROJECT#$(PROJECT)#g" \
182                 -e "s#BUILD_DIR#$(BUILD_DIR)#g" \
183                 -e "s#LIBDIR_BUILD#$(LIBDIR_BUILD)#g" \
184                 -e "s#JAVASRC#$(JAVASRC)#g" \
185                 -e "s#JAVAVERSIONSRC#$(JAVAVERSIONSRC)#g" \
186                 -e "s#JAVAVERSIONDST#$(JAVAVERSIONDST)#g" \
187                 -e "s#DEBUG#$(DEBUGBOOLEAN)#g" \
188                 "$<" > "$@"
189
190
191 #
192 # generate java classes
193 #
194
195 $(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java: \
196       $(RESOURCES_DIR)/WireFormatConstants.java.h \
197       $(BUILD_DIR_JNI)/c/library.h \
198       $(BUILD_DIR_JNI)/c/wireFormat.h
199         @echo "[generate] $@"
200         @$(CPP) -I "$(BUILD_DIR_JNI)/c" -DPLUGIN_VER=\"$(PLUGIN_VER)\" -DGIT_SHA=\"$(GIT_SHA)\" "$<" | \
201           sed -r -e '/^[[:space:]]*#.*$$/ d' \
202                  -e '/^[[:space:]]*$$/ d' \
203                  > "$@"
204
205
206 #
207 # generate jni includes
208 #
209
210 $(BUILD_DIR_JNI)/c/library.h: Makefile.inc
211         @echo "[generate] $@"
212         @echo "#define PUD_WIRE_FORMAT_LIBRARYNAME \"$(PROJECT)\"" > "$@"
213
214 $(BUILD_DIR_JNI)/c/wireFormat.h: $(INC_DIR_WIREFORMAT_FULL)/wireFormat.h
215         @echo "[generate] $@"
216         @grep -E '^[[:space:]]*#define[[:space:]]+' "$<" > "$@"
217
218
219 #
220 # Phony Targets
221 #
222
223 prepare:
224         @mkdir -p "$(BUILD_DIR)" \
225                   "$(LIBDIR_BUILD)" \
226                   "$(BUILD_DIR_JNI)/c"
227
228
229 clean: doc-clean
230         @echo "[$@]"
231         @rm -fr "$(BUILD_DIR)" "$(LIBDIR_BUILD)" \
232                 build.xml \
233                 "$(SRC_DIR_C)/$(JAVA_PKG_UNDER)_PositionUpdate.h" \
234                 "$(JAVASRC)/$(JAVA_PKG_DIR)/WireFormatConstants.java"
235
236 doc: build.xml
237         @$(MAKE) -C doc all
238         @ant -f build.xml javadoc
239
240 doc-clean:
241         @$(MAKE) -C doc clean
242
243 install: all
244         mkdir -v -p "$(LIBDIR)"
245         cp "$(LIBDIR_BUILD)/$(SONAME)" "$(LIBDIR)/$(SONAME).$(PLUGIN_VER)"
246         $(STRIP) "$(LIBDIR)/$(SONAME).$(PLUGIN_VER)"
247         /sbin/ldconfig -n "$(LIBDIR)"
248         mkdir -v -p "$(SHAREJAVADIR)"
249         cp -t "$(SHAREJAVADIR)" \
250       "$(LIBDIR_BUILD)/$(PROJECT).jar" \
251       "$(LIBDIR_BUILD)/$(PROJECT)-src.zip" \
252       "$(LIBDIR_BUILD)/$(PROJECT)-doc.zip"
253
254 uninstall:
255         rm -f "$(LIBDIR)/$(SONAME)" \
256               "$(LIBDIR)/$(SONAME).$(PLUGIN_VER)"
257         /sbin/ldconfig -n "$(LIBDIR)"
258         rmdir -v -p --ignore-fail-on-non-empty "$(LIBDIR)"
259         rm -f "$(SHAREJAVADIR)/$(PROJECT).jar" \
260           "$(SHAREJAVADIR)/$(PROJECT)-src.zip" \
261           "$(SHAREJAVADIR)/$(PROJECT)-doc.zip"
262         rmdir -v -p --ignore-fail-on-non-empty "$(SHAREJAVADIR)"
263
264 endif