[Mimedefang] PATCH: autoconf cleanups

James Ralston qralston+ml.mimedefang at andrew.cmu.edu
Wed Aug 1 16:21:09 EDT 2007


Mimedefang fails to detect libmilter on x86_64 systems, because it's
located in /usr/lib64, not /usr/lib, and mimedefang/configure.in is
calling AC_PATH_PROG with a hardcoded path.

When I went to fix this, I discovered that configure.in is "cheating"
in how it is using autoconf macros.  Take, for example:

    AC_PATH_PROG(LIBMILTER,
	 libmilter.a,
	 no,
	 $MILTERLIB:$SMPATH:/usr/local/lib:/lib:/usr/lib:/usr/lib/libmilter)

The reason why this is cheating is because AC_PATH_PROG is designed to
find programs, not library files.  And, in fact, recent versions of
autoconf won't consider a file that AC_PATH_PROG finds to be a match
unless the file is executable.  So, mimedefang's use of AC_PATH_PROG
never finds anything.

The solution I am using for my local builds of mimedefang is to use
AC_CHECK_HEADERS and AC_CHECK_LIB instead of AC_PATH_PROG.  I've
attached a patch that implements thus (plus some other autoconf
cleanups).

My patch does *not* implement the ability to link against a local
build tree of sendmail; it expects to see the milter include and
library files in the standard directory paths.  I think it would be
possible to add this capability back, but it would be fairly difficult
to do, and I'm not sure how many people nowadays need this capability.

David, does this fly with you?  I'd much rather see this patch (or
some flavor of it) incorporated upstream; it would save me a lot of
time having to continually regenerate it...
-------------- next part --------------
--- mimedefang-2.62/configure.in.autoconf-cleanups	2007-03-28 15:37:15.000000000 -0400
+++ mimedefang-2.62/configure.in	2007-08-01 15:57:18.000000000 -0400
@@ -30,7 +30,7 @@
 ], [socklen_t x;], ac_have_socklen_t=yes, ac_have_socklen_t=no)
 AC_MSG_RESULT($ac_have_socklen_t)
 if test "$ac_have_socklen_t" = "yes" ; then
-   AC_DEFINE(HAVE_SOCKLEN_T)
+   AC_DEFINE([HAVE_SOCKLEN_T], [], [Define if socklen_t is defined in <sys/socket.h>])
 fi
 
 for thing in prefix siteprefix vendorprefix installarchlib installprivlib installbin installman1dir installman3dir installscript installsitearch installsitelib; do
@@ -79,18 +79,6 @@
 
 AC_SUBST(IP_HEADER)
 
-dnl Allow user to tell us where milter includes are
-MILTERINC=
-AC_ARG_WITH(milterinc,
-[  --with-milterinc=PATH   specify alternative location of milter includes],
-   MILTERINC=$with_milterinc, MILTERINC=)
-
-dnl Allow user to tell us where milter libraries are
-MILTERLIB=
-AC_ARG_WITH(milterlib,
-[  --with-milterlib=PATH   specify alternative location of milter libraries],
-   MILTERLIB=$with_milterlib, MILTERLIB=)
-
 dnl Allow specification of sysconfig subdir
 AC_ARG_WITH(confsubdir,
 [  --with-confsubdir=DIR   specify configuration subdirectory
@@ -304,7 +292,7 @@
 AC_MSG_RESULT($ac_uint32_t_defined)
 
 if test "$ac_uint32_t_defined" = "yes" ; then
-   AC_DEFINE(HAVE_UINT32_T)
+   AC_DEFINE([HAVE_UINT32_T], [], [Define if uint32_t is defined in <stdint.h>])
 fi
 
 dnl Check if sys/types.h defines uint32_t
@@ -315,7 +303,7 @@
 AC_MSG_RESULT($ac_uint32_t_defined)
 
 if test "$ac_uint32_t_defined" = "yes" ; then
-   AC_DEFINE(HAVE_UINT32_T)
+   AC_DEFINE([HAVE_UINT32_T], [], [Define if uint32_t is defined in <sys/types.h>])
 fi
 
 if test "$HAVE_UNIX_SYSLOG" = "no" ; then
@@ -334,7 +322,7 @@
 ], [sig_atomic_t foo;], ac_have_sig_atomic_t=yes, ac_have_sig_atomic_t=no)
 AC_MSG_RESULT($ac_have_sig_atomic_t)
 if test "$ac_have_sig_atomic_t" = "yes" ; then
