1dnl Checks for libcnotify required headers and functions
2dnl
3dnl Version: 20190308
4
5dnl Function to detect if libcnotify is available
6dnl ac_libcnotify_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments
7AC_DEFUN([AX_LIBCNOTIFY_CHECK_LIB],
8  [AS_IF(
9    [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libcnotify" = xno],
10    [ac_cv_libcnotify=no],
11    [ac_cv_libcnotify=check
12    dnl Check if the directory provided as parameter exists
13    AS_IF(
14      [test "x$ac_cv_with_libcnotify" != x && test "x$ac_cv_with_libcnotify" != xauto-detect],
15      [AS_IF(
16        [test -d "$ac_cv_with_libcnotify"],
17        [CFLAGS="$CFLAGS -I${ac_cv_with_libcnotify}/include"
18        LDFLAGS="$LDFLAGS -L${ac_cv_with_libcnotify}/lib"],
19        [AC_MSG_FAILURE(
20          [no such directory: $ac_cv_with_libcnotify],
21          [1])
22        ])
23      ],
24      [dnl Check for a pkg-config file
25      AS_IF(
26        [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"],
27        [PKG_CHECK_MODULES(
28          [libcnotify],
29          [libcnotify >= 20120425],
30          [ac_cv_libcnotify=yes],
31          [ac_cv_libcnotify=check])
32        ])
33      AS_IF(
34        [test "x$ac_cv_libcnotify" = xyes],
35        [ac_cv_libcnotify_CPPFLAGS="$pkg_cv_libcnotify_CFLAGS"
36        ac_cv_libcnotify_LIBADD="$pkg_cv_libcnotify_LIBS"])
37      ])
38
39    AS_IF(
40      [test "x$ac_cv_libcnotify" = xcheck],
41      [dnl Check for headers
42      AC_CHECK_HEADERS([libcnotify.h])
43
44      AS_IF(
45        [test "x$ac_cv_header_libcnotify_h" = xno],
46        [ac_cv_libcnotify=no],
47        [dnl Check for the individual functions
48        ac_cv_libcnotify=yes
49
50        AC_CHECK_LIB(
51          cnotify,
52          libcnotify_get_version,
53          [ac_cv_libcnotify_dummy=yes],
54          [ac_cv_libcnotify=no])
55
56        dnl Print functions
57        AC_CHECK_LIB(
58          cnotify,
59          libcnotify_printf,
60          [ac_cv_libcnotify_dummy=yes],
61          [ac_cv_libcnotify=no])
62        AC_CHECK_LIB(
63          cnotify,
64          libcnotify_print_data,
65          [ac_cv_libcnotify_dummy=yes],
66          [ac_cv_libcnotify=no])
67        AC_CHECK_LIB(
68          cnotify,
69          libcnotify_print_error_backtrace,
70          [ac_cv_libcnotify_dummy=yes],
71          [ac_cv_libcnotify=no])
72
73        dnl Stream functions
74        AC_CHECK_LIB(
75          cnotify,
76          libcnotify_stream_set,
77          [ac_cv_libcnotify_dummy=yes],
78          [ac_cv_libcnotify=no])
79        AC_CHECK_LIB(
80          cnotify,
81          libcnotify_stream_open,
82          [ac_cv_libcnotify_dummy=yes],
83          [ac_cv_libcnotify=no])
84        AC_CHECK_LIB(
85          cnotify,
86          libcnotify_stream_close,
87          [ac_cv_libcnotify_dummy=yes],
88          [ac_cv_libcnotify=no])
89
90        dnl Verbose functions
91        AC_CHECK_LIB(
92          cnotify,
93          libcnotify_verbose_set,
94          [ac_cv_libcnotify_dummy=yes],
95          [ac_cv_libcnotify=no])
96
97        ac_cv_libcnotify_LIBADD="-lcnotify"])
98      ])
99    AS_IF(
100      [test "x$ac_cv_with_libcnotify" != x && test "x$ac_cv_with_libcnotify" != xauto-detect && test "x$ac_cv_libcnotify" != xyes],
101      [AC_MSG_FAILURE(
102        [unable to find supported libcnotify in directory: $ac_cv_with_libcnotify],
103        [1])
104      ])
105    ])
106
107  AS_IF(
108    [test "x$ac_cv_libcnotify" = xyes],
109    [AC_DEFINE(
110      [HAVE_LIBCNOTIFY],
111      [1],
112      [Define to 1 if you have the `cnotify' library (-lcnotify).])
113    ])
114
115  AS_IF(
116    [test "x$ac_cv_libcnotify" = xyes],
117    [AC_SUBST(
118      [HAVE_LIBCNOTIFY],
119      [1]) ],
120    [AC_SUBST(
121      [HAVE_LIBCNOTIFY],
122      [0])
123    ])
124  ])
125
126dnl Function to detect if libcnotify dependencies are available
127AC_DEFUN([AX_LIBCNOTIFY_CHECK_LOCAL],
128  [dnl Headers included in libcnotify/libcnotify_print.c
129  AC_CHECK_HEADERS([stdarg.h varargs.h])
130
131  AS_IF(
132    [test "x$ac_cv_header_stdarg_h" != xyes && test "x$ac_cv_header_varargs_h" != xyes],
133    [AC_MSG_FAILURE(
134      [Missing headers: stdarg.h and varargs.h],
135      [1])
136    ])
137
138  dnl Headers included in libcnotify/libcnotify_stream.c
139  AC_CHECK_HEADERS([errno.h])
140
141  ac_cv_libcnotify_CPPFLAGS="-I../libcnotify";
142  ac_cv_libcnotify_LIBADD="../libcnotify/libcnotify.la";
143
144  ac_cv_libcnotify=local
145  ])
146
147dnl Function to detect how to enable libcnotify
148AC_DEFUN([AX_LIBCNOTIFY_CHECK_ENABLE],
149  [AX_COMMON_ARG_WITH(
150    [libcnotify],
151    [libcnotify],
152    [search for libcnotify in includedir and libdir or in the specified DIR, or no if to use local version],
153    [auto-detect],
154    [DIR])
155
156  dnl Check for a shared library version
157  AX_LIBCNOTIFY_CHECK_LIB
158
159  dnl Check if the dependencies for the local library version
160  AS_IF(
161    [test "x$ac_cv_libcnotify" != xyes],
162    [AX_LIBCNOTIFY_CHECK_LOCAL
163
164    AC_DEFINE(
165      [HAVE_LOCAL_LIBCNOTIFY],
166      [1],
167      [Define to 1 if the local version of libcnotify is used.])
168    AC_SUBST(
169      [HAVE_LOCAL_LIBCNOTIFY],
170      [1])
171    ])
172
173  AM_CONDITIONAL(
174    [HAVE_LOCAL_LIBCNOTIFY],
175    [test "x$ac_cv_libcnotify" = xlocal])
176  AS_IF(
177    [test "x$ac_cv_libcnotify_CPPFLAGS" != "x"],
178    [AC_SUBST(
179      [LIBCNOTIFY_CPPFLAGS],
180      [$ac_cv_libcnotify_CPPFLAGS])
181    ])
182  AS_IF(
183    [test "x$ac_cv_libcnotify_LIBADD" != "x"],
184    [AC_SUBST(
185      [LIBCNOTIFY_LIBADD],
186      [$ac_cv_libcnotify_LIBADD])
187    ])
188
189  AS_IF(
190    [test "x$ac_cv_libcnotify" = xyes],
191    [AC_SUBST(
192      [ax_libcnotify_pc_libs_private],
193      [-lcnotify])
194    ])
195
196  AS_IF(
197    [test "x$ac_cv_libcnotify" = xyes],
198    [AC_SUBST(
199      [ax_libcnotify_spec_requires],
200      [libcnotify])
201    AC_SUBST(
202      [ax_libcnotify_spec_build_requires],
203      [libcnotify-devel])
204    ])
205  ])
206
207