configure: cleanup

- add quotes: eval opt=\"$opt\"
- use $source_path/conftest.c for OOT build
- add fn_makelink() for OOT build
- do not check lddir etc. on Windows/MSYS
- formatting

config-print.c
- rename to conftest.c (for consistency)
- change option e to b
- change output from that from "yes" to "no"
- remove inttypes.h dependency
- simpify version output

Makefile:
- improve GCC warning flag checks

tcc.h:
- add back default CONFIG_LDDIR
- add default CONFIG_TCCDIR also (just for fun)

tccpp.c:
- fix Christian's last warning
  tccpp.c: In function ‘macro_subst’:
  tccpp.c:2803:12: warning: ‘*((void *)&cval+4)’ is used uninitialized
     in this function [-Wuninitialized]
  That the change fixes the warning doesn't make sense but anyway.

libtcc.c:
- tcc_error/warning: print correct source filename/line for
  token :paste: (also inline :asm:)

lddir and multiarch logic still needs fixing.
master
grischka 2013-02-14 06:53:07 +01:00
parent e298f60838
commit 944627c479
8 changed files with 257 additions and 225 deletions

View File

@ -13,11 +13,14 @@ CFLAGS_P=$(CFLAGS) -pg -static
LIBS_P=
LDFLAGS_P=$(LDFLAGS)
ifeq ($(patsubst %gcc,gcc,$(CC)),gcc)
ifneq ($(GCC_MAJOR),2)
ifeq (-$(findstring $(GCC_MAJOR),01)-,--)
CFLAGS+=-fno-strict-aliasing
ifneq ($(GCC_MAJOR),3)
ifeq (-$(findstring $(GCC_MAJOR),23)-,--)
CFLAGS+=-Wno-pointer-sign -Wno-sign-compare
ifeq (-$(GCC_MAJOR)-$(findstring $(GCC_MINOR),56789)-,-4--)
CFLAGS+=-D_FORTIFY_SOURCE=0
else
CFLAGS+=-Wno-unused-result
endif
endif
endif

View File

@ -1,35 +0,0 @@
#include <inttypes.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
switch(argc == 2 ? argv[1][0] : 0) {
case 'v':
#ifdef __GNUC__
# if __GNUC__ >= 4
puts("4");
# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
puts("3");
# else
puts("2");
# endif
#else
puts("0");
#endif
break;
case 'm':
#ifdef __GNUC__
printf("%d\n", __GNUC_MINOR__);
#else
puts("-1");
#endif
break;
case 'e':
{
volatile uint32_t i=0x01234567;
if ((*((uint8_t*)(&i))) == 0x67)
puts("yes");
}
break;
}
return 0;
}

366
configure vendored
View File

