view configure.ac @ 18199:b7d3e1f762e1

don't include umap_xsignbit with char mapper cases (see 0d5721873d6b) * ov-base-sparse.cc (octave_base_sparse<T>::map): Don't include umap_xsignbit in the set of char mapper cases. * ov-float.cc (octave_float_scalar::map): Likewise. * ov-flt-re-mat.cc (octave_float_matrix::map): Likewise. * ov-re-mat.cc (octave_matrix::map): Likewise. * ov-scalar.cc (octave_scalar::map): Likewise.
author John W. Eaton <jwe@octave.org>
date Fri, 03 Jan 2014 11:23:08 -0500
parents c56ce7c65019
children 775e7874b38d
line wrap: on
line source

dnl Process this file with autoconf to produce a configure script.
dnl
dnl Copyright (C) 1993-2013 John W. Eaton
### 
### This file is part of Octave.
### 
### Octave is free software; you can redistribute it and/or modify it
### under the terms of the GNU General Public License as published by the
### Free Software Foundation; either version 3 of the License, or (at
### your option) any later version.
### 
### Octave is distributed in the hope that it will be useful, but WITHOUT
### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
### FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
### for more details.
### 
### You should have received a copy of the GNU General Public License
### along with Octave; see the file COPYING.  If not, see
### <http://www.gnu.org/licenses/>.

AC_PREREQ([2.62])
AC_INIT([GNU Octave], [4.1.0+], [http://octave.org/bugs.html], [octave])

dnl PACKAGE_VERSION is set by the AC_INIT VERSION arg
OCTAVE_VERSION="$PACKAGE_VERSION"
OCTAVE_API_VERSION_NUMBER="49"
OCTAVE_API_VERSION="api-v$OCTAVE_API_VERSION_NUMBER+"
OCTAVE_RELEASE_DATE="2013-12-21"
OCTAVE_COPYRIGHT="Copyright (C) 2013 John W. Eaton and others."
AC_SUBST(OCTAVE_VERSION)
AC_SUBST(OCTAVE_API_VERSION_NUMBER)
AC_SUBST(OCTAVE_API_VERSION)
AC_SUBST(OCTAVE_RELEASE_DATE)
AC_SUBST(OCTAVE_COPYRIGHT)

dnl FIXME: We should auto-insert the Mercurial changeset ID into the
dnl        AC_REVISION field whenever configure.ac is modified.
dnl AC_REVISION($Revision: 1.603 $)
AC_CONFIG_SRCDIR([libinterp/octave.cc])
AC_CONFIG_HEADERS([config.h:config.in.h])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE([1.11 foreign -Wno-portability -Wno-override tar-ustar subdir-objects])

## Add the option to enable silent rules, available since Automake 1.11
## and included by default starting with Automake 1.13.
AM_SILENT_RULES

OCTAVE_CANONICAL_HOST

AC_DEFINE(OCTAVE_SOURCE, 1, [Define to 1 if this is Octave.])
  
AC_USE_SYSTEM_EXTENSIONS

### Make configure args available for other uses.

config_opts=$ac_configure_args
AC_SUBST(config_opts)

### Set default file locations

OCTAVE_SET_DEFAULT([octlibdir], '$(libdir)/octave/$(version)')
OCTAVE_SET_DEFAULT([archlibdir],
  '$(libexecdir)/octave/$(version)/exec/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([localarchlibdir],
  '$(libexecdir)/octave/site/exec/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([localapiarchlibdir],
  '$(libexecdir)/octave/$(api_version)/site/exec/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([localverarchlibdir],
  '$(libexecdir)/octave/$(version)/site/exec/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([octfiledir],
  '$(libdir)/octave/$(version)/oct/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([localoctfiledir],
  '$(libdir)/octave/site/oct/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([localapioctfiledir],
  '$(libdir)/octave/site/oct/$(api_version)/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([localveroctfiledir],
  '$(libdir)/octave/$(version)/site/oct/$(canonical_host_type)')
OCTAVE_SET_DEFAULT([octincludedir], '$(includedir)/octave-$(version)/octave')
OCTAVE_SET_DEFAULT([fcnfiledir], '$(datadir)/octave/$(version)/m')
OCTAVE_SET_DEFAULT([localfcnfiledir], '$(datadir)/octave/site/m')
OCTAVE_SET_DEFAULT([localapifcnfiledir],
  '$(datadir)/octave/site/$(api_version)/m')
OCTAVE_SET_DEFAULT([localverfcnfiledir], '$(datadir)/octave/$(version)/site/m')
OCTAVE_SET_DEFAULT([octetcdir], '$(datadir)/octave/$(version)/etc')
OCTAVE_SET_DEFAULT([octlocaledir], '$(datadir)/octave/$(version)/locale')
OCTAVE_SET_DEFAULT([doc_cache_file], '$(octetcdir)/doc-cache')
OCTAVE_SET_DEFAULT([octtestsdir], '$(octetcdir)/tests')
OCTAVE_SET_DEFAULT([texi_macros_file], '$(octetcdir)/macros.texi')
OCTAVE_SET_DEFAULT([imagedir], '$(datadir)/octave/$(version)/imagelib')
OCTAVE_SET_DEFAULT([man1dir], '$(mandir)/man1')
OCTAVE_SET_DEFAULT([man1ext], '.1')
OCTAVE_SET_DEFAULT([infofile], '$(infodir)/octave.info')

### Check for programs used in building, installing, and running Octave.

## Programs used in configuring Octave.
## Find pkg-config executable (sets $PKG_CONFIG)
PKG_PROG_PKG_CONFIG

## Programs used in Makefiles.
AC_PROG_AWK
AC_PROG_GREP
OCTAVE_PROG_FIND
OCTAVE_PROG_SED
OCTAVE_PROG_PERL

## Programs used to build parts of Octave.
OCTAVE_PROG_GPERF

OCTAVE_PROG_FLEX
AC_SUBST([LEX_OUTPUT_ROOT], [lex.octave_])

OCTAVE_PROG_BISON

OCTAVE_PROG_MAKEINFO
OCTAVE_PROG_TEXI2DVI
OCTAVE_PROG_TEXI2PDF

## Programs used when installing Octave.
AC_PROG_LN_S
AC_PROG_MKDIR_P

AC_PROG_INSTALL
INSTALL_SCRIPT='${INSTALL}'
AC_SUBST(INSTALL_SCRIPT)

OCTAVE_PROG_DESKTOP_FILE_INSTALL

## Programs used when running Octave
OCTAVE_PROG_GHOSTSCRIPT
OCTAVE_PROG_GNUPLOT
OCTAVE_PROG_PAGER
OCTAVE_PROG_PYTHON

### Default terminal font for the GUI
case $host_os in
  mingw* | msdosmsvc)
    DEFAULT_TERMINAL_FONT="Lucida Console"
  ;;
  *)
    DEFAULT_TERMINAL_FONT="Courier"
  ;;
