1## Copyright (C) 2020 David Miguel Susano Pinto <carandraug@octave.org>
2##
3## Copying and distribution of this file, with or without modification,
4## are permitted in any medium without royalty provided the copyright
5## notice and this notice are preserved.  This file is offered as-is,
6## without any warranty.
7
8AC_PREREQ([2.67])
9AC_INIT([Octave-Forge image package], [2.12.0])
10
11AC_CONFIG_HEADERS([config.h])
12
13AC_PROG_SED
14
15AC_PATH_PROG([OCTAVE], [octave])
16if test -z "$OCTAVE"; then
17  AC_MSG_ERROR([*** 'octave' not found.])
18fi
19
20AC_PATH_PROG([MKOCTFILE], [mkoctfile])
21if test -z "$MKOCTFILE"; then
22  AC_MSG_ERROR([*** 'mkoctfile' not found.])
23fi
24
25dnl CXX is the compiler including options such as -std=c++11.
26dnl CXXFLAGS are flags for CXX coming from the environment.
27dnl XTRA_CXXFLAGS are extra flags that we want to set ourselves.
28
29
30dnl We will not actually use CXX in the build, we only use mkoctfile
31dnl which picks up the dnl CXX environment variable and defaults to what
32dnl was used to build Octave.  However, that may not be enough for our
33dnl C++11 dependency (Octave 4.0 did not require C++11) so we set CXX
34dnl ourselves, check if any extra flag was needed, and then use that
35dnl on MKOCTFILE.
36
37CXX=`${MKOCTFILE} -p CXX`
38image_save_CXX="$CXX"
39
40AC_PROG_CXX
41if test "x$ac_prog_cxx_stdcxx" != "xcxx11"; then
42  AC_MSG_ERROR([** could not find a C++11 compiler])
43fi
44
45CXX11_SWITCH=$(echo "$CXX" | $SED "s,^$image_save_CXX,,")
46MKOCTFILE="$MKOCTFILE $CXX11_SWITCH"
47CXX="$image_save_CXX"
48
49
50dnl Pick up any warnings as soon as possible.
51XTRA_CXXFLAGS="-Wall"
52
53
54AC_LANG(C++)
55
56
57image_save_CXXFLAGS="$CXXFLAGS"
58CXXFLAGS="$CXXFLAGS -I`$MKOCTFILE -p OCTINCLUDEDIR`"
59
60## Starting with Octave 4.2, functions have been moved into the octave
61## namespace.  While the old ones still exist and are deprecated,
62## warnings scare users.  So check for their correct location and wrap
63## them if needed.
64
65## feval was moved into octave:: during 4.3 development series.
66AC_CACHE_CHECK(
67  [whether feval is in the octave namespace],
68  [octave_image_cv_feval_in_octave_namespace],
69  [AC_COMPILE_IFELSE(
70    [AC_LANG_PROGRAM([#include <parse.h>],
71                     [octave::feval ("eye")])],
72    [octave_image_cv_feval_in_octave_namespace=yes],
73    [octave_image_cv_feval_in_octave_namespace=no])])
74
75if test "$octave_image_cv_feval_in_octave_namespace" = yes; then
76  AC_DEFINE([HAVE_FEVAL_IN_OCTAVE_NAMESPACE], [1],
77            [Define if octave::feval exists as replacement to feval.])
78fi
79
80## Sometime during 4.3 development, the is_* style methods were
81## deprecated in favour of others whose names match the functions
82## in the Octave language:
83##   is_bool_type    -> islogical
84##   is_complex_type -> iscomplex
85##   is_empty        -> isempty
86##   is_float_type   -> isfloat
87##   is_numeric_type -> isnumeric
88##   is_real_type    -> isreal
89## Warnings are scary to users, so use the new style if it's available.
90AC_CACHE_CHECK([whether octave value has Octave style is* methods],
91   [octave_image_cv_octave_style_is_functions],
92   [AC_COMPILE_IFELSE(
93     [AC_LANG_PROGRAM([#include <ov.h>],
94                      [octave_value foo = octave_value ();
95                       bool is_result;
96                       is_result = foo.iscomplex ();
97                       is_result = foo.isempty ();
98                       is_result = foo.isfloat ();
99                       is_result = foo.islogical ();
100                       is_result = foo.isnumeric ();
101                       is_result = foo.isreal ();])],
102     [octave_image_cv_octave_style_is_functions=yes],
103     [octave_image_cv_octave_style_is_functions=no])]
104)
105
106if test "$octave_image_cv_octave_style_is_functions" = yes; then
107  AC_DEFINE([HAVE_OCTAVE_STYLE_IS_FUNCTIONS], [1],
108            [Define if octave_value has is* style like the Octave language.])
109fi
110
111## Since Octave 6.0 the exception throw in C++ has its own message.
112## Check for that.  In older Octave versions there's a single error
113## message at a time (see iptcheckconn code).
114AC_CACHE_CHECK([whether octave::execution_exception has message member],
115  [octave_image_cv_execution_exception_has_message],
116  [AC_COMPILE_IFELSE(
117    [AC_LANG_PROGRAM([#include <error.h>],
118                     [try
119                        {
120                          error("test");
121                        }
122                      catch (octave::execution_exception& e)
123                        {
124                          std::string msg = e.message ();
125                        }])],
126    [octave_image_cv_execution_exception_has_message=yes],
127    [octave_image_cv_execution_exception_has_message=no])]
128)
129
130if test "$octave_image_cv_execution_exception_has_message" = yes; then
131  AC_DEFINE([HAVE_OCTAVE_EXCEPTION_MESSAGE], [1],
132            [Define if octave_exception has message member.])
133fi
134
135
136CXXFLAGS="$image_save_CXXFLAGS"
137
138
139## Test for gcc bug #65843 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65843
140## which shows up as Octave bug #45096 https://savannah.gnu.org/bugs/?45096
141AC_CACHE_CHECK([whether templated lambda functions accept '&const int'],
142  [_cv_template_lambda_accepts_ref_const_inst],
143  [AC_COMPILE_IFELSE(
144    [AC_LANG_PROGRAM([[
145      template<class T>
146      void test (T b)
147      {
148        const int a = b;
149        [&] () { return a, a; }();
150      }
151      ]], [[ test (1); ]])],
152    [_cv_template_lambda_accepts_ref_const_inst=yes],
153    [_cv_template_lambda_accepts_ref_const_inst=no])
154])
155if test $_cv_template_lambda_accepts_ref_const_inst = no; then
156  AC_MSG_WARN([
157    Your C++ compiler (are you using GCC 5.0 or 5.1?) has a bug that
158    prevents it from building the Octave Forge image package.  But you
159    can fix it very easily.  See https://savannah.gnu.org/bugs/?45096
160    for details on working around it.
161  ])
162fi
163
164## Some functions have been moving between Octave core and the Image
165## package so make sure we are not shadowing anything on this
166## installation.
167##
168##  im2double - moved into core for core version 4.2
169##  ntsc2rgb - moved into the image package for core version 4.4
170##  rgb2ntsc - moved into the image package for core version 4.4
171
172M_FILES=""
173m4_foreach([FNAME], [im2double, ntsc2rgb, rgb2gray, rgb2ntsc], [
174  AC_MSG_CHECKING([Octave core for function FNAME])
175  HAS_FUNCTION=`$OCTAVE -qfH --eval "printf ('%i', exist ('FNAME'))"`
176  if test "$HAS_FUNCTION" == 0; then
177    AC_MSG_RESULT([no])
178    M_FILES="${M_FILES} FNAME.m"
179  else
180    AC_MSG_RESULT([yes])
181  fi
182])
183
184AC_SUBST([XTRA_CXXFLAGS])
185AC_SUBST([M_FILES])
186
187AC_CONFIG_FILES([Makefile])
188
189AC_OUTPUT
190