-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
134 lines (101 loc) · 3.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
# set default install prefix if not set
PREFIX ?= $(CURDIR)/build
K_INCLUDE ?= $(shell llvm-kompile --include-dir)
DESTDIR ?=
INSTALL_PREFIX ?= /usr/local
INSTALL_DIR := $(DESTDIR)$(INSTALL_PREFIX)
INSTALL_INCLUDE := $(INSTALL_DIR)/include/kframework
PLUGIN_NAMESPACE := blockchain-k-plugin
K_SOURCES := krypto.md
.PHONY: build
build: krypto
.PHONY: install
install: $(patsubst %, $(INSTALL_INCLUDE)/$(PLUGIN_NAMESPACE)/%, $(K_SOURCES))
$(INSTALL_INCLUDE)/$(PLUGIN_NAMESPACE)/%.md: plugin/%.md
@mkdir -p $(dir $@)
cp $< $@
.PHONY: clean
clean:
rm -rf */*.o */*/*.o build deps/libff/build
.PHONY: test
test: build
$(MAKE) -C krypto test-integration
# -----------
# libcryptopp
# -----------
.PHONY: libcryptopp
libcryptopp: $(PREFIX)/libcryptopp/lib/libcryptopp.a
$(PREFIX)/libcryptopp/lib/libcryptopp.a:
cd deps/cryptopp \
&& $(MAKE) CXXFLAGS="-DNDEBUG -g2 -O3 -fPIC" \
&& $(MAKE) install PREFIX=$(PREFIX)/libcryptopp
# -----
# libff
# -----
LIBFF_CMAKE_FLAGS += -DCMAKE_CXX_FLAGS=-fPIC -DWITH_PROCPS=OFF
# set OS specific defaults
ifeq ($(shell uname -s),Darwin)
# 1. OSX doesn't have /proc/ filesystem
# 2. fix cmake openssl detection for brew
SSL_ROOT ?= $(shell brew --prefix openssl)
LIBFF_CMAKE_FLAGS += -DOPENSSL_ROOT_DIR=$(SSL_ROOT)
else
# llvm-backend code doesn't play nice with g++
export CXX := $(if $(findstring default, $(origin CXX)), clang++, $(CXX))
endif
ifneq ($(APPLE_SILICON),)
LIBFF_CMAKE_FLAGS += -DCURVE=ALT_BN128 -DUSE_ASM=Off
endif
.PHONY: libff
libff: $(PREFIX)/libff/lib/libff.a
$(PREFIX)/libff/lib/libff.a:
cd deps/libff \
&& cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX)/libff $(LIBFF_CMAKE_FLAGS) \
&& $(MAKE) \
&& $(MAKE) install
# ------
# blake2
# ------
.PHONY: blake2
blake2: $(PREFIX)/blake2/lib/blake2.a
CXXFLAGS=-O3
ifeq ($(shell uname -p),x86_64)
$(PREFIX)/blake2/lib/blake2.a: CXXFLAGS+=-mavx2
endif
$(PREFIX)/blake2/lib/blake2.a: plugin-c/blake2-compress.o plugin-c/blake2-avx2.o plugin-c/blake2-generic.o
mkdir -p $(dir $@)
ar qs $@ $^
# --------
# plugin-c
# --------
INCLUDES := -I $(K_INCLUDE)/kllvm -I $(K_INCLUDE) -I $(PREFIX)/libcryptopp/include -I $(PREFIX)/libff/include -I dummy-version -I plugin -I plugin-c -I deps/cpp-httplib
ifneq ($(APPLE_SILICON),)
GMP_PREFIX ?= $(shell brew --prefix gmp)
MPFR_PREFIX ?= $(shell brew --prefix mpfr)
OPENSSL_PREFIX ?= $(shell brew --prefix openssl)
CRYPTOPP_PREFIX ?= $(shell brew --prefix [email protected])
SECP256K1_PREFIX ?= $(shell brew --prefix secp256k1)
BOOST_PREFIX ?= $(shell brew --prefix boost)
INCLUDES += -I $(GMP_PREFIX)/include -I $(MPFR_PREFIX)/include -I $(OPENSSL_PREFIX)/include -I $(CRYPTOPP_PREFIX)/include -I $(SECP256K1_PREFIX)/include -I $(BOOST_PREFIX)/include
endif
CPPFLAGS += --std=c++17 -fPIC -O3 $(INCLUDES)
plugin-c/%.o: plugin-c/%.cpp $(PREFIX)/libcryptopp/lib/libcryptopp.a $(PREFIX)/libff/lib/libff.a
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
$(PREFIX)/plugin/lib/plugin.a: plugin-c/crypto.o plugin-c/hash_ext.o plugin-c/json.o plugin-c/k.o plugin-c/plugin_util.o
mkdir -p $(dir $@)
ar r $@ $^
.PHONY: plugin
plugin: $(PREFIX)/plugin/lib/plugin.a
# ------
# krypto
# ------
$(PREFIX)/krypto/lib/krypto.a: $(PREFIX)/libff/lib/libff.a $(PREFIX)/libcryptopp/lib/libcryptopp.a $(PREFIX)/blake2/lib/blake2.a $(PREFIX)/plugin/lib/plugin.a
$(eval TMP := $(shell mktemp -d))
for lib in $^; do \
(cd $(TMP); ar x $$lib;) \
done
mkdir -p $(dir $@)
ar r $@ $(TMP)/*.o
rm -rf $(TMP)
.PHONY: krypto
krypto: $(PREFIX)/krypto/lib/krypto.a