From 2507c7170443cf4cced4d2cda8ba3c8cc259adb1 Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Sat, 24 Sep 2022 01:05:02 +0200 Subject: [PATCH] tcc.h: Extend search path for include, lib and crt This allow the tcc cross compilers to work as expected, when tcc was build with '--enable-cross' and a simple config-extra.mak (see the provided config-extra.mak.example). Make sure, that cross development packages for libc are installed Fixes also open bugs in various bug tracker. Example in debian: 940469 tcc: error: library 'c' not found tcc: error: file 'crtn.o' not found tcc: error: undefined symbol 'printf' --- config-extra.mak.example | 27 +++++++++++++++++++++++++++ tcc.h | 8 +++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 config-extra.mak.example diff --git a/config-extra.mak.example b/config-extra.mak.example new file mode 100644 index 00000000..567ab470 --- /dev/null +++ b/config-extra.mak.example @@ -0,0 +1,27 @@ +# +# during 'make', this file is included from the tcc Makefile +# +# this is an example, how to help tcc to find +# the c library and the startup files for cross compiling. +# +# we expect here, that the GNU libc is used and that the related development files +# are installed in a subdirectory with the target triplet used by gcc +# + +# set CONFIG_TRIPLET for cross compiler targets +DEF-i386+= -UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"i386-linux-gnu\" " +DEF-x86_64+=-UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"x86_64-linux-gnu\" " + +# many api/fp combinations are possible for arm +DEF-arm+=-UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"arm-linux-gnueabihf\" " +DEF-arm64+= -UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"aarch64-linux-gnu\" " + +DEF-riscv64+= -UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"riscv64-linux-gnu\" " +# For win32/win64 targets, we expect mingw 64 +# is is for additional packes, as tcc has ist own win32 startfiles +DEF-i386-win32+= -UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"i686-w64-mingw32\" " +DEF-x86_64-win32+= -UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"x86_64-w64-mingw32\" " + +# is a free cross compile toolchain for macos available? +#DEF-x86_64-osx+= -UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"x86_64-apple-darwin\" " +#DEF-arm64-osx+= -UCONFIG_TRIPLET -DCONFIG_TRIPLET="\"aarch64-apple-darwin\" " diff --git a/tcc.h b/tcc.h index 0c7208f7..a589ad3c 100644 --- a/tcc.h +++ b/tcc.h @@ -260,7 +260,9 @@ extern long double strtold (const char *__nptr, char **__endptr); /* path to find crt1.o, crti.o and crtn.o */ #ifndef CONFIG_TCC_CRTPREFIX -# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) +# define CONFIG_TCC_CRTPREFIX \ + ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ + ":" USE_TRIPLET(CONFIG_SYSROOT "/usr") "/lib" #endif #ifndef CONFIG_USR_INCLUDE @@ -277,6 +279,8 @@ extern long double strtold (const char *__nptr, char **__endptr); # define CONFIG_TCC_SYSINCLUDEPATHS \ "{B}/include" \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \ + ":" USE_TRIPLET(CONFIG_SYSROOT "/usr") "/include" \ + ":" USE_TRIPLET(CONFIG_SYSROOT "/usr/local") "/include" \ ":" ALSO_TRIPLET(CONFIG_SYSROOT CONFIG_USR_INCLUDE) # endif #endif @@ -289,6 +293,8 @@ extern long double strtold (const char *__nptr, char **__endptr); # define CONFIG_TCC_LIBPATHS \ "{B}" \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ + ":" USE_TRIPLET(CONFIG_SYSROOT "/usr") "/lib" \ + ":" USE_TRIPLET(CONFIG_SYSROOT "/usr/local") "/lib" \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR) # endif