-   AC_DEFINE(HAVE_SIG_ATOMIC_T)
+   AC_DEFINE([HAVE_SIG_ATOMIC_T], [], [Define if sig_atomic_t is defined in <signal.h>])
 fi
 
 dnl Check if compiler allows "-pthread" option, but only if
@@ -478,11 +466,25 @@
 AC_CHECK_FUNCS(pathconf)
 AC_CHECK_FUNCS(inet_ntop)
 
-dnl Find sendmail include file.  The nasty path is in case you're building
-dnl Sendmail at the same level as MIMEDefang... we want to use that include
-dnl file...
-SMMILTER=`echo ../sendmail-*/include`
-AC_PATH_PROG(MINCLUDE, libmilter/mfapi.h, no, $MILTERINC:$SMMILTER:/usr/include:/usr/local/include:/usr/local/include/sendmail:/opt/local/include)
+AC_CHECK_HEADERS([libmilter/mfapi.h], [], [echo "ERROR: libmilter/mfapi.h is required - have you installed sendmail-devel?"; exit 1], [])
+AC_SUBST(MINCLUDE)
+
+# Check to make sure we can link against libmilter.  Also test all possible
+# dependency combinations that libmilter might have.  (This is ugly.)
+AC_CHECK_LIB([milter], [smfi_main])
+for dep_libs in '-lsfio' '-lsm' '-lsm -ldap' '-lsfio -lsm' '-lsfio -lsm -lldap'; do
+  if test $ac_cv_lib_milter_smfi_main = yes; then
+    break
+  else
+    # must unset this each time, else configure will cache "no" result
+    unset ac_cv_lib_milter_smfi_main
+  fi
+  AC_CHECK_LIB([milter], [smfi_main], [], [], [$dep_libs])
+done
+
+if test $ac_cv_lib_milter_smfi_main != yes; then
+  AC_MSG_ERROR([ERROR: libmilter is required - have you installed sendmail-devel?])
+fi
 
 if test "$SPOOLDIR" = "no" -o "$SPOOLDIR" = "" ; then
 	SPOOLDIR=/var/spool/MIMEDefang
@@ -623,15 +625,6 @@
     ENABLE_DEBUGGING=
 fi
 
-dnl find libmilter.a and libsm.a
-SMPATH=`echo ../sendmail-*/obj.*/libmilter`
-AC_PATH_PROG(LIBMILTER, libmilter.a, no, $MILTERLIB:$SMPATH:/usr/local/lib:/lib:/usr/lib:/usr/lib/libmilter)
-SMPATH=`echo ../sendmail-*/obj.*/libsm`
-AC_PATH_PROG(LIBSM, libsm.a, no, $SMPATH:/usr/local/lib:/lib:/usr/lib:/usr/lib/libmilter)
-
-dnl find libmilter.so in case we have shared libraries
-AC_PATH_PROG(LIBMILTERSO, libmilter.so, no, $MILTERLIB:$SMPATH:/usr/local/lib:/lib:/usr/lib:/usr/lib/libmilter)
-
 dnl find Sendmail
 if test "$SENDMAILPROG" = "no" ; then
    AC_PATH_PROG(SENDMAILPROG, sendmail, no, $PATH:/sbin:/usr/sbin:/usr/lib:/usr/libexec)
@@ -640,79 +633,8 @@
 dnl rm
 AC_PATH_PROG(RM, rm, no, $PATH)
 
