From b502c4ecb7b5701026c315d7df6370918fb1fe3d Mon Sep 17 00:00:00 2001 From: YI Date: Thu, 19 Oct 2023 09:38:37 +0800 Subject: [PATCH] try to build lua-loader --- Makefile.clang | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Makefile.clang b/Makefile.clang index 02b81a2..e18dd21 100644 --- a/Makefile.clang +++ b/Makefile.clang @@ -11,9 +11,18 @@ OBJCOPY := llvm-objcopy${LLVM_SURFFIX} AR := llvm-ar${LLVM_SURFFIX} RANLIB := llvm-ranlib${LLVM_SURFFIX} -CFLAGS := -fPIC -O3 -fno-builtin -nostdinc -nostdlib -nostartfiles -fvisibility=hidden -fdata-sections -ffunction-sections -I lualib -I include/ckb-c-stdlib -I include/ckb-c-stdlib/libc -I include/ckb-c-stdlib/molecule -Wall -Werror -Wno-nonnull -Wno-nonnull-compare -Wno-unused-function -g +CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs +CFLAGS += -D__ISO_C_VISIBLE=1999 -DCKB_DECLARATION_ONLY -fPIC -g -O3 +CFLAGS += -fno-builtin-printf -fno-builtin-memcmp \ + -nostdinc -nostdlib\ + -fdata-sections -ffunction-sections -LDFLAGS := -nostdlib -nostartfiles -fno-builtin -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-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 DOCKER_USER := $(shell id -u):$(shell id -g) DOCKER_EXTRA_FLAGS ?= @@ -32,6 +41,10 @@ docker-interactive: 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/impl.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 liblua.a @@ -51,8 +64,8 @@ build/lua-loader.o: lua-loader/lua-loader.c # Note when -nostdlib is specified, libgcc is not linked to the program automatically. # Also note libgcc.a must be appended to the file list, simply -lgcc does not for some reason. # It seems gcc does not search libgcc in the install path. -build/lua-loader: build/lua-loader.o lualib/liblua.a - $(LD) $(LDFLAGS) -o $@ $^ $(shell $(CC) --print-search-dirs | sed -n '/install:/p' | sed 's/install:\s*//g')libgcc.a +build/lua-loader: build/lua-loader.o build/impl.o lualib/liblua.a deps/compiler-rt-builtins-riscv/build/libcompiler-rt.a + $(LD) $(LDFLAGS) -o $@ $^ cp $@ $@.debug $(OBJCOPY) --strip-debug --strip-all $@