dnl Process this file with autoconf to produce a configure script.
## Copyright INRIA/Enpc

AC_REVISION($Revision: 1.132.2.6 $)dnl
AC_INIT(license.txt)
SCIDIR=`pwd`
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_HEADER(routines/machine.h)

dnl Get system type
dnl use "config.guess" and "config.sub" from directory "config"
AC_CANONICAL_HOST

# default prefix
ac_default_prefix=/usr

#################################

AC_ARG_ENABLE(debug,
   [  --enable-debug          compile with "-g" option and do not optimize ])

AC_ARG_WITH(gcc,
    [  --with-gcc              use gcc C compiler ])
    
AC_ARG_WITH(g77,
    [  --with-g77              use g77, GNU Fortran 77 compiler ])

AC_ARG_WITH(gfortran,
    [  --with-gfortran         use gfortran, GNU Fortran 95 compiler ])

AC_ARG_WITH(gnu,
    [  --with-gnu              use gcc C compiler and gnu Fortran compiler (g77 or gfortran) ])

AC_ARG_WITH(intelcompilers,
    [  --with-intelcompilers   use intel icc and ifort Fortran compiler ])

AC_ARG_WITH(f2c,
    [  --with-f2c              use f2c C compiler on Linux systems ])
    
AC_ARG_WITH(local-xaw,
    [  --with-local-xaw        use Xaw3d widgets given with Scilab  ])

AC_ARG_WITH(pvm,
    [  --without-pvm           do not compile with PVM library ])

AC_ARG_WITH(tk,
    [  --without-tk            do not compile with TCL/TK ])

AC_ARG_WITH(gtk,
    [  --with-gtk              use Gtk widgets ])

AC_ARG_WITH(gtk2,
    [  --with-gtk2             use Gtk widgets ])

AC_ARG_WITH(addedf2c,
    [  --with-addedf2c         build a local f2c (routines/f2c)])

AC_ARG_WITH(ocam,
    [  --without-ocaml         do not compile with ocaml ])

AC_ARG_WITH(java,
    [  --without-java          do not compile  Java interface ])

#################################
## check this is a source version
#################################

if test -f .binary; then
  echo "Humm... this is a binary version";
  echo "  you'd better read the README file first."
  exit
fi

###############################
## creating Path.incl if needed
###############################
# 
# change scidir for mingw 
#   *-*-cygwin* |   *-*-mingw32*)

case "$host" in
   *-*-mingw32*)
    SCIDIR=`echo $SCIDIR | sed -e 's+/cygdrive/\([[a-zA-Z]]*\)/+\1:/+g' `
    ;;
esac

if test -f Path.incl; then
  PATH_INCL=`cat Path.incl`
fi
if test "$PATH_INCL" != "SCIDIR=$SCIDIR"; then
  echo "creating Path.incl"
  cat << EOF > Path.incl
SCIDIR=$SCIDIR
EOF
fi

###############################
## get the version 
###############################

SCIVERSION=`cat Version.incl | sed -e "s/SCIVERSION=//" `

########################
## removing and cleaning
########################

RM='rm -f'
FILES_TO_CLEAN='*.CKP *.ln *.BAK *.bak core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut .*~ *.trace so_locations *.orig *.cos *.obj' 

#####################################################
## if specific compilers required check if they exist
#####################################################

if test "$with_gnu" = yes; then
	# GNU C and Fortran compilers required
	AC_CHECK_PROG(WITH_GCC,gcc,yes,no)
	if test "$WITH_GCC" = no; then
		AC_MSG_ERROR([Unable to configure: gcc compiler not found])
	fi
	AC_CHECK_PROG(WITH_G77,g77,yes,no)
	if test "$WITH_G77" = no; then
		AC_CHECK_PROG(WITH_GFORTRAN,gfortran,yes,no)
		if test "$WITH_GFORTRAN" = no; then
			AC_MSG_ERROR([Unable to configure: g77 or gfortran compiler not found])
		fi
	fi
elif test "$with_intelcompilers" = yes; then
	# intel C and Fortran compilers required
	AC_CHECK_PROGS(ICC,icc ecc,no)
	if test "$ICC" = no; then
		AC_MSG_ERROR([Unable to configure: icc nor ecc  compiler found])
	fi
	AC_CHECK_PROGS(IFC,ifort ifc efc,no)
	if test "$IFC" = no; then
		AC_MSG_ERROR([Unable to configure: ifc nor efc compiler  found])
	fi
	AC_MSG_WARN([Scilab incremental link may be buggy with Intel Compiler(s). 
See bug 1925])
	sleep 5
elif test "$with_gcc" = yes; then
	# GNU gcc required
	AC_CHECK_PROG(WITH_GCC,gcc,yes,no)
	if test "$WITH_GCC" = no; then
		AC_MSG_ERROR([Unable to configure: gcc compiler not found])
	fi
elif test "$with_g77" = yes; then
	# GNU g77 required
	AC_CHECK_PROG(WITH_G77,g77,yes,no)
	if test "$WITH_G77" = no; then
		AC_MSG_ERROR([Unable to configure: g77 compiler not found])
	fi
elif test "$with_gfortran" = yes; then
	# GNU g95 (gfortran) required
	AC_CHECK_PROG(WITH_GFORTRAN,gfortran,yes,no)
	if test "$WITH_GFORTRAN" = no; then
		AC_MSG_ERROR([Unable to configure: gfortran compiler not found])
	fi
fi

#############################################
## Compilers and options according to machine
#############################################

# use for making scripts in script directory
#   different for MIPS Ultrix
SCILAB_GS=sh
# scilab script file in script directory: default is "scilab.g" for UNIX
#   for gcwin32 use "scilab-gcwin32.g"
SCILABSCRIPT=scilab.g
# Fortran program in routines/os_specific: default is "fgetarg.f" 
#   for HPUX use "fgetarg-hpux.f"
FGETARG=fgetarg
GETARG=getarg
# For old Hp computer (9.x), used in "routines/os_specific/Makefile.in"
#   for choosing the good file between link_std.c and link_SYSV.c
HPPA_OLD=
# Scilab main file: default is "mainsci.o" for UNIX
MAIN='mainsci.o'
# for graphics: default is X11
#   different for Win32
PERIFILE=periX11.o
# specific scilab dirs for graphics: default is "xsci" for X11
#   different for Win32
GUILIB=xsci 
# specific for gnome/gtk version 
GZVT=
# specific scilab dirs for xdr:  default is void for X11
#   xdr for Win32
XDRLIB=
XDRLIBNAME=
# objects files in routines/menusX: default is XOBJS for UNIX
#   for Win32 use WOBJS
MENUSOBJS=XOBJS
# use other malloc (in "routines/os_specific" directory) for some 64 bits machines
MALLOC=
# USE_CDEC directives for Dec Alpha
FC_USE_CDEC=DEC
# want to build Scilab f2c too 
if test "$with_addedf2c" = yes; then
  F2C_SUBDIR=f2c/src
else
  F2C_SUBDIR=
fi
# on windows target generating scripts for 
# printing is useless 
BLPR_SCRIPTS='$(BPROGRAMS)'
# on windows target when generating script 
# cygdrive/xxx must be replaced by xxx:/ 
# for mingw32 
SED_CYGDRIVE=
# subset of examples which are supposed to work 
EXAMPLES_TESTS='$(SUBDIRS1) $(SUBDIRS2)'
# special stuff for cygwin in impdir 
IMPPREF=S
IMPENV= 
# strip executable (not to be done on darwin) 
STRIP=strip
# periX11.c must be compiled without optimization on Darwin
PERIX11NOPT=periX11darwin
NMOPT=

#########################
## libtool 
#########################

echo "configuration of libtool"

AC_PROG_LIBTOOL

echo "end of configuration of libtool"
#########################
# setting parameters according to system types
#########################
# suffix of dynamic libraries
SONAME=so

GCCFIX=

case "$host" in
# Dec Alpha OSF 4
  alpha*-dec-osf4.*)
    # C compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    else
      CC=cc
      CC_OPTIONS='-std -O -DNDEBUG -ieee_with_inexact'
      CC_LDFLAGS='-ieee_with_inexact'
    fi
    #fortran compiler
    if test "$WITH_G77" = yes; then    
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    else
      AC_CHECK_PROGS(F77,f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran f77 compiler not found])
      fi
      FC="$F77"
      FC_OPTIONS='-O -fpe3'
      FC_OPTIONS_O0='-fpe3'
      FC_LDFLAGS=
      FC_USE_CDEC='   '
      if test "$enable_debug" = yes; then 
        CC_OPTIONS='-std -g -ieee_with_inexact'
        FC_OPTIONS='-g -fpe3'
      fi
    fi
    LD=ld
    LD_LDFLAGS=

    MAKEFILE_TARGET=Makefile.alpha
    ;;
