2 # This file is part of the aMule Project.
4 # Copyright (c) 2003-2008 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
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 dnl ---------------------------------------------------------------------------
27 dnl ---------------------------------------------------------------------------
28 m4_pattern_forbid(MULE_)dnl Check for unexpanded *MULE_* macros
29 m4_pattern_allow(AMULE_)dnl Allow the *AMULE_* names
31 dnl MULE_APPEND(VARNAME, VALUE)
32 AC_DEFUN([MULE_APPEND], [$1="$$1 $2"])
34 dnl MULE_PREPEND(VARNAME, VALUE)
35 AC_DEFUN([MULE_PREPEND], [$1="$2 $$1"])
37 dnl MULE_ADDFLAG(FLAGTYPE, VALUE)
38 AC_DEFUN([MULE_ADDFLAG], [MULE_APPEND([MULE[]$1[]FLAGS], [$2])])
40 dnl MULE_ADDCCXXFLAG(VALUE)
41 AC_DEFUN([MULE_ADDCCXXFLAG],
43 MULE_ADDFLAG([C], [$1])
44 MULE_ADDFLAG([CXX], [$1])
48 AC_DEFUN([MULE_BACKUP], [mule_backup_$1="$$1"])
51 AC_DEFUN([MULE_RESTORE], [$1="$mule_backup_$1"])
53 dnl Helper macro for MULE_IF
54 m4_define([__mule_if_helper],
56 [$#], 1, [m4_ifvaln([$1], [m4_n([else]) $1])],
57 [m4_n([elif $1; then]) m4_ifvaln([$2], [$2], :)])dnl
58 m4_if(m4_eval([$# > 2]), 1, [$0(m4_shiftn(2, $@))])])
60 dnl MULE_IF(CONDITION, [IF-TRUE] [, ELIF-CONDITION, [IF-TRUE]]... [, ELSE-BRANCH])
64 [m4_n([if $1; then]) m4_ifval([$2],[$2], :)
65 m4_if(m4_eval([$# > 2]), 1, [__mule_if_helper(m4_shiftn(2, $@))])m4_n([fi])])])
67 dnl ---------------------------------------------------------------------------
70 dnl Checks host system type, and sets system-specific flags accordingly.
71 dnl Sets $SYS to the name of the host os.
72 dnl ---------------------------------------------------------------------------
73 AC_DEFUN([MULE_CHECK_SYSTEM],
74 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
79 MULECPPFLAGS="-no-cpp-precomp -D_INTL_REDIRECT_MACROS -DNOPCH";
80 MULELDFLAGS="-bind_at_load"
85 LIBS="$LIBS -L/usr/local/lib"
86 X11LIBS="-lX11 -L/usr/X11R6/lib"
87 MULECPPFLAGS="-D__OPENBSD__"
91 MULECPPFLAGS="-DNOMINMAX"
95 RESOLV_LIB="-lresolv -lnsl"
101 # Now this is against autoconf recommendation that configure should not modify CPPFLAGS and LDFLAGS
102 # However, these values in NetBSD are required even to run the tests, and this is the easiest way to do it.
103 # Still, we prepend them, instead of adding, so the user may override them.
104 MULE_PREPEND([CPPFLAGS], [-I/usr/pkg/include])
105 MULE_PREPEND([LDFLAGS], [-R/usr/pkg/lib -L/usr/pkg/lib])
112 # -lpthread is needed by Debian but FreeBSD < 5 doesn't support it
113 AS_IF([test ${SYS:-unknown} != win32],
115 AC_MSG_CHECKING([if this is a FreeBSD 4 or earlier system])
116 AS_IF([test x"`uname -s`" = xFreeBSD && test 0`uname -r | cut -c 1` -lt 5],
118 MULE_ADDFLAG([LD], [-pthread])
121 MULE_ADDFLAG([LD], [-lpthread])
126 AC_SUBST([RESOLV_LIB])dnl
127 AC_SUBST([X11LIBS])dnl
128 AC_SUBST([MULECPPFLAGS])dnl
129 AC_SUBST([MULECFLAGS])dnl
130 AC_SUBST([MULECXXFLAGS])dnl
131 AC_SUBST([MULELDFLAGS])dnl
132 AC_SUBST([MULERCFLAGS])dnl
135 dnl ---------------------------------------------------------------------------
136 dnl _MULE_CHECK_DEBUG_FLAG
137 dnl ---------------------------------------------------------------------------
138 AC_DEFUN([_MULE_CHECK_DEBUG_FLAG],
139 [AC_REQUIRE([MULE_CHECK_GLIBCXX])dnl
143 [AS_HELP_STRING([--disable-debug], [disable additional debugging output])],
144 [USE_DEBUG=${enableval:-yes}], [USE_DEBUG=yes])
146 AS_IF([test $USE_DEBUG = yes],
148 MULE_ADDFLAG([CPP], [-D__DEBUG__])
149 MULE_ADDCCXXFLAG([-g])
150 AS_IF([test ${GLIBCXX:-no} = yes], [MULE_ADDFLAG([CPP], [-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC])])
151 AS_IF([test ${GCC:-no} = yes], [MULE_ADDCCXXFLAG([-W -Wall -Wshadow -Wundef -ggdb -fno-inline -fmessage-length=0])])
152 AS_IF([test ${SYS:-unknown} = win32], [MULE_ADDFLAG([RC], [-D__DEBUG__])])
154 AS_IF([test ${GCC:-no} = yes], [MULE_ADDCCXXFLAG([-W -Wall -Wshadow -Wundef])])
158 dnl ---------------------------------------------------------------------------
159 dnl _MULE_CHECK_PROFILE_FLAG
160 dnl ---------------------------------------------------------------------------
161 AC_DEFUN([_MULE_CHECK_PROFILE_FLAG],
165 [AS_HELP_STRING([--enable-profile], [enable code profiling])],
166 [USE_PROFILE=${enableval:-no}], [USE_PROFILE=no])
168 AS_IF([test $USE_PROFILE = yes],
170 MULE_ADDCCXXFLAG([-pg])
171 MULE_ADDFLAG([LD], [-pg])
175 dnl ---------------------------------------------------------------------------
176 dnl _MULE_CHECK_OPTIMIZE_FLAG
177 dnl ---------------------------------------------------------------------------
178 AC_DEFUN([_MULE_CHECK_OPTIMIZE_FLAG],
182 [AS_HELP_STRING([--enable-optimize], [enable code optimization])],
183 [USE_OPTIMIZE=${enableval:-no}], [USE_OPTIMIZE=no])
185 AS_IF([test $USE_OPTIMIZE = yes], [MULE_ADDCCXXFLAG([-O2])])
188 dnl ---------------------------------------------------------------------------
189 dnl MULE_COMPILATION_FLAGS
191 dnl Checks type of compilation requested by user, and sets various flags
193 dnl ---------------------------------------------------------------------------
194 AC_DEFUN([MULE_COMPILATION_FLAGS],
196 _MULE_CHECK_DEBUG_FLAG
197 _MULE_CHECK_OPTIMIZE_FLAG
198 _MULE_CHECK_PROFILE_FLAG
200 AC_MSG_CHECKING([if the applications should be statically linked])
203 [AS_HELP_STRING([--enable-static], [produce a statically linked executable])],
204 [AS_IF([test ${enableval:-no} = yes], [MULE_ADDFLAG([LD], [-static])])])
205 AC_MSG_RESULT(${enableval:-no})
207 MULE_ADDFLAG([CPP], [-DUSE_WX_EXTENSIONS])
210 dnl ---------------------------------------------------------------------------
211 dnl MULE_CHECK_GLIBCXX
213 dnl Checks whether we use the GNU C++ Library.
214 dnl ---------------------------------------------------------------------------
215 AC_DEFUN([MULE_CHECK_GLIBCXX],
217 AC_REQUIRE([AC_PROG_EGREP])dnl
218 AC_REQUIRE([AC_PROG_CXXCPP])dnl
219 AC_LANG_ASSERT([C++])dnl
221 AC_MSG_CHECKING([if we're using the GNU C++ library])
226 #error Non-GNU C++ library found.
229 ], [GLIBCXX=yes], [GLIBCXX=no])
230 AC_MSG_RESULT([$GLIBCXX])
233 dnl ---------------------------------------------------------------------------
234 dnl MULE_CHECK_WX_SUPPORTS_LARGEFILE
236 dnl Test that wxWidgets is built with support for large-files. If not
237 dnl configure is terminated.
238 dnl ---------------------------------------------------------------------------
239 AC_DEFUN([MULE_CHECK_WX_SUPPORTS_LARGEFILE],
240 [AC_LANG_ASSERT([C++])dnl
242 dnl Backup current flags and setup flags for testing
243 MULE_BACKUP([CPPFLAGS])
244 MULE_APPEND([CPPFLAGS], [$WX_CPPFLAGS])
246 AC_MSG_CHECKING([that wxWidgets has support for large files])
250 #if !HAVE_LARGEFILE_SUPPORT && !defined(_LARGE_FILES) && !defined(__WXMSW__)
251 #error No LargeFile support!
259 Support for large files in wxWidgets is required by aMule.
260 To continue you must recompile wxWidgets with support for
261 large files enabled.])
264 dnl Restore backup'd flags
265 MULE_RESTORE([CPPFLAGS])
269 dnl --------------------------------------------------------------------------
270 dnl MULE_CHECK_CCACHE
272 dnl Checks if ccache is requested and available, and makes use of it
273 dnl --------------------------------------------------------------------------
274 AC_DEFUN([MULE_CHECK_CCACHE],
276 AC_ARG_ENABLE([ccache],
277 [AS_HELP_STRING([--enable-ccache], [enable ccache support for fast recompilation])])
279 AC_ARG_WITH([ccache-prefix],
280 [AS_HELP_STRING([--with-ccache-prefix=PREFIX], [prefix where ccache is installed])])
282 AC_MSG_CHECKING([whether ccache support should be added])
283 AC_MSG_RESULT([${enable_ccache:-no}])
285 AS_IF([test ${enable_ccache:-no} = yes], [
286 AC_MSG_CHECKING([for ccache presence])
287 AS_IF([test -z "$with_ccache_prefix"], [
288 ccache_full=`which ccache`
289 with_ccache_prefix=`dirname ${ccache_full}`
291 AS_IF([$with_ccache_prefix/ccache -V >/dev/null 2>&1], [
293 CC="$with_ccache_prefix/ccache $CC"
294 CXX="$with_ccache_prefix/ccache $CXX"
295 BUILD_CC="$with_ccache_prefix/ccache $BUILD_CC"
303 dnl ----------------------------------------------------
305 dnl check if bfd.h is on the system and usable
306 dnl ----------------------------------------------------
307 AC_DEFUN([MULE_CHECK_BFD],
309 AC_MSG_CHECKING([for bfd])
311 MULE_PREPEND([LIBS], [-lbfd -liberty])
314 #include <ansidecl.h>
317 char *dummy = bfd_errmsg(bfd_get_error());
321 BFD_CPPFLAGS="-DHAVE_BFD"
322 BFD_LIBS="-lbfd -liberty"
326 bfd.h not found or unusable, please install binutils development
327 package if you are a developer or want to help testing aMule])
331 AC_SUBST([BFD_CPPFLAGS])dnl
332 AC_SUBST([BFD_LIBS])dnl
336 dnl ----------------------------------------------------
337 dnl MULE_CHECK_FLEX_EXTENDED
338 dnl check if flex can produce header files
339 dnl ----------------------------------------------------
340 AC_DEFUN([MULE_CHECK_FLEX_EXTENDED],
342 AC_MSG_CHECKING([for extended flex capabilities])
344 extended_flex=`flex --help | grep header-file`
345 AS_IF([test -n "$extended_flex"], [HAVE_FLEX_EXTENDED=yes], [HAVE_FLEX_EXTENDED=no])
346 AC_MSG_RESULT($HAVE_FLEX_EXTENDED)
348 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])])
352 dnl ----------------------------------------------------
353 dnl MULE_CHECK_EXCEPTIONS
354 dnl Checks for broken exception-handling. This is needed
355 dnl because exception handling is broken for some archs/
357 dnl ----------------------------------------------------
358 AC_DEFUN([MULE_CHECK_EXCEPTIONS],
359 [AC_LANG_ASSERT([C++])dnl
361 AC_MSG_CHECKING([for exception-handling])
375 AC_MSG_ERROR([Exception handling does not work. Broken compiler?])
377 AC_MSG_RESULT([undeterminable])
379 Cross-compilation detected, so exception handling cannot be tested.
380 Note that broken exception handling in your compiler may lead to
381 unexpected crashes.])
386 dnl ---------------------------------------------------------------------------
387 dnl MULE_CHECK_REGEX([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
389 dnl This function will test the existance of a POSIX compliant regex library.
390 dnl ---------------------------------------------------------------------------
391 AC_DEFUN([MULE_CHECK_REGEX],
393 AC_MSG_CHECKING([for a POSIX compliant regex library])
395 for REGEX_LIBS in '' -lgnurx -lregex; do
397 MULE_PREPEND([LIBS], [$REGEX_LIBS])
403 regcomp(&preg, "", REG_EXTENDED);
405 regexec(&preg, "", 0, pmatch, 0);
412 ], [MULE_RESTORE([LIBS])])
414 AC_MSG_RESULT([$regex_found])
415 ifelse([$1$2],,, [AS_IF([test $regex_found = yes], [$1], [$2])])
416 AC_SUBST([REGEX_LIBS])dnl
420 dnl ---------------------------------------------------------------------------
421 dnl MULE_CHECK_CXXABI
423 dnl This function will test the header <cxxabi.h> and abi::__cxa_demangle()
424 dnl ---------------------------------------------------------------------------
425 AC_DEFUN([MULE_CHECK_CXXABI],
426 [AC_LANG_ASSERT([C++])dnl
428 AC_MSG_CHECKING([for <cxxabi.h> and __cxa_demangle()])
434 char * demangled = abi::__cxa_demangle("", 0, 0, &status);
435 std::type_info *ti = abi::__cxa_current_exception_type();
438 AH_TEMPLATE([HAVE_CXXABI], [Define to 1 if you have the <cxxabi.h> header which declares abi::__cxa_demangle()])
439 AC_DEFINE([HAVE_CXXABI])
447 dnl ---------------------------------------------------------------------------
448 dnl MULE_CHECK_EXECINFO
450 dnl This function will test the header <execinfo.h> and backtrace()
451 dnl ---------------------------------------------------------------------------
452 AC_DEFUN([MULE_CHECK_EXECINFO],
454 AC_MSG_CHECKING([for <execinfo.h> and backtrace()])
457 #include <execinfo.h>
460 int n = backtrace(&bt, 1);
461 const char **bt_syms = backtrace_symbols(bt, n);
464 AH_TEMPLATE([HAVE_EXECINFO], [Define to 1 if you have the <execinfo.h> header which declares backtrace()])
465 AC_DEFINE([HAVE_EXECINFO])
473 dnl ---------------------------------------------------------------------------
476 dnl Test for denoising level and add denoiser commands to config.status
477 dnl ---------------------------------------------------------------------------
478 AC_DEFUN([MULE_DENOISER],
480 AC_ARG_WITH([denoise-level],
481 [AS_HELP_STRING([--with-denoise-level=<level>], [Specifies denoising level (0-4):])
482 AS_HELP_STRING([], [0 - Do nothing])
483 AS_HELP_STRING([], [4 - Suppress all normal output])
484 AS_HELP_STRING([], [(for more information see src/utils/scripts/denoiser.rules)])
487 AC_MSG_CHECKING([denoising level])
488 AS_IF([test ${with_denoise_level:-5} = yes], [with_denoise_level=5])
489 AS_IF([test ${with_denoise_level:-5} = no], [with_denoise_level=0])
490 AS_IF([test ${with_denoise_level:-5} -gt 4],
491 [AS_IF([test "${svndate:+set}" = "set"], [with_denoise_level=0], [with_denoise_level=4])])
492 AC_MSG_RESULT([$with_denoise_level])
494 AC_CONFIG_COMMANDS([denoiser], [[if test $denoiserlevel -gt 0; then
495 if test ! -d src/utils/scripts; then mkdir -p src/utils/scripts; fi
496 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" \
497 $srcdir/src/utils/scripts/denoiser.rules > src/utils/scripts/denoiser.sed
498 for i in `find . -name 'Makefile' -print`; do
499 if test -n "`head -n 1 $i | grep '^#'`"; then
500 sed -f src/utils/scripts/denoiser.sed $i > $i.tmp && mv $i.tmp $i
503 fi]], [denoiserlevel=$with_denoise_level])