-AC_DEFUN(MD_MILTER_SFIO,[
-    AC_MSG_CHECKING([whether libmilter requires -lsfio])
-    RESULT=`$NM $LIBMILTER | grep sfsprintf`
-    if test -z "$RESULT" ; then
-	AC_MSG_RESULT(no)
-    else
-	AC_MSG_RESULT(yes)
-	LIBS="$LIBS -lsfio"
-    fi
-])
-
-AC_DEFUN(MD_SM_LDAP,[
-    AC_MSG_CHECKING([whether libsm requires -lldap])
-    RESULT=`$NM $LIBSM | grep ldap_`
-    if test -z "$RESULT" ; then
-	AC_MSG_RESULT(no)
-    else
-	AC_MSG_RESULT(yes)
-	LIBS="$LIBS -lldap -llber"
-    fi
-])
-
-AC_DEFUN(MD_MILTER_SM,[
-    AC_MSG_CHECKING([whether libmilter requires -lsm])
-    RESULT=`$NM $LIBMILTER | grep sm_strlcpy`
-    if test -z "$RESULT" ; then
-	AC_MSG_RESULT(no)
-	LIBSM=""
-    else
-	AC_MSG_RESULT(yes)
-	LIBS="$LIBS"
-	if test "$LIBSM" = "no" ; then
-	    AC_MSG_WARN([Oops.. I couldn't find libsm.a.  Please install Sendmail 8.12])
-	    AC_MSG_WARN([and its libraries.])
-	    PROBLEM=1
-	else
-	    MD_SM_LDAP
-	fi
-    fi
-])
-
-
 dnl Sanity checks
 
-if test "$LIBMILTER" = "no" -a "$LIBMILTERSO" = "no" ; then
-    AC_MSG_WARN([Oops.. I couldn't find libmilter.a or libmilter.so.  Please install Sendmail])
-    AC_MSG_WARN([and its libraries.  You must run Build in the libmilter/ directory])
-    AC_MSG_WARN([to compile libmilter.])
-    PROBLEM=1
-fi
-
-if test "$LIBMILTER" != "no" ; then
-    LIBMILTERACTUAL="$LIBMILTER"
-else
-    LIBMILTERACTUAL="$LIBMILTERSO"
-fi
-
-dnl The directory containing libmilter
-LIBMILTERDIR=`dirname $LIBMILTERACTUAL`
-
-dnl Don't include standard directory paths
-if test "$LIBMILTERDIR" = "/usr/lib" -o "$LIBMILTERDIR" = "/lib" -o "$LIBMILTERDIR" = "/usr/lib64" -o "$LIBMILTERDIR" = "/lib64" ; then
-   LIBMILTERDIR=""
-else
-   LIBMILTERDIR="-L$LIBMILTERDIR"
-fi
-
-if test "$MINCLUDE" = "no" ; then
-    AC_MSG_WARN([Oops.. I couldn't find libmilter/mfapi.h.  Please install Sendmail 8.12])
-    AC_MSG_WARN([and its header files.])
-    PROBLEM=1
-fi
-
 if test "$SENDMAILPROG" = "no" ; then
     AC_MSG_WARN([Oops.. I couldn't find the 'sendmail' program.  Please install it.])
     PROBLEM=1
@@ -729,52 +651,11 @@
     fi
 fi
 
-dnl Fix up the include stuff
-MINCLUDE=`dirname $MINCLUDE`
-MINCLUDE=`dirname $MINCLUDE`
-
-dnl If MINCLUDE is "/usr/include", do NOT add to include path, because
-dnl this messes up compilation with gcc on Solaris.
-if test "$MINCLUDE" = "/usr/include" ; then
-   MINCLUDE=""
-else
-   MINCLUDE="-I${MINCLUDE}"
-fi
-
 AC_SUBST(ENABLE_DEBUGGING)
 AC_SUBST(PTHREAD_FLAG)
 VERSION=2.62
 AC_SUBST(VERSION)
 
-NEED_LIBSM=0
-dnl Jigger for machines without snprintf
-if test "$ac_cv_func_snprintf" != "yes" -o "$ac_cv_func_vsnprintf" != "yes" ; then
-   AC_MSG_RESULT([Your OS lacks snprintf or vsnprintf, but we'll use the])
-   AC_MSG_RESULT([equivalents in $LIBSM])
-   NEED_LIBSM=1
-   LIBS_WITHOUT_PTHREAD="$LIBSM $LIBS_WITHOUT_PTHREAD"
-fi
-
-dnl Check if our libmilter is old...
-if test "$AR" != "no" -a "$LIBMILTER" != "no" ; then
-   AC_MSG_CHECKING(whether libmilter must be linked with libsm)
-   $AR -t $LIBMILTER | fgrep strl.o > /dev/null 2>&1
-   if test "$?" = 0 ; then
-      AC_MSG_RESULT(no)
-   else
-      AC_MSG_RESULT(yes)
-      NEED_LIBSM=1
-   fi
-fi
-
-if test "$NEED_LIBSM" = 1 ; then
-   if test "$LIBSM" = "no" ; then
-      AC_MSG_ERROR([Problem: we need to link with libsm.a, but I can't find it.])
-      exit 1
-   fi
-   LIBS="$LIBSM $LIBS"
-fi
-
 AC_SUBST(LIBS_WITHOUT_PTHREAD)
 dnl evaluated versions of conf dir
 CONFDIR_EVAL=`echo ${sysconfdir}${CONFSUBDIR}`


More information about the MIMEDefang mailing list