forked from cell-labs/cell-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
160 lines (149 loc) · 5.25 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
SHELL:=/bin/sh
MKFILE_PATH := ${abspath $(lastword $(MAKEFILE_LIST))}
MKFILE_DIR := $(dir $(MKFILE_PATH))
RELEASE_DIR := ${MKFILE_DIR}/output
# XUDT
MOLECULEC := moleculec
MOLECULEC2 := ${MKFILE_DIR}/third-party/molecule2-c2/target/release/moleculec-c2
CELL := ${RELEASE_DIR}/cell
# Color helper
# Reset
Color_Off := \033[0m
# Regular Colors
Red := \033[0;31m
Green := \033[0;32m
Yellow := \033[0;33m
Blue := \033[0;34m
White := \033[0;37m
>>> := ${Yellow}>>>
<<< := <<<${Color_Off}
.PHONY: clean antlr grammar dev build test test_cell_examples
clean:
# rm -rf internal/parser
# rm -rf internal/lexer
rm -rf output
rm -f third-party/ckb-c-stdlib/*.o
rm -f third-party/ckb-c-stdlib/*.a
grammar: antlr
all: ckb-libc build install
debug: ckb-libc build/debug install
antlr:
go generate ./...
dev:
go run main.go
fmt:
cd ${MKFILE_DIR} && go fmt ./...
build:
@echo " ${>>>} build ${<<<} "
make clean
git submodule update --init --recursive
make ckb-libc
go build -v -trimpath \
-o ${CELL} ./cmd/cell
@echo " ${>>>} sussecfully build cell ${<<<} "
build/debug:
go build -gcflags=all="-N -l" -o ${CELL} ./cmd/cell
sudt-c:
@echo " ${>>>} build sudt-c ${<<<} "
cd third-party/ckb-c-stdlib && \
clang --target=riscv64 \
-march=rv64imc \
-nostdlib \
-Wall -Werror -Wextra -Wno-unused-parameter -Wno-nonnull -fno-builtin-printf -fno-builtin-memcmp -O3 -fdata-sections -ffunction-sections \
-I libc \
-I molecule \
-I . \
../sudt.c \
-o sudt-c && \
cp sudt-c ../..
@echo " ${>>>} sussecfully build sudt-c ${<<<} "
molecule-xudt:
cd third-party/molecule2-c2 && cargo build --release
@echo "generate mol header files for xudt"
cd third-party/xudt && ${MOLECULEC} --language c --schema-file xudt_rce.mol > xudt_rce_mol.h
@echo "generate mol2 header files for xudt"
cd third-party/xudt && ${MOLECULEC} --language - --schema-file xudt_rce.mol --format json > blockchain_mol2.json
cd third-party/xudt && ${MOLECULEC2} --input blockchain_mol2.json | clang-format -style=Google > xudt_rce_mol2.h
xudt-c: molecule-xudt
cd third-party/xudt && make xudt-c
ckb-libc: ckb-libc-debug ckb-libc-release install
ckb-libc-debug:
@echo " ${>>>} build libdummylibc-debug.a ${<<<} "
cd third-party/ckb-c-stdlib && \
clang --target=riscv64 -v \
-march=rv64imc \
-nostdlib \
-Wall -Werror -Wextra -Wno-unused-parameter -Wno-nonnull -fno-builtin-printf -fno-builtin-memcmp -O3 -g -fdata-sections -ffunction-sections \
-I libc \
-I molecule \
-I . \
-I ../sparse-merkle-tree/c \
-c ../xudt/xudt.c \
-DCKB_C_STDLIB_PRINTF=1 \
-DCKB_PRINTF_DECLARATION_ONLY=1 && \
riscv64-unknown-elf-ar rcs libdummylibc-debug.a xudt.o
ckb-libc-release:
@echo " ${>>>} build libdummylibc.a ${<<<} "
cd third-party/ckb-c-stdlib && \
clang --target=riscv64 \
-march=rv64imc \
-nostdlib \
-Wall -Werror -Wextra -Wno-unused-parameter -Wno-nonnull -fno-builtin-printf -fno-builtin-memcmp -O3 -fdata-sections -ffunction-sections \
-I libc \
-I molecule \
-I . \
-I ../sparse-merkle-tree/c \
-c ../xudt/xudt.c && \
riscv64-unknown-elf-ar rcs libdummylibc.a xudt.o
install:
mkdir -p output/pkg
cp -r third-party/ckb-c-stdlib/libdummylibc-debug.a output/pkg
@echo " ${>>>} sussecfully install libdummylibc-debug.a ${<<<} "
cp -r third-party/ckb-c-stdlib/libdummylibc.a output/pkg
@echo " ${>>>} sussecfully install libdummylibc.a ${<<<} "
cp -r pkg/* output/pkg
@echo " ${>>>} sussecfully install stdlib ${<<<} "
@echo " ${>>>} manually run following command ${<<<} "
@echo "source ./install.sh"
test: unittest test/example
unittest:
@echo "unit test"
go mod tidy
git diff --exit-code go.mod go.sum
go mod verify
go test -v ${MKFILE_DIR}/compiler/lexer/*.go
go test -v ${MKFILE_DIR}/compiler/parser/*.go
# go test -v ${MKFILE_DIR}/compiler/passes/bigint/*.go
test/example:
@echo " ${>>>} test cell examples ${<<<} "
make build
${CELL} || true
${CELL} tests/examples/hi.cell && ./hi
${CELL} -d -t riscv tests/examples/always-true.cell && ckb-debugger --bin always-true
${CELL} -d -t riscv tests/examples/helloworld.cell && ckb-debugger --bin helloworld | grep "hello world! 0"
${CELL} -t riscv tests/examples/table.cell && ckb-debugger --bin table
${CELL} -t riscv tests/examples/cell-data.cell && ckb-debugger --bin cell-data
${CELL} -t riscv tests/examples/inputs.cell && ckb-debugger --bin inputs
${CELL} -t riscv tests/examples/outputs.cell && ckb-debugger --bin outputs
${CELL} -t riscv tests/examples/sudt.cell && ckb-debugger --bin sudt || true
${CELL} -t riscv tests/examples/multi-files && ckb-debugger --bin multi-files
${CELL} -t riscv tests/examples/import-package && ckb-debugger --bin import-package
${CELL} -t riscv tests/examples/brainfuck-vm.cell && ckb-debugger --bin brainfuck-vm
${CELL} -t riscv tests/examples/byte.cell && ckb-debugger --bin byte
${CELL} -t riscv tests/examples/xudt-data.cell && ckb-debugger --bin xudt-data
${CELL} -t riscv tests/examples/xudt.cell && ckb-debugger --bin xudt || true
test/cross:
@echo " ${>>>} test cross compiling ${<<<} "
@echo cross hi.ll with linking dummy.c
which clang
clang --target=riscv64 \
-march=rv64imc \
-Wno-override-module \
-ffunction-sections -fdata-sections \
-DCKB_C_STDLIB_PRINTF=1 \
-nostdlib \
-L output/pkg \
-ldummylibc-debug \
-Wl,--gc-sections \
-o main tests/examples/hi.ll
ckb-debugger --bin main