Debian Codegraph @

m4/libcpath.m4

raw
1 dnl Checks for libcpath required headers and functions
2 dnl
3 dnl Version: 20240518
4
5 dnl Function to detect if libcpath is available
6 dnl ac_libcpath_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments
7 AC_DEFUN([AX_LIBCPATH_CHECK_LIB],
8 [AS_IF(
9 [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libcpath" = xno],
10 [ac_cv_libcpath=no],
11 [ac_cv_libcpath=check
12 dnl Check if the directory provided as parameter exists
13 dnl For both --with-libcpath which returns "yes" and --with-libcpath= which returns ""
14 dnl treat them as auto-detection.
15 AS_IF(
16 [test "x$ac_cv_with_libcpath" != x && test "x$ac_cv_with_libcpath" != xauto-detect && test "x$ac_cv_with_libcpath" != xyes],
17 [AX_CHECK_LIB_DIRECTORY_EXISTS([libcpath])],
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 [libcpath],
23 [libcpath >= 20180716],
24 [ac_cv_libcpath=yes],
25 [ac_cv_libcpath=check])
26 ])
27 AS_IF(
28 [test "x$ac_cv_libcpath" = xyes && test "x$ac_cv_enable_wide_character_type" != xno],
29 [AC_CACHE_CHECK(
30 [whether libcpath/features.h defines LIBCPATH_HAVE_WIDE_CHARACTER_TYPE as 1],
31 [ac_cv_header_libcpath_features_h_have_wide_character_type],
32 [AC_LANG_PUSH(C)
33 AC_COMPILE_IFELSE(
34 [AC_LANG_PROGRAM(
35 [[#include <libcpath/features.h>]],
36 [[#if !defined( LIBCPATH_HAVE_WIDE_CHARACTER_TYPE ) || ( LIBCPATH_HAVE_WIDE_CHARACTER_TYPE != 1 )
37 #error LIBCPATH_HAVE_WIDE_CHARACTER_TYPE not defined
38 #endif]] )],
39 [ac_cv_header_libcpath_features_h_have_wide_character_type=yes],
40 [ac_cv_header_libcpath_features_h_have_wide_character_type=no])
41 AC_LANG_POP(C)],
42 [ac_cv_header_libcpath_features_h_have_wide_character_type=no])
43
44 AS_IF(
45 [test "x$ac_cv_header_libcpath_features_h_have_wide_character_type" = xno],
46 [ac_cv_libcpath=no])
47 ])
48 AS_IF(
49 [test "x$ac_cv_libcpath" = xyes],
50 [ac_cv_libcpath_CPPFLAGS="$pkg_cv_libcpath_CFLAGS"
51 ac_cv_libcpath_LIBADD="$pkg_cv_libcpath_LIBS"])
52 ])
53
54 AS_IF(
55 [test "x$ac_cv_libcpath" = xcheck],
56 [dnl Check for headers
57 AC_CHECK_HEADERS([libcpath.h])
58
59 AS_IF(
60 [test "x$ac_cv_header_libcpath_h" = xno],
61 [ac_cv_libcpath=no],
62 [ac_cv_libcpath=yes
63
64 AX_CHECK_LIB_FUNCTIONS(
65 [libcpath],
66 [cpath],
67 [[libcpath_get_version],
68 [libcpath_path_change_directory],
69 [libcpath_path_get_current_working_directory],
70 [libcpath_path_get_full_path],
71 [libcpath_path_get_sanitized_filename],
72 [libcpath_path_get_sanitized_path],
73 [libcpath_path_join],
74 [libcpath_path_make_directory]])
75
76 AS_IF(
77 [test "x$ac_cv_enable_wide_character_type" != xno],
78 [AX_CHECK_LIB_FUNCTIONS(
79 [libcpath],
80 [cpath],
81 [[libcpath_path_change_directory_wide],
82 [libcpath_path_get_current_working_directory_wide],
83 [libcpath_path_get_full_path_wide],
84 [libcpath_path_get_sanitized_filename_wide],
85 [libcpath_path_get_sanitized_path_wide],
86 [libcpath_path_join_wide],
87 [libcpath_path_make_directory_wide]])
88 ])
89
90 ac_cv_libcpath_LIBADD="-lcpath"])
91 ])
92
93 AX_CHECK_LIB_DIRECTORY_MSG_ON_FAILURE([libcpath])
94 ])
95
96 AS_IF(
97 [test "x$ac_cv_libcpath" = xyes],
98 [AC_DEFINE(
99 [HAVE_LIBCPATH],
100 [1],
101 [Define to 1 if you have the `cpath' library (-lcpath).])
102 ])
103
104 AS_IF(
105 [test "x$ac_cv_libcpath" = xyes],
106 [AC_SUBST(
107 [HAVE_LIBCPATH],
108 [1]) ],
109 [AC_SUBST(
110 [HAVE_LIBCPATH],
111 [0])
112 ])
113 ])
114
115 dnl Function to detect if mkdir is available
116 dnl Also checks how to use mkdir
117 AC_DEFUN([AX_LIBCPATH_CHECK_FUNC_MKDIR],
118 [AC_CHECK_FUNCS([mkdir])
119
120 AS_IF(
121 [test "x$ac_cv_func_mkdir" = xyes],
122 [AC_MSG_CHECKING(
123 [how to use mkdir])
124
125 SAVE_CFLAGS="$CFLAGS"
126 CFLAGS="$CFLAGS -Wall -Werror"
127 AC_LANG_PUSH(C)
128
129 AC_LINK_IFELSE(
130 [AC_LANG_PROGRAM(
131 [[#include <sys/stat.h>
132 #include <sys/types.h>]],
133 [[mkdir( "", 0 )]] )],
134 [AC_MSG_RESULT(
135 [with additional mode argument])
136 ac_cv_cv_mkdir_mode=yes],
137 [ac_cv_cv_mkdir_mode=no])
138
139 AS_IF(
140 [test "x$ac_cv_cv_mkdir_mode" = xno],
141 [AC_LINK_IFELSE(
142 [AC_LANG_PROGRAM(
143 [[#include <io.h>]],
144 [[mkdir( "" )]] )],
145 [AC_MSG_RESULT(
146 [with single argument])
147 ac_cv_cv_mkdir=yes],
148 [ac_cv_cv_mkdir=no])
149 ])
150
151 AC_LANG_POP(C)
152 CFLAGS="$SAVE_CFLAGS"
153
154 AS_IF(
155 [test "x$ac_cv_cv_mkdir_mode" = xno && test "x$ac_cv_cv_mkdir" = xno],
156 [AC_MSG_WARN(
157 [unknown])
158 ac_cv_func_mkdir=no])
159
160 AS_IF(
161 [test "x$ac_cv_func_mkdir" = xyes],
162 [AC_DEFINE(
163 [HAVE_MKDIR],
164 [1],
165 [Define to 1 if you have the mkdir function.])
166 ])
167
168 AS_IF(
169 [test "x$ac_cv_cv_mkdir_mode" = xyes],
170 [AC_DEFINE(
171 [HAVE_MKDIR_MODE],
172 [1],
173 [Define to 1 if you have the mkdir function with a second mode argument.])
174 ])
175 ])
176
177 AS_IF(
178 [test "x$ac_cv_func_mkdir" = xno],
179 [AC_MSG_FAILURE(
180 [Missing function: mkdir],
181 [1])
182 ])
183 ])
184
185 dnl Function to detect if libcpath dependencies are available
186 AC_DEFUN([AX_LIBCPATH_CHECK_LOCAL],
187 [dnl Headers included in libcpath/libcpath_path.h
188 AC_CHECK_HEADERS([errno.h sys/stat.h sys/syslimits.h])
189
190 dnl Path functions used in libcpath/libcpath_path.h
191 AC_CHECK_FUNCS([chdir getcwd])
192
193 AS_IF(
194 [test "x$ac_cv_func_chdir" != xyes],
195 [AC_MSG_FAILURE(
196 [Missing functions: chdir],
197 [1])
198 ])
199
200 AS_IF(
201 [test "x$ac_cv_func_getcwd" != xyes],
202 [AC_MSG_FAILURE(
203 [Missing functions: getcwd],
204 [1])
205 ])
206
207 AX_LIBCPATH_CHECK_FUNC_MKDIR
208
209 ac_cv_libcpath_CPPFLAGS="-I../libcpath -I\$(top_srcdir)/libcpath";
210 ac_cv_libcpath_LIBADD="../libcpath/libcpath.la";
211
212 ac_cv_libcpath=local
213 ])
214
215 dnl Function to detect how to enable libcpath
216 AC_DEFUN([AX_LIBCPATH_CHECK_ENABLE],
217 [AX_COMMON_ARG_WITH(
218 [libcpath],
219 [libcpath],
220 [search for libcpath in includedir and libdir or in the specified DIR, or no if to use local version],
221 [auto-detect],
222 [DIR])
223
224 dnl Check for a shared library version
225 AX_LIBCPATH_CHECK_LIB
226
227 dnl Check if the dependencies for the local library version
228 AS_IF(
229 [test "x$ac_cv_libcpath" != xyes],
230 [AX_LIBCPATH_CHECK_LOCAL
231
232 AC_DEFINE(
233 [HAVE_LOCAL_LIBCPATH],
234 [1],
235 [Define to 1 if the local version of libcpath is used.])
236 AC_SUBST(
237 [HAVE_LOCAL_LIBCPATH],
238 [1])
239 ])
240
241 AM_CONDITIONAL(
242 [HAVE_LOCAL_LIBCPATH],
243 [test "x$ac_cv_libcpath" = xlocal])
244 AS_IF(
245 [test "x$ac_cv_libcpath_CPPFLAGS" != "x"],
246 [AC_SUBST(
247 [LIBCPATH_CPPFLAGS],
248 [$ac_cv_libcpath_CPPFLAGS])
249 ])
250 AS_IF(
251 [test "x$ac_cv_libcpath_LIBADD" != "x"],
252 [AC_SUBST(
253 [LIBCPATH_LIBADD],
254 [$ac_cv_libcpath_LIBADD])
255 ])
256
257 AS_IF(
258 [test "x$ac_cv_libcpath" = xyes],
259 [AC_SUBST(
260 [ax_libcpath_pc_libs_private],
261 [-lcpath])
262 ])
263
264 AS_IF(
265 [test "x$ac_cv_libcpath" = xyes],
266 [AC_SUBST(
267 [ax_libcpath_spec_requires],
268 [libcpath])
269 AC_SUBST(
270 [ax_libcpath_spec_build_requires],
271 [libcpath-devel])
272 ])
273 ])
274