# Dec Alpha not OSF 4 (NO LONGER SUPPORTED)
  alpha*-dec-osf*)
    # standard compilers
    CC=cc
    CC_OPTIONS='-O -DNDEBUG -ieee_with_inexact'
    CC_LDFLAGS='-ieee_with_inexact'
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,f77,yes,no)
      AC_CHECK_PROGS(F77,f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran f77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    FC_OPTIONS='-O -fpe3 -switch nosqrt_recip'
    FC_OPTIONS_O0='-fpe3 -switch nosqrt_recip'
    FC_LDFLAGS=
    FC_USE_CDEC='   '
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -ieee_with_inexact'
      FC_OPTIONS='-g -fpe3 -switch nosqrt_recip'
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi
    MAKEFILE_TARGET=Makefile.alpha
    ;;
# IBM AIX RS 6000 (NO LONGER SUPPORTED)
  rs6000-*-*)
    # standard compilers
    CC=cc
    CC_OPTIONS='-Daix -DSYSV'
    CC_LDFLAGS=
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,f77,yes,no)
      AC_CHECK_PROGS(F77,f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran f77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    FC_OPTIONS='-qcharlen=4096'
    FC_OPTIONS_O0='-qcharlen=4096'
    FC_LDFLAGS=
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -Daix -DSYSV'
      FC_OPTIONS='-g -qcharlen=4096'
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi
    MAKEFILE_TARGET=Makefile.aix
    ;;
# SUN OS (NO LONGER SUPPORTED)
  sparc-*-sunos*)
    # standard compilers
    CC=cc
    CC_OPTIONS=-O -DNDEBUG
    CC_LDFLAGS=
    CC_PICFLAGS=-PIC
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,f77,yes,no)
      AC_CHECK_PROGS(F77,f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran f77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    FC_OPTIONS=-O
    FC_OPTIONS_O0=
    FC_LDFLAGS=
    FC_PICFLAGS=-PIC
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS=-g
      FC_OPTIONS=-g
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      CC_PICFLAGS=
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      FC_PICFLAGS=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
      FC_LDFLAGS='-Xlinker'
    fi
    MAKEFILE_TARGET=Makefile.sunos
    ;;
# SUN SOLARIS
  *-*-solaris*)
    # standard compilers
    CC=cc
    CC_OPTIONS='-O -DNDEBUG -DSVR4 -DSYSV -Dsolaris'
    CC_LDFLAGS=
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,f77,yes,no)
      AC_CHECK_PROGS(F77,f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran f77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    FC_OPTIONS=-O
    FC_OPTIONS_O0=
    FC_LDFLAGS=
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -DSVR4 -DSYSV -Dsolaris'
      FC_OPTIONS=-g
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS='-O2 -DNDEBUG -DSVR4 -DSYSV -Dsolaris'
      if test "$enable_debug" = yes; then 
        CC_OPTIONS='-g -DSVR4 -DSYSV -Dsolaris'
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O2
      FC_OPTIONS_O0=
      FC_LDFLAGS='-t' 
#     for solaris 2.7 with gcc/g77 2.95.2, binutils 2.9 
#     the correct value should be 
#     FC_LDFLAGS='-t -Wl,-export-dynamic'
#     but we need to check this case 
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi
    AC_F77_LIBRARY_LDFLAGS
    MAKEFILE_TARGET=Makefile.solaris
    ;;
# Linux, old binary format a.out (NO LONGER SUPPORTED)
  *-pc-linux-gnuaout)
    LIEEELIB=
    AC_CHECK_LIB(ieee,main,
      [LIEEELIB=-lieee])
    GCC=yes
    CC=gcc
    CC_OPTIONS='-O -DNDEBUG -Dlinux -fwritable-strings'
    CC_LDFLAGS=$LIEEELIB
    # find Fortran compiler
    # g77 already asked and found: good
    if test "$WITH_G77" = yes; then
      FC=g77
    # option with-f2c
    elif test "$with_f2c" = yes; then
      AC_CHECK_PROG(F2C,f2c,yes,no)
      if test "$F2C" = no; then
        AC_MSG_ERROR([Unable to configure: f2c compiler not found])
      fi
      # script shell f77 have bugs, get ours
      FC='${SCIDIR}/bin/f77-linux'
    else
      # first find g77
      AC_CHECK_PROG(WITH_G77,g77,yes,no)
      if test "$WITH_G77" = yes; then
        FC=g77
      else
      # otherwise find f2c
        AC_CHECK_PROG(F2C,f2c,yes,no)
        if test "$F2C" = yes; then
          # script shell f77 have bugs, get ours
          FC='${SCIDIR}/bin/f77-linux'
        else
          AC_MSG_ERROR([Unable to configure: no Fortran compiler found])    
        fi
      fi
    fi
    FC_OPTIONS=-O
    FC_OPTIONS_O0=
    FC_LDFLAGS=$LIEEELIB
    LD=ld
    LD_LDFLAGS=$LIEEELIB
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -Dlinux -fwritable-strings'
      FC_OPTIONS=-g
    fi
    DLDLIB='${SCIDIR}/libs/libdld.a'
    DLD_SUBDIR=dld
    MAKEFILE_TARGET=Makefile.linux
   ;;
   
# Linux gnu: x86_64 distributions added by cdh 2004-09-29 ( modified 2006-06-01 to find gfortran if needed )
x86_64-*-linux-gnu)
	LIEEELIB=
	AC_CHECK_LIB(ieee,main,
	[LIEEELIB=-lieee])

	MALLOC=malloc.o

	if test "$with_intelcompilers" = yes; then
		GCC=no
		CC=$ICC
		FC=$IFC
		CC_OPTIONS='-O -DNDEBUG -Dlinux -DNARROWPROTO -mp'
		CC_PICFLAGS="-fPIC"
		# -cm remove comments displays, -w90  -w95 remove warnings abort f90 f95 non standard
		FC_OPTIONS="-O -cm -w90 -w95 -mp "
		FC_OPTIONS_O0="-cm  -w90 -w95 -mp "
		if test "$enable_debug" = yes; then
			CC_OPTIONS='-g -Wall -Dlinux  -DNARROWPROTO  -mp '
			FC_OPTIONS="-g -cm  -w90 -w95 -mp "
		fi
		CC_LDFLAGS="$LIEEELIB  -Wl,-relax"
		FC_LDFLAGS="$LIEEELIB -ldl  -lPEPCF90 -Wl,-relax "
		LD=xild
		LD_LDFLAGS="$LIEEELIB -lPEPCF90 -Wl,-relax "
	else
		GCC=yes
		CC=gcc
		# CC_PLAT_OPTIONS is optional, and is used to add CPU specific code generation tuning for Athlon64 presumably Opteron could benefit too but these are not optimized for the Opteron
		CC_PLAT_OPTIONS='-march=athlon64 -mfpmath=sse -msse2 -m3dnow -m64'
		
		CC_PICFLAGS='-fPIC'
		FC_PICFLAGS='-fPIC'
		
		CC_OPTIONS="-O2 -DNDEBUG -Dlinux  -DNARROWPROTO $CC_PLAT_OPTIONS $CC_PICFLAGS "
		CC_LDFLAGS=$LIEEELIB

		if test "$enable_debug" = yes; then
			CC_OPTIONS="-g -Wall -Dlinux -DNARROWPROTO $CC_PLAT_OPTIONS $CC_PICFLAGS "
		fi
		# find Fortran compiler
		# g77 already asked and found: good
		if test "$WITH_G77" = yes; then
			FC=g77
			FC_PICFLAGS=-fPIC
			if test "$enable_debug" = yes; then
				FC_OPTIONS="-g $CC_PLAT_OPTIONS $FC_PICFLAGS"
				FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
			else
				FC_OPTIONS="-O $CC_PLAT_OPTIONS $FC_PICFLAGS"
				FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
			fi
		elif test "$WITH_GFORTRAN" = yes; then
			FC=gfortran
			if test "$enable_debug" = yes; then
				FC_OPTIONS="-g -ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
				FC_OPTIONS_O0="-ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
			else
				FC_OPTIONS="-O -ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
				FC_OPTIONS_O0="-ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
			fi
			AC_DEFINE(G95_FORTRAN)
		# option with-f2c
		elif test "$with_f2c" = yes; then
			AC_CHECK_PROG(F2C,f2c,yes,no)
			if test "$F2C" = no; then
				AC_MSG_ERROR([Unable to configure: f2c compiler not found])
			fi
			# script shell f77 have bugs, get ours
			FC='${SCIDIR}/bin/f77-linux'
			if test "$enable_debug" = yes; then
				FC_OPTIONS="-g $CC_PLAT_OPTIONS $FC_PICFLAGS"
				FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
			else
				FC_OPTIONS="-O $CC_PLAT_OPTIONS $FC_PICFLAGS"
				FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
			fi
		else
			# first find g77
			AC_CHECK_PROG(WITH_G77,g77,yes,no)
			if test "$WITH_G77" = yes; then
				FC=g77
				FC_PICFLAGS=-fPIC
				if test "$enable_debug" = yes; then
					FC_OPTIONS="-g $CC_PLAT_OPTIONS"
					FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
				else
					FC_OPTIONS="-O $CC_PLAT_OPTIONS"
					FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
				fi
			else
				AC_CHECK_PROG(WITH_GFORTRAN,gfortran,yes,no)
				if test "$WITH_GFORTRAN" = yes; then
					FC=gfortran
					FC_PICFLAGS=-fPIC
					AC_DEFINE(G95_FORTRAN)
					if test "$enable_debug" = yes; then
						FC_OPTIONS="-g -ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
						FC_OPTIONS_O0="-ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
					else
						FC_OPTIONS="-O -ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
						FC_OPTIONS_O0="-ff2c $CC_PLAT_OPTIONS $FC_PICFLAGS"
					fi
				else
					AC_CHECK_PROG(WITH_F95,f95,yes,no)
					if test "$WITH_F95" = yes; then
						FC=f95
						FC_PICFLAGS=-fPIC
						AC_DEFINE(F95_FORTRAN)
						if test "$enable_debug" = yes; then
							FC_OPTIONS="-g $CC_PLAT_OPTIONS $FC_PICFLAGS"
							FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
						else
							FC_OPTIONS="-O $CC_PLAT_OPTIONS $FC_PICFLAGS"
							FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS "
						fi
					else
						# otherwise find f2c
						AC_CHECK_PROG(F2C,f2c,yes,no)
						if test "$F2C" = yes; then
							# script shell f77 have bugs, get ours
							FC='${SCIDIR}/bin/f77-linux'
							if test "$enable_debug" = yes; then
								FC_OPTIONS="-g $CC_PLAT_OPTIONS $FC_PICFLAGS"
								FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
							else
								FC_OPTIONS="-O $CC_PLAT_OPTIONS $FC_PICFLAGS"
								FC_OPTIONS_O0="$CC_PLAT_OPTIONS $FC_PICFLAGS"
							fi
						else
							AC_MSG_ERROR([Unable to configure: no Fortran compiler found])    
						fi
					fi
				fi
			fi
		fi
		FC_LDFLAGS="$LIEEELIB -ldl -rdynamic -Wl,-relax "
		LD=ld
		LD_LDFLAGS="$LIEEELIB -Wl,-relax "
	fi
	MAKEFILE_TARGET=Makefile.linux64
	;;
# Linux gnu: ia64 distributions
  ia64-*-linux-gnu)
    LIEEELIB=
    AC_CHECK_LIB(ieee,main,
      [LIEEELIB=-lieee])
    MALLOC=malloc.o
    if test "$with_intelcompilers" = yes; then
       GCC=no
       CC=$ICC
       FC=$IFC
       CC_OPTIONS='-O -DNDEBUG -Dlinux -DNARROWPROTO -mp'
       CC_PICFLAGS="-fPIC"
