1dnl Checks for libcerror required headers and functions
2dnl
3dnl Version: 20190308
4
5dnl Function to detect if libcerror is available
6dnl ac_libcerror_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments
7AC_DEFUN([AX_LIBCERROR_CHECK_LIB],
8  [AS_IF(
9    [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libcerror" = xno],
10    [ac_cv_libcerror=no],
11    [ac_cv_libcerror=check
12    dnl Check if the directory provided as parameter exists
13    AS_IF(
14      [test "x$ac_cv_with_libcerror" != x && test "x$ac_cv_with_libcerror" != xauto-detect],
15      [AS_IF(
16        [test -d "$ac_cv_with_libcerror"],
17        [CFLAGS="$CFLAGS -I${ac_cv_with_libcerror}/include"
18        LDFLAGS="$LDFLAGS -L${ac_cv_with_libcerror}/lib"],
19        [AC_MSG_FAILURE(
20          [no such directory: $ac_cv_with_libcerror],
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          [libcerror],
29          [libcerror >= 20120425],
30          [ac_cv_libcerror=yes],
31          [ac_cv_libcerror=check])
32        ])
33      AS_IF(
34        [test "x$ac_cv_libcerror" = xyes],
35        [ac_cv_libcerror_CPPFLAGS="$pkg_cv_libcerror_CFLAGS"
36        ac_cv_libcerror_LIBADD="$pkg_cv_libcerror_LIBS"])
37      ])
38
39    AS_IF(
40      [test "x$ac_cv_libcerror" = xcheck],
41      [dnl Check for headers
42      AC_CHECK_HEADERS([libcerror.h])
43
44      AS_IF(
45        [test "x$ac_cv_header_libcerror_h" = xno],
46        [ac_cv_libcerror=no],
47        [dnl Check for the individual functions
48        ac_cv_libcerror=yes
49
50        AC_CHECK_LIB(
51          cerror,
52          libcerror_get_version,
53          [ac_cv_libcerror_dummy=yes],
54          [ac_cv_libcerror=no])
55
56        dnl Error functions
57        AC_CHECK_LIB(
58          cerror,
59          libcerror_error_free,
60          [ac_cv_libcerror_dummy=yes],
61          [ac_cv_libcerror=no])
62        AC_CHECK_LIB(
63          cerror,
64          libcerror_error_set,
65          [ac_cv_libcerror_dummy=yes],
66          [ac_cv_libcerror=no])
67        AC_CHECK_LIB(
68          cerror,
69          libcerror_error_matches,
70          [ac_cv_libcerror_dummy=yes],
71          [ac_cv_libcerror=no])
72        AC_CHECK_LIB(
73          cerror,
74          libcerror_error_fprint,
75          [ac_cv_libcerror_dummy=yes],
76          [ac_cv_libcerror=no])
77        AC_CHECK_LIB(
78          cerror,
79          libcerror_error_sprint,
80          [ac_cv_libcerror_dummy=yes],
81          [ac_cv_libcerror=no])
82        AC_CHECK_LIB(
83          cerror,
84          libcerror_error_backtrace_fprint,
85          [ac_cv_libcerror_dummy=yes],
86          [ac_cv_libcerror=no])
87        AC_CHECK_LIB(
88          cerror,
89          libcerror_error_backtrace_sprint,
90          [ac_cv_libcerror_dummy=yes],
91          [ac_cv_libcerror=no])
92
93        dnl System error functions
94        AC_CHECK_LIB(
95          cerror,
96          libcerror_system_set_error,
97          [ac_cv_libcerror_dummy=yes],
98          [ac_cv_libcerror=no])
99
100        ac_cv_libcerror_LIBADD="-lcerror"])
101      ])
102    AS_IF(
103      [test "x$ac_cv_with_libcerror" != x && test "x$ac_cv_with_libcerror" != xauto-detect && test "x$ac_cv_libcerror" != xyes],
104      [AC_MSG_FAILURE(
105        [unable to find supported libcerror in directory: $ac_cv_with_libcerror],
106        [1])
107      ])
108    ])
109
110  AS_IF(
111    [test "x$ac_cv_libcerror" = xyes],
112    [AC_DEFINE(
113      [HAVE_LIBCERROR],
114      [1],
115      [Define to 1 if you have the `cerror' library (-lcerror).])
116    ])
117
118  AS_IF(
119    [test "x$ac_cv_libcerror" = xyes],
120    [AC_SUBST(
121      [HAVE_LIBCERROR],
122      [1]) ],
123    [AC_SUBST(
124      [HAVE_LIBCERROR],
125      [0])
126    ])
127  ])
128
129dnl Function to detect if libcerror dependencies are available
130AC_DEFUN([AX_LIBCERROR_CHECK_LOCAL],
131  [dnl Headers included in libcerror/libcerror_error.c
132  AC_CHECK_HEADERS([stdarg.h varargs.h])
133
134  AS_IF(
135    [test "x$ac_cv_header_stdarg_h" != xyes && test "x$ac_cv_header_varargs_h" != xyes],
136    [AC_MSG_FAILURE(
137      [Missing headers: stdarg.h and varargs.h],
138      [1])
139    ])
140
141  dnl Wide character string functions used in libcerror/libcerror_error.c
142  AS_IF(
143    [test "x$ac_cv_enable_wide_character_type" != xno],
144    [AC_CHECK_FUNCS([wcstombs])
145
146    AS_IF(
147      [test "x$ac_cv_func_wcstombs" != xyes],
148      [AC_MSG_FAILURE(
149        [Missing function: wcstombs],
150        [1])
151      ])
152    ])
153
154  dnl Check for error string functions used in libcerror/libcerror_system.c
155  AC_FUNC_STRERROR_R()
156
157  AS_IF(
158    [test "x$ac_cv_have_decl_strerror_r" != xyes],
159    [AC_CHECK_FUNCS([strerror])
160
161    AS_IF(
162      [test "x$ac_cv_func_strerror" != xyes],
163      [AC_MSG_FAILURE(
164        [Missing functions: strerror_r and strerror],
165        [1])
166      ])
167    ])
168
169  ac_cv_libcerror_CPPFLAGS="-I../libcerror";
170  ac_cv_libcerror_LIBADD="../libcerror/libcerror.la";
171
172  ac_cv_libcerror=local
173  ])
174
175dnl Function to detect how to enable libcerror
176AC_DEFUN([AX_LIBCERROR_CHECK_ENABLE],
177  [AX_COMMON_ARG_WITH(
178    [libcerror],
179    [libcerror],
180    [search for libcerror in includedir and libdir or in the specified DIR, or no if to use local version],
181    [auto-detect],
182    [DIR])
183
184  dnl Check for a shared library version
185  AX_LIBCERROR_CHECK_LIB
186
187  dnl Check if the dependencies for the local library version
188  AS_IF(
189    [test "x$ac_cv_libcerror" != xyes],
190    [AX_LIBCERROR_CHECK_LOCAL
191
192    AC_DEFINE(
193      [HAVE_LOCAL_LIBCERROR],
194      [1],
195      [Define to 1 if the local version of libcerror is used.])
196    AC_SUBST(
197      [HAVE_LOCAL_LIBCERROR],
198      [1])
199    ])
200
201  AM_CONDITIONAL(
202    [HAVE_LOCAL_LIBCERROR],
203    [test "x$ac_cv_libcerror" = xlocal])
204  AS_IF(
205    [test "x$ac_cv_libcerror_CPPFLAGS" != "x"],
206    [AC_SUBST(
207      [LIBCERROR_CPPFLAGS],
208      [$ac_cv_libcerror_CPPFLAGS])
209    ])
210  AS_IF(
211    [test "x$ac_cv_libcerror_LIBADD" != "x"],
212    [AC_SUBST(
213      [LIBCERROR_LIBADD],
214      [$ac_cv_libcerror_LIBADD])
215    ])
216
217  AS_IF(
218    [test "x$ac_cv_libcerror" = xyes],
219    [AC_SUBST(
220      [ax_libcerror_pc_libs_private],
221      [-lcerror])
222    ])
223
224  AS_IF(
225    [test "x$ac_cv_libcerror" = xyes],
226    [AC_SUBST(
227      [ax_libcerror_spec_requires],
228      [libcerror])
229    AC_SUBST(
230      [ax_libcerror_spec_build_requires],
231      [libcerror-devel])
232    ])
233  ])
234
235