-
-# libidn
-AC_MSG_CHECKING([if Libidn can be used])
-AC_ARG_WITH(libidn, AC_HELP_STRING([--with-libidn=[DIR]],
- [Support IDN (needs GNU Libidn)]),
-libidn=$withval, libidn=yes)
-if test "$libidn" != "no"; then
- if test "$libidn" != "yes"; then
- LDFLAGS="${LDFLAGS} -L$libidn/lib"
- CPPFLAGS="${CPPFLAGS} -I$libidn/include"
- fi
-fi
-libidn=no
-AC_CHECK_HEADER(idna.h,
- AC_CHECK_LIB(idn, stringprep_check_version,
- [libidn=yes LIBS="${LIBS} -lidn"], []), [])
-if test "$libidn" != "yes"; then
- AC_MSG_FAILURE([GNUnet requires libidn.
-libidn-1.13 should be sufficient, newer versions work too.])
-fi
-AC_MSG_RESULT($libidn)
-
+# libidn and libidn2. The ideal goal is this:
+# check for libidn2, if it doesn't exist check for libidn
+# if both exist, prefer libidn2
+# if none exist, fail and message that libidn or libidn2
+# is required with a preference for libidn2.
+# TODO: What we have right here can probably be improved.
+my_with_libidn=1
+AC_ARG_WITH(libidn,
+ AS_HELP_STRING([--with-libidn=pathname],
+ [Support IDN (needs libidn)]),
+ [],
+ [withval="yes"])
+AS_IF([test x_$withval = x_yes],
+ [AC_CHECK_HEADERS([idna.h],
+ AC_MSG_NOTICE([Found idna.h]),
+ AC_CHECK_HEADERS([idn/idna.h],
+ AC_MSG_NOTICE([Found idn/idna.h]),
+ my_with_libidn=0))],
+ [AS_IF([test x_$withval != x_no],
+ [CFLAGS="$CFLAGS -I$withval/include"
+ LDFLAGS="$LDFLAGS -L$withval/lib"
+ AC_CHECK_HEADERS([idna.h],
+ AC_MSG_NOTICE([Found idna.h]),
+ [AC_MSG_NOTICE([Failed to find idna.h])
+ my_with_libidn=0])],
+ [my_with_libidn=0])])
+
+my_with_libidn2=1
+AC_ARG_WITH(libidn2,
+ AS_HELP_STRING([--with-libidn2=pathname],
+ [Support IDN (needs libidn2)]),
+ [],
+ [withval="yes"])
+AS_IF([test x_$withval = x_yes],
+ [AC_CHECK_HEADERS([idn2.h],
+ AC_MSG_NOTICE([Found idn2.h]),
+ AC_CHECK_HEADERS([idn2/idn2.h],
+ AC_MSG_NOTICE([Found idn2/idn2.h]),
+ [AC_MSG_NOTICE([Failed to find idn2.h])
+ my_with_libidn2=0]))],
+ [AS_IF([test x_$withval != x_no],
+ [CFLAGS="$CFLAGS -I$withval/include"
+ LDFLAGS="$LDFLAGS -L$withval/lib"],
+ [my_with_libidn2=0])])
+
+AC_MSG_CHECKING([if libidn can be used])
+# Check for LIBIDNs
+there_can_only_be_one=1
+
+working_libidn1=0
+working_libidn2=0
+AS_IF([test x$my_with_libidn2 = x1],
+ [AC_MSG_NOTICE([Checking for libidn2])
+ AC_CHECK_LIB([idn2],
+ [idn2_to_unicode_8z8z],
+ [working_libidn2=1
+ LIBS="-lidn2 $LIBS"
+ AC_DEFINE_UNQUOTED([HAVE_LIBIDN2],
+ [1],
+ [Define to 1 if you have 'libidn2' (-lidn2).])],
+ [MISSING_DEPS="${MISSING_DEPS}${MISSING_SEP}libidn2"
+ MISSING_SEP=", "])])
+AM_CONDITIONAL(HAVE_LIBIDN2, test x$working_libidn2 = x1)
+AS_IF([test x$working_libidn2 = x0],
+ [AS_IF([test x$my_with_libidn = x1],
+ [AC_MSG_NOTICE([Checking for libidn])
+ AC_CHECK_LIB([idn],
+ [idna_to_ascii_8z],
+ [working_libidn1=1
+ LIBS="-lidn $LIBS"
+ AC_DEFINE_UNQUOTED([HAVE_LIBIDN],
+ [1],
+ [Define to 1 if you have 'libidn' (-lidn).])],
+ [there_can_only_be_one=0])],
+ [AS_IF([test x$my_with_libidn2 = x1],
+ [there_can_only_be_one=0
+ AC_MSG_FAILURE([* There can only be one libidn.
+ * Provide either libidn >= 1.13
+ * or
+ * libidn2 to the configure
+ * script via
+ * --with-libidn2
+ * --with-libidn])])])])
+AM_CONDITIONAL(HAVE_LIBIDN, test x$working_libidn1 = x1)
+
+AS_IF([test x$there_can_only_be_one = x0],
+ [AC_MSG_FAILURE([Missing dependencies: $MISSING_DEPS])])