3.5. Autoconf tests

If you work on a project that uses Autoconf () to help find installed libraries, the suggestions in the previous section are not the entire story. There are a few methods to detect and incorporate Libidn into your Autoconf based package.

3.5.1. Autoconf test via pkg-config

If your audience is a typical GNU/Linux desktop, you can often assume they have the pkg-config tool installed, in which you can use its Autoconf M4 macro to find and set up your package for use with Shishi. The following illustrate this scenario.

AC_ARG_ENABLE(idn,
	AC_HELP_STRING([--disable-idn],
                       [Don't use Libidn]),
	libidn=$enableval)
if test "$libidn" != "no" ; then
	PKG_CHECK_MODULES(LIBIDN, libidn >= 0.0.0,
			[libidn=yes],
                        [libidn=no])
	if test "$libidn" != "yes" ; then
		libidn=no
		AC_MSG_WARN([Libidn not found])
	else
		libidn=yes
		AC_DEFINE(USE_LIBIDN, 1, [Define to 1 if you want Libidn.])
	fi
fi
AC_MSG_CHECKING([if Libidn should be used])
AC_MSG_RESULT($libidn)

3.5.2. Standalone Autoconf test

The following illustrate a standalone autconf test, that work regardless of if your project Libtool () or not. It is the most portable solution, and is recommended.

AC_CHECK_HEADER(idna.h,
	AC_CHECK_LIB(idn, stringprep_check_version,
		[libidn=yes AC_SUBST(SHISHI_LIBS, -lidn)],
		libidn=no),
	kerberos5=no)
AC_ARG_ENABLE(idn, AC_HELP_STRING([--disable-idn], [Don't use Libidn]),
	libidn=$enableval)
if test "$libidn" != "no" ; then
	AC_DEFINE(USE_LIBIDN, 1, [Define to 1 if you want Libidn.])
else
	AC_MSG_WARN([Libidn not found])
fi
AC_MSG_CHECKING([if Libidn should be used])
AC_MSG_RESULT($libidn)