This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
126 lines (108 loc) · 3.51 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
SHELL := /usr/bin/env bash
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
ifeq ($(OS), darwin)
JAVA_OS := $(OS)
LIB_PATH := DYLD_LIBRARY_PATH
LIBCRYPTOBOX_JNI := libcryptobox-jni.dylib
LIBCRYPTOBOX := libcryptobox.dylib
LIBSODIUM := libsodium.dylib
OPT_SONAME := -install_name
else ifneq ($(findstring mingw,$(OS)),)
JAVA_OS := win32
LIB_PATH := LD_LIBRARY_PATH
LIBCRYPTOBOX_JNI := cryptobox-jni.dll
LIBCRYPTOBOX := cryptobox.dll
LIBSODIUM := libsodium.dll
OPT_SONAME := -soname
else
JAVA_OS := $(OS)
LIB_PATH := LD_LIBRARY_PATH
LIBCRYPTOBOX_JNI := libcryptobox-jni.so
LIBCRYPTOBOX := libcryptobox.so
LIBSODIUM := libsodium.so
OPT_SONAME := -soname
endif
include mk/version.mk
.PHONY: all
all: compile
.PHONY: clean
clean:
rm -rf build/classes
rm -f build/lib/$(LIBCRYPTOBOX_JNI)
.PHONY: compile
compile: cryptobox compile-native compile-java
.PHONY: compile-native
compile-native:
$(CC) -std=c99 -g -Wall src/cryptobox-jni.c \
-I"${JAVA_HOME}/include" \
-I"${JAVA_HOME}/include/$(JAVA_OS)" \
-Ibuild/include \
-Lbuild/lib \
-lsodium \
-lcryptobox \
-shared \
-fPIC \
-Wl,$(OPT_SONAME),$(LIBCRYPTOBOX_JNI) \
-o build/lib/$(LIBCRYPTOBOX_JNI)
.PHONY: compile-java
compile-java:
mkdir -p build/classes
javac -d build/classes src/java/com/wire/cryptobox/*.java
.PHONY: doc
doc:
mkdir -p dist/javadoc
javadoc -Xdoclint:none -public -d dist/javadoc src/java/com/wire/cryptobox/*.java
.PHONY: distclean
distclean:
rm -rf build
rm -rf dist
.PHONY: dist
dist: compile doc
mkdir -p dist/lib
cp build/lib/$(LIBSODIUM) dist/lib/
cp build/lib/$(LIBCRYPTOBOX) dist/lib/
cp build/lib/$(LIBCRYPTOBOX_JNI) dist/lib/
jar -cvf dist/cryptobox-jni-$(VERSION).jar -C build/classes .
tar -C dist -czf dist/cryptobox-jni-$(OS)-$(ARCH)-$(VERSION).tar.gz lib javadoc cryptobox-jni-$(VERSION).jar
#############################################################################
# cryptobox
include mk/cryptobox-src.mk
.PHONY: cryptobox
cryptobox: build/lib/$(LIBCRYPTOBOX) build/include/cbox.h
build/lib/$(LIBCRYPTOBOX): libsodium | build/src/$(CRYPTOBOX_NAME)
mkdir -p build/lib
cd build/src/$(CRYPTOBOX_NAME) && \
PKG_CONFIG_PATH="$(CURDIR)/build/src/$(LIBSODIUM_NAME)/build/lib/pkgconfig:$$PKG_CONFIG_PATH" \
cargo rustc --lib --release -- \
-L ../../lib \
-l sodium \
-C link_args="-Wl,$(OPT_SONAME),$(LIBCRYPTOBOX)"
cp build/src/$(CRYPTOBOX_NAME)/target/release/$(LIBCRYPTOBOX) build/lib/$(LIBCRYPTOBOX)
# OSX name mangling
ifeq ($(OS), darwin)
install_name_tool -id "@loader_path/$(LIBCRYPTOBOX)" build/lib/$(LIBCRYPTOBOX)
endif
build/include/cbox.h: | build/src/$(CRYPTOBOX_NAME)
mkdir -p build/include
cp build/src/$(CRYPTOBOX_NAME)/src/cbox.h build/include/
#############################################################################
# libsodium
include mk/libsodium-src.mk
.PHONY: libsodium
libsodium: build/lib/$(LIBSODIUM)
build/lib/$(LIBSODIUM): build/src/$(LIBSODIUM_NAME)
mkdir -p build/lib
cd build/src/$(LIBSODIUM_NAME) && \
./configure --prefix="$(CURDIR)/build/src/$(LIBSODIUM_NAME)/build" \
--disable-soname-versions \
&& make -j3 && make install
ifneq ($(findstring mingw,$(OS)),)
cp build/src/$(LIBSODIUM_NAME)/build/bin/$(LIBSODIUM) build/lib/
else
cp build/src/$(LIBSODIUM_NAME)/build/lib/$(LIBSODIUM) build/lib/
endif
# OSX name mangling
ifeq ($(OS), darwin)
install_name_tool -id "@loader_path/$(LIBSODIUM)" build/lib/$(LIBSODIUM)
endif