Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

333 lines
13KB

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