aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrischka <grischka>2011-08-06 16:11:12 +0200
committergrischka <grischka>2011-08-06 16:11:12 +0200
commit81cd0cf6fdcbdd1d38c1a9f317d04fdac287a1e5 (patch)
treed1d0015cd3ba90177e7c6eefd677a090287f7464
parent9ffd77f18d07c595e7bd1fcc032f3cbb7b09cc6f (diff)
downloadtinycc-81cd0cf6fdcbdd1d38c1a9f317d04fdac287a1e5.tar.gz
tinycc-81cd0cf6fdcbdd1d38c1a9f317d04fdac287a1e5.tar.bz2
configure: add switches to set search paths
--sysincludepaths=.. specify system include paths, colon separated" Sets CONFIG_TCC_SYSINCLUDEPATHS --libpaths=... specify system library paths, colon separated" Sets CONFIG_TCC_LIBPATHS --crtprefix=... specify location of crt?.o" Sets CONFIG_TCC_CRTPREFIX --elfinterp=... specify elf interpreter" Sets CONFIG_TCC_ELFINTERP Also the CONFIG_TCC_XXX were renamed to make them look more consistent. Also move the elf_interp definitions to tcc.h.
-rw-r--r--Makefile4
-rwxr-xr-xconfigure41
-rw-r--r--libtcc.c42
-rw-r--r--tcc.h69
-rw-r--r--tccelf.c52
5 files changed, 117 insertions, 91 deletions
diff --git a/Makefile b/Makefile
index 453748c..2467f93 100644
--- a/Makefile
+++ b/Makefile
@@ -164,10 +164,10 @@ $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
$(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64
$(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
-DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
- -DCONFIG_TCC_LIBPATH="\"\b/lib/32;\b/lib\""
+ -DCONFIG_TCC_LIBPATHS="\"\b/lib/32;\b/lib\""
$(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
-DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
- -DCONFIG_TCC_LIBPATH="\"\b/lib/64;\b/lib\""
+ -DCONFIG_TCC_LIBPATHS="\"\b/lib/64;\b/lib\""
$(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE
$(C67_CROSS): DEFINES = -DTCC_TARGET_C67
$(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
diff --git a/configure b/configure
index c9bc83a..f495ca5 100755
--- a/configure
+++ b/configure
@@ -38,6 +38,12 @@ ar="ar"
strip="strip"
cygwin="no"
cpu=`uname -m`
+
+tcc_sysincludepaths=""
+tcc_libpaths=""
+tcc_crtprefix=""
+tcc_elfinterp=""
+
case "$cpu" in
i386|i486|i586|i686|i86pc|BePC|i686-AT386)
cpu="x86"
@@ -132,6 +138,14 @@ for opt do
;;
--extra-libs=*) extralibs=${opt#--extra-libs=}
;;
+ --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
+ ;;
+ --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
+ ;;
+ --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
+ ;;
+ --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
+ ;;
--cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
;;
--enable-gprof) gprof="yes"
@@ -265,6 +279,10 @@ echo " --extra-cflags= extra compiler flags"
echo " --extra-ldflags= extra linker options"
echo " --with-selinux use mmap instead of exec mem"
echo " [requires write access to /tmp]"
+echo " --sysincludepaths=... specify system include paths, colon separated"
+echo " --libpaths=... specify system library paths, colon separated"
+echo " --crtprefix=... specify location of crt?.o"
+echo " --elfinterp=... specify elf interpreter"
echo ""
#echo "NOTE: The object files are build at the place where configure is launched"
exit 1
@@ -352,13 +370,23 @@ echo "includedir=\$(DESTDIR)$includedir" >> config.mak
echo "mandir=\$(DESTDIR)$mandir" >> config.mak
echo "infodir=\$(DESTDIR)$infodir" >> config.mak
echo "docdir=\$(DESTDIR)$docdir" >> config.mak
+print_var1()
+{
+ echo "#ifndef $1" >> $TMPH
+ echo "# define $1 \"$2\"" >> $TMPH
+ echo "#endif" >> $TMPH
+}
+print_var2()
+{
+ if test -n "$2"; then print_var1 $1 "$2"; fi
+}
+print_var1 CONFIG_SYSROOT "$sysroot"
+print_var1 CONFIG_TCCDIR "$tccdir"
+print_var2 CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
+print_var2 CONFIG_TCC_LIBPATHS "$tcc_libpaths"
+print_var2 CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
+print_var2 CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
-echo "#ifndef CONFIG_SYSROOT" >> $TMPH
-echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
-echo "#endif" >> $TMPH
-echo "#ifndef CONFIG_TCCDIR" >> $TMPH
-echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
-echo "#endif" >> $TMPH
echo "CC=$cc" >> config.mak
echo "GCC_MAJOR=$gcc_major" >> config.mak
echo "#define GCC_MAJOR $gcc_major" >> $TMPH
@@ -369,6 +397,7 @@ echo "CFLAGS=$CFLAGS" >> config.mak
echo "LDFLAGS=$LDFLAGS" >> config.mak
echo "LIBSUF=$LIBSUF" >> config.mak
echo "EXESUF=$EXESUF" >> config.mak
+
if test "$cpu" = "x86" ; then
echo "ARCH=i386" >> config.mak
echo "#define HOST_I386 1" >> $TMPH
diff --git a/libtcc.c b/libtcc.c
index bcef2a6..41eab81 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -306,38 +306,25 @@ PUB_FUNC void dynarray_reset(void *pp, int *n)
*(void**)pp = NULL;
}
-/* out must not point to a valid dynarray since a new one is created */
static void tcc_split_path(TCCState *s, void ***p_ary, int *p_nb_ary, const char *in)
{
const char *p;
do {
- const char *r = NULL;
int c;
CString str;
cstr_new(&str);
- for (p = in;;) {
- if (r) {
- if ((c = *r++) == 0) {
- r = NULL;
- continue;
- }
- } else if ((c = *p++) == 0) {
- ;
- } else if (c == PATHSEP) {
- c = 0;
- } else if (c == '\b') {
- r = s->tcc_lib_path;
- continue;
+ for (p = in; c = *p, c != '\0' && c != PATHSEP; ++p) {
+ if (c == '\b') {
+ cstr_cat(&str, s->tcc_lib_path);
+ } else {
+ cstr_ccat(&str, c);
}
- cstr_ccat(&str, c);
- if (0 == c)
- break;
}
- //printf("path: %s\n", (char*)str.data);
+ cstr_ccat(&str, '\0');
dynarray_add(p_ary, p_nb_ary, str.data);
- in = p;
- } while (p[-1]);
+ in = p+1;
+ } while (*p);
}
/********************************************************/
@@ -1006,7 +993,7 @@ LIBTCCAPI TCCState *tcc_new(void)
#ifndef TCC_TARGET_PE
/* default library paths */
- tcc_add_library_path(s, CONFIG_TCC_LIBPATH);
+ tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
#endif
/* no section zero */
@@ -1229,7 +1216,6 @@ the_end:
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
{
dynarray_add((void ***)&s->input_files, &s->nb_input_files, tcc_strdup(filename));
-
if (s->output_type == TCC_OUTPUT_PREPROCESS)
return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR | AFF_PREPROCESS);
else
@@ -1306,7 +1292,7 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
if (!s->nostdinc) {
/* default include paths */
/* -isystem paths have already been handled */
- tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDE_PATHS);
+ tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
}
/* if bound checking, then add corresponding sections */
@@ -1338,18 +1324,18 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
put_stabs("", 0, 0, 0, 0);
}
- /* add libc crt1/crti objects */
#ifdef TCC_TARGET_PE
- tcc_add_library_path(s, CONFIG_TCC_LIBPATH);
+ tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
# ifdef _WIN32
tcc_add_systemdir(s);
# endif
#else
+ /* add libc crt1/crti objects */
if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) &&
!s->nostdlib) {
if (output_type != TCC_OUTPUT_DLL)
- tcc_add_file(s, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/crt1.o");
- tcc_add_file(s, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/crti.o");
+ tcc_add_file(s, TCC_CRTO("crt1.o"));
+ tcc_add_file(s, TCC_CRTO("crti.o"));
}
#endif
return 0;
diff --git a/tcc.h b/tcc.h
index f8ad00c..6e9b01f 100644
--- a/tcc.h
+++ b/tcc.h
@@ -133,44 +133,75 @@
#define CONFIG_TCC_BACKTRACE
#endif
-#define FALSE 0
-#define false 0
-#define TRUE 1
-#define true 1
-typedef int BOOL;
+/* ------------ path configuration ------------ */
#ifndef CONFIG_TCC_LDDIR
- #if defined(TCC_TARGET_X86_64_CENTOS)
- #define CONFIG_TCC_LDDIR "/lib64"
- #else
- #define CONFIG_TCC_LDDIR "/lib"
- #endif
+# if defined(TCC_TARGET_X86_64_CENTOS)
+# define CONFIG_TCC_LDDIR "/lib64"
+# else
+# define CONFIG_TCC_LDDIR "/lib"
+# endif
#endif
/* path to find crt1.o, crti.o and crtn.o */
-#ifndef CONFIG_TCC_CRT_PREFIX
-# define CONFIG_TCC_CRT_PREFIX "/usr" CONFIG_TCC_LDDIR
+#ifndef CONFIG_TCC_CRTPREFIX
+# define CONFIG_TCC_CRTPREFIX "/usr" CONFIG_TCC_LDDIR
#endif
-#ifndef CONFIG_TCC_SYSINCLUDE_PATHS
+/* system include paths */
+#ifndef CONFIG_TCC_SYSINCLUDEPATHS
# ifdef TCC_TARGET_PE
-# define CONFIG_TCC_SYSINCLUDE_PATHS "\b/include;\b/include/winapi"
+# define CONFIG_TCC_SYSINCLUDEPATHS "\b/include;\b/include/winapi"
# else
-# define CONFIG_TCC_SYSINCLUDE_PATHS "/usr/local/include:/usr/include:\b/include"
+# define CONFIG_TCC_SYSINCLUDEPATHS \
+ CONFIG_SYSROOT "/usr/local/include" \
+ ":" CONFIG_SYSROOT "/usr/include" \
+ ":" "\b/include"
# endif
#endif
-#ifndef CONFIG_TCC_LIBPATH
+/* library search paths */
+#ifndef CONFIG_TCC_LIBPATHS
# ifdef TCC_TARGET_PE
-# define CONFIG_TCC_LIBPATH "\b/lib"
+# define CONFIG_TCC_LIBPATHS "\b/lib"
# else
-# define CONFIG_TCC_LIBPATH \
- CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX \
+# define CONFIG_TCC_LIBPATHS \
+ CONFIG_SYSROOT CONFIG_TCC_CRTPREFIX \
":" CONFIG_SYSROOT CONFIG_TCC_LDDIR \
":" CONFIG_SYSROOT "/usr/local" CONFIG_TCC_LDDIR
# endif
#endif
+/* name of ELF interpreter */
+#ifndef CONFIG_TCC_ELFINTERP
+# if defined __FreeBSD__
+# define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
+# elif defined __FreeBSD_kernel__
+# define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld.so.1"
+# elif defined TCC_ARM_EABI
+# define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-linux.so.3"
+# elif defined(TCC_TARGET_X86_64)
+# define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-linux-x86-64.so.2"
+# elif defined(TCC_UCLIBC)
+# define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-uClibc.so.0"
+# else
+# define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-linux.so.2"
+# endif
+#endif
+
+/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
+#define TCC_LIBGCC CONFIG_SYSROOT CONFIG_TCC_LDDIR "/libgcc_s.so.1"
+/* crt?.o files */
+#define TCC_CRTO(crto) CONFIG_SYSROOT CONFIG_TCC_CRTPREFIX "/" crto
+
+/* -------------------------------------------- */
+
+#define FALSE 0
+#define false 0
+#define TRUE 1
+#define true 1
+typedef int BOOL;
+
#define INCLUDE_STACK_SIZE 32
#define IFDEF_STACK_SIZE 64
#define VSTACK_SIZE 256
diff --git a/tccelf.c b/tccelf.c
index c0f1c94..47369ac 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -1189,6 +1189,13 @@ static void add_init_array_defines(TCCState *s1, const char *section_name)
s->sh_num, sym_end);
}
+static int tcc_add_support(TCCState *s1, const char *filename)
+{
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename);
+ return tcc_add_file(s1, buf);
+}
+
ST_FUNC void tcc_add_bcheck(TCCState *s1)
{
#ifdef CONFIG_TCC_BCHECK
@@ -1208,11 +1215,7 @@ ST_FUNC void tcc_add_bcheck(TCCState *s1)
bounds_section->sh_num, "__bounds_start");
/* add bound check code */
#ifndef TCC_TARGET_PE
- {
- char buf[1024];
- snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, "bcheck.o");
- tcc_add_file(s1, buf);
- }
+ tcc_add_support(s1, "bcheck.o");
#endif
#ifdef TCC_TARGET_I386
if (s1->output_type != TCC_OUTPUT_MEMORY) {
@@ -1236,23 +1239,15 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
/* add libc */
if (!s1->nostdlib) {
-#ifdef CONFIG_USE_LIBGCC
- tcc_add_library(s1, "c");
- tcc_add_file(s1, CONFIG_SYSROOT CONFIG_TCC_LDDIR"/libgcc_s.so.1");
-#else
tcc_add_library(s1, "c");
-#ifndef WITHOUT_LIBTCC
- {
- char buf[1024];
- snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, "libtcc1.a");
- tcc_add_file(s1, buf);
- }
-#endif
+#ifdef CONFIG_USE_LIBGCC
+ tcc_add_file(s1, TCC_LIBGCC);
+#elif !defined WITHOUT_LIBTCC
+ tcc_add_support(s1, "libtcc1.a");
#endif
- }
- /* add crt end if not memory output */
- if (s1->output_type != TCC_OUTPUT_MEMORY && !s1->nostdlib) {
- tcc_add_file(s1, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/crtn.o");
+ /* add crt end if not memory output */
+ if (s1->output_type != TCC_OUTPUT_MEMORY)
+ tcc_add_file(s1, TCC_CRTO("crtn.o"));
}
}
@@ -1316,21 +1311,6 @@ ST_FUNC void tcc_add_linker_symbols(TCCState *s1)
}
}
-/* name of ELF interpreter */
-#if defined __FreeBSD__
-static const char elf_interp[] = "/libexec/ld-elf.so.1";
-#elif defined __FreeBSD_kernel__
-static char elf_interp[] = CONFIG_TCC_LDDIR"/ld.so.1";
-#elif defined TCC_ARM_EABI
-static const char elf_interp[] = CONFIG_TCC_LDDIR"/ld-linux.so.3";
-#elif defined(TCC_TARGET_X86_64)
-static const char elf_interp[] = CONFIG_TCC_LDDIR"/ld-linux-x86-64.so.2";
-#elif defined(TCC_UCLIBC)
-static const char elf_interp[] = CONFIG_TCC_LDDIR"/ld-uClibc.so.0";
-#else
-static const char elf_interp[] = CONFIG_TCC_LDDIR"/ld-linux.so.2";
-#endif
-
static void tcc_output_binary(TCCState *s1, FILE *f,
const int *section_order)
{
@@ -1473,7 +1453,7 @@ static int elf_output_file(TCCState *s1, const char *filename)
/* allow override the dynamic loader */
const char *elfint = getenv("LD_SO");
if (elfint == NULL)
- elfint = elf_interp;
+ elfint = CONFIG_TCC_ELFINTERP;
/* add interpreter section only if executable */
interp = new_section(s1, ".interp", SHT_PROGBITS, SHF_ALLOC);
interp->sh_addralign = 1;