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