2 dnl configure.ac -- autoconf template for mmh
7 dnl (I was able to configure with autoconf-2.59 --meillo 2012-03-22)
9 AC_INIT(mmh, m4_normalize(m4_include([VERSION])))
10 AC_CONFIG_SRCDIR(h/mh.h)
11 AC_CONFIG_HEADER(config.h)
15 dnl ---------------------
16 dnl define a macro or two
17 dnl ---------------------
19 AC_DEFUN(NMH_PROG_GNU_LIBTOOL, [
20 if test -n "$LIBTOOL" ; then
21 tmptest=`$LIBTOOL --version 2>&1 | grep GNU`
22 if test x"$tmptest" != x ; then
24 AC_SUBST(GNU_LIBTOOL)dnl
29 echo "configuring for AC_PACKAGE_NAME-AC_PACKAGE_VERSION"
30 AC_SUBST(VERSION,AC_PACKAGE_VERSION)dnl
32 dnl What date of mmh are we building?
33 DATE=`cat ${srcdir}/DATE`
34 echo "configuring for mmh dated $DATE"
37 dnl --------------------------
38 dnl CHECK COMMAND LINE OPTIONS
39 dnl --------------------------
41 dnl Do you want to debug mmh?
43 AS_HELP_STRING([--enable-debug],[enable nmh code debugging]))
44 dnl The old redundant --enable-nmh-debug is deprecated and undocumented.
45 if test x"$enable_nmh_debug" = x"yes"; then
49 dnl What method of locking to use?
51 AS_HELP_STRING([--with-locking=@<:@dot|fcntl|flock|lockf@:>@],
52 [specify the file locking method]))
54 if test x"$with_locking" = x"dot"; then
56 AC_DEFINE(DOT_LOCKING, 1, [Define to use dot based file locking.])dnl
57 elif test x"$with_locking" = x"flock"; then
59 AC_DEFINE(FLOCK_LOCKING, 1, [Define to use flock() based locking.])dnl
60 elif test x"$with_locking" = x"lockf"; then
62 AC_DEFINE(LOCKF_LOCKING, 1, [Define to use lockf() based locking.])dnl
63 elif test x"$with_locking" = x"fcntl"; then
65 AC_DEFINE(FCNTL_LOCKING, 1, [Define to use fnctl() based locking.])dnl
68 AC_DEFINE(DOT_LOCKING)dnl
72 dnl ----------------------------------------------------
73 dnl Default location is /usr/local/mmh/{bin,etc,lib,share/man}
74 dnl ----------------------------------------------------
75 AC_PREFIX_DEFAULT(/usr/local/mmh)
78 dnl ------------------
79 dnl CHECK THE COMPILER
80 dnl ------------------
81 dnl We want these before the checks,
82 dnl so the checks can modify their values.
83 test -z "$CFLAGS" && CFLAGS= auto_cflags=1
84 if test x"$enable_debug" = x"yes"; then
85 test -z "$LDFLAGS" && LDFLAGS=-g
90 AC_CACHE_CHECK(whether compiler supports -Wno-pointer-sign, nmh_cv_has_noptrsign,
91 [nmh_saved_cflags="$CFLAGS"
92 CFLAGS="$CFLAGS -Wno-pointer-sign"
93 AC_TRY_COMPILE([],[],nmh_cv_has_noptrsign=yes,nmh_cv_has_noptrsign=no)
94 CFLAGS="$nmh_saved_cflags"])
96 dnl if the user hasn't specified CFLAGS, then
97 dnl if compiler is gcc, then
98 dnl use -O2 and some warning flags
100 dnl We use -Wall; if the compiler supports it we also use -Wno-pointer-sign,
101 dnl because gcc 4 now produces a lot of new warnings which are probably mostly
102 dnl spurious and which in any case we don't want to deal with now.
103 if test "$nmh_cv_has_noptrsign" = "yes"; then
104 nmh_gcc_warnflags="-Wall -Wno-pointer-sign"
106 nmh_gcc_warnflags="-Wall"
109 if test -n "$auto_cflags"; then
110 if test x"$enable_debug" = x"yes"; then
111 if test -n "$GCC"; then
112 test -z "$CFLAGS" && CFLAGS="$nmh_gcc_warnflags -g" || CFLAGS="$CFLAGS $nmh_gcc_warnflags -g"
114 test -z "$CFLAGS" && CFLAGS=-g || CFLAGS="$CFLAGS -g"
117 if test -z "$LDFLAGS"; then
127 if test -n "$GCC"; then
128 test -z "$CFLAGS" && CFLAGS="$nmh_gcc_warnflags -O2" || CFLAGS="$CFLAGS $nmh_gcc_warnflags -O2"
130 test -z "$CFLAGS" && CFLAGS=-O || CFLAGS="$CFLAGS -O"
135 AC_C_CONST dnl Does compiler support `const'.
137 dnl ------------------
138 dnl CHECK FOR PROGRAMS
139 dnl ------------------
140 AC_PROG_MAKE_SET dnl Does make define $MAKE
141 AC_PROG_INSTALL dnl Check for BSD compatible `install'
142 AC_PROG_RANLIB dnl Check for `ranlib'
143 AC_PROG_AWK dnl Check for mawk,gawk,nawk, then awk
144 AC_PROG_LEX dnl Check for lex/flex
146 dnl Look for `realpath'
147 pathtmp=/bin:/usr/bin:/usr/local/bin
148 AC_PATH_PROG(realpathpath, realpath, no, [$pathtmp])
151 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
152 AC_PATH_PROG(cutpath, cut, no, [$pathtmp])
154 dnl ----------------------------------------------
155 dnl check for lclint, and lint if it doesn't exist
156 dnl ----------------------------------------------
157 AC_CHECK_PROG(linttmp1, lclint, lclint, no)dnl
158 if test x$ac_cv_prog_linttmp1 != xno ; then
159 LINT=$ac_cv_prog_linttmp1
160 LINTFLAGS="-weak +posixlib -macrovarprefixexclude"
162 AC_CHECK_PROG(linttmp2, lint, lint, no)dnl
163 if test x$ac_cv_prog_linttmp2 != xno ; then
164 LINT=$ac_cv_prog_linttmp2
167 LINT="echo 'No lint program found'"
172 AC_SUBST(LINTFLAGS)dnl
174 dnl try to figure out which one we've got
175 AC_CHECK_PROG(LIBTOOL, libtool, libtool, , [$pathtmp])
178 dnl Check for lorder and tsort commands
179 AC_CHECK_PROG(LORDER, lorder, lorder, no)dnl
180 AC_CHECK_PROG(TSORT, tsort, tsort, no)dnl
182 dnl If either doesn't exist, replace them with echo and cat
183 if test x$ac_cv_prog_LORDER != xlorder -o x$ac_cv_prog_TSORT != xtsort; then
188 dnl Mac OS X has lorder, but sh is too broken for it to work
189 dnl elif test -z "`lorder config/config.c 2>&1 | grep config/config.c`" ; then
192 dnl AC_SUBST(LORDER)dnl
193 dnl AC_SUBST(TSORT)dnl
196 dnl Check whether tsort can deal with loops
197 AC_CACHE_CHECK(whether tsort can deal with loops, nmh_cv_tsort_loop,
198 [if test -z "`echo a b b a | tsort 2>/dev/null | grep a`" ; then
201 nmh_cv_tsort_loop=yes
203 if test x$nmh_cv_tsort_loop = xno ; then
211 pathtmp=/usr/bin:/bin:/usr/local/bin:/usr/xpg4/bin:/usr/ucb
212 AC_PATH_PROG(lspath, ls, no, [$pathtmp])
214 dnl See how we get ls to display the owner and the group
215 if test "$lspath" != "no"; then
216 AC_CACHE_CHECK(how to get ls to show us the group ownership of a file,
218 [if test x"`$lspath -dl / | $AWK '{print $9}'`" = x"/"; then
219 dnl There were 9 parameters, so unless this is a really bizarre, nonstandard
220 dnl ls, it would seem -l gave us both the user and group. On this type of
221 dnl ls, -g makes _only_ the group be displayed (and not the user).
222 nmh_cv_ls_grpopt="-l"
224 dnl Looks like -l only gave us the user, so we need -g to get the group too.
225 nmh_cv_ls_grpopt="-lg"
229 dnl Look for `sendmail'
230 pathtmp=/usr/lib:/usr/sbin:/usr/etc:/usr/ucblib:/usr/bin:/bin
231 AC_PATH_PROG(sendmailpath, sendmail, /usr/sbin/sendmail, [$pathtmp])
234 pathtmp=/usr/bin:/bin:/usr/ucb:/usr/local/bin
235 AC_PATH_PROG(vipath, vi, /bin/vi, [$pathtmp])
237 dnl ----------------------------------------------------------
238 dnl FIND MAIL SPOOL AND SEE IF WE NEED TO MAKE inc SETGID MAIL
239 dnl ----------------------------------------------------------
240 AC_CACHE_CHECK(where mail spool is located, nmh_cv_mailspool,
241 [for mailspool in /var/mail dnl
244 /dev/null; dnl Just in case we fall through
246 mailspool = $realpathpath $mailspool;
247 test -d $mailspool && break
249 nmh_cv_mailspool=$mailspool
251 mailspool=$nmh_cv_mailspool
252 AC_SUBST(mailspool)dnl
254 dnl See whether the mail spool directory is world-writable.
255 if test "$lspath" != "no" -a "$cutpath" != "no"; then
256 AC_CACHE_CHECK(whether the mail spool is world-writable,
257 nmh_cv_mailspool_world_writable,
258 [if test "`$lspath -dlL $mailspool | $cutpath -c9`" = "-"; then
259 nmh_cv_mailspool_world_writable=no
261 nmh_cv_mailspool_world_writable=yes
265 dnl Also, check for liblockfile (as found on Debian systems)
266 AC_CHECK_HEADER(lockfile.h, AC_CHECK_LIB(lockfile, lockfile_create) )
268 dnl and whether its companion program dotlockfile is setgid
269 AC_PATH_PROG(dotlockfilepath, dotlockfile, no)
270 if test "$ac_cv_lib_lockfile_lockfile_create" != "no" ; then
271 if test "$ac_cv_path_dotlockfilepath" != "no" ; then
272 AC_CACHE_CHECK(whether dotlockfile is setgid, nmh_cv_dotlockfile_setgid,
273 [ if test -g "$ac_cv_path_dotlockfilepath" ; then
274 nmh_cv_dotlockfile_setgid=yes
276 nmh_cv_dotlockfile_setgid=no
281 dnl If mailspool is not world-writable and dotlockfile is not setgid,
282 dnl we need to #define MAILGROUP to 1 and make inc setgid.
283 if test x"$LOCKTYPE" = x"dot" -a x"$nmh_cv_mailspool_world_writable" = x"no" -a x"$nmh_cv_dotlockfile_setgid" != x"yes" ; then
284 dnl do we really need both of these?
285 AC_DEFINE(MAILGROUP,1,
286 [Define to 1 if you need to make `inc' set-group-id because your mail spool is not world writable. There are no guarantees as to the safety of doing this, but this #define will add some extra security checks.])dnl
289 AC_SUBST(SETGID_MAIL)dnl
291 dnl Use ls to see which group owns the mail spool directory.
292 AC_CACHE_CHECK(what group owns the mail spool, nmh_cv_ls_mail_grp,
293 [nmh_cv_ls_mail_grp=`$lspath -dL $nmh_cv_ls_grpopt $mailspool|$AWK '{print $4}'`
295 MAIL_SPOOL_GRP=$nmh_cv_ls_mail_grp
296 AC_SUBST(MAIL_SPOOL_GRP)dnl
298 dnl ------------------
299 dnl CHECK HEADER FILES
300 dnl ------------------
302 dnl On glibc we need to define at least the '_XOPEN_SOURCE' level of features,
303 dnl or wchar.h doesn't declare a prototype for wcwidth(). But if we only define
304 dnl that level then db.h won't compile. So we define _GNU_SOURCE which turns
305 dnl on everything. Perhaps other OSes need some feature switch set to get wcwidth()
306 dnl declared; if so they should have an entry added to this case statement.
307 dnl NB that we must define this on the compiler command line, not in config.h,
308 dnl because it must be set before any system header is included and there's no
309 dnl portable way to make sure that files generated by lex include config.h
310 dnl before system header files.
314 # Like DEFS, but doesn't get stomped on by configure when using config.h:
315 OURDEFS="$OURDEFS -D_GNU_SOURCE"
322 AC_CHECK_HEADERS(fcntl.h crypt.h termcap.h \
323 langinfo.h wchar.h wctype.h iconv.h \
324 sys/param.h sys/time.h sys/stream.h )
327 dnl Checks for _IO_write_ptr. A Linuxism used by nmh on linux. We
328 dnl really use a whole set of them, but this check should be
331 AC_CHECK_HEADER(libio.h, [
332 AC_EGREP_HEADER(_IO_write_ptr, libio.h, [
333 AC_DEFINE(LINUX_STDIO,1,[Use the Linux _IO_*_ptr defines from <libio.h>.]) ]) ])
335 AC_CHECK_HEADER([sys/ptem.h], AC_DEFINE(WINSIZE_IN_PTEM,1,
336 [Define to 1 if `struct winsize' requires <sys/ptem.h>.]),,
337 [[#if HAVE_SYS_STREAM_H
338 # include <sys/stream.h>
345 AC_CHECK_FUNCS(nl_langinfo mbtowc wcwidth)
347 dnl Look for the initgroups() declaration. On AIX 4.[13], Solaris 4.1.3, and
348 dnl ULTRIX 4.2A the function is defined in libc but there's no declaration in
349 dnl any system header.
351 dnl On Solaris 2.[456], the declaration is in <grp.h>. On HP-UX 9-11 and
352 dnl (reportedly) FreeBSD 3.[23], it's in <unistd.h>. Any other locations we
354 AH_TEMPLATE(INITGROUPS_HEADER, [Define to the header containing the declaration of `initgroups'.])
355 AC_EGREP_HEADER(initgroups, grp.h, AC_DEFINE(INITGROUPS_HEADER, <grp.h>),
356 AC_EGREP_HEADER(initgroups, unistd.h,
357 AC_DEFINE(INITGROUPS_HEADER, <unistd.h>)))
359 dnl Check for multibyte character set support
360 if test "x$ac_cv_header_wchar_h" = "xyes" -a "x$ac_cv_header_wctype_h" = "xyes" \
361 -a "x$ac_cv_func_wcwidth" = "xyes" -a "x$ac_cv_func_mbtowc" = "xyes"; then
362 AC_DEFINE(MULTIBYTE_SUPPORT, 1,
363 [Define to enable support for multibyte character sets.])
366 dnl -------------------
367 dnl CHECK FOR LIBRARIES
368 dnl -------------------
369 dnl Check location of modf
370 AC_CHECK_FUNC(modf, , AC_CHECK_LIB(m, modf))
372 dnl Checks for network libraries (nsl, socket)
375 termcap_curses_order="termcap curses ncurses"
376 for lib in $termcap_curses_order; do
377 AC_CHECK_LIB(${lib}, tgetent, [TERMLIB="-l$lib"; break])
380 if test "x$TERMLIB" = "x"; then
381 echo 'Could not find tgetent() in any library.'
382 echo 'Is there a ncurses-devel package that you can install?'
391 dnl Find iconv. It may be in libiconv and may be iconv() or libiconv()
392 if test "x$ac_cv_header_iconv_h" = "xyes"; then
393 AC_CHECK_FUNC(iconv, ac_found_iconv=yes, ac_found_iconv=no)
394 if test "x$ac_found_iconv" = "xno"; then
395 AC_CHECK_LIB(iconv, iconv, ac_found_iconv=yes)
396 if test "x$ac_found_iconv" = "xno"; then
397 AC_CHECK_LIB(iconv, libiconv, ac_found_iconv=yes)
399 if test "x$ac_found_iconv" != "xno"; then
403 dnl Handle case where there is a native iconv but iconv.h is from libiconv
404 AC_CHECK_DECL(_libiconv_version,
405 [ AC_CHECK_LIB(iconv, libiconv, LIBS="-liconv $LIBS") ],,
406 [ #include <iconv.h> ])
409 if test "x$ac_found_iconv" = xyes; then
410 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
413 dnl Check if iconv uses const in prototype declaration
414 if test "x$ac_found_iconv" = "xyes"; then
415 AC_CACHE_CHECK(for iconv declaration, ac_cv_iconv_const,
416 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
417 #include <iconv.h>]],
421 #if defined(__STDC__) || defined(__cplusplus)
422 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
426 [ac_cv_iconv_const=],
427 [ac_cv_iconv_const=const])])
428 AC_DEFINE_UNQUOTED([ICONV_CONST], $ac_cv_iconv_const,
429 [Define as const if the declaration of iconv() needs const.])
433 dnl ---------------------
434 dnl CHECK TERMCAP LIBRARY
435 dnl ---------------------
437 dnl Add the termcap library, so that the following configure
438 dnl tests will find it when it tries to link test programs.
439 nmh_save_LIBS="$LIBS"
440 LIBS="$TERMLIB $LIBS"
442 dnl Check if tgetent accepts NULL (and will allocate its own termcap buffer)
443 dnl Some termcaps reportedly accept a zero buffer, but then dump core
445 dnl Under Cygwin test program crashes but exit code is still 0. So,
446 dnl we test for a file that porgram should create
447 AH_TEMPLATE([TGETENT_ACCEPTS_NULL],
448 [Define to 1 if tgetent() accepts NULL as a buffer.])
449 AC_CACHE_CHECK(if tgetent accepts NULL,
450 nmh_cv_func_tgetent_accepts_null,
455 int r1 = tgetent(buf, "vt100");
456 int r2 = tgetent(NULL,"vt100");
457 if (r1 >= 0 && r1 == r2) {
461 creat("conftest.tgetent", 0640);
463 exit((r1 != r2) || r2 == -1);
466 if test -f conftest.tgetent; then
467 nmh_cv_func_tgetent_accepts_null=yes
469 nmh_cv_func_tgetent_accepts_null=no
471 nmh_cv_func_tgetent_accepts_null=no,
472 nmh_cv_func_tgetent_accepts_null=no)])
473 if test x$nmh_cv_func_tgetent_accepts_null = xyes; then
474 AC_DEFINE(TGETENT_ACCEPTS_NULL)
476 AC_CACHE_CHECK(if tgetent returns 0 on success,
477 nmh_cv_func_tgetent_zero_success,
482 int r1 = tgetent(buf, "!@#$%^&*");
483 int r2 = tgetent(buf, "vt100");
484 if (r1 < 0 && r2 == 0) {
488 creat("conftest.tgetent0", 0640);
493 if test -f conftest.tgetent0; then
494 nmh_cv_func_tgetent_zero_success=yes
496 nmh_cv_func_tgetent_zero_success=no
498 nmh_cv_func_tgetent_zero_success=no,
499 nmh_cv_func_tgetent_zero_success=no)])
500 AH_TEMPLATE([TGETENT_SUCCESS],
501 [Define to what tgetent() returns on success (0 on HP-UX X/Open curses).])
502 if test x$nmh_cv_func_tgetent_zero_success = xyes; then
503 AC_DEFINE(TGETENT_SUCCESS, 0)
505 AC_DEFINE(TGETENT_SUCCESS, 1)
508 dnl Now put the libraries back to what it was before we
509 dnl starting checking the termcap library.
510 LIBS="$nmh_save_LIBS"
525 dnl For platforms such as FreeBSD that have tm_gmtoff in struct tm.
526 dnl (FreeBSD has a timezone() function but not a timezone global
527 dnl variable that is visible).
528 AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[#include <time.h>])
530 AC_STRUCT_DIRENT_D_TYPE
532 dnl Where is <signal.h> located? Needed as input for signames.awk
533 AC_CACHE_CHECK(where signal.h is located, nmh_cv_path_signal_h,
534 [for SIGNAL_H in /usr/include/bsd/sys/signal.h dnl Next
535 /usr/include/asm/signal.h dnl Linux 1.3.0 and above
536 /usr/include/asm/signum.h dnl some versions of Linux/Alpha
537 /usr/include/linux/signal.h dnl Linux up to 1.2.11
538 /usr/include/sys/signal.h dnl Almost everybody else
539 /dev/null; dnl Just in case we fall through
541 test -f $SIGNAL_H && \
542 grep '#[ ]*define[ ][ ]*SIG[0-9A-Z]*[ ]*[0-9][0-9]*' $SIGNAL_H > /dev/null && \
545 nmh_cv_path_signal_h=$SIGNAL_H
547 SIGNAL_H=$nmh_cv_path_signal_h
548 AC_SUBST(SIGNAL_H)dnl
554 AC_CONFIG_FILES(Makefile config/Makefile h/Makefile sbr/Makefile uip/Makefile \
555 etc/Makefile docs/Makefile man/Makefile)
556 AC_CONFIG_COMMANDS([stamp],[test -z "$CONFIG_HEADERS" || echo > stamp-h])
559 dnl These odd looking assignments are done to expand out unexpanded
560 dnl variables in bindir et al (for instance mandir is '${datarootdir}/man',
561 dnl but expanding that gives '${prefix}/share/man', so we need to expand
562 dnl again to get the final answer.
563 dnl We only use the expanded versions to print the install paths in
564 dnl the final summary and should use them nowhere else (see the autoconf
565 dnl docs for the rationale for bindir etc being unexpanded).
566 eval "nmhbin=${bindir}"; eval "nmhbin=${nmhbin}"
567 eval "nmhsysconf=${sysconfdir}"; eval "nmhsysconf=${nmhsysconf}"
568 eval "nmhlib=${libdir}"; eval "nmhlib=${nmhlib}"
569 eval "nmhman=${mandir}"; eval "nmhman=${nmhman}"
574 mmh version : AC_PACKAGE_VERSION
575 target os : ${target}
577 compiler flags : ${CFLAGS}
578 linker flags : ${LDFLAGS}
579 definitions : ${OURDEFS}
580 source code location : ${srcdir}
582 binary install path : ${nmhbin}
583 library install path : ${nmhlib}
584 config install path : ${nmhsysconf}
585 man page install path : ${nmhman}
587 sendmail path : ${sendmailpath}
588 mail spool : ${mailspool}
590 file locking type : ${LOCKTYPE}