# @configure_input@
#
# Common configuration rules for all of octave's Makefiles.
#
# Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
#               2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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/>.
 
SHELL = /bin/sh

AWK = @AWK@
export AWK

SED = @SED@
export SED

FIND = @FIND@
export FIND

PERL = @PERL@
export PERL

PYTHON = @PYTHON@

GNUPLOT = @GNUPLOT@

DESKTOP_FILE_INSTALL = @DESKTOP_FILE_INSTALL@

# A shell command to extract the version number from version.h.
getversion = $(SED) -e '/OCTAVE_VERSION/!d' -e 's/.*"\(.*\)".*$$/\1/' -e q

# A shell command to extract the API version number from version.h.
getapiversion = $(SED) -e '/OCTAVE_API_VERSION/!d' -e 's/.*"\(.*\)".*$$/\1/' -e q

# Look for version.h to get version information.
xfiles := $(TOPDIR)/src/version.h $(srcdir)/$(TOPDIR)/src/version.h
version_file := $(firstword $(foreach file, $(xfiles), $(wildcard $(file))))
version := $(shell $(getversion) $(version_file))
api_version := $(shell $(getapiversion) $(version_file))

#### Start of system configuration section. ####

EXEEXT = @EXEEXT@

BUILD_EXEEXT = @BUILD_EXEEXT@

LEX = @LEX@
LFLAGS = @LFLAGS@
LEXLIB = @LEXLIB@

YACC = @YACC@
YFLAGS = -dv

GPERF = @GPERF@

AR = @AR@
ARFLAGS = @ARFLAGS@ 

TEMPLATE_AR = @TEMPLATE_AR@
TEMPLATE_ARFLAGS = @TEMPLATE_ARFLAGS@

RANLIB = @RANLIB@

LN_S = @LN_S@

MAKEINFO = @MAKEINFO@
TEXI2DVI = @TEXI2DVI@
TEXI2PDF = @TEXI2PDF@

GHOSTSCRIPT = @GHOSTSCRIPT@

DEFAULT_PAGER = @DEFAULT_PAGER@

ENABLE_DYNAMIC_LINKING = @ENABLE_DYNAMIC_LINKING@

STATIC_LIBS = @STATIC_LIBS@

SHARED_LIBS = @SHARED_LIBS@
SHLEXT = @SHLEXT@
SHLEXT_VER = @SHLEXT_VER@
SHLLIB = @SHLLIB@
SHLLIB_VER = @SHLLIB_VER@
SHLBIN = @SHLBIN@
SHLBIN_VER = @SHLBIN_VER@
SHLLINKEXT=

LIBEXT = a
LIBPRE = @LIBPRE@
SHLPRE = @SHLPRE@
SHLLIBPRE = @SHLLIBPRE@
SHLBINPRE = @SHLBINPRE@

# Fortran compiler flags.

FC = @FC@
F77 = @F77@
FFLAGS = @FFLAGS@
FPICFLAG = @FPICFLAG@
ALL_FFLAGS = $(FFLAGS)
F77_FLOAT_STORE_FLAG = @F77_FLOAT_STORE_FLAG@

F77_TOLOWER=@F77_TOLOWER@
F77_APPEND_UNDERSCORE=@F77_TOLOWER@
F77_APPEND_EXTRA_UNDERSCORE=@F77_TOLOWER@

# cc and associated flags.

# Clean up INCFLAGS a bit if we are not compiling in a separate
# directory.
ifeq ($(srcdir),.)
  TMP_IF_1 = -I.
else
  TMP_IF_1 = -I. -I$(srcdir)
endif
ifeq ($(TOPDIR),$(top_srcdir))
  TMP_IF_2 = \
    -I$(TOPDIR) \
    -I$(TOPDIR)/liboctave \
    -I$(TOPDIR)/src \
    -I$(TOPDIR)/libcruft/misc
else
  TMP_IF_2 = \
    -I$(TOPDIR) \
    -I$(TOPDIR)/liboctave \
    -I$(TOPDIR)/src \
    -I$(TOPDIR)/libcruft/misc \
    -I$(top_srcdir) \
    -I$(top_srcdir)/liboctave \
    -I$(top_srcdir)/src \
    -I$(top_srcdir)/libcruft/misc
