Index: EcnlProtoTool/trunk/tcc-0.9.27/configure
===================================================================
--- EcnlProtoTool/trunk/tcc-0.9.26/configure	(revision 279)
+++ EcnlProtoTool/trunk/tcc-0.9.27/configure	(revision 331)
@@ -18,6 +18,4 @@
 
 # default parameters
-build_cross="no"
-use_libgcc="no"
 prefix=""
 execprefix=""
@@ -31,36 +29,42 @@
 cross_prefix=""
 cc="gcc"
-host_cc="gcc"
 ar="ar"
 strip="strip"
-cygwin="no"
-gprof="no"
 bigendian="no"
 mingw32="no"
 LIBSUF=".a"
 EXESUF=""
+DLLSUF=".so"
 tcc_sysincludepaths=""
 tcc_libpaths=""
 tcc_crtprefix=""
 tcc_elfinterp=""
+triplet=
 tcc_lddir=
 confvars=
-
-#cpu=`uname -m`
-cpu="armv7a"
+suggest="yes"
+cpu=
+cpuver=
+gcc_major=0
+gcc_minor=0
 
 # OS specific
-#targetos=`uname -s`
-targetos=""
+targetos=`uname`
 case $targetos in
-  MINGW32*)  mingw32=yes;;
-  DragonFly) noldl=yes;;
-  OpenBSD)   noldl=yes;;
-  *) ;;
+  Darwin)
+    confvars="$confvars OSX"
+    DLLSUF=".dylib"
+    ;;
+  MINGW*|MSYS*|CYGWIN*)
+    mingw32=yes
+    ;;
+  DragonFly|OpenBSD|FreeBSD|NetBSD)
+    confvars="$confvars ldl=no"
+    ;;
+  *)
+    ;;
 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%/}
@@ -71,45 +75,4 @@
 fi
 
-case "$cpu" in
-  i386|i486|i586|i686|i86pc|BePC|i686-AT386)
-    cpu="x86"
-  ;;
-  x86_64)
-    cpu="x86-64"
-  ;;
-  arm*)
-    case "$cpu" in
-      arm|armv4l)
-        cpuver=4
-      ;;
-      armv5tel|armv5tejl)
-        cpuver=5
-      ;;
-      armv6j|armv6l)
-        cpuver=6
-      ;;
-      armv7a|armv7l)
-        cpuver=7
-      ;;
-    esac
-    cpu="armv4l"
-  ;;
-  alpha)
-    cpu="alpha"
-  ;;
-  "Power Macintosh"|ppc|ppc64)
-    cpu="powerpc"
-  ;;
-  mips)
-    cpu="mips"
-  ;;
-  s390)
-    cpu="s390"
-  ;;
-  *)
-    cpu="unknown"
-  ;;
-esac
-
 for opt do
   eval opt=\"$opt\"
@@ -143,9 +106,11 @@
   --cc=*) cc=`echo $opt | cut -d '=' -f 2`
   ;;
+  --ar=*) ar=`echo $opt | cut -d '=' -f 2`
+  ;;
   --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
   ;;
   --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
   ;;
-  --extra-libs=*) extralibs=${opt#--extra-libs=}
+  --extra-libs=*) extralibs="${opt#--extra-libs=}"
   ;;
   --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
@@ -157,23 +122,25 @@
   --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
   ;;
+  --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
+  ;;
   --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
   ;;
-  --enable-gprof) gprof="yes"
-  ;;
-  --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
-  ;;
-  --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
-  ;;
-  --enable-cross) build_cross="yes"
-  ;;
-  --disable-static) disable_static="yes"
-  ;;
-  --disable-rpath) disable_rpath="yes"
-  ;;
-  --strip-binaries) strip_binaries="yes"
-  ;;
-  --with-libgcc) use_libgcc="yes"
-  ;;
-  --with-selinux) have_selinux="yes"
+  --enable-cross) confvars="$confvars cross"
+  ;;
+  --disable-static) confvars="$confvars static=no"
+  ;;
+  --enable-static) confvars="$confvars static"
+  ;;
+  --disable-rpath) confvars="$confvars rpath=no"
+  ;;
+  --strip-binaries) confvars="$confvars strip"
+  ;;
+  --with-libgcc) confvars="$confvars libgcc"
+  ;;
+  --with-selinux) confvars="$confvars selinux"
+  ;;
+  --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
+  ;;
+  --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
   ;;
   --help|-h) show_help="yes"
