Skip to content

Commit

Permalink
Merge pull request #18 from jserv/java-integration
Browse files Browse the repository at this point in the history
Better Java integration
  • Loading branch information
WEI, CHEN committed Mar 19, 2018
2 parents 412d634 + a4ba8bf commit dff5cd8
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 87 deletions.
19 changes: 2 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
OPENCL_LIB ?= /usr/local/cuda-9.1/lib64
OPENJDK_PATH ?= $(shell readlink -f /usr/bin/javac | sed "s:bin/javac::")
SRC ?= ./src
OUT ?= ./build
DISABLE_GPU ?= 1
Expand All @@ -24,18 +23,7 @@ PYFLAGS += 0
endif

ifneq ("$(DISABLE_JNI)","1")
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
JAVA_HOME := $(shell /usr/libexec/java_home)
CFLAGS_JNI = \
-I$(JAVA_HOME)/include \
-I$(JAVA_HOME)/include/darwin
else
# Default to Linux
CFLAGS_JNI = \
-I$(OPENJDK_PATH)/include \
-I$(OPENJDK_PATH)/include/linux
endif
include mk/java.mk
endif

TESTS = \
Expand All @@ -54,6 +42,7 @@ LIBS = libdcurl.so
LIBS := $(addprefix $(OUT)/, $(LIBS))

all: $(TESTS) $(LIBS)
.DEFAULT_GOAL := all

OBJS = \
hash/curl.o \
Expand Down Expand Up @@ -87,10 +76,6 @@ $(OUT)/test_%.o: test/test_%.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -c -MMD -MF $@.d $<

$(OUT)/jni/%.o: jni/%.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) $(CFLAGS_JNI) -c -MMD -MF $@.d $<

$(OUT)/trinary/%.o: $(SRC)/trinary/%.c
$(OUT)/hash/%.o: $(SRC)/hash/%.c
$(OUT)/%.o: $(SRC)/%.c
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Reference Implementation (IRI).

# Warning
* You need to configure OpenCL platform and device by yourself in ```src/clcontext.c```
* You also need to configure path of OpenCL Library and OpenJDK in ```Makefile```
* You need to configure paths and flags of OpenCL installation in ```Makefile```
* Check JDK installation and set JAVA_HOME if you wish to specify.
* Only one GPU can be facilitated with dcurl at the moment.

# Build
Expand Down
69 changes: 0 additions & 69 deletions jni/iri-pearldiver-exlib.h

This file was deleted.

61 changes: 61 additions & 0 deletions mk/java.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
UNAME_S := $(shell uname -s)

# if JAVA_HOME is not set, guess it according to system configurations
ifndef JAVA_HOME
ifeq ($(UNAME_S),Darwin)
# macOS
JAVA_HOME := $(shell /usr/libexec/java_home)
else
# Default to Linux
JAVAC := $(shell which javac)
ifndef JAVAC
$(error "javac is not available. Please check JDK installation")
endif
JAVA_HOME := $(shell readlink -f $(JAVAC) | sed "s:bin/javac::")
endif
endif # JAVA_HOME

JAVAH = javah
ifdef JAVA_HOME
JAVAH = $(JAVA_HOME)/bin/javah
endif
JAVAH := $(shell which $(JAVAH))
ifndef JAVAH
$(error "javah is not available. Please check JDK installation")
endif

CURL := $(shell which curl)
ifndef CURL
$(error "curl is not available.")
endif

SHELL_HACK := $(shell mkdir -p $(OUT)/com/iota/iri/hash)

GITHUB_REPO ?= chenwei-tw/iri/feat/new_pow_interface
PearlDriverSRC := src/main/java/com/iota/iri/hash/PearlDiver.java

$(OUT)/com/iota/iri/hash/PearlDiver.java: $(OUT)/com/iota/iri/hash
$(VECHO) " CURL\t$@\n"
$(Q)$(CURL) -s -o $@ \
"https://github.com/raw/$(GITHUB_REPO)/$(PearlDriverSRC)"

$(OUT)/jni/iri-pearldiver-exlib.h: $(OUT)/com/iota/iri/hash/PearlDiver.java
$(VECHO) " JAVAH\t$@\n"
$(Q)$(JAVAH) -classpath $(OUT) -o $@ com.iota.iri.hash.PearlDiver

ifeq ($(UNAME_S),Darwin)
# macOS
CFLAGS_JNI := -I$(JAVA_HOME)/include/darwin
else
# Default to Linux
CFLAGS_JNI := -I$(JAVA_HOME)/include/linux
endif

CFLAGS_JNI += -I$(JAVA_HOME)/include
CFLAGS_JNI += -I$(OUT)/jni

jni/iri-pearldiver-exlib.c: $(OUT)/jni/iri-pearldiver-exlib.h

$(OUT)/jni/%.o: jni/%.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) $(CFLAGS_JNI) -c -MMD -MF $@.d $<

0 comments on commit dff5cd8

Please sign in to comment.