esac
DEFAULT_TERMINAL_FONT_SIZE=10
AC_SUBST(DEFAULT_TERMINAL_FONT)
AC_SUBST(DEFAULT_TERMINAL_FONT_SIZE)

### Path separator.

sepchar=':'
AC_ARG_WITH([sepchar],
  [AS_HELP_STRING([--with-sepchar=<char>],
    [use <char> as the path separation character])])
case $with_sepchar in
  yes | "")
    case $host_os in
      mingw* | msdosmsvc)
        sepchar=';' ;;
    esac
    ;;
  no)
    AC_MSG_ERROR([You are required to define a path separation character])
    ;;
  *)
    sepchar=$with_sepchar
    ;;
esac
AC_SUBST(sepchar)
AC_DEFINE_UNQUOTED(SEPCHAR, ['$sepchar'],
  [Define this to be the path separator for your system, as a character constant.])
AC_DEFINE_UNQUOTED(SEPCHAR_STR, ["$sepchar"],
  [Define this to be the path separator for your system, as a string.])

### Define the path to the shell on the host system.  Most systems will
### ensure /bin/sh is the default shell so this can be safely ignored by
### almost everyone.  However, when building for Android, for example,
### this will need to be set.
SHELL_PATH=/bin/sh
AC_ARG_WITH([shell],
  [AS_HELP_STRING([--with-shell=SHELL],
    [use SHELL as the shell interpreter (default: /bin/sh)])])
case $with_shell in
  no)
    AC_MSG_ERROR([A shell interpreter is required])
  ;;
  yes | "")
  ;;
  *)
    SHELL_PATH=$with_shell
  ;;
esac
AC_DEFINE_UNQUOTED([SHELL_PATH], ["$SHELL_PATH"],
  [Define this to be the path to the shell command interpreter.])

### Enable bounds checking on element references within Octave's array and
### matrix classes.  This slows down some operations a bit, so it is turned off
### by default.

BOUNDS_CHECKING=no
AC_ARG_ENABLE([bounds-check],
  [AS_HELP_STRING([--enable-bounds-check],
    [enable bounds checking for indexing in internal array classes])],
  [if test "$enableval" = yes; then BOUNDS_CHECKING=yes; fi], [])