@@ -183,4 +150,57 @@
   esac
 done
+
+if test -z "$cpu" ; then
+    if test -n "$ARCH" ; then
+	cpu="$ARCH"
+    else
+	cpu=`uname -m`
+    fi
+fi
+
+case "$cpu" in
+  x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
+    cpu="i386"
+  ;;
+  x86_64|amd64|x86-64)
+    cpu="x86_64"
+  ;;
+  arm*)
+    case "$cpu" in
+      arm|armv4l)
+	cpuver=4
+      ;;
+      armv5tel|armv5tejl)
+	cpuver=5
+      ;;
+      armv6j|armv6l)
+	cpuver=6
+      ;;
+      armv7a|armv7l)
+	cpuver=7
+      ;;
+    esac
+    cpu="arm"
+  ;;
+  aarch64)
+    cpu="aarch64"
+  ;;
+  alpha)
+    cpu="alpha"
+  ;;
+  "Power Macintosh"|ppc|ppc64)
+    cpu="ppc"
+  ;;
+  mips)
+    cpu="mips"
+  ;;
+  s390)
+    cpu="s390"
+  ;;
+  *)
+    echo "Unsupported CPU"
+    exit 1
+  ;;
+esac
 
 # Checking for CFLAGS
@@ -190,56 +210,51 @@
 
 if test "$mingw32" = "yes" ; then
-    if test x"$tccdir" = x""; then
-    tccdir="tcc"
-    fi
-    if test -z "$prefix" ; then
-    prefix="C:/Program Files/${tccdir}"
-    fi
-    if test -z "$sharedir" ; then
-    sharedir="${prefix}"
-    fi
-    execprefix="$prefix"
-    bindir="${prefix}"
-    tccdir="${prefix}"
-    libdir="${prefix}/lib"
-    docdir="${sharedir}/doc"
-    mandir="${sharedir}/man"
-    infodir="${sharedir}/info"
+    if test "$source_path_used" = "no"; then
+      source_path="."
+    fi
+    if test "$cc" = gcc; then
+      test -z "$LDFLAGS" && LDFLAGS="-static"
+    fi
+    test -z "$prefix" && prefix="C:/Program Files/tcc"
+    test -z "$tccdir" && tccdir="${prefix}"
+    test -z "$bindir" && bindir="${tccdir}"
+    test -z "$docdir" && docdir="${tccdir}/doc"
+    test -z "$libdir" && libdir="${tccdir}/libtcc"
+    confvars="$confvars WIN32"
     LIBSUF=".lib"
     EXESUF=".exe"
+    DLLSUF=".dll"
 else
     if test -z "$prefix" ; then
-    prefix="/usr/local"
+      prefix="/usr/local"
     fi
     if test -z "$sharedir" ; then
-    sharedir="${prefix}/share"
+      sharedir="${prefix}/share"
     fi
     if test x"$execprefix" = x""; then
-    execprefix="${prefix}"
+      execprefix="${prefix}"
     fi
     if test x"$libdir" = x""; then
-    libdir="${execprefix}/lib"
+      libdir="${execprefix}/lib"
     fi
     if test x"$bindir" = x""; then
-    bindir="${execprefix}/bin"
+      bindir="${execprefix}/bin"
+    fi
+    if test x"$docdir" = x""; then
+      docdir="${sharedir}/doc"
+    fi
+    if test x"$mandir" = x""; then
+      mandir="${sharedir}/man"
+    fi
+    if test x"$infodir" = x""; then
+      infodir="${sharedir}/info"
     fi
     if test x"$tccdir" = x""; then
-    tccdir="tcc"
-    fi
-    if test x"$docdir" = x""; then
-    docdir="${sharedir}/doc/${tccdir}"
-    fi
-    if test x"$mandir" = x""; then
-    mandir="${sharedir}/man"
-    fi
-    if test x"$infodir" = x""; then
-    infodir="${sharedir}/info"
-    fi
-    tccdir="${libdir}/${tccdir}"
+      tccdir="${libdir}/tcc"
+    fi
+    if test x"$includedir" = x""; then
+      includedir="${prefix}/include"
+    fi
 fi # mingw32
