From 31ca000d72bc48060f205d94bfffc25ffe5fd18d Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 5 Jul 2011 10:47:32 +0200 Subject: [PATCH] Add multiarch dirs to linker search path By default, tcc search libraries in /lib and /usr/local/lib while crt*.o files are searched in /usr/lib and ld.so is searched in /lib. Unfortunetely the path are hardcoded in source code. This patch allow tcc to look in an other directory and also to look in extra directories. It's then possible to make tcc search libraries in /lib/x86_64-linux-gnu and /usr/local/lib/x86_64-linux-gnu while crt*.o files are searched in /usr/lib/x86_64-linux-gnu and ld.so is searched in /lib/x86_64-linux-gnu. --- configure | 42 +++++++++++++++++++++++++++--------------- libtcc.c | 24 ++++++++++++++++++++++++ tcc.h | 13 +++++++------ 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/configure b/configure index d2049af6..57317be0 100755 --- a/configure +++ b/configure @@ -26,6 +26,8 @@ prefix="" execprefix="" bindir="" libdir="" +lddir="" +extralddir="" tccdir="" includedir="" mandir="" @@ -108,6 +110,10 @@ for opt do ;; --libdir=*) libdir=`echo $opt | cut -d '=' -f 2` ;; + --lddir=*) lddir=`echo $opt | cut -d '=' -f 2` + ;; + --extralddir=*) extralddir="$extralddir:`echo $opt | cut -d '=' -f 2`" + ;; --includedir=*) includedir=`echo $opt | cut -d '=' -f 2` ;; --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2` @@ -241,6 +247,8 @@ echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX echo " [same as prefix]" echo " --bindir=DIR user executables in DIR [EPREFIX/bin]" echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]" +echo " --lddir=DIR loader library search path in DIR [/lib]" +echo " --extralddir=DIR extra loader library search path in DIR []" echo " --tccdir=DIR installation directory [EPREFIX/lib/tcc]" echo " --includedir=DIR C header files in DIR [PREFIX/include]" echo " --sharedir=DIR documentation root DIR [PREFIX]/share" @@ -322,21 +330,23 @@ if test x"$includedir" = x""; then includedir="${prefix}/include" fi -echo "Binary directory $bindir" -echo "TinyCC directory $tccdir" -echo "Library directory $libdir" -echo "Include directory $includedir" -echo "Manual directory $mandir" -echo "Info directory $infodir" -echo "Doc directory $docdir" -echo "Target root prefix $sysroot" -echo "Source path $source_path" -echo "C compiler $cc" -echo "CPU $cpu" -echo "Big Endian $bigendian" -echo "gprof enabled $gprof" -echo "cross compilers $build_cross" -echo "use libgcc $use_libgcc" +echo "Binary directory $bindir" +echo "TinyCC directory $tccdir" +echo "Library directory $libdir" +echo "Loader library search directory ${lddir:-default value (see tcc.h)}" +echo "Extra loader library search directory ${extralddir:-(none)}" +echo "Include directory $includedir" +echo "Manual directory $mandir" +echo "Info directory $infodir" +echo "Doc directory $docdir" +echo "Target root prefix $sysroot" +echo "Source path $source_path" +echo "C compiler $cc" +echo "CPU $cpu" +echo "Big Endian $bigendian" +echo "gprof enabled $gprof" +echo "cross compilers $build_cross" +echo "use libgcc $use_libgcc" echo "Creating config.mak and config.h" @@ -356,6 +366,8 @@ echo "docdir=\$(DESTDIR)$docdir" >> config.mak echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH echo "#ifndef CONFIG_TCCDIR" >> $TMPH echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH +echo "#define CONFIG_TCC_LDDIR \"$lddir\"" >> $TMPH +echo "#define CONFIG_TCC_EXTRA_LDDIR \"$extralddir\"" >> $TMPH echo "#endif" >> $TMPH echo "CC=$cc" >> config.mak echo "GCC_MAJOR=$gcc_major" >> config.mak diff --git a/libtcc.c b/libtcc.c index f97336e6..995e7792 100644 --- a/libtcc.c +++ b/libtcc.c @@ -971,6 +971,30 @@ LIBTCCAPI TCCState *tcc_new(void) tcc_add_library_path(s, CONFIG_TCC_CRT_PREFIX); tcc_add_library_path(s, CONFIG_SYSROOT CONFIG_TCC_LDDIR); tcc_add_library_path(s, CONFIG_SYSROOT "/usr/local"CONFIG_TCC_LDDIR); +#ifdef CONFIG_TCC_EXTRA_LDDIR + { + const char delim[] = ":"; + char *tok, *tok_extra_libdir = NULL, *tok_save_ptr, *extra_libdir_str; + size_t toklen = 0, old_toklen = 0; + + extra_libdir_str = tcc_strdup(CONFIG_TCC_EXTRA_LDDIR); + tok = strtok_r(extra_libdir_str, delim, &tok_save_ptr); + while (tok != NULL) + { + toklen = strlen(CONFIG_SYSROOT "/usr/local") + strlen(tok); + if (toklen > old_toklen) + tok_extra_libdir = tcc_realloc(tok_extra_libdir, + toklen * sizeof(char)); + /* No need for snprintf: value in tok comes from tcc compilation */ + sprintf(tok_extra_libdir, CONFIG_SYSROOT "%s", tok); + tcc_add_library_path(s, tok_extra_libdir); + sprintf(tok_extra_libdir, CONFIG_SYSROOT "/usr/local%s", tok); + tcc_add_library_path(s, tok_extra_libdir); + tok = strtok_r(NULL, delim, &tok_save_ptr); + } + tcc_free(tok_extra_libdir); + } +#endif #endif /* no section zero */ diff --git a/tcc.h b/tcc.h index fcbfadcd..686b3c50 100644 --- a/tcc.h +++ b/tcc.h @@ -142,13 +142,14 @@ typedef int BOOL; /* path to find crt1.o, crti.o and crtn.o. Only needed when generating executables or dlls */ -#if defined(TCC_TARGET_X86_64_CENTOS) -# define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib64" -# define CONFIG_TCC_LDDIR "/lib64" -#else -# define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib" -# define CONFIG_TCC_LDDIR "/lib" +#ifndef CONFIG_TCC_LDDIR + #if defined(TCC_TARGET_X86_64_CENTOS) + #define CONFIG_TCC_LDDIR "/lib64" + #else + #define CONFIG_TCC_LDDIR "/lib" + #endif #endif +#define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR #define INCLUDE_STACK_SIZE 32 #define IFDEF_STACK_SIZE 64 -- 2.11.4.GIT