# -cm remove comments displays, -w90  -w95 remove warnings abort f90 f95 non standard
       FC_OPTIONS="-O -cm -w90 -w95 -mp "
       FC_OPTIONS_O0="-cm  -w90 -w95 -mp "
       if test "$enable_debug" = yes; then 
         CC_OPTIONS='-g -Wall -Dlinux  -DNARROWPROTO  -mp '
         FC_OPTIONS="-g -cm  -w90 -w95 -mp "
       fi
       CC_LDFLAGS="$LIEEELIB  -Wl,-relax"
       FC_LDFLAGS="$LIEEELIB -ldl -Wl,-relax "
       LD=xild
       LD_LDFLAGS="$LIEEELIB  -Wl,-relax "
    else
       GCC=yes
       CC=gcc
       CC_OPTIONS='-O -DNDEBUG -Dlinux  -DNARROWPROTO'
       CC_LDFLAGS=$LIEEELIB
       CC_PICFLAGS=-fPIC
       # find Fortran compiler
       # g77 already asked and found: good
       if test "$WITH_G77" = yes; then
         FC=g77
         FC_PICFLAGS=-fPIC
       # option with-f2c
       elif test "$with_f2c" = yes; then
         AC_CHECK_PROG(F2C,f2c,yes,no)
         if test "$F2C" = no; then
           AC_MSG_ERROR([Unable to configure: f2c compiler not found])
         fi
         # script shell f77 have bugs, get ours
         FC='${SCIDIR}/bin/f77-linux'
       else
         # first find g77
         AC_CHECK_PROG(WITH_G77,g77,yes,no)
         if test "$WITH_G77" = yes; then
           FC=g77
           FC_PICFLAGS=-fPIC
         else
         # otherwise find f2c
           AC_CHECK_PROG(F2C,f2c,yes,no)
           if test "$F2C" = yes; then
             # script shell f77 have bugs, get ours
             FC='${SCIDIR}/bin/f77-linux'
           else
             AC_MSG_ERROR([Unable to configure: no Fortran compiler found])    
           fi
         fi
       fi
       FC_OPTIONS=-O
       FC_OPTIONS_O0=
       FC_LDFLAGS="$LIEEELIB -ldl -rdynamic -Wl,-relax"
       LD=ld
       LD_LDFLAGS=$LIEEELIB  -Wl,-relax
       if test "$enable_debug" = yes; then 
         CC_OPTIONS='-g -Wall -Dlinux -DNARROWPROTO'
         FC_OPTIONS=-g
       fi
    fi
    MAKEFILE_TARGET=Makefile.linux
   ;;
# Alpha Linux
  alpha-*-linux-gnu)
    MALLOC=malloc.o
    GCC=yes
    CC=gcc
    CC_OPTIONS='-O -DNDEBUG -mieee-with-inexact -Dlinux -fwritable-strings'
    CC_LDFLAGS='-ldl -rdynamic -mieee-with-inexact'
    CC_PICFLAGS=-fPIC
    # find Fortran compiler
    # g77 already asked and found: good
    if test "$WITH_G77" = yes; then
      FC=g77
    # option with-f2c
    elif test "$with_f2c" = yes; then
      AC_CHECK_PROG(F2C,f2c,yes,no)
      if test "$F2C" = no; then
        AC_MSG_ERROR([Unable to configure: f2c compiler not found])
      fi
      # script shell f77 have bugs, get ours
      FC='${SCIDIR}/bin/f77-linux'
    else
      # first find g77
      AC_CHECK_PROG(WITH_G77,g77,yes,no)
      if test "$WITH_G77" = yes; then
        FC=g77
      else
      # otherwise find f2c
        AC_CHECK_PROG(F2C,f2c,yes,no)
        if test "$F2C" = yes; then
          # script shell f77 have bugs, get ours
          FC='${SCIDIR}/bin/f77-linux'
        else
          AC_MSG_ERROR([Unable to configure: no Fortran compiler found])    
        fi
      fi
    fi
    FC_OPTIONS='-O -mieee-with-inexact'
    FC_OPTIONS_O0='-mieee-with-inexact'
    FC_LDFLAGS='-ldl -rdynamic -mieee-with-inexact'
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -mieee-with-inexact -Dlinux -fwritable-strings'
      FC_OPTIONS='-g -mieee-with-inexact'
    fi
    MAKEFILE_TARGET=Makefile.linux
   ;;
# Mklinux PowerPC (Macintosh)
  powerpc-*-linux-gnu)
    LIEEELIB=
    AC_CHECK_LIB(ieee,main,
      [LIEEELIB=-lieee])
    GCC=yes
    CC=gcc
    CC_OPTIONS='-O -DNDEBUG -D_GNU_SOURCE -Dlinux'
    CC_LDFLAGS=$LIEEELIB
    CC_PICFLAGS=-fPIC
    # find Fortran compiler
    # g77 already asked and found: good
    if test "$WITH_G77" = yes; then
      FC=g77
    elif test "$WITH_GFORTRAN" = yes;then
      FC=gfortran
      FC_OPTIONS="-O -ff2c"
      FC_OPTIONS_O0="-ff2c"
      FC_PICFLAGS=-fPIC
      AC_DEFINE(G95_FORTRAN)
    # option with-f2c
    elif test "$with_f2c" = yes; then
      AC_CHECK_PROG(F2C,f2c,yes,no)
      if test "$F2C" = no; then
        AC_MSG_ERROR([Unable to configure: f2c compiler not found])
      fi
      # script shell f77 have bugs, get ours
      FC='${SCIDIR}/bin/f77-linux'
    else
      # first find g77
      AC_CHECK_PROG(WITH_G77,g77,yes,no)
      if test "$WITH_G77" = yes; then
        FC=g77
      else
      # otherwise find f2c
        AC_CHECK_PROG(F2C,f2c,yes,no)
        if test "$F2C" = yes; then
          # script shell f77 have bugs, get ours
          FC='${SCIDIR}/bin/f77-linux'
        else
          AC_MSG_ERROR([Unable to configure: no Fortran compiler found])    
        fi
      fi
    fi
    FC_OPTIONS=-O
    FC_OPTIONS_O0=
    FC_LDFLAGS="$LIEEELIB -ldl -rdynamic"
    FC_PICFLAGS=-fPIC
    LD=ld
    LD_LDFLAGS=$LIEEELIB
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -Dlinux -D_GNU_SOURCE'
      FC_OPTIONS=-g
    fi
    MAKEFILE_TARGET=Makefile.linux
   ;;

# Linux ELF: all standard distributions (catch all other)
i*86-*-linux-gnu | *-linux-gnu )
	LIEEELIB=
	AC_CHECK_LIB(ieee,main,[LIEEELIB=-lieee])

	if test "$with_intelcompilers" = yes; then
		GCC=no
		CC=$ICC
		FC=$IFC
		CC_OPTIONS='-O -DNDEBUG -Dlinux -DNARROWPROTO -mp -pc64 -ffnalias -falias '
		CC_PICFLAGS="-fPIC"
		# -cm remove comments displays, -w90  -w95 remove warnings abort f90 f95 non standard
		FC_OPTIONS="-O -cm -w90 -w95 -mp -pc64 -ffnalias -falias"
		FC_OPTIONS_O0="-cm  -w90 -w95 -mp -pc64 -ffnalias -falias"
		if test "$enable_debug" = yes; then 
			CC_OPTIONS='-g -Wall -Dlinux  -DNARROWPROTO  -mp -pc64 -ffnalias -falias'
			FC_OPTIONS="-g -cm  -w90 -w95 -mp -pc64 -ffnalias -falias"
		fi
		CC_LDFLAGS=$LIEEELIB
		FC_LDFLAGS="$LIEEELIB -ldl"
		LD=xild
		LD_LDFLAGS="$LIEEELIB"
	else
		GCC=yes
		GCCFIX=fix.o
		CC=gcc
		if test "$enable_debug" = yes; then
			CC_OPTIONS='-g -Wall -Dlinux  -DNARROWPROTO'
		else
			CC_OPTIONS='-O -DNDEBUG -Dlinux  -DNARROWPROTO'
		fi
		CC_LDFLAGS=$LIEEELIB
		CC_PICFLAGS=-fPIC
		# find Fortran compiler
		# g77 already asked and found: good
		if test "$WITH_G77" = yes; then
			FC=g77
			FC_PICFLAGS=-fPIC
			if test "$enable_debug" = yes; then
				FC_OPTIONS="-g"
				FC_OPTIONS_O0=""
			else
				FC_OPTIONS="-O"
				FC_OPTIONS_O0=""
			fi
		elif test "$WITH_GFORTRAN" = yes;then
			FC=gfortran
			if test "$enable_debug" = yes; then
				FC_OPTIONS="-g -ff2c"
				FC_OPTIONS_O0="-ff2c"
			else
				FC_OPTIONS="-O -ff2c"
				FC_OPTIONS_O0="-ff2c"
			fi
			FC_PICFLAGS=-fPIC
			AC_DEFINE(G95_FORTRAN)
		# option with-f2c
		elif test "$with_f2c" = yes; then
			AC_CHECK_PROG(F2C,f2c,yes,no)
			if test "$F2C" = no; then
				AC_MSG_ERROR([Unable to configure: f2c compiler not found])
			fi
			# script shell f77 have bugs, get ours
			FC='${SCIDIR}/bin/f77-linux'
			if test "$enable_debug" = yes; then
				FC_OPTIONS="-g"
				FC_OPTIONS_O0=""
			else
				FC_OPTIONS="-O"
				FC_OPTIONS_O0=""
			fi
		else
			# first find g77
			AC_CHECK_PROG(WITH_G77,g77,yes,no)
			if test "$WITH_G77" = yes; then
				FC=g77
				FC_PICFLAGS=-fPIC
				if test "$enable_debug" = yes; then
					FC_OPTIONS="-g"
					FC_OPTIONS_O0=""
				else
					FC_OPTIONS="-O"
					FC_OPTIONS_O0=""
				fi
			else
				AC_CHECK_PROG(WITH_GFORTRAN,gfortran,yes,no)
				if test "$WITH_GFORTRAN" = yes; then
					FC=gfortran
					FC_PICFLAGS=-fPIC
					AC_DEFINE(G95_FORTRAN)
					if test "$enable_debug" = yes; then
						FC_OPTIONS="-g -ff2c"
						FC_OPTIONS_O0="-ff2c"
					else
						FC_OPTIONS="-O -ff2c"
						FC_OPTIONS_O0="-ff2c"
					fi
				else
					AC_CHECK_PROG(WITH_F95,f95,yes,no)
					if test "$WITH_F95" = yes; then
						FC=f95
						FC_PICFLAGS=-fPIC
						AC_DEFINE(F95_FORTRAN)
						if test "$enable_debug" = yes; then
							FC_OPTIONS="-g"
							FC_OPTIONS_O0=""
						else
							FC_OPTIONS="-O"
							FC_OPTIONS_O0=""
						fi
					else
						# otherwise find f2c
						AC_CHECK_PROG(F2C,f2c,yes,no)
						if test "$F2C" = yes; then
							# script shell f77 have bugs, get ours
							FC='${SCIDIR}/bin/f77-linux'
							if test "$enable_debug" = yes; then
								FC_OPTIONS="-g"
								FC_OPTIONS_O0=""
							else
								FC_OPTIONS="-O"
								FC_OPTIONS_O0=""
							fi
						else
							AC_MSG_ERROR([Unable to configure: no Fortran compiler found])    
						fi
					fi
				fi
			fi
		fi
		FC_LDFLAGS="$LIEEELIB -ldl -rdynamic"
		LD=ld
		LD_LDFLAGS=$LIEEELIB
	fi
	MAKEFILE_TARGET=Makefile.linux
	;;
