]> git.ipfire.org Git - thirdparty/util-linux.git/blob - m4/ul.m4
kill: add missing ifdefs
[thirdparty/util-linux.git] / m4 / ul.m4
1 dnl If needed, define the m4_ifblank and m4_ifnblank macros from autoconf 2.64
2 dnl This allows us to run with earlier Autoconfs as well.
3 dnl
4 dnl m4_ifblank(COND, [IF-BLANK], [IF-TEXT])
5 dnl m4_ifnblank(COND, [IF-TEXT], [IF-BLANK])
6 dnl ----------------------------------------
7 dnl If COND is empty, or consists only of blanks (space, tab, newline),
8 dnl then expand IF-BLANK, otherwise expand IF-TEXT. This differs from
9 dnl m4_ifval only if COND has just whitespace, but it helps optimize in
10 dnl spite of users who mistakenly leave trailing space after what they
11 dnl thought was an empty argument:
12 dnl macro(
13 dnl []
14 dnl )
15 dnl
16 dnl Writing one macro in terms of the other causes extra overhead, so
17 dnl we inline both definitions.
18 ifdef([m4_ifblank],[],[
19 m4_define([m4_ifblank],
20 [m4_if(m4_translit([[$1]], [ ][ ][
21 ]), [], [$2], [$3])])])
22
23 ifdef([m4_ifnblank],[],[
24 m4_define([m4_ifnblank],
25 [m4_if(m4_translit([[$1]], [ ][ ][
26 ]), [], [$3], [$2])])])
27
28 dnl UL_PKG_STATIC(VARIABLE, MODULES)
29 dnl
30 dnl Calls pkg-config --static
31 dnl
32 AC_DEFUN([UL_PKG_STATIC], [
33 if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
34 $1=`$PKG_CONFIG --libs --static "$2"`
35 else
36 AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
37 fi
38 ])
39
40 dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1]))
41 dnl
42 dnl The VARSUFFIX is optional and overrides the default behavior. For example:
43 dnl UL_CHECK_LIB(yyy, func, xxx) generates have_xxx and HAVE_LIBXXX
44 dnl UL_CHECK_LIB(yyy, func) generates have_yyy and HAVE_LIBYYY
45 dnl
46 AC_DEFUN([UL_CHECK_LIB], [
47 m4_define([suffix], m4_default([$3],$1))
48 [have_]suffix=yes
49 m4_ifdef([$3],
50 [AC_CHECK_LIB([$1], [$2], [AC_DEFINE(AS_TR_CPP([HAVE_LIB]suffix), 1)], [[have_]suffix=no])],
51 [AC_CHECK_LIB([$1], [$2], [], [[have_]suffix=no])])
52 AM_CONDITIONAL(AS_TR_CPP([HAVE_]suffix), [test [$have_]suffix = yes])
53 ])
54
55
56 dnl UL_SET_ARCH(ARCHNAME, PATTERN)
57 dnl
58 dnl Define ARCH_<archname> condition if the pattern match with the current
59 dnl architecture
60 dnl
61 AC_DEFUN([UL_SET_ARCH], [
62 cpu_$1=false
63 case "$host" in
64 $2) cpu_$1=true ;;
65 esac
66 AM_CONDITIONAL(AS_TR_CPP(ARCH_$1), [test "x$cpu_$1" = xtrue])
67 ])
68
69
70 dnl UL_SET_FLAGS(CFLAGS, CPPFLAGS, LDFLAGS)
71 dnl
72 dnl Sets new global CFLAGS, CPPFLAGS and LDFLAG, the original
73 dnl setting could be restored by UL_RESTORE_FLAGS()
74 dnl
75 AC_DEFUN([UL_SET_FLAGS], [
76 old_CFLAGS="$CFLAGS"
77 old_CPPFLAGS="$CPPFLAGS"
78 old_LDFLAGS="$LDFLAGS"
79 CFLAGS="$CFLAGS $1"
80 CPPFLAGS="$CPPFLAGS $2"
81 LDFLAGS="$LDFLAGS $3"
82 ])
83
84 dnl UL_RESTORE_FLAGS()
85 dnl
86 dnl Restores CFLAGS, CPPFLAGS and LDFLAG previously saved by UL_SET_FLAGS()
87 dnl
88 AC_DEFUN([UL_RESTORE_FLAGS], [
89 CFLAGS="$old_CFLAGS"
90 CPPFLAGS="$old_CPPFLAGS"
91 LDFLAGS="$old_LDFLAGS"
92 ])
93
94
95 dnl UL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
96 dnl
97 dnl Only specify FALLBACK if the SYSCALL you're checking for is a "newish" one
98 dnl
99 AC_DEFUN([UL_CHECK_SYSCALL], [
100 dnl This macro uses host_cpu.
101 AC_REQUIRE([AC_CANONICAL_HOST])
102 AC_CACHE_CHECK([for syscall $1],
103 [ul_cv_syscall_$1],
104 [_UL_SYSCALL_CHECK_DECL([SYS_$1],
105 [syscall=SYS_$1],
106 [dnl Our libc failed use, so see if we can get the kernel
107 dnl headers to play ball ...
108 _UL_SYSCALL_CHECK_DECL([__NR_$1],
109 [syscall=__NR_$1],
110 [
111 syscall=no
112 if test "x$linux_os" = xyes; then
113 case $host_cpu in
114 _UL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
115 esac
116 fi
117 ])
118 ])
119 ul_cv_syscall_$1=$syscall
120 ])
121 case $ul_cv_syscall_$1 in #(
122 no) AC_MSG_WARN([Unable to detect syscall $1.]) ;;
123 SYS_*) ;;
124 *) AC_DEFINE_UNQUOTED([SYS_$1], [$ul_cv_syscall_$1],
125 [Fallback syscall number for $1]) ;;
126 esac
127 ])
128
129
130 dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
131 dnl
132 dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
133 dnl
134 m4_define([_UL_SYSCALL_CHECK_DECL],
135 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
136 #include <sys/syscall.h>
137 #include <unistd.h>
138 ]], [[int test = $1;]])],
139 [$2], [$3])
140 ])
141
142 dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
143 dnl
144 dnl Helper macro to create the body for the above `case'.
145 dnl
146 m4_define([_UL_CHECK_SYSCALL_FALLBACK],
147 [m4_ifval([$1],
148 [#(
149 $1) syscall="$2" ;;dnl
150 _UL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
151 ])
152
153
154 dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1])
155 dnl
156 dnl Modifies $build_<name> variable according to $enable_<name> and OS type. The
157 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
158 dnl all checks are skipped.
159 dnl
160 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
161 dnl
162 AC_DEFUN([UL_REQUIRES_LINUX], [
163 m4_define([suffix], m4_default([$2],$1))
164 if test "x$[build_]suffix" != xno; then
165 AC_REQUIRE([AC_CANONICAL_HOST])
166 case $[enable_]suffix:$linux_os in #(
167 no:*)
168 [build_]suffix=no ;;
169 yes:yes)
170 [build_]suffix=yes ;;
171 yes:*)
172 AC_MSG_ERROR([$1 selected for non-linux system]);;
173 check:yes)
174 [build_]suffix=yes ;;
175 check:*)
176 AC_MSG_WARN([non-linux system; not building $1])
177 [build_]suffix=no ;;
178 esac
179 fi
180 ])
181
182
183 dnl UL_EXCLUDE_ARCH(NAME, ARCH, [VARSUFFIX = $1])
184 dnl
185 dnl Modifies $build_<name> variable according to $enable_<name> and $host. The
186 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
187 dnl all checks are skipped.
188 dnl
189 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
190 dnl
191 AC_DEFUN([UL_EXCLUDE_ARCH], [
192 m4_define([suffix], m4_default([$3],$1))
193 if test "x$[build_]suffix" != xno; then
194 AC_REQUIRE([AC_CANONICAL_HOST])
195 case $[enable_]suffix:"$host" in #(
196 no:*)
197 [build_]suffix=no ;;
198 yes:$2)
199 AC_MSG_ERROR([$1 selected for unsupported architecture]);;
200 yes:*)
201 [build_]suffix=yes ;;
202 check:$2)
203 AC_MSG_WARN([excluded for $host architecture; not building $1])
204 [build_]suffix=no ;;
205 check:*)
206 [build_]suffix=yes ;;
207 esac
208 fi
209 ])
210
211
212
213 dnl UL_REQUIRES_ARCH(NAME, ARCH, [VARSUFFIX = $1])
214 dnl
215 dnl Modifies $build_<name> variable according to $enable_<name> and $host. The
216 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
217 dnl all checks are skipped.
218 dnl
219 dnl The <arch> maybe a list, then at least one of the patterns in the list
220 dnl have to match.
221 dnl
222 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
223 dnl
224 AC_DEFUN([UL_REQUIRES_ARCH], [
225 m4_define([suffix], m4_default([$3],$1))
226 if test "x$[build_]suffix" != xno; then
227 AC_REQUIRE([AC_CANONICAL_HOST])
228 [ul_archone_]suffix=no
229 m4_foreach([onearch], [$2], [
230 case "$host" in #(
231 onearch)
232 [ul_archone_]suffix=yes ;;
233 esac
234 ])dnl
235 case $[enable_]suffix:$[ul_archone_]suffix in #(
236 no:*)
237 [build_]suffix=no ;;
238 yes:no)
239 AC_MSG_ERROR([$1 selected for unsupported architecture]);;
240 yes:*)
241 [build_]suffix=yes ;;
242 check:no)
243 AC_MSG_WARN([excluded for $host architecture; not building $1])
244 [build_]suffix=no ;;
245 check:*)
246 [build_]suffix=yes ;;
247 esac
248 fi
249 ])
250
251 dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC, [VARSUFFIX=$1])
252 dnl
253 dnl Modifies $build_<name> variable according to $enable_<name> and
254 dnl $have_<havename>. The <havedesc> is description used for warning/error
255 dnl message (e.g. "function").
256 dnl
257 dnl The <havename> maybe a list, then at least one of the items in the list
258 dnl have to exist, for example: [ncurses, tinfo] means that have_ncurser=yes
259 dnl *or* have_tinfo=yes must be defined.
260 dnl
261 dnl The default <name> for $build_ and $enable_ could be overwrited by option $4.
262 dnl
263 AC_DEFUN([UL_REQUIRES_HAVE], [
264 m4_define([suffix], m4_default([$4],$1))
265
266 if test "x$[build_]suffix" != xno; then
267
268 [ul_haveone_]suffix=no
269 m4_foreach([onehave], [$2], [
270 if test "x$[have_]onehave" = xyes; then
271 [ul_haveone_]suffix=yes
272 fi
273 ])dnl
274
275 case $[enable_]suffix:$[ul_haveone_]suffix in #(
276 no:*)
277 [build_]suffix=no ;;
278 yes:yes)
279 [build_]suffix=yes ;;
280 yes:*)
281 AC_MSG_ERROR([$1 selected, but required $3 not available]);;
282 check:yes)
283 [build_]suffix=yes ;;
284 check:*)
285 AC_MSG_WARN([$3 not found; not building $1])
286 [build_]suffix=no ;;
287 esac
288 fi
289 ])
290
291 dnl UL_REQUIRES_COMPILE(NAME, PROGRAM_PROLOGUE, PROGRAM_BODY, DESC, [VARSUFFIX=$1])
292 dnl
293 dnl Modifies $build_<name> variable according to $enable_<name> and
294 dnl ability compile AC_LANG_PROGRAM(<program_prologue>, <program_body>).
295 dnl
296 dnl The <desc> is description used for warning/error dnl message (e.g. "foo support").
297 dnl
298 dnl The default <name> for $build_ and $enable_ could be overwrited by option $5.
299
300 AC_DEFUN([UL_REQUIRES_COMPILE], [
301 m4_define([suffix], m4_default([$5],$1))
302
303 if test "x$[build_]suffix" != xno; then
304
305 AC_MSG_CHECKING([$4])
306 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
307 [AC_MSG_RESULT([yes])
308 [ul_haveprogram_]suffix=yes],
309 [AC_MSG_RESULT([no])
310 [ul_haveprogram_]suffix=no])
311
312 case $[enable_]suffix:$[ul_haveprogram_]suffix in #(
313 no:*)
314 [build_]suffix=no ;;
315 yes:yes)
316 [build_]suffix=yes ;;
317 yes:*)
318 AC_MSG_ERROR([$1 selected, but required $4 not available]);;
319 check:yes)
320 [build_]suffix=yes ;;
321 check:*)
322 AC_MSG_WARN([$4 not found; not building $1])
323 [build_]suffix=no ;;
324 esac
325 fi
326 ])
327
328 dnl
329 dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC, [VARSUFFIX=$1])
330 dnl
331 dnl - ends with error if $enable_<name> and $build_<another>
332 dnl are both set to 'yes'
333 dnl - sets $build_<name> to 'no' if $build_<another> is 'yes' and
334 dnl $enable_<name> is 'check' or 'no'
335 dnl
336 dnl The <havedesc> is description used for warning/error
337 dnl message (e.g. "function").
338 dnl
339 dnl The default <name> for $build_ and $enable_ could be overwrited by option $4.
340 dnl
341 AC_DEFUN([UL_CONFLICTS_BUILD], [
342 m4_define([suffix], m4_default([$4],$1))
343
344 if test "x$[build_]suffix" != xno; then
345 case $[enable_]suffix:$[build_]$2 in #(
346 no:*)
347 [build_]suffix=no ;;
348 check:yes)
349 [build_]suffix=no ;;
350 check:no)
351 [build_]suffix=yes ;;
352 yes:yes)
353 AC_MSG_ERROR([$1 selected, but it conflicts with $3]);;
354 esac
355 fi
356 ])
357
358
359 dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1])
360 dnl
361 dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname.
362 dnl
363 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
364 dnl
365 AC_DEFUN([UL_REQUIRES_BUILD], [
366 m4_define([suffix], m4_default([$3],$1))
367
368 if test "x$[build_]suffix" != xno; then
369 case $[enable_]suffix:$[build_]$2 in #(
370 no:*)
371 [build_]suffix=no ;;
372 yes:yes)
373 [build_]suffix=yes ;;
374 yes:*)
375 AC_MSG_ERROR([$2 is needed to build $1]);;
376 check:yes)
377 [build_]suffix=yes ;;
378 check:*)
379 AC_MSG_WARN([$2 disabled; not building $1])
380 [build_]suffix=no ;;
381 esac
382 fi
383 ])
384
385 dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1])
386 dnl
387 dnl Modifies $build_<name> variable according to $enable_<name> and SYSCALL-TEST
388 dnl result. The $enable_<name> variable could be "yes", "no" and "check". If build_<name>
389 dnl is "no" then all checks are skipped.
390 dnl
391 dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see
392 dnl also UL_CHECK_SYSCALL().
393 dnl
394 dnl The default <name> for $build_ and $enable_ count be overwrited by option $4 and
395 dnl $ul_cv_syscall_ could be overwrited by $3.
396 dnl
397 AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
398 m4_define([suffix], m4_default([$4],$1))
399 m4_define([callname], m4_default([$3],$1))
400
401 if test "x$[build_]suffix" != xno; then
402 if test "x$[enable_]suffix" = xno; then
403 [build_]suffix=no
404 else
405 $2
406 case $[enable_]suffix:$[ul_cv_syscall_]callname in #(
407 no:*)
408 [build_]suffix=no ;;
409 yes:no)
410 AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
411 check:no)
412 AC_MSG_WARN([callname syscall not found; not building $1])
413 [build_]suffix=no ;;
414 *)
415 dnl default $ul_cv_syscall_ is SYS_ value
416 [build_]suffix=yes ;;
417 esac
418 fi
419 fi
420 ])
421
422 dnl UL_BUILD_INIT(NAME, [ENABLE_STATE], [VARSUFFIX = $1])
423 dnl
424 dnl Initializes $build_<name> variable according to $enable_<name>. If
425 dnl $enable_<name> is undefined then ENABLE_STATE is used and $enable_<name> is
426 dnl set to ENABLE_STATE.
427 dnl
428 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
429 dnl
430 AC_DEFUN([UL_BUILD_INIT], [
431 m4_define([suffix], m4_default([$3],$1))
432 m4_ifblank([$2],
433 [if test "x$enable_[]suffix" = xno; then
434 build_[]suffix=no
435 else
436 build_[]suffix=yes
437 fi],
438 [if test "x$ul_default_estate" != x; then
439 enable_[]suffix=$ul_default_estate
440 build_[]suffix=yes
441 if test "x$ul_default_estate" = xno; then
442 build_[]suffix=no
443 fi
444 else[]
445 ifelse(
446 [$2], [check],[
447 build_[]suffix=yes
448 enable_[]suffix=check],
449 [$2], [yes],[
450 build_[]suffix=yes
451 enable_[]suffix=yes],
452 [$2], [no], [
453 build_[]suffix=no
454 enable_[]suffix=no])
455 fi])
456 ])
457
458 dnl UL_DEFAULT_ENABLE(NAME, ENABLE_STATE)
459 dnl
460 dnl Initializes $enable_<name> variable according to ENABLE_STATE. The default
461 dnl setting is possible to override by global $ul_default_estate.
462 dnl
463 AC_DEFUN([UL_DEFAULT_ENABLE], [
464 m4_define([suffix], $1)
465 if test "x$ul_default_estate" != x; then
466 enable_[]suffix=$ul_default_estate
467 else
468 enable_[]suffix=$2
469 fi
470 ])
471
472
473 dnl UL_ENABLE_ALIAS(NAME, MASTERNAME)
474 dnl
475 dnl Initializes $enable_<name> variable according to $enable_<mastername>. This
476 dnl is useful for example if you want to use one --enable-mastername option
477 dnl for group of programs.
478 dnl
479 AC_DEFUN([UL_ENABLE_ALIAS], [
480 m4_define([suffix], $1)
481 m4_define([mastersuffix], $2)
482
483 enable_[]suffix=$enable_[]mastersuffix
484 ])
485
486
487 dnl UL_NCURSES_CHECK(NAME)
488 dnl
489 dnl Initializes $have_<name>, NCURSES_LIBS and NCURSES_CFLAGS variables according to
490 dnl <name>{6,5}_config output.
491 dnl
492 dnl The expected <name> is ncurses or ncursesw.
493 dnl
494 AC_DEFUN([UL_NCURSES_CHECK], [
495 m4_define([suffix], $1)
496 m4_define([SUFFIX], m4_toupper($1))
497
498 # ncurses6-config
499 #
500 AS_IF([test "x$have_[]suffix" = xno], [
501 AC_CHECK_TOOL(SUFFIX[]6_CONFIG, suffix[]6-config)
502 if AC_RUN_LOG([$SUFFIX[]6_CONFIG --version >/dev/null]); then
503 have_[]suffix=yes
504 NCURSES_LIBS=`$SUFFIX[]6_CONFIG --libs`
505 NCURSES_CFLAGS=`$SUFFIX[]6_CONFIG --cflags`
506 else
507 have_[]suffix=no
508 fi
509 ])
510
511 # ncurses5-config
512 #
513 AS_IF([test "x$have_[]suffix" = xno], [
514 AC_CHECK_TOOL(SUFFIX[]5_CONFIG, suffix[]5-config)
515 if AC_RUN_LOG([$SUFFIX[]5_CONFIG --version >/dev/null]); then
516 have_[]suffix=yes
517 NCURSES_LIBS=`$SUFFIX[]5_CONFIG --libs`
518 NCURSES_CFLAGS=`$SUFFIX[]5_CONFIG --cflags`
519 else
520 have_[]suffix=no
521 fi
522 ])
523
524 # pkg-config (not supported by ncurses upstream by default)
525 #
526 AS_IF([test "x$have_[]suffix" = xno], [
527 PKG_CHECK_MODULES(SUFFIX, [$1], [
528 have_[]suffix=yes
529 NCURSES_LIBS=${SUFFIX[]_LIBS}
530 NCURSES_CFLAGS=${SUFFIX[]_CFLAGS}
531 ],[have_[]suffix=no])
532 ])
533
534 # classic autoconf way
535 #
536 AS_IF([test "x$have_[]suffix" = xno], [
537 AC_CHECK_LIB([$1], [initscr], [have_[]suffix=yes], [have_[]suffix=no])
538 AS_IF([test "x$have_[]suffix" = xyes], [NCURSES_LIBS="-l[]suffix"])
539 ])
540 ])
541
542 dnl
543 dnl UL_TINFO_CHECK(NAME)
544 dnl
545 dnl Initializes $have_<name>, TINFO_LIBS and TINFO_CFLAGS variables.
546 dnl
547 dnl The expected <name> is tinfow or tinfo.
548 dnl
549 AC_DEFUN([UL_TINFO_CHECK], [
550 m4_define([suffix], $1)
551 m4_define([SUFFIX], m4_toupper($1))
552
553 PKG_CHECK_MODULES(SUFFIX, [$1], [
554 dnl pkg-config success
555 have_[]suffix=yes
556 TINFO_LIBS=${SUFFIX[]_LIBS}
557 TINFO_CFLAGS=${SUFFIX[]_CFLAGS}
558 UL_PKG_STATIC([TINFO_LIBS_STATIC], [$1])
559 ],[
560 dnl If pkg-config failed, fall back to classic searching.
561 AC_CHECK_LIB([$1], [tgetent], [
562 have_[]suffix=yes
563 TINFO_LIBS="-l[]suffix"
564 TINFO_LIBS_STATIC="-l[]suffix"
565 TINFO_CFLAGS=""])
566 ])
567 ])