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 1
/
Makefile
155 lines (130 loc) · 4.61 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
PROMETHEUS_AGENT := prometheus-agent.jar
CRYPTOBOX_4J := cryptobox4j.jar
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 prometheus-agent
.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: compile-native
export LD_LIBRARY_PATH="$(PWD)/build/lib"; \
mvn package -DskipTests -DargLine="-Djava.library.path=$$LD_LIBRARY_PATH";
.PHONY: verify-java
verify-java: compile-java
export LD_LIBRARY_PATH="$(PWD)/build/lib"; \
mvn test -DskipTests -DargLine="-Djava.library.path=$$LD_LIBRARY_PATH";
.PHONY: distclean
distclean:
rm -rf build
rm -rf dist
.PHONY: dist
dist: compile
mkdir -p dist/lib dist/jar
cp build/lib/$(LIBSODIUM) dist/lib
cp build/lib/$(LIBCRYPTOBOX) dist/lib
cp build/lib/$(LIBCRYPTOBOX_JNI) dist/lib
cp build/lib/$(PROMETHEUS_AGENT) dist/jar/
cp target/$(CRYPTOBOX_4J) dist/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
#############################################################################
# prometheus java agent
include mk/prometheus-agent-src.mk
.PHONY: prometheus-agent
prometheus-agent: build/lib/$(PROMETHEUS_AGENT)
build/lib/$(PROMETHEUS_AGENT): build/src/$(PROMETHEUS_AGENT_NAME)
mkdir -p build/lib
cd build/src/$(PROMETHEUS_AGENT_NAME)/jmx_prometheus_javaagent && mvn package;
cp build/src/$(PROMETHEUS_AGENT_NAME)/jmx_prometheus_javaagent/target/jmx_prometheus_javaagent-$(PROMETHEUS_AGENT_VERSION).jar build/lib/$(PROMETHEUS_AGENT)
#############################################################################
# list out folders from java.library.path
list-java-library:
@(cd src/test/java && javac JavaLib.java && java JavaLib JavaLib.class)
#############################################################################
# docker stuff
docker-build: docker-cryptobox docker-runtime
docker-cryptobox:
docker build --file dockerfiles/Dockerfile --target cryptobox --tag wirebot/cryptobox .
docker-runtime:
docker build --file dockerfiles/Dockerfile --target runtime --tag wirebot/runtime .