#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/configure                     */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Tue Jan 25 16:05:10 1994                          */
#*    Last change :  Wed Jun 12 20:23:20 2019 (serrano)                */
#*    Copyright   :  1994-2019 Manuel Serrano, see LICENSE file        */
#*    -------------------------------------------------------------    */
#*    The Bigloo configuration file                                    */
#*    -------------------------------------------------------------    */
#*    Please, dont talk to me about autoconf. I simply dont want       */
#*    to hear about it...                                              */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    Bigloo revision number                                           */
#*---------------------------------------------------------------------*/
release=4.3f
version=
bigloourl=http://www-sop.inria.fr/indes/fp/Bigloo

bigloosvn=ssh://hop@hop.inria.fr/bigloo

#*---------------------------------------------------------------------*/
#*    User variables                                                   */
#*---------------------------------------------------------------------*/
#*--- paths -----------------------------------------------------------*/
prefix=/usr/local
bindir=$prefix/bin
libdir=$prefix/lib
fildir=bigloo/$release
zipdir=$libdir/$fildir
dlldir=$libdir/$fildir
mandir=$prefix/man/man1
infodir=$prefix/info
docdir=$prefix/doc/bigloo-$release
tmpdir=/tmp
lispdir=
rpath=

#*--- api -------------------------------------------------------------*/
importantapis="pthread fthread srfi18 ssl sqlite web multimedia mail calendar pkgcomp pkglib text srfi1 crypto openpgp csv upnp libuv"
apis="$importantapis gstreamer phidget alsa pulseaudio wav flac mpg123 phone avahi srfi27 packrat patch"

#*--- bee configuration -----------------------------------------------*/
bee=partial # "partial" or "full"

#*--- build directory -------------------------------------------------*/
buildtmp=$TMPDIR

#*--- C back-end user configure ---------------------------------------*/
nativebackend=yes # set to "no" not to install the native (C) back-end
ccstyle=gcc
cc=$CC  # left blank for default automatic configuration
cflags=$CFLAGS
lflags=$LDFLAGS
lcustomflags=

bigloo=$BIGLOO # used only for cross compiling
if [ "$BFLAGS " != " " ]; then
  bflags=$BFLAGS;
else
  bflags="-O3 -fcfa-arithmetic -q";
fi
bootflags=""
featureflags=
coflags=-O3
crpath=

cstrip=""
cwarning=""
cpicflags="demanded" # Possible values for cpicflags are:
             #  - "no" not to use position independent code (recommended)
             #  - "demanded" auto configuration but with a preference to "no"
             #  - any legal C compiler option that enables PIC code.
             #  - blank (uninitalized) for automatic configuration of the
#    position independent code compiler option
cnanflags=-DBGL_NAN_TAGGING=0
as=          # left blank for autoconfiguration
ar=          # left blank for autoconfiguration
ranlib=      # left blank for autoconfiguration
arflags=     # left blank for autoconfiguration
ldstyle=gcc
ldflags=
ld=
ldlibs=-lc
ldcomplibs="-lc -lm"
strip=       # left blank for autoconfiguration
longlong=    # The C type to represent long long integers
havelonglong=
stringsplit="0"

gcconfigureopt="--disable-gcj-support --disable-java-finalization --disable-libcord"
gcconfigurethreadsopt=--enable-thread

belong_prealloc_min=-10
belong_prealloc_max=100

bglnantagging=0

#*--- Java back-end user configuration --------------------------------*/
jvmbackend=no # set to "no" not to install the Jvm back-end
zip=zip
jar="jar cmf"
zflags=
javac=javac
jcflags=-O
java=java
jflags=
jvflags=-noverify
jshell=sh

#*--- Misc user configuration -----------------------------------------*/
shell=/bin/sh
ccshell=$shell
shell_rm="rm"
shell_mv="mv"
bgl_shell_rm=$BGLRM
bgl_shell_mv=$BGLMV
emacs=
makeinfo=makeinfo
makeinfoopt="-U oldinfo"
texi2dvi=texi2dvi
texi2dviopt=-b
texi2html=texi2html
texi2htmlopt="-menu -monolithic -number"
texi2pdf=texi2pdf
iinfo=install-info
dlopenopt=-ldl
dirname=dirname
defaultbackend="native"
aout=""
abat=""
exe=""
cobj=o
specific=""
ln_s="ln -s"

#*--- gmp version (left blank for autoconfiguration) ------------------*/
gmplib=
gmpversion=
gmpforce=no
customgmp=no
gmpsrc=$GMPSRC
gmpconfigureopt=

if [ "$gmpsrc " = " " ]; then
  gmpsrc=gmp/gmp-6.1.2.tgz
fi  

srfi27force=no

#*--- resolv version (left blank for autoconfiguration) ---------------*/
resolv=
resolvforce=no

#*--- unistring version (left blank for autoconfiguration) ------------*/
unistring=
unistringforce=no
customunistring=
unistringsrc=$UNISTRINGSRC
unistringconfigureopt=

if [ "$unistringsrc " = " " ]; then
  unistringversion=0.9.10
  unistringsrc=libunistring/libunistring-$unistringversion.tgz
fi  

#*--- socket library (left empty for automatic configuration) ---------*/
socketlibs=

#*--- posix threads library (left blank for autoconfiguration) --------*/
threadsupport=
pthreadlibs=
pthreadtimedlock=1
pthreadtermsig=15
pthreadlocalstorage=

#*--- openssl library (left blank for autoconfiguration) --------------*/
openssllibs=
openssldtls=
openssltls1=
openssltls11=
openssltls12=
opensslrand=
opensslv2=
opensslv23=
opensslcflags=
opensslgetter=

#*--- sqlite library (left blank for autoconfiguration) ---------------*/
sqlitelibs=
sqltinyforce=no

#*--- dbus library (left blank for autoconfiguration) -----------------*/
dbuslibs=

#*--- gstreamer (left blank for autoconfiguration) --------------------*/
gstreamer=
gstreamerlibs=
gstreamercflags=
gstreameraudio=
gstreameraudiolibs=
gstreameraudiocflags=
gstusethread=0

#*--- alsa (left blank for autoconfiguration) -------------------------*/
alsa=
alsalibs=
alsacflags=

#*--- pulseaudio (left blank for autoconfiguration) --------------------*/
pulseaudio=
pulseaudiolibs=
pulseaudiocflags=

#*--- mpg123 (left blank for autoconfiguration) -----------------------*/
mpg123=
mpg123libs=
mpg123cflags=

#*--- flac (left blank for autoconfiguration) -------------------------*/
flac=
flaclibs=
flaccflags=

#*--- avahi (left blank for autoconfiguration) ------------------------*/
avahi=
avahilibs=
avahicflags=

#*--- libuv (left blank for autoconfiguration) ------------------------*/
libuv=
libuvlibs=
libuvcflags=
customlibuv=yes
libuvconfigureopt=
#* libuvversion=master-18jul2014                                       */
#* libuvversion=1.x-24jan2015                                          */
#* libuvversion=v1.19.1                                                */
#* libuvversion=v1.19.2                                                */
libuvversion=v1.20.3

#*--- patch (left blank for autoconfiguration) ------------------------*/
patchapi=
patchlibs=
patchcflags=

#*--- phidget (left blank for autoconfiguration) ----------------------*/
phidget=
phidgetlibs=
phidgetlibdir=$PHIDGETLIBDIR
phidgetcflags="$PHIDGETCFLAGS"
phidgetversion=21

#*--- regexp ----------------------------------------------------------*/
regexp=
regexphasfreestudy=0

#*--- gc source directory (left blank for default configuration) ------*/
customgc=yes
#gccustom=bdwgc-7_2alpha5-20110313
#gccustom=bdwgc-7_2alpha5-20110107
#gccustom=gc-7.2alpha6
#gccustom=gc-7.2d
#gccustom=gc-7.3alpha1-20120316
#gccustom=gc-7.3alpha2
#gccustom=gc-7.3alpha3-20130330
#gccustom=gc-7.5.0-27may2016
#gccustom=gc-7.6.2
gccustom=gc-8.0.2
gcversion=
gcbump=0
cgcflags=

# the following variables are relevant only when using
# standard (i.e. already existing and operational) Boehm's GC
# and when customgc=no
stdgclib=gc
gcneedstackbase=0

isoc99=0
stdint=
stdlibint=0
unistdint=

#*--- indent ----------------------------------------------------------*/
indent="indent -npro -bap -bad -nbc -bl -ncdb -nce -nfc1 -ip0 -nlp -npcs -nsc -nsob -cli0.5 -di0 -l80 -d1 -c0 -ts2 -st"

#*--- mask of Bigloo intalled files -----------------------------------*/
# obsolete, don't use it, use modXXX instead
bmask=755
modexe=755
moddir=755
modfile=644

#*--- ld shared library option ----------------------------------------*/
# set $ldopt to `no-share' if you don't want shared library
ldopt=
ldbuildsharedopt=
ldrpath=

# set $ldsoname to `blank' if you want to force it empty
ldsoname=
ldsonameopt=
ldinstallname=
ldinstallnamedirroot=$LDINSTALLNAMEDIRROOT

if [ "$ldinstallnamedirroot " = " " ]; then
  ldinstallnamedirroot=lib
fi

sharedsuffix=so
sharedlibraryclosed=yes
sharedlibrarygcclosed='-l$(GCLIB)-$(RELEASE)'

#*--- should the compiler be dynamically linked?  ---------------------*/
# the legal value for that variable is `yes' or `no'
sharedcompiler=no
sharedbde=no

#*--- forced OS -------------------------------------------------------*/
hostos=
hostosversion=
hostcpu=
jvmrecettebootpath=
jvmapibootpath=
oscharset=

buildos=
buildosversion=
buildcpu=

#*--- cygwin specific configuration -----------------------------------*/
# The location where cygwin is installed
cygwindospath=
cygwindosjvm="yes"

#*--- mingw/macosx specific configuration -----------------------------*/
mingw="no"
macosx=auto

#*--- android specifics -----------------------------------------------*/
droidroot=$DROID_ROOT
droidsdkroot=$DROID_SDK_ROOT
droidtarget=generic
droidtmp=
droidadb=adb

#*---------------------------------------------------------------------*/
#*    Hacker variables                                                 */
#*    -------------------------------------------------------------    */
#*    Dont modifiy these variables unless you know what you are        */
#*    doing.                                                           */
#*---------------------------------------------------------------------*/
#*--- configure debugging ---------------------------------------------*/
configurelog=configure.log
abortmissing=no

#*--- The basename of the compiler and tools --------------------------*/
afile=bglafile
jfile=bgljfile
btags=bgltags
bdepend=bgldepend
bmake=bglmake
bpp=bglpp
bprof=bglprof
mco=bglmco
jas=bgljas
bmem=bglmem
bmemrun=bglmemrun
bdb=bgldb
bglpkg=bglpkg

#*--- libraries -------------------------------------------------------*/
libraryname=bigloo

#--- additional user library used to link bigloo applications ---------*/
extralibs="-lm"
extragclibs="-lc"

#*--- custom GC configuration -----------------------------------------*/
gcincdir=
gclibdir=
customgclib=bigloogc
gchaveblocking=0
gchavedoblocking=0
gcfinalizer=0
gcparallelmark=

#*--- Cross Compilation -----------------------------------------------*/
hostsh=
buildsh=

#*--- bglpkg compilation ----------------------------------------------*/
# valid values are "no", "yes" or "force"
enable_bglpkg="no"

#*--- pcre configuration ----------------------------------------------*/
# valid values are "no", "yes"
enable_configure_pcre="yes"
custompcre=
pcresrc=$PCRESRC

if [ "$pcresrc " = " " ]; then
  pcreversion=8.43
  pcresrc=pcre/pcre-$pcreversion.tgz
fi  

#*---------------------------------------------------------------------*/
#*                 !!! DONT EDIT AFTER THIS LINE !!!                   */
#*---------------------------------------------------------------------*/
action=all
actiongc=install
branch="`echo $release | sed 's/[.a-z]*//g'`0";
mode=standard
tuning=
makefile_cfg=Makefile.config
makefile_build=Makefile.buildconfig
pwd=`pwd`
bootdir=$pwd
buildbindir=
cgcfinalflags="-DFINALIZE_ON_DEMAND"
bigloo_h=
bigloo_gc_h=
bigloo_static_h=
bigloo_config_h=
bigloo_config_jvm=
bigloo_config_sch=
summary=yes
java_configured=no
os=posix
gcspecial=
gcthread=
hardtune=
emacswarning=
stacksizerequired=2
configureinfo="no"
dnscache=1
scmpkgversion=0.0.1

autoconfdir=`dirname $0 2> /dev/null`/autoconf

if [ $? != "0" ]; then
   autoconfdir="autoconf"
fi

logopt="$*"

autoconf="$autoconfdir/runtest -v1 -- "