endif
INCFLAGS = $(TMP_IF_1) $(TMP_IF_2)

X11_INCFLAGS = @X11_INCFLAGS@
X11_LIBS = @X11_LIBS@

CARBON_LIBS = @CARBON_LIBS@

MAGICK_CONFIG = @MAGICK_CONFIG@
MAGICK_INCFLAGS = $(shell $(MAGICK_CONFIG) --cppflags)
MAGICK_LIBS = $(shell $(MAGICK_CONFIG) --libs)

LIBFLAGS = -L$(TOPDIR)

DEFS = @DEFS@

UGLY_DEFS = @UGLY_DEFS@

CC = @CC@
CC_VERSION = @CC_VERSION@
CFLAGS = @CFLAGS@
CPICFLAG = @CPICFLAG@
XTRA_CFLAGS = @XTRA_CFLAGS@
WARN_CFLAGS = @WARN_CFLAGS@
ALL_CFLAGS = $(INCFLAGS) $(DLL_CDEFS) $(DEFS) $(XTRA_CFLAGS) $(WARN_CFLAGS) $(CFLAGS)
BUG_CFLAGS = $(DEFS) $(XTRA_CFLAGS) $(WARN_CFLAGS) $(CFLAGS)

BUILD_CC = @BUILD_CC@
BUILD_CFLAGS = @BUILD_CFLAGS@

DEPEND_FLAGS = @DEPEND_FLAGS@
DEPEND_EXTRA_SED_PATTERN = @DEPEND_EXTRA_SED_PATTERN@
INCLUDE_DEPS = @INCLUDE_DEPS@
ifeq ($(INCLUDE_DEPS),false)
  omit_deps = true;
endif

GRAPHICS_CFLAGS = @GRAPHICS_CFLAGS@

CXX = @CXX@
CXX_VERSION = @CXX_VERSION@
CXXCPP = @CXXCPP@
CXXFLAGS = @CXXFLAGS@
CXXPICFLAG = @CXXPICFLAG@
XTRA_CXXFLAGS = @XTRA_CXXFLAGS@
WARN_CXXFLAGS = @WARN_CXXFLAGS@
ALL_CXXFLAGS = \
  $(INCFLAGS) $(DLL_CXXDEFS) $(DEFS) $(XTRA_CXXFLAGS) $(WARN_CXXFLAGS) $(CXXFLAGS)
BUG_CXXFLAGS = $(DEFS) $(XTRA_CXXFLAGS) $(WARN_CXXFLAGS) $(CXXFLAGS)

BUILD_CXX = @BUILD_CXX@
BUILD_CXXFLAGS = @BUILD_CXXFLAGS@

CPPFLAGS = @CPPFLAGS@

LD_CXX = @LD_CXX@
LDFLAGS = @LDFLAGS@
LD_STATIC_FLAG = @LD_STATIC_FLAG@
ALL_LDFLAGS = $(LIBFLAGS) $(LD_STATIC_FLAG) $(CPICFLAG) $(LDFLAGS)

BUILD_LDFLAGS = @BUILD_LDFLAGS@

SH_LD = @SH_LD@
SH_LDFLAGS = @SH_LDFLAGS@

DL_LD = @DL_LD@
DL_LDFLAGS = @DL_LDFLAGS@

SONAME_FLAGS = @SONAME_FLAGS@

RDYNAMIC_FLAG = @RDYNAMIC_FLAG@

RLD_FLAG = @RLD_FLAG@

FLIBS = @FLIBS@

LIBGLOB = @LIBGLOB@
LIBOCTINTERP = @LIBOCTINTERP@
LIBOCTAVE = @LIBOCTAVE@
LIBCRUFT = @LIBCRUFT@
LIBREADLINE = @LIBREADLINE@
TERMLIBS = @TERMLIBS@