@ -2,26 +2,18 @@
#
# tcc configure script (c) 2003 Fabrice Bellard
fn_dirname()
{
case $1 in
*/*) echo ${1%/*};;
*) echo '.'
esac
}
# set temporary file name
if test ! -z "$TMPDIR" ; then
TMPDIR1="${TMPDIR}"
elif test ! -z "$TEMPDIR" ; then
TMPDIR1="${TEMPDIR}"
else
TMPDIR1="/tmp"
fi
# if test ! -z "$TMPDIR" ; then
# TMPDIR1="${TMPDIR}"
# elif test ! -z "$TEMPDIR" ; then
# TMPDIR1="${TEMPDIR}"
# else
# TMPDIR1="/tmp"
# fi
#
# bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
TMPN="./conftest-$$"
TMPN="./conftest-$$"
TMPH=$TMPN.h
# default parameters
@ -42,12 +34,38 @@ host_cc="gcc"
ar="ar"
strip="strip"
cygwin="no"
cpu=`uname -m`
gprof="no"
bigendian="no"
mingw32="no"
LIBSUF=".a"
EXESUF=""
tcc_sysincludepaths=""
tcc_libpaths=""
tcc_crtprefix=""
tcc_elfinterp=""
tcc_lddir=
cpu=`uname -m`
# OS specific
targetos=`uname -s`
case $targetos in
MINGW32*) mingw32=yes;;
DragonFly) noldl=yes;;
OpenBSD) noldl=yes;;
*) ;;
esac
# find source path
# XXX: we assume an absolute path is given when launching configure,
# except in './configure' case.
source_path=${0%configure}
source_path=${source_path%/}
source_path_used="yes"
if test -z "$source_path" -o "$source_path" = "." ; then
source_path=`pwd`
source_path_used="no"
fi
case "$cpu" in
i386|i486|i586|i686|i86pc|BePC|i686-AT386)
@ -89,34 +107,9 @@ case "$cpu" in
cpu="unknown"
;;
esac
gprof="no"
bigendian="no"
mingw32="no"
LIBSUF=".a"
EXESUF=""
# OS specific
targetos=`uname -s`
case $targetos in
MINGW32*) mingw32=yes;;
DragonFly) noldl=yes;;
OpenBSD) noldl=yes;;
*) ;;
esac
# find source path
# XXX: we assume an absolute path is given when launching configure,
# except in './configure' case.
source_path=${0%configure}
source_path=${source_path%/}
source_path_used="yes"
if test -z "$source_path" -o "$source_path" = "." ; then
source_path=`pwd`
source_path_used="no"
fi
for opt do
eval opt=$opt
eval opt=\"$opt\"
case "$opt" in
--prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
;;
@ -192,89 +185,6 @@ if test -z "$CFLAGS"; then
CFLAGS="-Wall -g -O2"
fi
cc="${cross_prefix}${cc}"
ar="${cross_prefix}${ar}"
strip="${cross_prefix}${strip}"
if test "$mingw32" = "yes" ; then
LIBSUF=".lib"
EXESUF=".exe"
fi
if test -z "$cross_prefix" ; then
if ! $cc -o config-print config-print.c 2>/dev/null ; then
echo "$cc is not able to compile TCC"
else
bigendian="$(./config-print e)"
gcc_major="$(./config-print v)"
fi
else
# if cross compiling, cannot launch a program, so make a static guess
case $cpu in
powerpc|mips|s390) bigendian=yes;;
esac
fi
if test -z "$cross_prefix" ; then
libc_dir="$(ldd ./config-print | grep libc.so | sed 's|[^/]*/\(.*/\)[^/]*|\1|')"
multiarch_triplet=${libc_dir#*/}
multiarch_triplet=${multiarch_triplet%/}
lddir="${libc_dir%%/*}"
if test -n "$multiarch_triplet" ; then
lddir="$lddir/$multiarch_triplet"
fi
fi
rm config-print
if test x"$show_help" = "xyes" ; then
cat << EOF
Usage: configure [options]
Options: [defaults in brackets after descriptions]
Standard options:
--help print this message
--prefix=PREFIX install in PREFIX [$prefix]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[same as prefix]
--bindir=DIR user executables in DIR [EPREFIX/bin]
--libdir=DIR object code libraries in DIR [EPREFIX/lib]
--tccdir=DIR installation directory [EPREFIX/lib/tcc]
--includedir=DIR C header files in DIR [PREFIX/include]
--sharedir=DIR documentation root DIR [PREFIX]/share
--docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
--mandir=DIR man documentation in DIR [SHAREDIR/man]
--infodir=DIR info documentation in DIR [SHAREDIR/info]
Advanced options (experts only):
--source-path=PATH path of source code [$source_path]
--cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
--sysroot=PREFIX prepend PREFIX to library/include paths []
--cc=CC use C compiler CC [$cc]
--disable-static make libtcc.so instead of libtcc.a
--disable-rpath disable use of -rpath with the above
--strip-binaries strip symbol tables from resulting binaries
--with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a
--enable-mingw32 build windows version on linux with mingw32
--enable-cygwin build windows version on windows with cygwin
[requires cygwin and mingw32-make]
--enable-cross build cross compilers
--extra-cflags= extra compiler flags
--extra-ldflags= extra linker options
--with-selinux use mmap instead of exec mem
[requires write access to /tmp]
--sysincludepaths=... specify system include paths, colon separated
--libpaths=... specify system library paths, colon separated
--crtprefix=... specify locations of crt?.o, colon separated
--elfinterp=... specify elf interpreter
EOF
#echo "NOTE: The object files are build at the place where configure is launched"
exit 1
fi
if test "$mingw32" = "yes" ; then
if test x"$tccdir" = x""; then
tccdir="tcc"
@ -292,6 +202,8 @@ if test "$mingw32" = "yes" ; then
docdir="${sharedir}/doc"
mandir="${sharedir}/man"
infodir="${sharedir}/info"
LIBSUF=".lib"
EXESUF=".exe"
else
if test -z "$prefix" ; then
prefix="/usr/local"
@ -327,6 +239,106 @@ if test x"$includedir" = x""; then
includedir="${prefix}/include"
fi
if test x"$show_help" = "xyes" ; then
cat << EOF
Usage: configure [options]
Options: [defaults in brackets after descriptions]
Standard options:
--help print this message
--prefix=PREFIX install in PREFIX [$prefix]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[same as prefix]
--bindir=DIR user executables in DIR [EPREFIX/bin]
--libdir=DIR object code libraries in DIR [EPREFIX/lib]
--tccdir=DIR installation directory [EPREFIX/lib/tcc]
--includedir=DIR C header files in DIR [PREFIX/include]
--sharedir=DIR documentation root DIR [PREFIX/share]
--docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
--mandir=DIR man documentation in DIR [SHAREDIR/man]
--infodir=DIR info documentation in DIR [SHAREDIR/info]
Advanced options (experts only):
--source-path=PATH path of source code [$source_path]
--cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
--sysroot=PREFIX prepend PREFIX to library/include paths []
--cc=CC use C compiler CC [$cc]
--extra-cflags= specify compiler flags [$CFLAGS]
--extra-ldflags= specify linker options []
--strip-binaries strip symbol tables from resulting binaries
--disable-static make libtcc.so instead of libtcc.a
--disable-rpath disable use of -rpath with the above
--with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a
--enable-mingw32 build windows version on linux with mingw32
--enable-cygwin build windows version on windows with cygwin
--enable-cross build cross compilers
--with-selinux use mmap for exec mem [needs writable /tmp]
--sysincludepaths=... specify system include paths, colon separated
--libpaths=... specify system library paths, colon separated
--crtprefix=... specify locations of crt?.o, colon separated
--elfinterp=... specify elf interpreter
EOF
#echo "NOTE: The object files are build at the place where configure is launched"
exit 1
fi
cc="${cross_prefix}${cc}"
ar="${cross_prefix}${ar}"
strip="${cross_prefix}${strip}"
CONFTEST=./conftest$EXESUF
if test -z "$cross_prefix" ; then
if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
echo "configure: error: '$cc' failed to compile conftest.c."
else
bigendian="$($CONFTEST bigendian)"
gcc_major="$($CONFTEST version)"
gcc_minor="$($CONFTEST minor)"
if test "$mingw32" = "no" ; then
libc_dir="$(ldd $CONFTEST | grep libc.so | sed 's|[^/]*/\(.*/\)[^/]*|\1|')"
# gr: FIXME
# ldd $CONFTEST gives (ubuntu 8)
# linux-gate.so.1 => (0xb7fc3000)
# libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e37000)
# /lib/ld-linux.so.2 (0xb7fa9000)
# result is crap:
# CONFIG_LDDIR="lib/tls/i686/cmov"
# CONFIG_MUADIR="tls/i686/cmov"
multiarch_triplet=${libc_dir#*/}
multiarch_triplet=${multiarch_triplet%/}
tcc_lddir="${libc_dir%%/*}"
if test -n "$multiarch_triplet" ; then
tcc_lddir="$tcc_lddir/$multiarch_triplet"
fi
# gr: maybe for after the release:
# tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
# #echo "elfinterp $tcc_elfinterp"
fi
fi
else
# if cross compiling, cannot launch a program, so make a static guess
case $cpu in
powerpc|mips|s390) bigendian=yes;;
esac
fi
# gr: maybe for after the release:
# run compiler to see if it supports FLAG, if yes add to CFLAGS
#cc_option() {
# if $cc $CFLAGS $1 -S -o /dev/null -xc conftest.c >/dev/null 2>&1; then
# CFLAGS="$CFLAGS $1"; else if test -n "$2"; then
# CFLAGS="$CFLAGS $2"; fi; fi
#}
#cc_option -fno-strict-aliasing
#cc_option -Wno-pointer-sign
#cc_option -Wno-sign-compare
#cc_option -Wno-unused-result -D_FORTIFY_SOURCE=0
cat <<EOF
Binary directory $bindir
TinyCC directory $tccdir
@ -359,33 +371,9 @@ includedir=\$(DESTDIR)$includedir
mandir=\$(DESTDIR)$mandir
infodir=\$(DESTDIR)$infodir
docdir=\$(DESTDIR)$docdir
EOF
echo "/* Automatically generated by configure - do not modify */" > $TMPH
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_var2 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"
print_var2 CONFIG_MULTIARCHDIR "$multiarch_triplet"
print_var2 CONFIG_LDDIR "$lddir"
echo "#define GCC_MAJOR $gcc_major" >> $TMPH
cat >> config.mak <<EOF
CC=$cc
GCC_MAJOR=$gcc_major
GCC_MINOR=$gcc_minor
HOST_CC=$host_cc
AR=$ar
STRIP=$strip -s -R .comment -R .note
@ -395,6 +383,28 @@ LIBSUF=$LIBSUF
EXESUF=$EXESUF
EOF
print_def() {
if test -n "$2"; then
echo "#ifndef $1" >> $TMPH
echo "# define $1 \"$2\"" >> $TMPH
echo "#endif" >> $TMPH
fi
}
echo "/* Automatically generated by configure - do not modify */" > $TMPH
print_def CONFIG_SYSROOT "$sysroot"
print_def CONFIG_TCCDIR "$tccdir"
print_def CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
print_def CONFIG_TCC_LIBPATHS "$tcc_libpaths"
print_def CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
print_def CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
print_def CONFIG_MULTIARCHDIR "$multiarch_triplet"
print_def CONFIG_LDDIR "$tcc_lddir"
echo "#define GCC_MAJOR $gcc_major" >> $TMPH
echo "#define GCC_MINOR $gcc_minor" >> $TMPH
if test "$cpu" = "x86" ; then
echo "ARCH=i386" >> config.mak
echo "#define HOST_I386 1" >> $TMPH
@ -421,7 +431,9 @@ else
echo "Unsupported CPU"
exit 1
fi
echo "TARGETOS=$targetos" >> config.mak
if test "$noldl" = "yes" ; then
echo "CONFIG_NOLDL=yes" >> config.mak
fi
@ -431,7 +443,7 @@ if test "$mingw32" = "yes" ; then
fi
if test "$cygwin" = "yes" ; then
echo "#ifndef _WIN32" >> $TMPH
echo "#define _WIN32" >> $TMPH
echo "# define _WIN32" >> $TMPH
echo "#endif" >> $TMPH
echo "AR=ar" >> config.mak
fi
@ -470,21 +482,7 @@ echo "#define TCC_VERSION \"$version\"" >> $TMPH
echo "@set VERSION $version" > config.texi
echo "SRC_PATH=$source_path" >>config.mak
# build tree in object directory if source path is different from current one
if test "$source_path_used" = "yes" ; then
FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
for f in $FILES ; do
dir=`fn_dirname "$f"`
test -d "$dir" || mkdir -p "$dir"
# Build a symlink $f that points to $dest, its $source_path
# counterpart.
case $source_path in
/*) dest=$source_path/$f;;
*) dest=`echo "$dir/" | sed 's,^\./,,;s,[^/]*/,../,g'`
dest=$dest$source_path/$f;;
esac
ln -sf $dest $f
done
case $source_path in
/*) echo "top_srcdir=$source_path";;
*) echo "top_srcdir=\$(TOP)/$source_path";;
@ -501,4 +499,34 @@ else
echo "config.h is unchanged"
fi
rm -f $TMPN*
rm -f $TMPN* $CONFTEST
# ---------------------------------------------------------------------------
# build tree in object directory if source path is different from current one
fn_makelink()
{
tgt=$1/$2
case $2 in
*/*) dn=${2%/*}
test -d $dn || mkdir -p $dn
case $1 in
/*) ;;
*) while test $dn ; do
tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
done
;;
esac
;;
esac
ln -sfn $tgt $2
}
if test "$source_path_used" = "yes" ; then
FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
for f in $FILES ; do
fn_makelink $source_path $f
done
fi
# ---------------------------------------------------------------------------

31
conftest.c 100644
View File

@ -0,0 +1,31 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
switch(argc == 2 ? argv[1][0] : 0) {
#ifdef __GNUC__
case 'v':
printf("%d\n", __GNUC__);
break;
case 'm':
printf("%d\n", __GNUC_MINOR__);
break;
#else
case 'v':
case 'm':
puts("0");
break;
#endif
case 'b':
{
volatile unsigned foo = 0x01234567;
puts(*(unsigned char*)&foo == 0x67 ? "no" : "yes");
break;
}
case -1:
/* to test -Wno-unused-result */
fread(NULL, 1, 1, NULL);
break;
}
return 0;
}