# Argument parsing
while : ; do
  case $1 in
    "")
      break;;

    --bootconfig)
      prefix=$PWD;
      bindir=$PWD/bin;
      libdir=$PWD/lib;
      fildir=bigloo/$release;
      zipdir=$libdir/$fildir;
      dlldir=$libdir/$fildir;
      bootdir=$PWD;
      mandir=$HOME/house/man/man1
      lispdir=$HOME/emacs/site-lisp/bigloo;
      docdir=$PWD/manuals;
      sharedcompiler=no;
      sharedbde=yes;
      infodir=$HOME/house/info;
      java=java8;
      javac=javac8;
      ld=gcc;
      cflags="$cflags -Wpointer-arith -Wswitch -Wtrigraphs -DBGL_BOOTCONFIG";
      coflags="$coflags";
      bootflags="$bootflags -cg";
      jvmbackend="force";
      mode=standard;
      configureinfo="yes";
      bee="full";
      havebdb=1;
      pthreadlocalstorage=;
      action="all";;

    --bootdir=*)
      bootdir="`echo $1 | sed 's/^[^=]*=//'`";;

    --build-bindir=*)
      buildbindir="`echo $1 | sed 's/^[^=]*=//'`";;

    --thirdparty-configure-opt=*)
      opt="`echo $1 | sed 's/^[^=]*=//'`";
      gcconfigureopt="$gcconfigureopt $opt";
      libuvconfigureopt="$libuvconfigureopt $opt";
      pcreconfigureopt="$pcreconfigureopt $opt";
      unistringconfigureopt="$unistringconfigureopt $opt";
      gmpconfigureopt="$gmpconfigureopt $opt";;
      
    --bigloo_config.h)
      action="bigloo_config";;

    --bigloo.h=*)
      action="bigloo_config";
      bigloo_h="`echo $1 | sed 's/^[^=]*=//'`";;

    --bigloo_gc.h=*)
      action="bigloo_config";
      bigloo_gc_h="`echo $1 | sed 's/^[^=]*=//'`";;

    --bigloo_static.h=*)
      action="bigloo_config";
      bigloo_static_h="`echo $1 | sed 's/^[^=]*=//'`";;

    --bigloo_config.h=*)
      action="bigloo_config";
      bigloo_config_h="`echo $1 | sed 's/^[^=]*=//'`";;

    --bigloo_config.jvm=*)
      action="bigloo_config";
      bigloo_config_jvm="`echo $1 | sed 's/^[^=]*=//'`";;

    --bigloo_config.sch=*)
      action="bigloo_config";
      bigloo_config_sch="`echo $1 | sed 's/^[^=]*=//'`";;

    --bigloo_config.el=*)
      action="bigloo_config_el";
      bigloo_config_el="`echo $1 | sed 's/^[^=]*=//'`";;

    --Makefile.config)
      action="Makefile.config";;

    --configure.log=*)
      configurelog="`echo $1 | sed 's/^[^=]*=//'`";;

    --abort-missing)
      abortmissing=yes;;

    --bindir=*)
      bindir="`echo $1 | sed 's/^[^=]*=//'`";;

    --libdir=*)
      libdir="`echo $1 | sed 's/^[^=]*=//'`";
      zipdir=$libdir/$fildir;
      dlldir=$libdir/$fildir;;

    --gcprefix=*)
      gcprefix="`echo $1 | sed 's/^[^=]*=//'`";
      gclibdir=$gcprefix/lib;
      gcincdir=$gcprefix/include/gc;;

    --gclibdir=*)
      gclibdir="`echo $1 | sed 's/^[^=]*=//'`";;

    --gcincdir=*)
      gcincdir="`echo $1 | sed 's/^[^=]*=//'`";;

    --gccustomversion=*)
      gccustom="`echo $1 | sed 's/^[^=]*=//'`";;

    --gccustominstall=*)
      actiongc="`echo $1 | sed 's/^[^=]*=//'`";;

    --gcparallelmark=*)
      gcparallelmark="`echo $1 | sed 's/^[^=]*=//'`";;

    --gcbump)
      gcbump=1;;
    
    --gcbump=*)
      if [ "`echo $1 | sed 's/^[^=]*=//'` " = "yes " ]; then
        gcbump=1;
      fi
      ;;

    --fildir=*)
      fildir="`echo $1 | sed 's/^[^=]*=//'`";;

    --zipdir=*)
      zipdir="`echo $1 | sed 's/^[^=]*=//'`";;

    --dlldir=*)
      dlldir="`echo $1 | sed 's/^[^=]*=//'`";;

    --mandir=*)
      mandir="`echo $1 | sed 's/^[^=]*=//'`";;

    --infodir=*)
      infodir="`echo $1 | sed 's/^[^=]*=//'`";;

    --docdir=*)
      docdir="`echo $1 | sed 's/^[^=]*=//'`";;

    --tmpdir=*)
      tmpdir="`echo $1 | sed 's/^[^=]*=//'`";;

    --tmp=*)
      buildtmp="`echo $1 | sed 's/^[^=]*=//'`";;

    --emacs=*)
      emacs="`echo $1 | sed 's/^[^=]*=//'`";;

    --xemacs=*)
      emacs="`echo $1 | sed 's/^[^=]*=//'`";;

    --indent=*)
      indent="`echo $1 | sed 's/^[^=]*=//'`";;

    --dirname=*)
      dirname="`echo $1 | sed 's/^[^=]*=//'`";;

    --lispdir=*)
      lispdir="`echo $1 | sed 's/^[^=]*=//'`";;

    --prefix=*)
      prefix="`echo $1 | sed 's/^[^=]*=//'`";
      bindir=$prefix/bin;
      libdir=$prefix/lib;
      fildir=bigloo/$release;
      zipdir=$libdir/$fildir;
      dlldir=$libdir/$fildir;
      mandir=$prefix/man/man1;
      infodir=$prefix/info;
      docdir=$prefix/doc/bigloo-$release;;

    --bigloo=*)
      bigloo="`echo $1 | sed 's/^[^=]*=//'`";;

    --cc=*)
      cc="`echo $1 | sed 's/^[^=]*=//'`";;

    --as=*)
      as="`echo $1 | sed 's/^[^=]*=//'`";;

    --ld=*)
      ld="`echo $1 | sed 's/^[^=]*=//'`";;

    --shell=*)
      shell="`echo $1 | sed 's/^[^=]*=//'`";;

    --mv=*)
      bgl_shell_mv="`echo $1 | sed 's/^[^=]*=//'`";;

    --rm=*)
      bgl_shell_rm="`echo $1 | sed 's/^[^=]*=//'`";;

    --bflags=*)
      bflags="`echo $1 | sed 's/^[^=]*=//'`";;

    --cflags=*)
      cflags="`echo $1 | sed 's/^[^=]*=//'`";;

    --lflags=*)
      lflags="`echo $1 | sed 's/^[^=]*=//'`";;

    --coflags=*)
      coflags="`echo $1 | sed 's/^[^=]*=//'`";;

    --ldlibs=*)
      ldlibs="`echo $1 | sed 's/^[^=]*=//'`";;

    --ldcomplibs=*)
      ldcomplibs="`echo $1 | sed 's/^[^=]*=//'`";;

    --ldflags=*)
      ldflags="`echo $1 | sed 's/^[^=]*=//'`";;

    --stringsplit=*)
      stringsplit="`echo $1 | sed 's/^[^=]*=//'`";;

    --native=*)
      nativebackend="`echo $1 | sed 's/^[^=]*=//'`";;

    --sharedcompiler=*)
      sharedcompiler="`echo $1 | sed 's/^[^=]*=//'`";;

    --sharedbde=*)
      sharedbde="`echo $1 | sed 's/^[^=]*=//'`";;

    --bee=partial)
      bee="partial";;

    --bee=full)
      bee="full";;

    --a.out=*)
      aout="`echo $1 | sed 's/^[^=]*=//'`";;

    --a.bat=*)
      abat="`echo $1 | sed 's/^[^=]*=//'`";;

    --jvm=*)
      jvmbackend="`echo $1 | sed 's/^[^=]*=//'`";;

    --java=*)
      java="`echo $1 | sed 's/^[^=]*=//'`";;

    --javac=*)
      javac="`echo $1 | sed 's/^[^=]*=//'`";;

    --javaprefix=*)
      java="`echo $1 | sed 's/^[^=]*=//'`"/java;
      javac="`echo $1 | sed 's/^[^=]*=//'`"/javac;
      jar="`echo $1 | sed 's/^[^=]*=//'`/jar cmf";;

    --javashell=sh)
      jshell="sh";;

    --javashell=msdos)
      jshell="msdos";;

    --native-default-backend)
      defaultbackend="native";;

    --jvm-default-backend)
      defaultbackend="jvm";;

    --no-share)
      ldopt="no-share";;

    --no-ldpreload)
      ldpreload="no";;

    --force-hostos=*)
      hostos="`echo $1 | sed 's/^[^=]*=//'`";;

    --os-win32)
      hostos="win32";;

    --os-macosx)
      hostos="darwin";;

    --no-os-macosx)
      macosx=false;;

    --os-android)
      hostos="android";;

    --android-sdk-root=*)
      droidsdkroot="`echo $1 | sed 's/^[^=]*=//'`";;

    --android-root=*)
      droidroot="`echo $1 | sed 's/^[^=]*=//'`";;

    --android-target=*)
      droidtarget="`echo $1 | sed 's/^[^=]*=//'`";;

    --android-tmp=*)
      droidtmp="`echo $1 | sed 's/^[^=]*=//'`";;

    --android-adb=*)
      droidadb="`echo $1 | sed 's/^[^=]*=//'`";;

    --cygwin-dos-path=*)
      cygwindospath="`echo $1 | sed 's/^[^=]*=//'`";;

    --cygwin-dos-jvm=yes)
      cygwindosjvm="yes";;

    --cygwin-dos-jvm=no)
      cygwindosjvm="no";;

    --arch=athlon)
      hardtune="athlon";
      gcspecial=-DUSE_3DNOW_PREFETCH;;

    --arch=athlon-tbird)
      hardtune="athlon-tbird";
      gcspecial=-DUSE_3DNOW_PREFETCH;;

    --arch=athlon-xp)
      hardtune="athlon-xp";
      gcspecial=-DUSE_3DNOW_PREFETCH;;

    --arch=athlon-mp)
      hardtune="athlon-mp";
      gcspecial=-DUSE_3DNOW_PREFETCH;;

    --arch=k6-2)
      hardtune="k6-2";
      gcspecial=-DUSE_3DNOW_PREFETCH;;

    --arch=k6-3)
      hardtune="k6-3";
      gcspecial=-DUSE_3DNOW_PREFETCH;;

    --arch=pentium3)
      hardtune="pentium3";
      gcspecial=-DUSE_I686_PREFETCH;;

    --arch=pentium4)
      hardtune="pentium4";
      gcspecial=-DUSE_I686_PREFETCH;;

    --arch=i586)
      hardtune="i586";;

    --arch=i686)
      hardtune="i686";;

    --no-summary)
      summary=no;;

    --icc)
      if [ "$cc " = " " ]; then
        cc=icc;
      fi;
      as=icc;
      ldopt="no-share";
      coflags="$coflags -O3 -ip";
      customgc=no;
      extralibs="";
      cstrip="no";;

    --clang)
      cflags="-fbracket-depth=1024 $cflags";;

    --strip=no)
      cstrip="no";
      strip="no";;

    --customgc=yes|--customgc)
      customgc=yes;;

    --customgc=no)
      customgc=no;;

    --gcconfigureopt=*)
      gcconfigureopt="`echo $1 | sed 's/^[^=]*=//'`";;

    --custom-all-libs)
      customgc=yes;
      customgmp=yes;
      customunistring=yes;
      customlibuv=yes;
      custompcre=yes;;
      
    --finalization=yes)
      gcfinalizer=1;
      cgcfinalflags=;;

    --finalization=no)
      cgcfinalflags=-DFINALIZE_ON_DEMAND;;

    --stack-check=no)
      stacksizerequired=0;;

    --benchmark=no)
      mode=standard;;

    --benchmark=yes)
      if [ "$tuning " = "MacOS X " ]; then
        echo "*** ERROR: --benchmark is incompatible with --os-macosx";
        exit 1;
      fi;
      mode=benchmark;;

    --debug)
      cflags="$cflags -g";
      bflags="$bflags -cg";;

    --debug2)
      cstrip="";
      cflags="$cflags -g";
      bflags="-cg -q";;

    --cwarningflags=*)
      cwarningflags="`echo $1 | sed 's/^[^=]*=//'`";;

    --cpicflags=*)
      cpicflags="`echo $1 | sed 's/^[^=]*=//'`";;

    --configureinfo=no)
      configureinfo="no";;

    --configureinfo=yes)
      configureinfo="yes";;

    --mingw=yes)
      mingw="yes";;

    --nan-tagging)
      bglnantagging=1;;
      
    --enable-thread|--enable-threads)
      threadsupport=yes;
      addp=1;
      addf=1;
      adds=1;
      for a in $apis; do
        case $a in
          pthread) addp=0;;
          fthread) addf=0;;
          srfi18) adds=0;;
        esac;
      done
      if [ $addf = 1 ]; then
        apis="fthread $apis";
      fi
      if [ $adds = 1 ]; then
        apis="srfi18 $apis";
      fi
      if [ $addp = 1 ]; then
        apis="pthread $apis";
      fi
      ;;

    --disable-thread|--disable-threads)
      threadsupport=no;
      napis=;
      for a in $apis; do
         if [ $a != "fthread" -a $a != "pthread" -a $a != "gstreamer" -a $a != "srfi18" ]; then
           if [ "$napis " = " " ]; then
             napis="$a";
           else
             napis="$napis $a";
           fi
         fi
      done
      apis=$napis;;

    --enable-thread-local-storage)
      pthreadlocalstorage=;;

    --disable-thread-local-storage)
      pthreadlocalstorage=no;;

    --thread-local-storage=auto)
      pthreadlocalstorage=;;

    --enable-gstreamer-thread)
      gstusethread=1;;

    --disable-gstreamer-thread)
      gstusethread=0;;

    --no-gmp|--disable-gmp)
      gmpversion="no";;

    --enable-gmp)
      gmpversion=""
      gmpforce="yes";;

    --customgmp=yes|--customgmp)
      customgmp=yes;;

    --customgmp=no)
      customgmp=no;;

    --gmpsrc=*)
      gmpsrc="`echo $1 | sed 's/^[^=]*=//'`";;

    --gmpconfigureopt=*)
      gmpconfigureopt="`echo $1 | sed 's/^[^=]*=//'`";;

    --no-resolv|--disable-resolv)
      resolv="no";;

    --enable-resolv)
      resolv=""
      resolvforce="yes";;

    --no-unistring|--disable-unistring)
      unistring="no";;

    --enable-unistring)
      unistring=""
      unistringforce="yes";;

    --customunistring=yes)
      customunistring=yes;;

    --customunistring=no)
      customunistring=no;;

    --unistringsrc=*)
      unistringsrc="`echo $1 | sed 's/^[^=]*=//'`";;

    --unistringconfigureopt=*)
      unistringconfigureopt="`echo $1 | sed 's/^[^=]*=//'`";;

    --customlibuv=yes|--customlibuv)
      customlibuv=yes;;

    --customlibuv=no)
      customlibuv=no;;

    --libuvconfigureopt=*)
      libuvconfigureopt="`echo $1 | sed 's/^[^=]*=//'`";;

    --enable-bglpkg)
      enable_bglpkg="force";;

    --disable-bglpkg)
      enable_bglpkg="no";;

    --no-pcre|--disable-pcre)
      enable_configure_pcre="no";;

    --custompcre=yes|--custompcre)
      custompcre=yes;;

    --pcresrc=*)
      pcresrc="`echo $1 | sed 's/^[^=]*=//'`";;

    --sqltiny)
      sqltinyforce="yes";;

    --enable-srfi27)
      srfi27force="yes";;

    --enable-*)
      api="`echo $1 | sed 's/--[^-]*-//'`";
      add=1;
      for a in $apis; do
        if [ "$a " = "$api " ]; then
          add=0;
          break;
        fi
      done
      if [ $add = 1 ]; then
        apis="$api $apis";
      fi
      ;;

    --disable-*)
      api="`echo $1 | sed 's/--[^-]*-//'`";
      napis=;
      for a in $apis; do
         if [ $a != $api ]; then
           if [ "$napis " = " " ]; then
             napis="$a";
           else
             napis="$napis $a";
           fi
         fi
      done
      apis=$napis;;

    --hostsh=*)
      hostsh="`echo $1 | sed 's/^[^=]*=//'`";;

    -*)
      if [ "$1" != "-h" -a "$1" != "-help" -a "$1" != "--help" ]; then
        echo "*** ERROR: unknown option \"$1\""
        echo "Run \"$0 --help\" for available options." >&2;
        exit 1;
      fi
      # Existing apis
      eapis=
      cd $bootdir/api;
      for p in *; do
        if [ -d $p ]; then
          if [ "$eapis " = " " ]; then
            eapis="$p";
          else
            eapis="$eapis|$p";
          fi
        fi
      done;
      cd $bootdir;
      echo "Bigloo compiler:"  >&2;
      echo "   --native=yes|no [default yes]" >&2;
      echo "   --jvm=yes|no|force [default no]" >&2;
      echo "   --bee=partial|full [default partial]" >&2;
      echo "" >&2;
      echo "API:" >&2;
      echo "   --enable-[$eapis]" >&2;
      echo "   --disable-[$eapis]" >&2;
      echo "" >&2;
      echo "Path:"  >&2;
      echo "   --prefix=dir (sets bin, lib, zip, man, info and doc dirs)" >&2;
      echo "   --bindir=file" >&2;
      echo "   --libdir=file" >&2;
      echo "   --fildir=file" >&2;
      echo "   --zipdir=file" >&2;
      echo "   --dlldir=file" >&2;
      echo "   --mandir=file" >&2;
      echo "   --infodir=file" >&2;
      echo "   --docdir=file" >&2;
      echo "   --tmpdir=file (Bigloo tmp dir)" >&2;
      echo "   --tmp=file (Installation tmp dir)" >&2;
      echo "   --lispdir=file" >&2;
      echo "" >&2;
      echo "GC:"  >&2;
      echo "   --customgc=yes|no [default yes]" >&2;
      echo "   --gcprefix=dir (non-custom gc installation prefix (/usr)"  >&2;
      echo "   --gclibdir=dir (non-custom gc library dir (/usr/lib)" >&2;
      echo "   --gcincdir=dir (non-custom gc include dir (/usr/include/gc)" >&2;
      echo "   --gccustomversion=version (custom gc version, e.g., \"gc-7.1\")" >&2;
      echo "   --gccustominstall=[install|skip] (configure and install the gc)" >&2;
      echo "   --gcparallelmark=[yes|no] (configure the gc for parallel mark)" >&2;
      echo "" >&2;
      echo "Tools and compilers:"  >&2;
      echo "   --bigloo=comp [default bigloo]" >&2;
      echo "   --cc=comp [default gcc]" >&2;
      echo "   --ld=comp [default gcc]" >&2;
      echo "   --as=asm" >&2;
      echo "   --bflags=Bigloo compilation flags" >&2;
      echo "   --cflags=C compilation flags" >&2;
      echo "   --lflags=compiler link flags" >&2;
      echo "   --coflags=optimization_flags" >&2;
      echo "   --cwarningflags=warning_flags" >&2;
      echo "   --cpicflags=pic_flags" >&2;
      echo "   --ldlibs=ld_libs" >&2;
      echo "   --ldcomplibs=ld_compiler_libs" >&2;
      echo "   --ldflags=ld_flags" >&2;
      echo "   --emacs=file" >&2;
      echo "   --xemacs=file (deprecated, use \"--emacs\" option)" >&2;
      echo "   --indent=file" >&2;
      echo "   --icc (configure for icc, Intel C compiler)"  >&2;
      echo "   --clang (configure for clang LLVM C compiler)"  >&2;
      echo "   --shell=cmd [default $shell]" >&2;
      echo "   --mv=cmd [default $shell_mv]" >&2;
      echo "   --rm=dmd [default $shell_rm]" >&2;
      echo "" >&2;
      echo "Host configuration:"  >&2;
      echo "   --arch=[i586|i686|athlon|athlon-tbird|athlon-mp|athlon-xp|k6-2|k6-3|pentium3|pentium4] (configure for specified hardware)"  >&2;
      echo "   --a.out=file" >&2;
      echo "   --a.bat=file" >&2;
      echo "   --dirname=file-or-command" >&2;
      echo "   --force-hostos=operating-system" >&2;
      echo "   --os-win32" >&2;
      echo "   --os-macosx (tune for MacOSX)"  >&2;
      echo "   --no-os-macosx (disable MacOSX auto configuration)"  >&2;
      echo "   --os-android (configure for Android)"  >&2;
      echo "   --android-sdk-root=path (Android SDK root directory)"  >&2;
      echo "   --android-root=path (Android root directory)"  >&2;
      echo "   --android-target=target (defaults to \"generic\")"  >&2;
      echo "   --android-tmp=path (tmp directory on the emulator)"  >&2;
      echo "   --cygwin-dos-path=[dos path]" >&2;
      echo "   --cygwin-dos-jvm=yes|no [default yes]" >&2;
      echo "   --no-share (disable shared libraries support)" >&2;
      echo "   --no-gmp (disable gmp library support)" >&2;
      echo "   --no-resolv (disable resolv library support)" >&2;
      echo "   --no-unistring (disable unistring library support)" >&2;
      echo "   --no-pcre (disable prce library support)" >&2;
      echo "   --no-ldpreload" >&2;
      echo "   --sharedbde=yes|no [default no] (link Bde tools against shared libraries)" >&2;
      echo "   --sharedcompiler=yes|no [default no] (link Bigloo against shared libraries)" >&2;
      echo "" >&2;
      echo "JVM configuration:"  >&2;
      echo "   --java=file" >&2;
      echo "   --javac=file" >&2;
      echo "   --javaprefix=dir" >&2;
      echo "   --javashell=shell [should be sh or msdos (default sh)]" >&2;
      echo "   --native-default-backend" >&2;
      echo "   --jvm-default-backend" >&2;
      echo "" >&2;
      echo "Misc:"  >&2;
      echo "   --custom-all-libs [use custom version for all third party libs]" >&2;
      echo "   --finalization=yes|no [default no]" >&2;
      echo "   --benchmark=yes|no [default no] (must use --arch too)" >&2;
      echo "   --strip=no (disable stripping during linking)" >&2;
      echo "   --debug[2] (configure for debugging)" >&2;
      echo "   --stack-check=no" >&2;
      echo "   --enable-thread-local-storage" >&2;
      echo "   --disable-thread-local-storage" >&2;
      echo "   --thread-local-storage=auto (auto detect)" >&2;
      echo "   --enable-gstreamer-thread" >&2;
      echo "   --disable-gstreamer-thread" >&2;
      echo "   --disable-gmp (see --no-gmp)" >&2;
      echo "   --disable-revolv (see --no-resolv)" >&2;
      echo "   --disable-unistring (see --no-unistring)" >&2;
      echo "   --disable-pcre (see --no-pcre)" >&2;
      echo "   --custompcre=yes|no [default no]" >&2;
      echo "   --pcresrc=file [default \$PCRE\")" >&2;
      echo "   --customgmp=yes|no [default no]" >&2;
      echo "   --gmpsrc=file [default \$GMP\")" >&2;
      echo "   --customunistring=yes|no [default no]" >&2;
      echo "   --unistringsrc=file [default \$UNISTRING\")" >&2;
      echo "   --customlibuv=yes|no [default yes]" >&2;
      echo "   --sqltiny [force sqltiny backend]" >&2;
      echo "" >&2;
      echo "Configuration settings:"  >&2;
      echo "   --bigloo.h[=file]" >&2;
      echo "   --bigloo_gc.h[=file]" >&2;
      echo "   --bigloo_static.h[=file]" >&2;
      echo "   --bigloo_config.h[=file]" >&2;
      echo "   --bigloo_config.jvm[=file]" >&2;
      echo "   --Makefile.config=file" >&2;
      echo "   --$configurelog=file" >&2;
      echo "   --abort-missing (abort as soon as a system lib is missing)" >&2;
      echo "   --no-summary" >&2;
      echo "   --bootconfig" >&2;
      echo "   --bootdir=dir" >&2;
      echo "   --build-bindir=dir (directory which contains the binaries used to bootstrap)" >&2;
      echo "   --thirdparty-configure-opt=opt" >&2;
      echo "   --configureinfo=yes|no [default no]" >&2;
      echo "" >&2;
      echo "Experimental features:"  >&2;
      echo "   --gcbump=[yes|no] (configure the gc for bump allocation)" >&2;
      echo "   --nan-tagging" >&2;
      echo "" >&2;
      echo "Environment variables:" >&2;
      echo "CC         C compiler command" >&2;
      echo "CFLAGS     C compiler flags" >&2;
      echo "LDFLAGS    linker flags, e.g. -L<lib dir> -static" >&2;
      echo "TAR        the tar archiving utility" >&2;
      echo "PATCH      the command that applies a diff file to an original" >&2;
      exit 3;
  esac
  shift
done

# buildbindir
if [ "$buildbindir " = " " ]; then
  buildbindir=$bootdir/bin
  if [ "$buildlibdir " = " " ]; then
    buildlibdir=$bootdir/lib/bigloo/$release
  fi
else
  if [ "$buildlibdir " = " " ]; then
    buildlibdir=`$buildbindir/bigloo -eval '(begin (print *default-lib-dir*) (exit 0))'` || exit 1
  fi
fi

# bigloo
if [ "$bigloo " = " " ]; then
  bigloo=$buildbindir/bigloo
fi

# The bigloo.h file
if [ "$bigloo_h " = " " ]; then
  bigloo_h=lib/bigloo/$release/bigloo.h
  bigloo_saw_h=lib/bigloo/$release/bigloo_saw.h
  bigloo_pair_h=lib/bigloo/$release/bigloo_pair.h
  bigloo_real_h=lib/bigloo/$release/bigloo_real.h
  bigloo_bignum_h=lib/bigloo/$release/bigloo_bignum.h
  bigloo_int_h=lib/bigloo/$release/bigloo_int.h
  bigloo_vector_h=lib/bigloo/$release/bigloo_vector.h
  bigloo_string_h=lib/bigloo/$release/bigloo_string.h
  bigloo_struct_h=lib/bigloo/$release/bigloo_struct.h
  bigloo_cell_h=lib/bigloo/$release/bigloo_cell.h
  bigloo_semaphore_h=lib/bigloo/$release/bigloo_semaphore.h
  bigloo_object_h=lib/bigloo/$release/bigloo_object.h
  bigloo_exit_h=lib/bigloo/$release/bigloo_exit.h
fi

# The bigloo_gc.h file
if [ "$bigloo_gc_h " = " " ]; then
  bigloo_gc_h=lib/bigloo/$release/bigloo_gc.h
fi

# The bigloo_static.h file
if [ "$bigloo_static_h " = " " ]; then
  bigloo_static_h=lib/bigloo/$release/bigloo_static.h
fi

# The bigloo_config.h file
if [ "$bigloo_config_h " = " " ]; then
  bigloo_config_h=lib/bigloo/$release/bigloo_config.h
fi

# The bigloo_config.jvm file
if [ "$bigloo_config_jvm " = " " ]; then
  bigloo_config_jvm=runtime/Jlib/configure.java
fi

# The bigloo_config.sch file
if [ "$bigloo_config_sch " = " " ]; then
  bigloo_config_sch=lib/bigloo/$release/bigloo_config.sch
fi

# The bigloo_bmacs.el file
if [ "$bigloo_config_el " = " " ]; then
  bigloo_config_el=bmacs/bmacs-config.el
fi

# Shell commands
if [ "$bgl_shell_rm " = " " ]; then
  bgl_shell_rm=$shell_rm;
fi

if [ "$bgl_shell_mv " = " " ]; then
  bgl_shell_mv=$shell_mv;
fi

# Cleaning
rm -f $configurelog
echo "# configure... " > $configurelog
echo -n "# " >> $configurelog
date >> $configurelog
echo "# $0 $logopt" >> $configurelog
echo >> $configurelog

# the mandir
if [ -d "$mandir/man1" ]; then
  mandir=$mandir/man1;
fi

# buildtmpdir
if [ "$buildtmp " = " " ]; then
  buildtmp=/tmp
fi

#*---------------------------------------------------------------------*/
#*    all action                                                       */
#*---------------------------------------------------------------------*/
if [ $action = "all" ]; then
  if [ ! -d bin ]; then
     mkdir bin || exit 3
  fi
  if [ ! -d lib ]; then
     mkdir lib || exit 3
  fi
  if [ ! -d lib/bigloo/$release ]; then
     if [ ! -d lib/bigloo ]; then
       mkdir lib/bigloo || exit 3
     fi
     mkdir lib/bigloo/$release || exit 3
  fi
fi

echo "Checking local configuration..."

#*---------------------------------------------------------------------*/
#*    Weeding out bad configurations                                   */
#*---------------------------------------------------------------------*/
if [ "$action" != "bigloo_config_el" ]; then
  # checking the correctness of selected apis
  err=
  for p in $apis; do
    if [ ! -d api/$p ]; then
      err="$err $p";
    fi
  done

  if [ "$err " != " " ]; then
    echo "*** ERROR: unknown apis:$err";
    exit 1
  fi
  
  # check apis cross dependencies
  srfi1_is_enabled=no
  packrat_is_enabled=no
  pkgcomp_is_enabled=no
  pkglib_is_enabled=no
  sqlite_is_enabled=no
  dbus_is_enabled=no
  fthread_is_enabled=no
  srfi18_is_enabled=no
  pthread_is_enabled=no
  srfi27_is_enabled=no
  crypto_is_enabled=no
  openpgp_is_enabled=no
  gstreamer_is_enabled=no
  libuv_is_enabled=no
  patch_is_enabled=no
  
  for a in $apis; do
    case $a in
      srfi1) srfi1_is_enabled="yes";;
      srfi27) srfi27_is_enabled="yes";;
      packrat) packrat_is_enabled="yes";;
      sqlite) sqlite_is_enabled="yes";;
      pkgcomp) pkgcomp_is_enabled="yes";;
      pkglib) pkglib_is_enabled="yes";;
      dbus) dbus_is_enabled="yes";;
      pthread) pthread_is_enabled="yes";;
      srfi18) srfi18_is_enabled="yes";;
      fthread) fthread_is_enabled="yes";;
      crypto) crypto_is_enabled="yes";;
      openpgp) openpgp_is_enabled="yes";;
      gstreamer) gstreamer_is_enabled="yes";;
      libuv) libuv_is_enabled="yes";;
      patch) patch_is_enabled="yes";;
    esac
  done
  
  if [ $packrat_is_enabled = "yes" -a $srfi1_is_enabled = "no" ]; then
      echo "*** ERROR: packrat library requires srfi1."
      echo "Either disable packrat or enable srfi1."
      echo
      echo "Enabled apis: $apis"
      exit 1
  fi
  
  if [ $pkglib_is_enabled = "yes" -a $sqlite_is_enabled = "no" ]; then
      echo "*** ERROR: pkglib library requires sqlite."
      echo "Either disable pkglib or enable sqlite."
      echo
      echo "Enabled apis: $apis"
      exit 1
  fi
  
  if [ $fthread_is_enabled = "yes" -a $pthread_is_enabled = "no" ]; then
      echo "*** ERROR: fthread library requires pthread."
      echo "Either disable fthread or enable pthread."
      echo
      echo "Enabled apis: $apis"
      exit 1
  fi
  
  if [ $srfi18_is_enabled = "yes" -a $pthread_is_enabled = "no" ]; then
      echo "*** ERROR: srfi18 library requires pthread."
      echo "Either disable srfi18 or enable pthread."
      echo
      echo "Enabled apis: $apis"
      exit 1
  fi
  
  if [ $gstreamer_is_enabled = "yes" -a $pthread_is_enabled = "no" ]; then
      echo "*** ERROR: gstreamer library requires pthread."
      echo "Either disable gstreamer or enable pthread."
      echo
      echo "Enabled apis: $apis"
      exit 1
  fi
  
  if [ $openpgp_is_enabled = "yes" -a $crypto_is_enabled = "no" ]; then
      echo "*** ERROR: openpgp library requires crypto."
      echo "Either disable openpgp, or enable crypto."
      echo 
      echo "Enabled apis: $apis"
      exit 1
  fi
fi

# Check depends for bglpkg
if [ "$enable_bglpkg " = "yes " ]; then
    if [ $pkgcomp_is_enabled = "no" ]; then
	echo "*** WARNING: bglpkg binary requires pkgcomp library"
	echo "Disabling bglpkg."
	enable_bglpkg="no"
    fi
    if [ $pkglib_is_enabled = "no" ]; then
	echo "*** ERROR: bglpkg binary requires pkglib library"
	echo "Disabling bglpkg."
	enable_bglpkg="no"
    fi
    if [ $sqlite_is_enabled = "no" ]; then
	echo "*** ERROR: bglpkg binary requires sqlite library"
	echo "Disabling bglpkg."
	enable_bglpkg="no"
    fi
    if [ $web_is_enabled = "no" ]; then
	echo "*** ERROR: bglpkg binary requires web library"
	echo "Disabling bglpkg."
	enable_bglpkg="no"
    fi
fi

if [ "$enable_bglpkg " = "force " ]; then
    if [ $pkgcomp_is_enabled = "no" ]; then
	echo "*** ERROR: bglpkg binary requires pkgcomp library"
	echo "Either disable bglpkg, or enable pkgcomp."
	echo 
	echo "Enabled apis: $apis"
	exit 1
    fi
    if [ $pkglib_is_enabled = "no" ]; then
	echo "*** ERROR: bglpkg binary requires pkglib library"
	echo "Either disable bglpkg, or enable pkglib."
	echo 
	echo "Enabled apis: $apis"
	exit 1
    fi
    if [ $sqlite_is_enabled = "no" ]; then
	echo "*** ERROR: bglpkg binary requires sqlite library"
	echo "Either disable bglpkg, or enable sqlite."
	echo 
	echo "Enabled apis: $apis"
	exit 1
    fi
    if [ $web_is_enabled = "no" ]; then
	echo "*** ERROR: bglpkg binary requires web library"
	echo "Either disable bglpkg, or enable web."
	echo 
	echo "Enabled apis: $apis"
	exit 1
    fi
fi

# Here, bglpkg has all its dependencies, setting it just to "yes"
#  in order to have not to double test its value
if [ "$enable_bglpkg " = "force " ]; then
    enable_bglpkg="yes"
fi

#*---------------------------------------------------------------------*/
#*    User hostos specific configuration                               */
#*---------------------------------------------------------------------*/
echo "+ User specified host specific configuration ($hostos)..." >> $configurelog

dirsep="/"

