"Fossies" - the Fresh Open Source Software Archive

Member "amavisd-milter-1.7.2/aclocal/ax_path_milter.m4" (27 Jan 2019, 14744 Bytes) of package /linux/privat/amavisd-milter-1.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 dnl @synopsis AX_PATH_MILTER([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
    2 dnl
    3 dnl This macro tries to automatically find the library libmilter.a and
    4 dnl the header file "libmilter/mfapi.h", which are required when compiling
    5 dnl a milter for Sendmail.  When successful, it sets the output variable
    6 dnl MILTER_LIBS to "-lmilter", MILTER_LDFLAGS to contain an -Lpathtolib
    7 dnl option, and MILTER_CPPFLAGS to contain an -Ipathtoinclude option, if
    8 dnl they are necessary.
    9 dnl
   10 dnl The easiest way to use this macro is something like:
   11 dnl
   12 dnl   AX_PATH_MILTER([8.12],[
   13 dnl     LIBS="$MILTER_LIBS $LIBS"
   14 dnl     LDFLAGS="$MILTER_LDFLAGS $LDFLAGS"
   15 dnl     CPPFLAGS="$CPPFLAGS $MILTER_CPPFLAGS"
   16 dnl   ],[
   17 dnl     AC_MSG_ERROR([required milter library and header not found])
   18 dnl   ])
   19 dnl
   20 dnl If the macro is successful, it just adds any flags to the necessary
   21 dnl environment.  If it is not successful, it would likely be a fatal
   22 dnl error, because if an application is linking with libmilter.a,
   23 dnl it is probably because it is a milter.
   24 dnl
   25 dnl There are two optional "--with" options for configure which are added.
   26 dnl If they are specified, they override any searching that is done.
   27 dnl They are:
   28 dnl
   29 dnl   --with-sendmail-base=<DIR>  This option is used to explicitly
   30 dnl          specify the base of the sendmail distribution.
   31 dnl
   32 dnl   --with-sendmail-obj=<DIR>   The option is used to explicitly specify
   33 dnl          the "obj.*" subdirectory in the sendmail distribution
   34 dnl          that should be used.
   35 dnl
   36 dnl When sendmail-base is not specified, the current environment is first
   37 dnl tested to see if the header and library are available, and if so
   38 dnl MILTER_LDFLAGS and MILTER_CPPFLAGS are left empty.
   39 dnl
   40 dnl There are two places that are searched for the sendmail base
   41 dnl directory.  The first location is one directory down from the
   42 dnl current directory.  It checks if there is a directory of the
   43 dnl form sendmail-8.1*, limited to version 8.12.x or higher, then
   44 dnl chooses the directory with the highest version number.
   45 dnl If that method does not succeed, it then looks in the file
   46 dnl /etc/mail/sendmail.cf for the directory it was built from,
   47 dnl and uses the base of that distribution.  If neither of these
   48 dnl methods work, then it fails.
   49 dnl
   50 dnl There are two methods for finding the "obj.*" directory when it is
   51 dnl not specified.  The first is to try to run sendmail's Build program
   52 dnl with the -M option which will print out the name of the obj. directory
   53 dnl for the tool in the directory where it is run from.  If this
   54 dnl does not work, is looks for the newest directory of the
   55 dnl form "obj.*" in the sendmail base directory.
   56 dnl
   57 dnl Two addition output variables that are defined, whether or not the
   58 dnl files are found are SENDMAIL_BASE_DIR and SENDMAIL_OBJ_DIR, which
   59 dnl are the suspected location of the sendmail base directory and
   60 dnl obj.* subdirectory.
   61 dnl
   62 dnl NOTE: POSIX threads MUST be configured BEFORE this function is called
   63 dnl or it will not find libmilter.a even if it exists.  The easiest way is
   64 dnl to use the ACX_PTHREAD macro by Steven G. Johnson and Alejandro Forero
   65 dnl Cuervo which is available from the Autoconf Macro Archive.
   66 dnl
   67 dnl @author Tim Toolan <toolan@ele.uri.edu>
   68 dnl
   69 ###############################################################################
   70 AC_DEFUN([AX_PATH_MILTER], [
   71 
   72 # Used to indicate success or failure of this function.
   73 ax_path_milter_ok=no
   74 
   75 # Convert sections of MINIMUM-VERSION to three digit numbers by adding zeros.
   76 # For example 8.12.9 would become 008.012.009
   77 ac_milter_minimum_version=`echo "$1" | sed 's,\([[0-9]]*\),x\1x,g;s,x\([[0-9]]\)x,x0\1x,g;s,x\([[0-9]][[0-9]]\)x,x0\1x,g;s,x,,g'`
   78 
   79 # Add options --with-sendmail --with-sendmail-base and --with-sendmail-obj
   80 # to configure.
   81 AC_ARG_WITH([sendmail],
   82   [  --with-sendmail=<DIR>       base directory of sendmail installation])
   83 AC_ARG_WITH([sendmail-base],
   84   [  --with-sendmail-base=<DIR>  base directory of sendmail distribution])
   85 AC_ARG_WITH([sendmail-obj],
   86   [  --with-sendmail-obj=<DIR>   obj.* subdirectory in sendmail distribution])
   87 
   88 # Check for functions required by libmilter.
   89 AC_CHECK_FUNC(inet_aton, [], [AC_SEARCH_LIBS(inet_aton, [socket nsl resolv])])
   90 AC_CHECK_FUNC(socket, [], [AC_SEARCH_LIBS(socket, [socket nsl])])
   91 AC_CHECK_FUNC(gethostbyname, [], [AC_SEARCH_LIBS(gethostbyname, [socket nsl])])
   92 
   93 # Check if the linker accepts --rpath (for Darwin)
   94 AC_MSG_CHECKING([if ld accepts --rpath])
   95 SAVEDLDFLAGS=$LDFLAGS
   96 LDFLAGS=$LDFLAGS" -Wl,--rpath=/"
   97 AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
   98     [rpath="--rpath="; ldrpath=yes], [rpath="-L"; ldrpath=no])
   99 LDFLAGS=$SAVEDLDFLAGS
  100 AC_MSG_RESULT([$ldrpath])
  101 
  102 
  103 ###############################################################################
  104 #
  105 # If neither --with-sendmail-base or --with-sendmail-obj is specified
  106 # check the existing environment first for mfapi.h and libmilter without
  107 # modifying CPPFLAGS, LDFLAGS, and LIBS first.
  108 #
  109 if test "x$with_sendmail_base$with_sendmail_obj" = "x" ; then
  110   if test "x$with_sendmail" != "x" ; then
  111     CPPFLAGS="$CPPFLAGS -I$with_sendmail/include"
  112     LDFLAGS="$LDFLAGS -L$with_sendmail/lib -Wl,$rpath$with_sendmail/lib"
  113     AC_MSG_CHECKING([for sendmail install directory])
  114     AC_MSG_RESULT([$with_sendmail])
  115   else
  116     AC_MSG_CHECKING([for sendmail install directory])
  117     AC_MSG_RESULT([default])
  118   fi
  119   AC_CHECK_HEADER([libmilter/mfapi.h],[
  120     AC_CHECK_LIB([milter],[smfi_main],[
  121       # both tests succeeded so indicate success
  122       ax_path_milter_ok=yes
  123 
  124       # add -lmilter to the libraries to link
  125       MILTER_LIBS="-lmilter"
  126     ])
  127   ])
  128 
  129   # Debian use for libmilter.a /usr/lib/libmilter instead of /usr/lib
  130   if test "$ax_path_milter_ok" = "no" ; then
  131     unset ac_cv_lib_milter_smfi_main
  132     ac_milter_save_LDFLAGS="$LDFLAGS"
  133     MILTER_LDFLAGS="-L/usr/lib/libmilter"
  134     LDFLAGS="$MILTER_LDFLAGS $LDFLAGS"
  135     AC_CHECK_HEADER([libmilter/mfapi.h],[
  136       AC_CHECK_LIB([milter],[smfi_main],[
  137         # both tests succeeded so indicate success
  138         ax_path_milter_ok=yes
  139 
  140         # add -lmilter to the libraries to link
  141         MILTER_LIBS="-lmilter"
  142       ])
  143     ])
  144     LDFLAGS="$ac_milter_save_LDFLAGS"
  145   fi
  146 
  147   if test "$ax_path_milter_ok" = "no" ; then
  148     # Unset the cached test results because we will be trying them again later.
  149     ac_milter_tmp=abcdefg
  150     if unset ac_milter_tmp 2> /dev/null ; then
  151       unset ac_cv_header_libmilter_mfapi_h
  152       unset ac_cv_lib_milter_smfi_main
  153     else
  154       AC_MSG_WARN(
  155         [system doesn't have unset so either use --with-sendmail-base
  156          or set LDFLAGS and CPPFLAGS with the necessary -L and -I options])
  157     fi
  158   fi
  159 fi
  160 
  161 ###############################################################################
  162 #
  163 # If didn't already fine necessary files then search.
  164 #
  165 if test "$ax_path_milter_ok" = "no" ; then
  166   #############################################################################
  167   #
  168   # Determine the sendmail base directory and set SENDMAIL_BASE_DIR.
  169   #
  170   if test "x$with_sendmail_base" != "x" ; then
  171     AC_MSG_CHECKING([for sendmail base directory])
  172     # set SENDMAIL_BASE_DIR to the one specified by--with-sendmail-base
  173     SENDMAIL_BASE_DIR="$with_sendmail_base"
  174     AC_MSG_RESULT([$SENDMAIL_BASE_DIR])
  175   else
  176     AC_MSG_CHECKING([for sendmail base directory in ../ ])
  177     #
  178     # --with-sendmail-base is not used, so we will try to determine it
  179     #
  180     # 1) List all directories one level down that look like sendmail.
  181     # 2) Select ones that are sendmail 8.12 or higher (including 8.13
  182     #    versions when they come out).
  183     # 3) Replace any single digit last version numbers with a two digit
  184     #    version number (ie. 8.12.9 becomes 8.12.09).
  185     # 4) Sort all of the directories found in reverse order.
  186     # 5) Take the first one (the highest version).
  187     # 6) Restore the single digit version numbers.
  188     #
  189     ac_milter_tmp=`ls -d ../sendmail-8.1* 2> /dev/null | grep '../sendmail-8.1[[2-9]]' | sed 's,\.\([[0-9]]\)$,.0\1,' | sort -r | sed '1q' | sed 's,\.0\([[0-9]]\)$,.\1,'`
  190 
  191     # Convert found version sections to three digit numbers by adding zeros.
  192     ac_milter_found_version=`echo "$ac_milter_tmp" | sed 's,.*/sendmail-,,;s,\([[0-9]]*\),x\1x,g;s,x\([[0-9]]\)x,x0\1x,g;s,x\([[0-9]][[0-9]]\)x,x0\1x,g;s,x,,g'`
  193 
  194     # If ac_milter_minimum_version is equal to ac_milter_lower_version, then
  195     # the found version is greater than or equal to the minumum version.
  196     # Pick the version string that is the lesser of the two.
  197     # An empty string would be less than anything.
  198     # In short, ac_milter_version_ok will equal yes if the version is ok,
  199     # and no otherwise.
  200     ac_milter_version_ok=`echo "x$ac_milter_minimum_version
  201 x$ac_milter_found_version" | sort | sed '1q' | sed "s,x${ac_milter_minimum_version},yes,;s,x${ac_milter_found_version},no," `
  202 
  203     # If we have something add the current directory to it.
  204     if test "x$ac_milter_tmp" != "x" ; then
  205       ac_milter_tmp="`pwd`/$ac_milter_tmp"
  206     fi
  207 
  208     if test -r "${ac_milter_tmp}/include/libmilter/mfapi.h" && \
  209        test "$ac_milter_version_ok" = "yes" ; then
  210       # The file mfapi.h exists so we will use this as SENDMAIL_BASE_DIR.
  211       SENDMAIL_BASE_DIR="$ac_milter_tmp"
  212       AC_MSG_RESULT([$SENDMAIL_BASE_DIR])
  213     else
  214       AC_MSG_RESULT([no])
  215       AC_MSG_CHECKING([for sendmail base from /etc/mail/sendmail.cf])
  216       #
  217       # The previous method to find SENDMAIL_BASE_DIR failed, so we will
  218       # try this method.
  219       #
  220       # 1) Check for a line in /etc/mail/sendmail.cf of the form:
  221       #         ##### in /some/path/sendmail-8.x.x/more/path
  222       #    This is the directory that the sendmail.cf file was built in.
  223       # 2) Take the first occurrence if there are more than one.
  224       # 3) Remove the leading "##### in ".
  225       # 4) Remove everything after the sendmail-8.x.x path component.
  226       #
  227 dnl   # Note that the following expression only should not use double
  228 dnl   # square brackets because for some reason, possibly having to
  229 dnl   # do with the pound sign, m4 doesn't convert them to single brackets.
  230 dnl   #
  231       ac_milter_tmp=`grep "^##### in /" /etc/mail/sendmail.cf 2> /dev/null | grep "/sendmail-8.1" | sed '1q' | sed 's,^##### in ,,' | sed 's,\(/sendmail-8\.[0-9.]*\).*,\1,'`
  232 
  233       # Convert found version sections to three digit numbers by adding zeros.
  234       ac_milter_found_version=`echo "$ac_milter_tmp" | sed 's,.*/sendmail-,,;s,\([[0-9]]*\),x\1x,g;s,x\([[0-9]]\)x,x0\1x,g;s,x\([[0-9]][[0-9]]\)x,x0\1x,g;s,x,,g'`
  235 
  236       # ac_milter_version_ok will equal yes if the version is ok, otherwise no.
  237       ac_milter_version_ok=`echo "x$ac_milter_minimum_version
  238 x$ac_milter_found_version" | sort | sed '1q' | sed "s,x${ac_milter_minimum_version},yes,;s,x${ac_milter_found_version},no," `
  239 
  240       if test -r "${ac_milter_tmp}/include/libmilter/mfapi.h" && \
  241          test "$ac_milter_version_ok" = "yes" ; then
  242         # The file mfapi.h exists so we will use this as SENDMAIL_BASE_DIR.
  243         SENDMAIL_BASE_DIR="$ac_milter_tmp"
  244         AC_MSG_RESULT([$SENDMAIL_BASE_DIR])
  245       else
  246         AC_MSG_RESULT([no])
  247       fi
  248     fi
  249   fi
  250 
  251   #############################################################################
  252   #
  253   # Determine the sendmail obj.* directory and set SENDMAIL_OBJ_DIR.
  254   # We can only do this if we found SENDMAIL_BASE_DIR.
  255   #
  256   if test "x$SENDMAIL_BASE_DIR" != "x" ; then
  257     if test "x$with_sendmail_obj" != "x" ; then
  258       # set SENDMAIL_OBJ_DIR to the one specified by--with-sendmail-obj
  259       SENDMAIL_OBJ_DIR="$with_sendmail_obj"
  260     else
  261       AC_MSG_CHECKING([for sendmail obj.* subdirectory using Build -M])
  262       #
  263       # --with-sendmail-obj is not used, so we will try to determine it
  264       #
  265       # Try to run sendmail's Build program with the -M option which will
  266       # print out the name of the obj. directory for the tool in the
  267       # directory where it is run from.
  268       #
  269       ac_milter_tmp=`(cd ${SENDMAIL_BASE_DIR}/libmilter 1> /dev/null ; ./Build -M ) 2> /dev/null`
  270 
  271       if test -f "${ac_milter_tmp}/libmilter.a" ; then
  272         # libmilter.a exists so this is the one we will choose
  273         # Remove beginning and end of path from obj.* directory.
  274         SENDMAIL_OBJ_DIR=`echo "$ac_milter_tmp" | sed 's,/libmilter$,,;s,.*/,,'`
  275         AC_MSG_RESULT([${SENDMAIL_BASE_DIR}/${SENDMAIL_OBJ_DIR}])
  276       else
  277         AC_MSG_RESULT([no])
  278         AC_MSG_CHECKING([for sendmail obj.* subdirectory using ls])
  279         #
  280         # List all directories of the form "obj." in the sendmail base
  281         # directory, and choose the one with the latest modification date.
  282         #
  283         ac_milter_tmp=`ls -dt ${SENDMAIL_BASE_DIR}/obj.*/libmilter 2> /dev/null | sed '1q'`
  284 
  285         if test -f "${ac_milter_tmp}/libmilter.a" ; then
  286           # libmilter.a exists so this is the one we will choose
  287           # Remove beginning and end of path from obj.* directory.
  288           SENDMAIL_OBJ_DIR=`echo "$ac_milter_tmp" | sed 's,/libmilter$,,;s,.*/,,'`
  289           AC_MSG_RESULT([${SENDMAIL_BASE_DIR}/${SENDMAIL_OBJ_DIR}])
  290         else
  291           AC_MSG_RESULT([no])
  292         fi
  293       fi
  294     fi
  295   fi
  296 
  297   #############################################################################
  298   #
  299   # If we have both SENDMAIL_BASE_DIR and SENDMAIL_OBJ_DIR we will check
  300   # for the necessary files.
  301   #
  302   if test "x$SENDMAIL_BASE_DIR" != "x" && \
  303      test "x$SENDMAIL_OBJ_DIR" != "x" ; then
  304 
  305     # Save and modify CPPFLAGS.
  306     ac_milter_save_CPPFLAGS="$CPPFLAGS"
  307     MILTER_CPPFLAGS="-I$SENDMAIL_BASE_DIR/include"
  308     CPPFLAGS="$CPPFLAGS $MILTER_CPPFLAGS"
  309 
  310     # Save and modify LDFLAGS.
  311     ac_milter_save_LDFLAGS="$LDFLAGS"
  312     MILTER_LDFLAGS="-L${SENDMAIL_BASE_DIR}/${SENDMAIL_OBJ_DIR}/libmilter"
  313     LDFLAGS="$MILTER_LDFLAGS $LDFLAGS"
  314 
  315     AC_CHECK_HEADER([libmilter/mfapi.h],[
  316       AC_CHECK_LIB([milter],[smfi_main],[
  317         # both tests succeeded so add -lmilter to the libraries to link
  318         MILTER_LIBS="-lmilter"
  319 
  320         # indicate success
  321         ax_path_milter_ok=yes
  322       ])
  323     ])
  324 
  325     # Restore the modified environment
  326     CPPFLAGS="$ac_milter_save_CPPFLAGS"
  327     LDFLAGS="$ac_milter_save_LDFLAGS"
  328 
  329   fi
  330 fi
  331 
  332 # If failure, clear MILTER_LIBS, MILTER_LDFLAGS and MILTER_CPPFLAGS.
  333 if test "$ax_path_milter_ok" = "no" ; then
  334   MILTER_CPPFLAGS=""
  335   MILTER_LIBS=""
  336   MILTER_LDFLAGS=""
  337 fi
  338 
  339 # export these to the make environment
  340 AC_SUBST([MILTER_LIBS])
  341 AC_SUBST([MILTER_CPPFLAGS])
  342 AC_SUBST([MILTER_LDFLAGS])
  343 AC_SUBST([SENDMAIL_BASE_DIR])
  344 AC_SUBST([SENDMAIL_OBJ_DIR])
  345 
  346 # Indicate status of checking for libmilter stuff.
  347 AC_MSG_CHECKING([if files required by libmilter are present])
  348 
  349 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND.
  350 if test "$ax_path_milter_ok" = "yes" ; then
  351   AC_MSG_RESULT([yes])
  352   $2
  353 else
  354   AC_MSG_RESULT([no])
  355   $3
  356 fi
  357 
  358 ])dnl