if test $BOUNDS_CHECKING = yes; then
  AC_DEFINE(BOUNDS_CHECKING, 1, [Define to 1 to use internal bounds checking.])
fi

### Use Octave's built-in memory allocator rather than straightforward malloc.
### Disabled by default.

USE_OCTAVE_ALLOCATOR=no
AC_ARG_ENABLE([octave-allocator],
  [AS_HELP_STRING([--enable-octave-allocator],
    [use the obsolete octave_allocator class for many of Octave's objects (mostly octave_value types).  You probably do NOT want to enable this feature.])],
  [if test "$enableval" = yes; then USE_OCTAVE_ALLOCATOR=yes; fi], [])
if test $USE_OCTAVE_ALLOCATOR = yes; then
  AC_DEFINE(USE_OCTAVE_ALLOCATOR, 1,
    [Define to 1 to use octave_allocator class.])
fi

### Use atomic operations for internal reference counting.  This is required
### for thread-safe behavior but incurs a significant slowdown, and is thus
### disabled by default.

USE_ATOMIC_REFCOUNT=no
AC_ARG_ENABLE([atomic-refcount],
  [AS_HELP_STRING([--enable-atomic-refcount],
    [use atomic operations for internal reference counting.  This is required for thread-safe behavior but does not by itself make Octave internals thread safe.])],
  [if test "$enableval" = yes; then USE_ATOMIC_REFCOUNT=yes; fi], [])
if test $USE_ATOMIC_REFCOUNT = yes; then
  AC_DEFINE(USE_ATOMIC_REFCOUNT, 1,
    [Define to 1 to use atomic operations for reference counting.])
fi

### Disable running Make in the doc directory.
### This is useful, for example, when building Octave on systems without TeX.

DOCDIR=doc
AC_ARG_ENABLE([docs],
  [AS_HELP_STRING([--disable-docs], [don't build documentation files])],
  [if test "$enableval" = no; then
     DOCDIR=
     warn_docs="building documentation disabled; make dist will fail"
     OCTAVE_CONFIGURE_WARNING([warn_docs])
   fi],
  [])
AC_SUBST(DOCDIR)

### If possible, use a 64-bit integer type for array dimensions and indexing.

USE_64_BIT_IDX_T=no
OCTAVE_IDX_TYPE=int
AC_ARG_ENABLE(64,
  [AS_HELP_STRING([--enable-64],
    [(EXPERIMENTAL) use 64-bit integers for array dimensions and indexing])],
  [if test "$enableval" = yes; then USE_64_BIT_IDX_T=yes; fi], [])
if test $USE_64_BIT_IDX_T = yes; then
  AC_CHECK_SIZEOF([void *])
  AC_CHECK_SIZEOF([int])
  AC_CHECK_SIZEOF([long])
  AC_CHECK_SIZEOF([int64_t])
  if test $ac_cv_sizeof_void_p -eq 8; then
    OCTAVE_IDX_TYPE=int64_t
  else
    warn_64_bit="pointers are not 64-bits wide; disabling 64-bit features"
    OCTAVE_CONFIGURE_WARNING([warn_64_bit])
    USE_64_BIT_IDX_T=no
  fi
fi
AC_SUBST(OCTAVE_IDX_TYPE)
AC_DEFINE_UNQUOTED(OCTAVE_IDX_TYPE, [$OCTAVE_IDX_TYPE],
  [Define to the type of octave_idx_type (64 or 32 bit signed integer).])
if test $USE_64_BIT_IDX_T = yes; then
  AC_DEFINE(USE_64_BIT_IDX_T, 1,
    [Define to 1 if using 64-bit integers for array dimensions and indexing.])
fi
AC_SUBST(USE_64_BIT_IDX_T)

### It seems that there are some broken inline assembly functions in
### the GNU libc.  Since I'm not sure how to test whether we are using
### GNU libc, just disable them for all platforms.

AC_MSG_NOTICE([defining __NO_MATH_INLINES avoids buggy GNU libc exp function])
AC_DEFINE(__NO_MATH_INLINES, 1,
  [Define to 1 if your version of GNU libc has buggy inline assembly code for math functions like exp.])

### Determine which C++ compiler to use (we expect to find g++).

AC_PROG_CXX
AC_PROG_CXXCPP

### Check version number when using g++.

GXX_VERSION=
if test "$GXX" = yes; then
  gxx_version=`$CXX -v 2>&1 | $GREP "^.*g.. version" | \
    $SED -e 's/^.*g.. version *//' -e 's/cygnus-//' -e 's/egcs-//' -e 's/ .*//'`

  AX_COMPARE_VERSION([$gxx_version], [lt], [3.5],
    [AC_MSG_ERROR([g++ version $gxx_version will probably fail to compile Octave])])

  GXX_VERSION=$gxx_version
fi
AC_SUBST(GXX_VERSION)

### Determine which C compiler to use (we expect to find gcc).

AC_PROG_CC
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL

## Check for MSVC
have_msvc=no
case $host_os in
  msdosmsvc)
    have_msvc=yes
  ;;
  mingw*)
    AC_MSG_CHECKING([for MSVC compiler])
    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
        #ifndef _MSC_VER
        #error "Not MSVC compiler"
        #endif
        ]])],
      have_msvc=yes, have_msvc=no)
    AC_MSG_RESULT([$have_msvc])
  ;;
