Skip to content

Commit

Permalink
Canonicalize build targets and allow custom config
Browse files Browse the repository at this point in the history
In previous commits, there are some inconsistent build targets. It is
time to unify them:
  * Inside GNU make, conditions start with `BUILD_`.
  * Inside C source files, macros start with `ENABLE_`.

`build/local.mk` can be modified in advance, and new build system would
defer it for conditional build targets.
  • Loading branch information
jserv committed Mar 19, 2018
1 parent bf9f746 commit 3943709
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
OPENCL_LIB ?= /usr/local/cuda-9.1/lib64
SRC ?= ./src
OUT ?= ./build
DISABLE_GPU ?= 1
DISABLE_JNI ?= 1

CFLAGS = -Os -fPIC -g
LDFLAGS = -lpthread
PYFLAGS = --gpu_enable

-include $(OUT)/local.mk

# FIXME: avoid hardcoded architecture flags. We might support advanced SIMD
# instructions for Intel and Arm later.
CFLAGS += -msse2

ifneq ("$(DISABLE_GPU)","1")
ifeq ("$(BUILD_GPU)","1")
CFLAGS += \
-DENABLE_OPENCL \
-I$(OPENCL_PATH)/include
Expand All @@ -22,7 +22,7 @@ else
PYFLAGS += 0
endif

ifneq ("$(DISABLE_JNI)","1")
ifeq ("$(BUILD_JNI)","1")
include mk/java.mk
endif

Expand All @@ -32,7 +32,7 @@ TESTS = \
pow_sse \
multi_pow_cpu

ifneq ("$(DISABLE_GPU)","1")
ifeq ("$(BUILD_GPU)","1")
TESTS += \
pow_cl \
multi_pow_gpu
Expand All @@ -43,7 +43,7 @@ TESTS := $(addprefix $(OUT)/test-, $(TESTS))
LIBS = libdcurl.so
LIBS := $(addprefix $(OUT)/, $(LIBS))

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

OBJS = \
Expand All @@ -53,13 +53,13 @@ OBJS = \
dcurl.o \
pow_sse.o

ifneq ("$(DISABLE_GPU)","1")
ifeq ("$(BUILD_GPU)","1")
OBJS += \
pow_cl.o \
clcontext.o
endif

ifneq ("$(DISABLE_JNI)","1")
ifeq ("$(BUILD_JNI)","1")
OBJS += \
jni/iri-pearldiver-exlib.o
endif
Expand Down Expand Up @@ -101,6 +101,8 @@ check: $(addsuffix .done, $(TESTS))

clean:
$(RM) -r $(OUT)
distclean: clean
$(RM) local.mk

include mk/common.mk
-include $(deps)
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ Reference Implementation (IRI).
* Build a shared library for IRI, generating object files in directory `build`
* Generate JNI header file from downloading from [latest JAVA source](https://github.com/chenwei-tw/iri/tree/feat/new_pow_interface)
```shell
$ make DISABLE_JNI=0
$ make BUILD_JNI=1
```
You can modify `build/local.mk` for custom build options.
Alternatively, you can specify conditional build as following:
```shell
$ make DISABLE_GPU=1 DISABLE_JNI=1
$ make BUILD_GPU=0 BUILD_JNI=1
```

# Test
* Make a test with GPU

```$ make check DISABLE_GPU=0```
* Test with GPU
```shell
$ make BUILD_GPU=1 check
```

* Expected Results

Expand Down
7 changes: 7 additions & 0 deletions mk/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ ifeq ($(UNAME_S),Darwin)
else
PRINTF = env printf
endif

config: $(OUT)/config-timestamp

$(OUT)/config-timestamp: $(OUT)/local.mk
$(Q)touch $@
$(OUT)/local.mk:
$(Q)cp -f mk/defs.mk $@
5 changes: 5 additions & 0 deletions mk/defs.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Build OpenCL backend or not
BUILD_GPU ?= 0

# Build JNI glue as the bridge between dcurl and IRI
BUILD_JNI ?= 0

0 comments on commit 3943709

Please sign in to comment.