FT2_LIBS = @FT2_LIBS@
GRAPHICS_LIBS = @GRAPHICS_LIBS@
QHULL_LIBS = @QHULL_LIBS@
REGEX_LIBS = @REGEX_LIBS@
BLAS_LIBS = @BLAS_LIBS@
FFTW_LIBS = @FFTW_LIBS@
GLPK_LIBS = @GLPK_LIBS@
CURL_LIBS = @CURL_LIBS@
AMD_LIBS = @AMD_LIBS@
CAMD_LIBS = @CAMD_LIBS@
UMFPACK_LIBS = @UMFPACK_LIBS@
COLAMD_LIBS = @COLAMD_LIBS@
CCOLAMD_LIBS = @CCOLAMD_LIBS@
CHOLMOD_LIBS = @CHOLMOD_LIBS@
CXSPARSE_LIBS = @CXSPARSE_LIBS@
OPENGL_LIBS = @OPENGL_LIBS@
QRUPDATE_LIBS = @QRUPDATE_LIBS@
ARPACK_LIBS = @ARPACK_LIBS@
LIBS = @LIBS@

USE_64_BIT_IDX_T = @USE_64_BIT_IDX_T@

TEXINFO_COLAMD = @TEXINFO_COLAMD@
TEXINFO_CHOLMOD = @TEXINFO_CHOLMOD@
TEXINFO_UMFPACK = @TEXINFO_UMFPACK@
TEXINFO_QHULL = @TEXINFO_QHULL@

# The arguments passed to configure.
config_opts = @config_opts@

CONFIG_SUBDIRS = @subdirs@

# ==================== Where To Install Things ====================

# The default location for installation.  Everything is placed in
# subdirectories of this directory.  The default values for many of
# the variables below are expressed in terms of this one, so you may
# not need to change them.  This defaults to /usr/local.
prefix = @prefix@

# Like `prefix', but used for architecture-specific files.
exec_prefix = @exec_prefix@

# Where to install Octave and other binaries that people will want to
# run directly.
bindir = @bindir@

# Normally the directory for installing executables that system
# administrators run.  This is the same as libexecdir on Cygwin systems.
sbindir = @sbindir@

# The root of the directory tree for read-only
# architecture-independent data files.
datarootdir = @datarootdir@

# Where to install architecture-independent data files.  ${fcnfiledir}
# and ${localfcnfiledir} are subdirectories of this.
datadir = @datadir@

libdir = @libdir@

# Where to install and expect extra files like NEWS and doc-cache.
octetcdir = @octetcdir@

# Where to install and expect libraries like libcruft.a, liboctave.a,
# and other architecture-dependent data.
octlibdir = @octlibdir@

# Where to install and expect executable programs to be run by Octave
# rather than directly by users.
libexecdir = @libexecdir@

# The prefix for Octave's include file directory.  The default is
# ${prefix}/include
includedir = @includedir@

# Where to install Octave's man pages, and what extension they should
# have.  The default is ${prefix}/man/man1
mandir = @mandir@
man1dir = @man1dir@
man1ext = @man1ext@

# The full path to the default doc cache file.
doc_cache_file = @doc_cache_file@

# Where to install and expect the info files describing Octave..
infodir = @infodir@

# The full path to the default info file.
infofile = @infofile@

# ==================== Octave-specific directories ====================

# These variables hold the values specific to Octave.  They are
# based on the values of the standard Make variables above.

# What is the path separation character
sepchar = @sepchar@

# Where to install Octave's include files (they will actually be
# installed in a subdirectory called octave).  The default is
# ${includedir}/octave-${version}
octincludedir = @octincludedir@

# Where to install the function file distributed with
# Octave.  This includes the Octave version, so that the
# function files for different versions of Octave will install
# themselves in separate directories.
fcnfiledir = @fcnfiledir@

# Directories Octave should search for function files specific
# to this site (i.e. customizations), before consulting
# ${fcnfiledir}.  This should be a colon-separated list of
# directories.
localfcnfiledir = @localfcnfiledir@
localapifcnfiledir = @localapifcnfiledir@
localverfcnfiledir = @localverfcnfiledir@

