Skip to content

Commit beb07a1

Browse files
authored
Makefile improvements for packaging (#402)
* Makefile, README: organize external library building * Makefile: put non-k dependencies before k dependencies * Makefile: allow linking against libraries in LIBRARY_PATH * Makefile: correct submodule path, enable updating submodule libprocps * Makefile: remove quotes * Makefile: add install target * Makefile: linking against lff requires libff_out * Makefile: quicker proof smoke test * Makefile: disclean leaves submodules alone * Makefile: update how INSTALL_DIR is calculated * README: update installation instructions
1 parent 792a343 commit beb07a1

File tree

2 files changed

+91
-60
lines changed

2 files changed

+91
-60
lines changed

Makefile

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export C_INCLUDE_PATH
1313
export CPLUS_INCLUDE_PATH
1414
export PKG_CONFIG_PATH
1515

16+
INSTALL_PREFIX:=/usr/local
17+
INSTALL_DIR?=$(DESTDIR)$(INSTALL_PREFIX)/bin
18+
1619
DEPS_DIR:=deps
1720
K_SUBMODULE:=$(abspath $(DEPS_DIR)/k)
1821
PLUGIN_SUBMODULE:=$(abspath $(DEPS_DIR)/plugin)
@@ -31,7 +34,7 @@ LUA_PATH:=$(PANDOC_TANGLE_SUBMODULE)/?.lua;;
3134
export TANGLER
3235
export LUA_PATH
3336

34-
.PHONY: all clean clean-submodules distclean \
37+
.PHONY: all clean clean-submodules distclean install \
3538
deps all-deps llvm-deps haskell-deps repo-deps system-deps k-deps ocaml-deps plugin-deps libsecp256k1 libff \
3639
build build-ocaml build-java build-node build-kore split-tests \
3740
defn java-defn ocaml-defn node-defn haskell-defn llvm-defn \
@@ -44,26 +47,57 @@ export LUA_PATH
4447

4548
all: build split-tests
4649

47-
clean: clean-submodules
50+
clean:
4851
rm -rf $(DEFN_DIR)
4952
git clean -dfx -- tests/specs
5053

51-
clean-submodules:
52-
rm -rf $(DEPS_DIR)/k/make.timestamp $(DEPS_DIR)/pandoc-tangle/make.timestamp $(DEPS_DIR)/metropolis/*.sty \
53-
tests/ethereum-tests/make.timestamp tests/proofs/make.timestamp $(DEPS_DIR)/plugin/make.timestamp
54-
5554
distclean: clean
5655
rm -rf $(BUILD_DIR)
56+
57+
clean-submodules: distclean
58+
rm -rf $(DEPS_DIR)/k/make.timestamp $(DEPS_DIR)/pandoc-tangle/make.timestamp $(DEPS_DIR)/metropolis/*.sty \
59+
tests/ethereum-tests/make.timestamp tests/proofs/make.timestamp $(DEPS_DIR)/plugin/make.timestamp \
60+
$(DEPS_DIR)/libff/build
5761
cd $(DEPS_DIR)/k && mvn clean --quiet
5862
cd $(DEPS_DIR)/secp256k1 && make distclean || true
59-
cd $(DEPS_DIR)/libff && rm -rf build
6063

61-
# Dependencies
62-
# ------------
64+
# Non-K Dependencies
65+
# ------------------
66+
67+
libsecp256k1_out:=$(LIBRARY_PATH)/pkgconfig/libsecp256k1.pc
68+
libff_out:=$(LIBRARY_PATH)/libff.a
69+
70+
libsecp256k1: $(libsecp256k1_out)
71+
libff: $(libff_out)
72+
73+
$(libsecp256k1_out):
74+
@echo "== submodule: $(DEPS_DIR)/secp256k1"
75+
git submodule update --init --recursive -- $(DEPS_DIR)/secp256k1
76+
cd $(DEPS_DIR)/secp256k1/ \
77+
&& ./autogen.sh \
78+
&& ./configure --enable-module-recovery --prefix="$(BUILD_LOCAL)" \
79+
&& make -s -j4 \
80+
&& make install
81+
82+
LIBFF_CC ?=clang-6.0
83+
LIBFF_CXX?=clang++-6.0
84+
85+
$(libff_out):
86+
@echo "== submodule: $(DEPS_DIR)/libff"
87+
git submodule update --init --recursive -- $(DEPS_DIR)/libff
88+
cd $(DEPS_DIR)/libff/ \
89+
&& mkdir -p build \
90+
&& cd build \
91+
&& CC=$(LIBFF_CC) CXX=$(LIBFF_CXX) cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(BUILD_LOCAL) \
92+
&& make -s -j4 \
93+
&& make install
94+
95+
# K Dependencies
96+
# --------------
6397

6498
all-deps: deps llvm-deps haskell-deps
6599
all-deps: BACKEND_SKIP=
66-
llvm-deps: $(BUILD_LOCAL)/lib/libff.a deps
100+
llvm-deps: $(libff_out) deps
67101
llvm-deps: BACKEND_SKIP=-Dhaskell.backend.skip
68102
haskell-deps: deps
69103
haskell-deps: BACKEND_SKIP=-Dllvm.backend.skip
@@ -97,41 +131,14 @@ ocaml-deps:
97131
eval $$(opam config env) \
98132
opam install --yes mlgmp zarith uuidm cryptokit secp256k1.0.3.2 bn128 ocaml-protoc rlp yojson hex ocp-ocamlres
99133

100-
# install secp256k1 from bitcoin-core
101-
libsecp256k1: $(BUILD_LOCAL)/lib/pkgconfig/libsecp256k1.pc
102-
103-
$(BUILD_LOCAL)/lib/pkgconfig/libsecp256k1.pc:
104-
@echo "== submodule: $(DEPS_DIR)/secp256k1"
105-
git submodule update --init -- $(DEPS_DIR)/secp256k1/
106-
cd $(DEPS_DIR)/secp256k1/ \
107-
&& ./autogen.sh \
108-
&& ./configure --enable-module-recovery --prefix="$(BUILD_LOCAL)" \
109-
&& make -s -j4 \
110-
&& make install
111-
112-
# install libff from scipr-lab
113-
libff: $(BUILD_LOCAL)/lib/libff.a
114-
115-
LIBFF_CC ?=clang-6.0
116-
LIBFF_CXX?=clang++-6.0
117-
118-
$(BUILD_LOCAL)/lib/libff.a:
119-
@echo "== submodule: $(DEPS_DIR)/libff"
120-
git submodule update --init --recursive -- $(DEPS_DIR)/libff/
121-
cd $(DEPS_DIR)/libff/ \
122-
&& mkdir -p build \
123-
&& cd build \
124-
&& CC=$(LIBFF_CC) CXX=$(LIBFF_CXX) cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$(BUILD_LOCAL)" \
125-
&& make -s -j4 \
126-
&& make install
127-
128134
# Building
129135
# --------
130136

131137
MAIN_MODULE:=ETHEREUM-SIMULATION
132138
SYNTAX_MODULE:=$(MAIN_MODULE)
133139
MAIN_DEFN_FILE:=driver
134140
KOMPILE_OPTS:=
141+
LLVM_KOMPILE_OPTS:=
135142

136143
ocaml_kompiled:=$(DEFN_DIR)/ocaml/$(MAIN_DEFN_FILE)-kompiled/interpreter
137144
java_kompiled:=$(DEFN_DIR)/java/$(MAIN_DEFN_FILE)-kompiled/timestamp
@@ -266,7 +273,7 @@ $(DEFN_DIR)/ocaml/$(MAIN_DEFN_FILE)-kompiled/interpreter: $(DEFN_DIR)/ocaml/$(MA
266273

267274
# Node Backend
268275

269-
$(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/interpreter: $(node_files) $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin/proto/msg.pb.cc
276+
$(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/interpreter: $(node_files) $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin/proto/msg.pb.cc $(libff_out)
270277
@echo "== kompile: $@"
271278
$(K_BIN)/kompile --debug --main-module $(MAIN_MODULE) --backend llvm \
272279
--syntax-module $(SYNTAX_MODULE) $(DEFN_DIR)/node/$(MAIN_DEFN_FILE).k \
@@ -275,29 +282,42 @@ $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/interpreter: $(node_files) $(DEFN_DI
275282
$(KOMPILE_OPTS) \
276283
-ccopt $(PLUGIN_SUBMODULE)/plugin-c/crypto.cpp -ccopt $(PLUGIN_SUBMODULE)/plugin-c/blockchain.cpp -ccopt $(PLUGIN_SUBMODULE)/plugin-c/world.cpp -ccopt $(CURDIR)/$(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin/proto/msg.pb.cc \
277284
-ccopt -I$(CURDIR)/$(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin \
285+
-ccopt -L$(LIBRARY_PATH) \
278286
-ccopt -lff -ccopt -lcryptopp -ccopt -lsecp256k1 -ccopt -lprocps -ccopt -lprotobuf -ccopt -g -ccopt -std=c++11 -ccopt -O2
279287

280288
$(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin/proto/msg.pb.cc: $(PLUGIN_SUBMODULE)/plugin/proto/msg.proto
281289
mkdir -p $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin
282290
protoc --cpp_out=$(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin -I $(PLUGIN_SUBMODULE)/plugin $(PLUGIN_SUBMODULE)/plugin/proto/msg.proto
283291

284-
$(node_kompiled): $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/interpreter
292+
$(node_kompiled): $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/interpreter $(libff_out)
285293
mkdir -p $(DEFN_DIR)/vm
286294
$(K_BIN)/llvm-kompile $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/definition.kore $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/dt library $(PLUGIN_SUBMODULE)/vm-c/main.cpp $(PLUGIN_SUBMODULE)/vm-c/vm.cpp \
287-
-I $(PLUGIN_SUBMODULE)/plugin-c/ -I $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin $(PLUGIN_SUBMODULE)/plugin-c/*.cpp $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin/proto/msg.pb.cc \
288-
-lff -lprotobuf -lgmp -lprocps -lcryptopp -lsecp256k1 -I $(PLUGIN_SUBMODULE)/vm-c/ -I $(PLUGIN_SUBMODULE)/vm-c/kevm/ -I node/ $(PLUGIN_SUBMODULE)/vm-c/kevm/semantics.cpp -o $(DEFN_DIR)/vm/kevm-vm -g -O2
295+
$(PLUGIN_SUBMODULE)/plugin-c/*.cpp $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin/proto/msg.pb.cc $(PLUGIN_SUBMODULE)/vm-c/kevm/semantics.cpp -o $@ -g -O2 \
296+
-I $(PLUGIN_SUBMODULE)/plugin-c/ -I $(DEFN_DIR)/node/$(MAIN_DEFN_FILE)-kompiled/plugin -I $(PLUGIN_SUBMODULE)/vm-c/ -I $(PLUGIN_SUBMODULE)/vm-c/kevm/ -I node/ \
297+
$(LLVM_KOMPILE_OPTS) \
298+
-L$(LIBRARY_PATH) \
299+
-lff -lprotobuf -lgmp -lprocps -lcryptopp -lsecp256k1
289300

290301
# LLVM Backend
291302

292-
$(llvm_kompiled): $(llvm_files)
303+
$(llvm_kompiled): $(llvm_files) $(libff_out)
293304
@echo "== kompile: $@"
294305
$(K_BIN)/kompile --debug --main-module $(MAIN_MODULE) --backend llvm \
295306
--syntax-module $(SYNTAX_MODULE) $(DEFN_DIR)/llvm/$(MAIN_DEFN_FILE).k \
296307
--directory $(DEFN_DIR)/llvm -I $(DEFN_DIR)/llvm -I $(DEFN_DIR)/llvm \
297308
--hook-namespaces KRYPTO \
298309
$(KOMPILE_OPTS) \
299310
-ccopt $(PLUGIN_SUBMODULE)/plugin-c/crypto.cpp \
300-
-ccopt -lff -ccopt -lcryptopp -ccopt -lsecp256k1 -ccopt -lprocps -ccopt -g -ccopt -std=c++11 -ccopt -O2
311+
-ccopt -g -ccopt -std=c++11 -ccopt -O2 \
312+
-ccopt -L$(LIBRARY_PATH) \
313+
-ccopt -lff -ccopt -lcryptopp -ccopt -lsecp256k1 -ccopt -lprocps
314+
315+
# Installing
316+
# ----------
317+
318+
install: $(node_kompiled)
319+
mkdir -p $(INSTALL_DIR)
320+
cp $(node_kompiled) $(INSTALL_DIR)/
301321

302322
# Tests
303323
# -----
@@ -358,8 +378,7 @@ smoke_tests_run=tests/ethereum-tests/VMTests/vmArithmeticTest/add0.json \
358378
tests/ethereum-tests/VMTests/vmIOandFlowOperations/pop1.json \
359379
tests/interactive/sumTo10.evm
360380

361-
smoke_tests_prove=tests/specs/examples/sum-to-n-spec.k \
362-
tests/specs/ds-token-erc20/transfer-failure-1-a-spec.k
381+
smoke_tests_prove=tests/specs/ds-token-erc20/transfer-failure-1-a-spec.k
363382

364383
# Conformance Tests
365384

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ These may be useful for learning KEVM and K (newest to oldest):
1515

1616
To get support for KEVM, please join our [Riot Room](https://riot.im/app/#/room/#k:matrix.org).
1717

18+
Repository Structure
19+
--------------------
20+
21+
The following files constitute the KEVM semantics:
22+
23+
- [krypto.md](krypto.md) sets up some basic cryptographic primitives.
24+
- [data.md](data.md) provides the (functional) data of EVM (256 bit words, wordstacks, etc...).
25+
- [network.md](network.md) provides the status codes which are reported to an Ethereum client on execution exceptions.
26+
- [evm.md](evm.md) is the main KEVM semantics, containing the configuration and transition rules of EVM.
27+
28+
These additional files extend the semantics to make the repository more useful:
29+
30+
- [driver.md](driver.md) is an execution harness for KEVM, providing a simple language for describing tests/programs.
31+
- [edsl.md](edsl.md) defines high-level notations of [eDSL], a domain-specific language for EVM specifications, for formal verification of EVM bytecode using [K Reachability Logic Prover].
32+
- [evm-node.md](evm-node.md) is the protobuf interface that an external Ethereum client can connect to for using KEVM as the execution engine.
33+
1834
Installing/Building
1935
-------------------
2036

@@ -92,6 +108,16 @@ make deps
92108
make build
93109
```
94110

111+
### Installing
112+
113+
To install the `kevm-vm` binary for use in Firefly and other full-nodes, do:
114+
115+
```sh
116+
make install
117+
```
118+
119+
You can set `DESTDIR` and `INSTALL_PREFIX` to change where the installation goes.
120+
95121
### OPTIONAL: K LLVM/Haskell Backends
96122

97123
The K LLVM/Haskell backends, currently under development, require extra dependencies to work.
@@ -152,20 +178,6 @@ make build-haskell
152178
make build-llvm
153179
```
154180

155-
This Repository
156-
---------------
157-
158-
The following files constitute the KEVM semantics:
159-
160-
- [krypto.md](krypto.md) sets up some basic cryptographic primitives.
161-
- [data.md](data.md) provides the (functional) data of EVM (256 bit words, wordstacks, etc...).
162-
- [evm.md](evm.md) is the main KEVM semantics, containing the configuration and transition rules of EVM.
163-
164-
These additional files extend the semantics to make the repository more useful:
165-
166-
- [driver.md](driver.md) is an execution harness for KEVM, providing a simple language for describing tests/programs.
167-
- [edsl.md](edsl.md) defines high-level notations of [eDSL], a domain-specific language for EVM specifications, for formal verification of EVM bytecode using [K Reachability Logic Prover].
168-
169181
Example Usage
170182
-------------
171183

0 commit comments

Comments
 (0)