-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
136 lines (119 loc) · 4.15 KB
/
Makefile
File metadata and controls
136 lines (119 loc) · 4.15 KB
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
# We cannot use $(shell pwd), which will return unix path format on Windows,
# making it hard to use.
cur_dir = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TOP := $(cur_dir)
# RUSTFLAGS that are likely to be tweaked by developers. For example,
# while we enable debug logs by default here, some might want to strip them
# for minimal code size / consumed cycles.
CUSTOM_RUSTFLAGS :=
# Additional cargo args to append here. For example, one can use
# make test CARGO_ARGS="-- --nocapture" so as to inspect data emitted to
# stdout in unit tests
CARGO_ARGS :=
MODE := release
# Tweak this to change the clang version to use for building C code. By default
# we use a bash script with somes heuristics to find clang in current system.
CLANG := $(shell $(TOP)/scripts/find_clang)
# When this is set, a single contract will be built instead of all contracts
CONTRACT :=
# By default, we would clean build/{release,debug} folder first, in case old
# contracts are mixed together with new ones, if for some reason you want to
# revert this behavior, you can change this to anything other than true
CLEAN_BUILD_DIR_FIRST := true
BUILD_DIR := build/$(MODE)
ifeq (release,$(MODE))
MODE_ARGS := --release
endif
# Pass setups to child make processes
export CUSTOM_RUSTFLAGS
export TOP
export CARGO_ARGS
export MODE
export CLANG
export BUILD_DIR
default: build test
build:
@if [ "x$(CLEAN_BUILD_DIR_FIRST)" = "xtrue" ]; then \
echo "Cleaning $(BUILD_DIR) directory..."; \
rm -rf $(BUILD_DIR); \
fi
mkdir -p $(BUILD_DIR)
@echo "Building ckb_deterministic library..."
cargo build -p ckb_deterministic $(MODE_ARGS) $(CARGO_ARGS)
build-contracts:
@echo "Building shared libraries..."
cargo build -p deterministic-cdp-shared $(MODE_ARGS) $(CARGO_ARGS)
@echo "Building example contracts for RISC-V target..."
@set -eu; \
if [ "x$(CONTRACT)" = "x" ]; then \
for contract in $(wildcard example_contracts/*); do \
if [ -f "$$contract/Makefile" ]; then \
$(MAKE) -e -C $$contract build; \
fi \
done; \
else \
$(MAKE) -e -C example_contracts/$(CONTRACT) build; \
fi
# Run a single make task for a specific contract. For example:
#
# make run CONTRACT=deterministic_cdp_project TASK=build
TASK :=
run:
$(MAKE) -e -C example_contracts/$(CONTRACT) $(TASK)
# test, check, clippy and fmt here are provided for completeness,
# there is nothing wrong invoking cargo directly instead of make.
test:
cargo test $(CARGO_ARGS)
check:
cargo check $(CARGO_ARGS)
clippy:
cargo clippy $(CARGO_ARGS)
fmt:
cargo fmt $(CARGO_ARGS)
# Arbitrary cargo command is supported here. For example:
#
# make cargo CARGO_CMD=expand CARGO_ARGS="--ugly"
#
# Invokes:
# cargo expand --ugly
CARGO_CMD :=
cargo:
cargo $(CARGO_CMD) $(CARGO_ARGS)
clean:
rm -rf build
cargo clean
TEMPLATE_TYPE := --git
TEMPLATE_REPO := https://github.com/cryptape/ckb-script-templates
CRATE :=
TEMPLATE := contract
DESTINATION := contracts
generate:
@set -eu; \
if [ "x$(CRATE)" = "x" ]; then \
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) $(TEMPLATE) \
--destination $(DESTINATION); \
GENERATED_DIR=$$(ls -dt $(DESTINATION)/* | head -n 1); \
if [ -f "$$GENERATED_DIR/.cargo-generate/tests.rs" ]; then \
cat $$GENERATED_DIR/.cargo-generate/tests.rs >> tests/src/tests.rs; \
rm -rf $$GENERATED_DIR/.cargo-generate/; \
fi; \
sed "s,@@INSERTION_POINT@@,@@INSERTION_POINT@@\n \"$$GENERATED_DIR\"\,," Cargo.toml > Cargo.toml.new; \
mv Cargo.toml.new Cargo.toml; \
else \
cargo generate $(TEMPLATE_TYPE) $(TEMPLATE_REPO) $(TEMPLATE) \
--destination $(DESTINATION) \
--name $(CRATE); \
if [ -f "$(DESTINATION)/$(CRATE)/.cargo-generate/tests.rs" ]; then \
cat $(DESTINATION)/$(CRATE)/.cargo-generate/tests.rs >> tests/src/tests.rs; \
rm -rf $(DESTINATION)/$(CRATE)/.cargo-generate/; \
fi; \
sed '/@@INSERTION_POINT@@/s/$$/\n "$(DESTINATION)\/$(CRATE)",/' Cargo.toml > Cargo.toml.new; \
mv Cargo.toml.new Cargo.toml; \
fi
prepare:
rustup target add riscv64imac-unknown-none-elf
# Generate checksum info for reproducible build
CHECKSUM_FILE := build/checksums-$(MODE).txt
checksum: build
shasum -a 256 build/$(MODE)/* > $(CHECKSUM_FILE)
.PHONY: build build-contracts test check clippy fmt cargo clean prepare checksum