forked from antlinker/libmqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
65 lines (52 loc) · 2.04 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright Go-IIoT (https://github.com/goiiot)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
C_BUILD_DIR := ../c/build
BUILD_DIR := build
JAVA_PACKAGE := org.goiiot.libmqtt
JAVA_PACKAGE_PATH := org/goiiot/libmqtt
JAVA_HOME ?= /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
CFLAGS := -std=c++0x -I $(C_BUILD_DIR) -I build -L $(C_BUILD_DIR)
SRC_SET := libmqtt_jni.cpp handlers_jni.cpp options_jni.cpp
# detect build system for native build
HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
SYSTEM ?= $(HOST_SYSTEM)
# linux
ifeq ($(SYSTEM),Linux)
PLATFORM_FLAGS := -fPIC -shared -lpthread -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
SUFFIX=so
endif
# macOS
ifeq ($(SYSTEM),Darwin)
PLATFORM_FLAGS := -dynamiclib -framework JavaVM -framework CoreFoundation -framework Security -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
SUFFIX=jnilib
endif
.PHONY: build compile-java gen-jni-header clean
build: gen-jni-header
$(CC) $(CFLAGS) $(PLATFORM_FLAGS) -o $(BUILD_DIR)/libmqtt-jni.$(SUFFIX) -lmqtt $(SRC_SET)
gen-jni-header: compile-java
javah -jni -classpath $(BUILD_DIR) -d $(BUILD_DIR) $(JAVA_PACKAGE).LibMQTT
compile-java:
mkdir -p build
javac -Xlint:unchecked $(JAVA_PACKAGE_PATH)/LibMQTT.java -d $(BUILD_DIR)
run-example: compile-example
cd $(BUILD_DIR) && \
DYLD_LIBRARY_PATH=../$(C_BUILD_DIR) \
LD_LIBRARY_PATH=../$(C_BUILD_DIR) \
java -Djava.library.path=. \
$(JAVA_PACKAGE_PATH)/example/Example && \
cd ..
compile-example:
javac -Xdiags:verbose $(JAVA_PACKAGE_PATH)/example/Example.java -d $(BUILD_DIR)
clean:
rm -rf $(BUILD_DIR)