From 8fa443879c7b765b67873f9594352b57b2702eaa Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 4 Dec 2024 21:23:09 +0200 Subject: [PATCH] ports: Add working tcc port! You can actually now compile programs within banan-os!! --- ports/tcc/build.sh | 27 +++++++++++++++++ .../patches/0001-add-banan_os-target.patch | 30 +++++++++++++++++++ .../patches/0002-remove-malloc-hooks.patch | 23 ++++++++++++++ .../0003-use-crt0-instead-of-crt1.patch | 17 +++++++++++ 4 files changed, 97 insertions(+) create mode 100755 ports/tcc/build.sh create mode 100644 ports/tcc/patches/0001-add-banan_os-target.patch create mode 100644 ports/tcc/patches/0002-remove-malloc-hooks.patch create mode 100644 ports/tcc/patches/0003-use-crt0-instead-of-crt1.patch diff --git a/ports/tcc/build.sh b/ports/tcc/build.sh new file mode 100755 index 00000000..ed2b8a60 --- /dev/null +++ b/ports/tcc/build.sh @@ -0,0 +1,27 @@ +#!/bin/bash ../install.sh + +NAME='tcc' +VERSION='0.9.27' +DOWNLOAD_URL="https://download.savannah.gnu.org/releases/tinycc/tcc-$VERSION.tar.bz2#de23af78fca90ce32dff2dd45b3432b2334740bb9bb7b05bf60fdbfc396ceb9c" + +configure() { + ./configure \ + --prefix=/usr \ + --sysroot=$BANAN_SYSROOT \ + --cpu=$BANAN_ARCH \ + --enable-cross \ + --cross-prefix=$BANAN_TOOLCHAIN_TRIPLE- \ + --sysincludepaths=/usr/include:/usr/lib/tcc/include \ + --libpaths=/usr/lib \ + --crtprefix=/usr/lib \ + --elfinterp=/usr/lib/DynamicLoader.so +} + +build() { + make -j$(nproc) cross-$BANAN_ARCH $BANAN_ARCH-libtcc1-usegcc=yes || exit 1 +} + +install() { + make install-unx DESTDIR=$BANAN_SYSROOT || exit 1 + ln -sf $BANAN_ARCH-tcc $BANAN_SYSROOT/usr/bin/tcc +} diff --git a/ports/tcc/patches/0001-add-banan_os-target.patch b/ports/tcc/patches/0001-add-banan_os-target.patch new file mode 100644 index 00000000..33438945 --- /dev/null +++ b/ports/tcc/patches/0001-add-banan_os-target.patch @@ -0,0 +1,30 @@ +diff -ruN tcc-0.9.27/configure tcc-0.9.27-banan_os/configure +--- tcc-0.9.27/configure 2017-12-17 10:27:05.000000000 +0200 ++++ tcc-0.9.27-banan_os/configure 2024-08-25 18:43:00.329466309 +0300 +@@ -49,8 +49,11 @@ + gcc_minor=0 + + # OS specific +-targetos=`uname` ++targetos='banan_os' + case $targetos in ++ banan_os) ++ confvars="$confvars ldl=no lm=no" ++ ;; + Darwin) + confvars="$confvars OSX" + DLLSUF=".dylib" +diff -ruN tcc-0.9.27/Makefile tcc-0.9.27-banan_os/Makefile +--- tcc-0.9.27/Makefile 2017-12-17 10:27:05.000000000 +0200 ++++ tcc-0.9.27-banan_os/Makefile 2024-08-25 18:43:44.996196450 +0300 +@@ -30,7 +30,9 @@ + CFGWIN = -win + NATIVE_TARGET = $(ARCH)-win$(if $(findstring arm,$(ARCH)),ce,32) + else +- LIBS=-lm ++ ifneq ($(CONFIG_lm),no) ++ LIBS=-lm ++ endif + ifneq ($(CONFIG_ldl),no) + LIBS+=-ldl + endif diff --git a/ports/tcc/patches/0002-remove-malloc-hooks.patch b/ports/tcc/patches/0002-remove-malloc-hooks.patch new file mode 100644 index 00000000..a2a51554 --- /dev/null +++ b/ports/tcc/patches/0002-remove-malloc-hooks.patch @@ -0,0 +1,23 @@ +diff -ruN tcc-0.9.27/lib/bcheck.c tcc-0.9.27-banan_os/lib/bcheck.c +--- tcc-0.9.27/lib/bcheck.c 2017-12-17 10:27:05.000000000 +0200 ++++ tcc-0.9.27-banan_os/lib/bcheck.c 2024-08-25 22:29:43.193883000 +0300 +@@ -26,7 +26,8 @@ + && !defined(__FreeBSD_kernel__) \ + && !defined(__DragonFly__) \ + && !defined(__OpenBSD__) \ +- && !defined(__NetBSD__) ++ && !defined(__NetBSD__) \ ++ && !defined(__banan_os__) + #include + #endif + +@@ -56,7 +57,8 @@ + || defined(__OpenBSD__) \ + || defined(__NetBSD__) \ + || defined(__dietlibc__) \ +- || defined(_WIN32) ++ || defined(_WIN32) \ ++ || defined(__banan_os__) + //#warning Bound checking does not support malloc (etc.) in this environment. + #undef CONFIG_TCC_MALLOC_HOOKS + #undef HAVE_MEMALIGN diff --git a/ports/tcc/patches/0003-use-crt0-instead-of-crt1.patch b/ports/tcc/patches/0003-use-crt0-instead-of-crt1.patch new file mode 100644 index 00000000..5bece859 --- /dev/null +++ b/ports/tcc/patches/0003-use-crt0-instead-of-crt1.patch @@ -0,0 +1,17 @@ +diff -ruN tcc-0.9.27/libtcc.c tcc-0.9.27-banan_os/libtcc.c +--- tcc-0.9.27/libtcc.c 2017-12-17 10:27:05.000000000 +0200 ++++ tcc-0.9.27-banan_os/libtcc.c 2024-08-26 01:26:52.175524270 +0300 +@@ -971,11 +971,11 @@ + #else + /* paths for crt objects */ + tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX); +- /* add libc crt1/crti objects */ ++ /* add libc crt0/crti objects */ + if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) && + !s->nostdlib) { + if (output_type != TCC_OUTPUT_DLL) +- tcc_add_crt(s, "crt1.o"); ++ tcc_add_crt(s, "crt0.o"); + tcc_add_crt(s, "crti.o"); + } + #endif