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