case $hostos in
  android)
    if [ "$droidsdkroot " = " " -a "$droidadb " = " " ]; then
      echo "" >&2
      echo "*** ERROR: Bad Android configuration: DROID_SDK_ROOT missing." >&2
      echo "You must either use the --android-sdk-root=path option "
      echo "or define and export a DROID_SDK_ROOT shell variable." >&2
      echo "" >&2
      echo "The DROID_SDK_ROOT must refer to a directory that contains the" >&2
      echo "official Android SDK. It must at least contain the file \"platform-tools/adb\"." >&2
      echo "Alternative adb path may be specified with \"--android-adb\"." >&2
      exit 1
    fi
  
    # check if we can connect to a device (physical or emulated)
    if [ "$droidadb " = " " ]; then
      droidadb=$droidsdkroot/platform-tools/adb
    fi
    
    echo -n "executing $droidadb shell ls /mnt/sdcard -> " >&2
  
    $droidadb shell ls /mnt/sdcard 2> /dev/null > /dev/null

    if [ $? = 0 ]; then
      echo "ok" >&2
    else
      echo "no" >&2
      echo "" >&2
      echo "*** ERROR: Cannot contact any connected Android device!" >&2
      echo "Connect a physical device to a USB port or spawn the emulator with" >&2
      echo "  $ $droidsdkroot/tools/android" >&2
      exit 1
    fi

    # Find a proper tmp on the phone
    if [ "$droidtmp " = " " ]; then
      for dir in /tmp /sdcard/tmp /mnt/sdcard/tmp /data/local/tmp; do
        if $autoconfdir/androidmkdir $droidadb $dir >&2; then
          droidtmp=$dir
          break
        fi
      done
    fi

    if [ "$droidtmp " = " " ]; then
      echo "" >&2
      echo "*** ERROR: Bad Android configuration: Cannot setup /tmp." >&2
      echo "You must specify a write/execute path with the --android-tmp=path option " >&2
     exit 1
    fi
  
    # Generate the adhoc shell wrapper and tool
    hostsh=$pwd/arch/android/androidsh;
  
    cat $hostsh.in \
      | sed -e "s|@DROID_SDK_ROOT@|$droidsdkroot|" \
            -e "s|@DROID_TMP@|$droidtmp|" \
            -e "s|@DROID_ADB@|$droidadb|" \
      > $hostsh && chmod u+x $hostsh || exit 1

    doit=$pwd/arch/android/doit;
    cat $doit.in \
      | sed -e "s|@BGL_RELEASE@|$release|" \
      > $doit && chmod u+x $doit || exit 1

    # Use droid-gcc if no CC specified
    if [ "$cc " = " " ]; then
      cc=$pwd/arch/android/droid-gcc
  
      cat $cc.in \
        | sed -e "s|@DROID_SDK_ROOT@|$droidsdkroot|" \
              -e "s|@DROID_ROOT@|$droidroot|" \
              -e "s|@DROID_TARGET@|$droidtarget|" \
              -e "s|@DROID_TMP@|$droidtmp|" \
              -e "s|@DROID_ADB@|$droidadb|" \
        > $cc && chmod u+x $cc || exit 1
    fi
  
    # Add the correct cflags option
    cflags="$cflags -DBGL_ANDROID"
    gcspecial=-DIGNORE_DYNAMIC_LOADING;
    # Use the multithreaded libbigloogc to close the other shared libraries
    sharedlibrarygcclosed='-l$(GCLIB)_fth-$(RELEASE)'
  
    ;;
esac
echo >> $configurelog


#*---------------------------------------------------------------------*/
#*    Configure bootstrap                                              */
#*---------------------------------------------------------------------*/
# COMMAND_MODE is required by bash to support echo -n (used by runtest.in)
COMMAND_MODE=legacy; export COMMAND_MODE

# First, generate an incomplete version of runtest that is used to grab 
# HOST info
$autoconfdir/mkruntest $autoconfdir/runtest \
   --autoconfdir=$autoconfdir \
   --log=$configurelog \
   --hostsh="$hostsh" \
   --hostos=$hostos \
   --user=""

# Grab the hostos info
if [ "$hostos " = " " ]; then
  hostos=`$autoconf os` || exit 1
fi

# Grab the hostcpu info
if [ "$hostcpu " = " " ]; then
  hostcpu=`$autoconf cpu` || exit 1
fi

# Grab the hostosversion info
if [ "$hostosversion " = " " ]; then
  hostosversion=`$autoconf osversion` || exit 1
fi

# Get the user info
if [ "$user " = " " ]; then
  user=`$autoconf user` || exit 1
fi

# Check the C compiler
# [flo/20090907] in theory we could try to use the hostos, etc to try to find a
#                cross compiler.
if [ "$cc " = " " ]; then
  for cc in "gcc cc"; do
     cc=`$autoconf cctest --cc=gcc` || exit 1
     if [ "$cc " != " " ]; then break; fi
  done

  if [ "$cc " = " " ]; then
    echo "Can't configure C compiler. Aborting (see configure.log)" >&2;
    exit 1;
  fi
else
  ncc=`$autoconf cctest --cc="$cc"` || exit 1
  if [ "$ncc " != "$cc " ]; then
    echo "C compiler \"$cc\" broken. Aborting (see configure.log)" >&2;
    exit 1;
  fi
fi

# Second, replace runtest by one that contains the host information.
$autoconfdir/mkruntest $autoconfdir/runtest \
   --autoconfdir=$autoconfdir \
   --log=$configurelog \
   --hostsh="$hostsh" \
   --hostos="$hostos" \
   --hostosversion="$hostosversion" \
   --hostcpu="$hostcpu" \
   --buildsh="$buildsh" \
   --tmp="$buildtmp" \
   --user="$user" \
   --cc="$cc" \
   --cflags="$cflags"

#*---------------------------------------------------------------------*/
#*    Cross Compilation                                                */
#*---------------------------------------------------------------------*/
# Grab the buildos info
if [ "$buildos " = " " ]; then
  buildos=`$autoconfdir/os --sh=""` || exit 1
fi

# Grab the buildcpu info
if [ "$buildcpu " = " " ]; then
  buildcpu=`$autoconfdir/cpu --sh=""` || exit 1
fi

# Grab the buildosversion info
if [ "$buildosversion " = " " ]; then
  buildosversion=`$autoconfdir/osversion --sh=""` || exit 1
fi

#*---------------------------------------------------------------------*/
#*    Pointer alignment                                                */
#*---------------------------------------------------------------------*/
alignment=`$autoconf alignment` || exit 1

if [ "$alignment" = "3" ]; then
  if [ "$bglnantagging " != "0 " ]; then
    intsize=32
  else
    intsize=61
  fi
  elongsize=64
else
  intsize=30
  elongsize=32
fi

#*---------------------------------------------------------------------*/
#*    Autoconfigure hostos specific configuration                      */
#*---------------------------------------------------------------------*/
echo "+ Post host specific configuration ($hostos)..." >> $configurelog

dirsep="/"

case $hostos in
  cygwin)
    exe=".exe";
    jshell="msdos";

    if [ "$cygwindospath " = " " ]; then
      cygwindospath=`$autoconfdir/cygwindospath`
    fi

    if [ "$cygwindospath " = " " ]; then
      echo "*** ERROR:Can't find out where cygwin is installed."
      echo "Run configure with the --cygwin-dos-path option."
      exit 1
    else
      cygwindospath=`echo "$cygwindospath" | sed -e 's|/$||g'`
      if [ ! -d $cygwindospath ]; then
        echo "*** WARNING:Can't find cygwindospath \"$cygwindospath\""
      fi
      cygwindospath=`echo "$cygwindospath" | sed -e 's/\\\\/\\\\\\\\/g'`

      zipdir=`echo $zipdir | sed -e 's/\/cygdrive\/\([a-z]\)\//\1:\//'`
      zipdir=`echo $zipdir | sed -e "s/^\//$cygwindospath\\\\\\\\\\\\\\\\/"`
      zipdir=`echo $zipdir | sed -e 's/\//\\\\\\\\/g'`
      zipdir=`echo $zipdir | sed -e 's/\([^\\\\]\)\\\\\([^\\\\]\)/\1\\\\\\\\\2/g'`
      syszipdir=$zipdir
      syszipdirstr=`echo $syszipdir | sed -e 's|\\\\|\\\\\\\\|g'`

      dlldir=`echo $dlldir | sed -e 's/\/cygdrive\/\([a-z]\)\//\1:\//'`
      dlldir=`echo $dlldir | sed -e "s/^\//$cygwindospath\\\\\\\\\\\\\\\\/"`
      dlldir=`echo $dlldir | sed -e 's/\//\\\\\\\\/g'`
      dlldir=`echo $dlldir | sed -e 's/\([^\\\\]\)\\\\\([^\\\\]\)/\1\\\\\\\\\2/g'`
      sysdlldir=$dlldir
      sysdlldirstr=`echo $sysdlldir | sed -e 's|\\\\|\\\\\\\\|g'`
    fi

    jvmrecettebootpath="-classpath \".;../lib/bigloo/$release/bigloo_s.zip;objs_jvm\""
    jvmapibootpath="\".;../../../../../lib/bigloo/$release/bigloo_s.zip\""

    ldopt="no-share"

    if [ "$cygwindosjvm" = "yes" ]; then
      jshell="msdos"
    fi
    ;;

  mingw)
    exe=".exe"
    hostos="mingw"
    ld="gcc"
    ldlibs=""
    ldcomplibs=""
    ldflags="$ldflags -Wl,--enable-runtime-pseudo-reloc"
    ldopt=-shared
    havedlopen=1
    dlopen=""
    threadsupport=no;
    #cflags="$cflags -mthreads -D_MINGW_VER"
    cflags="$cflags -D_MINGW_VER"
    sharedsuffix="dll"
    sharedlibraryclosed=yes
    extralibs="$extralibs -Wl,--stack,8000000"
    extragclibs=""
    jshell="msdos"
    syszipdir=$zipdir
    syszipdirstr=$zipdir
    ;;

  darwin)
    sharedlibraryclosed=yes;
    if [ "$macosx " = "auto " ]; then
      macosx=`$autoconf macosx` || exit 1
    fi

    uname -r | grep "^9.8" > /dev/null

    if [ $? = 0 ]; then
      # workaround to patch MacOS 10.5 buggous execl
      ccshell=
    fi 

    if [ "$macosx" = "yes" ]; then
      echo "* MacOS X tuning enabled"; >&2;
      if [ "$mode " != "benchmark " -a "$pthreadlibs " != "no " ]; then
        if [ "$threadsupport " = "no " ]; then
          threadsupport=no;
          pthreadlibs=no;
          ldcomplibs="\$(GCCLOSELIB) -lc -lm";
        else
          customgclib=bigloogc_fth;
          extralibs="$extralibs $pthreadlibs";
          ldcomplibs="\$(GCCLOSELIB) $pthreadlibs -lc -lm";
        fi
      fi
      if [ `dirname $bindir` != `dirname $libdir` ]; then
        echo "*** ERROR: on MacOS X, bindir and libdir must have a";
        echo "common parent directory. Please re-configure accordingly";
        exit 1;
      fi

      cstrip=no
      strip=no
      ldbuildsharedopt=" -dynamiclib -single_module";
      ldinstallname="-install_name";
      sharedsuffix="dylib";
      ldlibs="$ldlibs \$(GCCLOSELIB) -lc";
      ldsonameopt="-install_name ~a";
      sharedcompiler=yes;
      sharedbde=yes;
      ldflags="$ldflags -dynamiclib -single_module -Wl,-read_only_relocs,suppress";
      customgmp=yes
      customgmpmakefile=Makefile.macosx
      customunistring=yes
      customlibuv=yes
      customgc=yes
      custompcre=yes
      
      tuning="MacOS X"
    fi

    if [ "$tuning " = "MacOS X " ]; then
      if [ ! -d lib/bigloo ]; then
        (cd lib && ln -s . bigloo) || exit 3
        ln -s lib Frameworks || exit 3
      fi
    fi

    phidgetcflags="-I/Library/Frameworks/Phidget21.framework/Headers"
    
    syszipdir=$zipdir
    syszipdirstr=$zipdir
    ;;

  win32)
    dirsep="\\"
    bindir=`echo $bindir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    libdir=`echo $libdir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    fildir=`echo $fildir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    zipdir=`echo $zipdir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    dlldir=`echo $dlldir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    mandir=`echo $mandir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    infodir=`echo $infodir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    docdir=`echo $docdir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    lispdir=`echo $lispdir | sed -e 's/\//\\\\\\\\/g' | sed -e 's/[.]//g'`
    ;;

  android)
    # Add the adhoc configure option for the collector
    gcconfigurethreadsopt="--enable-threads=posix";
  
    # Requires closed libraries
    sharedlibraryclosed=yes
    ;;

  *)
    syszipdir=$zipdir
    syszipdirstr=$zipdir
    sysdlldir=$dlldir
    sysdlldirstr=$dlldir
    ;;
esac
echo >> $configurelog

#*---------------------------------------------------------------------*/
#*    C tool chain                                                     */
#*---------------------------------------------------------------------*/
if [ "$hostos " != "$buildos " -o \
     "$hostcpu " != "$buildcpu " -o \
     "$hostosversion " != "$buildosversion " ]; then
  echo "Cross compilation detected..."

  # try to detect cross-tools
  tmp=`echo $cc | sed 's/-gcc$/-ar/'`;
  if [ "$ar " = " " -a "$tmp " != "$cc " -a -x "$tmp" ]; then
      ar="$tmp";
      echo "  Using ar=$ar";
  fi
  tmp=`echo $cc | sed 's/-gcc$/-as/'`;
  if [ "$as " = " " -a "$tmp " != "$cc " -a -x "$tmp" ]; then
      as="$tmp";
      echo "  Using as=$as";
  fi
  tmp=`echo $cc | sed 's/-gcc$/-strip/'`;
  if [ "$strip " = " " -a "$tmp " != "$cc " -a -x "$tmp" ]; then
      strip="$tmp";
      echo "  Using strip=$strip";
  fi
  tmp=`echo $cc | sed 's/-gcc$/-ranlib/'`;
  if [ "$ranlib " = " " -a "$tmp " != "$cc " -a -x "$tmp" ]; then
      ranlib="$tmp";
      echo "  Using ranlib=$ranlib";
  fi
fi

# create an unexisting temporary file name
name=$buildtmp/foo
while( test -f "$name.s" -o -f "$name.o" ); do
  name="$name"x;
done

if [ $action = "all" -o $action = "bigloo_config_el" ]; then
  # ld
  if [ "$ld " = " " ]; then ld=$cc; fi

  # as
  if [ ! $as ]; then as="as"; fi
  as=`$autoconf ascpp --as="$as" --name=$name` || exit 1

  if [ "$as " = " " -o ! -f $name.o ]; then
    echo "Can't find assembly that invokes cpp. Set the as variable" >&2;
    exit 1;
  fi

  # ar
  if [ ! $ar ]; then ar="ar"; fi
  arflags=`$autoconf arflags --ar=$ar --name=$name` || exit 1

  echo " ar arflags -> $ar $arflags" >> $configurelog

  rm -f $name.s $name.o $name.a

  # ranlib
  if [ ! $ranlib ]; then ranlib="ranlib"; fi
  rl=`$autoconf ranlib --ranlib="$ranlib"` || exit 1

  if [ "$rl" = "yes " ]; then
    ranlib=true;
  fi

  if [ "$strip " = " " ]; then strip="strip"; fi
  strip=`$autoconf strip --strip=$strip` || exit 1
fi

# checking patch
patch=$PATCH

if [ "$patch " = " " ]; then
  patch=patch
fi

$patch --help 2> /dev/null > /dev/null

if [ $? != 0 ]; then
  echo "*** ERROR: patch ($patch) command not found. Aborting..." >&2;
  exit 1;
fi
  
#*---------------------------------------------------------------------*/
#*    Executable names                                                 */
#*---------------------------------------------------------------------*/
echo "+ checking executable names..." >> $configurelog
if [ "$aout " = " " ]; then
  case $hostos in
    cygwin|mingw)
      aout=a.exe;;
    *)
      aout=a.out;;
  esac
fi

if [ "$abat " = " " ]; then
  case $hostos in
    cygwin|mingw)
      abat=a.bat;;
    *)
      abat=a.out;;
  esac
fi

echo "  -> aout=$aout, abat=$abat" >> $configurelog
echo >> $configurelog

#*---------------------------------------------------------------------*/
#*    Multi-threading                                                  */
#*---------------------------------------------------------------------*/
echo "* threadsupport=$threadsupport" >> $configurelog

if [ "$threadsupport " = "no " ]; then
   pthreadlibs=no;
   gcthread=no;
   pthreadhastls=0
elif [ $hostos = "mingw" ]; then
  # MinGW pre-test
  if [ "$threadsupport " = " " ]; then
     pthreadlibs=no;
     gcthread=no;
     pthreadhastls=0
  else
     echo "*** ERROR: MinGW does not support threads."
     echo" Disable multithreading and re-configure."
     exit 1
  fi
else
  # Does the system support threads
  if [ "$gcthread " = " "  ]; then
     gcthread=`$autoconf thread --cflags="$cgcfinalflags $cflags"` || exit 1;
  fi

  # find out the C library for posix threads
  if [ "$pthreadlibs " = " " ]; then
    pthreadlibs=`$autoconf pthread` || exit 1
  fi

  # pthread_mutex_timedlock
  if [ "$pthreadlibs" != "no" ]; then
    pthreadtimedlock=`$autoconf pthreadlock --lib="$pthreadlibs"` || exit 1;
  fi

  # pthread_spinlock
  if [ "$pthreadlibs" != "no" ]; then
    pthreadspinlock=`$autoconf pthreadspinlock --lib="$pthreadlibs"` || exit 1;
  fi

  # pthread_mutex_recursive
  if [ "$pthreadlibs" != "no" ]; then
    pthreadmutexrec=`$autoconf pthreadmutexrec --lib="$pthreadlibs"` || exit 1;
  fi

  # pthread_cond_timedwait
  if [ "$pthreadlibs" != "no" ]; then
    pthreadcondvtimedwait=`$autoconf pthreadcondvtimedwait --lib="$pthreadlibs"` || exit 1;
  fi

  # pthread_timedjoin_np
  if [ "$pthreadlibs" != "no" ]; then
    pthreadtimedjoin=`$autoconf pthreadtimedjoin --lib="$pthreadlibs"` || exit 1;
  fi

  # pthread local storage
  if [ "$pthreadlibs" != "no" -a "$pthreadlocalstorage " = " " ]; then
    pthreadlocalstorage=`$autoconf pthreadlocalstorage --lib="$pthreadlibs"` || exit 1;
  fi

  # pthread kill
  if [ "$pthreadlibs" != "no" ]; then
    pthreadkill=`$autoconf pthreadkill --lib="$pthreadlibs"` || exit 1;
    cgcflags="$cgcflags -DBGL_$pthreadkill"
  fi
  
  # get the number of processors of the machine
  if [ "$gcparallelmark " = " " ]; then
    nbprocs=`$autoconf nbprocs` || exit 1

    if [ "$nbprocs " = "0 " -o "$nbprocs " = "1 " ]; then
      gcparallelmark=no;
    else
      gcparallelmark=yes;
    fi
  fi

  if [ "$gcparallelmark " = "yes " ]; then
    gcthread="$gcthread -DPARALLEL_MARK";
  fi

  # thread local storage
  if [ "$pthreadlocalstorage " != " " -a "$threadsupport " != "no " ]; then
    pthreaddecl=$pthreadlocalstorage
    pthreadhastls=1
    gcthread="$gcthread -DUSE_COMPILER_TLS"
  else
    pthreaddecl=
    pthreadhastls=0
  fi
fi

#*---------------------------------------------------------------------*/
#*    semaphore                                                        */
#*---------------------------------------------------------------------*/
semaphore=`$autoconf semaphore` || exit 1;

#*---------------------------------------------------------------------*/
#*    semaphore                                                        */
#*---------------------------------------------------------------------*/
lockf=`$autoconf lockf` || exit 1;

#*---------------------------------------------------------------------*/
#*    Java configuration                                               */
#*---------------------------------------------------------------------*/
echo "+ Java specific configuration ($hostos)..." >> $configurelog
jvmrecettebootpath="-classpath \".:../lib/bigloo/$release/bigloo_s.zip:objs_jvm\""
jvmapibootpath="\".:../../../../../lib/bigloo/$release/bigloo_s.zip\""
echo >> $configurelog

#*---------------------------------------------------------------------*/
#*    GC configuration                                                 */
#*---------------------------------------------------------------------*/
if [ "$action" != "bigloo_config_el" ]; then
  if [ "$bglnantagging " != "0 " ]; then
    if [ "$alignment" = "3" ]; then 
      customgc=yes;
      bglnantagging=64;
      cnanflags="-DBGL_NAN_TAGGING=64";
      cgcflags="-DPOINTER_MASK=0xffffffffffff $cgcflags";
    else
      echo "*** ERROR: Nan-tagging requires 64bit platforms"
      exit 1
    fi
  fi

  echo "+ GC configuration ($customgc)..." >> $configurelog
  
  cgcflags="`$autoconf gcflags` $cgcflags" || exit 1
  
  # We check the standard GC if we have to use one
  if [ "$customgc " = "no " ]; then
    isgccustom=0
    gclib=
    if [ "$gclibdir " = " " ]; then
      gclibdir=/usr/lib;
    fi
    if [ "$gcincdir " = " " ]; then
      gcincdir=/usr/include/gc
    fi
    gclib=`$autoconf gcstd --cflags="$coflags $lflags $cflags" --gclib="$stdgclib" --gcincdir="$gcincdir" --gclibdir="$gclibdir" --dlopen=$dlopen` || exit 1
    if [ "$gclib " = " " ]; then
       echo "*** ERROR:configure:Standard GC. Aborting";
       echo "You are trying to configure Bigloo so that it uses an existing"
       echo "GC library. The configuration script is enable to make this"
       echo "library working properly."
       echo "Try to configure Bigloo with \"--customgc=yes\"."
       exit 1;
    fi
  else
    isgccustom=1
    gclib=$customgclib;
  
    gcincdir=$pwd/gc/$gccustom/include
  
    # detect if we are using maemo for an ARM emulation
    maemo=`$autoconf maemo.arm --cflags="$coflags"` || exit 1
    if [ "$maemo " = "yes " ]; then
      # This is required for compiling under QEMU (use to be the -DQEMU flag)
      cgcflags="$cgcflags -DNO_PROC_STAT"
      cflags="$cflags -DBGL_FORBID_GC_COLLECT"
    fi
  
    # android
    if [ $hostos = "android" ]; then
      cgcflags="-DPLATFORM_ANDROID"
    fi

    # configure directories
    gcconfiguredir="--prefix=$pwd/gc/preinst"
    # install the gc source code if needed
  
    if [ $actiongc = "install" ]; then
      if [ ! -d gc/$gccustom ]; then
        echo "+ Installing custom GC ($gccustom) source code."
  
        (cd gc \
         && GC="$gccustom"; export GC \
         && HOSTOS="$hostos"; export HOSTOS \
         && . ./install-$gccustom) || exit 1
      fi
  
      if [ -f gc/configure-$gccustom ]; then
        autoopts=`$autoconf gcconfigureopt --gc-dir="$pwd/gc/$gccustom"`
        gcconfigureopt="$autoopts $gcconfigureopt"
        gcconfigurethreadsopt="$gcconfigurethreadsopt"
        echo "+ Configuring custom GC ($gccustom)..." && \
        (. ./gc/configure-$gccustom $configuregcextraopt) || exit 1
      fi
    fi
  fi
  
  # Check the version of the collector
  if [ "$gcversion " = " " ]; then
    gcversion=`$autoconf gcversion --gcincdir="$gcincdir" --cflags="$lflags $cflags"` || exit 1
  
    if [ "$gcversion" -le "000" ]; then
      doblocking=`$autoconf gchavedoblocking --gclib="$stdgclib" --gcincdir="$gcincdir" --gclibdir="$gclibdir" --cflags="$lflags" --tmp=$buildtmp` || exit 1
  
      if [ "$doblocking " = "yes " ]; then
        gchavedoblocking=1
        gcversion="700"
      else
        startblocking=`$autoconf gchavestartblocking --gclib="$stdgclib" --gcincdir="$gcincdir" --gclibdir="$gclibdir" --cflags="$lflags"` || exit 1
        if [ "$startblocking " = "yes " ]; then
          gchaveblocking=1
        else
          gcversion="680"
        fi
      fi
    else
      if [ "$hostos " != "win32" -a $hostos != "cygwin" ]; then
        if [ "$gcversion" -lt "700" ]; then
          gchaveblocking=1
          gcversion="680"
        fi
        if [ "$gcversion" -ge "700" ]; then
          gchavedoblocking=1
        fi
      fi
    fi
  fi
  
  # correct gchavedoblocking for win32
  if [ $hostos = "cygwin" ]; then
    gchaveblocking=0
  elif [ $hostos = "mingw" ]; then
     gchaveblocking=0
     gchavedoblocking=0
  fi
  echo >> $configurelog