# SGI MIPS ULTRIX (NO LONGER SUPPORTED)
  mips-*-ultrix*)
    # standard compilers
    CC=cc
    CC_OPTIONS=-O0 -DNDEBUG
    CC_LDFLAGS=
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,f77,yes,no)
      AC_CHECK_PROGS(F77,f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran f77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    FC_OPTIONS='-O0 -fpe1'
    FC_OPTIONS_O0='-O0 -fpe1'
    FC_LDFLAGS=
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS=-g
      FC_OPTIONS='-g -fpe1'
    fi
    SCILAB_GS=sh5
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi
    MAKEFILE_TARGET=Makefile.ultrix
    ;;
# SGI
  mips-sgi-irix*)
    # standard compilers
    CC=cc
    CC_OPTIONS='-O -DNDEBUG -DSYSV -DSVR4'
    CC_LDFLAGS=
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,f77,yes,no)
      AC_CHECK_PROGS(F77,f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran f77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    FC_OPTIONS='-O '
    FC_OPTIONS_O0=

    FC_LDFLAGS=
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -c -DSYSV -DSVR4'
      FC_OPTIONS='-g '
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi

    MAKEFILE_TARGET=Makefile.sgi
    ;;
# OLD HP (NO LONGER SUPPORTED)
  *-*-hpux9.*)
    # standard compilers
    HPPA_OLD=-Dhppa_old
    CC=cc
    CC_OPTIONS='-O -DNDEBUG -DSYSV -Dhpux'
    CC_LDFLAGS='-Wl,-a,archive'
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,fort77,yes,no)
      AC_CHECK_PROGS(F77,fort77 f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran fort77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    FC_OPTIONS='-O +Obb1200 +E4'
    FC_OPTIONS_O0='+Obb1200 +E4'
    FC_LDFLAGS='-Wl,-a,archive'
    LD=ld
    LD_LDFLAGS='-a archive'
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -DSYSV -Dhpux'
      FC_OPTIONS='-g +E4'
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi
    MAKEFILE_TARGET=Makefile.hpux9
    FGETARG=fgetarg-hpux
    ;;
# HP 10
  *-*-hpux10.*)
    # standard compilers
    CC=cc
    CC_OPTIONS='-O -DNDEBUG -DSYSV -Dhpux +Z +DAportable'
    CC_LDFLAGS='-Wl,+vnocompatwarnings,-E /usr/lib/libdld.sl'
    if test "$WITH_G77" != yes; then    
      #AC_CHECK_PROG(F77,fort77,yes,no)
      AC_CHECK_PROGS(F77,fort77 f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran fort77 compiler not found])
      fi
      FC="$F77"
    fi
    #FC="$F77"
    AC_F77_LIBRARY_LDFLAGS
    FC_OPTIONS='+O2 +E4 +Z +DAportable'
    FC_OPTIONS_O0='+E4 +Z +DAportable'
    FC_LDFLAGS='-Wl,+vnocompatwarnings,-E /usr/lib/libdld.sl'
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -DSYSV -Dhpux'
      FC_OPTIONS='-g +E4'
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi
    MAKEFILE_TARGET=Makefile.hpux
    FGETARG=fgetarg-hpux
    ;;
# HP 11
  *-*-hpux11.*)
    SONAME=sl
    # standard compilers
    CC=cc
    CC_OPTIONS='-O -DNDEBUG -DSYSV -Dhpux -Dhppa +Z +DAportable'
    CC_LDFLAGS='-Wl,+vnocompatwarnings,-E /usr/lib/libdld.sl'
    if test "$WITH_G77" != yes; then    
      AC_CHECK_PROGS(F77,fort77 f77 f90 f2c-f77,no)
      if test "$F77" = no; then
        AC_MSG_ERROR([Unable to configure: Fortran fort77 compiler not found])
      fi
      FC="$F77"
    fi
    FC_OPTIONS='+O2 +Z +DAportable'
    FC_OPTIONS_O0=' +Z +DAportable'
    #do not call AC_F77_LIBRARY_LDFLAGS because if assumes PA2.0 while Scilab is built with 
    #DAportable=PA1.1
    #AC_F77_LIBRARY_LDFLAGS
    FLIBS='-ldld -lnsl -lU77 -lm'

    FC_LDFLAGS='-Wl,+vnocompatwarnings,-E /usr/lib/libdld.sl'
    LD=ld
    LD_LDFLAGS=
    if test "$enable_debug" = yes; then 
      CC_OPTIONS='-g -DSYSV -Dhpuxx -Dhppa +Z +DAportable'
      FC_OPTIONS='-g  +Z +DAportable'
      FC_OPTIONS_O0='-g +Z +DAportable'
    fi
    # GNU compilers
    if test "$WITH_GCC" = yes; then
      CC=gcc
      CC_OPTIONS=-O -DNDEBUG
      if test "$enable_debug" = yes; then 
        CC_OPTIONS=-g
      fi
    fi
    if test "$WITH_G77" = yes; then
      FC=g77
      FC_OPTIONS=-O
      FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS=-g
      fi
    fi
    MAKEFILE_TARGET=Makefile.hpux11
    GETARG=getarg-hpux
    FGETARG=fgetarg-hpux
    cp -f $SCIDIR/pvm3/conf/HPPA.def $SCIDIR/pvm3/conf/HPPA.def.orig
    cp -f $SCIDIR/pvm3/conf/HPPA11.def $SCIDIR/pvm3/conf/HPPA.def
    ;;

# CYGWIN32 for Windows 9X/NT/XP 
  *-*-cygwin* )
    SCILABSCRIPT=scilab-gcwin32.g
    PERIFILE=periWin.o
    MAIN='mainsci.o'
    GUILIB='wsci'
    XDRLIB='xdr'
    XDRLIBNAME='libs/xdr.a'
    MENUSOBJS=WOBJS
    BLPR_SCRIPTS=
    # with cygwin we keep /cygdrive/ SED_CYGDRIVE='$(CYGDRIVE)'
    IMPPREF=B
    IMPENV=env.o
    # want to build f2c comand 
    # which is required for building fortran dlls 
    # which can be loaded into scilab 
    F2C_SUBDIR=f2c/src
    # just *-so tests 
    EXAMPLES_TESTS='$(SUBDIRS1)'
    GCC=yes
    CC=gcc 
    CC_OPTIONS=' -mieee-fp -O2 -DNDEBUG  -Wall'
      if test "$enable_debug" = yes; then 
	CC_OPTIONS=' -g   -Wall'
      fi
    CC_LDFLAGS=
    WITH_G77='yes'
    FC=g77
    if test "$WITH_G77" = yes; then
      FC=g77
    fi 
    FC_OPTIONS="-O2 "
    FC_OPTIONS_O0=
      if test "$enable_debug" = yes; then 
        FC_OPTIONS="-g "
      fi
    FC_LDFLAGS=
    if test "$with_f2c" = yes; then
      # ignore with_f2c here       
      FC=g77
    fi    
    LD=gcc
    #LD_LDFLAGS="-mconsole --enable-stdcall-fixup"
    WINXFLAGS='-I../xdr'
    MAKEFILE_TARGET=Makefile.gcwin32
    ;;
# CYGWIN32 for Windows 9X/NT/XP 
# mingw32 is detected 
   *-*-mingw32*)
    SCILABSCRIPT=scilab-gcwin32.g
    PERIFILE=periWin.o
    MAIN='mainwin95.o'
    GUILIB='wsci'
    XDRLIB='xdr'
    XDRLIBNAME='libs/xdr.a'
    MENUSOBJS=WOBJS
    BLPR_SCRIPTS=
    SED_CYGDRIVE='$(CYGDRIVE)'
    IMPPREF=B
    IMPENV=env.o
    # want to build f2c comand 
    # which is required for building fortran dlls 
    # which can be loaded into scilab 
    F2C_SUBDIR=f2c/src
    # just *-so tests 
    EXAMPLES_TESTS='$(SUBDIRS1)'
    GCC=yes
    CC=gcc 
    CC_OPTIONS='-mno-cygwin -mieee-fp -O -DNDEBUG -fwritable-strings  -Wall'
      if test "$enable_debug" = yes; then 
	CC_OPTIONS='-mno-cygwin -g -fwritable-strings  -Wall'
      fi
    CC_LDFLAGS=
    FC=g77
    if test "$WITH_G77" = yes; then
      FC=g77
    fi 
    FC_OPTIONS="-O -mno-cygwin"
    FC_OPTIONS_O0="-mno-cygwin"
      if test "$enable_debug" = yes; then 
        FC_OPTIONS="-g -mno-cygwin"
      fi
    FC_LDFLAGS=
    if test "$with_f2c" = yes; then
      # ignore with_f2c here       
      FC=g77
    fi    
    LD=gcc
    LD_LDFLAGS="-mconsole --enable-stdcall-fixup"
    WINXFLAGS='-I../xdr'
    MAKEFILE_TARGET=Makefile.mingwin32
    ;;