esac

### gnulib initialization: part 1
### Must take place immediately after a compiler is determined

gl_EARLY

### Check version number when using gcc.

GCC_VERSION=
if test "$GCC" = yes; then
  AC_MSG_CHECKING([C compiler version number])
  gcc_version=`$CC -v 2>&1 | $GREP "^.*gcc version" | \
    $SED -e 's/^.*g.. version *//' -e 's/cygnus-//' -e 's/egcs-//' -e 's/ .*//'`

  AX_COMPARE_VERSION([$gcc_version], [lt], [3],
    [warn_gcc_version="gcc version $gcc_version is likely to cause problems"
     OCTAVE_CONFIGURE_WARNING([warn_gcc_version])])

  GCC_VERSION=$gcc_version
  AC_MSG_RESULT([$GCC_VERSION])
fi
AC_SUBST(GCC_VERSION)

### Also check g++ version number, it might be different from the
## gcc version number.

GXX_VERSION=
if test "$GXX" = yes; then
  AC_MSG_CHECKING([C++ compiler version number])
  gxx_version=`$CXX -v 2>&1 | $GREP "^.*g.. version" | \
    $SED -e 's/^.*g.. version *//' -e 's/cygnus-//' -e 's/egcs-//' -e 's/ .*//'`

  AX_COMPARE_VERSION([$gxx_version], [lt], [3],
    [warn_gxx_version="g++ version $gxx_version is likely to cause problems"
     OCTAVE_CONFIGURE_WARNING([warn_gxx_version])])

  GXX_VERSION=$gxx_version
  AC_MSG_RESULT([$GXX_VERSION])
fi
AC_SUBST(GXX_VERSION)

OCTAVE_CHECK_BROKEN_STL_ALGO_H
AM_CONDITIONAL([AMCOND_HAVE_BROKEN_STL_ALGO_H],
  [test $octave_cv_broken_stl_algo_h = yes])

if test $octave_cv_broken_stl_algo_h = yes; then
  warn_stl_algo_h="Found nth_element broken in g++ $GXX_VERSION.  Attempting to repair by using local patched version of bits/stl_algo.h."
  OCTAVE_CONFIGURE_WARNING([warn_stl_algo_h])
fi

### Determine the compiler flag necessary to create dependencies

## Assume GCC.
INCLUDE_DEPS=yes
DEPEND_FLAGS="-M"
DEPEND_EXTRA_SED_PATTERN=""
if test "$GCC" != yes; then
  case $canonical_host_type in
    sparc-sun-solaris2* | i386-pc-solaris2*)
      DEPEND_FLAGS="-xM1"
      DEPEND_EXTRA_SED_PATTERN="-e '/\/opt\/SUNWspro/d'"
    ;;
    *-*-msdosmsvc)
    ;;
    *-*-mingw*)
      if test $have_msvc = no; then
        INCLUDE_DEPS=no
      fi
    ;;
    *)
      INCLUDE_DEPS=no
    ;;
  esac
fi
AC_SUBST(INCLUDE_DEPS)
AC_SUBST(DEPEND_FLAGS)
AC_SUBST(DEPEND_EXTRA_SED_PATTERN)

### Check for pthread library

AX_PTHREAD
## Include pthread libs and flags early in case other tests need them.
## They seem to be required for the OpenGL tests on Debian systems.
LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"

