]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/sntp/m4/ntp_libevent.m4
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / sntp / m4 / ntp_libevent.m4
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
22 dnl NTP_ENABLE_LOCAL_LIBEVENT
23 dnl
24 dnl Provide only the --enable-local-libevent command-line option.
25 dnl
26 dnl Used standalone by top-level NTP configure.ac, which should have
27 dnl --enable-local-libevent in its --help output but which doesn't do
28 dnl anything differently based upon its presence or value.
29 dnl
30 dnl Also AC_REQUIRE'd by NTP_LIBEVENT_CHECK_NOBUILD.
31 AC_DEFUN([NTP_ENABLE_LOCAL_LIBEVENT], [
32
33 AC_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
45 dnl NTP_LIBEVENT_CHECK_NOBUILD([MINVERSION [, DIR]])         -*- Autoconf -*-
46 dnl
47 dnl Look for libevent, which must be at least MINVERSION.
48 dnl DIR is the location of our "bundled" copy of libevent.
49 dnl If NOBUILD is provided as the 3rd argument, do all of the above,
50 dnl but DO NOT invoke DIR/configure if we are going to use our bundled
51 dnl version.  This may be the case for nested packages.
52 dnl
53 dnl provides: --enable-local-libevent 
54 dnl
55 dnl Examples:
56 dnl
57 dnl    NTP_LIBEVENT_CHECK_NOBUILD([2.0.9], [sntp/libevent])
58 dnl    NTP_LIBEVENT_CHECK
59 dnl
60 AC_DEFUN([NTP_LIBEVENT_CHECK_NOBUILD], [
61 AC_REQUIRE([NTP_PKG_CONFIG])dnl
62 AC_REQUIRE([NTP_ENABLE_LOCAL_LIBEVENT])dnl
63
64 ntp_libevent_min_version=m4_default([$1], [2.0.9])
65 ntp_libevent_tearoff=m4_default([$2], [libevent])
66
67 AC_SUBST([CPPFLAGS_LIBEVENT])
68 AC_SUBST([LDADD_LIBEVENT])
69
70 case "$ntp_use_local_libevent" in
71  yes)
72     ;;
73  *) # If we have (a good enough) pkg-config, see if it can find libevent
74     case "$PKG_CONFIG" in
75      /*)
76         AC_MSG_CHECKING([if libevent $ntp_libevent_min_version or later is installed])
77         if $PKG_CONFIG --atleast-version=$ntp_libevent_min_version libevent
78         then
79             ntp_use_local_libevent=no
80             AC_MSG_NOTICE([Using the installed libevent])
81             CPPFLAGS_LIBEVENT=`$PKG_CONFIG --cflags-only-I libevent`
82             # HMS: I hope the following is accurate.
83             # We don't need -levent, we only need  -levent_core.
84             # While we could grab only the -L stuff, there *might* be
85             # other flags there we want.  Originally we just removed -levent
86             # but then somebody decided to install -levent-2.0
87             # LDADD_LIBEVENT=`$PKG_CONFIG --libs libevent | sed 's:-levent::'`
88             # So now we dance...
89             LDADD_LIBEVENT=
90             for i in `$PKG_CONFIG --libs libevent`
91             do
92                 case "$i" in
93                  -levent*) ;;
94                  *) case "$LDADD_LIBEVENT" in
95                      '') LDADD_LIBEVENT="$i" ;;
96                      *) LDADD_LIBEVENT="$LDADD_LIBEVENT $i" ;;
97                     esac
98                     ;;
99                 esac
100             done
101             case "$LIBISC_PTHREADS_NOTHREADS" in
102              pthreads)
103                 LDADD_LIBEVENT="$LDADD_LIBEVENT -levent_pthreads"
104             esac
105             LDADD_LIBEVENT="$LDADD_LIBEVENT -levent_core"
106             AC_MSG_RESULT([yes])
107         else
108             ntp_use_local_libevent=yes
109             AC_MSG_RESULT([no])
110         fi
111         ;;
112      *)
113         ntp_use_local_libevent=yes
114         ;;
115     esac
116     ;;
117 esac
118
119 case "$ntp_use_local_libevent" in
120  yes)
121     AC_MSG_NOTICE([Using libevent tearoff])
122     CPPFLAGS_LIBEVENT="-I\$(top_builddir)/$ntp_libevent_tearoff/include -I\$(top_srcdir)/$ntp_libevent_tearoff/include"
123     case "$LIBISC_PTHREADS_NOTHREADS" in
124      pthreads)
125         LDADD_LIBEVENT="\$(top_builddir)/$ntp_libevent_tearoff/libevent_pthreads.la \$(top_builddir)/$ntp_libevent_tearoff/libevent_core.la"
126         ;;
127      *)
128         LDADD_LIBEVENT="\$(top_builddir)/$ntp_libevent_tearoff/libevent_core.la"
129     esac
130 esac
131
132 AM_CONDITIONAL([BUILD_LIBEVENT], [test "x$ntp_use_local_libevent" = "xyes"])
133
134 ]) dnl NTP_LIBEVENT_CHECK_NOBUILD
135
136 dnl NTP_LIBEVENT_CHECK([MINVERSION [, DIR]])         -*- Autoconf -*-
137 AC_DEFUN([NTP_LIBEVENT_CHECK], [
138
139 AC_SUBST([NTP_FORCE_LIBEVENT_DIST])
140 NTP_LIBEVENT_CHECK_NOBUILD([$1], [$2])
141
142 case "$ntp_libevent_tearoff" in
143  libevent)
144     ;;
145  *)
146     AC_MSG_ERROR([ntp_libevent.m4 dir must be libevent, not $ntp_libevent_tearoff])
147     ;;
148 esac
149
150 case "$ntp_use_local_libevent" in
151  yes)
152     dnl ac_configure_args is undocumented but widely abused, as here,
153     dnl to modify the defaults of the libevent subpackage, by prefixing
154     dnl our changes to the child configure arguments already assembled.
155     dnl User-supplied contradictory choices should prevail thanks to
156     dnl "last wins".
157     ac_configure_args=" --disable-openssl${ac_configure_args}"
158     ac_configure_args=" --disable-shared${ac_configure_args}"
159     ac_configure_args=" --disable-libevent-regress${ac_configure_args}"
160     ac_configure_args=" --disable-libevent-install${ac_configure_args}"
161     ac_configure_args=" --enable-silent-rules${ac_configure_args}"
162     ac_configure_args=" --enable-function-sections${ac_configure_args}"
163     AC_CONFIG_SUBDIRS([libevent])
164     ;;
165  *)
166     NTP_FORCE_LIBEVENT_DIST=libevent
167     ;;
168 esac
169
170 ]) dnl NTP_LIBEVENT_CHECK
171