xref: /freebsd/contrib/ntp/sntp/m4/ntp_libevent.m4 (revision f5f40dd63bc7acbb5312b26ac1ea1103c12352a6)
12b15cb3dSCy Schubert# SYNOPSIS						-*- Autoconf -*-
22b15cb3dSCy Schubert#
32b15cb3dSCy Schubert#  NTP_ENABLE_LOCAL_LIBEVENT
42b15cb3dSCy Schubert#  NTP_LIBEVENT_CHECK([MINVERSION [, DIR]])
52b15cb3dSCy Schubert#  NTP_LIBEVENT_CHECK_NOBUILD([MINVERSION [, DIR]])
62b15cb3dSCy Schubert#
72b15cb3dSCy Schubert# DESCRIPTION
82b15cb3dSCy Schubert#
92b15cb3dSCy Schubert# AUTHOR
102b15cb3dSCy Schubert#
112b15cb3dSCy Schubert#  Harlan Stenn
122b15cb3dSCy Schubert#
132b15cb3dSCy Schubert# LICENSE
142b15cb3dSCy Schubert#
152b15cb3dSCy Schubert#  This file is Copyright (c) 2014 Network Time Foundation
162b15cb3dSCy Schubert#
172b15cb3dSCy Schubert#  Copying and distribution of this file, with or without modification, are
182b15cb3dSCy Schubert#  permitted in any medium without royalty provided the copyright notice,
192b15cb3dSCy Schubert#  author attribution and this notice are preserved.  This file is offered
202b15cb3dSCy Schubert#  as-is, without any warranty.
212b15cb3dSCy Schubert
222b15cb3dSCy Schubertdnl NTP_ENABLE_LOCAL_LIBEVENT
232b15cb3dSCy Schubertdnl
242b15cb3dSCy Schubertdnl Provide only the --enable-local-libevent command-line option.
252b15cb3dSCy Schubertdnl
262b15cb3dSCy Schubertdnl Used standalone by top-level NTP configure.ac, which should have
272b15cb3dSCy Schubertdnl --enable-local-libevent in its --help output but which doesn't do
282b15cb3dSCy Schubertdnl anything differently based upon its presence or value.
292b15cb3dSCy Schubertdnl
302b15cb3dSCy Schubertdnl Also AC_REQUIRE'd by NTP_LIBEVENT_CHECK_NOBUILD.
312b15cb3dSCy SchubertAC_DEFUN([NTP_ENABLE_LOCAL_LIBEVENT], [
322b15cb3dSCy Schubert
332b15cb3dSCy SchubertAC_ARG_ENABLE(
342b15cb3dSCy Schubert    [local-libevent],
352b15cb3dSCy Schubert    [AC_HELP_STRING(
362b15cb3dSCy Schubert	[--enable-local-libevent],
372b15cb3dSCy Schubert	[Force using the supplied libevent tearoff code]
382b15cb3dSCy Schubert    )],
392b15cb3dSCy Schubert    [ntp_use_local_libevent=$enableval],
402b15cb3dSCy Schubert    [ntp_use_local_libevent=${ntp_use_local_libevent-detect}]
412b15cb3dSCy Schubert)
422b15cb3dSCy Schubert
432b15cb3dSCy Schubert]) dnl NTP_ENABLE_LOCAL_LIBEVENT
442b15cb3dSCy Schubert
452b15cb3dSCy Schubertdnl NTP_LIBEVENT_CHECK_NOBUILD([MINVERSION [, DIR]])	     -*- Autoconf -*-
462b15cb3dSCy Schubertdnl
472b15cb3dSCy Schubertdnl Look for libevent, which must be at least MINVERSION.
482b15cb3dSCy Schubertdnl DIR is the location of our "bundled" copy of libevent.
492b15cb3dSCy Schubertdnl If NOBUILD is provided as the 3rd argument, do all of the above,
502b15cb3dSCy Schubertdnl but DO NOT invoke DIR/configure if we are going to use our bundled
512b15cb3dSCy Schubertdnl version.  This may be the case for nested packages.
522b15cb3dSCy Schubertdnl
532b15cb3dSCy Schubertdnl provides: --enable-local-libevent
542b15cb3dSCy Schubertdnl
552b15cb3dSCy Schubertdnl Examples:
562b15cb3dSCy Schubertdnl
572b15cb3dSCy Schubertdnl    NTP_LIBEVENT_CHECK_NOBUILD([2.0.9], [sntp/libevent])
582b15cb3dSCy Schubertdnl    NTP_LIBEVENT_CHECK
592b15cb3dSCy Schubertdnl
602b15cb3dSCy SchubertAC_DEFUN([NTP_LIBEVENT_CHECK_NOBUILD], [
612b15cb3dSCy SchubertAC_REQUIRE([NTP_PKG_CONFIG])dnl
622b15cb3dSCy SchubertAC_REQUIRE([NTP_ENABLE_LOCAL_LIBEVENT])dnl
632b15cb3dSCy Schubert
642b15cb3dSCy Schubertntp_libevent_min_version=m4_default([$1], [2.0.9])
652b15cb3dSCy Schubertntp_libevent_tearoff=m4_default([$2], [libevent])
662b15cb3dSCy Schubert
679034852cSGleb SmirnoffAC_SUBST([CFLAGS_LIBEVENT])
682b15cb3dSCy SchubertAC_SUBST([CPPFLAGS_LIBEVENT])
692b15cb3dSCy SchubertAC_SUBST([LDADD_LIBEVENT])
702b15cb3dSCy Schubert
712b15cb3dSCy Schubertcase "$ntp_use_local_libevent" in
722b15cb3dSCy Schubert yes)
732b15cb3dSCy Schubert    ;;
742b15cb3dSCy Schubert *) # If we have (a good enough) pkg-config, see if it can find libevent
752b15cb3dSCy Schubert    case "$PKG_CONFIG" in
762b15cb3dSCy Schubert     /*)
772b15cb3dSCy Schubert	if $PKG_CONFIG --atleast-version=$ntp_libevent_min_version libevent
782b15cb3dSCy Schubert	then
792b15cb3dSCy Schubert	    ntp_use_local_libevent=no
8009100258SXin LI	    ntp_libevent_version="`$PKG_CONFIG --modversion libevent`"
8109100258SXin LI	    case "$ntp_libevent_version" in
8209100258SXin LI	     *.*) ;;
8309100258SXin LI	     *) ntp_libevent_version='(unknown)' ;;
8409100258SXin LI	    esac
85*f5f40dd6SCy Schubert	    AC_MSG_CHECKING([if libevent $ntp_libevent_min_version or later is installed])
8609100258SXin LI	    AC_MSG_RESULT([yes, version $ntp_libevent_version])
879034852cSGleb Smirnoff	    CFLAGS_LIBEVENT=`$PKG_CONFIG --cflags libevent_pthreads`
882b15cb3dSCy Schubert	    CPPFLAGS_LIBEVENT=`$PKG_CONFIG --cflags-only-I libevent`
892b15cb3dSCy Schubert	    # HMS: I hope the following is accurate.
902b15cb3dSCy Schubert	    # We don't need -levent, we only need  -levent_core.
912b15cb3dSCy Schubert	    # While we could grab only the -L stuff, there *might* be
922b15cb3dSCy Schubert	    # other flags there we want.  Originally we just removed -levent
932b15cb3dSCy Schubert	    # but then somebody decided to install -levent-2.0
942b15cb3dSCy Schubert	    # LDADD_LIBEVENT=`$PKG_CONFIG --libs libevent | sed 's:-levent::'`
952b15cb3dSCy Schubert	    # So now we dance...
962b15cb3dSCy Schubert	    LDADD_LIBEVENT=
973311ff84SXin LI	    for i in `$PKG_CONFIG --libs libevent` `$PKG_CONFIG --cflags-only-other libevent_pthreads`
982b15cb3dSCy Schubert	    do
992b15cb3dSCy Schubert		case "$i" in
1003311ff84SXin LI		 -D*) ;;
1012b15cb3dSCy Schubert		 -levent*) ;;
1022b15cb3dSCy Schubert		 *) case "$LDADD_LIBEVENT" in
1032b15cb3dSCy Schubert		     '') LDADD_LIBEVENT="$i" ;;
1042b15cb3dSCy Schubert		     *) LDADD_LIBEVENT="$LDADD_LIBEVENT $i" ;;
1052b15cb3dSCy Schubert		    esac
1062b15cb3dSCy Schubert		    ;;
1072b15cb3dSCy Schubert		esac
1082b15cb3dSCy Schubert	    done
1092b15cb3dSCy Schubert	    case "$LIBISC_PTHREADS_NOTHREADS" in
1102b15cb3dSCy Schubert	     pthreads)
1112b15cb3dSCy Schubert		LDADD_LIBEVENT="$LDADD_LIBEVENT -levent_pthreads"
1122b15cb3dSCy Schubert	    esac
1132b15cb3dSCy Schubert	    LDADD_LIBEVENT="$LDADD_LIBEVENT -levent_core"
1142b15cb3dSCy Schubert	else
1152b15cb3dSCy Schubert	    ntp_use_local_libevent=yes
1169034852cSGleb Smirnoff	    # HMS: do we only need to do this if LIBISC_PTHREADS_NOTHREADS
1179034852cSGleb Smirnoff	    # is "pthreads"?
1189034852cSGleb Smirnoff	    CFLAGS_LIBEVENT=`$PKG_CONFIG --cflags libevent_pthreads`
119*f5f40dd6SCy Schubert	    AC_MSG_CHECKING([if libevent $ntp_libevent_min_version or later is installed])
1202b15cb3dSCy Schubert	    AC_MSG_RESULT([no])
1212b15cb3dSCy Schubert	fi
1222b15cb3dSCy Schubert	;;
1232b15cb3dSCy Schubert     *)
1242b15cb3dSCy Schubert	ntp_use_local_libevent=yes
1252b15cb3dSCy Schubert	;;
1262b15cb3dSCy Schubert    esac
1272b15cb3dSCy Schubert    ;;
1282b15cb3dSCy Schubertesac
1292b15cb3dSCy Schubert
1302b15cb3dSCy Schubertcase "$ntp_use_local_libevent" in
1312b15cb3dSCy Schubert yes)
1322b15cb3dSCy Schubert    AC_MSG_NOTICE([Using libevent tearoff])
1332b15cb3dSCy Schubert    CPPFLAGS_LIBEVENT="-I\$(top_builddir)/$ntp_libevent_tearoff/include -I\$(top_srcdir)/$ntp_libevent_tearoff/include"
1342b15cb3dSCy Schubert    case "$LIBISC_PTHREADS_NOTHREADS" in
1352b15cb3dSCy Schubert     pthreads)
1362b15cb3dSCy Schubert	LDADD_LIBEVENT="\$(top_builddir)/$ntp_libevent_tearoff/libevent_pthreads.la \$(top_builddir)/$ntp_libevent_tearoff/libevent_core.la"
1372b15cb3dSCy Schubert	;;
1382b15cb3dSCy Schubert     *)
1392b15cb3dSCy Schubert	LDADD_LIBEVENT="\$(top_builddir)/$ntp_libevent_tearoff/libevent_core.la"
1402b15cb3dSCy Schubert    esac
1412b15cb3dSCy Schubertesac
1422b15cb3dSCy Schubert
1439034852cSGleb Smirnoffdnl AC_ARG_ENABLE(
1449034852cSGleb Smirnoffdnl     [cflags-libevent],
1459034852cSGleb Smirnoffdnl     [AC_HELP_STRING(
1469034852cSGleb Smirnoffdnl 	[--enable-cflags-libevent=-pthread],
1479034852cSGleb Smirnoffdnl 	[CFLAGS value to build with pthreads]
1489034852cSGleb Smirnoffdnl     )],
1499034852cSGleb Smirnoffdnl     [CFLAGS_LIBEVENT=$enableval],
1509034852cSGleb Smirnoffdnl     [# See above about LIBISC_PTHREADS_NOTHREADS
1519034852cSGleb Smirnoffdnl     case "$CFLAGS_LIBEVENT" in
1529034852cSGleb Smirnoffdnl      '') CFLAGS_LIBEVENT="-pthread" ;;
1539034852cSGleb Smirnoffdnl      *) ;;
1549034852cSGleb Smirnoffdnl     esac]
1559034852cSGleb Smirnoffdnl )
1569034852cSGleb Smirnoffdnl AC_MSG_NOTICE([LIBISC_PTHREADS_NOTHREADS is <$LIBISC_PTHREADS_NOTHREADS>])
1579034852cSGleb Smirnoffdnl AC_MSG_NOTICE([CFLAGS_LIBEVENT is <$CFLAGS_LIBEVENT>])
1589034852cSGleb Smirnoff
1592b15cb3dSCy SchubertAM_CONDITIONAL([BUILD_LIBEVENT], [test "x$ntp_use_local_libevent" = "xyes"])
1602b15cb3dSCy Schubert
1612b15cb3dSCy Schubert]) dnl NTP_LIBEVENT_CHECK_NOBUILD
1622b15cb3dSCy Schubert
1632b15cb3dSCy Schubertdnl NTP_LIBEVENT_CHECK([MINVERSION [, DIR]])	     -*- Autoconf -*-
1642b15cb3dSCy SchubertAC_DEFUN([NTP_LIBEVENT_CHECK], [
1652b15cb3dSCy Schubert
1662b15cb3dSCy SchubertAC_SUBST([NTP_FORCE_LIBEVENT_DIST])
1672b15cb3dSCy SchubertNTP_LIBEVENT_CHECK_NOBUILD([$1], [$2])
1682b15cb3dSCy Schubert
1692b15cb3dSCy Schubertcase "$ntp_libevent_tearoff" in
1702b15cb3dSCy Schubert libevent)
1712b15cb3dSCy Schubert    ;;
1722b15cb3dSCy Schubert *)
1732b15cb3dSCy Schubert    AC_MSG_ERROR([ntp_libevent.m4 dir must be libevent, not $ntp_libevent_tearoff])
1742b15cb3dSCy Schubert    ;;
1752b15cb3dSCy Schubertesac
1762b15cb3dSCy Schubert
1772b15cb3dSCy Schubertcase "$ntp_use_local_libevent" in
1782b15cb3dSCy Schubert yes)
1792b15cb3dSCy Schubert    dnl ac_configure_args is undocumented but widely abused, as here,
1802b15cb3dSCy Schubert    dnl to modify the defaults of the libevent subpackage, by prefixing
1812b15cb3dSCy Schubert    dnl our changes to the child configure arguments already assembled.
1822b15cb3dSCy Schubert    dnl User-supplied contradictory choices should prevail thanks to
1832b15cb3dSCy Schubert    dnl "last wins".
1842b15cb3dSCy Schubert    ac_configure_args=" --disable-openssl${ac_configure_args}"
185*f5f40dd6SCy Schubert    ac_configure_args=" --disable-samples${ac_configure_args}"
1862b15cb3dSCy Schubert    ac_configure_args=" --disable-shared${ac_configure_args}"
1872b15cb3dSCy Schubert    ac_configure_args=" --disable-libevent-regress${ac_configure_args}"
1882b15cb3dSCy Schubert    ac_configure_args=" --disable-libevent-install${ac_configure_args}"
1892b15cb3dSCy Schubert    ac_configure_args=" --enable-silent-rules${ac_configure_args}"
1902b15cb3dSCy Schubert    ac_configure_args=" --enable-function-sections${ac_configure_args}"
191*f5f40dd6SCy Schubert    ac_configure_args=" LIBEVENT_CFLAGS='${NTP_HARD_CFLAGS}'${ac_configure_args}"
192*f5f40dd6SCy Schubert    ac_configure_args=" LIBEVENT_CPPFLAGS='${NTP_HARD_CPPFLAGS}'${ac_configure_args}"
193*f5f40dd6SCy Schubert    ac_configure_args=" LIBEVENT_LDFLAGS='${NTP_HARD_LDFLAGS}'${ac_configure_args}"
1942b15cb3dSCy Schubert    AC_CONFIG_SUBDIRS([libevent])
1952b15cb3dSCy Schubert    ;;
1962b15cb3dSCy Schubert *)
1972b15cb3dSCy Schubert    NTP_FORCE_LIBEVENT_DIST=libevent
1982b15cb3dSCy Schubert    ;;
1992b15cb3dSCy Schubertesac
2002b15cb3dSCy Schubert
2012b15cb3dSCy Schubert]) dnl NTP_LIBEVENT_CHECK
2022b15cb3dSCy Schubert
203