### When compiling math for x87, problems may arise in some code comparing
### floating-point intermediate results.  The root cause is the extra precision
### (~80 bits) of x87 co-processor registers versus the IEEE standard 64 bits.
### Generally, storing the result in a local volatile variable forces a
### truncation back to 64 bits, but it also degrades performance.
### Thus, we provide a FLOAT_TRUNCATE macro that may be defined to "volatile"
### when compiling for x87 target, or left empty for modern SSE math, that
### doesn't suffer from this problem at all.
### FIXME: If no option value is given, configure uses a default heuristic
###        which assumes that truncation should occur for MinGW and Cygwin
###        systems and not for any others.  It would be marginally nicer
###        to replace this with a test that checks whether the problem arises
###        and only sets the flag if necessary.  However, the principal
###        scenario for those two systems is a cross-build where we can't
###        run an executable so the test wouldn't be too useful most of the
###        time (only native builds on MinGW and Cygwin *might* benefit).
###        Maybe, one could generate assembly code with -S option and inspect
###        it without having to run an executable, but this sounds pretty dicey.
AC_ARG_ENABLE([float-truncate],
  [AS_HELP_STRING([--enable-float-truncate],
    [truncate intermediate FP results])],
  [if test "$enableval" = yes; then
     ac_float_truncate=volatile
   else
     ac_float_truncate=
   fi],
  [case $host_os in
     mingw* | cygwin*)
       ac_float_truncate=volatile
     ;;
     *)
       ac_float_truncate=
     ;;
   esac])

AC_DEFINE_UNQUOTED(FLOAT_TRUNCATE, [$ac_float_truncate], 
  [Define to volatile if you need to truncate intermediate FP results.])

### Determine extra CFLAGS that may be necessary for Octave.

## On Intel systems with gcc, we may need to compile with -mieee-fp
## to get full support for IEEE floating point.
##
## On Alpha/OSF systems, we need -mieee.

ieee_fp_flag=
case $canonical_host_type in
  i[[3456789]]86-*-*)
    if test "$GCC" = yes; then
      OCTAVE_CC_FLAG([-mieee-fp], [
        ieee_fp_flag=-mieee-fp
        XTRA_CFLAGS="$XTRA_CFLAGS -mieee-fp"
        AC_MSG_NOTICE([adding -mieee-fp to XTRA_CFLAGS])])
    fi
    if test "$GXX" = yes; then
      OCTAVE_CXX_FLAG([-mieee-fp], [
        ieee_fp_flag=-mieee-fp
        XTRA_CXXFLAGS="$XTRA_CXXFLAGS -mieee-fp"
        AC_MSG_NOTICE([adding -mieee-fp to XTRA_CXXFLAGS])])
    fi
  ;;
  alpha*-*-*)
    if test "$GCC" = yes; then
      OCTAVE_CC_FLAG([-mieee], [
        ieee_fp_flag=-mieee
        XTRA_CFLAGS="$XTRA_CFLAGS -mieee"
        AC_MSG_NOTICE([adding -mieee to XTRA_CFLAGS])])
    else
      OCTAVE_CC_FLAG([-ieee], [
        ieee_fp_flag=-ieee
        XTRA_CFLAGS="$XTRA_CFLAGS -ieee"
        AC_MSG_NOTICE([adding -ieee to XTRA_CFLAGS])])
    fi
    if test "$GXX" = yes; then
      OCTAVE_CXX_FLAG([-mieee], [
        ieee_fp_flag=-mieee
        XTRA_CXXFLAGS="$XTRA_CXXFLAGS -mieee"
        AC_MSG_NOTICE([adding -mieee to XTRA_CXXFLAGS])])
    else
      OCTAVE_CXX_FLAG([-ieee], [
        ieee_fp_flag=-ieee
        XTRA_CXXFLAGS="$XTRA_CXXFLAGS -ieee"
        AC_MSG_NOTICE([adding -ieee to XTRA_CXXFLAGS])])
    fi
  ;;
  *ibm-aix4*)
    OCTAVE_CC_FLAG([-mminimal-toc], [
      XTRA_CFLAGS="$XTRA_CFLAGS -mminimal-toc"])

    OCTAVE_CXX_FLAG([-mminimal-toc], [
      XTRA_CXXFLAGS="$XTRA_CXXFLAGS -mminimal-toc"])
  ;;
esac

AC_SUBST(XTRA_CFLAGS)
AC_SUBST(XTRA_CXXFLAGS)

### Test whether the compiler supports OpenMP.  This is experimental so disable
### it by default.  Enable it with the flag --enable-openmp.

USE_OPENMP=no
AC_ARG_ENABLE([openmp],
  [AS_HELP_STRING([--enable-openmp],
    [(EXPERIMENTAL) use OpenMP SMP multi-threading])],
  [if test "$enableval" = yes; then USE_OPENMP=yes; fi], [])
if test $USE_OPENMP = yes; then
  case $host_os in
    mingw* | cygwin* | *-gnu*)
      OCTAVE_CHECK_OPENMP(-fopenmp)
    ;;
    msdosmsvc)
      ## FIXME: is this the right flag for MSVC?
      OCTAVE_CHECK_OPENMP(-openmp)
    ;;
    ## Add other compilers supporting OpenMP here
  esac
