Add a --multiarch-triplet switch to configure

Add a --multiarch-triplet switch to configure. The switch will allow
files to be search for each default path in path/<triplet> and then
path.
Default paths handled that way:
- CONFIG_TCC_SYSINCLUDE_PATHS
- CONFIG_TCC_LIBPATH
- path to crt*.o
- path to libgcc_s.so.1

Path missing: elf interpreter path (will be handled in another commit)
This commit is contained in:
Thomas Preud'homme 2011-08-01 22:32:44 +02:00
parent 5e954fef32
commit 76adc5770f
4 changed files with 153 additions and 74 deletions

159
configure vendored
View File

@ -31,6 +31,7 @@ includedir=""
mandir=""
infodir=""
sysroot=""
multiarch_triplet=""
cross_prefix=""
cc="gcc"
host_cc="gcc"
@ -120,6 +121,8 @@ for opt do
;;
--sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
;;
--multiarch-triplet=*) multiarch_triplet=`echo $opt | cut -d '=' -f 2`
;;
--source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
;;
--cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
@ -235,36 +238,37 @@ Options: [defaults in brackets after descriptions]
EOF
echo "Standard options:"
echo " --help print this message"
echo " --prefix=PREFIX install in PREFIX [$prefix]"
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 " --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"
echo " --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]"
echo " --mandir=DIR man documentation in DIR [SHAREDIR/man]"
echo " --infodir=DIR info documentation in DIR [SHAREDIR/info]"
echo " --help print this message"
echo " --prefix=PREFIX install in PREFIX [$prefix]"
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 " --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"
echo " --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]"
echo " --mandir=DIR man documentation in DIR [SHAREDIR/man]"
echo " --infodir=DIR info documentation in DIR [SHAREDIR/info]"
echo ""
echo "Advanced options (experts only):"
echo " --source-path=PATH path of source code [$source_path]"
echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
echo " --cc=CC use C compiler CC [$cc]"
echo " --disable-static make libtcc.so instead of libtcc.a"
echo " --disable-rpath disable use of -rpath with the above"
echo " --strip-binaries strip symbol tables from resulting binaries"
echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
echo " --enable-mingw32 build windows version on linux with mingw32"
echo " --enable-cygwin build windows version on windows with cygwin"
echo " [requires cygwin and mingw32-make]"
echo " --enable-cross build cross compilers"
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 " --source-path=PATH path of source code [$source_path]"
echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
echo " --multiarch-triplet=SUFFIX append SUFFIX to library/include paths []"
echo " --cc=CC use C compiler CC [$cc]"
echo " --disable-static make libtcc.so instead of libtcc.a"
echo " --disable-rpath disable use of -rpath with the above"
echo " --strip-binaries strip symbol tables from resulting binaries"
echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
echo " --enable-mingw32 build windows version on linux with mingw32"
echo " --enable-cygwin build windows version on windows with cygwin"
echo " [requires cygwin and mingw32-make]"
echo " --enable-cross build cross compilers"
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 ""
#echo "NOTE: The object files are build at the place where configure is launched"
exit 1
@ -330,13 +334,14 @@ 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 "Multiarch triplet $multiarch_triplet"
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,9 +361,93 @@ echo "docdir=\$(DESTDIR)$docdir" >> config.mak
echo "#ifndef CONFIG_SYSROOT" >> $TMPH
echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
echo "#endif" >> $TMPH
echo "" >> $TMPH
# Set default include and library paths
win_incpaths="\\\b/include;\\\b/include/winapi"
unix_incpaths="/usr/local/include:/usr/include:\\\b/include"
win_libpaths="\\\b/lib"
unix_libpaths="CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX"
unix_libpaths="$unix_libpaths\":\"CONFIG_SYSROOT CONFIG_TCC_LDDIR"
unix_libpaths="$unix_libpaths\":\"CONFIG_SYSROOT \"/usr/local\" CONFIG_TCC_LDDIR"
# sep: path separator in paths
# tmp: paths multiarchified (one path per line)
# q: quote (if sep contains ")
# r: carriage return pattern (if sep contains ")
# s: space (if sep contains ")
multiarchify()
{
local sep tmp
paths="$1"
sep="$2"
tmp=""
q=""
r=""
s=""
if [ -z "${sep%%\"*}" ] ; then
q="\""
r=" \\\\\n "
s=" "
fi
paths="$paths$sep"
while test -n "$paths" ; do
tmp="$tmp${tmp:+$r$sep$s}${paths%%$sep*}$s$q/$multiarch_triplet$q"
tmp="$tmp$r$sep$s${paths%%$sep*}"
paths="${paths#*$sep}"
done
paths="$tmp"
}
if test -n "$multiarch_triplet" ; then
multiarchify "$win_incpaths" ";"
win_incpaths="\"$paths\""
multiarchify "$unix_incpaths" ":"
unix_incpaths="\"$paths\""
multiarchify "$win_libpaths" ";"
win_libpaths="\"$paths\""
multiarchify "$unix_libpaths" "\":\""
unix_libpaths="$paths"
echo "#define CONFIG_TCC_MULTIARCH_TRIPLET \"$multiarch_triplet\"" >> $TMPH
fi
echo "#ifndef CONFIG_TCC_LDDIR" >> $TMPH
echo " #if defined(TCC_TARGET_X86_64_CENTOS)" >> $TMPH
echo " #define CONFIG_TCC_LDDIR \"/lib64\"" >> $TMPH
echo " #else" >> $TMPH
echo " #define CONFIG_TCC_LDDIR \"/lib\"" >> $TMPH
echo " #endif" >> $TMPH
echo "#endif" >> $TMPH
echo "" >> $TMPH
echo "/* path to find crt1.o, crti.o and crtn.o */" >> $TMPH
echo "#ifndef CONFIG_TCC_CRT_PREFIX" >> $TMPH
echo "# define CONFIG_TCC_CRT_PREFIX \"/usr\" CONFIG_TCC_LDDIR" >> $TMPH
echo "#endif" >> $TMPH
echo "" >> $TMPH
echo "#ifndef CONFIG_TCC_SYSINCLUDE_PATHS" >> $TMPH
echo "# ifdef TCC_TARGET_PE" >> $TMPH
echo "# define CONFIG_TCC_SYSINCLUDE_PATHS $win_incpaths" >> $TMPH
echo "# else" >> $TMPH
echo "# define CONFIG_TCC_SYSINCLUDE_PATHS $unix_incpaths" >> $TMPH
echo "# endif" >> $TMPH
echo "#endif" >> $TMPH
echo "" >> $TMPH
echo "#ifndef CONFIG_TCC_LIBPATH" >> $TMPH
echo "# ifdef TCC_TARGET_PE" >> $TMPH
echo "# define CONFIG_TCC_LIBPATH $win_libpaths" >> $TMPH
echo "# else" >> $TMPH
echo "# define CONFIG_TCC_LIBPATH $unix_libpaths" >> $TMPH
echo "# endif" >> $TMPH
echo "#endif" >> $TMPH
echo "" >> $TMPH
echo "#ifndef CONFIG_TCCDIR" >> $TMPH
echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
echo "#endif" >> $TMPH
echo "" >> $TMPH
echo "CC=$cc" >> config.mak
echo "GCC_MAJOR=$gcc_major" >> config.mak
echo "#define GCC_MAJOR $gcc_major" >> $TMPH

