1 dnl -*-fundamental-*- *@--GLOB-HEADER--@*
5 dnl Common library of autoconf macros
7 dnl (c) 1997 Mark Wooding, except for macros and documentation where noted.
10 dnl----- Licensing notice ---------------------------------------------------
12 dnl This file is part of the Common Files Distribution (`common')
14 dnl `Common' is free software; you can redistribute it and/or modify
15 dnl it under the terms of the GNU General Public License as published by
16 dnl the Free Software Foundation; either version 2 of the License, or
17 dnl (at your option) any later version.
19 dnl `Common' is distributed in the hope that it will be useful,
20 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
21 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 dnl GNU General Public License for more details.
24 dnl You should have received a copy of the GNU General Public License
25 dnl along with `common'; if not, write to the Free Software Foundation,
26 dnl Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 dnl *@--NOTICE--@* Common File Distribution
31 dnl --- *@-mdw_REQUIRE-@* ---
33 dnl Author: Mark Wooding
35 dnl Synopsis: mdw_REQUIRE(MACRO, ARGS...)
37 dnl Arguments: MACRO = name of a macro which should have been called
38 dnl ARGS = arguments to pass
40 dnl Use: Like `AC_REQUIRE', only it handles arguments.
42 AC_DEFUN([mdw_REQUIRE],
43 [ifdef([AC_PROVIDE_$1], ,
44 [AC_DIVERT_PUSH(builtin(eval, AC_DIVERSION_CURRENT - 1))dnl
49 dnl --- *@-mdw_CURSES-@* ---
51 dnl Author: Mark Wooding
53 dnl Synopsis: mdw_CURSES
57 dnl Use: Searches for a `curses' library (one of `ncurses' or
58 dnl `curses') using mdw_CHECK_MANYLIBS. If one is found, the
59 dnl preprocessor macro HAVE_CURSES is defined, and a search is
60 dnl made for a `curses' header file (one of <ncurses.h>,
61 dnl <ncurses/ncurses.h> or <curses.h>) using AC_CHECK_HEADERS
62 dnl and the appropriate preprocessor symbol is defined.
63 dnl Finally, a check is made for the function `wresize' using
66 AC_DEFUN([mdw_CURSES],
67 [mdw_CHECK_MANYLIBS(newwin, ncurses curses, AC_DEFINE(HAVE_CURSES))
68 if test $mdw_cv_lib_newwin != no; then
69 AC_CHECK_HEADERS([ncurses.h ncurses/ncurses.h curses.h], [break])
70 if test "$ac_cv_header_ncurses_h" = "no" &&
71 test "$ac_cv_header_ncurses_ncurses_h" = "no" &&
72 test "$ac_cv_header_curses_h" = "no"; then
73 AC_MSG_WARN([couldn't find a \`curses' header. Assuming \`curses.h'.])
74 AC_DEFINE(HAVE_CURSES_H)
76 AC_CHECK_FUNCS(wresize)
79 dnl --- *@-mdw_TYPE_SSIZE_T-@* ---
81 dnl Author: Mark Wooding
83 dnl Synopsis: mdw_TYPE_SSIZE_T
87 dnl Use: Checks whether the Posix type `ssize_t' is defined. If not,
88 dnl it defaults to `int'.
90 AC_DEFUN([mdw_TYPE_SSIZE_T],
91 [AC_REQUIRE([AC_HEADER_STDC])
92 AC_CACHE_CHECK(for ssize_t, mdw_cv_ssize_t,
93 [AC_EGREP_CPP(ssize_t,
94 [#include <sys/types.h>
102 [mdw_cv_ssize_t=yes], [mdw_cv_ssize_t=no])])
103 if test $mdw_cv_ssize_t = no; then
104 AC_DEFINE(ssize_t, int)
107 dnl --- *@-mdw_DECL_ENVIRON-@* ---
109 dnl Author: Mark Wooding
111 dnl Synopsis: mdw_DECL_ENVIRON
115 dnl Use: Searches for a declaration of the global `environ' variable.
116 dnl If one is found in one of the `usual' places, DECL_ENVIRON
117 dnl is defined as a preprocessor symbol.
119 AC_DEFUN([mdw_DECL_ENVIRON],
120 [AC_CACHE_CHECK([for declaration of \`environ'], mdw_cv_environ,
121 [AC_EGREP_CPP(environ,
122 [#include <sys/types.h>
129 #endif], [mdw_cv_environ=yes], [mdw_cv_environ=no])])
130 if test $mdw_cv_environ = yes; then
131 AC_DEFINE(DECL_ENVIRON)
134 dnl --- *@-mdw_CHECK_MANYLIBS-@* ---
136 dnl Author: Mark Wooding
138 dnl Synopsis: mdw_CHECK_MANYLIBS(FUNC, LIBS, [IF-FOUND], [IF-NOT-FOUND],
139 dnl [INCLUDES], [ARGS])
141 dnl Arguments: FUNC = a function to try to find
142 dnl LIBS = a whitespace-separated list of libraries to search
143 dnl IF-FOUND = what to do when the function is found
144 dnl IF-NOT-FOUND = what to do when the function isn't found
145 dnl INCLUDES = other include files to add
146 dnl ARGS = arguments to pass the function
148 dnl Use: Searches for a library which defines FUNC. It first tries
149 dnl without any libraries; then it tries each library specified
150 dnl in LIBS in turn. If it finds a match, it adds the
151 dnl appropriate library to `LIBS'.
153 dnl This is particularly handy under DIREIX: if you link with
154 dnl `-lnsl' then you get non-NIS-aware versions of getpwnam and
155 dnl so on, which is clearly a Bad Thing.
157 AC_DEFUN([mdw_CHECK_MANYLIBS],
158 [AC_CACHE_CHECK([for library containing $1], [mdw_cv_lib_$1],
159 [mdw_save_LIBS="$LIBS"
161 AC_TRY_LINK([$5], [$1($6)], [mdw_cv_lib_$1="none required"])
162 test "$mdw_cv_lib_$1" = "no" && for i in $2; do
163 LIBS="-l$i $mdw_save_LIBS"
164 AC_TRY_LINK([$5], [$1($6)],
165 [mdw_cv_lib_$1="-l$i"
168 LIBS="$mdw_save_LIBS"])
169 if test "$mdw_cv_lib_$1" != "no"; then
170 test "$mdw_cv_lib_$1" = "none required" || LIBS="$mdw_cv_lib_$1 $LIBS"
176 dnl --- *@-mdw__PERL_VERSION-@* ---
178 dnl AC_DEFUN relies on `[', `]' being quotes, so I have to drop down a level.
180 AC_DEFUN([mdw__PERL_VERSION], [mdw__PERL_VERSION_hack([$1], [$2])])
182 define(<<mdw__PERL_VERSION_hack>>, <<$1 -e 'exit ($] < $2);' >&5 2>&5>>)
185 dnl --- *@-mdw_PROG_PERL-@* ---
187 dnl Author: Mark Wooding
189 dnl Synopsis: mdw_PROG_PERL(VERSION, [IF-FOUND], [IF-NOT-FOUND])
191 dnl Arguments: VERSION = version number of Perl required
192 dnl IF-FOUND = what to do if it's found
193 dnl IF-NOT-FOUND = what to do if it isn't
195 dnl Use: Attempts to find a working version of Perl with a late
196 dnl enough version number. It supplies an option `--with-perl'
197 dnl to allow the user to provide a Perl interpreter. If one
198 dnl isn't provided explicitly, it searches for `perl' and `perl5'
199 dnl in the current PATH, asking them whether they have a late
200 dnl enough version number. The path of the working Perl is
201 dnl put into the `PERL' environment variable; `AC_SUBST' is used
202 dnl to substitute its value into Perl scripts. If there is no
203 dnl Perl to be found, the value of `PERL' is set to be `none'.
205 AC_DEFUN([mdw_PROG_PERL],
207 [ --with-perl=PERL specify path to Perl version $1 or newer],
209 if test -z "$PERL"; then
210 [AC_CACHE_CHECK([for Perl version $1 or later], mdw_cv_prog_perl,
211 [mdw_cv_prog_perl="none"
212 for p in `echo "$PATH:/usr/local/bin" | tr ":" " "`; do
213 case $p in /*) ;; *) p=`pwd`/$p ;; esac
214 if mdw__PERL_VERSION(["$p/perl"], $1); then
215 mdw_cv_prog_perl="$p/perl"
218 if mdw__PERL_VERSION(["$p/perl5"], $1); then
219 mdw_cv_prog_perl="$p/perl5"
223 PERL="$mdw_cv_prog_perl"])
227 if test "$PERL" = "none"; then :
233 dnl --- *@-mdw_CHECK_PERL-@* ---
235 dnl Author: Mark Wooding
237 dnl Synopsis: mdw_CHECK_PERL(VERSION)
239 dnl Arguments: VERSION = version number of Perl required
241 dnl Use: Verifies that the Perl interpreter in the `PERL' shell
242 dnl variable actually works and is of the right version. If it's
243 dnl not, an error is raised and configuration is aborted.
245 AC_DEFUN([mdw_CHECK_PERL],
246 [mdw_REQUIRE([mdw_PROG_PERL], [$1])
247 AC_MSG_CHECKING([whether Perl ($PERL) works])
248 if test "$PERL" != "none" && mdw__PERL_VERSION("$PERL", $1); then
252 AC_MSG_ERROR([Perl version $1 or newer not found.
253 If you have a recent enough Perl, and I just failed to find it, try using
254 the --with-perl=PERL option to give me an explicit pathname.])
257 dnl --- *@-mdw_PERLLIB_CHECK-@* ---
259 dnl Author: Mark Wooding
261 dnl Synopsis: mdw_PERLLIB_CHECK(LIBRARY)
263 dnl Arguments: LIBRARY = name of a Perl library to check for
265 dnl Use: Ensures that a Perl script can `use LIBRARY;'. If it can,
266 dnl all's well and good; if it can't, `LIBRARY.pm' is added to
267 dnl the variable `NEEDED_PERLLIBS' and a line which adds
268 dnl `pkgdatadir' to Perl's `@INC' array is placed in the
269 dnl variable `INC_PERLLIBS'; `AC_SUBST' is called for both of
270 dnl these variables. It's expected that `NEEDED_PERLLIBS' will
271 dnl be used in the `Makefile.in' to decide which versions from
272 dnl the distribution need installing.
274 dnl This macro isn't terribly useful in the general case. It
275 dnl Also implicitly assumes that `$PERL' is Perl 5 or later.
277 AC_DEFUN([mdw__PERLLIB_INIT],
278 [AC_SUBST(INC_PERLLIBS)dnl
279 AC_SUBST(NEEDED_PERLLIBS)dnl
282 AC_DEFUN([mdw_PERLLIB_CHECK],
283 [AC_REQUIRE([mdw__PERLLIB_INIT])
284 mdw_REQUIRE([mdw_CHECK_PERL], 5)
285 AC_CACHE_CHECK([for Perl library $1], mdw_cv_perllib_$1,
286 [if $PERL -e 'use $1;' >&5 2>&5; then
287 mdw_cv_perllib_$1="yes"
289 mdw_cv_perllib_$1="no"
292 if test "$mdw_cv_perllib_$1" = "no"; then
293 NEEDED_PERLLIBS="$NEEDED_PERLLIBS $1.pm"
295 # --- Deal with autoconf lossage ---
297 # It doesn't want to define `prefix' until rather later on, so I have
300 if test -z "$INC_PERLLIBS"; then
301 mdw_old_prefix="$prefix"
302 test "$prefix" = "NONE" && prefix="$ac_default_prefix";
303 INC_PERLLIBS="BEGIN { push @INC, \"`eval echo $datadir/$PACKAGE`\"; }"
304 prefix="$mdw_old_prefix";
308 dnl --- *@-mdw_GCC_FLAGS-@* ---
310 dnl Author: Mark Wooding
312 dnl Synopsis: mdw_GCC_FLAGS([FLAGS], [CFLAGS], [C++FLAGS])
314 dnl Arguments: FLAGS = GCC compiler flags to add (default is
315 dnl `-pedantic -Wall')
316 dnl CFLAGS = GCC C compiler flags to add (default is empty)
317 dnl C++FLAGS = GCC C++ compiler flags to add (default is
318 dnl `-fhandle-exceptions').
320 dnl Use: If the C compiler is GCC, add the compiler flags.
322 AC_DEFUN([mdw_GCC_FLAGS],
323 [if test "$GCC" = "yes"; then
324 CFLAGS="$CFLAGS ifelse([$1], [], [-pedantic -Wall], [$1])"
325 CFLAGS="$CFLAGS ifelse([$2], [], [], [$2])"
327 if test "$GXX" = "yes"; then
328 CXXFLAGS="$CXXFLAGS ifelse([$1], [], [-pedantic -Wall], [$1])"
329 CXXFLAGS="$CXXFLAGS ifelse([$3], [], [-fhandle-exceptions], [$3])"
332 dnl --- *@-mdw_INIT_LIB-@* ---
334 dnl Author: Mark Wooding
336 dnl Synopsis: mdw_INIT_LIB(LIB, NAME, VERSION, [PACKAGE])
338 dnl Arguments: LIB = the name of the library (and the package)
339 dnl NAME = a presentable version of the library's name
340 dnl VERSION = version of the library
341 dnl PACKAGE = package name to pass on to AM_INIT_AUTOMAKE
343 dnl Use: Sets up various useful variables. This macro calls
344 dnl AM_INIT_AUTOMAKE, which might be considered useful. It also
345 dnl provides variables for the use of `lib-config.in'.
347 AC_DEFUN([mdw_INIT_LIB],
348 [AM_INIT_AUTOMAKE(ifelse([$4], [], [$1], [$4]), [$3])
349 LIBRARY="$1" AC_SUBST(LIBRARY)
350 LIBNAME="$2" AC_SUBST(LIBNAME)])
352 dnl --- *@-mdw_LIB_CONFIG-@* ---
354 dnl Author: Mark Wooding
356 dnl Synopsis: mdw_LIB_CONFIG(LIB, NAME, VERSION, IF-FOUND, IF-NOT-FOUND)
358 dnl Arguments: LIB = the name of the library (and its configuration program)
359 dnl NAME = a presentable version of the library's name
360 dnl VERSION = version of library required
361 dnl IF-FOUND = what to do if found
362 dnl IF-NOT-FOUND = what to do if not found
364 dnl Use: Configures a library client program, using a configuration
365 dnl script provided by the library maintainer.
367 dnl The default version is 1.0.0pre0; the default action is to
368 dnl add everything to the CFLAGS and LIBS variables, and complain
369 dnl if the library couldn't be found.
371 dnl The variable LIB_VERSION contains the version number of
372 dnl the library; LIB_CFLAGS is the C compiler flags required
373 dnl and LIB_LIBS is the linker flags.
375 AC_DEFUN([mdw_LIB_CONFIG],
376 [pushdef([upname], translit([$1], [a-z], [A-Z]))dnl
377 AC_MSG_CHECKING([for $2 library])
378 if $1-config --check $3 >/dev/null 2>&1; then
379 upname[]_VERSION=`$1-config --version`
380 upname[]_CFLAGS=`$1-config --cflags`
381 upname[]_LIBS=`$1-config --libs`
382 AC_SUBST(upname[]_VERSION)
383 AC_SUBST(upname[]_CFLAGS)
384 AC_SUBST(upname[]_LIBS)
386 [CFLAGS="$CFLAGS $upname[]_CFLAGS"
387 LIBS="$upname[]_LIBS $LIBS"],
389 AC_MSG_RESULT([$upname[]_VERSION])
392 AC_MSG_ERROR([$2 library not found or too old.]),
394 AC_MSG_RESULT([not found])
398 dnl --- *@-mdw_MLIB-@* ---
400 dnl Author: Mark Wooding
402 dnl Synopsis: mdw_MLIB(VERSION, IF-FOUND, IF-NOT-FOUND
404 dnl Arguments: VERSION = version of library required
405 dnl IF-FOUND = what to do if found
406 dnl IF-NOT-FOUND = what to do if not found
408 dnl Use: Configures an mLib client program.
410 AC_DEFUN([mdw_MLIB], [mdw_LIB_CONFIG(mLib, mLib, $@)])
412 dnl --- *@-mdw_MGLIB-@* ---
414 dnl Author: Mark Wooding
416 dnl Synopsis: mdw_MGLIB(VERSION, IF-FOUND, IF-NOT-FOUND
418 dnl Arguments: VERSION = version of library required
419 dnl IF-FOUND = what to do if found
420 dnl IF-NOT-FOUND = what to do if not found
422 dnl Use: Configures an mgLib client program.
424 AC_DEFUN([mdw_MGLIB],
425 [mdw_REQUIRE([mdw_MLIB], [1.6.0])
426 mdw_LIB_CONFIG(mgLib, mgLib, $@)])
428 dnl --- *@-mdw_CATACOMB-@* ---
430 dnl Author: Mark Wooding
432 dnl Synopsis: mdw_CATACOMB([VERSION], [IF-FOUND], [IF-NOT-FOUND])
434 dnl Arguments: VERSION = version of Catacomb required
435 dnl IF-FOUND = what to do if found
436 dnl IF-NOT-FOUND = what to do if not found
438 dnl Use: Configures the program as a Catacomb client.
440 AC_DEFUN([mdw_CATACOMB],
441 [mdw_REQUIRE([mdw_MLIB], [1.6.0])
442 mdw_LIB_CONFIG(catacomb, Catacomb, $@)])
444 dnl --- *@-mdw_PK-@* ---
446 dnl Author: Mark Wooding
448 dnl Synopsis: mdw_PK([VERSION], [IF-FOUND], [IF-NOT-FOUND])
450 dnl Arguments: VERSION = version of PK required
451 dnl IF-FOUND = what to do if found
452 dnl IF-NOT-FOUND = what to do if not found
454 dnl Use: Configures the program as a PK client.
457 [mdw_REQUIRE([mdw_MLIB], [1.6.0])
458 mdw_LIB_CONFIG(pk, PK, $@)])
460 dnl --- *@-mdw_OPT_NDEBUG-@* ---
462 dnl Author: Mark Wooding
464 dnl Synopsis: mdw_OPT_NDEBUG
468 dnl Use: Turns on the `NDEBUG' flag, to disable useful things like
471 AC_DEFUN([mdw_OPT_NDEBUG],
472 [AC_ARG_ENABLE(debugging,
473 [ --disable-debugging spews vast swathes of useless information],
474 [if test "$enableval" = "no"; then
478 dnl --- *@-mdw_OPT_EFENCE-@* ---
480 dnl Author: Mark Wooding
482 dnl Synopsis: mdw_OPT_EFENCE
486 dnl Use: Links with the Electric Fence library.
488 AC_DEFUN([mdw_OPT_EFENCE],
489 [AC_ARG_WITH(electric-fence,
490 [ --with-electric-fence link programs with Electric Fence],
491 [if test "$withval" = "yes"; then
492 AC_CHECK_LIB(efence, malloc)
495 dnl --- *@-mdw_OPT_TRACE-@* ---
497 dnl Author: Mark Wooding
499 dnl Synopsis: mdw_OPT_TRACE
503 dnl Use: Turns on the `NTRACE' flag, to disable useful things like
506 AC_DEFUN([mdw_OPT_TRACE],
507 [AC_ARG_ENABLE(tracing,
508 [ --disable-tracing disable output of trace information],
509 [if test "$enableval" = "no"; then
513 dnl --- *@-mdw_OPT_mLib_TRACK-@* ---
515 dnl Author: Mark Wooding
517 dnl Synopsis: mdw_OPT_mLib_TRACK(PROGRAM)
519 dnl Arguments: PROGRAM = name of this program or package.
521 dnl Use: Controls the unsupported mLib memory tracker. The
522 dnl following are defined:
524 dnl --enable-track turns on malloc tracking
525 dnl --enable-blame-PROGRAM tracks malloc contexts in PROGRAM
527 dnl There must be a separate `blame' option for each program,
528 dnl so that the various blame options in a hierarchy get
529 dnl propagated properly. This is an obsolete feature from the
530 dnl days when mLib was provided as a subdirectory of other
533 AC_DEFUN([mdw_OPT_mLib_TRACK],
534 [AC_REQUIRE([mdw_OPT_TRACE])
536 [ --enable-track enable tracking of malloc and free],
537 [AC_DEFINE(TRACK_ENABLE, 1)])
538 AC_ARG_ENABLE(blame-$1,
540 track malloc contexts while in $1],
541 [AC_DEFINE(TRACK_BLAME, 1)])])
543 dnl --- *@-mdw_OPT_mLib_DEBUG-@* ---
545 dnl Author: Mark Wooding
547 dnl Synopsis: mdw_OPT_mLib_DEBUG(PROGRAM)
549 dnl Arguments: PROGRAM = name of this program or package.
551 dnl Use: Provides all of the above debugging options.
553 AC_DEFUN([mdw_OPT_mLib_DEBUG],
554 [mdw_REQUIRE([mdw_OPT_NDEBUG])
555 mdw_REQUIRE([mdw_OPT_mLib_TRACK], [$1])])
557 dnl --- *@-mdw_DEFINE_PATHS-@*
559 dnl Author: Mark Wooding
561 dnl Synopsis: mdw_DEFINE_FILES(CODE)
563 dnl Arguments: CODE = shell script code to execute
565 dnl Use: Fixes up various variables so that pathname defines can be
566 dnl defined. Within CODE, you may use the following macros:
568 dnl mdw_PROG(NAME) Transformed program name
570 dnl mdw_PATH(PATH) Expanded path (may contain variables)
572 dnl mdw_DEFINE_PROG(SYMBOL, PROG)
573 dnl Define a symbol as a transformed
576 dnl mdw_DEFINE_PATH(SYMBOL, NAME)
577 dnl Define a symbol as an expanded path
579 AC_DEFUN([mdw_DEFINE_PATHS],
580 [mdw_prefix=$prefix mdw_exec_prefix=$exec_prefix
581 mdw_transform=`echo "$program_transform_name"|sed 's,\\\\\\\\,\\\\,g; s,\\$\\$,$,g'`
582 test "$prefix" = "NONE" && prefix=$ac_default_prefix
583 test "$exec_prefix" = "NONE" && exec_prefix=$prefix
585 prefix=$mdw_prefix exec_prefix=$mdw_exec_prefix])
587 AC_DEFUN([mdw_PROG], [`echo "$1"|sed "$mdw_transform"`])
588 AC_DEFUN([mdw_PATH], [dnl
592 *\\$[]*) t=\`eval echo "$t"\`;; dnl
596 AC_DEFUN([mdw_DEFINE_PROG], [AC_DEFINE_UNQUOTED([$1], ["mdw_PROG([$2])"])])
597 AC_DEFUN([mdw_DEFINE_PATH], [AC_DEFINE_UNQUOTED([$1], ["mdw_PATH([$2])"])])
599 dnl --- *@-mdw_DIR_TEXMF-@* ---
601 dnl Author: Mark Wooding
603 dnl Synopsis: mdw_DIR_TEXMF
607 dnl Use: Sets the substitution `texmfdir' as a sensible TeX install
610 AC_DEFUN([mdw_DIR_TEXMF], [
611 AC_ARG_WITH([texmfdir],
612 [ --with-texmfdir=DIR set the TeX install directory to DIR],
614 [AC_MSG_CHECKING([where to put installed TeX files])
616 texmfdir='${datadir}/texmf'
618 '${datadir}/texmf' '${prefix}/lib/texmf' \
619 '${prefix}/texmf' '${libdir}/lib/texmf'; do
620 if test -d "mdw_PATH([$d])"; then
625 AC_MSG_RESULT([$texmfdir])])])
628 dnl --- *@-mdw_MANEXT-@* ---
630 dnl Author: Mark Wooding
632 dnl Synopsis: mdw_MANEXT
636 dnl Use: Sets the substitution `manext' for man page extensions.
638 AC_DEFUN([mdw_MANEXT], [
639 AC_ARG_WITH([man-ext],
640 [ --with-man-ext=EXT give manpages the EXT extension (e.g., foo.3EXT)],
641 [manext=$withval], [manext=mLib])
644 dnl----- That's all, folks --------------------------------- *@--GLOB-END--@*