fi

#*---------------------------------------------------------------------*/
#*    GMP configuration                                                */
#*---------------------------------------------------------------------*/
if [ "$customgmp " = "yes " ]; then
  echo ""
  echo "Preparing and configuring custom gmp ($gmpsrc)..."
  echo "+ gmp configuration ($gmpsrc)..." >> $configurelog

  gmpversion=`basename $gmpsrc .tar.gz`
  gmpversion=`basename $gmpversion .tgz`
  gmpversion=`basename $gmpversion .tar.bz2`
  gmpversion=`basename $gmpversion .tar.xz`

  (cd gmp && GMP=$gmpsrc; export GMP && . ./install-gmp) || exit 1
  (cd gmp; . ./configure-gmp) || exit 1
fi

#*---------------------------------------------------------------------*/
#*    LIBUV configuration                                              */
#*---------------------------------------------------------------------*/
if [ "$libuv_is_enabled " = "yes " -a "$customlibuv " = "yes " ]; then
  echo ""

  echo "+ Installing custom libuv ($libuvsrc) source code."
  (cd libuv; . ./install-libuv) || exit 1

  echo "+ Configuring custom libuv..."
  (cd libuv; . ./configure-libuv) || exit 1
fi

#*---------------------------------------------------------------------*/
#*    Benchmark mode                                                   */
#*---------------------------------------------------------------------*/
if [ "$mode" = "benchmark" ]; then
  echo "* setting benchmark mode ($hardtune)..." >> $configurelog

  ccprefix="`echo $cc | sed 's/[0-9]*//g'`"  # remove version numbers
  case $hardtune in
    i586|i686)
      if [ "$ccprefix" = "gcc" ]; then
        coflags="$coflags -march=$hardtune -mcpu=$hardtune -mpreferred-stack-boundary=2 -fomit-frame-pointer -fschedule-insns2 -ffast-math";
      fi
      gcspecial=-DDONT_ADD_BYTE_AT_END;;

    pentium3|pentium4)
      if [ "$ccprefix" = "gcc" ]; then
        coflags="$coflags -march=$hardtune -mpreferred-stack-boundary=2 -fomit-frame-pointer -fschedule-insns2 -ffast-math";
      fi
      gcspecial="-DUSE_I686_PREFETCH -DDONT_ADD_BYTE_AT_END";;

    athlon|athlon-mp|athlon-tbird|athlon-xp)
      if [ "$ccprefix" = "gcc" ]; then
        coflags="$coflags -march=$hardtune -mpreferred-stack-boundary=2 -fomit-frame-pointer -fschedule-insns2 -ffast-math";
      fi
      gcspecial="-DUSE_3DNOW_PREFETCH -DDONT_ADD_BYTE_AT_END";;

    k6-2|k6-3)
      if [ "$ccprefix" = "gcc" ]; then
        coflags="$coflags -march=$hardtune -mpreferred-stack-boundary=2 -fomit-frame-pointer -fschedule-insns2 -ffast-math";
      fi
      gcspecial="-DUSE_3DNOW_PREFETCH -DDONT_ADD_BYTE_AT_END";;
  esac
fi

#*---------------------------------------------------------------------*/
#*    Testing stack size                                               */
#*---------------------------------------------------------------------*/
if [ $hostos != "cygwin" -a "$hostos" != "mingw" ]; then
  if [ ! "$stacksizerequired" = "0" ]; then
    s=`$autoconf stacksize --stacksize=$stacksizerequired` || exit 1
    if [ "$s " != "0 " ]; then
      echo "*** ERROR:configure:the execution stack is too small.";
      echo ""
      echo "Bigloo REQUIRES a larger stack (it needs a stack of about $stacksizerequired MB to compile).";
      echo "In general, it is possible to adjust the stack size by the means of";
      echo "a shell command.";
      echo "On most Unix systems, it is frequently called \"ulimit\" or \"unlimit\".";
      echo "For instance, with Bash you should try \"ulimit -s 4096\"."
      echo "With Zsh, try \"unlimit\"."
      echo ""
      echo "Another solution, if you know what you are doing,";
      echo "is to use the configure option \"--stack-check=no\". This will";
      echo "simply, disable stack size checking.";
      exit 1;
    fi
  fi
fi

#*---------------------------------------------------------------------*/
#*    OpenSSL                                                          */
#*---------------------------------------------------------------------*/
# find out the C library for openssl
if [ "$openssllibs " = " " ]; then
   if [ "$opensslcflags " = " " ]; then
     opensslcflags=`$autoconf bgl-pkg-config --cflags openssl`;
   fi
  
   if [ "$opensslcflags " = " " ]; then
     opensslcflags=-I.
   fi

   openssllibs=`$autoconf bgl-pkg-config --libs openssl`;
    
   if [ "$openssllibs " = " " ]; then
     openssllibs=`$autoconf openssl` || exit 1;
     if [ "$openssllibs " = "no " ]; then
       openssllibs=`$autoconf openssl --cflags="$opensslcflags" --lib="-lcrypto -lssl"` || exit 1;
     fi
   else
     openssllibs=`$autoconf openssl --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
   fi
else
   openssllibs=`$autoconf openssl --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
fi

if [ "$openssllibs" != "no" ]; then
  openssldtls=`$autoconf openssl-dtls --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  openssltls1=`$autoconf openssl-tls1 --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  openssltls11=`$autoconf openssl-tls11 --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  openssltls12=`$autoconf openssl-tls12 --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  opensslrand=`$autoconf openssl-rand --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  opensslv2=`$autoconf openssl-v2 --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  opensslv3=`$autoconf openssl-v3 --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  opensslv23=`$autoconf openssl-v23 --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
  opensslgetter=`$autoconf openssl-getter --cflags="$opensslcflags" --lib="$openssllibs"` || exit 1;
fi

#*---------------------------------------------------------------------*/
#*    sqlite                                                           */
#*---------------------------------------------------------------------*/
# find out the C library for sqlite
if [ "$sqlite_is_enabled " = "yes " ]; then
  if [ "$sqltinyforce " = "yes " ]; then
    sqlitelibs=""
  elif [ "$sqlitelibs " = " " ]; then
    sqlitelibs=`$autoconf sqlite` || exit 1;
  fi
fi

#*---------------------------------------------------------------------*/
#*    dbus                                                             */
#*---------------------------------------------------------------------*/
# find out the C library for dbus
if [ "$dubs_is_enabled " = "yes " ]; then
  if [ "$dbuslibs " = " " ]; then
     dbuslibs=`$autoconf dbus` || exit 1;
  fi

  if [ "$dbuslibs " != " " ]; then
    dbusld=`echo $dbuslibs | awk -F "@" '{ print $1 }'`
    dbusincl=`echo $dbuslibs | awk -F "@" '{ print $2 }'`
  else
    dbusld=""
    dbusincl=""
  fi
else
  dbusld=""
fi

#*---------------------------------------------------------------------*/
#*    gstreamer                                                        */
#*---------------------------------------------------------------------*/
# find out the C library for gstreamer, the @VERSION@ is expansed
# by the autoconf/gstreamer script
pkg="gstreamer-@VERSION@ gstreamer-base-@VERSION@ gstreamer-plugins-base-@VERSION@"

if [ "$gstreamer " = " " ]; then
   gstreamer=`$autoconf gstreamer --pkg="$pkg"` || exit 1;
fi

if [ "$gstreamer " != " " ]; then
  pkgv=`echo $pkg | sed "s/@VERSION@/$gstreamer/g"`
  gstreamercflags="`$autoconf bgl-pkg-config --cflags $pkgv`"

  if [ "gstreamercflags " = " " ]; then
    echo "*** ERROR: Cannot configure gstreamer, cflags are empty";
    echo "Running the command \"pkg-config --cflags gstreamer-$gstreamer gstreamer-plugins-base-$gstreamer\" might help understanding what's wrong"
    exit 1;
  fi

  if [ "$gstreameraudio " = " " ]; then
    pkgaudio="$pkgv gstreamer-audio-$gstreamer"
    audioflags="`$autoconf bgl-pkg-config --cflags --libs $pkgaudio`"

    gstreameraudio=`$autoconf gstreameraudio --cflags="$audioflags"` || exit 1;
    if [ "$gstreameraudio " != " " ]; then
      gstaudio="#t"
      gsthaveaudio="1"
      gstreamerlibs="`$autoconf bgl-pkg-config --libs $pkgaudio`"
    else
      gstaudio="#f"
      gsthaveaudio="0"
      gstreamerlibs=`$autoconf bgl-pkg-config --libs $pkgv`
    fi
  fi
fi

#*---------------------------------------------------------------------*/
#*    alsa                                                             */
#*---------------------------------------------------------------------*/
# find out the C library for alsa
if [ "$alsa " = " " ]; then
   alsa=`$autoconf alsa` || exit 1;
fi

if [ "$alsa " != "no " ]; then
  alsacflags=`$autoconf bgl-pkg-config --cflags alsa`
  alsalibs="`$autoconf bgl-pkg-config --libs alsa`"

  if [ "$alsacflags " = " " -o "$alsalibs " = " " ]; then
    alsa="no"
  fi
fi

#*---------------------------------------------------------------------*/
#*    pulseaudio                                                       */
#*---------------------------------------------------------------------*/
# find out the C library for pulseaudio
if [ "$pulseaudio " = " " ]; then
   pulseaudio=`$autoconf pulseaudio` || exit 1;
fi

if [ "$pulseaudio " != "no " ]; then
  pulseaudiocflags=`$autoconf bgl-pkg-config --cflags libpulse-simple`
  pulseaudiolibs="`$autoconf bgl-pkg-config --libs libpulse-simple`"

  if [ "$pulseaudiocflags " = " " -o "$pulseaudiolibs " = " " ]; then
    pulseaudio=no;
  fi
fi

#*---------------------------------------------------------------------*/
#*    mpg123                                                           */
#*---------------------------------------------------------------------*/
# find out the C library for mpg123
if [ "$mpg123 " = " " ]; then
   mpg123libs=`$autoconf mpg123 --cflags="$cflags $mpg123cflags"` || exit 1;

   if [ "$mpg123libs " = "no " -a "$mpg123cflags " = " " ]; then
     mpg123cflags="-D_FILE_OFFSET_BITS=64"
     mpg123libs=`$autoconf mpg123 --cflags="$cflags $mpg123cflags"` || exit 1;
   fi
fi

#*---------------------------------------------------------------------*/
#*    flac                                                             */
#*---------------------------------------------------------------------*/
# find out the C library for flac
if [ "$flac " = " " ]; then
   flaclibs=`$autoconf flac` || exit 1;
fi

#*---------------------------------------------------------------------*/
#*    Multimedia                                                       */
#*---------------------------------------------------------------------*/
havemixer=`$autoconf mixer` || exit 1

#*---------------------------------------------------------------------*/
#*    Regexp                                                           */
#*---------------------------------------------------------------------*/
buildpcrelibdir=$buildlibdir

if [ "$regexp " = " " ]; then
  pcrelibs=no
    
  # find out the C library for pcre
  if [ "$enable_configure_pcre " = "yes " ]; then
    if [ "$custompcre " != "yes " ]; then
      pcrelibs=`$autoconf pcre` || exit 1;
      extrapcre=pcre
      pcreprefix=`pcre-config --prefix`

      if [ "$? " = "0 " ]; then
	if [ "$pcreprefix" != "/usr" -a "$pcreprefix" != "/usr/local" ]; then
	  rpath="$pcreprefix/lib $rpath"
	fi
      fi
    fi
  else
    custompcre=no
  fi

  if [ "$pcrelibs " = "no " ]; then
    if [ "$custompcre " != "no " ]; then
      custompcre=yes
      pcreversion=`echo $pcresrc | sed 's/[^0-9]*//' | sed 's/[.][^0-9]*$//'`
      buildpcrelibdir=$bootdir/pcre/pcre-$pcreversion/.libs
	
      echo "+ Installing custom pcre source code."
      (cd pcre &&  PCRE=$pcresrc && export PCRE && ./install-pcre) || exit 1

      echo "+ Configuring custom pcre..."
      (cd pcre; . ./configure-pcre) || exit 1
	
      pcrelibs=yes
      extrapcre=pcre
      libpcrebuildpath="\$(BOOTDIR)/pcre\$(LIBDIR)/\$(FILDIR)"
      lcustomflags="-L$bootdir/pcre$libdir/$fildir $lcustomflags"
      buildlibdir="$bootdir/pcre$libdir/$fildir:$buildlibdir"
      cflags="-I$bootdir/pcre$libdir/$fildir $cflags"
    else
      pcrelibs=no
    fi
  fi

  if [ "$pcrelibs " != "no " ]; then
    featureflags="-srfi enable-pcre $featureflags";
    extralibs="-l$extrapcre $extralibs"
    regexp=pcre

    if [ `$autoconf pcrefreestudy` = "yes" ]; then
      regexphasfreestudy=1
    fi
  else
    regexp=pregexp
  fi
fi

echo ";; generated file, don't edit (`date`)" > runtime/Unsafe/regexp.scm
cat runtime/Unsafe/$regexp.scm >>  runtime/Unsafe/regexp.scm

if [ -f runtime/objs/obj_u/Unsafe/$regexp.c ]; then
  cp runtime/objs/obj_u/Unsafe/$regexp.c runtime/objs/obj_u/Unsafe/regexp.c;
fi

featureflags="-srfi enable-$regexp"

#*---------------------------------------------------------------------*/
#*    unistring                                                        */
#*---------------------------------------------------------------------*/
buildlibunistringlibdir=$buildlibdir # dummy existing path

if [ "$unistring " != "no " ]; then
  if [ "$customunistring " != "yes " ]; then
    extraunistring=`$autoconf unistring` || exit 1
    
    if [ "$extraunistring " = "no " -a "$customunistring " != "no " ]; then
      customunistring=yes
    fi
  fi

  if [ "$customunistring " = "yes " ]; then
    unistringlibs=yes
    haveunistring=1;
    featureflags="-srfi enable-unistring $featureflags";
    extraunistring=unistring
    libunistringbuildpath="\$(BOOTDIR)/libunistring\$(LIBDIR)/\$(FILDIR)"
    lcustomflags="-L$bootdir/libunistring$libdir/$fildir $lcustomflags"
    buildlibdir="$bootdir/libunistring$libdir/$fildir:$buildlibdir"
    cflags="-I$bootdir/libunistring$libdir/$fildir $cflags"
    unistringversion=`echo $unistringsrc | sed 's/[^0-9]*//' | sed 's/[.][^0-9]*$//'`
    buildlibunistringlibdir=$bootdir/libunistring/libunistring-$unistringversion/lib/.libs
      
    echo "+ Installing custom unistring source code."
    (cd libunistring && UNISTRING=$unistringsrc && export UNISTRING && ./install-unistring) || exit 1
  
    echo "+ Configuring custom unistring..."
    (cd libunistring; . ./configure-unistring) || exit 1
  fi
    
  if [ "$extraunistring " = "no " ]; then
    haveunistring=0;
    extraunistring=no
    if [ $unistringforce = "yes" ]; then
      echo "*** ERROR:configure:--enable-unistring. Cannot find UNISTRING library."
      echo "Aborting";
      exit 1;
    fi
  else
    haveunistring=1;
    featureflags="-srfi enable-unistring $featureflags";
    extralibs="-l$extraunistring $extralibs"
  fi
else
  haveunistring=0;
  extraunistring=no;
  unistringlibs=no;
fi

#*---------------------------------------------------------------------*/
#*    avahi                                                            */
#*---------------------------------------------------------------------*/
# find out the C library for avahi
if [ "$avahi " = " " ]; then
   avahilibs=`$autoconf bgl-pkg-config --libs avahi-client`
   avahicflags=`$autoconf bgl-pkg-config --cflags avahi-client`

   avahi=`$autoconf avahi --cflags="$avahicflags" --libs="$avahilibs"` || exit 1;
fi

#*---------------------------------------------------------------------*/
#*    libuv                                                            */
#*---------------------------------------------------------------------*/
# find out the C library for libuv
buildlibuvlibdir=$buildlibdir # dummy existing path

if [ "$libuv_is_enabled " = "yes " -a "$libuv " = " " ]; then
   if [ "$customlibuv " = "yes " ]; then
     libuvlibs="-luv"
     libuv="yes"
     libuvcflags="-I$bootdir/libuv/libuv-$libuvversion/include"
     buildlibuvlibdir=$bootdir/libuv/libuv-$libuvversion/.libs
   else
     libuvlibs=`$autoconf bgl-pkg-config --libs libuv`
     libuvcflags=`$autoconf bgl-pkg-config --cflags libuv`

     libuv=`$autoconf libuv --cflags="$libuvcflags" --libs="$libuvlibs"` || exit 1;
  fi
fi

#*---------------------------------------------------------------------*/
#*    patch                                                            */
#*---------------------------------------------------------------------*/
# find out the C library for patch
if [ "$patch_is_enabled" = "yes" -a "$patchapi " = " " ]; then
   patchapi=`$autoconf patch` || exit 1;
fi

if [ "$patch " != "no " ]; then
  patchcflags=""
  patchlibs=""
fi

#*---------------------------------------------------------------------*/
#*    phidget                                                          */
#*---------------------------------------------------------------------*/
# find out the C library for phidget
if [ "$phidget " = " " ]; then
   phidgetlibs=`$autoconf phidget --cflags="$phidgetcflags" --version=$phidgetversion` 2> /dev/null

   if [ "$?" != "0" ]; then
      phidget=no;
   else
      if [ "$phidgetlibdir " = " " ]; then
        phidgetlibdir=`$autoconf phidgetlibdir --version=$phidgetversion`
      fi
   fi
fi