View File

@ -1226,14 +1226,19 @@ the_end:
return ret;
}
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
static int tcc_add_file_noerror(TCCState *s, const char *filename, int extra_flags)
{
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);
return tcc_add_file_internal(s, filename, extra_flags | AFF_PREPROCESS);
else
return tcc_add_file_internal(s, filename, AFF_PRINT_ERROR);
return tcc_add_file_internal(s, filename, extra_flags);
}
LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
{
return tcc_add_file_noerror(s, filename, AFF_PRINT_ERROR);
}
LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
@ -1347,9 +1352,16 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
#else
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");
if (output_type != TCC_OUTPUT_DLL) {
#ifdef CONFIG_TCC_MULTIARCH_TRIPLET
if (tcc_add_file_noerror(s, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/" CONFIG_TCC_MULTIARCH_TRIPLET "/crt1.o", 0))
#endif
tcc_add_file(s, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/crt1.o");
}
#ifdef CONFIG_TCC_MULTIARCH_TRIPLET
if (tcc_add_file_noerror(s, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/" CONFIG_TCC_MULTIARCH_TRIPLET "/crti.o", 0))
#endif
tcc_add_file(s, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/crti.o");
}
#endif
return 0;

34
tcc.h
View File

@ -139,37 +139,9 @@
#define true 1
typedef int BOOL;
#ifndef CONFIG_TCC_LDDIR
#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
#endif
#ifndef CONFIG_TCC_SYSINCLUDE_PATHS
# ifdef TCC_TARGET_PE
# define CONFIG_TCC_SYSINCLUDE_PATHS "\b/include;\b/include/winapi"
# else
# define CONFIG_TCC_SYSINCLUDE_PATHS "/usr/local/include:/usr/include:\b/include"
# endif
#endif
#ifndef CONFIG_TCC_LIBPATH
# ifdef TCC_TARGET_PE
# define CONFIG_TCC_LIBPATH "\b/lib"
# else
# define CONFIG_TCC_LIBPATH \
CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX \
":" CONFIG_SYSROOT CONFIG_TCC_LDDIR \
":" CONFIG_SYSROOT "/usr/local" CONFIG_TCC_LDDIR
# endif
#endif
/* See definition of default values of CONFIG_TCC_LDDIR, CONFIG_TCC_CRT_PREFIX,
CONFIG_TCC_SYSINCLUDE_PATHS and CONFIG_TCC_LIBPATH in config.h or configure
*/
#define INCLUDE_STACK_SIZE 32
#define IFDEF_STACK_SIZE 64

View File

@ -1238,7 +1238,10 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
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");
#ifdef CONFIG_TCC_MULTIARCH_TRIPLET
if (tcc_add_file_internal(s1, CONFIG_SYSROOT CONFIG_TCC_LDDIR "/" CONFIG_TCC_MULTIARCH_TRIPLET "/libgcc_s.so.1", 0))
#endif
tcc_add_file(s1, CONFIG_SYSROOT CONFIG_TCC_LDDIR"/libgcc_s.so.1");
#else
tcc_add_library(s1, "c");
#ifndef WITHOUT_LIBTCC
@ -1252,7 +1255,10 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
}
/* 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");
#ifdef CONFIG_TCC_MULTIARCH_TRIPLET
if (tcc_add_file_internal(s1, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/" CONFIG_TCC_MULTIARCH_TRIPLET "/crtn.o", 0))
#endif
tcc_add_file(s1, CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX "/crtn.o");
}
}