]> git.ipfire.org Git - thirdparty/util-linux.git/blame - m4/ul.m4
build-sys: allow autoconf < 2.64 to be used
[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], [
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
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 ])
121 AM_CONDITIONAL([HAVE_]m4_toupper($1), [test "x$ul_cv_syscall_$1" != xno])
122 case $ul_cv_syscall_$1 in #(
123 no) AC_MSG_WARN([Unable to detect syscall $1.]) ;;
124 SYS_*) ;;
125 *) AC_DEFINE_UNQUOTED([SYS_$1], [$ul_cv_syscall_$1],
126 [Fallback syscall number for $1]) ;;
127 esac
128])
129
130
131dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
132dnl
133dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
134dnl
135m4_define([_UL_SYSCALL_CHECK_DECL],
136[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
137#include <sys/syscall.h>
138#include <unistd.h>
139]], [[int test = $1;]])],
140[$2], [$3])
141])
142
143dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
144dnl
145dnl Helper macro to create the body for the above `case'.
146dnl
147m4_define([_UL_CHECK_SYSCALL_FALLBACK],
148[m4_ifval([$1],
149 [#(
150 $1) syscall="$2" ;;dnl
151 _UL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
152])
b17e8206
KZ
153
154
155dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1])
156dnl
157dnl Modifies $build_<name> variable according to $enable_<name> and OS type. The
158dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
159dnl all checks are skiped.
160dnl
161dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
162dnl
163AC_DEFUN([UL_REQUIRES_LINUX], [
b17e8206 164 m4_define([suffix], m4_default([$2],$1))
61a074f7
KZ
165 if test "x$[build_]suffix" != xno; then
166 AC_REQUIRE([AC_CANONICAL_HOST])
b17e8206
KZ
167 case $[enable_]suffix:$linux_os in #(
168 no:*)
169 [build_]suffix=no ;;
170 yes:yes)
171 [build_]suffix=yes ;;
172 yes:*)
173 AC_MSG_ERROR([$1 selected for non-linux system]);;
174 check:yes)
175 [build_]suffix=yes ;;
176 check:*)
bdef457d 177 AC_MSG_WARN([non-linux system; not building $1])
b17e8206
KZ
178 [build_]suffix=no ;;
179 esac
180 fi
181])
182
62b2c024
KZ
183
184dnl UL_EXCLUDE_ARCH(NAME, ARCH, VARSUFFIX = $1])
185dnl
186dnl Modifies $build_<name> variable according to $enable_<name> and $host. The
187dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
188dnl all checks are skiped.
189dnl
190dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
191dnl
192AC_DEFUN([UL_EXCLUDE_ARCH], [
193 m4_define([suffix], m4_default([$3],$1))
194 if test "x$[build_]suffix" != xno; then
195 AC_REQUIRE([AC_CANONICAL_HOST])
196 case $[enable_]suffix:"$host" in #(
197 no:*)
198 [build_]suffix=no ;;
199 yes:$2)
200 AC_MSG_ERROR([$1 selected for unsupported architecture]);;
201 yes:*)
202 [build_]suffix=yes ;;
203 check:$2)
bdef457d 204 AC_MSG_WARN([excluded for $host architecture; not building $1])
62b2c024
KZ
205 [build_]suffix=no ;;
206 check:*)
207 [build_]suffix=yes ;;
208 esac
209 fi
210])
211
b17e8206
KZ
212dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC [VARSUFFIX=$1])
213dnl
214dnl Modifies $build_<name> variable according to $enable_<name> and
215dnl $have_<havename>. The <havedesc> is description used ifor warning/error
216dnl message (e.g. "function").
217dnl
91626822
KZ
218dnl The <havename> maybe a list, then at least one of the items in the list
219dnl have to exist, for example: [ncurses, tinfo] means that have_ncurser=yes
220dnl *or* have_tinfo=yes must be defined.
221dnl
b17e8206
KZ
222dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
223dnl
224AC_DEFUN([UL_REQUIRES_HAVE], [
225 m4_define([suffix], m4_default([$4],$1))
226
61a074f7 227 if test "x$[build_]suffix" != xno; then
91626822 228
e1b8ba20 229 [ul_haveone_]suffix=no
91626822
KZ
230 m4_foreach([onehave], [$2], [
231 if test "x$[have_]onehave" = xyes; then
232 [ul_haveone_]suffix=yes
233 fi
234 ])dnl
235
236 case $[enable_]suffix:$[ul_haveone_]suffix in #(
b17e8206
KZ
237 no:*)
238 [build_]suffix=no ;;
239 yes:yes)
240 [build_]suffix=yes ;;
241 yes:*)
242 AC_MSG_ERROR([$1 selected, but required $3 not available]);;
243 check:yes)
244 [build_]suffix=yes ;;
245 check:*)
bdef457d 246 AC_MSG_WARN([$3 not found; not building $1])
b17e8206
KZ
247 [build_]suffix=no ;;
248 esac
249 fi
250])
251
a9e48470
KZ
252
253dnl
254dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC [VARSUFFIX=$1])
255dnl
256dnl - ends with error if $enable_<name> and $build_<another>
257dnl are both set to 'yes'
258dnl - sets $build_<name> to 'no' if $build_<another> is 'yes' and
259dnl $enable_<name> is 'check' or 'no'
260dnl
261dnl The <havedesc> is description used for warning/error
262dnl message (e.g. "function").
263dnl
264dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
265dnl
266AC_DEFUN([UL_CONFLICTS_BUILD], [
267 m4_define([suffix], m4_default([$4],$1))
268
269 if test "x$[build_]suffix" != xno; then
270 case $[enable_]suffix:$[build_]$2 in #(
271 no:*)
272 [build_]suffix=no ;;
273 check:yes)
274 [build_]suffix=no ;;
ad869f9e
KZ
275 check:no)
276 [build_]suffix=yes ;;
a9e48470
KZ
277 yes:yes)
278 AC_MSG_ERROR([$1 selected, but it conflicts with $3]);;
279 esac
280 fi
281])
282
283
b17e8206
KZ
284dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1])
285dnl
286dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname.
287dnl
288dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
289dnl
290AC_DEFUN([UL_REQUIRES_BUILD], [
291 m4_define([suffix], m4_default([$3],$1))
292
61a074f7 293 if test "x$[build_]suffix" != xno; then
b17e8206
KZ
294 case $[enable_]suffix:$[build_]$2 in #(
295 no:*)
296 [build_]suffix=no ;;
297 yes:yes)
298 [build_]suffix=yes ;;
299 yes:*)
300 AC_MSG_ERROR([$2 is needed to build $1]);;
301 check:yes)
302 [build_]suffix=yes ;;
303 check:*)
bdef457d 304 AC_MSG_WARN([$2 disabled; not building $1])
b17e8206
KZ
305 [build_]suffix=no ;;
306 esac
307 fi
308])
309
310dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1])
311dnl
312dnl Modifies $build_<name> variable according to $enable_<name> and SYSCALL-TEST
313dnl result. The $enable_<name> variable could be "yes", "no" and "check". If build_<name>
314dnl is "no" then all checks are skiped.
315dnl
316dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see
317dnl also UL_CHECK_SYSCALL().
318dnl
319dnl The default <name> for $build_ and $enable_ count be overwrited by option $4 and
320dnl $ul_cv_syscall_ could be overwrited by $3.
321dnl
322AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
323 m4_define([suffix], m4_default([$4],$1))
324 m4_define([callname], m4_default([$3],$1))
325
326 dnl This is default, $3 will redefine the condition
327 dnl
328 dnl TODO: remove this junk, AM_CONDITIONAL should not be used for any HAVE_*
329 dnl variables, all we need is BUILD_* only.
330 dnl
331 AM_CONDITIONAL([HAVE_]m4_toupper(callname), [false])
332
61a074f7 333 if test "x$[build_]suffix" != xno; then
b17e8206
KZ
334 if test "x$[enable_]suffix" = xno; then
335 [build_]suffix=no
336 else
337 $2
338 case $[enable_]suffix:$[ul_cv_syscall_]callname in #(
339 no:*)
340 [build_]suffix=no ;;
341 yes:no)
342 AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
343 check:no)
bdef457d 344 AC_MSG_WARN([callname syscall not found; not building $1])
b17e8206
KZ
345 [build_]suffix=no ;;
346 *)
347 dnl default $ul_cv_syscall_ is SYS_ value
348 [build_]suffix=yes ;;
349 esac
350 fi
351 fi
352])
61a074f7 353
3d9fdac5 354dnl UL_BUILD_INIT(NAME, [ENABLE_STATE], [VARSUFFIX = $1])
61a074f7
KZ
355dnl
356dnl Initializes $build_<name> variable according to $enable_<name>. If
357dnl $enable_<name> is undefined then ENABLE_STATE is used and $enable_<name> is
358dnl set to ENABLE_STATE.
359dnl
360dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
361dnl
362AC_DEFUN([UL_BUILD_INIT], [
363 m4_define([suffix], m4_default([$3],$1))
50d096ac 364 m4_ifblank([$2],
b248c9d4
KZ
365[if test "x$enable_[]suffix" = xno; then
366 build_[]suffix=no
367else
368 build_[]suffix=yes
369fi],
370[if test "x$ul_default_estate" != x; then
50d096ac 371 enable_[]suffix=$ul_default_estate
1ad36b52 372 build_[]suffix=yes
56ce2d58
KZ
373 if test "x$ul_default_estate" = xno; then
374 build_[]suffix=no
375 fi
50d096ac
KZ
376else[]
377 ifelse(
378 [$2], [check],[
b248c9d4
KZ
379 build_[]suffix=yes
380 enable_[]suffix=check],
50d096ac 381 [$2], [yes],[
b248c9d4
KZ
382 build_[]suffix=yes
383 enable_[]suffix=yes],
50d096ac 384 [$2], [no], [
b248c9d4
KZ
385 build_[]suffix=no
386 enable_[]suffix=no])
50d096ac
KZ
387fi])
388])
61a074f7 389
50d096ac
KZ
390dnl UL_DEFAULT_ENABLE(NAME, ENABLE_STATE)
391dnl
392dnl Initializes $enable_<name> variable according to ENABLE_STATE. The default
393dnl setting is possible to override by global $ul_default_estate.
394dnl
395AC_DEFUN([UL_DEFAULT_ENABLE], [
396 m4_define([suffix], $1)
397 if test "x$ul_default_estate" != x; then
398 enable_[]suffix=$ul_default_estate
399 else
400 enable_[]suffix=$2
401 fi
61a074f7 402])