1dnl configure.ac
2dnl Process this file with autoconf to produce a configure script.
3#
4# This file is part of msmtp, an SMTP client.
5#
6# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
7# 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021
8# Christophe Nowicki
9# Martin Lambers <marlam@marlam.de>
10# Jay Soffian <jaysoffian@gmail.com> (Mac OS X keychain support)
11#
12#   This program is free software; you can redistribute it and/or modify
13#   it under the terms of the GNU General Public License as published by
14#   the Free Software Foundation; either version 3 of the License, or
15#   (at your option) any later version.
16#
17#   This program is distributed in the hope that it will be useful,
18#   but WITHOUT ANY WARRANTY; without even the implied warranty of
19#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20#   GNU General Public License for more details.
21#
22#   You should have received a copy of the GNU General Public License
23#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
24#
25
26dnl Autotools init stuff
27AC_INIT([msmtp],[1.8.19],[marlam@marlam.de],[msmtp],[https://marlam.de/msmtp])
28AC_CONFIG_SRCDIR([src/msmtp.c])
29AC_CONFIG_AUX_DIR([build-aux])
30AC_CONFIG_HEADERS([config.h])
31AC_CANONICAL_TARGET
32AC_USE_SYSTEM_EXTENSIONS
33AC_SYS_LARGEFILE
34AM_INIT_AUTOMAKE([1.11.1 silent-rules no-texinfo.tex -Wall])
35AM_SILENT_RULES([yes])
36AC_PROG_CC
37AC_PROG_INSTALL
38AC_LANG([C])
39
40dnl System
41build_msmtpd_default="yes"
42AC_DEFINE_UNQUOTED([PLATFORM], ["${target}"], [Platform triplet])
43case "${target}" in *-*-mingw*) LIBS="$LIBS -lws2_32"; build_msmtpd_default="no" ;; esac
44
45dnl Gettext
46AM_GNU_GETTEXT([external])
47
48dnl Headers, functions, and types
49AC_CHECK_HEADERS([fnmatch.h sysexits.h netdb.h arpa/inet.h sys/select.h sys/socket.h sys/wait.h netinet/in.h])
50AC_CHECK_FUNCS([fmemopen fseeko fseeko64 getpass link signal strndup syslog vasprintf])
51AC_SEARCH_LIBS([nanosleep], [rt posix4])
52AC_SEARCH_LIBS([socket], [socket])
53
54dnl Unfortunately AC_SEARCH_LIBS([res_query], [resolv]) does not work because we
55dnl apparently need to include the appropriate header files, so we use a double
56dnl AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[],[]) instead.
57AC_MSG_CHECKING([for library containing res_query])
58AC_LINK_IFELSE([AC_LANG_PROGRAM([[
59    #include <netinet/in.h>
60    #include <arpa/nameser.h>
61    #include <resolv.h>
62    ]], [[res_query(0, 0, 0, 0, 0); ns_initparse(0, 0, 0);]])],[found_res_query=yes],[found_res_query=no])
63if test "$found_res_query" = "yes"; then
64    AC_MSG_RESULT([none required])
65else
66    LIBS_BAK="$LIBS"
67    LIBS="$LIBS -lresolv"
68    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
69        #include <netinet/in.h>
70        #include <arpa/nameser.h>
71        #include <resolv.h>
72        ]], [[res_query(0, 0, 0, 0, 0); ns_initparse(0, 0, 0);]])],[found_res_query=yes],[found_res_query=no])
73    if test "$found_res_query" = "yes"; then
74        AC_MSG_RESULT([-lresolv])
75    else
76        LIBS="$LIBS_BAK"
77        AC_MSG_RESULT([none])
78    fi
79fi
80if test "$found_res_query" = "yes"; then
81    AC_DEFINE([HAVE_LIBRESOLV], [1], [Define to 1 if libresolv is available])
82fi
83
84dnl pkg-config (required to detect libraries)
85PKG_PROG_PKG_CONFIG([])
86if test -z "$PKG_CONFIG"; then
87    AC_MSG_ERROR([pkg-config not found])
88fi
89
90dnl TLS
91have_tls="no"
92tls_lib="none"
93want_tls="yes"
94want_gnutls="yes"
95want_openssl="no"
96want_libtls="no"
97tls_CFLAGS=""
98tls_LIBS=""
99with_ssl_was_used=no
100AC_ARG_WITH([tls], [AS_HELP_STRING([--with-tls=[gnutls|openssl|libtls|no]],
101    [TLS support: GnuTLS (default), OpenSSL (discouraged), libtls, or none.])],
102    if test "$withval" = "gnutls"; then
103	want_tls=yes
104	want_gnutls=yes
105	want_openssl=no
106	want_libtls=no
107    elif test "$withval" = "openssl"; then
108	want_tls=yes
109	want_gnutls=no
110	want_openssl=yes
111	want_libtls=no
112    elif test "$withval" = "libtls"; then
113	want_tls=yes
114	want_gnutls=no
115	want_openssl=no
116	want_libtls=yes
117    elif test "$withval" = "no"; then
118	want_tls=no
119	want_gnutls=no
120	want_openssl=no
121	want_libtls=no
122    else
123	AC_MSG_ERROR([Use --with-tls=gnutls or --with-tls=openssl or --with-tls=libtls or --with-tls=no])
124    fi)
125if test "$want_gnutls" = "yes"; then
126    PKG_CHECK_MODULES([libgnutls], [gnutls >= 3.4], [HAVE_LIBGNUTLS=1], [HAVE_LIBGNUTLS=0])
127    if test "$HAVE_LIBGNUTLS" != "1"; then
128	AC_MSG_WARN([library libgnutls not found:])
129	AC_MSG_WARN([$libgnutls_PKG_ERRORS])
130	AC_MSG_WARN([libgnutls is provided by GnuTLS])
131    else
132	have_tls="yes"
133	tls_lib="GnuTLS"
134	tls_CFLAGS="$libgnutls_CFLAGS"
135	tls_LIBS="$libgnutls_LIBS"
136	AC_DEFINE([HAVE_LIBGNUTLS], [1], [Define to 1 if libgnutls is available])
137    fi
138fi
139if test "$want_openssl" = "yes" -a "$have_tls" = "no"; then
140    AC_MSG_WARN([Using OpenSSL is discouraged; consider using GnuTLS instead])
141    PKG_CHECK_MODULES([libssl], [openssl >= 0.0], [HAVE_LIBSSL=1], [HAVE_LIBSSL=0])
142    if test "$HAVE_LIBSSL" != "1"; then
143	AC_MSG_WARN([library libssl not found:])
144	AC_MSG_WARN([$libssl_PKG_ERRORS])
145	AC_MSG_WARN([libssl is provided by OpenSSL])
146    else
147	have_tls="yes"
148	tls_lib="OpenSSL"
149	tls_CFLAGS="$libssl_CFLAGS"
150	tls_LIBS="$libssl_LIBS"
151	AC_DEFINE([HAVE_LIBSSL], [1], [Define to 1 if libssl is available])
152    fi
153fi
154if test "$want_libtls" = "yes" -a "$have_tls" = "no"; then
155    PKG_CHECK_MODULES([libtls], [libtls >= 0.0], [HAVE_LIBTLS=1], [HAVE_LIBTLS=0])
156    if test "$HAVE_LIBTLS" != "1"; then
157	AC_MSG_WARN([library libtls not found:])
158	AC_MSG_WARN([$libtls_PKG_ERRORS])
159	AC_MSG_WARN([libtls is provided by LibreSSL])
160    else
161	have_tls="yes"
162	tls_lib="libtls"
163	tls_CFLAGS="$libtls_CFLAGS"
164	tls_LIBS="$libtls_LIBS"
165	AC_DEFINE([HAVE_LIBTLS], [1], [Define to 1 if libtls is available])
166    fi
167fi
168if test "$have_tls" = "yes"; then
169    AC_DEFINE([HAVE_TLS], [1], [Define to 1 to build with TLS/SSL support])
170elif test "$want_tls" = "yes"; then
171    AC_MSG_WARN([Disabling TLS support, which is very bad. Consider using GnuTLS!])
172fi
173AM_CONDITIONAL([HAVE_TLS], [test "$have_tls" = "yes"])
174AM_CONDITIONAL([HAVE_GNUTLS], [test "$tls_lib" = "GnuTLS"])
175AM_CONDITIONAL([HAVE_OPENSSL], [test "$tls_lib" = "OpenSSL"])
176AM_CONDITIONAL([HAVE_LIBTLS], [test "$tls_lib" = "libtls"])
177AC_SUBST([tls_CFLAGS])
178AC_SUBST([tls_LIBS])
179
180dnl GNU SASL
181AC_ARG_WITH([libgsasl], [AS_HELP_STRING([--with-libgsasl],
182	[Use GNU SASL authentication library.])],
183    [libgsasl=$withval], [libgsasl=no])
184if test "$libgsasl" != "no"; then
185    PKG_CHECK_MODULES([libgsasl], [libgsasl >= 0.0], [HAVE_LIBGSASL=1], [HAVE_LIBGSASL=0])
186    if test "$HAVE_LIBGSASL" != "1"; then
187	AC_MSG_WARN([library libgsasl not found:])
188	AC_MSG_WARN([$libgsasl_PKG_ERRORS])
189	AC_MSG_WARN([libgsasl is provided by GNU SASL])
190	libgsasl="no"
191    else
192	libgsasl="yes"
193	AC_DEFINE([HAVE_LIBGSASL], [1], [Define to 1 if libgsasl is available])
194    fi
195fi
196AM_CONDITIONAL([HAVE_LIBGSASL], [test "$libgsasl" = "yes"])
197
198dnl Check if getaddrinfo() has IDN support (and we want to use it)
199AC_ARG_ENABLE([gai-idn],
200    [AS_HELP_STRING([--enable-gai-idn], [Use IDN support from getaddrinfo if available. Enabled by default.])],
201    [if test "$enableval" = "yes"; then want_gai_idn="yes"; else want_gai_idn="no"; fi], [want_gai_idn="yes"])
202have_gai_idn=no
203if test "$want_gai_idn" = "yes"; then
204    dnl TODO: in the future there may be getaddrinfo() implementations that
205    dnl support IDN without requiring AI_IDN
206    AC_CHECK_DECL([AI_IDN], [], [],
207    [
208     #include <sys/types.h>
209     #include <sys/socket.h>
210     #include <netdb.h>
211    ])
212    if test "$ac_cv_have_decl_AI_IDN" = "yes"; then
213	dnl AI_IDN is defined, now check if it is actually supported
214	dnl (glibc without libidn will return EAI_BADFLAGS)
215        AC_MSG_CHECKING([whether getaddrinfo accepts AI_IDN])
216	AC_RUN_IFELSE(
217            [AC_LANG_PROGRAM(
218            [[
219             #include <sys/types.h>
220             #include <sys/socket.h>
221	     #include <netdb.h>
222            ]],
223            [[
224             struct addrinfo hints;
225             struct addrinfo *res;
226             int r;
227             hints.ai_flags = AI_IDN;
228             hints.ai_family = PF_UNSPEC;
229             hints.ai_socktype = SOCK_STREAM;
230             hints.ai_protocol = 0;
231             hints.ai_addrlen = 0;
232             hints.ai_addr = 0;
233             hints.ai_canonname = 0;
234             hints.ai_next = 0;
235             r = getaddrinfo("localhost", "1234", &hints, &res);
236             freeaddrinfo(res);
237             return (r == EAI_BADFLAGS ? 1 : 0);
238	    ]])],
239            [have_gai_idn="yes"],
240	    [have_gai_idn="no"],
241	    [have_gai_idn="assuming yes"])
242        AC_MSG_RESULT([$have_gai_idn])
243        if test "$have_gai_idn" = "assuming yes"; then
244            AC_MSG_NOTICE([if this assumption is wrong, use --disable-gai-idn])
245            have_gai_idn="yes"
246        fi
247        if test "$have_gai_idn" = "yes"; then
248            AC_DEFINE([HAVE_GAI_IDN], [1], [Define to 1 if getaddrinfo supports IDN])
249        fi
250    fi
251fi
252
253dnl Check if the TLS library has IDN support
254have_tls_idn=no
255if test "$tls_lib" = "GnuTLS"; then
256    have_tls_idn="yes"
257fi
258
259dnl Do we need libidn for IDN support?
260AC_MSG_CHECKING([whether libidn is needed for IDN support])
261want_libidn=no
262if test "$have_gai_idn" = "no"; then
263    want_libidn=yes
264elif test "$have_tls" = "yes" -a "$have_tls_idn" = "no"; then
265    want_libidn=yes
266fi
267AC_MSG_RESULT([$want_libidn])
268
269dnl GNU Libidn
270AC_ARG_WITH([libidn], [AS_HELP_STRING([--with-libidn],
271	[Support IDN (needs GNU Libidn)])],
272    [libidn=$withval], [libidn=yes])
273if test "$want_libidn" = "no"; then
274    libidn=no
275fi
276if test "$libidn" != "no"; then
277    PKG_CHECK_MODULES([libidn2], [libidn2 >= 0.0], [HAVE_LIBIDN=1], [HAVE_LIBIDN=0])
278    if test "$HAVE_LIBIDN" != "1"; then
279	AC_MSG_WARN([library libidn not found:])
280	AC_MSG_WARN([$libidn_PKG_ERRORS])
281	AC_MSG_WARN([libidn is provided by GNU Libidn])
282	libidn="no"
283    else
284	libidn="yes"
285	AC_DEFINE([HAVE_LIBIDN], [1], [Define to 1 if libidn is available])
286    fi
287fi
288
289dnl libsecret support (requires pkg-config).
290AC_ARG_WITH([libsecret], [AS_HELP_STRING([--with-libsecret],
291	[Support libsecret (GNOME password management)])],
292    [libsecret=$withval],[libsecret=yes])
293if test "$libsecret" != "no"; then
294    PKG_CHECK_MODULES([libsecret], [libsecret-1], [HAVE_LIBSECRET=1], [HAVE_LIBSECRET=0])
295    if test "$HAVE_LIBSECRET" != "1"; then
296	AC_MSG_WARN([library libsecret not found:])
297	AC_MSG_WARN([$libsecret_PKG_ERRORS])
298	AC_MSG_WARN([libsecret is provided by Gnome])
299	libsecret="no"
300    else
301	libsecret="yes"
302	AC_DEFINE([HAVE_LIBSECRET], [1], [Define to 1 if libsecret is available])
303    fi
304fi
305
306dnl MacOS X Keychain Services (Security Framework)
307AC_ARG_WITH([macosx-keyring], [AS_HELP_STRING([--with-macosx-keyring],
308	[Support Mac OS X Keyring])],
309    [macosx_keyring=$withval],[macosx_keyring=yes])
310if test "$macosx_keyring" != "no"; then
311    AC_CACHE_CHECK([for SecKeychainGetVersion],
312	ac_cv_func_SecKeychainGetVersion,
313	[ac_save_LIBS="$LIBS"
314	 LIBS="$LIBS -Wl,-framework -Wl,Security"
315	 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <Security/Security.h>]], [[SecKeychainGetVersion(NULL);]])],[ac_cv_func_SecKeychainGetVersion=yes],[ac_cv_func_SecKeychainGetVersion=no])
316	 LIBS="$ac_save_LIBS"])
317    if test $ac_cv_func_SecKeychainGetVersion = yes; then
318	macosx_keyring=yes
319	AC_DEFINE([HAVE_MACOSXKEYRING], [1],
320	    [Define to 1 if you have the MacOS X Keychain Services API.])
321	LIBS="$LIBS -Wl,-framework -Wl,Security"
322    else
323	macosx_keyring=no
324    fi
325fi
326
327dnl Check if msmtpd should be built
328AC_ARG_WITH([msmtpd],
329    [AS_HELP_STRING([--with-msmtpd], [Build msmtpd. Enabled by default.])],
330    [if test "$withval" = "yes"; then build_msmtpd="yes"; else build_msmtpd="no"; fi], [build_msmtpd="$build_msmtpd_default"])
331AM_CONDITIONAL([BUILD_MSMTPD], [test "$build_msmtpd" = "yes"])
332
333dnl Global #defines for all source files
334AH_VERBATIM([W32_NATIVE],
335[/* Define to 1 if the native W32 API should be used. */
336#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
337#define W32_NATIVE 1
338#endif])
339
340dnl End.
341AC_CONFIG_FILES([Makefile src/Makefile po/Makefile.in doc/Makefile scripts/Makefile])
342AC_OUTPUT
343
344echo
345echo "Install prefix ......... : $prefix"
346echo "NLS support ............ : $USE_NLS"
347echo "TLS support ............ : $have_tls (Library: $tls_lib)"
348if test "$want_libidn" = "no"; then
349    echo "IDN support ............ : yes (no library required)"
350elif test "$libidn" = "yes"; then
351    echo "IDN support ............ : yes (via GNU Libidn)"
352else
353    echo "IDN support ............ : no"
354fi
355echo "GNU SASL support ....... : $libgsasl (most likely unnecessary)"
356echo "Libsecret support (GNOME): $libsecret"
357echo "MacOS X Keychain support : $macosx_keyring"
358echo "Build msmtpd ............: $build_msmtpd"
359