-
-if test x"$includedir" = x""; then
-includedir="${prefix}/include"
-fi
 
 if test x"$show_help" = "xyes" ; then
@@ -252,5 +267,5 @@
   --prefix=PREFIX          install in PREFIX [$prefix]
   --exec-prefix=EPREFIX    install architecture-dependent files in EPREFIX
-                           [same as prefix]
+			   [same as prefix]
   --bindir=DIR             user executables in DIR [EPREFIX/bin]
   --libdir=DIR             object code libraries in DIR [EPREFIX/lib]
@@ -267,18 +282,21 @@
   --sysroot=PREFIX         prepend PREFIX to library/include paths []
   --cc=CC                  use C compiler CC [$cc]
+  --ar=AR                  create archives using AR [$ar]
   --extra-cflags=          specify compiler flags [$CFLAGS]
   --extra-ldflags=         specify linker options []
+  --cpu=CPU                CPU [$cpu]
   --strip-binaries         strip symbol tables from resulting binaries
   --disable-static         make libtcc.so instead of libtcc.a
+  --enable-static          make libtcc.a instead of libtcc.dll (win32)
   --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
+  --with-libgcc            use libgcc_s.so.1 instead of libtcc1.a
   --enable-cross           build cross compilers
-  --with-selinux           use mmap for exec mem [needs writable /tmp]
+  --with-selinux           use mmap for executable memory (with tcc -run)
   --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
+  --triplet=...            specify system library/include directory triplet
+  --config-uClibc,-musl,-mingw32... enable system specific configurations
 EOF
 #echo "NOTE: The object files are build at the place where configure is launched"
@@ -290,75 +308,98 @@
 strip="${cross_prefix}${strip}"
 
-CONFTEST=./conftest$EXESUF
-
 if test -z "$cross_prefix" ; then
+  CONFTEST=./conftest$EXESUF
   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
-      triplet="$($CONFTEST triplet)"
-      if test -f "/usr/lib/$triplet/crti.o" ; then
-        tcc_lddir="lib/$triplet"
-        multiarch_triplet="$triplet"
-      elif test -f "/usr/lib64/crti.o" ; then
-        tcc_lddir="lib64"
-      fi
-
-      if test "$cpu" = "armv4l" ; then
-        if test "${triplet%eabihf}" != "$triplet" ; then
-           confvars="$confvars arm_eabihf"
-        elif test "${triplet%eabi}" != "$triplet" ; then
-           confvars="$confvars arm_eabi"
-        fi
-        if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
-           confvars="$confvars arm_vfp"
+  fi
+  bigendian="$($CONFTEST bigendian)"
+  if test "$mingw32" = "no" ; then
+
+      if test -z "$triplet"; then
+        tt="$($CONFTEST triplet)"
+        if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
+          triplet="$tt"
         fi
       fi
 
-#      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
-
-      if test -f "/lib/ld-uClibc.so.0" ; then
-        confvars="$confvars uClibc"
+      if test -z "$triplet"; then
+        if test $cpu = "x86_64" -o $cpu = "aarch64" ; then
+          if test -f "/usr/lib64/crti.o" ; then
+            tcc_lddir="lib64"
+          fi
+        fi
       fi
-# gr: maybe for after the release:
-#       tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
-       # echo "elfinterp           $tcc_elfinterp"
-
-    fi
+
+      if test "$cpu" = "arm" ; then
+	if test "${triplet%eabihf}" != "$triplet" ; then
+	   confvars="$confvars arm_eabihf"
+	elif test "${triplet%eabi}" != "$triplet" ; then
+	   confvars="$confvars arm_eabi"
+	fi
+	if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
+	   confvars="$confvars arm_vfp"
+	fi
+      fi
+
+      if test "$suggest" = "yes"; then
+        if test -f "/lib/ld-uClibc.so.0" ; then
+          echo "Perhaps you want ./configure --config-uClibc"
+        fi
+        if test -f "/lib/ld-musl-$cpu.so.1"; then
+          echo "Perhaps you want ./configure --config-musl"
+        fi
+      fi
   fi
 else
   # if cross compiling, cannot launch a program, so make a static guess
   case $cpu in
