forked from cryptape/ckb-auth
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile.clang
152 lines (132 loc) · 5.05 KB
/
Makefile.clang
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
CC := clang-16
LD := ld.lld-16
OBJCOPY := llvm-objcopy-16
AR := llvm-ar-16
RANLIB := llvm-ranlib-16
LLVM_CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs \
-Wno-error=unused-but-set-variable \
-Wno-error=unused-command-line-argument \
-Wno-error=bitwise-instead-of-logical
LLVM_AUTH_CFLAGS := -DCKB_NO_ENTRY_GP
LDFLAGS := -static -Wl,--gc-sections
AUTH_DYN_LIST := --dynamic-list c/auth.syms
CFLAGS := -g -O3 -fPIC \
-Wall -Werror -Wno-nonnull -Wno-unused-function \
-fno-builtin-printf -fno-builtin-memcmp \
-nostdinc -nostdlib -fvisibility=hidden \
-fdata-sections -ffunction-sections \
$(GCC_CFLAGS) $(LLVM_CFLAGS)
INCLUDE_SECP256K1_CFLAGS = \
-I deps/secp256k1-20210801/src -I deps/secp256k1-20210801
INCLUDE_CKB_STD_CFLAGS = \
-I deps/ckb-c-stdlib-2023 -I deps/ckb-c-stdlib-2023/libc -I deps/ckb-c-stdlib-2023/molecule
INCLUDE_CFLAGS := $(INCLUDE_SECP256K1_CFLAGS) $(INCLUDE_CKB_STD_CFLAGS) \
-I c -I build -I deps/mbedtls/include -I deps/ed25519/src -I c/cardano/nanocbor
AUTH_CFLAGS := $(CFLAGS) $(INCLUDE_CFLAGS) -Wno-array-bounds
PASSED_MBEDTLS_CFLAGS := $(CFLAGS) -DCKB_DECLARATION_ONLY -I ../../ckb-c-stdlib-2023/libc
SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h
CFLAGS_LIBECC := $(CFLAGS) \
-DUSER_NN_BIT_LEN=256 -DWORDSIZE=64 -DWITH_STDLIB -DWITH_CKB -DCKB_DECLARATION_ONLY \
-Wno-unused-variable
LIBECC_OPTIMIZED_PATH := deps/libecc
LIBECC_OPTIMIZED_FILES := \
${LIBECC_OPTIMIZED_PATH}/build/libarith.a \
${LIBECC_OPTIMIZED_PATH}/build/libec.a \
${LIBECC_OPTIMIZED_PATH}/build/libsign.a
CFLAGS_LIBECC_OPTIMIZED = \
-I ../ckb-c-stdlib-2023 \
-I ../ckb-c-stdlib-2023/libc \
-I ../ckb-c-stdlib-2023/molecule \
$(CFLAGS_LIBECC) \
-DWITH_LL_U256_MONT
CFLAGS_LINK_TO_LIBECC_OPTIMIZED := \
-DWORDSIZE=64 -DWITH_STDLIB -DWITH_CKB \
-I ${LIBECC_OPTIMIZED_PATH}/src -I ${LIBECC_OPTIMIZED_PATH}/src/external_deps
all: \
build/secp256k1_data_info_20210801.h \
$(SECP256K1_SRC_20210801) \
deps/mbedtls/library/libmbedcrypto.a \
build/auth_libecc \
build/auth \
build/always_success
build/always_success: c/always_success.c
$(CC) $(AUTH_CFLAGS) $(LDFLAGS) -o $@ $<
$(OBJCOPY) --only-keep-debug $@ [email protected]
$(OBJCOPY) --strip-debug --strip-all $@
build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801
$<
build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801)
mkdir -p build
gcc -I deps/ckb-c-stdlib-2023 -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $<
$(SECP256K1_SRC_20210801):
cd deps/secp256k1-20210801 && \
./autogen.sh && \
CC=$(CC) LD=$(LD) ./configure --with-asm=no \
--enable-ecmult-static-precomputation --with-ecmult-window=6 --enable-module-recovery \
&& \
make src/ecmult_static_pre_context.h src/ecmult_static_context.h
$(LIBECC_OPTIMIZED_FILES): libecc
libecc:
make -C ${LIBECC_OPTIMIZED_PATH} LIBECC_WITH_LL_U256_MONT=1 \
CC=${CC} LD=${LD} AR=$(AR) RANLIB=$(RANLIB) CFLAGS="$(CFLAGS_LIBECC_OPTIMIZED)"
deps/mbedtls/library/libmbedcrypto.a:
cp deps/mbedtls-config-template.h deps/mbedtls/include/mbedtls/config.h
make -C deps/mbedtls/library \
APPLE_BUILD=0 AR=$(AR) CC=${CC} LD=${LD} CFLAGS="${PASSED_MBEDTLS_CFLAGS}" \
libmbedcrypto.a
build/nanocbor/%.o: c/cardano/nanocbor/%.c
mkdir -p build/nanocbor
$(CC) -c -DCKB_DECLARATION_ONLY -I c/cardano -I c/cardano/nanocbor $(AUTH_CFLAGS) -o $@ $^
build/libnanocbor.a: build/nanocbor/encoder.o build/nanocbor/decoder.o
$(AR) cr $@ $^
build/ed25519/%.o: deps/ed25519/src/%.c
mkdir -p build/ed25519
$(CC) -c -DCKB_DECLARATION_ONLY $(AUTH_CFLAGS) -o $@ $^
build/libed25519.a: \
build/ed25519/sign.o \
build/ed25519/verify.o \
build/ed25519/sha512.o \
build/ed25519/sc.o \
build/ed25519/keypair.o \
build/ed25519/key_exchange.o \
build/ed25519/ge.o \
build/ed25519/fe.o \
build/ed25519/add_scalar.o
$(AR) cr $@ $^
build/auth: \
c/auth.c \
c/cardano/cardano_lock_inc.h \
c/ripple.h \
deps/mbedtls/library/libmbedcrypto.a \
build/libed25519.a \
build/libnanocbor.a
$(CC) $(AUTH_CFLAGS) $(LLVM_AUTH_CFLAGS) -c -o [email protected] c/auth.c
$(LD) --shared --gc-sections $(AUTH_DYN_LIST) \
-o $@ \
deps/mbedtls/library/libmbedcrypto.a \
build/libed25519.a \
build/libnanocbor.a
cp $@ [email protected]
$(OBJCOPY) --strip-debug --strip-all $@
ls -lh $@
build/auth_libecc: c/auth_libecc.c $(LIBECC_OPTIMIZED_FILES)
$(CC) $(AUTH_CFLAGS) $(LLVM_AUTH_CFLAGS) $(CFLAGS_LINK_TO_LIBECC_OPTIMIZED) -c -o [email protected] c/auth_libecc.c
$(LD) --shared --gc-sections $(AUTH_DYN_LIST) \
-o $@ \
$(LIBECC_OPTIMIZED_FILES)
cp $@ [email protected]
$(OBJCOPY) --strip-debug --strip-all $@
ls -lh $@
fmt:
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 4}" c/*.c c/*.h
clean:
rm -rf build/*.debug
rm -f build/auth build/auth_libecc build/auth_c_lock build/auth-rust-demo
rm -rf build/secp256k1_data_info_20210801.h build/dump_secp256k1_data_20210801
rm -rf build/ed25519 build/libed25519.a build/nanocbor build/libnanocbor.a
cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean
make -C deps/mbedtls/library clean
make -C deps/libecc clean
.PHONY: all