From 31ca000d72bc48060f205d94bfffc25ffe5fd18d Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 5 Jul 2011 10:47:32 +0200 Subject: 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. --- libtcc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libtcc.c') diff --git a/libtcc.c b/libtcc.c index f97336e..995e779 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 */ -- cgit v1.3.1