Initial import of mutt-ng.
[apps/madmutt.git] / m4 / libesmtp.m4
1 dnl vim:ft=config:
2
3 dnl Search for libesmtp, by Steven Engelhardt <sengelha@yahoo.com>
4 dnl
5 dnl libesmtp often requires linking against -lpthread or -lc_r (BSD).
6 dnl This macro attempts to centralize this code.
7
8 AC_DEFUN([MUTT_AM_LIBESMTP],
9 [
10   AC_ARG_WITH(
11     [libesmtp],
12     [  --with-libesmtp=DIR      Compile in support for libesmtp for the MTA],
13     [ if test "$with_libesmtp" != "no"
14       then
15         mutt_libesmtp_check_path="$PATH"
16
17         if test "$with_libesmtp" != "yes"
18         then
19           mutt_libesmtp_check_path="$tmp_path:$withval/bin"
20         fi
21
22         dnl 1. Find libesmtp-config
23         AC_PATH_PROG([mutt_libesmtp_config_path],
24                      [libesmtp-config],
25                      [no],
26                      [$mutt_libesmtp_check_path])
27
28         if test "$mutt_libesmtp_config_path" = "no"
29         then
30           AC_MSG_ERROR([libesmtp-config binary not found.])
31         fi
32
33         dnl 2. Get CFLAGS and LIBS from libesmtp-config
34         mutt_libesmtp_cflags=`$mutt_libesmtp_config_path --cflags`
35         mutt_libesmtp_libs=`$mutt_libesmtp_config_path --libs`
36
37         dnl 3. Verify libesmtp.h can be found with these settings
38         temp_CFLAGS="$CFLAGS"
39         CFLAGS="$CFLAGS $mutt_libesmtp_cflags"
40         AC_CHECK_HEADER([libesmtp.h],
41                         [],
42                         AC_MSG_ERROR([Could not find libesmtp.h]))
43         CFLAGS="$temp_CFLAGS"
44
45         dnl 4. Verify the libesmtp library can be linked in
46         temp_CFLAGS="$CFLAGS"
47         temp_LIBS="$LIBS"
48         CFLAGS="$CFLAGS $mutt_libesmtp_cflags"
49         LIBS="$LIBS $mutt_libesmtp_libs"
50         AC_CHECK_LIB([esmtp],
51                      [smtp_create_session],
52                      [],
53                      AC_MSG_ERROR([Could not find libesmtp]))
54         CFLAGS="$temp_CFLAGS"
55         LIBS="$temp_LIBS"
56
57         dnl 5. Export use_libesmtp variable so configure.in can
58         dnl    act accordingly.
59         use_libesmtp=yes
60       fi
61     ]
62   )
63 ])