#*---------------------------------------------------------------------*/
#*    bigloo_config.h / configure.java / configure.cs / ...            */
#*    -------------------------------------------------------------    */
#*    This part of the configure script produces the files             */
#*    runtime/Include/bigloo_config.h, runtime/Jlib/configure.java and */
#*    runtime/CSlib/configure.cs. These files contain all the machine- */
#*    dependant information used by Bigloo.                            */
#*---------------------------------------------------------------------*/
if [ $action = "all" -o $action = "bigloo_config" ]; then

  # Tell what we are doing
  echo ""
  echo "Configuring $bigloo_config_h, $bigloo_config_jvm, $bigloo_config_sch:"

  # The C compiler options
  cbraflags=`$autoconf ccbracket` || exit 1
  cflags="$cflags $cbraflags"

  # The -O C compiler options
  coflags=`$autoconf ccoptim --cflags="$coflags"` || exit 1

  # The -s C linker options
  if [ "$cstrip" != "no" ]; then
    csflags=`$autoconf ccstrip --cflags="$cstrip"` || exit 1;
  else
    csflags="";
  fi

  # errnoh
  errnoh=`$autoconf checkinclude '#include <errno.h>'` || exit 1

  # The -p C compiler options
  cpflags=`$autoconf ccprof` || exit 1

  # C compiler nan and infinity
  ccdiv0=`$autoconf ccdiv0` || exit 1

  # C compiler sse and math operations on x86-32 architecture
  if [ "$alignment " = "2 " ]; then
    cflags="$cflags `$autoconf ccssex86`"
  fi

  # oscharset
  if [ "$oscharset " = " " ]; then
    oscharset=`$autoconf oscharset` || exit 1
  fi

  # The stack direction
  stackgrows=`$autoconf stackdown` || exit 1

  # stdint
  stdint=`$autoconf stdint` || exit 1
  if [ "$stdint" = "1" ]; then
    stdlibint=`$autoconf stdlibint` || exit 1
  fi

  # unistdint
  if [ "$unistdint " = " " ]; then
    unistdint=`$autoconf unistdint` || exit 1
  fi

  # getuid
  if [ "$getuid " = " " ]; then
    getuid=`$autoconf getuid` || exit 1
  fi

  # getuid
  if [ "$getgid " = " " ]; then
    getgid=`$autoconf getgid` || exit 1
  fi

  # gecos
  if [ "$gecos " = " " ]; then
    gecos=`$autoconf gecos` || exit 1
  fi

  # getprotoent
  if [ "$getprotoent " = " " ]; then
    getprotoent=`$autoconf getprotoent` || exit 1
  fi

  # setjmp/longjmp
  if [ "$HOSTOS " = "cygwin " ]; then
    setjmpprefix="_";
  else
    setjmpprefix=`$autoconf setjmp` || exit 1
  fi

  setjmp="$setjmpprefix"setjmp
  longjmp="$setjmpprefix"longjmp

  if [ "$setjmpprefix" = "sig" ]; then
    # MS 10 dec 2010: used to be: setjmp="sigsetjmp(__jb,1)";
    # I don't think signal have to be saved/restore thus we switched
    # to not restoring them. Switching from 0 to 1 significantly improve
    # the performance of BIND-EXIT (and thus UNWIND-PROTECT). This 
    # dramatically impacts the performance of the new evaluator (BPS) on
    # benchmarks such as peval.scm
    setjmp="sigsetjmp(__jb,SIGSETJMP_SAVESIGS)";
    jmpbuf=sigjmp_buf
  else
    setjmp="$setjmp(__jb)";
    jmpbuf=jmp_buf
  fi

  # Does the system have bcopy?
  havebcopy=`$autoconf bcopy` || exit 1

  # The number of window register
  window=`$autoconf winreg` || exit 1

  # Does the system have sigpipe?
  sigpipe=`$autoconf sigpipe` || exit 1

  # Does the system have getgroups?
  getgroups=`$autoconf getgroups` || exit 1

  # Does the system have ioctl?
  ioctl=`$autoconf ioctl`

  # Does the system have syslog?
  syslog=`$autoconf syslog`

  # Does the system have overflow?
  overflow=`$autoconf overflow`

  # Does the system have sigsetmask?
  sigsetmask=`$autoconf sigsetmask` || exit 1

  # Does the system have sigprocmask?
  sigprocmask=`$autoconf sigprocmask` || exit 1

  # A warning if neither sigsetmask nor sigprocmask is defined
  if( test $sigsetmask = "0" -a $sigprocmask = "0"); then
    echo "*** WARNING:sigsetmask nor sigprocmask available"
    echo "(^C disabled in the interpreter)."
  fi

  # Does the system have alloca?
  alloca=`$autoconf alloca` || exit 1
  if [ $alloca = "1" ]; then
    allocah=`$autoconf allocah` || exit 1
  fi

  # native mach_dep target
  nativemachdep=`$autoconf machdep` || exit 1

  # Does the system have mmap?
  mmap=`$autoconf mmap` || exit 1

  # Does the system have getcwd?
  getcwd=`$autoconf getcwd` || exit 1

  # Does the system have getwd?
  getwd=`$autoconf getwd` || exit 1

  # Does the C compiler support branch predication annotations?
  likely=`$autoconf likely`

  # Does the C compiler support GCC attributes
  gccattrs=`$autoconf gccattrs`

  # Is gmp available?
  buildgmplibdir=$buildlibdir
  if [ "$customgmp" != "no" ]; then
    havegmp=1;
    featureflags="-srfi enable-gmp $featureflags";
    extralibs="-lgmp $extralibs"
    libgmpbuildpath="\$(BOOTLIBDIR)"
    gmpversion="`echo $gmpsrc | sed 's|gmp/gmp-||' | sed 's|.tgz||'`"
  elif [ "$gmpversion " = " " ]; then
    gmplib=`$autoconf bgl-pkg-config --libs gmp`;

    if [ "$gmplib " = " " ]; then
      gmplib=-lgmp
    fi

    gmpversion=`$autoconf gmp --lib=$gmplib` || exit 1

    if [ $gmpversion = "no" ]; then
      havegmp=0;
      if [ $gmpforce = "yes" ]; then
	echo "*** ERROR:configure:--enable-gmp. Cannot find GMP library."
	echo "Aborting";
 	exit 1;
      fi
    else
      havegmp=1;
      featureflags="-srfi enable-gmp $featureflags";
      extralibs="$gmplib $extralibs"
    fi
  else
    havegmp=0;
  fi

  if [ "$havegmp " = "0 " ]; then
    if [ "$srfi27force " = "yes " ]; then
      echo "*** ERROR:configure: Cannot find GMP library required by SRFI27."
      echo "Please install GMP first or re-configure with \"--disable-srfi27\"."
      echo "Aborting";
      exit 1;
    else
      echo "*** WARNING:configure: Cannot find GMP library required by SRFI27."
      echo "Disabling SRFI27."
      napis=;
      for a in $apis; do
        if [ $a != "srfi27" ]; then
          if [ "$napis " = " " ]; then
            napis="$a";
          else
            napis="$napis $a";
          fi
        fi
      done
      apis=$napis;
    fi
    long_limbs=0;
    longlong_limbs=0;
  else
    long_limbs=`$autoconf limbs --type="long" --cflags="-I$bootdir/lib/$release -L$bootdir/lib/$release"` || exit 1
    longlong_limbs=`$autoconf limbs --type="$longlong" --cflags="-I$bootdir/lib/$release -L$bootdir/lib/$release"` || exit 1
  fi
    
  # Is resolv available?
  if [ "$resolv " = " " ]; then
    resolv=`$autoconf resolv` || exit 1

    if [ $resolv = "no" ]; then
      haveresolv=0;
      haveresolvapl=0;
      haveresolvzxfr=0;
      if [ $resolvforce = "yes" ]; then
	echo "*** ERROR:configure:--enable-resolv. Cannot find RESOLV library."
	echo "Aborting";
 	exit 1;
      fi
    else
      haveresolv=1;
      featureflags="-srfi enable-resolv $featureflags";
      extralibs="-l$resolv $extralibs"
      ldcomplibs="$ldcomplibs -l$resolv"
      haveresolvapl=`$autoconf resolvsym --sym=apl --lib=$resolv` || exit 1
      haveresolvzxfr=`$autoconf resolvsym --sym=zxfr --lib=$resolv` || exit 1
    fi
  else
    haveresolv=0;
    haveresolvapl=0;
    haveresolvzxfr=0;
  fi

  # Where to find the socket api
  socketlibs=`$autoconf socket --lib="$socketlibs"` || exit 1
  socklen=`$autoconf socklen --lib="$socketlibs"` || exit 1

  if [ "$socketlibs " != " " ]; then
     extralibs="$socketlibs $extralibs"
  fi

  tcpnodelay=`$autoconf setsockopt --lib="$socketlibs" --opt=TCP_NODELAY` || exit 1
  tcpcork=`$autoconf setsockopt --lib="$socketlibs" --opt=TCP_CORK` || exit 1
  tcpquickack=`$autoconf setsockopt --lib="$socketlibs" --opt=TCP_QUICKACK` || exit 1

  inet_aton=`$autoconf inet_aton --lib="$socketlibs"` || exit 1
  inet_pton=`$autoconf inet_pton --lib="$socketlibs"` || exit 1

  unix_socket=`$autoconf unixsocket --lib="$socketlibs"` || exit 1
  getaddrinfo=`$autoconf getaddrinfo --lib="$socketlibs"` || exit 1
  getifaddrs=`$autoconf getifaddrs --lib="$socketlibs"` || exit 1
  gethwaddrs=`$autoconf gethwaddrs --lib="$socketlibs"` || exit 1

  # Are the static constants aligned?
  cnstalign=`$autoconf cnstalign --alignment=$alignment` || exit 1
  if [ $? != "0" ]; then
     echo "*** ERROR:configure:cnstalign. Aborting";
     exit 1;
  fi

  enforcedcnstalign=`$autoconf enforcedcnstalign` || exit 1
  if [ "$cnstalign" = "0" -a "$enforcedcnstalign" = "0" ]; then
    echo "*** ERROR:configure:illegal alignment."
    echo "It is then impossible install Bigloo on this architecture, sorry."
    exit 1
  fi

  # Endianness
  endian=`$autoconf bigendian` || exit 1

  # Does this system implement pipe?
  pipe=`$autoconf pipe` || exit 1

  # Does this system implement symlink?
  symlink=`$autoconf symlink` || exit 1

  # Does this compiler implement labs?
  # llabs=`$autoconfdir/labs --user=$user --tmp=$buildtmp --cc="$cc"`
  # SE: fix, 27 oct 2006
  labs=`$autoconf labs` || exit 1
  if [ "$labs " != " " ]; then
    have_labs=1
  else
    have_labs=0
    labs=abs
  fi

  # Does this compiler implement longlong?
  longlong=`$autoconf longlong --longlong="$longlong"` || exit 1

  echo "#undef BGL_LONGLONG_T" >> $bigloo_config_h
  if [ "$longlong " = " " ]; then
    echo "   long long: no"
    havelonglong=0

    have_strtoull=0
    longlong=long
    have_llabs=0
    llabs=abs
    have_strtoll=0
    strtoll=strtol
    strtoull=strtoull
  else
    havelonglong=1

    llabs=`$autoconf llabs --longlong="$longlong"` || exit 1
    strtoll=`$autoconf strtoll --longlong="$longlong"` || exit 1
    strtoull=`$autoconf strtoull --longlong="$longlong"` || exit 1

    if [ "$llabs " != " " ]; then
      have_llabs=1
    else
      have_llabs=0
    fi
    if [ "$strtoll " != " " ]; then
      have_strtoll=1
    else
      have_strtoll=0
      strtoll="bgl_strtoll"
    fi
    if [ "$strtoull " != " " ]; then
      have_strtoull=1
    else
      have_strtoull=0
      strtoull="bgl_strtoull"
    fi
  fi

  long_sign_bit=`$autoconf signbit --type=long --alignment="$alignment"` || exit 1
  elong_sign_bit=`$autoconf signbit --type=long --alignment=0` || exit 1
  llong_sign_bit=`$autoconf signbit --type="$longlong" --alignment=0` || exit 1
  
  # Is sigchld available for us
  sigchld=`$autoconf sigchld` || exit 1

  # Is sigaction available
  sigaction=`$autoconf sigaction` || exit 1

  # Is setenv available for us
  setenv=`$autoconf setenv` || exit 1

  # Is select available
  select=`$autoconf select` || exit 1

  # Is fcntl available
  fcntl=`$autoconf fcntl` || exit 1

  # Is termio available
  termio=`$autoconf termio` || exit 1

  # Is termio available
  termios=`$autoconf termios` || exit 1

  # Does the system support posix-file-ops
  posixfileops=`$autoconf posixfileops` || exit 1

  # Does the system support sendfile
  sendfile=`$autoconf sendfile` || exit 1
  if [ "$sendfile" != "BGL_SENDFILE_NO" ]; then
    sendfile_rif=1;
    sendfile_ros=1;
  else
    sendfile_rif=0;
    sendfile_ros=0;
  fi

  # Does the system support nanosleep
  nanosleep=`$autoconf sleep --cflags="-DBGL_NANOSLEEP"` || exit 1
  # Does the system support normalsleep
  normalsleep=`$autoconf sleep --cflags="-DBGL_SLEEP"`

  # The timezone variable
  timezone=`$autoconf timezone --cflags="$coflags"` || exit 1
  # The timeval variable
  timeval=`$autoconf timeval --cflags="$coflags"` || exit 1
  # The gmtoff field
  gmtoff=`$autoconf gmtoff --cflags="$coflags"` || exit 1

  # The warning C compiler options
  if [ "$cwarningflags" != "no" ]; then
     if [ "$cwarningflags " = " " ]; then
        cwarningflags=`$autoconf ccwarning --cflags="$cwarningflags"` || exit 1
     fi
     
     if [ "$cwarningflags " != " " ]; then
       cflags="$cflags $cwarningflags"
     fi
  fi

  # The -pic C compiler options
  if [ "$cpicflags" = "no" ]; then
    cpicflags=""
  else
    if [ "$ldopt" != "no-share" ]; then
      if [ "$cpicflags" = "demanded" -o "$cpicflags " = " " ]; then
        cpicflags=`$autoconf ccpic --cflags="$cpicflags"` || exit 1
      fi
    else
      cpicflags=""
    fi
  fi

  if [ "$cpicflags " = " " ]; then
    cpicflags=-DBGL_NO_PIC;
  fi

  # ld option
  lflags=`$autoconf ldextraopt --lflags="$lflags"` || exit 1
  if [ "$hostos " != "mingw " ]; then
    rflags=`$autoconf rdynamic --rflags="-rdynamic"` || exit 1
  fi

  # shared link additional soname option
  if [ "$ldsoname" = "blank" ]; then
    ldsoname=""
  else
    ldsoname=`$autoconf ldsoname $libdir --ld="$ld" --soname="$ldsoname"` || exit 1

    if [ "$ldsoname " != " " -a "$ldsonameopt " = " " ]; then
      ldsonameopt="$ldsoname=~a"
    fi
  fi

  # The shared libraries
  if [ "$ldopt" = "no-share" ]; then
    echo "   shared library: no"
    haveshlib=0
  else
    ldlibs=-lc

    if [ "$hostos" = "mingw" ]; then
      ldlibs=""
    fi
    
    ldopt=`$autoconf ldshare --ld="$ld" --ldopt="$ldopt" --ldlibs="$ldlibs" --cflags="$cpicflags" --sharedsuffix="$sharedsuffix"` || exit 1
    if [ "$ldopt" = "no-share" ]; then
      ldopt=`$autoconf ldshare --ld="ld" --ldopt="$ldopt" --ldlibs="$ldlibs" --cflags="$cpicflags" --sharedsuffix="$sharedsuffix"` || exit 1
    fi

    if [ "$ldopt" = "no-share" ]; then
      haveshlib=0
      cpicflags="-DBGL_NO_PIC"
    else
      xldopt=`$autoconf ldshare --ld="$ld" --ldopt="$ldopt -Wl,-rpath=$libdir" --ldlibs="$ldlibs" --cflags="$cpicflags" --sharedsuffix="$sharedsuffix"`

      haveshlib=1
      ldpreload=`$autoconf ldpreload --ld="$ld" --ldlibs="-lc" --ldopt="$ldopt"` || exit 1
    fi
  fi

  # Does the system have dlopen?
  if [ "$ldopt " != "no-share" ]; then
    if [ "$hostos" = "mingw" ]; then
      havedlopen=1
      dlopen=""
    else
     dlopen=`$autoconf dlopen --dlopt="$dlopenopt"` || exit 1
     if [ "$dlopen" != "0" ]; then
       havedlopen=1
       dlopen=$dlopen
       extralibs="$dlopen $extralibs"
       ldcomplibs="$ldcomplibs -ldl"
     else
       havedlopen=0
       dlopen=""
     fi
    fi
  else
    havedlopen=0
    dlopen=""
  fi

  # for now only the port is Unix
  $autoconf unix >> $bigloo_config_h || exit 1

  # which shell to use
  `$shell -c "ls -l > /dev/null"` || exit 1

  # the C beautifier
  id=`$autoconf indent --indent="$indent"` || exit 1
  if [ "$id " != "1 " ]; then
    indent=
  fi

  # the dirname command
  dirname=`$autoconf dirname --dirname="$dirname"` || exit 1

  # double precision
  prec=`$autoconf doubleprec` || exit 1

  # static link additional option
  ldstaticopt=`$autoconf ldstaticopt` || exit 1

  if [ "$hostos " = "mingw " -a "$pthreadlibs" != "no"  ]; then
    ldstaticopt="$ldstaticopt $pthreadlibs"
  fi

  # shared link additional option
  ldsharedopt=`$autoconf ldsharedopt` || exit 1

  # check if -Wl,-rpath=XXX supported by the C compiler
  xcc=`$autoconf cctest --cc=$cc --cflags="-Wl,--enable-new-dtags,-rpath=$libdir"`
  if [ "$xcc " = "$cc " ]; then
    ldrpath="-Wl,--enable-new-dtags,-rpath="
    crpath="$ldrpath~a"
  else
    xcc=`$autoconf cctest --cc=$cc --cflags="-Wl,-rpath=$libdir"`
    if [ "$xcc " = "$cc " ]; then
      ldrpath="-Wl,-rpath="
      crpath="$ldrpath~a"
    else
      ldrpath=""
      crpath=""
    fi
  fi

  # bdb configuration
  if [ "$bee" = "partial" ]; then
    havebdb=0
  else
    havebdb=1
  fi

  # Java configuration
  if [ "$jvmbackend" = "yes" -o "$jvmbackend" = "force" ]; then
    if [ "$jshell" != "sh" ]; then
       if [ "$jshell" != "msdos" ]; then
          echo "*** ERROR:configure:Illegal Java shell \"$jshell\" (should be either \"sh\" or \"msdos\")";
          exit 3
       fi
    fi

    if [ "$HOSTOS " = "cygwin " -a "$cygwindosjvm" = "yes" ]; then
      cpsep=";";
    elif [ "$HOSTOS " = "mingw " ]; then
      cpsep=";";
    else
      cpsep=":";
     fi

    jtest=`$autoconf javatest --java=$java \
                              --jflags=$jflags \
                              --jvflags=$jvflags \
                              --javac=$javac \
                              --jcflags=$jcflags \
                              --cpsep="$cpsep"` || exit 1

    if [ $jtest != 0 ]; then
      echo "*** ERROR:configure:Can't configure Java (see $configurelog for details)."
      exit 1
    else
      java_configured=yes
    fi

    java_version=`$javac -version 2>&1 | head -n 1` || exit 1
    if echo "$java_version" | grep "1.9" > /dev/null
      then java_version=1.9
    elif echo "$java_version" | grep "1.8" > /dev/null
      then java_version=1.8
    elif echo "$java_version" | grep "1.7" > /dev/null
      then java_version=1.7
    elif echo "$java_version" | grep "1.6" > /dev/null
      then java_version=1.6
    elif echo "$java_version" | grep "1.5" > /dev/null
      then java_version=1.5
    elif echo "$java_version" | grep "1.4" > /dev/null
      then java_version=1.4
    else
      jvmversion=`$java -version 2>&1 | head -n 1`
      if echo "$jvmversion" | grep "1.4" > /dev/null
        then java_version=1.4
      else
        java_version=1.3
      fi
    fi
  else
    java=java
    jflags=
    jvflags=
    jshell=sh
    jar=
  fi

  # Posix Os
  case $hostos in
    mingw)
      osclass="mingw"
      pathseparator=";"
      fileseparator="/"
      ostmp="$tmpdir"
      staticlibsuf="a"
      ucs2displayable=0;;

    unknown)
      ostmp="/tmp"
      fileseparator="/"
      pathseparator=":"
      staticlibsuf="a"
      ucs2displayable=0;;

    *)
      osclass="unix"
      pathseparator=":"
      fileseparator="/"
      ostmp="$tmpdir"
      staticlibsuf="a"
      ucs2displayable=0;;
  esac

  if [ "$ostmp " = " " ]; then
    ostmp=/tmp
  fi

  # bigloo_config_h, bigloo_config_jvm, bigloo_config_sch, bigloo.sh
  for p in $bigloo_config_h $bigloo_config_jvm $bigloo_config_sch bigloo.sh bglafile.sh bgltags.sh bgljfile.sh bgldepend.sh bglmco.sh bglrun.sh bglld.sh bglmake.sh bglprof.sh bglpp.sh bgljas.sh; do
    if [ "$p " != " " ]; then
      rm -f $p 2> /dev/null
      rel=`echo $release | sed -e "s|[.]|_|"`;
      gciscustom=1

      if [ $customgc != "yes" ]; then
        gciscustom=0
      fi

      cat autoconf/`basename $p`.in \
        | sed -e "s|@CONFIGURE@|Automatically generated file (don't edit), `date`|" \
              -e "s|@BGL_RELEASE@|BGL_$rel|" \
              -e "s|@BGL_RELEASE_NUMBER@|$release|" \
              -e "s|@BGL_RELEASE_BRANCH@|$branch|" \
              -e "s|@BGL_HOMEURL@|$bigloourl|" \
              -e "s|@BGL_SPECIFIC_VERSION@|$specific|" \
              -e "s|@GC_VERSION@|$gcversion|" \
              -e "s|@GC_ISCUSTOM@|$gciscustom|" \
              -e "s|@GC_BUMP@|$gcbump|" \
              -e "s|@BGL_DEFAULT_BACK_END@|$defaultbackend|" \
              -e "s|@BGL_DEFAULT_A_OUT@|$aout|" \
              -e "s|@BGL_DEFAULT_A_BAT@|$abat|" \
              -e "s|@STACK_GROWS_DOWN@|$stackgrows|" \
              -e "s|@PTR_ALIGNMENT@|$alignment|" \
              -e "s|@INT_BIT_SIZE@|$intsize|" \
              -e "s|@ELONG_BIT_SIZE@|$elongsize|" \
              -e "s|@BGL_NAN_TAGGING@|$bglnantagging|" \
              -e "s|@BGL_ISOC99@|$isoc99|" \
              -e "s|@BGL_HAS_ERRNOH@|$errnoh|" \
              -e "s|@BGL_CCDIV0@|$ccdiv0|" \
              -e "s|@HAVE_STDINT@|$stdint|" \
              -e "s|@HAVE_STDLIBINT@|$stdlibint|" \
              -e "s|@HAVE_UNISTDINT@|$unistdint|" \
              -e "s|@HAVE_GETUID@|$getuid|" \
              -e "s|@HAVE_GETGID@|$getgid|" \
              -e "s|@HAVE_GECOS@|$gecos|" \
              -e "s|@HAVE_GETPROTOENT@|$getprotoent|" \
              -e "s|@SETJMP@|$setjmp|" \
              -e "s|@JMP_BUF@|$jmpbuf|" \
              -e "s|@LONGJMP@|$longjmp|" \
              -e "s|@HAVE_BCOPY@|$havebcopy|" \
              -e "s|@NB_WINDOW_REGISTER@|$window|" \
              -e "s|@HAVE_SIGPIPE@|$sigpipe|" \
              -e "s|@BGL_HAVE_GETGROUPS@|$getgroups|" \
              -e "s|@BGL_HAVE_IOCTL@|$ioctl|" \
              -e "s|@BGL_HAVE_LIKELY@|$likely|" \
              -e "s|@BGL_HAVE_GCCATTRS@|$gccattrs|" \
              -e "s|@BGL_HAVE_SYSLOG@|$syslog|" \
              -e "s|@BGL_HAVE_OVERFLOW@|$overflow|" \
              -e "s|@HAVE_SIGSETMASK@|$sigsetmask|" \
              -e "s|@HAVE_SIGPROCMASK@|$sigprocmask|" \
              -e "s|@HAVE_ALLOCA@|$alloca|" \
              -e "s|@HAVE_ALLOCAH@|$allocah|" \
              -e "s|@HAVE_MMAP@|$mmap|" \
              -e "s|@HAVE_GETCWD@|$getcwd|" \
              -e "s|@HAVE_GETWD@|$getwd|" \
              -e "s|@CONSTANT_ALIGNED@|$cnstalign|" \
              -e "s|@BGL_BIG_ENDIAN@|$endian|" \
              -e "s|@HAVE_PIPE@|$pipe|" \
              -e "s|@HAVE_SYMLINK@|$symlink|" \
              -e "s|@BGL_LONGLONG_T@|$longlong|" \
              -e "s|@BGL_HAVE_LONGLONG@|$havelonglong|" \
              -e "s|@BGL_LONG_LIMBS@|$long_limbs|" \
              -e "s|@BGL_LONGLONG_LIMBS@|$longlong_limbs|" \
              -e "s|@C_LONG_SIGN_BIT@|$long_sign_bit|" \
              -e "s|@C_ELONG_SIGN_BIT@|$elong_sign_bit|" \
              -e "s|@C_LLONG_SIGN_BIT@|$llong_sign_bit|" \
              -e "s|@BGL_HAVE_LABS@|$have_labs|" \
              -e "s|@BGL_LABS@|$labs|" \
              -e "s|@BGL_HAVE_LLABS@|$have_llabs|" \
              -e "s|@BGL_LLABS@|$llabs|" \
              -e "s|@BGL_HAVE_STRTOLL@|$have_strtoll|" \
              -e "s|@BGL_STRTOLL@|$strtoll|" \
              -e "s|@BGL_HAVE_STRTOULL@|$have_strtoull|" \
              -e "s|@BGL_STRTOULL@|$strtoull|" \
              -e "s|@BGL_HAVE_GMP@|$havegmp|" \
              -e "s|@BGL_HAVE_RESOLV@|$haveresolv|" \
              -e "s|@BGL_HAVE_RESOLV_APL@|$haveresolvapl|" \
              -e "s|@BGL_HAVE_RESOLV_ZXFR@|$haveresolvzxfr|" \
              -e "s|@BGL_HAVE_UNISTRING@|$haveunistring|" \
              -e "s|@HAVE_SIGCHLD@|$sigchld|" \
              -e "s|@HAVE_SETENV@|$setenv|" \
              -e "s|@HAVE_SIGACTION@|$sigaction|" \
              -e "s|@BGL_HAVE_SELECT@|$select|" \
              -e "s|@BGL_HAVE_FCNTL@|$fcntl|" \
              -e "s|@HAVE_TERMIO@|$termio|" \
              -e "s|@HAVE_TERMIOS@|$termios|" \
              -e "s|@POSIX_FILE_OPS@|$posixfileops|" \
              -e "s|@BGL_SENDFILE_BRAND@|$sendfile|" \
              -e "s|@BGL_SENDFILE_REQUIRE_INPUT_FILE@|$sendfile_rif|" \
              -e "s|@BGL_SENDFILE_REQUIRE_OUTPUT_SOCKET@|$sendfile_ros|" \
              -e "s|@BGL_NANOSLEEP@|$nanosleep|" \
              -e "s|@BGL_SLEEP@|$normalsleep|" \
              -e "s|@BGL_TIMEZONE@|$timezone|" \
              -e "s|@BGL_HAVE_TIMEVAL@|$timeval|" \
              -e "s|@BGL_HAVE_GMTOFF@|$gmtoff|" \
              -e "s|@HAVE_SHARED_LIBRARY@|$haveshlib|" \
              -e "s|@HAVE_DLOPEN@|$havedlopen|" \
              -e "s|@DLOPEN_LD_OPT@|$dlopen|" \
              -e "s|@HAVE_SOCKLEN@|$socklen|" \
              -e "s|@BGL_HAVE_SOCKET_TCP_NODELAY@|$tcpnodelay|" \
              -e "s|@BGL_HAVE_SOCKET_TCP_CORK@|$tcpcork|" \
              -e "s|@BGL_HAVE_SOCKET_TCP_QUICKACK@|$tcpquickack|" \
              -e "s|@BGL_HAVE_INET_ATON@|$inet_aton|" \
              -e "s|@BGL_HAVE_INET_PTON@|$inet_pton|" \
              -e "s|@BGL_HAVE_UNIX_SOCKET@|$unix_socket|" \
              -e "s|@BGL_HAVE_GETADDRINFO@|$getaddrinfo|" \
              -e "s|@BGL_HAVE_GETIFADDRS@|$getifaddrs|" \
              -e "s|@BGL_HAVE_GETHWADDRS@|$gethwaddrs|" \
              -e "s|@BGL_AUTO_FINALIZER@|$gcfinalizer|" \
              -e "s|@SHELL@|$ccshell|" \
              -e "s|@SHELL_MV@|$bgl_shell_mv|" \
              -e "s|@SHELL_RM@|$bgl_shell_rm|" \
              -e "s|@C_COMPILER_STYLE@|$ccstyle|" \
              -e "s|@C_COMPILER@|$cc|" \
              -e "s|@C_LD@|$ld|" \
              -e "s|@C_FLAGS@|$cflags|" \
              -e "s|@C_PICFLAGS@|$cpicflags|" \
              -e "s|@C_NANFLAGS@|$cnanflags|" \
              -e "s|@C_COMPILER_O_OPTION@|-o |" \
              -e "s|@C_COMPILER_DEBUG_OPTION@|-g|" \
              -e "s|@C_OBJECT_FILE_EXTENSION@|$cobj|" \
              -e "s|@C_COMPILER_OPTIM_FLAGS@|$coflags|" \
              -e "s|@C_COMPILER_RPATH@|$crpath|" \
              -e "s|@C_STRIP_FLAGS@|$csflags|" \
              -e "s|@C_LINKER_STYLE@|$ldstyle|" \
              -e "s|@C_LINKER_FLAGS@|$lflags $lcustomflags|" \
              -e "s|@C_LINKER_O_OPTION@|-o |" \
              -e "s|@C_LINKER_DEBUG_OPTION@|-g |" \
              -e "s|@C_LINKER_OPTIM_FLAGS@|$loflags|" \
              -e "s|@C_PROFILE_FLAGS@|$cpflags $cflags|" \
              -e "s|@C_STRING_SPLIT@|$stringsplit|" \
              -e "s|@BGL_LD_LIBRARY_DIR@|$libdir|" \
              -e "s|@BGL_NON_CUSTOM_GC_DIR@|$gclibdir|" \
              -e "s|@LIBRARY_DIRECTORY@|$libdir$dirsep$fildir|" \
              -e "s|@BGL_GC_LIBRARY@|$gclib|" \
              -e "s|@BGL_GC_CUSTOM@|$isgccustom|" \
              -e "s|@ZIP_DIRECTORY@|$syszipdirstr|" \
              -e "s|@DLL_DIRECTORY@|$sysdlldirstr|" \
              -e "s|@DNS_CACHE@|$dnscache|" \
          | sed \
              -e "s|@USER_LIBRARIES@|$extralibs|" \
              -e "s|@C_BEAUTIFIER@|$indent|" \
              -e "s|@DIRNAME_CMD@|$dirname|" \
              -e "s|@LIBRARY_BASE_NAME@|$libraryname|" \
              -e "s|@DOUBLE_PRECISION@|$prec|" \
              -e "s|@ADDITIONAL_STATIC_LINK_OPTION@|$ldstaticopt|" \
              -e "s|@ADDITIONAL_SHARED_LINK_OPTION@|$ldsharedopt|" \
              -e "s|@BGL_HAVE_BIGLOO_ABORT@|0|" \
              -e "s|@BGL_HAVE_BDB@|$havebdb|" \
              -e "s|@BGL_JAVA@|$java|" \
              -e "s|@BGL_JAVA_OPT@|$jflags|" \
              -e "s|@BGL_JAVA_VOPT@|$jvflags|" \
              -e "s|@BGL_JAR@|$jar|" \
              -e "s|@BGL_JAVA_SHELL@|$jshell|" \
              -e "s|@BGL_IMPORT@|extern|" \
              -e "s|@BGL_EXPORTED_DECL@|extern|" \
              -e "s|@BGL_EXPORTED_DEF@||" \
              -e "s|@BGL_RUNTIME_DECL@|extern|" \
              -e "s|@BGL_RUNTIME_DEF@||" \
              -e "s|@OS_CLASS@|$osclass|" \
              -e "s|@OS_NAME@|$hostos|" \
              -e "s|@OS_ARCH@|$hostcpu|" \
              -e "s|@OS_VERSION@|$hostosversion|" \
              -e "s|@OS_TMP@|$ostmp|" \
              -e "s|@OS_CHARSET@|$oscharset|" \
              -e "s|@FILE_SEPARATOR@|$fileseparator|" \
              -e "s|@PATH_SEPARATOR@|$pathseparator|" \
              -e "s|@STATIC_LIB_SUFFIX@|$staticlibsuf|" \
              -e "s|@SHARED_LIB_SUFFIX@|$sharedsuffix|" \
              -e "s|@UCS2_DISPLAYABLE@|$ucs2displayable|" \
              -e "s|@GC_HAVE_BLOCKING@|$gchaveblocking|" \
              -e "s|@GC_HAVE_DO_BLOCKING@|$gchavedoblocking|" \
              -e "s|@PTHREAD_HAVE_TIMEDLOCK@|$pthreadtimedlock|" \
              -e "s|@PTHREAD_HAVE_SPINLOCK@|$pthreadspinlock|" \
              -e "s|@PTHREAD_HAVE_MUTEX_RECURSIVE@|$pthreadmutexrec|" \
              -e "s|@PTHREAD_POSIX_CONDV_TIMEDWAIT@|$pthreadcondvtimedwait|" \
              -e "s|@PTHREAD_HAVE_TIMEDJOIN@|$pthreadtimedjoin|" \
              -e "s|@BGL_HAVE_SEMAPHORE@|$semaphore|" \
              -e "s|@BGL_HAVE_LOCKF@|$lockf|" \
              -e "s|@BGL_PTHREAD_TERM_SIG@|$pthreadtermsig|" \
              -e "s|@BGL_HAS_THREAD_LOCALSTORAGE@|$pthreadhastls|" \
              -e "s|@BGL_THREAD_DECL@|$pthreaddecl|" \
              -e "s|@BGL_HEAP_DEBUG_COPT@||" \
              -e "s|@BGL_HAVE_MIXER@|$havemixer|" \
              -e "s|@BGL_REGEXP_FAMILY@|$regexp|" \
              -e "s|@BGL_REGEXP_HAS_FREE_STUDY@|$regexphasfreestudy|" \
	      -e "s|@BOOTBINDIR@|$bootdir/bin|" \
	      -e "s|@BGLBUILDBINDIR@|$buildbindir|" \
	      -e "s|@BGLBUILDLIBDIR@|$buildlibdir|" \
	      -e "s|@BGLBUILDLIBUVLIBDIR@|$buildlibuvlibdir|" \
	      -e "s|@BGLBUILDLIBUNISTRINGLIBDIR@|$buildlibunistringlibdir|" \
	      -e "s|@BGLBUILDPCRELIBDIR@|$buildpcrelibdir|" \
	      -e "s|@BGLBUILDGMPLIBDIR@|$buildgmplibdir|" \
	      -e "s|@SHELL@|$shell|" \
	      -e "s|@BIGLOO@|$bigloo|" \
	      -e "s|@AFILE@|$buildbindir/$afile|" \
	      -e "s|@JFILE@|$buildbindir/$jfile|" \
	      -e "s|@BTAGS@|$buildbindir/$btags|" \
	      -e "s|@BMAKE@|$buildbindir/$bmake|" \
	      -e "s|@BPROF@|$buildbindir/$bprof|" \
	      -e "s|@BPP@|$buildbindir/$bpp|" \
	      -e "s|@JAS@|$buildbindir/$jas|" \
	      -e "s|@BDEPEND@|$buildbindir/$bdepend|" \
	      -e "s|@MCO@|$buildbindir/$mco|" \
          | sed \
	      -e "s|@LD@|$ld|" \
	      -e "s|@LDOPT@|$ldopt|" \
	      -e "s|@RPATH@|$ldrpath|" \
	      -e "s|@RPATHBGL@|$libdir/$fildir|" \
	      -e "s|@LIBDIR@|$libdir|" \
	      -e "s|@FILDIR@|$fildir|" \
	      -e "s|@EXTRALIBS@|$extralibs $extragclibs|" \
	      -e "s|@GCLIBS@|$sharedlibrarygcclosed|" \
	      -e "s|@GCLIB@|$gclib|" \
	      -e "s|@SHAREDSUFFIX@|$sharedsuffix|" \
	      -e "s|@SONAME@|$ldsoname|" \
	      -e "s|@C_LINKER_SONAME_OPTION@|$ldsonameopt|" \
	      -e "s|@C_LINKER_SHARED_OPTION@|$ldopt$ldbuildsharedopt|" \
        > $p
    fi
  done

  # bigloo_h
  cp runtime/Include/`basename $bigloo_h` $bigloo_h
  cp runtime/Include/`basename $bigloo_saw_h` $bigloo_saw_h
  cp runtime/Include/`basename $bigloo_pair_h` $bigloo_pair_h
  cp runtime/Include/`basename $bigloo_real_h` $bigloo_real_h
  cp runtime/Include/`basename $bigloo_bignum_h` $bigloo_bignum_h
  cp runtime/Include/`basename $bigloo_int_h` $bigloo_int_h
  cp runtime/Include/`basename $bigloo_vector_h` $bigloo_vector_h
  cp runtime/Include/`basename $bigloo_string_h` $bigloo_string_h
  cp runtime/Include/`basename $bigloo_struct_h` $bigloo_struct_h
  cp runtime/Include/`basename $bigloo_cell_h` $bigloo_cell_h
  cp runtime/Include/`basename $bigloo_semaphore_h` $bigloo_semaphore_h
  cp runtime/Include/`basename $bigloo_object_h` $bigloo_object_h
  cp runtime/Include/`basename $bigloo_exit_h` $bigloo_exit_h

  # bigloo.sh
  for p in bigloo.sh bglafile.sh bgljfile.sh bgltags.sh bgldepend.sh bglmco.sh bglrun.sh bglld.sh bglmake.sh bgljas.sh bglpp.sh bglprof.sh; do
    mv $p $bootdir/bin/$p
    chmod u+rx $bootdir/bin/$p
  done
