forked from nervosnetwork/ckb-lua-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.clang
71 lines (54 loc) · 2.59 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
CURRENT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
ifeq ($(origin LLVM_VERSION),undefined)
LLVM_VERSION = 16
endif
LLVM_SUFFIX = $(if $(LLVM_VERSION),-$(LLVM_VERSION),)
CC := clang${LLVM_SUFFIX}
LD := ld.lld${LLVM_SUFFIX}
OBJCOPY := llvm-objcopy${LLVM_SUFFIX}
AR := llvm-ar${LLVM_SUFFIX}
RANLIB := llvm-ranlib${LLVM_SUFFIX}
CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs
CFLAGS += -D__ISO_C_VISIBLE=1999 -DCKB_DECLARATION_ONLY -DCKB_MALLOC_DECLARATION_ONLY -DCKB_PRINTF_DECLARATION_ONLY -fPIC -g -O3
CFLAGS += -fno-builtin-printf -fno-builtin-memcmp \
-nostdinc -nostdlib\
-fdata-sections -ffunction-sections
CFLAGS += -I lualib -I lualib/c-stdlib -I include/ckb-c-stdlib -I include/ckb-c-stdlib/libc -I include/ckb-c-stdlib/molecule
CFLAGS += -I deps/compiler-rt-builtins-riscv/compiler-rt/lib/builtins
CFLAGS += -Wall -Werror -Wno-error=unused-command-line-argument -Wno-error=incompatible-library-redeclaration -Wno-error=invalid-noreturn -Wno-error=unused-function
LDFLAGS := -static --gc-sections
LDFLAGS += -Ldeps/compiler-rt-builtins-riscv/build -lcompiler-rt
all: lualib/liblua.a build/lua-loader build/spawnexample
deps/compiler-rt-builtins-riscv/build/libcompiler-rt.a:
cd deps/compiler-rt-builtins-riscv && $(MAKE) CC=$(CC) LD=$(LD) OBJCOPY=$(OBJCOPY) AR=$(AR) RANLIB=$(RANLIB)
build/stdlib.o: include/ckb-c-stdlib/libc/src/impl.c
@echo $(CC) $(filter-out -DCKB_DECLARATION_ONLY, $(CFLAGS)) -c -o $@ $<
@$(CC) $(filter-out -DCKB_DECLARATION_ONLY, $(CFLAGS)) -c -o $@ $<
lualib/liblua.a:
make -C lualib -f Makefile.clang CC=$(CC) liblua.a
build/spawnexample.o: examples/spawn.c
$(CC) -c $(CFLAGS) -o $@ $<
build/spawnexample: build/spawnexample.o build/stdlib.o deps/compiler-rt-builtins-riscv/build/libcompiler-rt.a
$(LD) $(LDFLAGS) -o $@ $^
cp $@ [email protected]
$(OBJCOPY) --strip-debug --strip-all $@
build/lua-loader.o: lua-loader/lua-loader.c
$(CC) -c $(CFLAGS) -o $@ $<
build/lua-loader: build/lua-loader.o build/stdlib.o lualib/liblua.a deps/compiler-rt-builtins-riscv/build/libcompiler-rt.a
$(LD) $(LDFLAGS) -o $@ $^
cp $@ [email protected]
$(OBJCOPY) --strip-debug --strip-all $@
fmt:
clang-format -style="{BasedOnStyle: google, IndentWidth: 4, SortIncludes: false}" -i lualib/*.c lualib/*.h lua-loader/*.h lua-loader/*.c include/*.c include/*.h tests/test_cases/*.c
clean-local:
rm -f build/*.o
rm -f build/lua-loader
rm -f build/lua-loader*
rm -f build/libckblua*
rm -f build/dylibtest
rm -f build/dylibexample
rm -f build/spawnexample*
clean: clean-local
make -C lualib clean
run-gdb:
riscv64-unknown-linux-gnu-gdb -ex "target remote 127.0.0.1:${PORT}" build/lua-loader.debug