]> git.ipfire.org Git - thirdparty/util-linux.git/blob - m4/ul.m4
Merge branch 'ioclt' of https://github.com/lanurmi/util-linux
[thirdparty/util-linux.git] / m4 / ul.m4
1
2 dnl UL_PKG_STATIC(VARIABLE, MODULES)
3 dnl
4 dnl Calls pkg-config --static
5 dnl
6 AC_DEFUN([UL_PKG_STATIC], [
7 if AC_RUN_LOG([pkg-config --exists --print-errors "$2"]); then
8 $1=`pkg-config --libs --static "$2"`
9 else
10 AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
11 fi
12 ])
13
14 dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1]))
15 dnl
16 dnl The VARSUFFIX is optional and overrides the default behavior. For example:
17 dnl UL_CHECK_LIB(yyy, func, xxx) generates have_xxx and HAVE_LIBXXX
18 dnl UL_CHECK_LIB(yyy, func) generates have_yyy and HAVE_LIBYYY
19 dnl
20 AC_DEFUN([UL_CHECK_LIB], [
21 m4_define([suffix], m4_default([$3],$1))
22 [have_]suffix=yes
23 m4_ifdef([$3],
24 [AC_CHECK_LIB([$1], [$2], [AC_DEFINE(AS_TR_CPP([HAVE_LIB]suffix), 1)], [[have_]suffix=no])],
25 [AC_CHECK_LIB([$1], [$2], [], [[have_]suffix=no])])
26 AM_CONDITIONAL(AS_TR_CPP([HAVE_]suffix), [test [$have_]suffix = yes])
27 ])
28
29
30 dnl UL_SET_ARCH(ARCHNAME, PATTERN)
31 dnl
32 dnl Define ARCH_<archname> condition if the pattern match with the current
33 dnl architecture
34 dnl
35 AC_DEFUN([UL_SET_ARCH], [
36 cpu_$1=false
37 case "$host" in
38 $2) cpu_$1=true ;;
39 esac
40 AM_CONDITIONAL(AS_TR_CPP(ARCH_$1), [test "x$cpu_$1" = xtrue])
41 ])
42
43
44 dnl UL_SET_FLAGS(CFLAGS, CPPFLAGS, LDFLAGS)
45 dnl
46 dnl Sets new global CFLAGS, CPPFLAGS and LDFLAG, the original
47 dnl setting could be restored by UL_RESTORE_FLAGS()
48 dnl
49 AC_DEFUN([UL_SET_FLAGS], [
50 old_CFLAGS="$CFLAGS"
51 old_CPPFLAGS="$CPPFLAGS"
52 old_LDFLAGS="$LDFLAGS"
53 CFLAGS="$CFLAGS $1"
54 CPPFLAGS="$CPPFLAGS $2"
55 LDFLAGS="$LDFLAGS $3"
56 ])
57
58 dnl UL_RESTORE_FLAGS()
59 dnl
60 dnl Restores CFLAGS, CPPFLAGS and LDFLAG previously saved by UL_SET_FLAGS()
61 dnl
62 AC_DEFUN([UL_RESTORE_FLAGS], [
63 CFLAGS="$old_CFLAGS"
64 CPPFLAGS="$old_CPPFLAGS"
65 LDFLAGS="$old_LDFLAGS"
66 ])
67
68
69 dnl UL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
70 dnl
71 dnl Only specify FALLBACK if the SYSCALL you're checking for is a "newish" one
72 dnl
73 AC_DEFUN([UL_CHECK_SYSCALL], [
74 dnl This macro uses host_cpu.
75 AC_REQUIRE([AC_CANONICAL_HOST])
76 AC_CACHE_CHECK([for syscall $1],
77 [ul_cv_syscall_$1],
78 [_UL_SYSCALL_CHECK_DECL([SYS_$1],
79 [syscall=SYS_$1],
80 [dnl Our libc failed use, so see if we can get the kernel
81 dnl headers to play ball ...
82 _UL_SYSCALL_CHECK_DECL([_NR_$1],
83 [syscall=_NR_$1],
84 [
85 syscall=no
86 if test "x$linux_os" = xyes; then
87 case $host_cpu in
88 _UL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
89 esac
90 fi
91 ])
92 ])
93 ul_cv_syscall_$1=$syscall
94 ])
95 AM_CONDITIONAL([HAVE_]m4_toupper($1), [test "x$ul_cv_syscall_$1" != xno])
96 case $ul_cv_syscall_$1 in #(
97 no) AC_MSG_WARN([Unable to detect syscall $1.]) ;;
98 SYS_*) ;;
99 *) AC_DEFINE_UNQUOTED([SYS_$1], [$ul_cv_syscall_$1],
100 [Fallback syscall number for $1]) ;;
101 esac
102 ])
103
104
105 dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
106 dnl
107 dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
108 dnl
109 m4_define([_UL_SYSCALL_CHECK_DECL],
110 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
111 #include <sys/syscall.h>
112 #include <unistd.h>
113 ]], [[int test = $1;]])],
114 [$2], [$3])
115 ])
116
117 dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
118 dnl
119 dnl Helper macro to create the body for the above `case'.
120 dnl
121 m4_define([_UL_CHECK_SYSCALL_FALLBACK],
122 [m4_ifval([$1],
123 [#(
124 $1) syscall="$2" ;;dnl
125 _UL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
126 ])
127
128
129 dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1])
130 dnl
131 dnl Modifies $build_<name> variable according to $enable_<name> and OS type. The
132 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
133 dnl all checks are skiped.
134 dnl
135 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
136 dnl
137 AC_DEFUN([UL_REQUIRES_LINUX], [
138 m4_define([suffix], m4_default([$2],$1))
139 if test "x$[build_]suffix" != xno; then
140 AC_REQUIRE([AC_CANONICAL_HOST])
141 case $[enable_]suffix:$linux_os in #(
142 no:*)
143 [build_]suffix=no ;;
144 yes:yes)
145 [build_]suffix=yes ;;
146 yes:*)
147 AC_MSG_ERROR([$1 selected for non-linux system]);;
148 check:yes)
149 [build_]suffix=yes ;;
150 check:*)
151 AC_MSG_WARN([non-linux system; not building $1])
152 [build_]suffix=no ;;
153 esac
154 fi
155 ])
156
157
158 dnl UL_EXCLUDE_ARCH(NAME, ARCH, VARSUFFIX = $1])
159 dnl
160 dnl Modifies $build_<name> variable according to $enable_<name> and $host. The
161 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
162 dnl all checks are skiped.
163 dnl
164 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
165 dnl
166 AC_DEFUN([UL_EXCLUDE_ARCH], [
167 m4_define([suffix], m4_default([$3],$1))
168 if test "x$[build_]suffix" != xno; then
169 AC_REQUIRE([AC_CANONICAL_HOST])
170 case $[enable_]suffix:"$host" in #(
171 no:*)
172 [build_]suffix=no ;;
173 yes:$2)
174 AC_MSG_ERROR([$1 selected for unsupported architecture]);;
175 yes:*)
176 [build_]suffix=yes ;;
177 check:$2)
178 AC_MSG_WARN([excluded for $host architecture; not building $1])
179 [build_]suffix=no ;;
180 check:*)
181 [build_]suffix=yes ;;
182 esac
183 fi
184 ])
185
186 dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC [VARSUFFIX=$1])
187 dnl
188 dnl Modifies $build_<name> variable according to $enable_<name> and
189 dnl $have_<havename>. The <havedesc> is description used ifor warning/error
190 dnl message (e.g. "function").
191 dnl
192 dnl The <havename> maybe a list, then at least one of the items in the list
193 dnl have to exist, for example: [ncurses, tinfo] means that have_ncurser=yes
194 dnl *or* have_tinfo=yes must be defined.
195 dnl
196 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
197 dnl
198 AC_DEFUN([UL_REQUIRES_HAVE], [
199 m4_define([suffix], m4_default([$4],$1))
200
201 if test "x$[build_]suffix" != xno; then
202
203 [ul_haveone_]suffix=no
204 m4_foreach([onehave], [$2], [
205 if test "x$[have_]onehave" = xyes; then
206 [ul_haveone_]suffix=yes
207 fi
208 ])dnl
209
210 case $[enable_]suffix:$[ul_haveone_]suffix in #(
211 no:*)
212 [build_]suffix=no ;;
213 yes:yes)
214 [build_]suffix=yes ;;
215 yes:*)
216 AC_MSG_ERROR([$1 selected, but required $3 not available]);;
217 check:yes)
218 [build_]suffix=yes ;;
219 check:*)
220 AC_MSG_WARN([$3 not found; not building $1])
221 [build_]suffix=no ;;
222 esac
223 fi
224 ])
225
226
227 dnl
228 dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC [VARSUFFIX=$1])
229 dnl
230 dnl - ends with error if $enable_<name> and $build_<another>
231 dnl are both set to 'yes'
232 dnl - sets $build_<name> to 'no' if $build_<another> is 'yes' and
233 dnl $enable_<name> is 'check' or 'no'
234 dnl
235 dnl The <havedesc> is description used for warning/error
236 dnl message (e.g. "function").
237 dnl
238 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
239 dnl
240 AC_DEFUN([UL_CONFLICTS_BUILD], [
241 m4_define([suffix], m4_default([$4],$1))
242
243 if test "x$[build_]suffix" != xno; then
244 case $[enable_]suffix:$[build_]$2 in #(
245 no:*)
246 [build_]suffix=no ;;
247 check:yes)
248 [build_]suffix=no ;;
249 check:no)
250 [build_]suffix=yes ;;
251 yes:yes)
252 AC_MSG_ERROR([$1 selected, but it conflicts with $3]);;
253 esac
254 fi
255 ])
256
257
258 dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1])
259 dnl
260 dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname.
261 dnl
262 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
263 dnl
264 AC_DEFUN([UL_REQUIRES_BUILD], [
265 m4_define([suffix], m4_default([$3],$1))
266
267 if test "x$[build_]suffix" != xno; then
268 case $[enable_]suffix:$[build_]$2 in #(
269 no:*)
270 [build_]suffix=no ;;
271 yes:yes)
272 [build_]suffix=yes ;;
273 yes:*)
274 AC_MSG_ERROR([$2 is needed to build $1]);;
275 check:yes)
276 [build_]suffix=yes ;;
277 check:*)
278 AC_MSG_WARN([$2 disabled; not building $1])
279 [build_]suffix=no ;;
280 esac
281 fi
282 ])
283
284 dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1])
285 dnl
286 dnl Modifies $build_<name> variable according to $enable_<name> and SYSCALL-TEST
287 dnl result. The $enable_<name> variable could be "yes", "no" and "check". If build_<name>
288 dnl is "no" then all checks are skiped.
289 dnl
290 dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see
291 dnl also UL_CHECK_SYSCALL().
292 dnl
293 dnl The default <name> for $build_ and $enable_ count be overwrited by option $4 and
294 dnl $ul_cv_syscall_ could be overwrited by $3.
295 dnl
296 AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
297 m4_define([suffix], m4_default([$4],$1))
298 m4_define([callname], m4_default([$3],$1))
299
300 dnl This is default, $3 will redefine the condition
301 dnl
302 dnl TODO: remove this junk, AM_CONDITIONAL should not be used for any HAVE_*
303 dnl variables, all we need is BUILD_* only.
304 dnl
305 AM_CONDITIONAL([HAVE_]m4_toupper(callname), [false])
306
307 if test "x$[build_]suffix" != xno; then
308 if test "x$[enable_]suffix" = xno; then
309 [build_]suffix=no
310 else
311 $2
312 case $[enable_]suffix:$[ul_cv_syscall_]callname in #(
313 no:*)
314 [build_]suffix=no ;;
315 yes:no)
316 AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
317 check:no)
318 AC_MSG_WARN([callname syscall not found; not building $1])
319 [build_]suffix=no ;;
320 *)
321 dnl default $ul_cv_syscall_ is SYS_ value
322 [build_]suffix=yes ;;
323 esac
324 fi
325 fi
326 ])
327
328 dnl UL_BUILD_INIT(NAME, [ENABLE_STATE], [VARSUFFIX = $1])
329 dnl
330 dnl Initializes $build_<name> variable according to $enable_<name>. If
331 dnl $enable_<name> is undefined then ENABLE_STATE is used and $enable_<name> is
332 dnl set to ENABLE_STATE.
333 dnl
334 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
335 dnl
336 AC_DEFUN([UL_BUILD_INIT], [
337 m4_define([suffix], m4_default([$3],$1))
338 m4_ifblank([$2],
339 [if test "x$enable_[]suffix" = xno; then
340 build_[]suffix=no
341 else
342 build_[]suffix=yes
343 fi],
344 [if test "x$ul_default_estate" != x; then
345 enable_[]suffix=$ul_default_estate
346 build_[]suffix=yes
347 if test "x$ul_default_estate" = xno; then
348 build_[]suffix=no
349 fi
350 else[]
351 ifelse(
352 [$2], [check],[
353 build_[]suffix=yes
354 enable_[]suffix=check],
355 [$2], [yes],[
356 build_[]suffix=yes
357 enable_[]suffix=yes],
358 [$2], [no], [
359 build_[]suffix=no
360 enable_[]suffix=no])
361 fi])
362 ])
363
364 dnl UL_DEFAULT_ENABLE(NAME, ENABLE_STATE)
365 dnl
366 dnl Initializes $enable_<name> variable according to ENABLE_STATE. The default
367 dnl setting is possible to override by global $ul_default_estate.
368 dnl
369 AC_DEFUN([UL_DEFAULT_ENABLE], [
370 m4_define([suffix], $1)
371 if test "x$ul_default_estate" != x; then
372 enable_[]suffix=$ul_default_estate
373 else
374 enable_[]suffix=$2
375 fi
376 ])