view m4/ax_octave.m4 @ 385:132fec49e438

build: support user selection of Octave version or prefix or both * m4/ax_octave.m4: Add OCTAVE and OCTAVE_VERSION input variables. Test for Octave programs with optional suffix derived from OCTAVE_VERSION. * Makefile.am (check-local): Use configured $(OCTAVE) interpreter. Add options to avoid unnecessary initialization.
author Mike Miller <mtmiller@octave.org>
date Sun, 02 Apr 2017 16:24:02 -0700
parents 30a305837ae6
children
line wrap: on
line source

# ===========================================================================
#
# ===========================================================================
#
# SYNOPSIS
#
#   AX_OCTAVE([OCTAVE_CONFIG], [ACTION_IF_FOUND], [ACTION_IF_NOT_FOUND])
#
# DESCRIPTION
#
#   This macro does a Octave development environment check.
#
#   It accepts one optional argument, OCTAVE_CONFIG.  This is the full
#   path the the octave-config used to find out the environment.
#
#   If OCTAVE_CONFIG is not set, or empty, a octave-config executable
#   is searched for using AC_PATH_TOOL.  If the executable is not
#   found, or does not return results, the Octave interpreter will be
#   used instead.
#
#   As a final check, a simple test program is compiled and linked
#   against the found Octave installation.  If the check is
#   successful, ACTION_IF_FOUND is executed, otherwise
#   ACTION_IF_NOT_FOUND.
#
#   AX_OCTAVE substitutes OCTAVE_CPPFLAGS, OCTAVE_LDFLAGS and
#   OCTAVE_LIBS, along with the optional OCTAVE_LIBRARYDIR and
#   OCTAVE_INCLUDEDIR.
#
#   Typical usage:
#
#	AX_OCTAVE([], [], [
#		AC_MSG_ERROR([[Octave required but not available]])
#		])
#	LIBS="$LIBS $OCTAVE_LIBS"
#	CPPFLAGS="$CPPFLAGS $OCTAVE_CPPFLAGS"
#	LDFLAGS="$LDFLAGS $OCTAVE_LDFLAGS"
#
# LAST MODIFICATION
#
#   2009-05-04
#
# COPYING
#
#   Copyright (c) 2009 David Grundberg
#
#   This program 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 2 of the License, or (at your
#   option) any later version.
#
#   This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
#   As a special exception, the respective Autoconf Macro's copyright owner
#   gives unlimited permission to copy, distribute and modify the configure
#   scripts that are the output of Autoconf when processing the Macro. You
#   need not follow the terms of the GNU General Public License when using
#   or distributing such scripts, even though portions of the text of the
#   Macro appear in them. The GNU General Public License (GPL) does govern
#   all other use of the material that constitutes the Autoconf Macro.
#
#   This special exception to the GPL applies to versions of the Autoconf
#   Macro released by the Autoconf Macro Archive. When you make and
#   distribute a modified version of the Autoconf Macro, you may extend this
#   special exception to the GPL to apply to your modified version as well.