# Where to put executables to be run by Octave rather than
# the user.  This path usually includes the Octave version
# and configuration name, so that multiple configurations
# for multiple versions of Octave may be installed at once.
archlibdir = @archlibdir@

# Where to put executables to be run by Octave rather than by the
# user that are specific to this site.
localarchlibdir = @localarchlibdir@
localapiarchlibdir = @localapiarchlibdir@
localverarchlibdir = @localverarchlibdir@

# Where to put object files that will by dynamically loaded.
# This path usually includes the Octave version and configuration
# name, so that multiple configurations for multiple versions of
# Octave may be installed at once. 
octfiledir = @octfiledir@

# Directories Octave should search for object files that will be
# dynamically loaded and that are specific to this site
# (i.e. customizations), before consulting ${octfiledir}.  This should
# be a colon-separated list of directories.
localoctfiledir = @localoctfiledir@
localapioctfiledir = @localapioctfiledir@
localveroctfiledir = @localveroctfiledir@

# Where Octave will search to find image files.
imagedir = @imagedir@

# The type of computer we are running on.
canonical_host_type = @canonical_host_type@

# Where Octave will look for startup files
startupfiledir = ${fcnfiledir}/startup
localstartupfiledir = ${localfcnfiledir}/startup

# LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, PATH, ...
library_path_var = @library_path_var@

NO_OCT_FILE_STRIP = @NO_OCT_FILE_STRIP@

# The following pattern rules and the substitution functions require
# GNU make.  If you don't have it, get it!

# How to make .o files:

%.o : %.f
	$(FC) -c $(ALL_FFLAGS) -o $@ $<

%.o : %.c
	$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $< -o $@

%.o : %.cc
	$(CXX) -c $(CPPFLAGS) $(ALL_CXXFLAGS) $< -o $@

pic/%.o : %.f
	$(FC) -c $(FPICFLAG) $(ALL_FFLAGS) $< -o $@

pic/%.o : %.c
	$(CC) -c $(CPPFLAGS) $(CPICFLAG) $(ALL_CFLAGS) $< -o $@

pic/%.o : %.cc
	$(CXX) -c $(CPPFLAGS) $(CXXPICFLAG) $(ALL_CXXFLAGS) $< -o $@

# Here is a rule for generating dependencies for .cc files:

%.d : %.cc
	@echo making $@ from $<
	@rm -f $@
	@$(CXX) $(DEPEND_FLAGS) $(CPPFLAGS) $(ALL_CXXFLAGS) $< | \
	  $(SED) \
              $(DEPEND_EXTRA_SED_PATTERN) \
	      -e 's,^[^:]*/\(.*\.o\):,\1:,' \
	      -e 's,$*\.o,pic/& & $*.df $@,g' > $@-t
	@mv $@-t $@

# And one for .c files.too:

%.d : %.c
	@echo making $@ from $<
	@rm -f $@
	@$(CC) $(DEPEND_FLAGS) $(CPPFLAGS) $(ALL_CFLAGS) $< | \
	  $(SED) \
              $(DEPEND_EXTRA_SED_PATTERN) \
	      -e 's,^[^:]*/\(.*\.o\):,\1:,' \
	      -e 's,$*\.o,pic/& & $@,g' > $@-t
	@mv $@-t $@

define do-subdir-for-command
echo making $@ in $d; $(MAKE) -C $d $@;
endef

define subdir-for-command
$(foreach d, $(SUBDIRS), $(do-subdir-for-command))
endef

define simple-move-if-change-rule
if [ -s $@-t ]; then \
  $(top_srcdir)/move-if-change $@-t $@; \
else \
  echo "$@-t is empty!" 1>&2; \
  rm -f $@-t; \
  exit 1; \
fi
endef

define builddir-move-if-change-rule
if [ -s $(@F)-t ]; then \
  $(top_srcdir)/move-if-change $(@F)-t $(@F); \
else \
  echo "$(@F)-t is empty!" 1>&2; \
  rm -f $(@F)-t; \
  exit 1; \
fi
endef

# Yes, the second sed command near the end is needed, to avoid limits
# in command lengths for some versions of sed.  UGLY_DEFS is often
# quite large, so it makes sense to split this command there.

