fixed a new bison warning in Ubuntu 13.4
[amule.git] / acinclude.m4
blob026bc04e95279d8936ae7658c0c4254607c260b0
1 #                                                       -*- Autoconf -*-
2 # This file is part of the aMule Project.
4 # Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 # Any parts of this program derived from the xMule, lMule or eMule project,
7 # or contributed by third-party developers are copyrighted by their
8 # respective authors.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
25 m4_pattern_forbid(MULE_)dnl Check for unexpanded *MULE_* macros
26 m4_pattern_allow(AMULE_)dnl Allow the *AMULE_* names
27 m4_pattern_forbid(__mule_)dnl Check for unexpanded internal macros
30 # -------------------- #
31 # Common useful macros #
32 # -------------------- #
34 dnl MULE_APPEND(VARNAME, VALUE)
35 AC_DEFUN([MULE_APPEND], [$1="$$1 $2"])
37 dnl MULE_PREPEND(VARNAME, VALUE)
38 AC_DEFUN([MULE_PREPEND], [$1="$2 $$1"])
40 dnl MULE_ADDFLAG(FLAGTYPE, VALUE)
41 AC_DEFUN([MULE_ADDFLAG], [MULE_APPEND([MULE[]$1[]FLAGS], [$2])])
43 dnl MULE_ADDCCXXFLAG(VALUE)
44 AC_DEFUN([MULE_ADDCCXXFLAG],
46         MULE_ADDFLAG([C], [$1])
47         MULE_ADDFLAG([CXX], [$1])
50 dnl MULE_BACKUP(VAR)
51 AC_DEFUN([MULE_BACKUP], [mule_backup_$1="$$1"])
53 dnl MULE_RESTORE(VAR)
54 AC_DEFUN([MULE_RESTORE], [$1="$mule_backup_$1"])
57 # ------------------- #
58 # Issuing diagnostics #
59 # ------------------- #
61 # -----------------------------------------------------------------------------
62 # __mule_print_final_warning(section, condition, message)
63 # -----------------------------------------------------------------------------
64 m4_define([__mule_print_final_warning],
65 [m4_divert_push($1)dnl
66 if test [$2]; then
67 cat <<_MULEEOT
69 m4_pushdef([__mule_Prefix1], [* ])dnl
70 m4_pushdef([__mule_Prefix], [  ])dnl
71 m4_foreach([__mule_Line], m4_quote(m4_split([$3], [
72 ])), [m4_text_wrap(m4_defn([__mule_Line]), __mule_Prefix, __mule_Prefix1)
73 m4_define([__mule_Prefix1], __mule_Prefix)dnl
74 ])[]dnl
75 m4_popdef([__mule_Prefix])dnl
76 m4_popdef([__mule_Prefix1])dnl
77 _MULEEOT
79 m4_divert_pop()])
81 dnl ---------------------------------------------------------------------------
82 dnl MULE_WARNING(MESSAGE)
83 dnl
84 dnl Works like AC_MSG_WARN(), but the warning will be reproduced at the end of
85 dnl the configure run. An empty line is prepended at the final output and a
86 dnl newline is appended for free.
87 dnl ---------------------------------------------------------------------------
88 m4_ifndef([_MULE_WARNINGS],[
89 m4_define([_m4_divert(_MULE_WARNINGS)], m4_incr(_m4_divert([BODY])))])
90 m4_define([_MULE_WARNCOUNT], [0])
92 m4_divert_push(_MULE_WARNINGS)dnl
93 if test ${_mule_has_warnings:-no} = yes; then
94 echo ""
95 echo ""
96 echo " *** Warnings during configuration ***"
98 m4_divert_pop()dnl
100 m4_define([MULE_WARNING],
101 [AC_MSG_WARN(
102 m4_pushdef([__mule_Prefix], [        ])dnl
103 m4_foreach([__mule_Line], m4_quote(m4_split([$1], [
104 ])), [
105 m4_text_wrap(m4_defn([__mule_Line]), __mule_Prefix)])[]dnl
106 m4_popdef([__mule_Prefix])dnl
108 _mule_warning_[]_MULE_WARNCOUNT[]=yes
109 _mule_has_warnings=yes
110 __mule_print_final_warning([_MULE_WARNINGS], [${_mule_warning_]_MULE_WARNCOUNT[:-no} = yes], [$1])dnl
111 m4_define([_MULE_WARNCOUNT], incr(_MULE_WARNCOUNT))])
113 dnl ---------------------------------------------------------------------------
114 dnl MULE_DEPRECATED(OLDFLAG [, NEWFLAG])
116 dnl Marks OLDFLAG as deprecated and produces an appropriate warning. If NEWFLAG
117 dnl is specified and is unset the value of OLDFLAG is assigned to NEWFLAG (i.e.
118 dnl if the user specified both OLDFLAG and NEWFLAG, NEWFLAG takes precedence;
119 dnl if only OLDFLAG is specified it will be redirected to NEWFLAG).
121 dnl There should be no AC_ARG_* for the deprecated flag, and if the old flag is
122 dnl deprecated in favour of a new one, MULE_DEPRECATED *MUST* precede the
123 dnl AC_ARG_* definition of the new flag (otherwise redirection may not work).
124 dnl ---------------------------------------------------------------------------
125 m4_define([_MULE_DEPRECATIONWARNINGS], [incr(_MULE_WARNINGS)])
126 m4_define([__mule_display_option_name], [m4_if(m4_substr([$1], 0, 1), [-],, [--])m4_bpatsubst([$1], [_], [-])])
127 m4_define([__mule_ac_option_name], [m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(m4_bpatsubst([$1], [^-+], []), [-], [_]), [^disable], [enable]), [^without], [with])])
129 m4_define([MULE_DEPRECATED],
130 [if test "${__mule_ac_option_name([$1])+set}" = "set"; then
131   _mule_has_warnings=yes
132 m4_ifvaln([$2], [  if test "${__mule_ac_option_name([$2]):-unset}" = "unset"; then
133     __mule_ac_option_name([$2])=$__mule_ac_option_name([$1])
134   fi])fi
135 __mule_print_final_warning([_MULE_DEPRECATIONWARNINGS], ["${]__mule_ac_option_name([$1])[+set}" = set], __mule_display_option_name([$1])[ is now deprecated and ]m4_ifval([$2], [might be removed in the future without further notice. Please use ]__mule_display_option_name([$2])[ instead.], [not supported anymore.]))])
138 # ----------------- #
139 # Argument handling #
140 # ----------------- #
141 m4_define([__mule_arg_default], [__mule_arg_[]m4_translit([$1], [-], [_])[]_default])
142 m4_define([__mule_arg_value], [${enable_[]m4_translit([$1], [-], [_])[]:-[]__mule_arg_default([$1])[]}])
144 dnl ---------------------------------------------------------------------------
145 dnl MULE_ARG_ENABLE(FEATURE, DEFAULT-VALUE, HELP-STRING [, AUTOMAKE-CONDITIONAL])
147 dnl Wrapper around AC_ARG_ENABLE() that supports automatically setting up a
148 dnl conditional variable for automake, remembering default value for
149 dnl conditionals and supplying the help string based on the default value (i.e.
150 dnl it produce "--enable-FEATURE   HELP-STRING" if the default is no, and
151 dnl "--disable-FEATURE    HELP-STRING" if the default is yes. The default value
152 dnl *MUST* be either `yes' or `no'.
153 dnl ---------------------------------------------------------------------------
154 m4_define([MULE_ARG_ENABLE],
155 [m4_if([$2], [yes],, [m4_if([$2], [no],, [m4_fatal([Default value must be either `yes' or `no'!])])])dnl
156 m4_define(__mule_arg_default([$1]), [$2])dnl
157 AC_ARG_ENABLE([$1], [AS_HELP_STRING(m4_if([$2], [yes], [--disable-$1], [--enable-$1]), [$3])])
158 m4_ifvaln([$4], [AM_CONDITIONAL([$4], [test ]__mule_arg_value([$1])[ = yes])])])
160 dnl ---------------------------------------------------------------------------
161 dnl MULE_IS_ENABLED(FEATURE)
163 dnl Used in shell conditionals, tests whether the named feature is enabled or
164 dnl not, considering also the default value. FEATURE *must* have been set up
165 dnl using MULE_ARG_ENABLE().
166 dnl ---------------------------------------------------------------------------
167 m4_define([MULE_IS_ENABLED],
168 [m4_ifdef(__mule_arg_default([$1]), __mule_arg_value([$1])[ = yes], [m4_fatal([Unknown feature `$1'!])])])
170 m4_define([MULE_IS_ENABLED_ANY], [__mule_if_multi([$1], [-o])])
171 m4_define([MULE_IS_ENABLED_ALL], [__mule_if_multi([$1], [-a])])
173 dnl ---------------------------------------------------------------------------
174 dnl MULE_ENABLEVAR(FEATURE)
176 dnl Expands to the name of the shell variable holding the enabled/disabled
177 dnl status of FEATURE. FEATRUE *must* have been set up using MULE_ARG_ENABLE().
178 dnl ---------------------------------------------------------------------------
179 m4_define([MULE_ENABLEVAR],
180 [m4_ifdef(__mule_arg_default([$1]), [enable_[]m4_translit([$1], [-], [_])], [m4_fatal([Unknown feature `$1'!])])])
182 dnl ---------------------------------------------------------------------------
183 dnl MULE_STATUSOF(FEATURE)
185 dnl Expands to the value of the shell variable holding the status of FEATURE,
186 dnl considering default values. FEATURE *must* have been set up using
187 dnl MULE_ARG_ENABLE().
188 dnl ---------------------------------------------------------------------------
189 m4_define([MULE_STATUSOF],
190 [m4_ifdef(__mule_arg_default([$1]), __mule_arg_value([$1]), [m4_fatal([Unknown feature `$1'!])])])
193 # ---------------------- #
194 # Conditional processing #
195 # ---------------------- #
196 m4_define([__mule_if_multi],
197 [m4_define([__mule_if_logic], [])dnl
198 m4_foreach([__mule_condition], [$1], [__mule_if_logic MULE_IS_ENABLED(__mule_condition) ][m4_define([__mule_if_logic], [$2])])dnl
199 m4_undefine([__mule_if_logic])])
201 dnl ---------------------------------------------------------------------------
202 dnl MULE_IF_ENABLED(FEATURE, [ACTION-IF-ENABLED], [ACTION-IF-DISABLED])
204 dnl Basically a wrapper around AS_IF(), the test being if FEATURE is enabled.
205 dnl FEATURE must have been set up by MULE_ARG_ENABLE().
206 dnl ---------------------------------------------------------------------------
207 m4_define([MULE_IF_ENABLED],
208 [AS_IF([test MULE_IS_ENABLED([$1])], [$2], [$3])])
210 m4_define([MULE_IF_ENABLED_ALL],
211 [AS_IF([test]__mule_if_multi([$1], [-a]), [$2], [$3])])
213 m4_define([MULE_IF_ENABLED_ANY],
214 [AS_IF([test]__mule_if_multi([$1], [-o]), [$2], [$3])])
216 dnl ---------------------------------------------------------------------------
217 dnl MULE_IF(CONDITION, [IF-TRUE] [, ELIF-CONDITION, [IF-TRUE]]... [, ELSE-BRANCH])
219 dnl Works like AS_IF(), but allows elif-branches too.
220 dnl ---------------------------------------------------------------------------
221 m4_define([__mule_if_helper],
222 [m4_if( [$#], 0,,
223         [$#], 1, [m4_ifvaln([$1], [m4_n([else])  $1])],
224         [m4_n([elif $1; then])  m4_ifvaln([$2], [$2], :)])dnl
225 m4_if(m4_eval([$# > 2]), 1, [$0(m4_shiftn(2, $@))])])
227 m4_define([MULE_IF],
228 [m4_if( [$#], 0,,
229         [$#], 1,,
230         [m4_n([if $1; then])  m4_ifval([$2],[$2], :)
231 m4_if(m4_eval([$# > 2]), 1, [__mule_if_helper(m4_shiftn(2, $@))])m4_n([fi])])])
234 # ----------------------- #
235 # Other high-level macros #
236 # ----------------------- #
238 dnl ---------------------------------------------------------------------------
239 dnl MULE_CHECK_SYSTEM
241 dnl Checks host system type, and sets system-specific flags accordingly.
242 dnl Sets $SYS to the name of the host os.
243 dnl ---------------------------------------------------------------------------
244 AC_DEFUN([MULE_CHECK_SYSTEM],
245 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
247         case "${host_os}" in
248         darwin*)
249                 SYS=darwin
250                 MULECPPFLAGS="-no-cpp-precomp -D_INTL_REDIRECT_MACROS -DNOPCH";
251                 MULELDFLAGS="-bind_at_load"
252                 touch src/Scanner.cpp
253                 ;;
254         openbsd*)
255                 SYS=openbsd
256                 LIBS="$LIBS -L/usr/local/lib"
257                 MULECPPFLAGS="-D__OPENBSD__"
258                 ;;
259         *cygwin* | *mingw32*)
260                 SYS=win32
261                 MULECPPFLAGS="-DNOMINMAX"
262                 ;;
263         solaris*)
264                 SYS=solaris
265                 RESOLV_LIB="-lresolv -lnsl"
266                 LIBS="$LIBS -lrt"
267                 ;;
268         *netbsd*)
269                 SYS=netbsd
270                 # Now this is against autoconf recommendation that configure should not modify CPPFLAGS and LDFLAGS
271                 # However, these values in NetBSD are required even to run the tests, and this is the easiest way to do it.
272                 # Still, we prepend them, instead of adding, so the user may override them.
273                 MULE_PREPEND([CPPFLAGS], [-I/usr/pkg/include])
274                 MULE_PREPEND([LDFLAGS], [-R/usr/pkg/lib -L/usr/pkg/lib])
275                 ;;
276         *irix*)
277                 SYS=irix
278                 MULECPPFLAGS="-D__IRIX__"
279                 ;;
280         *)
281                 SYS=unknown
282                 ;;
283         esac
285         # -lpthread is needed by Debian but FreeBSD < 5 doesn't support it
286         AS_IF([test ${SYS:-unknown} != win32],
287         [
288                 AC_MSG_CHECKING([if this is a FreeBSD 4 or earlier system])
289                 AS_IF([test x"`uname -s`" = xFreeBSD && test 0`uname -r | cut -c 1` -lt 5],
290                 [
291                         MULE_ADDFLAG([LD], [-pthread])
292                         AC_MSG_RESULT(yes)
293                 ], [
294                         MULE_ADDFLAG([LD], [-lpthread])
295                         AC_MSG_RESULT(no)
296                 ])
297         ])
299 AC_SUBST([RESOLV_LIB])dnl
300 AC_SUBST([MULECPPFLAGS])dnl
301 AC_SUBST([MULECFLAGS])dnl
302 AC_SUBST([MULECXXFLAGS])dnl
303 AC_SUBST([MULELDFLAGS])dnl
304 AC_SUBST([MULERCFLAGS])dnl
307 dnl ---------------------------------------------------------------------------
308 dnl MULE_COMPILATION_FLAGS
310 dnl Checks type of compilation requested by user, and sets various flags
311 dnl accordingly.
312 dnl ---------------------------------------------------------------------------
313 AC_DEFUN([MULE_COMPILATION_FLAGS],
314 [dnl AC_REQUIRE([MULE_CHECK_GLIBCXX])dnl
316         MULE_ARG_ENABLE([debug],        [yes],  [disable additional debugging output])
317         MULE_ARG_ENABLE([profile],      [no],   [enable code profiling])
318         MULE_ARG_ENABLE([optimize],     [no],   [enable code optimization])
320         MULE_IF_ENABLED([debug],
321         [
322                 MULE_ADDFLAG([CPP], [-D__DEBUG__])
323                 MULE_ADDCCXXFLAG([-g])
324                 AS_IF([test ${GCC:-no} = yes],          [MULE_ADDCCXXFLAG([-W -Wall -Wshadow -Wundef -ggdb -fno-inline -fmessage-length=0])])
325                 AS_IF([test ${SYS:-unknown} = win32],   [MULE_ADDFLAG([RC], [-D__DEBUG__])])
326         ], [
327                 AS_IF([test ${GCC:-no} = yes], [MULE_ADDCCXXFLAG([-W -Wall -Wshadow -Wundef])])
328         ])
330         MULE_IF_ENABLED([profile],
331         [
332                 MULE_ADDCCXXFLAG([-pg])
333                 MULE_ADDFLAG([LD], [-pg])
334         ])
336         MULE_IF_ENABLED([optimize],     [MULE_ADDCCXXFLAG([-O2])])
338         MULE_ADDFLAG([CPP], [-DUSE_WX_EXTENSIONS])
341 dnl ---------------------------------------------------------------------------
342 dnl MULE_CHECK_GLIBCXX
344 dnl Checks whether we use the GNU C++ Library.
345 dnl ---------------------------------------------------------------------------
346 AC_DEFUN([MULE_CHECK_GLIBCXX],
347 [dnl
348 AC_REQUIRE([AC_PROG_EGREP])dnl
349 AC_REQUIRE([AC_PROG_CXXCPP])dnl
350 AC_LANG_ASSERT([C++])dnl
352         AC_MSG_CHECKING([if we're using the GNU C++ library])
353         AC_PREPROC_IFELSE([
354                 AC_LANG_SOURCE([[
355                         #include <string>
356                         #ifndef __GLIBCXX__
357                         #error Non-GNU C++ library found.
358                         #endif
359                 ]])
360         ], [GLIBCXX=yes], [GLIBCXX=no])
361         AC_MSG_RESULT([$GLIBCXX])
364 dnl ---------------------------------------------------------------------------
365 dnl MULE_CHECK_STRICT_ALIASING
367 dnl Checks whether the C++ compiler uses strict aliasing.
368 dnl This check could use the C compiler, but the source is C++ and the two
369 dnl compilers are not necessarily the same, or they might use different
370 dnl compiler flags...
371 dnl ---------------------------------------------------------------------------
372 AC_DEFUN([MULE_CHECK_STRICT_ALIASING],
373 [AC_LANG_ASSERT([C++])dnl
375         AH_TEMPLATE([GCC_USES_STRICT_ALIASING], [Define to 1 if the C++ compiler is the GNU C++ compiler and it is using strict aliasing.])
377         AS_IF([test ${GCC:-no} = yes],
378         [
379                 dnl Backup current flags and turn warnings into errors
380                 MULE_BACKUP([CXXFLAGS])
381                 MULE_APPEND([CXXFLAGS], [$MULECPPFLAGS $MULECFLAGS $MULECXXFLAGS -Werror])
383                 AC_MSG_CHECKING([whether the C++ compiler ($CXX) uses strict aliasing])
384                 AC_COMPILE_IFELSE([
385                         AC_LANG_PROGRAM([], [[
386                                 int a;
387                                 short *b = (short*)&a;
388                                 short c = *b;
390                                 return c;
391                         ]])
392                 ], [
393                         AC_MSG_RESULT([no])
394                 ], [
395                         AC_MSG_RESULT([yes])
396                         AC_DEFINE([GCC_USES_STRICT_ALIASING])
397                 ])
399                 dnl Restore flags
400                 MULE_RESTORE([CXXFLAGS])
401         ])
404 dnl ---------------------------------------------------------------------------
405 dnl MULE_CHECK_WX_SUPPORTS_LARGEFILE
407 dnl Test that wxWidgets is built with support for large-files. If not
408 dnl configure is terminated.
409 dnl ---------------------------------------------------------------------------
410 AC_DEFUN([MULE_CHECK_WX_SUPPORTS_LARGEFILE],
411 [AC_LANG_ASSERT([C++])dnl
413         dnl Backup current flags and setup flags for testing
414         MULE_BACKUP([CPPFLAGS])
415         MULE_APPEND([CPPFLAGS], [$WX_CPPFLAGS])
417         AC_MSG_CHECKING([that wxWidgets has support for large files])
418         AC_PREPROC_IFELSE([
419                 AC_LANG_SOURCE([[
420                         #include <wx/wx.h>
421                         #include <wx/filefn.h>
422                         #ifndef wxHAS_LARGE_FILES
423                                 #error No LargeFile support!
424                         #endif
425                 ]])
426         ], [
427                 AC_MSG_RESULT([yes])
428         ], [
429                 AC_MSG_RESULT([no])
430                 AC_MSG_ERROR([
431         Support for large files in wxWidgets is required by aMule.
432         To continue you must recompile wxWidgets with support for
433         large files enabled.])
434         ])
436         dnl Restore backup'd flags
437         MULE_RESTORE([CPPFLAGS])
441 dnl --------------------------------------------------------------------------
442 dnl MULE_CHECK_CCACHE
444 dnl Checks if ccache is requested and available, and makes use of it
445 dnl --------------------------------------------------------------------------
446 AC_DEFUN([MULE_CHECK_CCACHE],
448         MULE_ARG_ENABLE([ccache], [no], [enable ccache support for fast recompilation])
450         AC_ARG_WITH([ccache-prefix],
451                 [AS_HELP_STRING([--with-ccache-prefix=PREFIX], [prefix where ccache is installed])])
453         AC_MSG_CHECKING([whether ccache support should be added])
454         AC_MSG_RESULT([MULE_STATUSOF([ccache])])
456         MULE_IF_ENABLED([ccache], [
457                 AC_MSG_CHECKING([for ccache presence])
458                 AS_IF([test -z "$with_ccache_prefix"], [
459                         ccache_full=`which ccache`
460                         with_ccache_prefix=`dirname ${ccache_full}`
461                 ])
462                 AS_IF([$with_ccache_prefix/ccache -V >/dev/null 2>&1], [
463                         CC="$with_ccache_prefix/ccache $CC"
464                         CXX="$with_ccache_prefix/ccache $CXX"
465                         BUILD_CC="$with_ccache_prefix/ccache $BUILD_CC"
466                 ], [MULE_ENABLEVAR([ccache])=no])
467                 AC_MSG_RESULT([MULE_STATUSOF([ccache])])
468         ])
472 dnl ----------------------------------------------------
473 dnl MULE_CHECK_BFD
474 dnl check if bfd.h is on the system and usable
475 dnl ----------------------------------------------------
476 AC_DEFUN([MULE_CHECK_BFD],
477 [AC_REQUIRE([MULE_CHECK_NLS])dnl
479         AC_MSG_CHECKING([for bfd])
480         result=no
481         for bfd_ldadd in "" "${LIBINTL}" "-ldl" "-ldl ${LIBINTL}"; do
482                 MULE_BACKUP([LIBS])
483                 MULE_BACKUP([LDFLAGS])
484                 MULE_PREPEND([LIBS], [-lbfd -liberty ${bfd_ldadd} ${ZLIB_LIBS}])
485                 MULE_APPEND([LDFLAGS], [${ZLIB_LDFLAGS}])
486                 AC_LINK_IFELSE([
487                         AC_LANG_PROGRAM([[
488                                 #include <ansidecl.h>
489                                 #include <bfd.h>
490                         ]], [[
491                                 char *dummy = bfd_errmsg(bfd_get_error());
492                         ]])
493                 ], [
494                         result=yes
495                         BFD_CPPFLAGS="-DHAVE_BFD"
496                         BFD_LIBS="-lbfd -liberty ${bfd_ldadd}"
497                         MULE_RESTORE([LIBS])
498                         MULE_RESTORE([LDFLAGS])
499                         break
500                 ])
501                 MULE_RESTORE([LIBS])
502                 MULE_RESTORE([LDFLAGS])
503         done
505         AC_MSG_RESULT([$result])
507         AS_IF([test $result = no],
508                 [MULE_WARNING([bfd.h not found or unusable, please install binutils development package if you are a developer or want to help testing aMule])])
510 AC_SUBST([BFD_CPPFLAGS])dnl
511 AC_SUBST([BFD_LIBS])dnl
515 dnl ----------------------------------------------------
516 dnl MULE_CHECK_FLEX_EXTENDED
517 dnl check if flex can produce header files
518 dnl ----------------------------------------------------
519 AC_DEFUN([MULE_CHECK_FLEX_EXTENDED],
521         AC_MSG_CHECKING([for extended flex capabilities])
523         extended_flex=`flex --help | grep header-file`
524         AS_IF([test -n "$extended_flex"], [HAVE_FLEX_EXTENDED=yes], [HAVE_FLEX_EXTENDED=no])
525         AC_MSG_RESULT($HAVE_FLEX_EXTENDED)
527         AS_IF([test $HAVE_FLEX_EXTENDED = no], [AC_MSG_NOTICE([Your flex version doesn't support --header-file flag. This is not critical, but an upgrade is recommended])])
531 dnl ----------------------------------------------------
532 dnl MULE_CHECK_EXCEPTIONS
533 dnl Checks for broken exception-handling. This is needed
534 dnl because exception handling is broken for some archs/
535 dnl compilers.
536 dnl ----------------------------------------------------
537 AC_DEFUN([MULE_CHECK_EXCEPTIONS],
538 [AC_LANG_ASSERT([C++])dnl
540         AC_MSG_CHECKING([for exception-handling])
541         AC_RUN_IFELSE([
542                 AC_LANG_PROGRAM(, [[
543                         try {
544                                 throw 1;
545                         } catch (int) {
546                                 return 0;
547                         }
548                         return 1;
549                 ]])
550         ], [
551                 AC_MSG_RESULT([yes])
552         ], [
553                 AC_MSG_RESULT([no])
554                 AC_MSG_ERROR([Exception handling does not work. Broken compiler?])
555         ], [
556                 AC_MSG_RESULT([undeterminable])
557                 MULE_WARNING(
558                         [Cross-compilation detected, so exception handling cannot be tested.
559                         Note that broken exception handling in your compiler may lead to unexpected crashes.])
560         ])
564 dnl ---------------------------------------------------------------------------
565 dnl MULE_CHECK_CXXABI
567 dnl This function will test the header <cxxabi.h> and abi::__cxa_demangle()
568 dnl ---------------------------------------------------------------------------
569 AC_DEFUN([MULE_CHECK_CXXABI],
570 [AC_LANG_ASSERT([C++])dnl
572         AC_CHECK_HEADERS([typeinfo])
573         AC_MSG_CHECKING([for <cxxabi.h> and __cxa_demangle()])
574         AC_LINK_IFELSE([
575                 AC_LANG_PROGRAM([[
576                         #ifdef HAVE_TYPEINFO
577                         #       include <typeinfo>
578                         #endif
579                         #include <cxxabi.h>
580                 ]], [[
581                         int status;
582                         char * demangled = abi::__cxa_demangle("", 0, 0, &status);
583                         std::type_info *ti = abi::__cxa_current_exception_type();
584                 ]])
585         ], [
586                 AH_TEMPLATE([HAVE_CXXABI], [Define to 1 if you have the <cxxabi.h> header which declares abi::__cxa_demangle()])
587                 AC_DEFINE([HAVE_CXXABI])
588                 AC_MSG_RESULT([yes])
589         ], [
590                 AC_MSG_RESULT([no])
591         ])
595 dnl ---------------------------------------------------------------------------
596 dnl MULE_CHECK_EXECINFO
598 dnl This function will test the header <execinfo.h> and backtrace()
599 dnl ---------------------------------------------------------------------------
600 AC_DEFUN([MULE_CHECK_EXECINFO],
602         AC_MSG_CHECKING([for <execinfo.h> and backtrace()])
603         AC_LINK_IFELSE([
604                 AC_LANG_PROGRAM([[
605                         #include <execinfo.h>
606                 ]], [[
607                         void *bt[1];
608                         int n = backtrace(&bt, 1);
609                         const char **bt_syms = backtrace_symbols(bt, n);
610                 ]])
611         ], [
612                 AH_TEMPLATE([HAVE_EXECINFO], [Define to 1 if you have the <execinfo.h> header which declares backtrace()])
613                 AC_DEFINE([HAVE_EXECINFO])
614                 AC_MSG_RESULT([yes])
615         ], [
616                 AC_MSG_RESULT([no])
617         ])
620 dnl ---------------------------------------------------------------------------
621 dnl MULE_CHECK_MMAP
623 dnl Checks for mmap() and makes use of it when found.
624 dnl ---------------------------------------------------------------------------
625 AC_DEFUN([MULE_CHECK_MMAP],
627         MULE_ARG_ENABLE([mmap], [no], [enable using mapped memory if supported])
629         MULE_IF_ENABLED([mmap], [
630                 AC_CHECK_HEADERS([sys/mman.h])
631                 AC_FUNC_MMAP
632                 AC_CHECK_FUNCS([munmap sysconf])
633                 AS_IF([test $ac_cv_func_sysconf = yes], [
634                         AC_MSG_CHECKING([for pagesize constant for sysconf])
635                         AC_LINK_IFELSE([
636                                 AC_LANG_PROGRAM([[
637                                         #include <unistd.h>
638                                 ]], [[
639                                         return sysconf(_SC_PAGESIZE);
640                                 ]])
641                         ], [
642                                 AC_MSG_RESULT([_SC_PAGESIZE])
643                                 AC_DEFINE([HAVE__SC_PAGESIZE], [1], [Define to 1 if you have the _SC_PAGESIZE constant in <unistd.h>])
644                         ], [
645                                 AC_LINK_IFELSE([
646                                         AC_LANG_PROGRAM([[
647                                                 #include <unistd.h>
648                                         ]], [[
649                                                 return sysconf(_SC_PAGE_SIZE);
650                                         ]])
651                                 ], [
652                                         AC_MSG_RESULT([_SC_PAGE_SIZE])
653                                         AC_DEFINE([HAVE__SC_PAGE_SIZE], [1], [Define to 1 if you have the _SC_PAGE_SIZE constant in <unistd.h>, but not _SC_PAGESIZE])
654                                 ], [
655                                         AC_MSG_RESULT([none])
656                                 ])
657                         ])
658                 ])
659         ], [
660                 # fake the result of the test for munmap() for the gettext macros
661                 ac_cv_func_munmap=no
662         ])
666 dnl ---------------------------------------------------------------------------
667 dnl MULE_DENOISER
669 dnl Test for denoising level and add denoiser commands to config.status
670 dnl ---------------------------------------------------------------------------
671 AC_DEFUN([MULE_DENOISER],
673         AC_ARG_WITH([denoise-level],
674                 [AS_HELP_STRING([--with-denoise-level=<level>], [Specifies denoising level (0-4):])
675                 AS_HELP_STRING([], [0 - Do nothing])
676                 AS_HELP_STRING([], [4 - Suppress all normal output])
677                 AS_HELP_STRING([], [(for more information see src/utils/scripts/denoiser.rules)])
678         ])
680         AC_MSG_CHECKING([denoising level])
681         AS_IF([test ${with_denoise_level:-5} = yes], [with_denoise_level=5])
682         AS_IF([test ${with_denoise_level:-5} = no], [with_denoise_level=0])
683         AS_IF([test ${with_denoise_level:-5} -gt 4],
684                 [AS_IF([test "${svndate:+set}" = "set"], [with_denoise_level=0], [with_denoise_level=4])])
685         AC_MSG_RESULT([$with_denoise_level])
687         AC_CONFIG_COMMANDS([denoiser], [[if test $denoiserlevel -gt 0; then
688                 if test ! -d src/utils/scripts; then mkdir -p src/utils/scripts; fi
689                 sed -e "1{x;s/.*/1/;x;};/^[      ]*\$/d;/^#if /{/level.*$denoiserlevel/{x;s/^/1/;x;b0;};x;s/^/0/;x;:0;d;};/^#else/{x;/^1/{s/1/0/;b1;};s/0/1/;:1;x;d;};/^#endif/{x;s/.//;x;d;};/^[        ]*#/d;x;/^1/{x;b;};x;d" \
690                         $srcdir/src/utils/scripts/denoiser.rules > src/utils/scripts/denoiser.sed
691                 for i in `find . -name 'Makefile' -print`; do
692                         if test -n "`head -n 1 $i | grep '^#'`"; then
693                                 sed -f src/utils/scripts/denoiser.sed $i > $i.tmp && mv $i.tmp $i
694                         fi
695                 done
696         fi]], [denoiserlevel=$with_denoise_level])