From 0960df714d626b7963f7544cc2df5aa1a6863d5b Mon Sep 17 00:00:00 2001 From: Thomas Oltmann Date: Sat, 15 Mar 2025 23:33:20 +0100 Subject: [PATCH] Compiling lua without a C standard library --- libc/include/string.h | 14 ++++++++++++++ lua/src/Makefile | 7 ++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 libc/include/string.h diff --git a/libc/include/string.h b/libc/include/string.h new file mode 100644 index 0000000..a39ab0e --- /dev/null +++ b/libc/include/string.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +char *strchr(const char *s, int c); +int strcmp(const char *s1, const char *s2); +char *strcpy(char *restrict d, const char *restrict s); +size_t strlen(const char *s); +size_t strspn(const char *s, const char *a); +char *strpbrk(const char *s, const char *a); +int strcoll(const char *s1, const char *s2); + +void *memcpy(void *restrict dest, const void *restrict src, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); diff --git a/lua/src/Makefile b/lua/src/Makefile index 7a09f27..43dfdc1 100644 --- a/lua/src/Makefile +++ b/lua/src/Makefile @@ -6,8 +6,9 @@ # Your platform. See PLATS for possible values. PLAT= generic -CC= gcc -std=gnu99 -CFLAGS= -O2 -Wall -Wextra $(SYSCFLAGS) $(MYCFLAGS) +CROSS_PATH = /home/thomas/karlos/gcc-14.2.0-nolibc/x86_64-linux/bin +CC = $(CROSS_PATH)/x86_64-linux-gcc +CFLAGS= -std=gnu99 -O2 -Wall -Wextra $(SYSCFLAGS) $(MYCFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LIBS= -lm $(SYSLIBS) $(MYLIBS) @@ -16,7 +17,7 @@ RANLIB= ranlib RM= rm -f UNAME= uname -SYSCFLAGS= +SYSCFLAGS=-nostdlib -ffreestanding -fpic -fno-stack-protector -fno-stack-check -fshort-wchar -mno-red-zone -maccumulate-outgoing-args -I ../../libc/include SYSLDFLAGS= SYSLIBS=