fi

### Defaults for cross compiling.  BUILD_CC and BUILD_CXX are
### the compilers that we use for building tools on the build system.
### For now, we assume that the only cross compiling we can do is
### with gcc on a Unixy system, but the dedicated hacker can override these.

if test "$cross_compiling" = yes; then
  BUILD_CC="gcc"
  BUILD_CFLAGS="-O2 -g"
  BUILD_CXX="g++"
  BUILD_CXXFLAGS="-O2 -g"
  BUILD_LDFLAGS=""
  BUILD_EXEEXT=""
else
  BUILD_CC='$(CC)'
  BUILD_CFLAGS='$(CFLAGS)'
  BUILD_CXX='$(CXX)'
  BUILD_CXXFLAGS='$(CXXFLAGS)'
  BUILD_LDFLAGS='$(LDFLAGS)'
  BUILD_EXEEXT='$(EXEEXT)'
fi

AC_ARG_VAR([BUILD_CC],
  [build system C compiler (used if cross compiling)])
AC_ARG_VAR([BUILD_CFLAGS],
  [build system C compiler flags (used if cross compiling)])
AC_ARG_VAR([BUILD_CXX],
  [build system C++ compiler (used if cross compiling)])
AC_ARG_VAR([BUILD_CXXFLAGS],
  [build system C++ compiler flags (used if cross compiling)])
AC_ARG_VAR([BUILD_LDFLAGS],
  [build system C++ compiler link flags (used if cross compiling)])
AC_ARG_VAR([BUILD_EXEEXT],
  [build system executable extension (used if cross compiling)])


### Look for math library.  If found, this will add -lm to LIBS.

dnl Keep this check before the check for the Fortran compiler,
dnl in case -lm is needed to compile Fortran programs.
AC_CHECK_LIB(m, sin)

### Determine the Fortran compiler and how to invoke it

## Default FFLAGS is -O.
if test x"$FFLAGS" = x""; then
  FFLAGS="-O"
fi

## the F77 variable, if set, overrides AC_PROG_F77 automatically
AC_PROG_F77
AC_F77_LIBRARY_LDFLAGS
AC_F77_DUMMY_MAIN
AC_F77_WRAPPERS

F77_TOLOWER=yes
F77_APPEND_UNDERSCORE=yes
F77_APPEND_EXTRA_UNDERSCORE=yes

case $ac_cv_f77_mangling in
  "upper case") F77_TOLOWER=no ;;
esac
case $ac_cv_f77_mangling in
  "no underscore") F77_APPEND_UNDERSCORE=no ;;
esac
case $ac_cv_f77_mangling in
  "no extra underscore") F77_APPEND_EXTRA_UNDERSCORE=no ;;
esac

case $canonical_host_type in
  i[[3456789]]86-*-*)
    if test $ac_cv_f77_compiler_gnu = yes; then
      OCTAVE_F77_FLAG([-mieee-fp])
    fi
  ;;
  alpha*-*-*)
    if test $ac_cv_f77_compiler_gnu = yes; then
      OCTAVE_F77_FLAG([-mieee])
    else
      OCTAVE_F77_FLAG([-ieee])
      OCTAVE_F77_FLAG([-fpe1])
    fi
  ;;
  powerpc-apple-machten*)
    FFLAGS=
  ;;
esac

if test -n "$FFLAGS"; then
  AC_MSG_NOTICE([defining FFLAGS to be $FFLAGS])
fi

AC_SUBST(F77_TOLOWER)
AC_SUBST(F77_APPEND_UNDERSCORE)
AC_SUBST(F77_APPEND_EXTRA_UNDERSCORE)

if test -z "$F77"; then
  AC_MSG_ERROR([in order to build Octave, you must have a compatible Fortran compiler or wrapper script for f2c that functions as a Fortran compiler installed and in your path.  See the file INSTALL for more information.])
fi

OCTAVE_CHECK_FUNC_FORTRAN_ISNAN
F77_ISNAN_MACRO=
if test $octave_cv_func_fortran_isnan = no; then
  AC_MSG_NOTICE([substituting ISNAN(X) with X.NE.X in Fortran sources])
  F77_ISNAN_MACRO="s|ISNAN(\(@<:@^)@:>@*\))|(\1.NE.\1)|"
fi
AC_SUBST(F77_ISNAN_MACRO)