View File

@ -567,23 +567,24 @@ static void strcat_printf(char *buf, int buf_size, const char *fmt, ...)
static void error1(TCCState *s1, int is_warning, const char *fmt, va_list ap)
{
char buf[2048];
BufferedFile **f;
BufferedFile **pf, *f;
buf[0] = '\0';
if (file) {
for(f = s1->include_stack; f < s1->include_stack_ptr; f++)
strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n",
(*f)->filename, (*f)->line_num);
if (file->line_num > 0) {
strcat_printf(buf, sizeof(buf),
"%s:%d: ", file->filename, file->line_num);
/* use upper file if inline ":asm:" or token ":paste:" */
for (f = file; f && f->filename[0] == ':'; f = f->prev);
if (f) {
for(pf = s1->include_stack; pf < s1->include_stack_ptr; pf++)
strcat_printf(buf, sizeof(buf), "In file included from %s:%d:\n",
(*pf)->filename, (*pf)->line_num);
if (f->line_num > 0) {
strcat_printf(buf, sizeof(buf), "%s:%d: ",
f->filename, f->line_num);
} else {
strcat_printf(buf, sizeof(buf),
"%s: ", file->filename);
strcat_printf(buf, sizeof(buf), "%s: ",
f->filename);
}
} else {
strcat_printf(buf, sizeof(buf),
"tcc: ");
strcat_printf(buf, sizeof(buf), "tcc: ");
}
if (is_warning)
strcat_printf(buf, sizeof(buf), "warning: ");

6
tcc.h
View File

@ -155,6 +155,12 @@
#ifndef CONFIG_SYSROOT
# define CONFIG_SYSROOT ""
#endif
#ifndef CONFIG_TCCDIR
# define CONFIG_TCCDIR "."
#endif
#ifndef CONFIG_LDDIR
# define CONFIG_LDDIR "lib"
#endif
/* path to find crt1.o, crti.o and crtn.o */
#ifndef CONFIG_TCC_CRTPREFIX

View File

@ -837,8 +837,7 @@ static void tcc_assemble_inline(TCCState *s1, char *str, int len)
saved_parse_flags = parse_flags;
saved_macro_ptr = macro_ptr;
tcc_open_bf(s1, file->filename, len);
file->line_num = file->prev->line_num;
tcc_open_bf(s1, ":asm:", len);
memcpy(file->buffer, str, len);
macro_ptr = NULL;

View File

@ -2800,13 +2800,13 @@ static inline int *macro_twosharps(const int *macro_str)
{
const int *ptr;
int t;
CValue cval;
TokenString macro_str1;
CString cstr;
int n, start_of_nosubsts;
/* we search the first '##' */
for(ptr = macro_str;;) {
CValue cval;
TOK_GET(&t, &ptr, &cval);
if (t == TOK_TWOSHARPS)
break;
@ -2835,10 +2835,9 @@ static inline int *macro_twosharps(const int *macro_str)
/* given 'a##b', remove nosubsts preceding 'b' */
while (t == TOK_NOSUBST)
t = *++ptr;
if (t && t != TOK_TWOSHARPS) {
CValue cval;
TOK_GET(&t, &ptr, &cval);
/* We concatenate the two tokens */
cstr_new(&cstr);
cstr_cat(&cstr, get_tok_str(tok, &tokc));
@ -2846,7 +2845,7 @@ static inline int *macro_twosharps(const int *macro_str)
cstr_cat(&cstr, get_tok_str(t, &cval));
cstr_ccat(&cstr, '\0');
tcc_open_bf(tcc_state, "<paste>", cstr.size);
tcc_open_bf(tcc_state, ":paste:", cstr.size);
memcpy(file->buffer, cstr.data, cstr.size);
for (;;) {
next_nomacro1();