define do-subst-config-vals
echo "making $@ from $<"
$(SED) < $< \
  -e "s|%NO_OCT_FILE_STRIP%|${NO_OCT_FILE_STRIP}|" \
  -e "s|%OCTAVE_BINDIR%|\"${bindir}\"|" \
  -e "s|%OCTAVE_CONF_ALL_CFLAGS%|\"${ALL_CFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_ALL_CXXFLAGS%|\"${ALL_CXXFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_ALL_FFLAGS%|\"${ALL_FFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_ALL_LDFLAGS%|\"${ALL_LDFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_AR%|\"${AR}\"|" \
  -e "s|%OCTAVE_CONF_ARFLAGS%|\"${ARFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_BLAS_LIBS%|\"${BLAS_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_CANONICAL_HOST_TYPE%|\"${canonical_host_type}\"|" \
  -e "s|%OCTAVE_CONF_CARBON_LIBS%|\"${CARBON_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_CC%|\"${CC}\"|" \
  -e "s|%OCTAVE_CONF_CC_VERSION%|\"${CC_VERSION}\"|" \
  -e "s|%OCTAVE_CONF_CFLAGS%|\"${CFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_CPICFLAG%|\"${CPICFLAG}\"|" \
  -e "s|%OCTAVE_CONF_CPPFLAGS%|\"${CPPFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_CURL_LIBS%|\"${CURL_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_CXX%|\"${CXX}\"|" \
  -e "s|%OCTAVE_CONF_CXXCPP%|\"${CXXCPP}\"|" \
  -e "s|%OCTAVE_CONF_CXXFLAGS%|\"${CXXFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_CXXPICFLAG%|\"${CXXPICFLAG}\"|" \
  -e "s|%OCTAVE_CONF_CXX_VERSION%|\"${CXX_VERSION}\"|" \
  -e "s|%OCTAVE_CONF_DEFAULT_PAGER%|\"${DEFAULT_PAGER}\"|" \
  -e "s|%OCTAVE_CONF_DEPEND_FLAGS%|\"${DEPEND_FLAGS}\"|" \
  -e "s|%OCTAVE_CONF_DEPEND_EXTRA_SED_PATTERN%|\"${DEPEND_EXTRA_SED_PATTERN}\"|" \
  -e "s|%OCTAVE_CONF_DL_LD%|\"${DL_LD}\"|" \
  -e "s|%OCTAVE_CONF_DL_LDFLAGS%|\"${DL_LDFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_EXEEXT%|\"${EXEEXT}\"|" \
  -e "s|%OCTAVE_CONF_F77%|\"${F77}\"|" \
  -e "s|%OCTAVE_CONF_F77_FLOAT_STORE_FLAG%|\"${F77_FLOAT_STORE_FLAG}\"|" \
  -e "s|%OCTAVE_CONF_FC%|\"${FC}\"|" \
  -e "s|%OCTAVE_CONF_FFLAGS%|\"${FFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_FFTW_LIBS%|\"${FFTW_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_FLIBS%|\"${FLIBS}\"|" \
  -e "s|%OCTAVE_CONF_FPICFLAG%|\"${FPICFLAG}\"|" \
  -e "s|%OCTAVE_CONF_GLPK_LIBS%|\"${GLPK_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_GNUPLOT%|\"${GNUPLOT}\"|" \
  -e "s|%OCTAVE_CONF_INCFLAGS%|\"${INCFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_INCLUDEDIR%|\"${includedir}\"|" \
  -e "s|%OCTAVE_CONF_LD_CXX%|\"${LD_CXX}\"|" \
  -e "s|%OCTAVE_CONF_LDFLAGS%|\"${LDFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_LD_STATIC_FLAG%|\"${LD_STATIC_FLAG}\"|" \
  -e "s|%OCTAVE_CONF_LEX%|\"${LEX}\"|" \
  -e "s|%OCTAVE_CONF_LEXLIB%|\"${LEXLIB}\"|" \
  -e "s|%OCTAVE_CONF_LFLAGS%|\"${LFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_LIBCRUFT%|\"${LIBCRUFT}\"|" \
  -e "s|%OCTAVE_CONF_LIBDIR%|\"${libdir}\"|" \
  -e "s|%OCTAVE_CONF_LIBEXT%|\"${LIBEXT}\"|" \
  -e "s|%OCTAVE_CONF_LIBFLAGS%|\"${LIBFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_LIBGLOB%|\"${LIBGLOB}\"|" \
  -e "s|%OCTAVE_CONF_LIBOCTAVE%|\"${LIBOCTAVE}\"|" \
  -e "s|%OCTAVE_CONF_LIBOCTINTERP%|\"${LIBOCTINTERP}\"|" \
  -e "s|%OCTAVE_CONF_LIBREADLINE%|\"${LIBREADLINE}\"|" \
  -e "s|%OCTAVE_CONF_LIBS%|\"${LIBS}\"|" \
  -e "s|%OCTAVE_CONF_LN_S%|\"${LN_S}\"|" \
  -e "s|%OCTAVE_CONF_MAGICK_INCFLAGS%|\"${MAGICK_INCFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_MAGICK_LIBS%|\"${MAGICK_LIBS}\"|" \
  -e 's|%OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS%|\"@MKOCTFILE_DL_LDFLAGS@\"|' \
  -e "s|%OCTAVE_CONF_OCTINCLUDEDIR%|\"${octincludedir}\"|" \
  -e "s|%OCTAVE_CONF_OCTLIBDIR%|\"${octlibdir}\"|" \
  -e "s|%OCTAVE_CONF_PREFIX%|\"${prefix}\"|" \
  -e "s|%OCTAVE_CONF_RANLIB%|\"${RANLIB}\"|" \
  -e "s|%OCTAVE_CONF_RDYNAMIC_FLAG%|\"${RDYNAMIC_FLAG}\"|" \
  -e "s|%OCTAVE_CONF_RLD_FLAG%|\"${RLD_FLAG}\"|" \
  -e "s|%OCTAVE_CONF_SED%|\"${SED}\"|" \
  -e "s|%OCTAVE_CONF_SHARED_LIBS%|\"${SHARED_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_SHLEXT%|\"${SHLEXT}\"|" \
  -e "s|%OCTAVE_CONF_SHLLINKEXT%|\"${SHLLINKEXT}\"|" \
  -e "s|%OCTAVE_CONF_SHLEXT_VER%|\"${SHLEXT_VER}\"|" \
  -e "s|%OCTAVE_CONF_SH_LD%|\"${SH_LD}\"|" \
  -e "s|%OCTAVE_CONF_SH_LDFLAGS%|\"${SH_LDFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_SONAME_FLAGS%|\"${SONAME_FLAGS}\"|" \
  -e "s|%OCTAVE_CONF_STATIC_LIBS%|\"${STATIC_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_UGLY_DEFS%|\"${UGLY_DEFS}\"|" \
  -e "s|%OCTAVE_CONF_USE_64_BIT_IDX_T%|\"${USE_64_BIT_IDX_T}\"|" \
  -e "s|%OCTAVE_CONF_VERSION%|\"${version}\"|" \
  -e "s|%OCTAVE_CONF_ENABLE_DYNAMIC_LINKING%|\"${ENABLE_DYNAMIC_LINKING}\"|" \
  -e "s|%OCTAVE_CONF_X11_INCFLAGS%|\"${X11_INCFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_X11_LIBS%|\"${X11_LIBS}\"|" \
  -e "s|%OCTAVE_CONF_XTRA_CFLAGS%|\"${XTRA_CFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_XTRA_CXXFLAGS%|\"${XTRA_CXXFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_YACC%|\"${YACC}\"|" \
  -e "s|%OCTAVE_CONF_YFLAGS%|\"${YFLAGS}\"|" \
  -e "s|%OCTAVE_CONF_config_opts%|\"${config_opts}\"|" | \
  $(SED)  -e "s|%OCTAVE_CONF_DEFS%|\"${UGLY_DEFS}\"|" > $@-t
