Makefile 1.83 KB
Newer Older
1 2 3 4
ifndef JAVA_HOME
    $(error JAVA_HOME is required. Invoke with 'make JAVA_HOME=/path/to/java/home')
endif

5 6 7 8 9 10 11 12 13 14
unamem := $(shell uname -m)

ifeq ($(unamem),x86_64)
    JDKARCH := amd64
else ifeq ($(unamem),aarch64)
    JDKARCH := aarch64
else
    $(error Unsupported architecture: $(unamem))
endif

15
CFLAGS += -std=gnu11 -g -I $(JAVA_HOME)/include
Kunshan Wang's avatar
Kunshan Wang committed
16 17

ifndef OS
18
    uname := $(shell uname)
19 20 21 22
	ifeq ($(uname),Darwin)
		OS = OSX
    else ifeq ($(uname),Linux)
		OS = LINUX
Kunshan Wang's avatar
Kunshan Wang committed
23
    else
24
		$(error Unrecognized operating system $(uname). I currently only worked on OSX and Linux.)
Kunshan Wang's avatar
Kunshan Wang committed
25 26 27 28
    endif
endif

ifeq ($(OS),OSX)
29
	CFLAGS += -I $(JAVA_HOME)/include/darwin
Zixian Cai's avatar
Zixian Cai committed
30
	LDFLAGS += -L $(JAVA_HOME)/lib/jli -l jli -rpath $(JAVA_HOME)/lib/jli -install_name '@rpath/libmurefimpl2start.so'
31 32
else ifeq ($(OS),LINUX)
	CFLAGS += -I $(JAVA_HOME)/include/linux
33
	LDFLAGS += -Wl,--no-as-needed -L $(JAVA_HOME)/jre/lib/$(JDKARCH)/server -l jvm -Wl,-rpath,$(JAVA_HOME)/jre/lib/$(JDKARCH)/server
Kunshan Wang's avatar
Kunshan Wang committed
34 35
endif

36
.PHONY: all
Kunshan Wang's avatar
Kunshan Wang committed
37
all: libs tests
38

39 40 41 42
ifeq ($(OS),OSX)
.PHONY: libs
libs: libmurefimpl2start.so libmurefimpl2start.dylib
else
Kunshan Wang's avatar
Kunshan Wang committed
43 44
.PHONY: libs
libs: libmurefimpl2start.so
45
endif
Kunshan Wang's avatar
Kunshan Wang committed
46 47

libmurefimpl2start.so: refimpl2-start.c classpath.h
48 49
	$(CC) -fPIC -shared $(CFLAGS) -o $@ $< $(LDFLAGS)

50 51 52
libmurefimpl2start.dylib:
	ln -s libmurefimpl2start.so libmurefimpl2start.dylib

53
../classpath.txt: ../build.sbt
Kunshan Wang's avatar
Kunshan Wang committed
54 55
	cd .. ; sbt makeClasspathFile

56 57 58
classpath.h: ../classpath.txt
	cp ../classpath.txt ./
	xxd -i classpath.txt ./classpath.h
59

Kunshan Wang's avatar
Kunshan Wang committed
60
.PHONY: tests
61
tests: test_client test_client2
Kunshan Wang's avatar
Kunshan Wang committed
62 63

test_client: test_client.c libmurefimpl2start.so
Kunshan Wang's avatar
Kunshan Wang committed
64
	$(CC) `./refimpl2-config --istart --cflags --libs` -o $@ $<
Kunshan Wang's avatar
Kunshan Wang committed
65

66 67 68
test_client2: test_client2.c libmurefimpl2start.so
	$(CC) `./refimpl2-config --istart --cflags --libs` -o $@ $<

Kunshan Wang's avatar
Kunshan Wang committed
69
.PHONY: clean veryclean
70
clean:
71
	rm -f *.so test_client test_client2 *.dylib
Kunshan Wang's avatar
Kunshan Wang committed
72

73 74
veryclean: clean
	rm -f classpath.txt classpath.h ../classpath.txt