# FreeBSD  systems (not supported by INRIA)
  *-*-freebsd*)
     GCC=yes
     CC=$CC
     CC_OPTIONS="${CFLAGS} -Dfreebsd"
     CC_LDFLAGS=-lm
     CC_PICFLAGS='-fPIC'
     # script shell f77 have bugs, get ours
     FC=$F77
     FC_OPTIONS="${CFLAGS} -Dfreebsd"	
     FC_OPTIONS_O0='-Dfreebsd'
     FC_LDFLAGS='-lm -Wl,--export-dynamic'
     FC_PICFLAGS='-fPIC'
     LD=ld
     LD_LDFLAGS=-lm

     if test "$enable_debug" = yes; then 
       CC_OPTIONS='-g -Dfreebsd'
       FC_OPTIONS=-g
     fi
     if test "$WITH_G77" = yes; then
       # On FreeBSD the gnu fortran compiler is named f77
       FC=f77
     fi
    DLDLIB='${SCIDIR}/libs/libdld.a'
    DLD_SUBDIR=dld
    MAKEFILE_TARGET=Makefile.freebsd
    ;;

# NetBSD  systems (not supported by INRIA)
  *-*-netbsd*)
    #
    # C Compiler
    #
    AC_PROG_CC
    CC_OPTIONS="${CFLAGS} -Dnetbsd"
    CC_LDFLAGS="${LDFLAGS} -Wl,-R${X11BASE}/lib"
    CC_PICFLAGS='-fPIC'
    # check for --export-dynamic
    ac_save_LDFLAGS="$LDFLAGS"
    LDFLAGS='-Wl,--export-dynamic'
    AC_MSG_CHECKING([if the linker accepts --export-dynamic])
    AC_TRY_LINK(,,
      AC_MSG_RESULT(yes)
      CC_LDFLAGS=["$CC_LDFLAGS  -Wl,--export-dynamic"],
      AC_MSG_RESULT(no))
    LDFLAGS="$ac_save_LDFLAGS"
   #
   # Fortran Compiler
   #

   AC_PROG_F77
   AC_F77_LIBRARY_LDFLAGS
   FC="$F77"
   FC_OPTIONS="${FFLAGS}"
   FC_OPTIONS_O0=`echo $FC_OPTIONS | sed 's/-O[0-9]*//g'`
   FC_LDFLAGS="${LDLAGS} -Wl,-R${X11BASE}/lib"
   FC_PICFLAGS='-fPIC'
   # check for --export-dynamic
   ac_save_LDFLAGS="$LDFLAGS"
   LDFLAGS='-Wl,--export-dynamic'
   AC_MSG_CHECKING([if the linker accepts --export-dynamic])
   AC_TRY_LINK(,,
     AC_MSG_RESULT(yes)
     FC_LDFLAGS=["$FC_LDFLAGS  -Wl,--export-dynamic"],
     AC_MSG_RESULT(no))
   LDFLAGS="$ac_save_LDFLAGS"
   #
   # Linker
   #
   LD=ld
   LD_LDFLAGS="-R${X11BASE}/lib"
   # check for --export-dynamic
   ac_save_LDFLAGS="$LDFLAGS"
   LDFLAGS='-Wl,--export-dynamic'
   AC_MSG_CHECKING([if the linker accepts --export-dynamic])
   AC_TRY_LINK(,,
     AC_MSG_RESULT(yes)
     LD_LDFLAGS=["$LD_LDFLAGS  --export-dynamic"],
     AC_MSG_RESULT(no))
   LDFLAGS="$ac_save_LDFLAGS" 

   MAKEFILE_TARGET=Makefile.netbsd
   ;;
# Darwin/MacOSX (Not supported by INRIA)
  *-*-darwin*)
     STRIP=echo 
     PERIX11NOPT=periX11
     GCC=yes
     CC=gcc
     CC_OPTIONS='-no-cpp-precomp -O2 -DNDEBUG -I/sw/include -L/sw/lib'
     CC_LDFLAGS='-L/sw/lib'
     CC_PICFLAGS='-fPIC'
     # script shell f77 have bugs, get ours
     FC=g77
     FC_OPTIONS='-O2'
     FC_OPTIONS_O0=
     FC_LDFLAGS='-L/sw/lib -ldl -lcc_dynamic'
     FC_PICFLAGS='-fPIC'
     LD=ld
     LD_LDFLAGS=
     if test "$enable_debug" = yes; then
       CC_OPTIONS='-g -I/sw/include '
       FC_OPTIONS=-g
     fi
     if test "$WITH_G77" = yes; then
       FC=g77
     fi
    # just *-so tests 
    EXAMPLES_TESTS='$(SUBDIRS1)'
    # FLIBS generated by libtool config should not be used 
    FLIBS= 
   # Dyn. loading - ????
   # DLDLIB=
   # DLD_SUBDIR=
   # DLDLIB=
   # DLD_SUBDIR=
   MAKEFILE_TARGET=Makefile.darwin
   # we need to patch libtool 		
   cp  libtool libtool-cp
   sed -e 's:\\\\"x\\\$module\\\\" = xyes:\\$module = .yes:' libtool-cp > libtool
   rm -f libtool-cp
    ;;
  *)
    AC_MSG_ERROR([Unable to configure for host $host])
    ;;
esac


# due to g77 Fortran compiler bugs, a few files must not be compiled
# with optimizer:
# in "routines/control": hqror2.f comqr3.f tql2.f imtql3.f dsvdc.f wsvdc.f 
#                        pade.f
# in "routines/sparse": intreadmps.f
# in "routines/calelm": unsfdcopy.f icopy.f

FC_OPTIONS1=$FC_OPTIONS
if test "$WITH_G77" = yes; then
  if test "$enable_debug" = yes; then   
    FC_OPTIONS1=$FC_OPTIONS
  else
    FC_OPTIONS1=$FC_OPTIONS_O0
  fi
fi

if test "$with_f2c" = yes; then
  if test "$enable_debug" = yes; then   
    FC_OPTIONS1=$FC_OPTIONS
  else
    FC_OPTIONS1=$FC_OPTIONS_O0
  fi
fi

if test "$WITH_GFORTRAN" = yes; then
  if test "$enable_debug" = yes; then   
    FC_OPTIONS1=$FC_OPTIONS
  else
    FC_OPTIONS1=$FC_OPTIONS_O0
  fi
fi

# due overlapping arguments a few files must not be compiled
# with optimizer on some computers (Sun sparc solaris with at least
# Sun C 5.5 getsym.f)

FC_OPTIONS2=$FC_OPTIONS

case "$host" in
# Sun solaris
  *solaris*)
    if test "$enable_debug" = yes; then
      FC_OPTIONS2=$FC_OPTIONS
    else
      FC_OPTIONS2=$FC_OPTIONS_O0
    fi
    ;;
esac


# due to a gcc bug, a few C functions must not be inlined when compiled
# with optimizer: the "floor" function in "routines/graphics/Format.c"

NOINLINE=
if test "$WITH_GCC" = yes; then
  NOINLINE='-D__NO_MATH_INLINES'
fi

# flag for possible compilations in configure
CFLAGS=$CC_OPTIONS
LDFLAGS=$CC_LDFLAGS

############################
## test for various programs
############################
# Using `AC_PROG_RANLIB' is rendered obsolete by `AC_PROG_LIBTOOL'
#AC_PROG_RANLIB

####################
## test for X Window
####################

if test "$PERIFILE" = periX11.o; then 
   AC_PATH_XTRA
   # fixing a bug for SunOs
   if test "$X_LIBS" = ' -L/usr/lib'; then
     X_LIBS=
   fi
   if test "$no_x" = yes; then
      AC_MSG_ERROR([X Window not found])
   fi
fi 

###################
## find X11 release
###################

if test "$PERIFILE" = periX11.o; then 
AC_CACHE_CHECK([for X11 release],ac_cv_X11_release,
[
cat << EOF > testX11.c
#include <X11/Xlib.h>
main()
{
#ifdef XlibSpecificationRelease
  if (XlibSpecificationRelease == 5)
    printf("R5\n");
  else if (XlibSpecificationRelease == 6)
    printf("R6\n");
  else
    printf("R?\n");
#else
  printf("R4\n");
#endif
}
EOF
eval "$CC $X_CFLAGS -o testX11 testX11.c > /dev/null 2>&1"
ac_cv_X11_release=`./testX11`
$RM testX11.c testX11
])
if test "$ac_cv_X11_release" = R4; then
    AC_MSG_ERROR([Scilab cannot be installed with X11R4.])
fi

fi

##########################################
## test for X11 and Xaw3d  Athena widgets
##########################################

# do not want to check for X11 when using gtk or gtk2
if test "$with_gtk" = yes; then	
   PERIFILE=periGtk.o  
fi 

if test "$with_gtk2" = yes; then	
   PERIFILE=periGtk.o  
fi 

if test "$PERIFILE" = periX11.o; then 
  ac_save_LDFLAGS="$LDFLAGS"
  if test -n "$x_libraries"; then
    LDFLAGS="$LDFLAGS -L$x_libraries"
  fi

##test Xaw3d (can be build locally)
  if test "$with_local_xaw" = yes; then
    XAWLIB='$(SCIDIR)/libs/libXaw3d.a'
    XMULIB='$(SCIDIR)/libs/libXmu.a'
    XAW_LOCAL_LIB='$(SCIDIR)/libs/libXaw3d.a $(SCIDIR)/libs/libXmu.a'
    XAW_LOCAL_INCLUDES='-I$(SCIDIR)/routines'
    XAW_LOCAL_SUBDIR=X11
    XAW=Xaw3d
  else