-    powerpc|mips|s390)  bigendian=yes;;
+    ppc|mips|s390)  bigendian=yes;;
   esac
 fi
 
-cat <<EOF
-Binary  directory   $bindir
-TinyCC directory    $tccdir
-Library directory   $libdir
-Include directory   $includedir
-Manual directory    $mandir
-Info directory      $infodir
-Doc directory       $docdir
-Target root prefix  $sysroot
-Source path      $source_path
-C compiler       $cc
-Target OS        $targetos
-CPU              $cpu
-Big Endian       $bigendian
-gprof enabled    $gprof
-cross compilers  $build_cross
-use libgcc       $use_libgcc
-EOF
-
+if test "$bigendian" = "yes" ; then
+  confvars="$confvars BIGENDIAN"
+fi
+
+# a final configuration tuning
+if ! echo "$cc" | grep -q "tcc"; then
+  OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
+  # we want -Wno- but gcc does not always reject unknown -Wno- options
+  OPT2="-Wpointer-sign -Wsign-compare -Wunused-result"
+  if echo "$cc" | grep -q "clang"; then
+    OPT1="$OPT1 -fheinous-gnu-extensions"
+    OPT2="$OPT2 -Wstring-plus-int"
+  fi
+  $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
+  for o in $OPT1; do # enable these options
+    if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
+  done
+  for o in $OPT2; do # disable these options
+    if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
+  done
+  # cat cc_msg.txt
+  # echo $CFLAGS
+  rm -f cc_msg.txt a.out
+fi
+
+fcho() { if test -n "$2"; then echo "$1$2"; fi }
+
+fcho "Binary directory    " "$bindir"
+fcho "TinyCC directory    " "$tccdir"
+fcho "Library directory   " "$libdir"
+fcho "Include directory   " "$includedir"
+fcho "Manual directory    " "$mandir"
+fcho "Info directory      " "$infodir"
+fcho "Doc directory       " "$docdir"
+fcho "Target root prefix  " "$sysroot"
+echo "Source path         $source_path"
+echo "C compiler          $cc ($gcc_major.$gcc_minor)"
+echo "Target OS           $targetos"
+echo "CPU                 $cpu"
+fcho "Triplet             " "$triplet"
+fcho "Config              " "${confvars# }"
 echo "Creating config.mak and config.h"
 
@@ -369,5 +410,4 @@
 tccdir=\$(DESTDIR)$tccdir
 libdir=\$(DESTDIR)$libdir
-ln_libdir=$libdir
 includedir=\$(DESTDIR)$includedir
 mandir=\$(DESTDIR)$mandir
@@ -377,5 +417,4 @@
 GCC_MAJOR=$gcc_major
 GCC_MINOR=$gcc_minor
-HOST_CC=$host_cc
 AR=$ar
 STRIP=$strip -s -R .comment -R .note
@@ -384,4 +423,5 @@
 LIBSUF=$LIBSUF
 EXESUF=$EXESUF
+DLLSUF=$DLLSUF
 EOF
 
@@ -393,7 +433,14 @@
   fi
 }
+
 print_mak() {
   if test -n "$2"; then
     echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
+  fi
+}
+
+print_mak_int() {
+  if test -n "$2"; then
+    echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
   fi
 }
@@ -408,98 +455,35 @@
 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
 print_mak CONFIG_LDDIR "$tcc_lddir"
-print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
-
-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
-elif test "$cpu" = "x86-64" ; then
-  echo "ARCH=x86-64" >> config.mak
-  echo "#define HOST_X86_64 1" >> $TMPH
-elif test "$cpu" = "armv4l" ; then
-  echo "ARCH=arm" >> config.mak
-  echo "#define HOST_ARM 1" >> $TMPH
-  echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
-elif test "$cpu" = "powerpc" ; then
-  echo "ARCH=ppc" >> config.mak
-  echo "#define HOST_PPC 1" >> $TMPH
-elif test "$cpu" = "mips" ; then
-  echo "ARCH=mips" >> config.mak
-  echo "#define HOST_MIPS 1" >> $TMPH
-elif test "$cpu" = "s390" ; then
-  echo "ARCH=s390" >> config.mak
-  echo "#define HOST_S390 1" >> $TMPH
-elif test "$cpu" = "alpha" ; then
-  echo "ARCH=alpha" >> config.mak
-  echo "#define HOST_ALPHA 1" >> $TMPH
+print_mak CONFIG_TRIPLET "$triplet"
+print_mak_int TCC_CPU_VERSION "$cpuver"
+
+if test "$cpu" = "aarch64" ; then
+  echo "ARCH=arm64" >> config.mak
 else