$(simple-move-if-change-rule)
endef

define do-subst-default-vals
echo "making $@ from $<"
$(SED) < $< > $@-t \
  -e "s|%OCTAVE_ARCHLIBDIR%|\"${archlibdir}\"|" \
  -e "s|%OCTAVE_BINDIR%|\"${bindir}\"|" \
  -e "s|%OCTAVE_CANONICAL_HOST_TYPE%|\"${canonical_host_type}\"|" \
  -e "s|%OCTAVE_DATADIR%|\"${datadir}\"|" \
  -e "s|%OCTAVE_DATAROOTDIR%|\"${datarootdir}\"|" \
  -e "s|%OCTAVE_DEFAULT_PAGER%|\"${DEFAULT_PAGER}\"|" \
  -e "s|%OCTAVE_DOC_CACHE_FILE%|\"${doc_cache_file}\"|" \
  -e "s|%OCTAVE_EXEC_PREFIX%|\"${exec_prefix}\"|" \
  -e "s|%OCTAVE_FCNFILEDIR%|\"${fcnfiledir}\"|" \
  -e "s|%OCTAVE_IMAGEDIR%|\"${imagedir}\"|" \
  -e "s|%OCTAVE_INCLUDEDIR%|\"${includedir}\"|" \
  -e "s|%OCTAVE_INFODIR%|\"${infodir}\"|" \
  -e "s|%OCTAVE_INFOFILE%|\"${infofile}\"|" \
  -e "s|%OCTAVE_LIBDIR%|\"${libdir}\"|" \
  -e "s|%OCTAVE_LIBEXECDIR%|\"${libexecdir}\"|" \
  -e "s|%OCTAVE_LOCALAPIFCNFILEDIR%|\"${localapifcnfiledir}\"|" \
  -e "s|%OCTAVE_LOCALAPIOCTFILEDIR%|\"${localapioctfiledir}\"|" \
  -e "s|%OCTAVE_LOCALARCHLIBDIR%|\"${localarchlibdir}\"|" \
  -e "s|%OCTAVE_LOCALFCNFILEDIR%|\"${localfcnfiledir}\"|" \
  -e "s|%OCTAVE_LOCALOCTFILEDIR%|\"${localoctfiledir}\"|" \
  -e "s|%OCTAVE_LOCALSTARTUPFILEDIR%|\"${localstartupfiledir}\"|" \
  -e "s|%OCTAVE_LOCALAPIARCHLIBDIR%|\"${localapiarchlibdir}\"|" \
  -e "s|%OCTAVE_LOCALVERARCHLIBDIR%|\"${localverarchlibdir}\"|" \
  -e "s|%OCTAVE_LOCALVERFCNFILEDIR%|\"${localverfcnfiledir}\"|" \
  -e "s|%OCTAVE_LOCALVEROCTFILEDIR%|\"${localveroctfiledir}\"|" \
  -e "s|%OCTAVE_MAN1DIR%|\"${man1dir}\"|" \
  -e "s|%OCTAVE_MAN1EXT%|\"${man1ext}\"|" \
  -e "s|%OCTAVE_MANDIR%|\"${mandir}\"|" \
  -e "s|%OCTAVE_OCTFILEDIR%|\"${octfiledir}\"|" \
  -e "s|%OCTAVE_OCTETCDIR%|\"${octetcdir}\"|" \
  -e "s|%OCTAVE_OCTINCLUDEDIR%|\"${octincludedir}\"|" \
  -e "s|%OCTAVE_OCTLIBDIR%|\"${octlibdir}\"|" \
  -e "s|%OCTAVE_STARTUPFILEDIR%|\"${startupfiledir}\"|" \
  -e "s|%OCTAVE_PREFIX%|\"${prefix}\"|" \
  -e "s|%OCTAVE_API_VERSION%|\"${api_version}\"|" \
  -e "s|%OCTAVE_RELEASE%|\"${OCTAVE_RELEASE}\"|" \
  -e "s|%OCTAVE_VERSION%|\"${version}\"|"