##test Xmu (Required)
    AC_CHECK_LIB(Xmu,main,[XMu=yes],[XMu=no],-lXt -lXext $X_PRE_LIBS -lX11 $X_EXTRA_LIBS)
    if test "$XMu" = no; then
      XAWLIB='$(SCIDIR)/libs/libXaw3d.a'
      XMULIB='$(SCIDIR)/libs/libXmu.a'
      XAW_LOCAL_LIB='$(SCIDIR)/libs/libXaw3d.a $(SCIDIR)/libs/libXmu.a'
      XAW_LOCAL_INCLUDES='-I$(SCIDIR)/routines'
      XAW_LOCAL_SUBDIR=X11
      XAW=Xaw3d
    else
      XMULIB=-lXmu
      AC_CHECK_LIB(Xaw3d,main,[XAthena3d=yes],[XAthena3d=no],-lXmu -lXt -lXext $X_PRE_LIBS -lX11 $X_EXTRA_LIBS)
      if test "$XAthena3d" = no; then
        XAWLIB='$(SCIDIR)/libs/libXaw3d.a'
        XMULIB='$(SCIDIR)/libs/libXmu.a'
        XAW_LOCAL_LIB='$(SCIDIR)/libs/libXaw3d.a $(SCIDIR)/libs/libXmu.a'
        XAW_LOCAL_INCLUDES='-I$(SCIDIR)/routines'
        XAW_LOCAL_SUBDIR=X11
        XAW=Xaw3d
      else
        XAWLIB=-lXaw3d
        XAW=Xaw3d
        LDFLAGS="$ac_save_LDFLAGS"
        save_cflags=$CFLAGS
        CFLAGS="$X_CFLAGS $CC_OPTIONS"
        AC_TRY_COMPILE([#include <X11/IntrinsicP.h> #include <X11/Xaw3d/ViewportP.h>],,,
        AC_MSG_ERROR([Include file "ViewportP.h" for Xaw3d not found. 
			       Get and put it in <X11/Xaw3d/> .]))
	CFLAGS=$save_cflags

      fi
    fi
  fi 
fi

#######################
## Xt 
#######################

# Pb of automatic insertion of -lXt -lXext -lX11 in Makefile.incl.in
# which does not work with mingwin. Thus I add this two vars to 
# configure.in 

XXTXEXT="-lXt -lXext"
XX11="-lX11"

  case "$host" in
      *-*-mingw32*)
      XXTXEXT=
      XX11=
    ;;
  esac
  
###########################
## test for JAVA compiler
###########################

JAVASCITARGET=javasci_disabled
JAVASCITARGET_DISTCLEAN=javasci_disabled

if test "$with_java" != no; then
	AC_CHECK_PROG(WITH_JAVAC,javac,yes,no)
	if test "$WITH_JAVAC" = yes; then
		JAVASCITARGET=scilex-lib
		JAVASCITARGET_DISTCLEAN=distclean
		JAVAC=javac
		JAVA_INCL=
		AC_JNI_INCLUDE_DIR
		for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS
		do
			JAVA_INCL="$JAVA_INCL -I$JNI_INCLUDE_DIR"
		done
	else
		AC_MSG_WARN([javac not found: I will not build the java interface])
		JAVASCITARGET=javasci_disabled
		JAVASCITARGET_DISTCLEAN=javasci_disabled
	fi
fi

#######################
## test for underscores
#######################

AC_MSG_CHECKING([for leading and/or trailing underscores])
cat << EOF > pipof.f
       subroutine pipof
       end
EOF

dnl expand possible $SCIDIR in $FC (wizard command...)
eval "FC1=\"$FC\""
eval "$FC1 -c pipof.f > /dev/null 2>&1"

FC_LEADING_UNDERSCORE=no
FC_TRAILING_UNDERSCORE=no

output=`nm $NMOPT pipof.o|grep _pipof 2>&1`
if test ! -z "$output"; then
  FC_LEADING_UNDERSCORE=yes
  FC_TRAILING_UNDERSCORE=no
fi

output=`nm $NMOPT pipof.o|grep pipof_ 2>&1`
if test ! -z "$output"; then
  FC_LEADING_UNDERSCORE=no
  FC_TRAILING_UNDERSCORE=yes
fi

output=`nm $NMOPT pipof.o|grep _pipof_ 2>&1`
if test ! -z "$output"; then
  FC_LEADING_UNDERSCORE=yes
  FC_TRAILING_UNDERSCORE=yes
fi

if test "$FC_LEADING_UNDERSCORE" = yes; then
  AC_DEFINE(WLU)
fi
if test "$FC_TRAILING_UNDERSCORE" = yes; then
  AC_DEFINE(WTU)
fi

$RM pipof.f pipof.o

AC_MSG_RESULT([$FC_LEADING_UNDERSCORE $FC_TRAILING_UNDERSCORE])

#####################
## test for sharpsign
#####################

AC_MSG_CHECKING([for use of sharpsign in CPP])
AC_TRY_COMPILE([#define C2F(name) name##_],
  [C2F(toto)()],  
  AC_MSG_RESULT(yes)
  AC_DEFINE(USE_SHARP_SIGN),
  AC_MSG_RESULT(no))

##############################################################
## test for functions in standard C library and C math library
##############################################################

AC_CHECK_LIB(m,main)
AC_CHECK_FUNCS(exp10)
AC_CHECK_FUNCS(getwd)
AC_CHECK_FUNCS(sleep)
AC_CHECK_FUNCS(strerror)
AC_CHECK_FUNCS(usleep)
AC_CHECK_FUNCS(finite)

########################
## test for header files
########################

AC_CHECK_HEADERS(limits.h values.h) 

##################
## termcap library
##################

TERMCAPLIB=no
AC_CHECK_LIB(ncurses,main,
  [TERMCAPLIB=-lncurses])
if test "$TERMCAPLIB" = no; then
  AC_CHECK_LIB(curses,main,
  [TERMCAPLIB=-lcurses])
fi
if test "$TERMCAPLIB" = no; then
  AC_CHECK_LIB(termcap,main,
  [TERMCAPLIB=-ltermcap])
fi
if test "$TERMCAPLIB" = no; then
  AC_CHECK_LIB(termlib,main,
  [TERMCAPLIB=-ltermlib])
fi
if test "$TERMCAPLIB" != no; then
  AC_DEFINE(HAVE_TERMCAP)
else
  TERMCAPLIB=
fi

#################
## PVM
#################

PVMTARGET=pvm_disabled
PVMTARGET_DISTCLEAN=pvm_disabled

PVMARCH=
PVMLIB=
PVMGLIB=
PVMSCIDIR=
PVMSCILIB=
PVMROOT=
PVMHELP=
# need an non empty default value for scilab script 
PVMROOTR='$SCI/pvm3'
PVMINST=
PVMINST1=

# files to be added for building the hoster with mingw 
PVMHOSTERFILES= 
# compile hoster ? 
PVMHOSTER=

if test "$with_pvm" != no; then

	# check for a locally installed PVM
	
	PVMHELP=pvm
	
	if test -x $PVM_ROOT/lib/pvmgetarch ; then
		PVMROOT=$PVM_ROOT
		PVMROOTR=$PVM_ROOT
		PVMTARGET=pvm_disabled
		PVMTARGET_DISTCLEAN=pvm_disabled
	else
		PVMTARGET=scilex-lib
		PVMTARGET_DISTCLEAN=distclean
		PVMROOT="$SCIDIR/pvm3"
		PVMROOTR='$SCI/pvm3'
		PVMINST='$(PVMBINDISTFILES) $(PVMBINDISTFILES1)'
		PVMINST1='$(INSTPVMBINDISTFILES) $(INSTPVMBINDISTFILES1)'
	fi
	
	PVMINCLUDE=$PVMROOT/include
	
	AC_ARG_WITH(pvm-include,
		[  --with-pvm-include=DIR  PVM include files are in DIR ],
		[  PVMINCLUDE=$withval
	])
	
	AC_CACHE_CHECK([for PVM architecture],ac_cv_PVM_arch,
	[
	ac_cv_PVM_arch=`$PVMROOT/lib/pvmgetarch`
	])

	if test "$ac_cv_PVM_arch" = UNKNOWN; then
		AC_MSG_WARN([PVM unable to find architecture: I will not use PVM])
		PVMTARGET=pvm_disabled
		PVMTARGET_DISTCLEAN=pvm_disabled
		PVMINST='$(PVMBINDISTFILES)'
		PVMINST1='$(INSTPVMBINDISTFILES)'
	else
		AC_DEFINE(WITH_PVM)
		PVMARCH="$ac_cv_PVM_arch"
		
		case "$host" in
		*-*-mingw32*)
			ac_cv_PVM_arch=MINGW
			PVMARCH="$ac_cv_PVM_arch"
			PVMHOSTERFILES="pvmwinrexec.o pvmwinrsh.o"
			PVMHOSTER=h
			;;
		esac
		
		PVMLIBDIR=$PVMROOT/lib/$ac_cv_PVM_arch
		AC_ARG_WITH(pvm-library,
			[  --with-pvm-library=DIR  PVM library files are in DIR ],
			[  PVMLIBDIR=$withval
		])
		
		PVMGLIB="$PVMLIBDIR/libgpvm3.a"
		PVMLIB="$PVMLIBDIR/libpvm3.a"
		PVMSCIDIR=pvm
		PVMSCILIB="\$(SCIDIR)/libs/pvm.a"
		
		case "$host" in
		*-*-mingw32*)
			# add src to PVMINCLUDE 
			PVMINCLUDE="$PVMINCLUDE -I$SCIDIR/pvm3/src"
			#     to have path with SCIDIR 
			# PVMROOT=`echo $PVMROOT | sed -e "s+$SCIDIR+\\$(SCIDIR)+g" `
			
			PVMLIB=`echo $PVMLIB | sed -e "s+$SCIDIR/pvm3+\\$(PVMROOT)+g" `
			PVMGLIB=`echo $PVMGLIB | sed -e "s+$SCIDIR/pvm3+\\$(PVMROOT)+g" `
			PVMINCLUDE=`echo $PVMINCLUDE | sed -e "s+$SCIDIR/pvm3+\\$(PVMROOT)+g" ` 
			;;
		esac
	fi
fi

#################
## Tcl/Tk library
#################

TK_INC_PATH=
TK_LIB_PATH=
TCLTK_LIBS=
TCLSCILIB=
TCLSCIDIR=
TCLTKHELP=

