Debian Codegraph @

m4/libcfile.m4

raw
1 dnl Checks for libcfile required headers and functions
2 dnl
3 dnl Version: 20240514
4
5 dnl Function to detect if libcfile is available
6 dnl ac_libcfile_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments
7 AC_DEFUN([AX_LIBCFILE_CHECK_LIB],
8 [AS_IF(
9 [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libcfile" = xno],
10 [ac_cv_libcfile=no],
11 [ac_cv_libcfile=check
12 dnl Check if the directory provided as parameter exists
13 dnl For both --with-libcfile which returns "yes" and --with-libcfile= which returns ""
14 dnl treat them as auto-detection.
15 AS_IF(
16 [test "x$ac_cv_with_libcfile" != x && test "x$ac_cv_with_libcfile" != xauto-detect && test "x$ac_cv_with_libcfile" != xyes],
17 [AX_CHECK_LIB_DIRECTORY_EXISTS([libcfile])],
18 [dnl Check for a pkg-config file
19 AS_IF(
20 [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"],
21 [PKG_CHECK_MODULES(
22 [libcfile],
23 [libcfile >= 20160409],
24 [ac_cv_libcfile=yes],
25 [ac_cv_libcfile=check])
26 ])
27 AS_IF(
28 [test "x$ac_cv_libcfile" = xyes && test "x$ac_cv_enable_wide_character_type" != xno],
29 [AC_CACHE_CHECK(
30 [whether libcfile/features.h defines LIBCFILE_HAVE_WIDE_CHARACTER_TYPE as 1],
31 [ac_cv_header_libcfile_features_h_have_wide_character_type],
32 [AC_LANG_PUSH(C)
33 AC_COMPILE_IFELSE(
34 [AC_LANG_PROGRAM(
35 [[#include <libcfile/features.h>]],
36 [[#if !defined( LIBCFILE_HAVE_WIDE_CHARACTER_TYPE ) || ( LIBCFILE_HAVE_WIDE_CHARACTER_TYPE != 1 )
37 #error LIBCFILE_HAVE_WIDE_CHARACTER_TYPE not defined
38 #endif]] )],
39 [ac_cv_header_libcfile_features_h_have_wide_character_type=yes],
40 [ac_cv_header_libcfile_features_h_have_wide_character_type=no])
41 AC_LANG_POP(C)],
42 [ac_cv_header_libcfile_features_h_have_wide_character_type=no])
43
44 AS_IF(
45 [test "x$ac_cv_header_libcfile_features_h_have_wide_character_type" = xno],
46 [ac_cv_libcfile=no])
47 ])
48 AS_IF(
49 [test "x$ac_cv_libcfile" = xyes],
50 [ac_cv_libcfile_CPPFLAGS="$pkg_cv_libcfile_CFLAGS"
51 ac_cv_libcfile_LIBADD="$pkg_cv_libcfile_LIBS"])
52 ])
53
54 AS_IF(
55 [test "x$ac_cv_libcfile" = xcheck],
56 [dnl Check for headers
57 AC_CHECK_HEADERS([libcfile.h])
58
59 AS_IF(
60 [test "x$ac_cv_header_libcfile_h" = xno],
61 [ac_cv_libcfile=no],
62 [ac_cv_libcfile=yes
63
64 AX_CHECK_LIB_FUNCTIONS(
65 [libcfile],
66 [cfile],
67 [[libcfile_get_version],
68 [libcfile_file_initialize],
69 [libcfile_file_free],
70 [libcfile_file_open],
71 [libcfile_file_open_with_error_code],
72 [libcfile_file_close],
73 [libcfile_file_read_buffer],
74 [libcfile_file_read_buffer_with_error_code],
75 [libcfile_file_write_buffer],
76 [libcfile_file_write_buffer_with_error_code],
77 [libcfile_file_seek_offset],
78 [libcfile_file_resize],
79 [libcfile_file_is_open],
80 [libcfile_file_get_offset],
81 [libcfile_file_get_size],
82 [libcfile_file_is_device],
83 [libcfile_file_io_control_read],
84 [libcfile_file_io_control_read_with_error_code],
85 [libcfile_file_exists],
86 [libcfile_file_remove]])
87
88 AS_IF(
89 [test "x$ac_cv_enable_wide_character_type" != xno],
90 [AX_CHECK_LIB_FUNCTIONS(
91 [libcfile],
92 [cfile],
93 [[libcfile_file_open_wide],
94 [libcfile_file_open_wide_with_error_code],
95 [libcfile_file_exists_wide],
96 [libcfile_file_remove_wide]])
97 ])
98
99 ac_cv_libcfile_LIBADD="-lcfile"])
100 ])
101
102 AX_CHECK_LIB_DIRECTORY_MSG_ON_FAILURE([libcfile])
103 ])
104
105 AS_IF(
106 [test "x$ac_cv_libcfile" = xyes],
107 [AC_DEFINE(
108 [HAVE_LIBCFILE],
109 [1],
110 [Define to 1 if you have the `cfile' library (-lcfile).])
111 ])
112
113 AS_IF(
114 [test "x$ac_cv_libcfile" = xyes],
115 [AC_SUBST(
116 [HAVE_LIBCFILE],
117 [1]) ],
118 [AC_SUBST(
119 [HAVE_LIBCFILE],
120 [0])
121 ])
122 ])
123
124 dnl Function to detect if posix_fadvise is available
125 AC_DEFUN([AX_LIBCFILE_CHECK_FUNC_POSIX_FADVISE],
126 [AC_CHECK_FUNCS([posix_fadvise])
127
128 AS_IF(
129 [test "x$ac_cv_func_posix_fadvise" = xyes],
130 [AC_MSG_CHECKING(
131 [whether posix_fadvise can be linked])
132
133 SAVE_CFLAGS="$CFLAGS"
134 CFLAGS="$CFLAGS -Wall -Werror"
135 AC_LANG_PUSH(C)
136
137 AC_LINK_IFELSE(
138 [AC_LANG_PROGRAM(
139 [[#include <fcntl.h>]],
140 [[#if !defined( POSIX_FADV_SEQUENTIAL )
141 #define POSIX_FADV_SEQUENTIAL 2
142 #endif
143 posix_fadvise( 0, 0, 0, POSIX_FADV_SEQUENTIAL )]] )],
144 [ac_cv_func_posix_fadvise=yes],
145 [ac_cv_func_posix_fadvise=no])
146
147 AC_LANG_POP(C)
148 CFLAGS="$SAVE_CFLAGS"
149
150 AS_IF(
151 [test "x$ac_cv_func_posix_fadvise" = xyes],
152 [AC_MSG_RESULT(
153 [yes])
154 AC_DEFINE(
155 [HAVE_POSIX_FADVISE],
156 [1],
157 [Define to 1 if you have the posix_fadvise function.]) ],
158 [AC_MSG_RESULT(
159 [no]) ])
160 ])
161 ])
162
163 dnl Function to detect if libcfile dependencies are available
164 AC_DEFUN([AX_LIBCFILE_CHECK_LOCAL],
165 [dnl Headers included in libcfile/libcfile_file.c and libcfile/libcfile_support.c
166 AC_CHECK_HEADERS([errno.h stdio.h sys/stat.h])
167
168 dnl Headers included in libcfile/libcfile_file.c
169 AC_CHECK_HEADERS([cygwin/fs.h fcntl.h linux/fs.h sys/disk.h sys/disklabel.h sys/ioctl.h unistd.h])
170
171 dnl File input/output functions used in libcfile/libcfile_file.c
172 AC_CHECK_FUNCS([close fstat ftruncate ioctl lseek open read write])
173
174 AS_IF(
175 [test "x$ac_cv_func_close" != xyes],
176 [AC_MSG_FAILURE(
177 [Missing function: close],
178 [1])
179 ])
180
181 AX_LIBCFILE_CHECK_FUNC_POSIX_FADVISE
182
183 AS_IF(
184 [test "x$ac_cv_func_fstat" != xyes],
185 [AC_MSG_FAILURE(
186 [Missing function: fstat],
187 [1])
188 ])
189
190 AS_IF(
191 [test "x$ac_cv_func_ftruncate" != xyes],
192 [AC_MSG_FAILURE(
193 [Missing function: ftruncate],
194 [1])
195 ])
196
197 AS_IF(
198 [test x"$ac_cv_enable_winapi" = xno],
199 [AS_IF(
200 [test "x$ac_cv_func_ioctl" != xyes],
201 [AC_MSG_FAILURE(
202 [Missing function: ioctl],
203 [1])
204 ])
205 ])
206
207 AS_IF(
208 [test "x$ac_cv_func_lseek" != xyes],
209 [AC_MSG_FAILURE(
210 [Missing function: lseek],
211 [1])
212 ])
213
214 AS_IF(
215 [test "x$ac_cv_func_open" != xyes],
216 [AC_MSG_FAILURE(
217 [Missing function: open],
218 [1])
219 ])
220
221 AS_IF(
222 [test "x$ac_cv_func_read" != xyes],
223 [AC_MSG_FAILURE(
224 [Missing function: read],
225 [1])
226 ])
227
228 AS_IF(
229 [test "x$ac_cv_func_write" != xyes],
230 [AC_MSG_FAILURE(
231 [Missing function: write],
232 [1])
233 ])
234
235 dnl File input/output functions used in libcfile/libcfile_support.c
236 AC_CHECK_FUNCS([stat unlink])
237
238 AS_IF(
239 [test "x$ac_cv_func_stat" != xyes],
240 [AC_MSG_FAILURE(
241 [Missing function: stat],
242 [1])
243 ])
244
245 AS_IF(
246 [test "x$ac_cv_func_unlink" != xyes],
247 [AC_MSG_FAILURE(
248 [Missing function: unlink],
249 [1])
250 ])
251
252 ac_cv_libcfile_CPPFLAGS="-I../libcfile -I\$(top_srcdir)/libcfile";
253 ac_cv_libcfile_LIBADD="../libcfile/libcfile.la";
254
255 ac_cv_libcfile=local
256 ])
257
258 dnl Function to detect how to enable libcfile
259 AC_DEFUN([AX_LIBCFILE_CHECK_ENABLE],
260 [AX_COMMON_ARG_WITH(
261 [libcfile],
262 [libcfile],
263 [search for libcfile in includedir and libdir or in the specified DIR, or no if to use local version],
264 [auto-detect],
265 [DIR])
266
267 dnl Check for a shared library version
268 AX_LIBCFILE_CHECK_LIB
269
270 dnl Check if the dependencies for the local library version
271 AS_IF(
272 [test "x$ac_cv_libcfile" != xyes],
273 [AX_LIBCFILE_CHECK_LOCAL
274
275 AC_DEFINE(
276 [HAVE_LOCAL_LIBCFILE],
277 [1],
278 [Define to 1 if the local version of libcfile is used.])
279 AC_SUBST(
280 [HAVE_LOCAL_LIBCFILE],
281 [1])
282 ])
283
284 AM_CONDITIONAL(
285 [HAVE_LOCAL_LIBCFILE],
286 [test "x$ac_cv_libcfile" = xlocal])
287 AS_IF(
288 [test "x$ac_cv_libcfile_CPPFLAGS" != "x"],
289 [AC_SUBST(
290 [LIBCFILE_CPPFLAGS],
291 [$ac_cv_libcfile_CPPFLAGS])
292 ])
293 AS_IF(
294 [test "x$ac_cv_libcfile_LIBADD" != "x"],
295 [AC_SUBST(
296 [LIBCFILE_LIBADD],
297 [$ac_cv_libcfile_LIBADD])
298 ])
299
300 AS_IF(
301 [test "x$ac_cv_libcfile" = xyes],
302 [AC_SUBST(
303 [ax_libcfile_pc_libs_private],
304 [-lcfile])
305 ])
306
307 AS_IF(
308 [test "x$ac_cv_libcfile" = xyes],
309 [AC_SUBST(
310 [ax_libcfile_spec_requires],
311 [libcfile])
312 AC_SUBST(
313 [ax_libcfile_spec_build_requires],
314 [libcfile-devel])
315 ])
316 ])
317