$(simple-move-if-change-rule)
endef

define do-subst-texinfo-vals
echo "making $@ from $<"
$(SED) < $< \
  -e "s|%abs_top_srcdir%|${abs_top_srcdir}|" \
  -e "s|%top_srcdir%|${top_srcdir}|" \
  -e "s|%OCTAVE_HOME%|${prefix}|" \
  -e "s|%OCTAVE_VERSION%|${version}|" \
  -e "s|%TEXINFO_COLAMD%|${TEXINFO_COLAMD}|" \
  -e "s|%TEXINFO_CHOLMOD%|${TEXINFO_CHOLMOD}|" \
  -e "s|%TEXINFO_UMFPACK%|${TEXINFO_UMFPACK}|" \
  -e "s|%TEXINFO_QHULL%|${TEXINFO_QHULL}|" | \
  $(SED) -e "s|%OCTAVE_CONF_DEFS%|\"${UGLY_DEFS}\"|" > $@-t
$(simple-move-if-change-rule)
endef

define do-subst-script-vals
echo "making $@ from $<"
$(SED) < $< \
  -e "s|%AWK%|${AWK}|g" \
  -e "s|%FIND%|${FIND}|g" \
  -e "s|%SED%|${SED}|g" \
  -e "s|%library_path_var%|${library_path_var}|g" \
  -e "s|%liboctinterp%|${SHLPRE}octinterp.${SHLEXT}|g" \
  -e "s|%liboctave%|${SHLPRE}octave.${SHLEXT}|g" \
  -e "s|%libcruft%|${SHLPRE}cruft.${SHLEXT}|g" \
  -e "s|%srcdir%|${srcdir}|" \
  -e "s|%top_srcdir%|${top_srcdir}|" \
  -e "s|%abs_top_srcdir%|${abs_top_srcdir}|" \
  -e "s|%builddir%|$(shell pwd)|" > $@-t
$(simple-move-if-change-rule)
endef

define do-subst-f77-mangling
echo "making $@ from $<"
$(SED) < $< \
  -e "s|%F77_TOLOWER%|${F77_TOLOWER}|g" \
  -e "s|%F77_APPEND_UNDERSCORE%|${F77_APPEND_UNDERSCORE}|" \
  -e "s|%F77_APPEND_EXTRA_UNDERSCORE%|${F77_APPEND_EXTRA_UNDERSCORE}|" > $@-t
$(simple-move-if-change-rule)
endef

define do-mkpkgadd
$(top_srcdir)/mkpkgadd $(srcdir) > PKG_ADD.t
if [ -n "`cat PKG_ADD.t`" ]; then \
  mv PKG_ADD.t PKG_ADD ; \
else \
  rm -f PKG_ADD.t ; \
fi
endef

define do-script-install
$(top_srcdir)/mkinstalldirs \
  $(addprefix $(DESTDIR), $(fcnfiledir)/$(script_sub_dir))
for f in $(FCN_FILES); do \
  fbase=`basename $$f`; \
  rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$fbase; \
  $(INSTALL_DATA) $$f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$fbase; \
done
$(top_srcdir)/mkpkgadd $(DESTDIR)$(fcnfiledir)/$(script_sub_dir) > $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/PKG_ADD.t
if [ -n "`cat $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/PKG_ADD.t`" ]; then \
  $(INSTALL_DATA) $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/PKG_ADD.t $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/PKG_ADD ; \
else \
  rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/PKG_ADD.t ; \
fi
endef

define do-script-uninstall
for f in $(FCN_FILES_NO_DIR); \
  do rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/$$f; \
done
rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/PKG_ADD
-rmdir $(addprefix $(DESTDIR), $(fcnfiledir)/$(script_sub_dir))
endef

define do-check-m-sources
for f in $(notdir $(wildcard $(srcdir)/*.m)); do \
  found=false; \
  for m in $(SOURCES); do \
    if [ "$$f" = "$$m" ]; then \
      found=true; \
      break; \
    fi; \
  done; \
  if $$found; then \
    true; \
  else \
    echo "$(script_sub_dir)/$$f: not listed in SOURCES"; \
  fi; \
done
endef