if test "$with_tk" != no; then

	TCLTKHELP=tksci

	# check user arguments
	USER_TCL_LIB_PATH=""
	USER_TCL_INC_PATH=""
	AC_ARG_WITH(tcl-library,
		[  --with-tcl-library=DIR  Tcl library files are in DIR ],
		[  USER_TCL_LIB_PATH=$withval
	])
	AC_ARG_WITH(tcl-include,
		[  --with-tcl-include=DIR  Tcl include files are in DIR ],
		[  USER_TCL_INC_PATH=$withval
	])
	
	USER_TK_LIB_PATH=$USER_TCL_LIB_PATH
	USER_TK_INC_PATH=$USER_TCL_INC_PATH
	
	AC_ARG_WITH(tk-library,
		[  --with-tk-library=DIR   Tk library files are in DIR ],
		[  USER_TK_LIB_PATH=$withval
	])
	
	AC_ARG_WITH(tk-include,
		[  --with-tk-include=DIR   Tk include files are in DIR ],
		[  USER_TK_INC_PATH=$withval
	])
	
	saved_cflags="$CFLAGS"
	saved_ldflags="$LDFLAGS"
	saved_cppflags="$CPPFLAGS"
	
	AC_CHECK_LIB(dl, main,TCLTK_LIBS=" -ldl")
	AC_CHECK_TCLTK()
	
	# set variables
	if test $WITH_TKSCI = 1; then
		AC_DEFINE(WITH_TK)
		TCLSCILIB="\$(SCIDIR)/libs/tclsci.a"
		TCLSCIDIR=tclsci
	else
		AC_MSG_ERROR([TCL/TK not found. Use --without-tk or specify the librairies and include paths manually])
	fi
	
	TKBASE=
	case "$host" in
	*-*-mingw32*)
		TKBASE=$SCIDIR
		TK_INC_PATH=`echo $TK_INC_PATH | sed -e "s+$SCIDIR+\\$(TKBASE)+g" `
		TCL_INC_PATH=`echo $TCL_INC_PATH | sed -e "s+$SCIDIR+\\$(TKBASE)+g" `
		TCLTK_LIBS=`echo $TCLTK_LIBS | sed -e "s+$SCIDIR+\\$(TKBASE)+g" `
	;;
	esac
	
	GETLIBTK=libtk$TK_MAJOR_VERSION.$TK_MINOR_VERSION.$SONAME
	
	case "$host" in
		*-*-darwin*)
		GETLIBTK=/sw/lib/libtk$TK_MAJOR_VERSION.$TK_MINOR_VERSION.dylib
		;;
		*-*-cygwin* |   *-*-mingw32*)
		GETLIBTK=tk$TK_MAJOR_VERSION$TK_MINOR_VERSION.dll
	esac 

fi

#################
## GTK
#################

ZZLEDT=
GTKPLUGBUG=

if test "$with_gtk" = yes; then
  AC_CHECK_PROG(GTK_CONFIG,gtk-config,yes,no)
  if test "$GTK_CONFIG" = no; then
    AC_MSG_WARN([gtk-config not found: I will not use -with-gtk])
    with_gtk="no"
  fi
  AC_CHECK_PROG(GNOME_CONFIG,gnome-config,yes,no)
  if test "$GNOME_CONFIG" = no; then
    AC_MSG_WARN([gnome-config not found: I will not use -with-gtk])
    with_gtk="no"
  fi
  if test "$with_gtk" = yes; then
    AC_MSG_CHECKING([if gtk is version 1.2 or later])
    GTK_VER=`gtk-config --version`
    case $GTK_VER in
      0.* )
        AC_MSG_ERROR([you need at least version 1.2 of gtk])
        ;;
      1.1* )
        AC_MSG_ERROR([you need at least version 1.2 of gtk])
        ;;
      * )
      # we have cheched above that gtk-config is in the 
      # path, then we don't want to generate a full path 
      # for gtk-config or to directly generate the 
      # result of `gtk-config --cflags`. Idem for gnome
      AC_MSG_RESULT([$GTK_VER])
      GTKCFLAGS='`gtk-config --cflags`'
      GTKLIBS='`gtk-config --libs` `gnome-config --libs  gtkxmhtml`'
      GNOMECFLAGS='`gnome-config --cflags gnome`'
      ;;
    esac    
    AC_DEFINE(WITH_GTK)
    GUILIB='gtksci'
    GZVT='gzvt'
    SCILABSCRIPT=scilab-gtk.g
    MENUSOBJS=GOBJS
    PERIFILE=periGtk.o
    # gtk 1 HTMLFLAGS=`gnome-config --cflags gnome`
    # gtk 2 HTMLFLAGS=`pkg-config libgtkhtml-2.0 --cflags`
    HTMLFLAGS='`gnome-config --cflags gnome`'
  fi
  # try to use readline with the gtk version 
  ac_save_LIBS="$LIBS"
  LIBS="$TERMCAPLIB  $LIBS"
  AC_CHECK_LIB(readline, rl_callback_read_char,[READLINE=-lreadline])
  LIBS=$ac_save_LIBS
  TERMCAPLIB="$READLINE $TERMCAPLIB"
  if test "no$READLINE" != no; then
     ZZLEDT="zzledt-rl.o"
     AC_DEFINE(WITH_READLINE)
  fi
  # we remove the X libs they were just used above during tcl/tk check 
  if test "$with_gtk" = yes; then
    XAWLIB=
    XMULIB=
    XAW_LOCAL_SUBDIR=
    XAW_LOCAL_LIB=
    X_CFLAGS=
    XAW_LOCAL_INCLUDES=
    X_EXTRA_LIBS=
    XXTXEXT=
    XX11=
    X_LIBS= 
    X_PRE_LIBS=
    if test "$TK_INC_PATH" = '-I/usr/include' ; then
        TK_INC_PATH=
    fi
    if test "$TCL_INC_PATH" = '-I/usr/include' ; then
        TCL_INC_PATH=
    fi
  fi
fi


#################
## GTK2 
#################

TERM_NAME=vte
TERM_LDFLAGS=VTE_LDFLAGS

if test "$with_gtk2" = yes; then
  AC_PATH_PROG(PKG_CONFIG,pkg-config)
  if test "x$PKG_CONFIG" = x; then
    # @*%&$ Ximian programmers renamed this application
    AC_PATH_PROG(PKG_CONFIG,pkgconfig,yes,no)
    if test "x$PKG_CONFIG" = x; then
    	AC_MSG_ERROR([Could not find the pkg-config (or pkgconfig) program.],)
	with_gtk2="no"
    fi
  fi
  #  AC_CHECK_PROG(GNOME_CONFIG,gnome-config,yes,no)
  #if test "$GNOME_CONFIG" = no; then
  #  AC_MSG_WARN([gnome-config not found: I will not use -with-gtk])
  #  with_gtk2="no"
  # fi
  if test "$with_gtk2" = yes; then
    AC_MSG_CHECKING([if gtk is version 2.1 or later])
    GTK_VER=`$PKG_CONFIG --modversion gtk+-2.0`
    case $GTK_VER in
      2.2.* | 2.3.0 | 2.3.1| 2.3.2| 2.3.4 )
        GTKPLUGBUG=gtkmenu.o
	;;
    esac    
    AC_MSG_RESULT([$GTK_VER])
    # we have cheched above that gtk-config is in the 
    # path, then we don't want to generate a full path 
    # for gtk-config or to directly generate the 
    # result of `gtk-config --cflags`. Idem for gnome
    GTKCFLAGS='`pkg-config gtk+-2.0 --cflags`'
    GTKLIBS='`pkg-config gtk+-2.0 libgtkhtml-2.0 --libs`'
    GNOMECFLAGS='`pkg-config gtk+-2.0 --cflags`'
    AC_DEFINE(WITH_GTK)
    GUILIB='gtksci'
    # GZVT='gzvt2' dose not work: gtk2 bug with plugged menus
    # gzvt2 works again with a gtk patch 
    GZVT='gzvt2'
    # we need a patched version 
    SCILABSCRIPT=scilab-gtk.g
    MENUSOBJS=GOBJS
    PERIFILE=periGtk.o
    # gtk 1 HTMLFLAGS=`gnome-config --cflags gnome`
    # gtk 2 HTMLFLAGS=`pkg-config libgtkhtml-2.0 --cflags`
    HTMLFLAGS='`pkg-config libgtkhtml-2.0 --cflags`'
    # check for libgtkhtml-2.0
    ac_save_LIBS="$LIBS"
    LIBS=`pkg-config libgtkhtml-2.0 --cflags --libs`
    GTKHTML=no
    AC_CHECK_LIB(gtkhtml-2,html_document_open_stream,[GTKHTML=yes])
    if test "$GTKHTML" = no; then
    	AC_MSG_ERROR([Could not find the libgtkhtml-2.0 package.],)
    fi
    LIBS=$ac_save_LIBS
    # check first for vte 
    ac_save_LIBS="$LIBS"
    LIBS=`pkg-config vte --cflags --libs` 
    VTE=no 
    AC_CHECK_LIB(vte,vte_terminal_new,[VTE=yes])
    if test "$VTE" = no; then
       AC_MSG_WARN([Could not find the vte library. I will try libzvt-2.0 ],)
       AC_MSG_WARN([you should install vte and vte-devel ],)
       # check for zzledt 
       LIBS=`pkg-config libzvt-2.0 --cflags --libs` 
       GZVT2=no
       AC_CHECK_LIB(zvt-2.0, zvt_term_new_with_size,[GZVT2=yes])
       if test "$GZVT2" = no; then
	  AC_MSG_ERROR([Could not find vte library or libzvt-2.0 library.],)
       else 
         TERM_NAME=zterm
         TERM_LDFLAGS=ZTERM_LDFLAGS
       fi
    else 
	 TERM_NAME=vte
	 TERM_LDFLAGS=VTE_LDFLAGS
    fi
    LIBS=$ac_save_LIBS
  fi
  # try to use readline with the gtk version 
  ac_save_LIBS="$LIBS"
  LIBS="$TERMCAPLIB  $LIBS"
  AC_CHECK_LIB(readline, rl_callback_read_char,[READLINE=-lreadline])
  LIBS=$ac_save_LIBS
  TERMCAPLIB="$READLINE $TERMCAPLIB"
  if test "no$READLINE" != no; then
     ZZLEDT="zzledt-rl.o"
     AC_DEFINE(WITH_READLINE)
  fi
  # we remove the X libs they were just used above during tcl/tk check 
  if test "$with_gtk2" = yes; then
    XAWLIB=
    XMULIB=
    XAW_LOCAL_SUBDIR=
    XAW_LOCAL_LIB=
    X_CFLAGS=
    XAW_LOCAL_INCLUDES=
    X_EXTRA_LIBS=
    XXTXEXT=
    XX11=
    X_LIBS= 
    X_PRE_LIBS=
    if test "$TK_INC_PATH" = '-I/usr/include' ; then
        TK_INC_PATH=
    fi
    if test "$TCL_INC_PATH" = '-I/usr/include' ; then
        TCL_INC_PATH=
    fi
  fi
