# HG changeset patch
# User John Donoghue
# Date 1546621476 18000
#      Fri Jan 04 12:04:36 2019 -0500
# Node ID 19eb8cbfb3df282dd985dcd6abe770639090c135
# Parent  bf3ec181282a4f2d3110dc48ec896eb15ff80524
* update to use configure

* src/Makefile.in, src/bootstrap, src/configure.ac,
  src/m4/octave-forge.m4, src/undef-ah-octave.h: new files

* src/Makefile: removed

* NEWS: add news item

diff -r bf3ec181282a -r 19eb8cbfb3df NEWS
--- a/NEWS	Thu Jun 11 12:19:38 2015 +0100
+++ b/NEWS	Fri Jan 04 12:04:36 2019 -0500
@@ -1,3 +1,8 @@
+Version 1.0.7+, released 2019-XX-XX:
+===================================
+
+ * Use configure to check for octave version specific function calls
+
 Version 1.0.7, released 2015-06-10:
 ===================================
  * Allow for extension in read_fits_image( filename, extension ) being zero to read the 
diff -r bf3ec181282a -r 19eb8cbfb3df src/Makefile
--- a/src/Makefile	Thu Jun 11 12:19:38 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-MKOCT_FLAGS = $(shell pkg-config --libs cfitsio --cflags cfitsio)
-
-all: read_fits_image.oct save_fits_image.oct save_fits_image_multi_ext.oct
-
-clean:
-	rm -f *.oct *.o
-
-%.oct: %.cc
-	mkoctfile --verbose -Wall $(MKOCT_FLAGS) $<
-
diff -r bf3ec181282a -r 19eb8cbfb3df src/Makefile.in
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Makefile.in	Fri Jan 04 12:04:36 2019 -0500
@@ -0,0 +1,35 @@
+MKOCTFILE := @MKOCTFILE@
+CXXFLAGS  := @CXXFLAGS@ @FITSIO_CXXFLAGS@ @DEFS@
+LIBS      := @LIBS@ @FITSIO_LIBS@
+LDFLAGS   := @LDFLAGS@
+
+SRC := read_fits_image.cc save_fits_image.cc save_fits_image_multi_ext.cc
+
+OBJ := $(SRC:.cc=.o)
+
+all: read_fits_image.oct save_fits_image.oct save_fits_image_multi_ext.oct
+
+%.o: %.cc
+	$(MKOCTFILE) -c $< $(CXXFLAGS)
+
+%.oct: %.o
+	$(MKOCTFILE) -o $@ $(LDFLAGS) $(LIBS) $<
+
+.PHONY: clean
+.PHONY: distclean
+.PHONY: extraclean
+.PHONY: all
+
+clean:
+	$(RM) -f *.o
+	$(RM) -f *.oct
+
+distclean: clean
+	$(RM) -rf autom4te.cache
+	$(RM) -f Makefile config.status config.log config.h
+	$(RM) -r oct-alt-includes.h
+
+extraclean: distclean
+	$(RM) -r config.h.in
+	$(RM) -r aclocal.m4
+	$(RM) -r configure
diff -r bf3ec181282a -r 19eb8cbfb3df src/bootstrap
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bootstrap	Fri Jan 04 12:04:36 2019 -0500
@@ -0,0 +1,6 @@
+#! /bin/sh
+
+## Generate ./configure
+aclocal
+autoconf
+autoheader -f
diff -r bf3ec181282a -r 19eb8cbfb3df src/configure.ac
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/configure.ac	Fri Jan 04 12:04:36 2019 -0500
@@ -0,0 +1,90 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+#
+### Copyright (C) 2019 John Donoghue <john.donoghue@ieee.org>
+###
+### 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 3 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/>.
+
+AC_PREREQ([2.67])
+AC_INIT([fits], [1.0.7])
+AC_CONFIG_HEADERS([config.h])
+
+# Avoid warnings for redefining AH-generated preprocessor symbols of
+# Octave.
+AH_TOP([#include "undef-ah-octave.h"])
+
+AC_CONFIG_MACRO_DIRS([m4])
+
+# Checks for programs.
+AC_PROG_CXX
+AC_LANG(C++)
+AC_CHECK_PROG(PKG_CONFIG, pkg-config, pkg-config)
+
+AC_CHECK_TOOL([MKOCTFILE], [mkoctfile], [none])
+if [ test "$MKOCTFILE" = "none" ]; then
+  AC_MSG_ERROR([mkoctfile required to install $PACKAGE_NAME])
+fi
+
+# checks for cfitsio
+FITSIO_CXXFLAGS=`$PKG_CONFIG --cflags cfitsio`
+FITSIO_LIBS=`$PKG_CONFIG --libs cfitsio`
+save_CXXFLAGS="$CXXFLAGS"
+CXXFLAGS="$CFITSIO_CXXFLAGS $CXXFLAGS"
+AC_CHECK_HEADER([fitsio.h])
+CXXFLAGS=$save_CXXFLAGS
+AC_SUBST([FITSIO_LIBS])
+AC_SUBST([FITSIO_CXXFLAGS])
+
+# Checks for octave depreciated symbols
+## Simple symbol alternatives of different Octave versions.
+save_altsyms_CXX="$CXX"
+save_altsyms_CXXFLAGS="$CXXFLAGS"
+save_altsyms_LDFLAGS="$LDFLAGS"
+save_altsyms_LIBS="$LIBS"
+OCTINCLUDEDIR=${OCTINCLUDEDIR:-`$MKOCTFILE -p INCFLAGS`}
+OCTLIBDIR=${OCTLIBDIR:-`$MKOCTFILE -p OCTLIBDIR`}
+CXX=`${MKOCTFILE} -p CXX`
+CXXFLAGS="$OCTINCLUDEDIR $CXXFLAGS"
+LDFLAGS="-L$OCTLIBDIR $LDFLAGS"
+LIBS="-loctinterp $LIBS"
+
+OF_OCTAVE_LIST_ALT_SYMS([
+[dnl
+  [D_NINT],
+  [octave::math::x_nint],
+  [[octave::math::x_nint (1);]],
+  [OCTAVE__D_NINT],
+  [[]],
+  [[]]
+]
+
+],[oct-alt-includes.h])
+
+CXX=$save_altsyms_CXX
+CXXFLAGS=$save_altsyms_CXXFLAGS
+LDFLAGS=$save_altsyms_LDFLAGS
+LIBS=$save_altsyms_LIBS
+
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+
+AC_MSG_NOTICE([
+
+$PACKAGE_NAME is configured with:
+  LIBS:     $LIBS $FITSIO_LIBS
+  CXXFLAGS: $CXXFLAGS $FITSION_CXXFLAGS $DEFS
+])
+
diff -r bf3ec181282a -r 19eb8cbfb3df src/m4/octave-forge.m4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/m4/octave-forge.m4	Fri Jan 04 12:04:36 2019 -0500
@@ -0,0 +1,93 @@
+# Copyright (C) 2017-2018 Olaf Till <i7tiol@t-online.de>
+# Modifications to print what is searching for by JohnD
+#
+# 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 3 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/>.
+
+# arguments of OF_OCTAVE_ALT_SYMS (see also description of
+# OF_OCTAVE_LIST_ALT_SYMS below):
+#
+# $1: symbol version 1
+# $2: symbol version 2
+# $3: test for symbol version 2
+# $4: macro name to access alternative symbols
+# $5: include directives for symbol version 1
+# $6: include directives for symbol version 2
+# (a list of lists of args 1--6 is $1 of OF_OCTAVE_LIST_ALT_SYMS)
+# $7: name of generated include file with alternatives of Octave headers
+# (arg7 is $2 of OF_OCTAVE_LIST_ALT_SYMS)
+AC_DEFUN([OF_OCTAVE_ALT_SYMS], [
+AC_MSG_CHECKING([$1 or $2])
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[#include <octave/oct.h>]
+                      $6],
+                     [$3])],
+    [AC_DEFINE($4,
+               [[$2]],
+               [macro for alternative Octave symbols])
+     AC_MSG_RESULT([$2])
+     echo '$6' >> $7],
+    [AC_DEFINE($4,
+               [[$1]],
+               [macro for alternative Octave symbols])
+     AC_MSG_RESULT([$1])
+     echo '$5' >> $7]
+)
+])
+
+
+# OF_OCTAVE_LIST_ALT_SYMS is called in the following way:
+#
+# OF_OCTAVE_LIST_ALT_SYMS([
+# [dnl
+#   [old_octave_symbol],
+#   [new_octave_symbol],
+#   [[compilation test]
+#    [for new_octave_symbol]],
+#   [NAME_OF_GENERATED_MACRO____WILL_EXPAND_TO_OLD_OR_NEW_SYMBOL],
+#   [[include directives]
+#    [except #include <octave/oct.h>]
+#    [necessary to compile with old_octave_symbol]],
+#   [[include directives]
+#    [except #include <octave/oct.h>]
+#    [nessary to compile with new_octave_symbol]
+#    [and to compile the test]]
+# ],
+#
+# ... further such lists as the above
+#
+# ],
+#
+# [name-of-header-file-for-alternative-octave-iclude-directives.h])
+#
+#
+# This file should be put into src/m4/, and the line
+#
+# AC_CONFIG_MACRO_DIRS([m4])
+#
+# should be put into src/configure.ac. The package should use
+# autoheader to generate config.h.in (src/bootstrap should contain the
+# lines 'aclocal', 'autoconf', and 'autoheader -f'). Package code
+# should include config.h and use the generated macros to access the
+# alternative symbols of Octave. An example of a call to
+# OF_OCTAVE_LIST_ALT_SYMS in src/configure.ac is available together
+# with this file.
+AC_DEFUN([OF_OCTAVE_LIST_ALT_SYMS], [
+
+echo '/* generated by configure */' > $2
+
+m4_foreach([it], [$1], [m4_apply([OF_OCTAVE_ALT_SYMS], [it, $2])])
+
+AH_BOTTOM([#include "$2"])
+
+])
diff -r bf3ec181282a -r 19eb8cbfb3df src/read_fits_image.cc
--- a/src/read_fits_image.cc	Thu Jun 11 12:19:38 2015 +0100
+++ b/src/read_fits_image.cc	Fri Jan 04 12:04:36 2019 -0500
@@ -18,6 +18,10 @@
 #include <octave/oct.h>
 #include <octave/version.h>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 extern "C"
 {
 #include "fitsio.h"
@@ -194,7 +198,7 @@
       return true;
     }
     double val = args(1).double_value();
-    if( (D_NINT( val ) !=  val) || (val < 0) )
+    if( (OCTAVE__D_NINT( val ) !=  val) || (val < 0) )
     {
       error( "read_fits_image: second argument must be a non-negative scalar integer value" );
       return true;
diff -r bf3ec181282a -r 19eb8cbfb3df src/save_fits_image.cc
--- a/src/save_fits_image.cc	Thu Jun 11 12:19:38 2015 +0100
+++ b/src/save_fits_image.cc	Fri Jan 04 12:04:36 2019 -0500
@@ -18,6 +18,10 @@
 #include <sstream>
 #include <octave/oct.h>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 extern "C"
 {
 #include "fitsio.h"
@@ -81,7 +85,7 @@
     else if( args(2).is_scalar_type() )
     {
       double val = args(2).double_value();
-      if( (D_NINT( val ) ==  val) )
+      if( (OCTAVE__D_NINT( val ) ==  val) )
       {
         if( BYTE_IMG == val )
           bitperpixel = BYTE_IMG;
diff -r bf3ec181282a -r 19eb8cbfb3df src/save_fits_image_multi_ext.cc
--- a/src/save_fits_image_multi_ext.cc	Thu Jun 11 12:19:38 2015 +0100
+++ b/src/save_fits_image_multi_ext.cc	Fri Jan 04 12:04:36 2019 -0500
@@ -18,6 +18,10 @@
 #include <sstream>
 #include <octave/oct.h>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 extern "C"
 {
 #include "fitsio.h"
@@ -78,7 +82,7 @@
     else if( args(2).is_scalar_type() )
     {
       double val = args(2).double_value();
-      if( (D_NINT( val ) ==  val) )
+      if( (OCTAVE__D_NINT( val ) ==  val) )
       {
         if( BYTE_IMG == val )
           bitperpixel = BYTE_IMG;
diff -r bf3ec181282a -r 19eb8cbfb3df src/undef-ah-octave.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/undef-ah-octave.h	Fri Jan 04 12:04:36 2019 -0500
@@ -0,0 +1,27 @@
+/* To be included at the top of config.h (by autoheader). Avoid
+   warnings for redefining AH-generated preprocessor symbols of
+   Octave. */
+
+#ifdef PACKAGE_BUGREPORT
+#undef PACKAGE_BUGREPORT
+#endif
+
+#ifdef PACKAGE_NAME
+#undef PACKAGE_NAME
+#endif
+
+#ifdef PACKAGE_STRING
+#undef PACKAGE_STRING
+#endif
+
+#ifdef PACKAGE_TARNAME
+#undef PACKAGE_TARNAME
+#endif
+
+#ifdef PACKAGE_URL
+#undef PACKAGE_URL
+#endif
+
+#ifdef PACKAGE_VERSION
+#undef PACKAGE_VERSION
+#endif
