-
Notifications
You must be signed in to change notification settings - Fork 5
/
contract.mk
72 lines (57 loc) · 1.55 KB
/
contract.mk
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
PREFIX ?= $(shell pwd)/dist
TARGET=wasm32-wasi
ifneq (, $(wildcard ./Cargo.toml))
CONTRACT_NAME=$(shell toml get -r Cargo.toml package.name | tr '-' '_')
SIDE_PROG_DIR=$(shell toml get -r Cargo.toml package.metadata.sideprog.path)
endif
ifneq (, $(SIDE_PROG_DIR))
SIDE_PROG=$(shell toml get -r Cargo.toml package.metadata.sideprog.name | tr '-' '_')
ifeq (, $(SIDE_PROG))
SIDE_PROG=$(shell toml get -r $(SIDE_PROG_DIR)/Cargo.toml package.name | tr '-' '_')
endif
SIDE_WASM=${SIDE_PROG_DIR}/target/${TARGET}/release/${SIDE_PROG}.wasm
endif
CONTRACT_OUTPUT=target/ink/${CONTRACT_NAME}.contract
all: ${CONTRACT_OUTPUT}
ifneq (, $(SIDE_PROG_DIR))
${CONTRACT_OUTPUT}: sideprog.wasm
endif
${CONTRACT_OUTPUT}: always-rerun
cargo check
cargo contract build --release
ifneq (, $(SIDE_PROG_DIR))
sideprog.wasm: ${SIDE_WASM}
cp ${SIDE_WASM} ./sideprog.wasm
wasm-strip sideprog.wasm
.PHONY: ${SIDE_WASM}
${SIDE_WASM}: always-rerun
cargo build --manifest-path ${SIDE_PROG_DIR}/Cargo.toml --release --target ${TARGET}
endif
.PHONY: install clean always-rerun
ifneq (, $(CONTRACT_NAME))
install: ${CONTRACT_OUTPUT}
mkdir -p ${PREFIX}
cp ${CONTRACT_OUTPUT} ${PREFIX}/${CONTRACT_NAME}.contract
ifneq (, $(SIDE_PROG_DIR))
cp sideprog.wasm ${PREFIX}/${CONTRACT_NAME}.sidevm.wasm
endif
clean:
rm -rf target/
ifneq (, $(SIDE_PROG_DIR))
rm -rf sideprog.wasm sideprog.wasm.hash
rm -rf ${SIDE_PROG_DIR}/target
endif
fmt:
cargo fmt
ifneq (, $(SIDE_PROG_DIR))
cd ${SIDE_PROG_DIR} && cargo fmt
endif
else
install:
make install
clean:
make clean
fmt:
make fmt
endif
always-rerun: