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.
This commit is contained in:
Thomas Preud'homme 2011-07-05 10:47:32 +02:00
parent cb2138f8b0
commit 31ca000d72
3 changed files with 58 additions and 21 deletions

42
configure vendored
View File

@ -26,6 +26,8 @@ prefix=""
execprefix="" execprefix=""
bindir="" bindir=""
libdir="" libdir=""
lddir=""
extralddir=""
tccdir="" tccdir=""
includedir="" includedir=""
mandir="" mandir=""
@ -108,6 +110,10 @@ for opt do
;; ;;
--libdir=*) libdir=`echo $opt | cut -d '=' -f 2` --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` --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
;; ;;
--sharedir=*) sharedir=`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 " [same as prefix]"
echo " --bindir=DIR user executables in DIR [EPREFIX/bin]" echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]" 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 " --tccdir=DIR installation directory [EPREFIX/lib/tcc]"
echo " --includedir=DIR C header files in DIR [PREFIX/include]" echo " --includedir=DIR C header files in DIR [PREFIX/include]"
echo " --sharedir=DIR documentation root DIR [PREFIX]/share" echo " --sharedir=DIR documentation root DIR [PREFIX]/share"
@ -322,21 +330,23 @@ if test x"$includedir" = x""; then
includedir="${prefix}/include" includedir="${prefix}/include"
fi fi
echo "Binary directory $bindir" echo "Binary directory $bindir"
echo "TinyCC directory $tccdir" echo "TinyCC directory $tccdir"
echo "Library directory $libdir" echo "Library directory $libdir"
echo "Include directory $includedir" echo "Loader library search directory ${lddir:-default value (see tcc.h)}"
echo "Manual directory $mandir" echo "Extra loader library search directory ${extralddir:-(none)}"
echo "Info directory $infodir" echo "Include directory $includedir"
echo "Doc directory $docdir" echo "Manual directory $mandir"
echo "Target root prefix $sysroot" echo "Info directory $infodir"
echo "Source path $source_path" echo "Doc directory $docdir"
echo "C compiler $cc" echo "Target root prefix $sysroot"
echo "CPU $cpu" echo "Source path $source_path"
echo "Big Endian $bigendian" echo "C compiler $cc"
echo "gprof enabled $gprof" echo "CPU $cpu"
echo "cross compilers $build_cross" echo "Big Endian $bigendian"
echo "use libgcc $use_libgcc" echo "gprof enabled $gprof"
echo "cross compilers $build_cross"
echo "use libgcc $use_libgcc"
echo "Creating config.mak and config.h" echo "Creating config.mak and config.h"
@ -356,6 +366,8 @@ echo "docdir=\$(DESTDIR)$docdir" >> config.mak
echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
echo "#ifndef CONFIG_TCCDIR" >> $TMPH echo "#ifndef CONFIG_TCCDIR" >> $TMPH
echo "#define CONFIG_TCCDIR \"$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 "#endif" >> $TMPH
echo "CC=$cc" >> config.mak echo "CC=$cc" >> config.mak
echo "GCC_MAJOR=$gcc_major" >> config.mak echo "GCC_MAJOR=$gcc_major" >> config.mak

View File

@ -971,6 +971,30 @@ LIBTCCAPI TCCState *tcc_new(void)
tcc_add_library_path(s, CONFIG_TCC_CRT_PREFIX); 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 CONFIG_TCC_LDDIR);
tcc_add_library_path(s, CONFIG_SYSROOT "/usr/local"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 #endif
/* no section zero */ /* no section zero */

13
tcc.h
View File

@ -142,13 +142,14 @@ typedef int BOOL;
/* path to find crt1.o, crti.o and crtn.o. Only needed when generating /* path to find crt1.o, crti.o and crtn.o. Only needed when generating
executables or dlls */ executables or dlls */
#if defined(TCC_TARGET_X86_64_CENTOS) #ifndef CONFIG_TCC_LDDIR
# define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib64" #if defined(TCC_TARGET_X86_64_CENTOS)
# define CONFIG_TCC_LDDIR "/lib64" #define CONFIG_TCC_LDDIR "/lib64"
#else #else
# define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib" #define CONFIG_TCC_LDDIR "/lib"
# define CONFIG_TCC_LDDIR "/lib" #endif
#endif #endif
#define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR
#define INCLUDE_STACK_SIZE 32 #define INCLUDE_STACK_SIZE 32
#define IFDEF_STACK_SIZE 64 #define IFDEF_STACK_SIZE 64