fi

#*---------------------------------------------------------------------*/
#*    bigloo_gc.h                                                      */
#*---------------------------------------------------------------------*/
if [ $action = "all" -o $action = "bigloo_gc" ]; then
  customgcbool=1
  if [ $customgc != "yes" ]; then
    customgcbool=0
  fi

  echo "/* Generated file, don't edit */" > $bigloo_gc_h
  cat autoconf/bigloo_gc.h.in \
     | sed -e "s|@GC_VERSION@|$gcversion|" >> $bigloo_gc_h
fi

#*---------------------------------------------------------------------*/
#*    bigloo_static.h                                                  */
#*---------------------------------------------------------------------*/
if [ $action = "all" -o $action = "bigloo_static" ]; then
  echo "/* Generated file, don't edit */" > $bigloo_static_h
  echo "" >> $bigloo_static_h
  echo "#define BGL_ELONG_PREALLOC_MIN $belong_prealloc_min" >> $bigloo_static_h
  echo "#define BGL_ELONG_PREALLOC_MAX $belong_prealloc_max" >> $bigloo_static_h
  echo "static struct elong belong_allocated[] = { " >> $bigloo_static_h
  max=`expr $belong_prealloc_max - 1`;
  i=$belong_prealloc_min
  while expr $i "<" $max > /dev/null; do
    echo "  { header: MAKE_HEADER( ELONG_TYPE, ELONG_SIZE ), val: $i }, " >> $bigloo_static_h
    i=`expr $i + 1`;
  done
  echo "  { header: MAKE_HEADER( ELONG_TYPE, ELONG_SIZE ), val: $i } }; " >> $bigloo_static_h
  echo "" >> $bigloo_static_h
  echo "#if( !defined( BGL_CNST_SHIFT_INT32 ) )" >> $bigloo_static_h
  echo "#define BGL_INT32_PREALLOC_MIN $belong_prealloc_min" >> $bigloo_static_h
  echo "#define BGL_INT32_PREALLOC_MAX $belong_prealloc_max" >> $bigloo_static_h
  echo "static struct bgl_sint32 bint32_allocated[] = { " >> $bigloo_static_h
  max=`expr $belong_prealloc_max - 1`;
  i=$belong_prealloc_min
  while expr $i "<" $max > /dev/null; do
    echo "  { header: MAKE_HEADER( INT32_TYPE, BGL_INT32_SIZE ), val: $i }, " >> $bigloo_static_h
    i=`expr $i + 1`;
  done
  echo "  { header: MAKE_HEADER( INT32_TYPE, BGL_INT32_SIZE ), val: $i } }; " >> $bigloo_static_h
  echo "" >> $bigloo_static_h
  echo "#define BGL_UINT32_PREALLOC_MAX $belong_prealloc_max" >> $bigloo_static_h
  echo "static struct bgl_uint32 buint32_allocated[] = { " >> $bigloo_static_h
  max=`expr $belong_prealloc_max - 1`;
  i=0
  while expr $i "<" $max > /dev/null; do
    echo "  { header: MAKE_HEADER( UINT32_TYPE, BGL_UINT32_SIZE ), val: $i }, " >> $bigloo_static_h
    i=`expr $i + 1`;
  done
  echo "  { header: MAKE_HEADER( UINT32_TYPE, BGL_UINT32_SIZE ), val: $i } }; " >> $bigloo_static_h
  echo "#endif" >> $bigloo_static_h
fi

#*---------------------------------------------------------------------*/
#*    bigloo_config.el                                                 */
#*---------------------------------------------------------------------*/
if [ $action = "all" -o $action = "bigloo_config_el" ]; then
  echo ""
  echo "Configuring $bigloo_config_el:"

  if [ "$emacs " = " " ]; then
    emacs=emacs
    emacsversion=`$autoconf emacsbrand --emacs=emacs` || exit 1
    if [ "$emacsversion" = "false" ]; then
      emacs=xemacs
      emacsversion=`$autoconf emacsbrand --emacs=xemacs` || exit 1
    fi
  else
    emacsversion=`$autoconf emacsbrand --emacs=$emacs` || exit 1
  fi

  if [ "$emacsversion" != "false" ]; then
    if [ "$lispdir " = " " ]; then
      emacslisppath=`$autoconf emacslisppath --emacs=$emacs` || exit 1
    else
      emacslisppath=`$autoconf emacslisppath --emacs=$emacs --path=$lispdir` || exit 1
    fi
    if [ "$emacslisppath" = "" ]; then
      emacsversion="false";
    fi
  else
    emacslisppath=""
  fi

  rm -f $bigloo_config_el 2> /dev/null

  echo ";; Automatically generated file (don't edit) */" > $bigloo_config_el
  echo ";; `date`" >> $bigloo_config_el
  echo "" >> $bigloo_config_el
  echo "(provide 'bmacs-config)" >> $bigloo_config_el
  echo "(defvar bmacs-docdir \"$docdir\")" >> $bigloo_config_el
  echo "(defvar bmacs-lispdir \"$emacslisppath\")" >> $bigloo_config_el
fi


#*---------------------------------------------------------------------*/
#*    texinfo                                                          */
#*---------------------------------------------------------------------*/
if [ "$configureinfo" = "yes" ]; then
  echo ""
  echo "Configuring texinfo:"

  infoinfo=`$autoconf info --makeinfo="$makeinfo" \
                           --texi2dvi="$texi2dvi" \
                           --texi2dviopt="$texi2dviopt" \
                           --texi2pdf="$texi2pdf" \
                           --texi2html="$texi2html" \
                           --texi2htmlopt="$texi2htmlopt"` || exit 1

  if [ "$infoinfo " != " " ]; then
     for p in $infoinfo; do
        case $p in
          "")
             break;;
          makeinfover=*)
             makeinfover="`echo $p | sed 's/^[-a-z_.]*=//'`";;
          texi2dvi=*)
             texi2dvi="`echo $p | sed 's/^[-a-z0-9_.]*=//'`";;
          texi2dviopt=*)
             texi2dviopt="`echo $p | sed 's/^[-a-z0-9_.]*=//'`";;
          texi2pdf=*)
             texi2pdf="`echo $p | sed 's/^[-a-z0-9_.]*=//'`";;
          texi2html=*)
             texi2html="`echo $p | sed 's/^[-a-z0-9_.]*=//'`";;
          texi2htmlopt=*)
             texi2htmlopt="`echo $p | sed 's/^[^=]*=//'`";;
        esac
     done

     if [ "$makeinfover" = "old" ]; then
         makeinfoopt="-D oldinfo"
     fi
  else
     makeinfo=no
     makeinfoopt=
     texi2dvi=
     texi2dviopt=
     texi2html=
     texi2htmlopt=
     texi2pdf=
  fi

  if [ "$iinfo " = " " ]; then
    installinfo=`$autoconf installinfo --exe=$exe` || exit 1
  else
    installinfo=`$autoconf installinfo --installinfo=$iinfo --exe=$exe` || exit 1
  fi
  if [ "$installinfo " != " " ]; then
    installinfodir=`$autoconf installinfodir --installinfo=$installinfo --exe=$exe` || exit 1
  fi
fi

