-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
96 lines (76 loc) · 3.62 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
TARGET := riscv64-unknown-elf
CC := $(TARGET)-gcc
LD := $(TARGET)-gcc
OBJCOPY := $(TARGET)-objcopy
CFLAGS := -O3 -Ideps/molecule -I deps/secp256k1/src -I deps/secp256k1 -I c -I build -Wall -Werror -Wno-nonnull-compare -Wno-unused-function -g
LDFLAGS := -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-sections
SECP256K1_SRC := deps/secp256k1/src/ecmult_static_pre_context.h
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
all: specs/cells/secp256k1_blake160_sighash_all specs/cells/dao specs/cells/secp256k1_blake160_multisig_all
all-via-docker: ${PROTOCOL_HEADER}
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make"
specs/cells/secp256k1_blake160_sighash_all: c/secp256k1_blake160_sighash_all.c ${PROTOCOL_HEADER} c/common.h c/utils.h build/secp256k1_data_info.h $(SECP256K1_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $(subst specs/cells,build,[email protected])
$(OBJCOPY) --strip-debug --strip-all $@
specs/cells/secp256k1_blake160_multisig_all: c/secp256k1_blake160_multisig_all.c ${PROTOCOL_HEADER} c/common.h c/utils.h build/secp256k1_data_info.h $(SECP256K1_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $(subst specs/cells,build,[email protected])
$(OBJCOPY) --strip-debug --strip-all $@
specs/cells/dao: c/dao.c ${PROTOCOL_HEADER}
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ $(subst specs/cells,build,[email protected])
$(OBJCOPY) --strip-debug --strip-all $@
build/secp256k1_data_info.h: build/dump_secp256k1_data
$<
build/dump_secp256k1_data: c/dump_secp256k1_data.c $(SECP256K1_SRC)
mkdir -p build
gcc $(CFLAGS) -o $@ $<
$(SECP256K1_SRC):
cd deps/secp256k1 && \
./autogen.sh && \
CC=$(CC) LD=$(LD) ./configure --with-bignum=no --enable-ecmult-static-precomputation --enable-endomorphism --enable-module-recovery --host=$(TARGET) && \
make src/ecmult_static_pre_context.h src/ecmult_static_context.h
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
publish:
git diff --exit-code Cargo.toml
sed -i.bak 's/.*git =/# &/' Cargo.toml
cargo publish --allow-dirty
git checkout Cargo.toml Cargo.lock
rm -f Cargo.toml.bak
package:
git diff --exit-code Cargo.toml
sed -i.bak 's/.*git =/# &/' Cargo.toml
cargo package --allow-dirty
git checkout Cargo.toml Cargo.lock
rm -f Cargo.toml.bak
package-clean:
git checkout Cargo.toml Cargo.lock
rm -rf Cargo.toml.bak target/package/
clean:
rm -rf specs/cells/secp256k1_blake160_sighash_all specs/cells/dao specs/cells/secp256k1_blake160_multisig_all
rm -rf build/secp256k1_data_info.h build/dump_secp256k1_data
rm -rf specs/cells/secp256k1_data
rm -rf build/*.debug
cd deps/secp256k1 && [ -f "Makefile" ] && make clean
cargo clean
dist: clean all
.PHONY: all all-via-docker dist clean package-clean package publish