-  echo "Unsupported CPU"
-  exit 1
-fi
-
+  echo "ARCH=$cpu" >> config.mak
+fi
 echo "TARGETOS=$targetos" >> config.mak
 
 for v in $confvars ; do
-  echo "CONFIG_$v=yes" >> config.mak
+  if test "${v%=*}" = "$v"; then
+    echo "CONFIG_$v=yes" >> config.mak
+  else
+    echo "CONFIG_$v" >> config.mak
+  fi
 done
-if test "$noldl" = "yes" ; then
-  echo "CONFIG_NOLDL=yes" >> config.mak
-fi
-if test "$mingw32" = "yes" ; then
-  echo "CONFIG_WIN32=yes" >> config.mak
-  echo "#define CONFIG_WIN32 1" >> $TMPH
-fi
-if test "$cygwin" = "yes" ; then
-  echo "#ifndef _WIN32" >> $TMPH
-  echo "# define _WIN32" >> $TMPH
-  echo "#endif" >> $TMPH
-  echo "AR=ar" >> config.mak
-fi
-if test "$bigendian" = "yes" ; then
-  echo "WORDS_BIGENDIAN=yes" >> config.mak
-  echo "#define WORDS_BIGENDIAN 1" >> $TMPH
-fi
-if test "$gprof" = "yes" ; then
-  echo "TARGET_GPROF=yes" >> config.mak
-  echo "#define HAVE_GPROF 1" >> $TMPH
-fi
-if test "$build_cross" = "yes" ; then
-  echo "CONFIG_CROSS=yes" >> config.mak
-fi
-if test "$disable_static" = "yes" ; then
-  echo "DISABLE_STATIC=yes" >> config.mak
-fi
-if test "$disable_rpath" = "yes" ; then
-  echo "DISABLE_RPATH=yes" >> config.mak
-fi
-if test "$strip_binaries" = "yes" ; then
-  echo "STRIP_BINARIES=yes" >> config.mak
-fi
-if test "$use_libgcc" = "yes" ; then
-  echo "#define CONFIG_USE_LIBGCC" >> $TMPH
-  echo "CONFIG_USE_LIBGCC=yes" >> config.mak
-fi
-if test "$have_selinux" = "yes" ; then
-  echo "#define HAVE_SELINUX" >> $TMPH
-  echo "HAVE_SELINUX=yes" >> config.mak
-fi
 
 version=`head $source_path/VERSION`
-echo "VERSION=$version" >>config.mak
+echo "VERSION = $version" >> config.mak
 echo "#define TCC_VERSION \"$version\"" >> $TMPH
 echo "@set VERSION $version" > config.texi
-echo "SRC_PATH=$source_path" >>config.mak
 
 if test "$source_path_used" = "yes" ; then
     case $source_path in
-       /*) echo "top_srcdir=$source_path";;
-        *) echo "top_srcdir=\$(TOP)/$source_path";;
+       /*) echo "TOPSRC=$source_path";;
+	*) echo "TOPSRC=\$(TOP)/$source_path";;
      esac >>config.mak
 else
-     echo 'top_srcdir=$(TOP)' >>config.mak
-fi
-echo 'top_builddir=$(TOP)' >>config.mak
+     echo 'TOPSRC=$(TOP)' >>config.mak
+fi
 
 diff $TMPH config.h >/dev/null 2>&1
@@ -520,19 +504,20 @@
     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
-         ;;
+	 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
+
+    ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
 }
 
 if test "$source_path_used" = "yes" ; then
-  FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
+  FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
   for f in $FILES ; do
     fn_makelink $source_path $f