#*---------------------------------------------------------------------*/
#*    Makefile.config                                                  */
#*    -------------------------------------------------------------    */
#*    This part of the configure script produces the file              */
#*    Makefile.config. This file contains machine dependant            */
#*    informations and location where Bigloo is to be installed.       */
#*---------------------------------------------------------------------*/
if [ $action = "all" -o $action = "Makefile.config" ]; then
  # We create an unexisting temporary file name
  name=$buildtmp/foo
  while( test -f "$name.s" -o -f "$name.o" ); do
    name="$name"x;
  done

  # Makefile.buildconfig
  rm -f $makefile_build 2> /dev/null
  echo "# automatically generated, don't edit" > $makefile_build
  echo "# `date`" >> $makefile_build
  echo "" >> $makefile_build
  # The Buildbin directory
  echo "BGLBUILDBINDIR=$buildbindir" >> $makefile_build
  echo "BGLBUILDLIBDIR=$buildlibdir" >> $makefile_build
  echo >> $makefile_build

  # The cmopilers and tools
  if [  "$buildbindir" = "$bootdir/bin" ]; then
    echo 'BIGLOO=$'"(BGLBUILDBINDIR)/bigloo.sh" >> $makefile_build
    echo 'BGLAFILE=$'"(BGLBUILDBINDIR)/bglafile.sh" >> $makefile_build
    echo 'BGLJFILE=$'"(BGLBUILDBINDIR)/bgljfile.sh" >> $makefile_build
    echo 'BGLTAGS=$'"(BGLBUILDBINDIR)/bgltags.sh" >> $makefile_build
    echo 'BGLDEPEND=$'"(BGLBUILDBINDIR)/bgldepend.sh" >> $makefile_build
    echo 'BGLMCO=$'"(BGLBUILDBINDIR)/bglmco.sh" >> $makefile_build
    echo 'CIGLOO=$'"(BGLBUILDBINDIR)/cigloo" >> $makefile_build
  else
    echo 'BIGLOO=$'"(BGLBUILDBINDIR)/bigloo" >> $makefile_build
    echo 'BGLAFILE=$'"(BGLBUILDBINDIR)/bglafile" >> $makefile_build
    echo 'BGLJFILE=$'"(BGLBUILDBINDIR)/bgljfile" >> $makefile_build
    echo 'BGLTAGS=$'"(BGLBUILDBINDIR)/bgltags" >> $makefile_build
    echo 'BGLDEPEND=$'"(BGLBUILDBINDIR)/bgldepend" >> $makefile_build
    echo 'BGLMCO=$'"(BGLBUILDBINDIR)/bglmco" >> $makefile_build
    echo 'CIGLOO=$'"(BGLBUILDBINDIR)/cigloo" >> $makefile_build
  fi
  echo >> $makefile_build

  # We first cleanup the file
  rm -f $makefile_cfg 2> /dev/null
  echo "# automatically generated, don't edit" > $makefile_cfg
  echo "# `date`" >> $makefile_cfg
  echo "" >> $makefile_cfg

  # The Bigloo release number
  echo "RELEASE=$release" >> $makefile_cfg
  echo "VERSION=$version" >> $makefile_cfg
  echo >> $makefile_cfg

  # The repository
  echo "BIGLOOSVN=$bigloosvn" >> $makefile_cfg
  echo >> $makefile_cfg

  # The OS
  echo "HOSTOS=$hostos" >> $makefile_cfg
  echo >> $makefile_cfg

  # The rm & mv commands
  echo "RM=$shell_rm" >> $makefile_cfg
  echo "MV=$shell_mv" >> $makefile_cfg
  echo >> $makefile_cfg

  # The ln -s command
  echo "LN_S=${ln_s}" >> $makefile_cfg
  echo >> $makefile_cfg

  # The bee support
  echo "INSTALLBEE=$bee" >> $makefile_cfg
  echo >> $makefile_cfg

  # The Boot directory
  echo "BOOTDIR=$bootdir" >> $makefile_cfg
  echo "BOOTBINDIR=$bootdir/bin" >> $makefile_cfg
  echo "BOOTLIBDIR=$bootdir/lib/bigloo/$release" >> $makefile_cfg
  echo >> $makefile_cfg

  # The cmopilers and tools
  if [  "$buildbindir" = "$bootdir/bin" ]; then
    echo 'BIGLOO?=$'"(BINDIR)/bigloo.sh" >> $makefile_cfg
    echo 'BGLAFILE?=$'"(BINDIR)/bglafile.sh" >> $makefile_cfg
    echo 'BGLJFILE?=$'"(BINDIR)/bgljfile.sh" >> $makefile_cfg
    echo 'BGLTAGS?=$'"(BINDIR)/bgltags.sh" >> $makefile_cfg
    echo 'BGLDEPEND?=$'"(BINDIR)/bgldepend.sh" >> $makefile_cfg
    echo 'BGLMCO?=$'"(BINDIR)/bglmco.sh" >> $makefile_cfg
    echo 'CIGLOO?=$'"(BINDIR)/cigloo" >> $makefile_cfg
  else
    echo 'BIGLOO?=$'"(BINDIR)/bigloo" >> $makefile_cfg
    echo 'BGLAFILE?=$'"(BINDIR)/bglafile" >> $makefile_cfg
    echo 'BGLJFILE?=$'"(BINDIR)/bgljfile" >> $makefile_cfg
    echo 'BGLTAGS?=$'"(BINDIR)/bgltags" >> $makefile_cfg
    echo 'BGLDEPEND?=$'"(BINDIR)/bgldepend" >> $makefile_cfg
    echo 'BGLMCO?=$'"(BINDIR)/bglmco" >> $makefile_cfg
    echo 'CIGLOO?=$'"(BINDIR)/cigloo" >> $makefile_cfg
  fi
  echo >> $makefile_cfg

  echo "BPP_EXE=$bpp" >> $makefile_cfg
  echo "BPROF_EXE=$bprof" >> $makefile_cfg
  echo "MCO_EXE=$mco" >> $makefile_cfg
  echo "JAS_EXE=$jas" >> $makefile_cfg
  echo "BMEM_EXE=$bmem" >> $makefile_cfg
  echo "BMEMRUN_EXE=$bmemrun" >> $makefile_cfg
  echo "BDB_EXE=$bdb" >> $makefile_cfg
  echo "BGLPKG_EXE=$bglpkg" >> $makefile_cfg
  echo >> $makefile_cfg

  # Directories
  echo "DESTDIR=" >> $makefile_cfg
  echo "BINDIR=$bindir" >> $makefile_cfg
  echo 'LIBDIR=$(DESTDIR)'"$libdir" >> $makefile_cfg
  echo "FILDIR=$fildir" >> $makefile_cfg
  echo 'ZIPDIR=$(DESTDIR)'"$zipdir" >> $makefile_cfg
  echo 'SYSZIPDIR=$(DESTDIR)'"$syszipdir" >> $makefile_cfg
  echo 'DLLDIR=$(DESTDIR)'"$dlldir" >> $makefile_cfg
  echo 'SYSDLLDIR=$(DESTDIR)'"$sysdlldir" >> $makefile_cfg
  echo 'LIBPATH=$(DESTDIR)'"$libdir/$fildir" >> $makefile_cfg
  echo 'MANDIR=$(DESTDIR)'"$mandir" >> $makefile_cfg
  echo 'INFODIR=$(DESTDIR)'"$infodir" >> $makefile_cfg
  echo 'DOCDIR=$(DESTDIR)'"$docdir" >> $makefile_cfg
  echo "TMP=$buildtmp" >> $makefile_cfg
  echo "RPATH=$libdir/$fildir $rpath" >> $makefile_cfg
  echo >> $makefile_cfg

  # Native backend
  echo "NATIVEBACKEND=$nativebackend" >> $makefile_cfg
  echo "NATIVE_MACHDEP=$nativemachdep" >> $makefile_cfg
  echo "SHAREDCOMPILER=$sharedcompiler" >> $makefile_cfg
  echo >> $makefile_cfg

  # The basename
  echo "LIBRARYNAME=$libraryname" >> $makefile_cfg
  echo >> $makefile_cfg

  # The C compiler
  echo "CC=$cc" >> $makefile_cfg
  echo "CFLAGS=$coflags $cflags" >> $makefile_cfg
  echo "CSTRIPFLAGS=$csflags" >> $makefile_cfg
  echo "CPICFLAGS=$cpicflags" >> $makefile_cfg
  echo "CNANFLAGS=$cnanflags" >> $makefile_cfg
  echo "CFLAGS_P=$""(CFLAGS) $cpflags" >> $makefile_cfg
  
  # Close and extra libs
  echo "EXTRALIBS=$extralibs" >> $makefile_cfg
  echo "CLOSELIBS= # always empty, does not contain GC, override by makefiles" >> $makefile_cfg
  echo >> $makefile_cfg

  # The GC library
  echo "CGCFLAGS=$cgcflags $cgcfinalflags $gcspecial -I$""(BOOTLIBDIR) $""(CPICFLAGS) $""(CPICFLAGS)" >> $makefile_cfg
  echo "EXTRAGCLIBS=$extragclibs" >> $makefile_cfg
  echo "CUSTOMGC=$gccustom" >> $makefile_cfg
  echo "GCLIB=$gclib" >> $makefile_cfg
  if [ $customgc = "yes" ]; then
     echo "GCCUSTOM=yes" >> $makefile_cfg
     echo "GCINCLUDE=-I$""(BOOTDIR)/gc/$""(CUSTOMGC)/include" >> $makefile_cfg
     echo "GCCLOSELIB=$sharedlibrarygcclosed" >> $makefile_cfg
     echo "GCSTDOBJ=" >> $makefile_cfg
  else
     echo "GCCUSTOM=no" >> $makefile_cfg
     echo "GCINCLUDE=-I$gcincdir" >> $makefile_cfg
     echo 'GCCLOSELIB=-l$(GCLIB)' >> $makefile_cfg
     echo "GCSTDOBJ=Clib/non_inline_alloc.o" >> $makefile_cfg
     echo "GCLIBDIR=$gclibdir" >>  $makefile_cfg
  fi
  echo >> $makefile_cfg

  # The GMP library
  if [ "$customgmp " = "yes " ]; then
    echo "GMPCUSTOM=yes" >> $makefile_cfg
    echo "GMPCUSTOMVERSION=$gmpversion" >> $makefile_cfg
    echo "GMP_LD_LIBRARY_PATH=$buildgmplibdir" >> $makefile_cfg
  else
    echo "GMPCUSTOM=no" >> $makefile_cfg
  fi
  echo >> $makefile_cfg

  # The PCRE library
  if [ "$custompcre " = "yes " ]; then
    echo "PCRECUSTOM=yes" >> $makefile_cfg
    echo "PCRECUSTOMVERSION=$pcreversion" >> $makefile_cfg
  else
    echo "PCRECUSTOM=no" >> $makefile_cfg
    echo "PCRECUSTOMVERSION=$pcreversion" >> $makefile_cfg
  fi
  echo >> $makefile_cfg

  # The UNISTRING library
  if [ "$customunistring " = "yes " ]; then
    echo "UNISTRINGCUSTOM=yes" >> $makefile_cfg
    echo "UNISTRINGCUSTOMVERSION=$unistringversion" >> $makefile_cfg
  else
    echo "UNISTRINGCUSTOM=no" >> $makefile_cfg
    echo "UNISTRINGCUSTOMVERSION=$unistringversion" >> $makefile_cfg
  fi
  echo >> $makefile_cfg

  # additional bigloo compiler link flags (some architecture such as AIX
  # require a special to link huge executable
  echo "EXTRA_LD_OPT=$lflags $lcustomflags $rflags" >> $makefile_cfg
  if [ $sharedcompiler = "yes" ]; then
     echo "SHRD_COMP=yes" >> $makefile_cfg;
  else
     echo "SHRD_COMP=no" >> $makefile_cfg;
  fi

  if [ $sharedbde = "yes" ]; then
     echo "SHRD_BDE_OPT=" >> $makefile_cfg;
  else
     echo "SHRD_BDE_OPT=-static-bigloo" >> $makefile_cfg;
  fi

  # Executable suffix
  echo "EXE_SUFFIX=$exe" >> $makefile_cfg;

  # The assembler
  echo "AS=$as" >> $makefile_cfg
  echo >> $makefile_cfg

  # Ar checking
  echo "AR=$ar" >> $makefile_cfg
  echo "ARFLAGS=$arflags" >> $makefile_cfg

  # Does the system require ranlib?
  echo "RANLIB=$ranlib" >> $makefile_cfg
  echo >> $makefile_cfg

  # The shared libraries
  if [ "$ldopt" = "no-share" ]; then
    echo "SHAREDLIBRARYSUPPORT=no" >> $makefile_cfg
    echo "LD=true# (true means no dynamic library)" >> $makefile_cfg
    echo "LDRPATHOPT=" >> $makefile_cfg
    echo "LDPRELOADSUPPORT=no" >> $makefile_cfg

    echo "LDSONAME=" >> $makefile_cfg
    echo "LDINSTALLNAME=$ldinstallname" >> $makefile_cfg
    echo "LDINSTALLNAMEDIRROOT=$ldinstallnamedirroot" >> $makefile_cfg
  else
    echo "SHAREDLIBRARYSUPPORT=yes" >> $makefile_cfg
    echo "SHAREDLIBRARYCLOSED=$sharedlibraryclosed" >> $makefile_cfg
    echo "LD=$ld $ldopt" >> $makefile_cfg
    echo "LDRPATHOPT=$ldrpath" >> $makefile_cfg
    echo "LDFLAGS=$ldflags" >> $makefile_cfg
    echo "LDLIBS=$ldlibs" >> $makefile_cfg
    echo "LDPRELOADSUPPORT=$ldpreload" >> $makefile_cfg

    echo "LDSONAME=$ldsoname" >> $makefile_cfg
    echo "LDINSTALLNAME=$ldinstallname" >> $makefile_cfg
    echo "LDINSTALLNAMEDIRROOT=$ldinstallnamedirroot" >> $makefile_cfg
  fi
  echo >> $makefile_cfg

  # The suffix of shared library
  echo "SHAREDSUFFIX=$sharedsuffix" >> $makefile_cfg
  echo >> $makefile_cfg

  # the compiler shared libraries
  # (i.e., the shared libraries linked against the compiler)
  ldcompstatic=""
  ldcompshared=""

  if [ "$customgc " = "yes " ]; then
    ldcompshared="-l\$(GCLIB)-\$(RELEASE) $ldcompshared"
    ldcompstatic="\$(BOOTLIBDIR)/lib\$(GCLIB)-\$(RELEASE).a $ldcompstatic"
  elif [ "$gclibdir " = " " ]; then
    ldcompshared="-lgc $ldcompshared"
    ldcompstatic="-lgc $ldcompshared"
  else
    ldcompshared="-L\$(GCLIBDIR) -lgc $ldcompshared"
    ldcompstatic="-L\$(GCLIBDIR) -lgc $ldcompshared"
  fi

  if [ "$havegmp " = "1 " ]; then
    if [ "$customgmp " = "yes " ]; then
      ldcompshared="-lgmp $ldcompshared" >> $makefile_cfg
      ldcompstatic="$libgmpbuildpath/libgmp.a $ldcompstatic" >> $makefile_cfg
    else
      ldcompshared="-lgmp $ldcompshared" >> $makefile_cfg
      ldcompstatic="-lgmp $ldcompstatic" >> $makefile_cfg
    fi
  fi
  
  if [ "$pcrelibs " != "no " ]; then
    if [ "$custompcre " = "yes " ]; then
      ldcompshared="-lpcre $ldcompshared" >> $makefile_cfg
      ldcompstatic="$libpcrebuildpath/libpcre.a $ldcompstatic" >> $makefile_cfg
    else
      ldcompshared="-lpcre $ldcompshared" >> $makefile_cfg
      ldcompstatic="-lpcre $ldcompstatic" >> $makefile_cfg
    fi
  fi
  
  if [ "$unistringlibs " != "no " ]; then
    if [ "$customunistring " = "yes " ]; then
      ldcompshared="-lunistring $ldcompshared" >> $makefile_cfg
      ldcompstatic="$libunistringbuildpath/libunistring.a $ldcompstatic" >> $makefile_cfg
    else
      ldcompshared="-lunistring $ldcompshared" >> $makefile_cfg
      ldcompstatic="-lunistring $ldcompstatic" >> $makefile_cfg
    fi
  fi
  
  ldcompstatic="\$(BOOTLIBDIR)/libbigloo_s-\$(RELEASE).a $ldcompstatic"
  ldcompshared="-lbigloo_s-\$(RELEASE) $ldcompshared"

  echo "LDCOMPLIBS_SHARED=$ldcompshared" >> $makefile_cfg
  echo "LDCOMPLIBS_STATIC=$ldcompstatic" >> $makefile_cfg
  echo "LDCOMPLIBS=$ldcomplibs" >> $makefile_cfg
  echo >> $makefile_cfg
  
  # The dlopen facility
  if [ "$dlopen" != "0" ]; then
    echo "DLOPENSUPPORT=yes" >> $makefile_cfg
  else
    echo "DLOPENSUPPORT=no" >> $makefile_cfg
  fi

  echo >> $makefile_cfg
  # Does the system support threads
  if [ "$gcthread" != "no" ]; then
    echo "GCTHREADSUPPORT=yes" >> $makefile_cfg
    echo "CGCTHREADFLAGS=$gcthread -DBGL_GC_THREADS" >> $makefile_cfg
  else
    echo "GCTHREADSUPPORT=no" >> $makefile_cfg
    echo "CGCTHREADFLAGS=" >> $makefile_cfg
  fi

  # find out the C library for posix threads
  echo "PTHREADLIBS=$pthreadlibs" >> $makefile_cfg

  # Patch the code of the thread when using non custom GC
  if [ "$pthreadlibs" != "no" ]; then
    # the default gc on mingw is built with thread support.
    # there is no need to link with a special version of gc library
    if [ $isgccustom = "0" ]; then
      gclibth=$stdgclib
    else
      if [ "$hostos " = "mingw " ]; then
        gclibth=bigloogc
      else
        gclibth=bigloogc_fth
      fi
    fi

    if [ "$pthreadtimedjoin " = "1 " ]; then
       srfitimedjoin=pthread-timedjoin;
    fi

    cat api/fthread/src/Misc/fthread.init.in \
        | sed -e "s|@BIGLOOGC_FTH@|$gclibth|g" \
        | sed -e "s|@PTHREADLIBS@|$pthreadlibs|g" \
        >  api/fthread/src/Misc/fthread.init
    cat api/srfi18/src/Misc/srfi18.init.in \
        | sed -e "s|@BIGLOOGC_FTH@|$gclibth|g" \
        | sed -e "s|@PTHREADLIBS@|$pthreadlibs|g" \
        >  api/srfi18/src/Misc/srfi18.init
    cat api/pthread/src/Misc/pthread.init.in \
        | sed -e "s|@BIGLOOGC_PTH@|$gclibth|g" \
        | sed -e "s|@PTHREADLIBS@|$pthreadlibs|g" \
        | sed -e "s|@PTHREADLIBS@|$pthreadlibs|g" \
        | sed -e "s|@PTHREAD_TIMEDJOIN@|$srfitimedjoin|g" \
        >  api/pthread/src/Misc/pthread.init
  else
    napis=;
    for a in $apis; do
      if [ "pthread" != "$a" -a "srfi18" != "$a" -a "fthread" != "$a" -a "gstreamer" != "$a" ]; then
        if [ "$napis " = " " ]; then
          napis="$a";
        else
          napis="$napis $a";
        fi
      fi
    done
    apis=$napis;
  fi

  # SSL
  if [ "$openssllibs" != "no" ]; then
    echo "OPENSSLLIBS=$openssllibs" >> $makefile_cfg
    echo "OPENSSLLIBSCFLAGS=$opensslcflags" >> $makefile_cfg
    echo ";; automatically generated. Don't edit" > api/ssl/src/Misc/ssl.init
    cat api/ssl/src/Misc/ssl.init.in \
        | sed -e "s|@OPENSSLLIBS@|$openssllibs|g" \
              -e "s|@OPENSSLCFLAGS@|$opensslcflags|g" \
        >>  api/ssl/src/Misc/ssl.init

    tls1=1
    tls11=1
    tls12=1
    dtls=1
    sslv2=1
    sslv3=1
    sslv23=1
    randstatus=1;
    randpoll=1;
    getter=1;
    
    if [ "$openssldtls" = "no" ]; then
      dtls=0;
    fi
    if [ "$openssltls1" = "no" ]; then
      tls1=0;
    fi
    if [ "$openssltls11" = "no" ]; then
      tls11=0;
    fi
    if [ "$openssltls12" = "no" ]; then
      tls12=0;
    fi
    if [ "$opensslv2" = "no" ]; then
      sslv2=0;
    fi
    if [ "$opensslv3" = "no" ]; then
      sslv3=0;
    fi
    if [ "$opensslv23" = "no" ]; then
      sslv23=0;
    fi
    if [ "$opensslrand" = "no" ]; then
      randstatus=0;
      randpoll=0;
    fi
    if [ "$opensslgetter" = "no" ]; then
      getter=0;
    fi
    
    echo "/* automatically generated, Don't edit */" >  api/ssl/src/C/bglssl.h
    cat api/ssl/src/C/bglssl.h.in \
      | sed -e "s|@HAVEDTLS@|$dtls|g" \
	    -e "s|@HAVETLS1@|$tls1|g" \
	    -e "s|@HAVETLS1_1@|$tls11|g" \
	    -e "s|@HAVETLS1_2@|$tls12|g" \
            -e "s|@HAVEV2@|$sslv2|g" \
            -e "s|@HAVEV3@|$sslv3|g" \
            -e "s|@HAVEV23@|$sslv23|g" \
            -e "s|@HAVERANDSTATUS@|$randstatus|g" \
            -e "s|@HAVERANDPOLL@|$randpoll|g" \
            -e "s|@HAVEGETTER@|$getter|g" \
            >>  api/ssl/src/C/bglssl.h
  else
    napis=;
    for a in $apis; do
       if [ "ssl" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "OPENSSLLIBS=" >> $makefile_cfg
  fi

  # SQLITE
  echo "SQLITELIBS=$sqlitelibs" >> $makefile_cfg
  if [ "$sqlitelibs " = " " ]; then
    sqlitesrfi=sqltiny;
    echo "SQLITESRFI=sqltiny" >> $makefile_cfg
  else
    sqlitesrfi=sqlite;
    echo "SQLITESRFI=sqlite" >> $makefile_cfg
  fi

  echo ";; automatically generated. Don't edit" > api/sqlite/src/Misc/sqlite.init
  cat api/sqlite/src/Misc/sqlite.init.in \
      | sed -e "s|@SQLITELIBS@|$sqlitelibs|g" \
      | sed -e "s|@SQLITESRFI@|$sqlitesrfi|g" \
      >>  api/sqlite/src/Misc/sqlite.init

  # GSTREAMER
  if [ "$gstreamer " != " " ]; then
    echo "GSTREAMER=$gstreamer" >> $makefile_cfg
    echo "GSTREAMERLIBS=$gstreamerlibs" >> $makefile_cfg
    echo "GSTREAMERCFLAGS=$gstreamercflags" >> $makefile_cfg

    # Patch the code of the GSTREAMER init file
    echo ";; automatically generated. Don't edit" > api/gstreamer/src/Misc/gstreamer.init
    cat api/gstreamer/src/Misc/gstreamer.init.in \
      | sed -e "s|@GSTREAMERLIBS@|$gstreamerlibs|g" \
            -e "s|@GSTREAMERCFLAGS@|$gstreamercflags|g" \
            -e "s|@GSTREAMERAUDIO@|$gstaudio|g" \
      >>  api/gstreamer/src/Misc/gstreamer.init

    # Produce the bglgst_config.h file
    cat api/gstreamer/src/Clib/bglgst_config.h.in \
      | sed -e "s|@CONFIGURE@|Automatically generated file (don't edit), `date`|" \
            -e "s|@GSTREAMER_VERSION@|$gstreamer|g" \
            -e "s|@GSTREAMER_USE_THREADS@|$gstusethread|g" \
            -e "s|@GSTREAMER_HAVE_AUDIO@|$gsthaveaudio|g" \
      >  api/gstreamer/src/Clib/bglgst_config.h

  else
    napis=;
    for a in $apis; do
       if [ "gstreamer" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "GSTREAMER=" >> $makefile_cfg
    echo "GSTREAMERLIBS=" >> $makefile_cfg
    echo "GSTREAMERFLAGS=" >> $makefile_cfg
  fi

  # ALSA
  if [ "$alsa " != "no " ]; then
    echo "ALSA=$alsa" >> $makefile_cfg
    echo "ALSALIBS=$alsalibs" >> $makefile_cfg
    echo "ALSACFLAGS=$alsacflags" >> $makefile_cfg

    # Patch the code of the ALSA init file
    echo ";; automatically generated. Don't edit" > api/alsa/src/Misc/alsa.init
    cat api/alsa/src/Misc/alsa.init.in \
      | sed -e "s|@ALSALIBS@|$alsalibs|g" \
            -e "s|@ALSACFLAGS@|$alsacflags|g" \
      >>  api/alsa/src/Misc/alsa.init
  else
    napis=;
    for a in $apis; do
       if [ "alsa" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "ALSA=" >> $makefile_cfg
    echo "ALSALIBS=" >> $makefile_cfg
    echo "ALSAFLAGS=" >> $makefile_cfg
  fi

  # PULSEAUDIO
  if [ "$pulseaudio " != "no " ]; then
    echo "PULSEAUDIO=$pulseaudio" >> $makefile_cfg
    echo "PULSEAUDIOLIBS=$pulseaudiolibs" >> $makefile_cfg
    echo "PULSEAUDIOCFLAGS=$pulseaudiocflags" >> $makefile_cfg

    # Patch the code of the PULSEAUDIO init file
    echo ";; automatically generated. Don't edit" > api/pulseaudio/src/Misc/pulseaudio.init
    cat api/pulseaudio/src/Misc/pulseaudio.init.in \
      | sed -e "s|@PULSEAUDIOLIBS@|$pulseaudiolibs|g" \
            -e "s|@PULSEAUDIOCFLAGS@|$pulseaudiocflags|g" \
      >>  api/pulseaudio/src/Misc/pulseaudio.init
  else
    napis=;
    for a in $apis; do
       if [ "pulseaudio" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "PULSEAUDIO=" >> $makefile_cfg
    echo "PULSEAUDIOLIBS=" >> $makefile_cfg
    echo "PULSEAUDIOFLAGS=" >> $makefile_cfg
  fi

  # MPG123
  if [ "$mpg123libs " != "no " ]; then
    echo "MPG123=$mpg123" >> $makefile_cfg
    echo "MPG123LIBS=$mpg123libs" >> $makefile_cfg
    echo "MPG123CFLAGS=$mpg123cflags" >> $makefile_cfg

    # Patch the code of the MPG123 init file
    echo ";; automatically generated. Don't edit" > api/mpg123/src/Misc/mpg123.init
    cat api/mpg123/src/Misc/mpg123.init.in \
      | sed -e "s|@MPG123LIBS@|$mpg123libs|g" \
            -e "s|@MPG123CFLAGS@|$mpg123cflags|g" \
      >>  api/mpg123/src/Misc/mpg123.init
  else
    napis=;
    for a in $apis; do
       if [ "mpg123" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "MPG123=" >> $makefile_cfg
    echo "MPG123LIBS=" >> $makefile_cfg
    echo "MPG123FLAGS=" >> $makefile_cfg
  fi

  # FLAC
  if [ "$flaclibs " != "no " ]; then
    echo "FLAC=$flac" >> $makefile_cfg
    echo "FLACLIBS=$flaclibs" >> $makefile_cfg

    # Patch the code of the FLAC init file
    echo ";; automatically generated. Don't edit" >  api/flac/src/Misc/flac.init
    cat api/flac/src/Misc/flac.init.in \
      | sed -e "s|@FLACLIBS@|$flaclibs|g" \
            -e "s|@FLACCFLAGS@|$flaccflags|g" \
      >>  api/flac/src/Misc/flac.init
  else
    napis=;
    for a in $apis; do
       if [ "flac" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "FLAC=" >> $makefile_cfg
    echo "FLACLIBS=" >> $makefile_cfg
    echo "FLACCFLAGS=" >> $makefile_cfg
  fi

  # WAV
  echo ";; automatically generated. Don't edit" >  api/wav/src/Misc/wav.init
  cat api/wav/src/Misc/wav.init.in \
    >>  api/wav/src/Misc/wav.init

  # AVAHI
  echo "AVAHI=$avahi" >> $makefile_cfg
  if [ "$avahi " != "no " ]; then
    echo "AVAHILIBS=$avahilibs" >> $makefile_cfg
    echo "AVAHICFLAGS=$avahicflags" >> $makefile_cfg

    # Patch the code of the AVAHI init file
    echo ";; automatically generated. Don't edit" >  api/avahi/src/Misc/avahi.init
    cat api/avahi/src/Misc/avahi.init.in \
      | sed -e "s|@AVAHILIBS@|$avahilibs|g" \
            -e "s|@AVAHICFLAGS@|$avahicflags|g" \
      >>  api/avahi/src/Misc/avahi.init
  else
    napis=;
    for a in $apis; do
       if [ "avahi" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "AVAHILIBS=" >> $makefile_cfg
    echo "AVAHICFLAGS=" >> $makefile_cfg
  fi

  # LIBUV
  echo "LIBUV=$libuv" >> $makefile_cfg
  if [ "$libuv_is_enabled " = "yes " -a "$libuv " != "no " ]; then
    echo "LIBUVLIBS=$libuvlibs" >> $makefile_cfg
    echo "LIBUVCFLAGS=$libuvcflags" >> $makefile_cfg

    if [ "$customlibuv " = "yes " ]; then
      echo "LIBUVCUSTOM=yes" >> $makefile_cfg
      echo "LIBUVCUSTOMVERSION=$libuvversion" >> $makefile_cfg
    else
      echo "LIBUVCUSTOM=no" >> $makefile_cfg
    fi

    # Patch the code of the LIBUV init file
    echo ";; automatically generated. Don't edit" >  api/libuv/src/Misc/libuv.init
    cat api/libuv/src/Misc/libuv.init.in \
      | sed -e "s|@LIBUVLIBS@|$libuvlibs|g" \
            -e "s|@LIBUVCFLAGS@|$libuvcflags|g" \
      >>  api/libuv/src/Misc/libuv.init
  else
    napis=;
    for a in $apis; do
       if [ "libuv" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "LIBUVCUSTOM=no" >> $makefile_cfg
    echo "LIBUVLIBS=" >> $makefile_cfg
    echo "LIBUVCFLAGS=" >> $makefile_cfg
  fi

  # ALSA
  if [ "$patch " != "no " ]; then
    # Patch the code of the PATCH init file
    echo ";; automatically generated. Don't edit" > api/patch/src/Misc/patch.init
    cat api/patch/src/Misc/patch.init.in \
      | sed -e "s|@PATCHLIBS@|$patchlibs|g" \
            -e "s|@PATCHCFLAGS@|$patchcflags|g" \
      >>  api/patch/src/Misc/patch.init
  else
    napis=;
    for a in $apis; do
       if [ "patch" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "PATCHAPI=" >> $makefile_cfg
    echo "PATCHLIBS=" >> $makefile_cfg
    echo "PATCHFLAGS=" >> $makefile_cfg
  fi

  # PHIDGET
  echo "PHIDGET=$phidget" >> $makefile_cfg
  if [ "$phidget " != "no " ]; then
    echo "PHIDGETLIBS=$phidgetlibs" >> $makefile_cfg
    echo "PHIDGETCFLAGS=$phidgetcflags" >> $makefile_cfg
    echo "PHIDGETLIBDIR=$phidgetlibdir" >> $makefile_cfg

    # Patch the code of the PHIDGET init file
    echo ";; automatically generated. Don't edit" >  api/phidget/src/Misc/phidget.init
    cat api/phidget/src/Misc/phidget.init.in \
      | sed -e "s|@PHIDGETLIBS@|$phidgetlibs|g" \
            -e "s|@PHIDGETCFLAGS@|$phidgetcflags|g" \
            -e "s|@PHIDGETVERSION@|$phidgetversion|g" \
            -e "s|@PHIDGETLIBDIR@|$phidgetlibdir|g" \
      >>  api/phidget/src/Misc/phidget.init

    # Patch the code of the bgphidget_config.h file
    echo "/* automatically generated. Don't edit */" >  api/phidget/src/Clib/bglphidget_config.h
    cat api/phidget/src/Clib/bglphidget_config.h.in \
      | sed -e "s|@PHIDGETLIBS@|$phidgetlibs|g" \
            -e "s|@PHIDGETCFLAGS@|$phidgetcflags|g" \
            -e "s|@PHIDGETVERSION@|$phidgetversion|g" \
            -e "s|@PHIDGETLIBDIR@|$phidgetlibdir|g" \
      >>  api/phidget/src/Clib/bglphidget_config.h
  else
    napis=;
    for a in $apis; do
       if [ "phidget" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
    echo "PHIDGETLIBS=" >> $makefile_cfg
    echo "PHIDGETCFLAGS=" >> $makefile_cfg
    echo "PHIDGETLIBDIR=" >> $makefile_cfg
  fi

  # DBUS
  if [ "$dbusld " != " " ]; then
    echo ";; automatically generated. Don't edit" >  api/dbus/src/Misc/dbus.init
    cat api/dbus/src/Misc/dbus.init.in \
        | sed -e "s|@DBUSLIBS@|$dbusld|g" \
              -e "s|@DBUSCFLAGS@|$dbusincl|g" \
        >>  api/dbus/src/Misc/dbus.init
    echo "CDBUSFLAGS=$dbusincl" >> $makefile_cfg
  else
    napis=;
    for a in $apis; do
       if [ "dbus" != $a ]; then
         if [ "$napis " = " " ]; then
           napis="$a";
         else
           napis="$napis $a";
         fi
       fi
    done
    apis=$napis;
  fi

  # CSV
  echo ";; automatically generated. Don't edit" > api/csv/src/Misc/csv.init
  cat api/csv/src/Misc/csv.init.in \
      >>  api/csv/src/Misc/csv.init
  cat api/csv/src/Llib/csv.sch \
      >>  api/csv/src/Misc/csv.init

  # SCMPKG
  configure=api/pkgcomp/src/Llib/configure.scm
  rm -f $configure
  echo ";; automatically generated. Don't edit" >  $configure
  cat $configure.in \
    | sed -e "s|@PKGCOMPVERSION@|$scmpkgversion|g" \
    >>  $configure
  chmod a-w $configure

  # pkgcomp.init
  pkgcomp_init=api/pkgcomp/src/Misc/pkgcomp.init
  rm -f $pkgcomp_init
  echo ";; automatically generated. Don't edit" >  $pkgcomp_init
  cat api/pkgcomp/src/Misc/pkgcomp.init.in \
      | sed -e "s|@PKGCOMPVERSION@|$scmpkgversion|g" \
      >>  $pkgcomp_init
  echo "" >> $pkgcomp_init

  for p in srfi89.sch interface.sch expanders.sch class.sch configure.sch; do
    cat api/pkgcomp/src/Llib/$p >> $pkgcomp_init
    echo "" >> $pkgcomp_init
  done

  # pkgcomp startup
  echo "(cond-expand ((not bigloo-@expanders) (@install-expanders!)))" \
     >> $pkgcomp_init

  # bglpkg
  configure=bglpkg/configure.scm
  rm -f $configure
  echo ";; automatically generated. Don't edit" >  $configure
  cat $configure.in \
       | sed -e "s|@BGLPKGVERSION@|$release|g" \
             -e "s|@BGLPKGNAME@|$bglpkg|g" \
       >>  $configure
  chmod a-w $configure
  echo "ENABLE_BGLPKG=$enable_bglpkg" >> $makefile_cfg
  echo "" >> $makefile_cfg

  # Does the system support strip
  echo "STRIP=$strip" >> $makefile_cfg
  echo "" >> $makefile_cfg

  # Display emacs
  echo "EMACS=$emacs" >> $makefile_cfg
  echo "EMACSDIR=$emacslisppath" >>  $makefile_cfg
  echo "EMACSBRAND=$emacsversion" >> $makefile_cfg
  echo "EWARN=$emacswarning" >> $makefile_cfg
  echo >> $makefile_cfg

  # bmask
  echo "BMASK=$bmask" >> $makefile_cfg
  echo "MODEXE=$modexe" >> $makefile_cfg
  echo "MODFILE=$modfile" >> $makefile_cfg
  echo "MODDIR=$moddir" >> $makefile_cfg
  echo >> $makefile_cfg

  # The info version
  if [ "$configureinfo" = "yes" ]; then
    if [ "$infoinfo " != " " ]; then
       echo "MAKEINFO=$makeinfo" >> $makefile_cfg
       echo "MAKEINFOOPT=$makeinfoopt" >> $makefile_cfg
       echo "TEXI2DVI=$texi2dvi" >> $makefile_cfg
       echo "TEXI2DVIOPT=$texi2dviopt" >> $makefile_cfg
       echo "TEXI2HTML=$texi2html" >> $makefile_cfg
       echo "TEXI2HTMLOPT=$texi2htmlopt" >> $makefile_cfg
       echo "TEXI2PDF=$texi2pdf" >> $makefile_cfg
    else
       echo "MAKEINFO=" >> $makefile_cfg
    fi
  fi

  # The info installation
  if [ "$installinfo " = " " ]; then
     echo "INSTALLINFO=\"\"" >> $makefile_cfg
  else
     echo "INSTALLINFO=$installinfo" >> $makefile_cfg
     echo "INSTALLINFODIROPT=$installinfodir" >> $makefile_cfg
  fi

  # The java configuration
  if [ "$jvmbackend" = "yes" -o "$jvmbackend" = "force" ]; then

    if [ "$jvmbackend" = "yes" ]; then
      $autoconfdir/ziptest --zip=$zip --zflags=$zflags --user=$user --tmp=$buildtmp

      if [ $? != 0 ]; then
        echo "*** ERROR:configure:Can't find zip needed for the JVM back-end"
        exit 3
      fi

      $autoconfdir/jartest --jar=$jar --user=$user --tmp=$buildtmp

      if [ $? != 0 ]; then
        echo "*** ERROR:configure:Can't find jar nedded for the JVM back-end"
        exit 3
      fi

      if [ "$java_configured" = "no" ]; then
        $autoconfdir/javatest --java=$java --jflags=$jflags --jvflags=$jvflags \
                              --javac=$javac --jcflags=$jcflags --user=$user --tmp=$buildtmp

        if [ $? != 0 ]; then
          echo "*** ERROR:configure:Can't configure JVM back-end"
          exit 3
        fi
        java_configured=yes
      fi
    else
        java_configured=yes
    fi

    echo "" >> $makefile_cfg
    echo "JVMBACKEND=yes" >> $makefile_cfg
    echo "JAVA=$java" >> $makefile_cfg
    echo "JAVA_VERSION=$java_version" >> $makefile_cfg
    echo "JFLAGS=$jflags" >> $makefile_cfg
    echo "JVFLAGS=$jvflags" >> $makefile_cfg
    echo "JAVAC=$javac" >> $makefile_cfg
    echo "JCFLAGS=$jcflags" >> $makefile_cfg
    echo "ZIP=$zip" >> $makefile_cfg
    echo "ZFLAGS=$zflags" >> $makefile_cfg
    echo "JAR=$jar" >> $makefile_cfg
    echo "JSHELL=$jshell" >> $makefile_cfg

    echo "JVMRECETTEBOOTPATH=$jvmrecettebootpath" >> $makefile_cfg
    echo "JVMAPIBOOTPATH=$jvmapibootpath" >> $makefile_cfg

    # Cygwin prefix
    if [ "$hostos" = "cygwin" ]; then
      echo "" >> $makefile_cfg
      echo CYGWINPREFIX=`echo "$cygwindospath" | sed -e 's/\\\\/\\\\\\\\/g'` >> $makefile_cfg
      bigloozip=$bootdir/lib/$release
      bigloozip=`echo $bigloozip | sed -e 's/\/cygdrive\/\([a-z]\)\//\1:\//'`        # corrects pathes like /cygdrive/...
      bigloozip=`echo $bigloozip | sed -e "s/^\//$cygwindospath\\\\\\\\\\\\\\\\/"`   # corrects pathes like /usr...
      echo "CYGWINJVMPATH=-classpath \".;"`echo $bigloozip | sed -e 's/\//\\\\\\\\/g'`"\\\\bigloo_s.zip\"" >> $makefile_cfg
    else
      echo "CYGWINJVMPATH=" >> $makefile_cfg
    fi

    echo "JVMCLASSPATHSEP=\"$cpsep\"" >> $makefile_cfg
  else
    echo "" >> $makefile_cfg
    echo "JVMBACKEND=no" >> $makefile_cfg
  fi

fi

# Bigloo compilation flags
echo "" >> $makefile_cfg
echo "BFLAGS=$bflags -lib-dir "'$'"(BOOTLIBDIR)" >> $makefile_cfg
echo "BOOTFLAGS=$bootflags" >> $makefile_cfg
echo "BFEATUREFLAGS=$featureflags" >> $makefile_cfg
if [ "$csflags " = " " ]; then
  echo "LDSTRIPFLAGS=" >> $makefile_cfg
else
  echo "LDSTRIPFLAGS=-ldopt $csflags" >> $makefile_cfg
fi

# script extension
echo "" >> $makefile_cfg
case $hostos in
  cygwin)
    echo "SCRIPTEXTENSION=.bat" >> $makefile_cfg;;
  *)
   echo "SCRIPTEXTENSION=" >> $makefile_cfg;;
esac

# C Object suffix
echo "C_OBJ_EXTENSION=$cobj" >> $makefile_cfg
echo >> $makefile_cfg

# APIs
echo "APIS=$apis" >> $makefile_cfg
echo "NOAPIS=" >> $makefile_cfg
echo >> $makefile_cfg

# Android specific
if [ "$hostos " = "android " ]; then
  echo "DROIDROOT=$droidroot" >> $makefile_cfg
  echo "DROIDSDKROOT=$droidsdkroot" >> $makefile_cfg
  echo >> $makefile_cfg
fi

#*---------------------------------------------------------------------*/
#*    Debian scripting                                                 */
#*---------------------------------------------------------------------*/
# debian
deb=arch/debian/makedeb.sh
rm -f $deb 2> /dev/null
echo "#!/bin/sh" > $deb
echo "#* Automatically generated file (don't edit) */" >> $deb

cat $deb.in \
   | sed -e "s|#!/bin/sh||" \
         -e "s|@VERSION@|$release|" \
         -e "s|@APIS@|$apis|" \
   >> $deb  
chmod a+rx $deb

#*---------------------------------------------------------------------*/
#*    Checking missing dependencies                                    */
#*---------------------------------------------------------------------*/
if [ "$abortmissing " = "yes " ]; then
    missing="";
    
    for p in $importantapis; do
       res=0;
       for q in $apis; do
           if [ $q = $p ]; then
	       res=1;
	       break;
	   fi
       done
       if [ $res = "0" ]; then
	   missing="$p $missing"
       fi
    done

    if [ "$missing " != " " ]; then
	echo ""
	echo "*** ERROR Missing libraries: $missing" >&2
	echo "exiting..." >&2
	exit 1;
    fi

    if [ "$unistring " = "no " ]; then
	echo ""
	echo "*** ERROR Missing library: unistring" >&2
	echo "exiting..." >&2
	exit 1;
    fi
    
    if [ ! "$regexp " = "pcre " ]; then
	echo ""
	echo "*** ERROR Missing library: pcre" >&2
	echo "exiting..." >&2
	exit 1;
    fi
    
    if [ ! "$havegmp " = "1 " ]; then
	echo ""
	echo "*** ERROR Missing library: gmp" >&2
	echo "exiting..." >&2
	exit 1;
    fi
fi

#*---------------------------------------------------------------------*/
#*    Ok, we are done now                                              */
#*---------------------------------------------------------------------*/
bcke="native:yes"
if [ "$jvmbackend" = "yes" -o "$jvmbackend" = "force" ]; then
  bcke="$bcke JVM:yes"
else
  bcke="$bcke JVM:no"
fi

echo  >> $configurelog
echo  >> $configurelog
echo "** Configuration summary **" >> $configurelog
echo  >> $configurelog
echo "Release features:" >> $configurelog
echo "  Bigloo release number................. $release" >> $configurelog
echo "  Bigloo supported backends............. $bcke" >> $configurelog
echo "  Bigloo default backend................ $defaultbackend" >> $configurelog
echo "  APIs.................................. $apis" >> $configurelog
if [ $customgc = "yes" ];then
   echo "  Bigloo gc............................. custom ($gclib $gcversion)" >> $configurelog
else
   echo "  Bigloo gc............................. standard ($gclib $gcversion, $gcincdir, $gclibdir)" >> $configurelog
fi
if [ "$pthreadlibs" = "no" ]; then
  echo "  support for native threads............ no" >> $configurelog
else
  echo "  support for native threads............ yes" >> $configurelog
  if [ "$pthreadhastls " = "1 " ]; then
    echo "  support for thread local storage ..... yes" >> $configurelog
  else
    echo "  support for thread local storage ..... no" >> $configurelog
  fi
fi
if [ "$openssllibs" = "no" ]; then
  echo "  Open SSL support...................... no" >> $configurelog
else
  echo "  Open SSL support...................... yes (dtls:$openssldtls, v2:$opensslv2, v3:$opensslv3, v23:$opensslv23)" >> $configurelog
fi
if [ "$sqlitelibs " = " " ]; then
  echo "  Sqlite ............................... sqltiny" >> $configurelog
else
  echo "  Sqlite ............................... sqltiny + sqlite" >> $configurelog
fi
if [ "$ldopt" = "no-share" ]; then
  echo "  support for dynamic libraries......... no" >> $configurelog
else
  echo "  support for dynamic libraries......... yes" >> $configurelog
fi
echo "  Bee support........................... $bee" >> $configurelog
echo >> $configurelog
echo "Directories where Bigloo will be installed:" >> $configurelog
echo "  binaries.............................. $bindir" >> $configurelog
echo "  libraries............................. $libdir" >> $configurelog
echo "  files directory....................... $fildir" >> $configurelog
echo "  standard zip.......................... $zipdir" >> $configurelog
if [ "$syszipdir " != "$zipdir " ]; then
  echo "  standard zip (os dependent)........... $syszipdir" >> $configurelog
fi
echo "  standard dll.......................... $dlldir" >> $configurelog
if [ "$sysdlldir " != "$dlldir " ]; then
  echo "  standard dll (os dependent)........... $sysdlldir" >> $configurelog
fi
echo "  manual pages.......................... $mandir" >> $configurelog
echo "  info documentation.................... $infodir" >> $configurelog
echo "  lisp files............................ $lispdir" >> $configurelog
echo "  temporary dir......................... $buildtmp" >> $configurelog
echo >> $configurelog
echo "Compilers and linkers:" >> $configurelog
echo "  C compiler used....................... $cc" >> $configurelog
echo "  options for compiling................. $cflags" >> $configurelog
echo "  options for optimizing................ $coflags" >> $configurelog
echo "  options for stripping................. $csflags" >> $configurelog
echo "  options for PIC code.................. $cpicflags" >> $configurelog
echo "  options for NAN code.................. $cnanflags" >> $configurelog
echo "  options for profiling................. $cpflags" >> $configurelog
echo "  options for linking................... $extralibs" >> $configurelog
echo "  assembly.............................. $as" >> $configurelog
echo "  static library builder................ $ar" >> $configurelog
echo "  shared library builder................ $ld" >> $configurelog
echo "  options for building static libs...... $arflags" >> $configurelog
echo "  socket libraries...................... $socketlibs" >> $configurelog
echo "  gmp version........................... $gmpversion" >> $configurelog
echo "  unistring library..................... $extraunistring" >> $configurelog
echo "  pthread libraries..................... $pthreadlibs" >> $configurelog
echo "  openssl libraries..................... $openssllibs" >> $configurelog
echo "  sqlite libraries...................... $sqlitelibs" >> $configurelog
if [ "$ldopt" != "no-share" ]; then
  echo "  suffix of shared libraries............ $sharedsuffix" >> $configurelog
  echo "  options for linking with shared libs.. $ldopt" >> $configurelog
fi
echo "  dynamically linked compiler........... $sharedcompiler" >> $configurelog
echo "  dynamically linked bde tools.......... $sharedbde" >> $configurelog
echo >> $configurelog
if [ "$jvmbackend" = "yes" -o "$jvmbackend" = "force" ]; then
  echo "JVM:" >> $configurelog
  if [ "$hostos" = "cygwin" ]; then
    echo "  Cygwin dos path....................... $cygwindospath" >> $configurelog
  fi
  echo "  java default shell.................... $jshell" >> $configurelog
  echo "  javac................................. $javac" >> $configurelog
  echo "  options for compiling java............ $jcflags" >> $configurelog
  echo "  java.................................. $java" >> $configurelog
  echo "  options for running java.............. $jflags" >> $configurelog
  echo "  options no byte code verification..... $jvflags" >> $configurelog
  echo "  zip................................... $zip" >> $configurelog
  echo "  zip flags............................. $zflags" >> $configurelog
  echo "  jar................................... $jar" >> $configurelog
fi
echo >> $configurelog
echo "GC configuration:" >> $configurelog
if [ $customgc = "yes" ]; then
  echo "  options for compiling the collector... $cgcflags $cgcfinalflags $gcspecial" >> $configurelog
  echo "  options for compiling with threads.... $gcthread" >> $configurelog
else
  echo "  pre-installed standard GC............. $gclib" >> $configurelog
fi
echo >> $configurelog
echo "Emacs configuration:" >> $configurelog
echo "  emacs................................. $emacs" >> $configurelog
echo "  emacs brand........................... $emacsversion" >> $configurelog
if [ $emacsversion = "generic" ]; then
  echo "  lisp directory........................ no support (update emacs)" >> $configurelog
else
  echo "  lisp directory........................ $emacslisppath" >> $configurelog
fi
echo >> $configurelog
echo "Misc configuration:" >> $configurelog
echo "  mask for installed files.............. $modfile" >> $configurelog
echo "  mask for installed executable......... $modexe" >> $configurelog
echo "  mask for installed directories........ $moddir" >> $configurelog
echo  >> $configurelog
echo "System configuration:" >> $configurelog
echo "  hardware tuning....................... $hardtune" >> $configurelog
echo "  operating system...................... $hostos" >> $configurelog
echo "  default executable name............... $aout" >> $configurelog
echo  >> $configurelog

#*---------------------------------------------------------------------*/
#*    Post configure                                                   */
#*---------------------------------------------------------------------*/
if [ -x configure.postcmd ]; then
  echo "Post configuration setup...";
fi

#*---------------------------------------------------------------------*/
#*    Generate the config.status file for debian packages              */
#*---------------------------------------------------------------------*/
echo "configuration completed" > config.status

#*---------------------------------------------------------------------*/
#*    Ok, we are done now                                              */
#*---------------------------------------------------------------------*/
if [ "$summary" = "yes" ]; then
  echo
  echo
  echo "** Configuration summary **"
  echo
  echo "Release features:"
  echo "  release number.............. $release"
  echo "  supported backends.......... $bcke"
  echo "  default backend............. $defaultbackend"
  echo "  APIs........................ $apis"
  if [ "$pthreadlibs" = "no" ]; then
    echo "  native threads support...... no"
  else
    echo "  native threads support...... yes"
  fi
  if [ "$openssllibs" = "no" ]; then
    echo "  openssl support............. no"
  else
    echo "  openssl support............. yes (dtls:$openssldtls, v2:$opensslv2, v3:$opensslv3, v23:$opensslv23)"
  fi
  if [ "$sqlitelibs " = " " ]; then
    echo "  sqlite support ............. sqltiny"
  else
    echo "  sqlite support.............. sqltiny + sqlite"
  fi
  if [ "$ldopt" = "no-share" ]; then
    echo "  dynamic libraries support... no"
  else
    echo "  dynamic libraries support... yes"
  fi
  echo
  echo "Bee configuration:"
  echo "  bee support................. $bee"
  echo "  emacs....................... $emacs"
  echo "  emacs brand................. $emacsversion"
  echo
  echo "Implementation details:"
  echo "  tuning...................... $mode $tuning"
  echo "  cc.......................... $cc"
  if [ $bglnantagging != "0" ]; then
    echo "  nan tagging................. $bglnantagging"
  else
    echo "  nan tagging................. no"
  fi
  if [ $customgc = "yes" ];then
     echo "  gc.......................... custom ($gclib-$release, v$gcversion)"
  else
     echo "  gc.......................... standard ($gclib, $gcincdir, v$gcversion)"
  fi
  if [ "$java_configured " = "yes " ]; then
    echo "  Java version................ $java_version"
  fi
  if [ "$gmpversion" = "no" ]; then
    echo "  bignum support.............. scheme implementation"
  else
    echo "  bignum support.............. gmp ($gmpversion)"
  fi
  if [ "$resolv" = "no" ]; then
    echo "  resolv support.............. no"
  else
    echo "  resolv support.............. lib$resolv"
  fi
  if [ "$unistring" = "no" ]; then
    echo "  unistring support........... minimal"
  else
    echo "  unistring support........... $extraunistring"
  fi
  echo
  echo "Directories where Bigloo will be installed:"
  echo "  binaries.................... $bindir"
  echo "  libraries................... $libdir"
  echo "  files directory............. $fildir"
  echo "  standard zip................ $zipdir"
  if [ "$syszipdir " != "$zipdir " ]; then
    echo "  standard zip (os dependent). $syszipdir"
  fi
  echo "  standard dll................ $dlldir"
  if [ "$sysdlldir " != "$dlldir " ]; then
    echo "  standard dll (os dependent). $sysdlldir"
  fi
  echo "  manual pages................ $mandir"
  echo "  info documentation.......... $infodir"
  echo "  lisp files.................. $lispdir"
  echo "  temporary build dir......... $buildtmp"
  echo
fi
