aboutsummaryrefslogtreecommitdiff
path: root/libtcc.c
diff options
context:
space:
mode:
authorThomas Preud'homme <thomas.preudhomme@celest.fr>2011-07-05 10:47:32 +0200
committerThomas Preud'homme <thomas.preudhomme@celest.fr>2011-07-05 11:16:12 +0200
commit31ca000d72bc48060f205d94bfffc25ffe5fd18d (patch)
treec020a188a8db2fe34a728c27d12cc143627f5378 /libtcc.c
parentcb2138f8b098feb1b51a407343a4b99e25d5b506 (diff)
downloadtinycc-31ca000d72bc48060f205d94bfffc25ffe5fd18d.tar.gz
tinycc-31ca000d72bc48060f205d94bfffc25ffe5fd18d.tar.bz2
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.
Diffstat (limited to 'libtcc.c')
-rw-r--r--libtcc.c24
1 files changed, 24 insertions, 0 deletions
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 */