AC_DEFUN([AX_OCTAVE],[
	# These are the variables AX_OCTAVE uses
	OCTAVE_LDFLAGS=
	OCTAVE_LIBS=
	OCTAVE_CPPFLAGS=
	OCTAVE_INCLUDEDIR=
	OCTAVE_LIBRARYDIR=

	AC_ARG_VAR([MKOCTFILE], [mkoctfile command])
	AC_ARG_VAR([OCTAVE], [octave command])
	AC_ARG_VAR([OCTAVE_CONFIG], [octave-config command])
	AC_ARG_VAR([OCTAVE_VERSION], [the full version of Octave to use])

	AS_IF([test -n "$OCTAVE_VERSION"],
	      [ax_octave_suffix="-$OCTAVE_VERSION"],
	      [ax_octave_suffix=""])

	AC_ARG_WITH([octave],
		    AS_HELP_STRING([--with-octave],
				   [specify root directory of Octave installation]))
	AS_IF([test -n "$with_octave"],
	      [AS_IF([test -z "$MKOCTFILE" && test -f "$with_octave/bin/mkoctfile$ax_octave_suffix"],
		     [MKOCTFILE="$with_octave/bin/mkoctfile$ax_octave_suffix"])
	       AS_IF([test -z "$OCTAVE" && test -f "$with_octave/bin/octave$ax_octave_suffix"],
		     [OCTAVE="$with_octave/bin/octave$ax_octave_suffix"])
	       AS_IF([test -z "$OCTAVE_CONFIG" && test -f "$with_octave/bin/octave-config$ax_octave_suffix"],
		     [OCTAVE_CONFIG="$with_octave/bin/octave-config$ax_octave_suffix"])],
	      [AC_CHECK_TOOLS([MKOCTFILE], [mkoctfile$ax_octave_suffix])
               AC_CHECK_TOOLS([OCTAVE], [octave$ax_octave_suffix])
               AC_CHECK_TOOLS([OCTAVE_CONFIG], [octave-config$ax_octave_suffix])])

	ax_octave_config="[$]$1"
	ax_octave_ok=

	AC_MSG_CHECKING([for octave-config filename])
	AS_IF([test -z "$ax_octave_config"], [
		AC_MSG_RESULT([determined from path])
		AC_PATH_TOOL([ax_octave_config], [octave-config], [])
		AS_IF([test -z "$ax_octave_config"], [
			AC_MSG_WARN([Could not find octave-config.])
		], [])
	], [
		AC_MSG_RESULT([specified $ax_octave_config])
	])

	AS_IF([test -n "$ax_octave_config"], [
		AC_MSG_CHECKING([for Octave library path])
		OCTAVE_LIBRARYDIR=`$ax_octave_config -p OCTLIBDIR`
		AC_MSG_RESULT([$OCTAVE_LIBRARYDIR])

		AC_MSG_CHECKING([for Octave include path])
		OCTAVE_INCLUDEDIR=`$ax_octave_config -p OCTINCLUDEDIR`
		AC_MSG_RESULT([$OCTAVE_INCLUDEDIR])
	])

	AS_IF([[test -z "$OCTAVE_LIBRARYDIR" -o -z "$OCTAVE_INCLUDEDIR"]], [
		AC_MSG_WARN([[
========================================================================
Octave library or include path not found using octave-config, trying
Octave interpreter.

This could be a sign that the Octave development package is missing.
========================================================================]])

		OCTAVE_LIBRARYDIR=
		OCTAVE_INCLUDEDIR=

		AC_MSG_NOTICE([[checking for Octave interpreter]])
		AC_PATH_TOOL([ax_octave_interpreter], [octave], [])
		AS_IF([test -z "$ax_octave_interpreter"], [
			AC_MSG_WARN([Could not find Octave interpreter.])
		], [
			AC_MSG_CHECKING([for Octave library path (alt)])
			OCTAVE_LIBRARYDIR=`$ax_octave_interpreter -q --eval "printf(octave_config_info.octlibdir)"`
			AC_MSG_RESULT([$OCTAVE_LIBRARYDIR])

			AC_MSG_CHECKING([for Octave include path (alt)])
			OCTAVE_INCLUDEDIR=`$ax_octave_interpreter -q --eval "printf(octave_config_info.octincludedir)"`
			AC_MSG_RESULT([$OCTAVE_INCLUDEDIR])
		])

		AS_IF([[test -z "$OCTAVE_LIBRARYDIR" -o -z "$OCTAVE_INCLUDEDIR"]], [
			ax_octave_ok=no
		])
	])

	AS_IF([test -z "$ax_octave_ok"], [
		if test -f "$OCTAVE_INCLUDEDIR/oct.h" ; then
			OCTAVE_INCLUDEDIR=`AS_DIRNAME(["$OCTAVE_INCLUDEDIR"])`
		fi

		OCTAVE_LDFLAGS="-L$OCTAVE_LIBRARYDIR"
		OCTAVE_LIBS="-loctinterp -loctave"
		OCTAVE_CPPFLAGS="-I$OCTAVE_INCLUDEDIR -I$OCTAVE_INCLUDEDIR/octave"

		AC_CACHE_CHECK([whether linking to Octave works], [ax_octave_cv_lib_octave],
		[
			ax_octave_cv_lib_octave=no

			AC_LANG_PUSH([C++])

			ax_octave_old_ldflags="$LDFLAGS"
			ax_octave_old_cppflags="$CPPFLAGS"
			ax_octave_old_libs="$LIBS"

			LDFLAGS="$OCTAVE_LDFLAGS $ax_octave_old_ldflags"
			CPPFLAGS="$OCTAVE_CPPFLAGS $ax_octave_old_cppflags"
			LIBS="$OCTAVE_LIBS $ax_octave_old_libs"

			AC_LANG_ASSERT(C++)
			AC_LINK_IFELSE([AC_LANG_PROGRAM(
				[[#include <octave/oct.h>
				#include <octave/Matrix.h> ]],
				[[MatrixType()]])],
				[ax_octave_cv_lib_octave=yes],
				[ax_octave_cv_lib_octave=no])

			LDFLAGS="$ax_octave_old_ldflags"
			CPPFLAGS="$ax_octave_old_cppflags"
			LIBS="$ax_octave_old_libs"

			AC_LANG_POP([C++])
		])
		AS_IF([test "x$ax_octave_cv_lib_octave" != "xyes"], [
			ax_octave_ok=no
		])
	])

	AS_IF([test -n "$ax_octave_ok"], [
		OCTAVE_LDFLAGS=
		OCTAVE_LIBS=
		OCTAVE_CPPFLAGS=
		OCTAVE_INCLUDEDIR=
		OCTAVE_LIBRARYDIR=

		AC_MSG_WARN([[
========================================================================
Can not link with Octave.

Make sure the Octave development package is installed.
========================================================================]])
	])
	AS_IF([test -z "$ax_octave_ok"], [
		AC_DEFINE([HAVE_OCTAVE], [1], [Define to 1 if you have Octave.])
		AC_DEFINE_UNQUOTED([OCTAVE_INCLUDEDIR], ["$OCTAVE_INCLUDEDIR"],
				   [Octave include directory.])
		AC_DEFINE_UNQUOTED([OCTAVE_LIBRARYDIR], ["$OCTAVE_LIBRARYDIR"],
				   [Octave library directory.])
	])

	AC_SUBST([OCTAVE_LDFLAGS])
	AC_SUBST([OCTAVE_CPPFLAGS])
	AC_SUBST([OCTAVE_LIBS])
	AC_SUBST([OCTAVE_INCLUDEDIR])
	AC_SUBST([OCTAVE_LIBRARYDIR])

	# Execute ACTION_IF_FOUND or ACTION_IF_NOT_FOUND
	if test -z "$ax_octave_ok" ; then
		m4_ifvaln([$2],[$2],[:])dnl
		m4_ifvaln([$3],[else $3])dnl
	fi

])