Skip to content

Commit

Permalink
try to build lua-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Oct 19, 2023
1 parent 130a4f2 commit b502c4e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Makefile.clang
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?=
Expand All @@ -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

Expand All @@ -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 $@ [email protected]
$(OBJCOPY) --strip-debug --strip-all $@

Expand Down

0 comments on commit b502c4e

Please sign in to comment.