OCTAVE_CHECK_SIZEOF_FORTRAN_INTEGER
if test $octave_cv_sizeof_fortran_integer = no; then
  if test $USE_64_BIT_IDX_T = yes; then
    case $F77 in
      *gfortran*)
        case $F77_INTEGER_8_FLAG in
          *-fdefault-integer-8*)
          ;;
          *)
            case $FFLAGS in
              *-fdefault-integer-8*)
                AC_MSG_NOTICE([setting -fdefault-integer-8 in F77_INTEGER_8_FLAG instead of FFLAGS])
                FFLAGS=`echo $FFLAGS | $SED 's/-fdefault-integer-8//g'`
                F77_INTEGER_8_FLAG="-fdefault-integer-8"
              ;;
              *)
                AC_MSG_NOTICE([adding -fdefault-integer-8 to F77_INTEGER_8_FLAG])
                F77_INTEGER_8_FLAG="-fdefault-integer-8"
                ## Invalidate the cache and try again.
                $as_unset octave_cv_sizeof_fortran_integer
              ;;
            esac
          ;;
        esac
      ;;
    esac
    if test -z "$octave_cv_sizeof_fortran_integer"; then
      OCTAVE_CHECK_SIZEOF_FORTRAN_INTEGER
    fi
    if test $octave_cv_sizeof_fortran_integer = no; then
      AC_MSG_ERROR([in order to build Octave with 64-bit indexing support your Fortran compiler must have an option for setting the default integer size to 8 bytes.  See the file INSTALL for more information.])
    fi
  else
    AC_MSG_ERROR([your Fortran compiler must have an option to make integers the same size as octave_idx_type ($OCTAVE_IDX_TYPE).  See the file INSTALL for more information.])
  fi
fi
AC_SUBST(F77_INTEGER_8_FLAG)

## FIXME: Is this really used?  Makefile seems to use $F77 for compiler
FC=$F77
AC_SUBST(FC)

OCTAVE_F77_FLAG([-ffloat-store], [
  AC_MSG_RESULT([setting F77_FLOAT_STORE_FLAG to -ffloat-store])
  F77_FLOAT_STORE_FLAG=-ffloat-store
  AC_SUBST(F77_FLOAT_STORE_FLAG)
])

### Check for the Qhull library

OCTAVE_CHECK_LIB(qhull, QHull,
  [Qhull library not found -- this will result in loss of functionality of some geometry functions.],
  [libqhull/libqhull.h qhull/libqhull.h libqhull.h qhull/qhull.h qhull.h],
  [qh_qhull], [], [],
  [warn_qhull=
  OCTAVE_CHECK_QHULL_VERSION
  OCTAVE_CHECK_LIB_QHULL_OK(
    [TEXINFO_QHULL="@set HAVE_QHULL"
    AC_DEFINE(HAVE_QHULL, 1, [Define to 1 if Qhull is available.])],
    [warn_qhull="Qhull library found, but does not seem to work properly -- this will result in loss of functionality of some geometry functions.  Please try recompiling the library with -fno-strict-aliasing."])])

### Check for PCRE regex library.

PCRE_LIBS=

pcre_fail_msg="to build Octave, you must have the PCRE library and header files installed"

AC_CHECK_HEADERS([pcre.h pcre/pcre.h])

