forked from RetricSu/nostr-binding
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
116 lines (101 loc) · 3.44 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
# 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 := --cfg debug_assertions
# 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)
# 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)
@set -eu; \
if [ "x$(CONTRACT)" = "x" ]; then \
for contract in $(wildcard contracts/*); do \
$(MAKE) -e -C $$contract build; \
done; \
else \
$(MAKE) -e -C contracts/$(CONTRACT) build; \
fi
# Run a single make task for a specific contract. For example:
#
# make run CONTRACT=stack-reorder TASK=adjust_stack_size STACK_SIZE=0x200000
TASK :=
run:
$(MAKE) -e -C 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); \
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); \
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
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 16
# Generate checksum info for reproducible build
CHECKSUM_FILE := build/checksums-$(MODE).txt
checksum: build
sha256sum build/$(MODE)/* > $(CHECKSUM_FILE)
.PHONY: build test check clippy fmt cargo clean prepare checksum