]> git.ipfire.org Git - thirdparty/util-linux.git/blame - m4/ul.m4
su: change error message
[thirdparty/util-linux.git] / m4 / ul.m4
CommitLineData
a8afc8c6
KK
1dnl If needed, define the m4_ifblank and m4_ifnblank macros from autoconf 2.64
2dnl This allows us to run with earlier Autoconfs as well.
3dnl
4dnl m4_ifblank(COND, [IF-BLANK], [IF-TEXT])
5dnl m4_ifnblank(COND, [IF-TEXT], [IF-BLANK])
6dnl ----------------------------------------
7dnl If COND is empty, or consists only of blanks (space, tab, newline),
8dnl then expand IF-BLANK, otherwise expand IF-TEXT. This differs from
9dnl m4_ifval only if COND has just whitespace, but it helps optimize in
10dnl spite of users who mistakenly leave trailing space after what they
11dnl thought was an empty argument:
12dnl macro(
13dnl []
14dnl )
15dnl
16dnl Writing one macro in terms of the other causes extra overhead, so
17dnl we inline both definitions.
18ifdef([m4_ifblank],[],[
19m4_define([m4_ifblank],
20[m4_if(m4_translit([[$1]], [ ][ ][
21]), [], [$2], [$3])])])
22
23ifdef([m4_ifnblank],[],[
24m4_define([m4_ifnblank],
25[m4_if(m4_translit([[$1]], [ ][ ][
26]), [], [$3], [$2])])])
132ea941
KZ
27
28dnl UL_PKG_STATIC(VARIABLE, MODULES)
29dnl
30dnl Calls pkg-config --static
31dnl
32AC_DEFUN([UL_PKG_STATIC], [
f776d76e
KZ
33 if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
34 $1=`$PKG_CONFIG --libs --static "$2"`
132ea941
KZ
35 else
36 AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
37 fi
38])
39
40dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1]))
41dnl
ee312c65 42dnl The VARSUFFIX is optional and overrides the default behavior. For example:
132ea941
KZ
43dnl UL_CHECK_LIB(yyy, func, xxx) generates have_xxx and HAVE_LIBXXX
44dnl UL_CHECK_LIB(yyy, func) generates have_yyy and HAVE_LIBYYY
45dnl
46AC_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
56dnl UL_SET_ARCH(ARCHNAME, PATTERN)
57dnl
58dnl Define ARCH_<archname> condition if the pattern match with the current
59dnl architecture
60dnl
61AC_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
70dnl UL_SET_FLAGS(CFLAGS, CPPFLAGS, LDFLAGS)
71dnl
72dnl Sets new global CFLAGS, CPPFLAGS and LDFLAG, the original
73dnl setting could be restored by UL_RESTORE_FLAGS()
74dnl
75AC_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
84dnl UL_RESTORE_FLAGS()
85dnl
86dnl Restores CFLAGS, CPPFLAGS and LDFLAG previously saved by UL_SET_FLAGS()
87dnl
88AC_DEFUN([UL_RESTORE_FLAGS], [
89 CFLAGS="$old_CFLAGS"
90 CPPFLAGS="$old_CPPFLAGS"
91 LDFLAGS="$old_LDFLAGS"
92])
93
94
95dnl UL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
96dnl
97dnl Only specify FALLBACK if the SYSCALL you're checking for is a "newish" one
98dnl
99AC_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 ])
132ea941
KZ
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
130dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
131dnl
132dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
133dnl
134m4_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
142dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
143dnl
144dnl Helper macro to create the body for the above `case'.
145dnl
146m4_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])
b17e8206
KZ
152
153
154dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1])
155dnl
156dnl Modifies $build_<name> variable according to $enable_<name> and OS type. The
157dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
158dnl all checks are skiped.
159dnl
160dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
161dnl
162AC_DEFUN([UL_REQUIRES_LINUX], [
b17e8206 163 m4_define([suffix], m4_default([$2],$1))
61a074f7
KZ
164 if test "x$[build_]suffix" != xno; then
165 AC_REQUIRE([AC_CANONICAL_HOST])
b17e8206
KZ
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:*)
bdef457d 176 AC_MSG_WARN([non-linux system; not building $1])
b17e8206
KZ
177 [build_]suffix=no ;;
178 esac
179 fi
180])
181
62b2c024 182
cce05a2a 183dnl UL_EXCLUDE_ARCH(NAME, ARCH, [VARSUFFIX = $1])
62b2c024
KZ
184dnl
185dnl Modifies $build_<name> variable according to $enable_<name> and $host. The
186dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
187dnl all checks are skiped.
188dnl
189dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
190dnl
191AC_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)
bdef457d 203 AC_MSG_WARN([excluded for $host architecture; not building $1])
62b2c024
KZ
204 [build_]suffix=no ;;
205 check:*)
206 [build_]suffix=yes ;;
207 esac
208 fi
209])
210
cce05a2a 211dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC, [VARSUFFIX=$1])
b17e8206
KZ
212dnl
213dnl Modifies $build_<name> variable according to $enable_<name> and
cce05a2a 214dnl $have_<havename>. The <havedesc> is description used for warning/error
b17e8206
KZ
215dnl message (e.g. "function").
216dnl
91626822
KZ
217dnl The <havename> maybe a list, then at least one of the items in the list
218dnl have to exist, for example: [ncurses, tinfo] means that have_ncurser=yes
219dnl *or* have_tinfo=yes must be defined.
220dnl
cce05a2a 221dnl The default <name> for $build_ and $enable_ could be overwrited by option $4.
b17e8206
KZ
222dnl
223AC_DEFUN([UL_REQUIRES_HAVE], [
224 m4_define([suffix], m4_default([$4],$1))
225
61a074f7 226 if test "x$[build_]suffix" != xno; then
91626822 227
e1b8ba20 228 [ul_haveone_]suffix=no
91626822
KZ
229 m4_foreach([onehave], [$2], [
230 if test "x$[have_]onehave" = xyes; then
231 [ul_haveone_]suffix=yes
232 fi
233 ])dnl
234
235 case $[enable_]suffix:$[ul_haveone_]suffix in #(
b17e8206
KZ
236 no:*)
237 [build_]suffix=no ;;
238 yes:yes)
239 [build_]suffix=yes ;;
240 yes:*)
241 AC_MSG_ERROR([$1 selected, but required $3 not available]);;
242 check:yes)
243 [build_]suffix=yes ;;
244 check:*)
bdef457d 245 AC_MSG_WARN([$3 not found; not building $1])
b17e8206
KZ
246 [build_]suffix=no ;;
247 esac
248 fi
249])
250
2bd0b84f
KZ
251dnl UL_REQUIRES_HAVE(NAME, PROGRAM_PROLOGUE, PROGRAM_BODY, DESC, [VARSUFFIX=$1])
252dnl
253dnl Modifies $build_<name> variable according to $enable_<name> and
254dnl ability compile AC_LANG_PROGRAM(<program_prologue>, <program_body>).
255dnl
256dnl The <desc> is description used for warning/error dnl message (e.g. "foo support").
257dnl
258dnl The default <name> for $build_ and $enable_ could be overwrited by option $5.
259
260AC_DEFUN([UL_REQUIRES_COMPILE], [
261 m4_define([suffix], m4_default([$5],$1))
262
263 if test "x$[build_]suffix" != xno; then
264
265 AC_MSG_CHECKING([$4])
266 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
267 [AC_MSG_RESULT([yes])
268 [ul_haveprogram_]suffix=yes],
269 [AC_MSG_RESULT([no])
270 [ul_haveprogram_]suffix=no])
271
272 case $[enable_]suffix:$[ul_haveprogram_]suffix in #(
273 no:*)
274 [build_]suffix=no ;;
275 yes:yes)
276 [build_]suffix=yes ;;
277 yes:*)
278 AC_MSG_ERROR([$1 selected, but required $4 not available]);;
279 check:yes)
280 [build_]suffix=yes ;;
281 check:*)
282 AC_MSG_WARN([$4 not found; not building $1])
283 [build_]suffix=no ;;
284 esac
285 fi
286])
287
a9e48470 288dnl
cce05a2a 289dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC, [VARSUFFIX=$1])
a9e48470
KZ
290dnl
291dnl - ends with error if $enable_<name> and $build_<another>
292dnl are both set to 'yes'
293dnl - sets $build_<name> to 'no' if $build_<another> is 'yes' and
294dnl $enable_<name> is 'check' or 'no'
295dnl
296dnl The <havedesc> is description used for warning/error
297dnl message (e.g. "function").
298dnl
cce05a2a 299dnl The default <name> for $build_ and $enable_ could be overwrited by option $4.
a9e48470
KZ
300dnl
301AC_DEFUN([UL_CONFLICTS_BUILD], [
302 m4_define([suffix], m4_default([$4],$1))
303
304 if test "x$[build_]suffix" != xno; then
305 case $[enable_]suffix:$[build_]$2 in #(
306 no:*)
307 [build_]suffix=no ;;
308 check:yes)
309 [build_]suffix=no ;;
ad869f9e
KZ
310 check:no)
311 [build_]suffix=yes ;;
a9e48470
KZ
312 yes:yes)
313 AC_MSG_ERROR([$1 selected, but it conflicts with $3]);;
314 esac
315 fi
316])
317
318
b17e8206
KZ
319dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1])
320dnl
321dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname.
322dnl
323dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
324dnl
325AC_DEFUN([UL_REQUIRES_BUILD], [
326 m4_define([suffix], m4_default([$3],$1))
327
61a074f7 328 if test "x$[build_]suffix" != xno; then
b17e8206
KZ
329 case $[enable_]suffix:$[build_]$2 in #(
330 no:*)
331 [build_]suffix=no ;;
332 yes:yes)
333 [build_]suffix=yes ;;
334 yes:*)
335 AC_MSG_ERROR([$2 is needed to build $1]);;
336 check:yes)
337 [build_]suffix=yes ;;
338 check:*)
bdef457d 339 AC_MSG_WARN([$2 disabled; not building $1])
b17e8206
KZ
340 [build_]suffix=no ;;
341 esac
342 fi
343])
344
345dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1])
346dnl
347dnl Modifies $build_<name> variable according to $enable_<name> and SYSCALL-TEST
348dnl result. The $enable_<name> variable could be "yes", "no" and "check". If build_<name>
349dnl is "no" then all checks are skiped.
350dnl
351dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see
352dnl also UL_CHECK_SYSCALL().
353dnl
354dnl The default <name> for $build_ and $enable_ count be overwrited by option $4 and
355dnl $ul_cv_syscall_ could be overwrited by $3.
356dnl
357AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
358 m4_define([suffix], m4_default([$4],$1))
359 m4_define([callname], m4_default([$3],$1))
360
61a074f7 361 if test "x$[build_]suffix" != xno; then
b17e8206
KZ
362 if test "x$[enable_]suffix" = xno; then
363 [build_]suffix=no
364 else
365 $2
366 case $[enable_]suffix:$[ul_cv_syscall_]callname in #(
367 no:*)
368 [build_]suffix=no ;;
369 yes:no)
370 AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
371 check:no)
bdef457d 372 AC_MSG_WARN([callname syscall not found; not building $1])
b17e8206
KZ
373 [build_]suffix=no ;;
374 *)
375 dnl default $ul_cv_syscall_ is SYS_ value
376 [build_]suffix=yes ;;
377 esac
378 fi
379 fi
380])
61a074f7 381
3d9fdac5 382dnl UL_BUILD_INIT(NAME, [ENABLE_STATE], [VARSUFFIX = $1])
61a074f7
KZ
383dnl
384dnl Initializes $build_<name> variable according to $enable_<name>. If
385dnl $enable_<name> is undefined then ENABLE_STATE is used and $enable_<name> is
386dnl set to ENABLE_STATE.
387dnl
cce05a2a 388dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
61a074f7
KZ
389dnl
390AC_DEFUN([UL_BUILD_INIT], [
391 m4_define([suffix], m4_default([$3],$1))
50d096ac 392 m4_ifblank([$2],
b248c9d4
KZ
393[if test "x$enable_[]suffix" = xno; then
394 build_[]suffix=no
395else
396 build_[]suffix=yes
397fi],
398[if test "x$ul_default_estate" != x; then
50d096ac 399 enable_[]suffix=$ul_default_estate
1ad36b52 400 build_[]suffix=yes
56ce2d58
KZ
401 if test "x$ul_default_estate" = xno; then
402 build_[]suffix=no
403 fi
50d096ac
KZ
404else[]
405 ifelse(
406 [$2], [check],[
b248c9d4
KZ
407 build_[]suffix=yes
408 enable_[]suffix=check],
50d096ac 409 [$2], [yes],[
b248c9d4
KZ
410 build_[]suffix=yes
411 enable_[]suffix=yes],
50d096ac 412 [$2], [no], [
b248c9d4
KZ
413 build_[]suffix=no
414 enable_[]suffix=no])
50d096ac
KZ
415fi])
416])
61a074f7 417
50d096ac
KZ
418dnl UL_DEFAULT_ENABLE(NAME, ENABLE_STATE)
419dnl
420dnl Initializes $enable_<name> variable according to ENABLE_STATE. The default
421dnl setting is possible to override by global $ul_default_estate.
422dnl
423AC_DEFUN([UL_DEFAULT_ENABLE], [
424 m4_define([suffix], $1)
425 if test "x$ul_default_estate" != x; then
426 enable_[]suffix=$ul_default_estate
427 else
428 enable_[]suffix=$2
429 fi
61a074f7 430])
e5cc93b5 431
6f2eb034
KZ
432
433dnl UL_ENABLE_ALIAS(NAME, MASTERNAME)
434dnl
fc72f51e 435dnl Initializes $enable_<name> variable according to $enable_<mastername>. This
73afd3f8 436dnl is useful for example if you want to use one --enable-mastername option
6f2eb034
KZ
437dnl for group of programs.
438dnl
439AC_DEFUN([UL_ENABLE_ALIAS], [
440 m4_define([suffix], $1)
441 m4_define([mastersuffix], $2)
442
fc72f51e 443 enable_[]suffix=$enable_[]mastersuffix
6f2eb034
KZ
444])
445
446
e5cc93b5
KZ
447dnl UL_NCURSES_CHECK(NAME)
448dnl
449dnl Initializes $have_<name>, NCURSES_LIBS and NCURSES_CFLAGS variables according to
450dnl <name>{6,5}_config output.
451dnl
452dnl The expected <name> is ncurses or ncursesw.
453dnl
454AC_DEFUN([UL_NCURSES_CHECK], [
455 m4_define([suffix], $1)
86232645 456 m4_define([SUFFIX], m4_toupper($1))
3f7429fd 457
86232645 458 # ncurses6-config
e5cc93b5 459 #
3f7429fd 460 AS_IF([test "x$have_[]suffix" = xno], [
86232645
KZ
461 AC_CHECK_TOOL(SUFFIX[]6_CONFIG, suffix[]6-config)
462 if AC_RUN_LOG([$SUFFIX[]6_CONFIG --version >/dev/null]); then
3f7429fd 463 have_[]suffix=yes
86232645
KZ
464 NCURSES_LIBS=`$SUFFIX[]6_CONFIG --libs`
465 NCURSES_CFLAGS=`$SUFFIX[]6_CONFIG --cflags`
466 else
467 have_[]suffix=no
468 fi
469 ])
470
471 # ncurses5-config
472 #
473 AS_IF([test "x$have_[]suffix" = xno], [
474 AC_CHECK_TOOL(SUFFIX[]5_CONFIG, suffix[]5-config)
475 if AC_RUN_LOG([$SUFFIX[]5_CONFIG --version >/dev/null]); then
3f7429fd 476 have_[]suffix=yes
86232645
KZ
477 NCURSES_LIBS=`$SUFFIX[]5_CONFIG --libs`
478 NCURSES_CFLAGS=`$SUFFIX[]5_CONFIG --cflags`
3f7429fd 479 else
86232645 480 have_[]suffix=no
3f7429fd
KZ
481 fi
482 ])
86232645 483
4c12a334
KZ
484 # pkg-config (not supported by ncurses upstream by default)
485 #
486 AS_IF([test "x$have_[]suffix" = xno], [
487 PKG_CHECK_MODULES(SUFFIX, [$1], [
488 have_[]suffix=yes
489 NCURSES_LIBS=${SUFFIX[]_LIBS}
490 NCURSES_CFLAGS=${SUFFIX[]_CFLAGS}
491 ],[have_[]suffix=no])
492 ])
493
86232645
KZ
494 # classic autoconf way
495 #
496 AS_IF([test "x$have_[]suffix" = xno], [
4c12a334
KZ
497 AC_CHECK_LIB([$1], [initscr], [have_[]suffix=yes], [have_[]suffix=no])
498 AS_IF([test "x$have_[]suffix" = xyes], [NCURSES_LIBS="-l[]suffix"])
86232645 499 ])
e5cc93b5 500])
ad442a81
KZ
501
502dnl
503dnl UL_TINFO_CHECK(NAME)
504dnl
505dnl Initializes $have_<name>, TINFO_LIBS and TINFO_CFLAGS variables.
506dnl
507dnl The expected <name> is tinfow or tinfo.
508dnl
509AC_DEFUN([UL_TINFO_CHECK], [
510 m4_define([suffix], $1)
511 m4_define([SUFFIX], m4_toupper($1))
512
513 PKG_CHECK_MODULES(SUFFIX, [$1], [
514 dnl pkg-config success
515 have_[]suffix=yes
516 TINFO_LIBS=${SUFFIX[]_LIBS}
517 TINFO_CFLAGS=${SUFFIX[]_CFLAGS}
518 UL_PKG_STATIC([TINFO_LIBS_STATIC], [$1])
519 ],[
520 dnl If pkg-config failed, fall back to classic searching.
521 AC_CHECK_LIB([$1], [tgetent], [
522 have_[]suffix=yes
523 TINFO_LIBS="-l[]suffix"
524 TINFO_LIBS_STATIC="-l[]suffix"
525 TINFO_CFLAGS=""])
526 ])
527])