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