fi


#################
## atlas 
#################

# check user arguments
USER_ATLAS_LIB_PATH=""

AC_ARG_WITH(atlas-library,
    [  --with-atlas-library=DIR  Atlas library files are in DIR and we use Atlas ],
    [  USER_ATLAS_LIB_PATH=$withval
    CC_OPTIONS="$CC_OPTIONS -DWITH_ATLAS"],
    )

if test "$USER_ATLAS_LIB_PATH" = ""; then
	WHICH_BLAS="STD_BLAS"
	IN_ATLAS=LOCAL
else 
	echo "using Atlas library"
	WHICH_BLAS="ATLAS_LAPACKBLAS"
	ATLAS_DIR=$USER_ATLAS_LIB_PATH
	IN_ATLAS=ATLAS
	AC_DEFINE(WITH_ATLAS)
fi


#################
## ocaml 
#################

OCAMLTARGET=ocaml_disabled
OCAMLTARGET_DISTCLEAN=ocaml_disabled

if test "$with_ocaml" != no; then
	AC_CHECK_PROG(with_ocamlc,ocamlc,yes,no)
	if test "$with_ocamlc" = no; then
		AC_MSG_WARN([ocamlc not found: I will not build Modelica compiler])
		OCAMLTARGET=ocaml_disabled
		OCAMLTARGET_DISTCLEAN=ocaml_disabled
	else
		AC_CHECK_PROG(with_ocamlopt,ocamlopt,yes,no)
		if test "$with_ocamlopt" = no; then
			AC_MSG_WARN([ocamlopt not found: I will not build Modelica compiler])
			OCAMLTARGET=ocaml_disabled
			OCAMLTARGET_DISTCLEAN=ocaml_disabled 
		else
			AC_CHECK_PROG(with_ocamldep,ocamldep,yes,no)
			if test "$with_ocamldep" = no; then
				AC_MSG_WARN([ocamldep not found: I will not build Modelica compiler])
				OCAMLTARGET=ocaml_disabled
				OCAMLTARGET_DISTCLEAN=ocaml_disabled
			else
				AC_DEFINE(WITH_OCAML)
				OCAMLTARGET=scilex-lib
				OCAMLTARGET_DISTCLEAN=distclean
			fi
		fi
	fi
fi

#################
## Man management
#################

# Sablotron or xsltproc
# ===================

AC_CHECK_PROG(WITH_XSLTPROC,xsltproc,yes,no)

if test "$WITH_XSLTPROC" = yes; then
	MANTARGET=man
	MANGENERATOR=xsltproc
else 
	AC_CHECK_PROG(WITH_SABCMD,sabcmd,yes,no)
	if test "$WITH_SABCMD" = yes; then
		MANTARGET=man
		MANGENERATOR=sabcmd
	else
		AC_MSG_WARN([Sablotron "sabcmd" or xmlto not found: I will not build man pages])
		MANTARGET=
	fi
fi

# Now check if man sources 
# are checked out or not
# ===================

AC_CHECK_FILE(man/fr/Makefile.in,[MAN_FR=man/fr/Makefile],[MAN_FR=])

if test "$MAN_FR" = ''; then
	MANTARGET=
	AC_MSG_WARN([man/fr/Makefile.in not found : I will not build man pages])
else
	AC_CHECK_FILE(man/eng/Makefile.in,[MAN_ENG=man/eng/Makefile],[MAN_ENG=])
	if test "$MAN_ENG" = ''; then
		MANTARGET=
		AC_MSG_WARN([man/eng/Makefile.in not found : I will not build man pages])
	fi
fi

#########################
## substituting variables
#########################

AC_SUBST(RM)
AC_SUBST(AR)
AC_SUBST(AR_FLAGS)
AC_SUBST(FILES_TO_CLEAN)
AC_SUBST(CC)
AC_SUBST(CC_OPTIONS)
AC_SUBST(CC_LDFLAGS)
AC_SUBST(CC_PICFLAGS)
AC_SUBST(CXX)
AC_SUBST(CXXFLAGS)
AC_SUBST(CXXCPP)
AC_SUBST(FC)
AC_SUBST(FC_OPTIONS)
AC_SUBST(FC_OPTIONS1)
AC_SUBST(FC_OPTIONS2)
AC_SUBST(FC_LDFLAGS)
AC_SUBST(FC_PICFLAGS)
AC_SUBST(LD)
AC_SUBST(LD_LDFLAGS)
AC_SUBST(SCILAB_GS)
AC_SUBST(SCILABSCRIPT)
AC_SUBST(FGETARG)
AC_SUBST(GETARG)
AC_SUBST(HPPA_OLD)
AC_SUBST(DLDLIB)
AC_SUBST(DLD_SUBDIR)
AC_SUBST(XAWLIB)
AC_SUBST(XAW)
AC_SUBST(XMULIB)
AC_SUBST(XAW_LOCAL_SUBDIR)
AC_SUBST(XAW_LOCAL_INCLUDES)
AC_SUBST(XAW_LOCAL_LIB)
AC_SUBST(GTKCFLAGS)
AC_SUBST(GTKLIBS)
AC_SUBST(GNOMECFLAGS)
AC_SUBST(TERMCAPLIB)
AC_SUBST(MAIN)
AC_SUBST(MAKEFILE_TARGET)
AC_SUBST(PERIFILE)
AC_SUBST(GUILIB)
AC_SUBST(GZVT)
AC_SUBST(XDRLIB)
AC_SUBST(XDRLIBNAME)
AC_SUBST(WINXFLAGS)
AC_SUBST(MENUSOBJS)
AC_SUBST(MALLOC)
AC_SUBST(PVMARCH)
AC_SUBST(PVMLIB)
AC_SUBST(PVMSCIDIR)
AC_SUBST(PVMSCILIB)
AC_SUBST(PVMGLIB)
AC_SUBST(PVMTARGET)
AC_SUBST(PVMTARGET_DISTCLEAN)
AC_SUBST(PVMROOT)
AC_SUBST(PVMROOTR)
AC_SUBST(PVMINST)
AC_SUBST(PVMINST1)
AC_SUBST(PVMINCLUDE)
AC_SUBST(PVMHOSTERFILES)
AC_SUBST(PVMHOSTER)
AC_SUBST(PVMHELP)

AC_SUBST(TKBASE)
AC_SUBST(TK_INC_PATH)
AC_SUBST(TCL_INC_PATH)
AC_SUBST(TCLTK_LIBS)
AC_SUBST(TCLSCILIB)
AC_SUBST(TCLSCIDIR)
AC_SUBST(TCLSCIDIR)
AC_SUBST(TCLTKHELP)
AC_SUBST(TK_MINOR_VERSION)
AC_SUBST(TK_MAJOR_VERSION)

AC_SUBST(NOINLINE)
AC_SUBST(WHICH_BLAS)
AC_SUBST(ATLAS_DIR)
AC_SUBST(IN_ATLAS)
AC_SUBST(OCAMLTARGET)
AC_SUBST(OCAMLTARGET_DISTCLEAN)
AC_SUBST(WITH_OCAML)
AC_SUBST(MANTARGET)
# for Makemex

AC_SUBST(SHELL)
AC_SUBST(DLLTOOL)
AC_SUBST(LD)
AC_SUBST(LIBM)
AC_SUBST(LIBTOOL)
AC_SUBST(LIBTOOL_DEPS)
AC_SUBST(LN_S)
AC_SUBST(NM)
AC_SUBST(OBJDUMP)
AC_SUBST(PACKAGE)
AC_SUBST(RANLIB)
AC_SUBST(STATIC)
AC_SUBST(SCIVERSION)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)
AC_SUBST(FLIBS)
AC_SUBST(SONAME)
#AC_SUBST(CC)
AC_SUBST(CFLAGS)
#AC_SUBST(FC_USE_CDEC)
AC_SUBST(FC_SUBDIR)
AC_SUBST(BLPR_SCRIPTS)
AC_SUBST(SED_CYGDRIVE)
AC_SUBST(F2C_SUBDIR)
AC_SUBST(EXAMPLES_TESTS)
AC_SUBST(IMPPREF)
AC_SUBST(IMPENV)
AC_SUBST(ZZLEDT)
AC_SUBST(STRIP)
AC_SUBST(HTMLFLAGS)
AC_SUBST(GTKPLUGBUG)
AC_SUBST(XXTXEXT)
AC_SUBST(XX11)
AC_SUBST(PERIX11NOPT)
AC_SUBST(GETLIBTK)
AC_SUBST(MANGENERATOR)
AC_SUBST(TERM_NAME)
AC_SUBST(TERM_LDFLAGS)
AC_SUBST(JAVASCITARGET)
AC_SUBST(JAVASCITARGET_DISTCLEAN)
AC_SUBST(JAVA_INCL)
AC_SUBST(GCCFIX)
AC_OUTPUT(Makefile.OBJ Makefile.incl Makefile scripts/Makefile routines/Makefile routines/default/Makefile routines/os_specific/Makefile routines/graphics/Makefile routines/menusX/Makefile routines/xsci/Makefile routines/sparse/Makefile Makemex  config/Makeso.incl routines/interf/Makefile routines/control/Makefile routines/system/Makefile routines/calelm/Makefile  config/Makefile.aix config/Makefile.ultrix routines/lapack/Makefile scripts/scilab.g scripts/scilab-gtk.g examples/Makefile routines/version.h imp/Makefile routines/gtksci/Makefile pvm3/Makefile pvm3/Makefile.aimk pvm3/hoster/Makefile.aimk config/configuration macros/util/gettklib.sci  macros/util/xmlfiletohtml.sci routines/gzvt2/Makefile routines/Javasci/Makefile $MAN_FR $MAN_ENG)
 



