1# SYNOPSIS -*- Autoconf -*- 2# 3# NTP_ENABLE_LOCAL_LIBEVENT 4# NTP_LIBEVENT_CHECK([MINVERSION [, DIR]]) 5# NTP_LIBEVENT_CHECK_NOBUILD([MINVERSION [, DIR]]) 6# 7# DESCRIPTION 8# 9# AUTHOR 10# 11# Harlan Stenn 12# 13# LICENSE 14# 15# This file is Copyright (c) 2014 Network Time Foundation 16# 17# Copying and distribution of this file, with or without modification, are 18# permitted in any medium without royalty provided the copyright notice, 19# author attribution and this notice are preserved. This file is offered 20# as-is, without any warranty. 21 22dnl NTP_ENABLE_LOCAL_LIBEVENT 23dnl 24dnl Provide only the --enable-local-libevent command-line option. 25dnl 26dnl Used standalone by top-level NTP configure.ac, which should have 27dnl --enable-local-libevent in its --help output but which doesn't do 28dnl anything differently based upon its presence or value. 29dnl 30dnl Also AC_REQUIRE'd by NTP_LIBEVENT_CHECK_NOBUILD. 31AC_DEFUN([NTP_ENABLE_LOCAL_LIBEVENT], [ 32 33AC_ARG_ENABLE( 34 [local-libevent], 35 [AC_HELP_STRING( 36 [--enable-local-libevent], 37 [Force using the supplied libevent tearoff code] 38 )], 39 [ntp_use_local_libevent=$enableval], 40 [ntp_use_local_libevent=${ntp_use_local_libevent-detect}] 41) 42 43]) dnl NTP_ENABLE_LOCAL_LIBEVENT 44 45dnl NTP_LIBEVENT_CHECK_NOBUILD([MINVERSION [, DIR]]) -*- Autoconf -*- 46dnl 47dnl Look for libevent, which must be at least MINVERSION. 48dnl DIR is the location of our "bundled" copy of libevent. 49dnl If NOBUILD is provided as the 3rd argument, do all of the above, 50dnl but DO NOT invoke DIR/configure if we are going to use our bundled 51dnl version. This may be the case for nested packages. 52dnl 53dnl provides: --enable-local-libevent 54dnl 55dnl Examples: 56dnl 57dnl NTP_LIBEVENT_CHECK_NOBUILD([2.0.9], [sntp/libevent]) 58dnl NTP_LIBEVENT_CHECK 59dnl 60AC_DEFUN([NTP_LIBEVENT_CHECK_NOBUILD], [ 61AC_REQUIRE([NTP_PKG_CONFIG])dnl 62AC_REQUIRE([NTP_ENABLE_LOCAL_LIBEVENT])dnl 63 64ntp_libevent_min_version=m4_default([$1], [2.0.9]) 65ntp_libevent_tearoff=m4_default([$2], [libevent]) 66 67AC_SUBST([CFLAGS_LIBEVENT]) 68AC_SUBST([CPPFLAGS_LIBEVENT]) 69AC_SUBST([LDADD_LIBEVENT]) 70 71case "$ntp_use_local_libevent" in 72 yes) 73 ;; 74 *) # If we have (a good enough) pkg-config, see if it can find libevent 75 case "$PKG_CONFIG" in 76 /*) 77 if $PKG_CONFIG --atleast-version=$ntp_libevent_min_version libevent 78 then 79 ntp_use_local_libevent=no 80 ntp_libevent_version="`$PKG_CONFIG --modversion libevent`" 81 case "$ntp_libevent_version" in 82 *.*) ;; 83 *) ntp_libevent_version='(unknown)' ;; 84 esac 85 AC_MSG_CHECKING([if libevent $ntp_libevent_min_version or later is installed]) 86 AC_MSG_RESULT([yes, version $ntp_libevent_version]) 87 CFLAGS_LIBEVENT=`$PKG_CONFIG --cflags libevent_pthreads` 88 CPPFLAGS_LIBEVENT=`$PKG_CONFIG --cflags-only-I libevent` 89 # HMS: I hope the following is accurate. 90 # We don't need -levent, we only need -levent_core. 91 # While we could grab only the -L stuff, there *might* be 92 # other flags there we want. Originally we just removed -levent 93 # but then somebody decided to install -levent-2.0 94 # LDADD_LIBEVENT=`$PKG_CONFIG --libs libevent | sed 's:-levent::'` 95 # So now we dance... 96 LDADD_LIBEVENT= 97 for i in `$PKG_CONFIG --libs libevent` `$PKG_CONFIG --cflags-only-other libevent_pthreads` 98 do 99 case "$i" in 100 -D*) ;; 101 -levent*) ;; 102 *) case "$LDADD_LIBEVENT" in 103 '') LDADD_LIBEVENT="$i" ;; 104 *) LDADD_LIBEVENT="$LDADD_LIBEVENT $i" ;; 105 esac 106 ;; 107 esac 108 done 109 case "$LIBISC_PTHREADS_NOTHREADS" in 110 pthreads) 111 LDADD_LIBEVENT="$LDADD_LIBEVENT -levent_pthreads" 112 esac 113 LDADD_LIBEVENT="$LDADD_LIBEVENT -levent_core" 114 else 115 ntp_use_local_libevent=yes 116 # HMS: do we only need to do this if LIBISC_PTHREADS_NOTHREADS 117 # is "pthreads"? 118 CFLAGS_LIBEVENT=`$PKG_CONFIG --cflags libevent_pthreads` 119 AC_MSG_CHECKING([if libevent $ntp_libevent_min_version or later is installed]) 120 AC_MSG_RESULT([no]) 121 fi 122 ;; 123 *) 124 ntp_use_local_libevent=yes 125 ;; 126 esac 127 ;; 128esac 129 130case "$ntp_use_local_libevent" in 131 yes) 132 AC_MSG_NOTICE([Using libevent tearoff]) 133 CPPFLAGS_LIBEVENT="-I\$(top_builddir)/$ntp_libevent_tearoff/include -I\$(top_srcdir)/$ntp_libevent_tearoff/include" 134 case "$LIBISC_PTHREADS_NOTHREADS" in 135 pthreads) 136 LDADD_LIBEVENT="\$(top_builddir)/$ntp_libevent_tearoff/libevent_pthreads.la \$(top_builddir)/$ntp_libevent_tearoff/libevent_core.la" 137 ;; 138 *) 139 LDADD_LIBEVENT="\$(top_builddir)/$ntp_libevent_tearoff/libevent_core.la" 140 esac 141esac 142 143dnl AC_ARG_ENABLE( 144dnl [cflags-libevent], 145dnl [AC_HELP_STRING( 146dnl [--enable-cflags-libevent=-pthread], 147dnl [CFLAGS value to build with pthreads] 148dnl )], 149dnl [CFLAGS_LIBEVENT=$enableval], 150dnl [# See above about LIBISC_PTHREADS_NOTHREADS 151dnl case "$CFLAGS_LIBEVENT" in 152dnl '') CFLAGS_LIBEVENT="-pthread" ;; 153dnl *) ;; 154dnl esac] 155dnl ) 156dnl AC_MSG_NOTICE([LIBISC_PTHREADS_NOTHREADS is <$LIBISC_PTHREADS_NOTHREADS>]) 157dnl AC_MSG_NOTICE([CFLAGS_LIBEVENT is <$CFLAGS_LIBEVENT>]) 158 159AM_CONDITIONAL([BUILD_LIBEVENT], [test "x$ntp_use_local_libevent" = "xyes"]) 160 161]) dnl NTP_LIBEVENT_CHECK_NOBUILD 162 163dnl NTP_LIBEVENT_CHECK([MINVERSION [, DIR]]) -*- Autoconf -*- 164AC_DEFUN([NTP_LIBEVENT_CHECK], [ 165 166AC_SUBST([NTP_FORCE_LIBEVENT_DIST]) 167NTP_LIBEVENT_CHECK_NOBUILD([$1], [$2]) 168 169case "$ntp_libevent_tearoff" in 170 libevent) 171 ;; 172 *) 173 AC_MSG_ERROR([ntp_libevent.m4 dir must be libevent, not $ntp_libevent_tearoff]) 174 ;; 175esac 176 177case "$ntp_use_local_libevent" in 178 yes) 179 dnl ac_configure_args is undocumented but widely abused, as here, 180 dnl to modify the defaults of the libevent subpackage, by prefixing 181 dnl our changes to the child configure arguments already assembled. 182 dnl User-supplied contradictory choices should prevail thanks to 183 dnl "last wins". 184 ac_configure_args=" --disable-openssl${ac_configure_args}" 185 ac_configure_args=" --disable-samples${ac_configure_args}" 186 ac_configure_args=" --disable-shared${ac_configure_args}" 187 ac_configure_args=" --disable-libevent-regress${ac_configure_args}" 188 ac_configure_args=" --disable-libevent-install${ac_configure_args}" 189 ac_configure_args=" --enable-silent-rules${ac_configure_args}" 190 ac_configure_args=" --enable-function-sections${ac_configure_args}" 191 ac_configure_args=" LIBEVENT_CFLAGS='${NTP_HARD_CFLAGS}'${ac_configure_args}" 192 ac_configure_args=" LIBEVENT_CPPFLAGS='${NTP_HARD_CPPFLAGS}'${ac_configure_args}" 193 ac_configure_args=" LIBEVENT_LDFLAGS='${NTP_HARD_LDFLAGS}'${ac_configure_args}" 194 AC_CONFIG_SUBDIRS([libevent]) 195 ;; 196 *) 197 NTP_FORCE_LIBEVENT_DIST=libevent 198 ;; 199esac 200 201]) dnl NTP_LIBEVENT_CHECK 202 203