AC_CACHE_CHECK([whether pcre.h defines the macros we need],
  [ac_cv_pcre_h_macros_present],
  [AC_EGREP_CPP([PCRE_HAS_MACROS_WE_NEED], [
    #if defined (HAVE_PCRE_H)
    # include <pcre.h>
    #elif defined (HAVE_PCRE_PCRE_H)
    # include <pcre/pcre.h>
    #error "NO PCRE HEADER"
    #endif
    #if defined (PCRE_INFO_NAMECOUNT) \
      && defined (PCRE_INFO_NAMEENTRYSIZE) \
      && defined (PCRE_INFO_NAMETABLE)
      PCRE_HAS_MACROS_WE_NEED
    #endif],
    ac_cv_pcre_h_macros_present=yes, ac_cv_pcre_h_macros_present=no)])

if test $ac_cv_pcre_h_macros_present = yes; then
  ## check for pcre-config, and if so, get build variables
  AC_CHECK_PROG(HAVE_PCRE_CONFIG, pcre-config, [yes], [no])
  if test $HAVE_PCRE_CONFIG = yes; then
    PCRE_CPPFLAGS=`pcre-config --cflags`
    PCRE_LIBS=`pcre-config --libs`
  else
    PCRE_LIBS="-lpcre"
  fi
  save_LIBS="$LIBS"
  LIBS="$PCRE_LIBS $LIBS"
  AC_CHECK_FUNCS([pcre_compile],
    [AC_SUBST(PCRE_CPPFLAGS)
     AC_SUBST(PCRE_LIBS)],
    [AC_MSG_ERROR([$pcre_fail_msg])])
  LIBS="$save_LIBS"
else
  AC_MSG_ERROR([$pcre_fail_msg])
fi

### Check for ZLIB library.

OCTAVE_CHECK_LIB(z, ZLIB,
  [ZLIB library not found.  Octave will not be able to save or load compressed data files or HDF5 files.],
  [zlib.h], [gzclearerr])

### Also define HAVE_ZLIB if libz is found.
if test $octave_cv_lib_z = yes; then
  AC_DEFINE(HAVE_ZLIB, 1, [Define to 1 if ZLIB is available.])
fi

 ### Check for the LLVM library

build_jit=yes
AC_ARG_ENABLE([jit],
  [AS_HELP_STRING([--enable-jit],
    [(EXPERIMENTAL) enable JIT compiler])],
  [if test "$enableval" = no; then
     build_jit=no
   fi],
  [])

LLVM_CXXFLAGS=
LLVM_CPPFLAGS=
LLVM_LDFLAGS=
LLVM_LIBS=

if test $build_jit = yes; then

  ## Find llvm-config program from environment variable or by searching
  AC_ARG_VAR([LLVM_CONFIG], [path to llvm-config utility])
  AC_CHECK_PROG([LLVM_CONFIG], llvm-config, llvm-config, [])

  if test -z "$LLVM_CONFIG"; then
    warn_llvm="llvm-config utility not found.  JIT compiler is disabled."
  else
    dnl Preset warning message in case compile fails
    warn_llvm="LLVM was not found or is to old.  JIT compiler is disabled."

    save_CPPFLAGS="$CPPFLAGS"
    save_CXXFLAGS="$CXXFLAGS"
    save_LDFLAGS="$LDFLAGS"

    ## Use -isystem if available because we don't want to see warnings in LLVM
    LLVM_INCLUDE_FLAG=-I
    OCTAVE_CC_FLAG([-isystem .], [
      LLVM_INCLUDE_FLAG=-isystem
      AC_MSG_NOTICE([using -isystem for LLVM headers])])

    dnl Use -isystem so we don't get warnings from llvm headers
    LLVM_CPPFLAGS="$LLVM_INCLUDE_FLAG `$LLVM_CONFIG --includedir`"
    LLVM_CXXFLAGS=
    LLVM_LDFLAGS="-L`$LLVM_CONFIG --libdir`"


    LDFLAGS="$LDFLAGS $LLVM_LDFLAGS"
    LLVM_SO=LLVM-`$LLVM_CONFIG --version`
    AC_CHECK_LIB([$LLVM_SO], [LLVMBuildAdd], [LLVM_LIBS="-l$LLVM_SO"], [LLVM_LIBS=`$LLVM_CONFIG --libs`])

    dnl
    dnl Define some extra flags that LLVM requires in order to include headers.
    dnl Ideally we should get these from llvm-config, but llvm-config isn't
    dnl very helpful.
    dnl
    CPPFLAGS="-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS $LLVM_CPPFLAGS $CPPFLAGS"
    CXXFLAGS="$LLVM_CXXFLAGS $CXXFLAGS"
    AC_LANG_PUSH(C++)
    AC_CHECK_HEADER([llvm/Support/TargetSelect.h], [warn_llvm=""])

    have_function_h=no
    AC_CHECK_HEADERS([llvm/IR/Function.h llvm/Function.h],
                     [have_function_h=yes; break])
    if test $have_function_h = no; then
      warn_llvm="Missing LLVM file Function.h.  JIT compiler is disabled."
    fi
    have_irbuilder_h=no
    AC_CHECK_HEADERS([llvm/Support/IRBuilder.h llvm/IR/IRBuilder.h \
                      llvm/IRBuilder.h], [have_irbuilder_h=yes; break])
    if test $have_irbuilder_h = no; then
      warn_llvm="Missing LLVM file IRBuilder.h.  JIT compiler is disabled."
    fi
    have_llvm_data_h=no
    AC_CHECK_HEADERS([llvm/Target/TargetData.h llvm/IR/DataLayout.h \
                      llvm/DataLayout.h], [have_llvm_data_h=yes; break])
    if test $have_llvm_data_h = no; then
      warn_llvm="Missing LLVM file TargetData.h.  JIT compiler is disabled."
    fi

    OCTAVE_LLVM_FUNCTION_ADDATTRIBUTE_API
    OCTAVE_LLVM_FUNCTION_ADDFNATTR_API
    OCTAVE_LLVM_CALLINST_ADDATTRIBUTE_API
    AC_LANG_POP(C++)
    CPPFLAGS="$save_CPPFLAGS"
    CXXFLAGS="$save_CXXFLAGS"