This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
88 lines (70 loc) · 2.92 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
TARGET := riscv64-unknown-elf
CC := $(TARGET)-gcc
LD := $(TARGET)-gcc
OBJCOPY := $(TARGET)-objcopy
CFLAGS := -nostartfiles -O3 -Ideps/molecule -I deps/ckb-c-std-lib -I deps/ckb-c-std-lib/libc -I c -I build -Wall -Werror -Wno-nonnull-compare -Wno-unused-function -g
LDFLAGS := -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-sections
MOLC := moleculec
MOLC_VERSION := 0.4.1
PROTOCOL_HEADER := c/protocol.h
PROTOCOL_SCHEMA := c/blockchain.mol
PROTOCOL_VERSION := d75e4c56ffa40e17fd2fe477da3f98c5578edcd1
PROTOCOL_URL := https://raw.githubusercontent.com/nervosnetwork/ckb/${PROTOCOL_VERSION}/util/types/schemas/blockchain.mol
# docker pull nervos/ckb-riscv-gnu-toolchain:bionic-20190702
BUILDER_DOCKER := nervos/ckb-riscv-gnu-toolchain@sha256:7b168b4b109a0f741078a71b7c4dddaf1d283a5244608f7851f5714fbad273ba
build:
# build custodian_lock
make all-via-docker
cargo build
# build dao_lock
make all-via-docker
cargo build
# build dckb
make all-via-docker
cargo build
make fmt
all: specs/cells/dckb specs/cells/dao_lock specs/cells/custodian_lock specs/cells/always_success
all-via-docker: ${PROTOCOL_HEADER}
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make all"
specs/cells/always_success: c/always_success.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $(subst specs/cells,build,$@.debug)
$(OBJCOPY) --strip-debug --strip-all $@
specs/cells/dckb: c/dckb.c ${PROTOCOL_HEADER} c/common.h c/dao_lock.h c/dao_utils.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $(subst specs/cells,build,$@.debug)
$(OBJCOPY) --strip-debug --strip-all $@
specs/cells/dao_lock: c/dao_lock.c ${PROTOCOL_HEADER} c/common.h c/custodian_lock.h c/dao_utils.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $(subst specs/cells,build,$@.debug)
$(OBJCOPY) --strip-debug --strip-all $@
specs/cells/custodian_lock: c/custodian_lock.c ${PROTOCOL_HEADER} c/common.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $(subst specs/cells,build,$@.debug)
$(OBJCOPY) --strip-debug --strip-all $@
generate-protocol: check-moleculec-version ${PROTOCOL_HEADER}
check-moleculec-version:
test "$$(${MOLC} --version | awk '{ print $$2 }' | tr -d ' ')" = ${MOLC_VERSION}
${PROTOCOL_HEADER}: ${PROTOCOL_SCHEMA}
${MOLC} --language c --schema-file $< > $@
${PROTOCOL_SCHEMA}:
curl -L -o $@ ${PROTOCOL_URL}
install-tools:
if [ ! -x "$$(command -v "${MOLC}")" ] \
|| [ "$$(${MOLC} --version | awk '{ print $$2 }' | tr -d ' ')" != "${MOLC_VERSION}" ]; then \
cargo install --force --version "${MOLC_VERSION}" "${MOLC}"; \
fi
clean:
rm -rf specs/cells/always_success
rm -rf specs/cells/dckb
rm -rf specs/cells/dao_lock
rm -rf specs/cells/custodian_lock
rm -rf build/*.debug
cargo clean
dist: clean all
fmt:
clang-format -i -style=Google $(wildcard *.h */*.h *.c */*.c)
check-fmt:
make fmt
git diff --exit-code
.PHONY: all all-via-docker dist clean fmt check-fmt build