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.
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:
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])])])
23 ifdef([m4_ifnblank],[],[
24 m4_define([m4_ifnblank],
25 [m4_if(m4_translit([[$1]], [ ][ ][
26 ]), [], [$3], [$2])])])
28 dnl UL_PKG_STATIC(VARIABLE, MODULES)
30 dnl Calls pkg-config --static
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"`
36 AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
40 dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1]))
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
46 AC_DEFUN([UL_CHECK_LIB], [
47 m4_define([suffix], m4_default([$3],$1))
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])
56 dnl UL_SET_ARCH(ARCHNAME, PATTERN)
58 dnl Define ARCH_<archname> condition if the pattern match with the current
61 AC_DEFUN([UL_SET_ARCH], [
66 AM_CONDITIONAL(AS_TR_CPP(ARCH_$1), [test "x$cpu_$1" = xtrue])
70 dnl UL_SET_FLAGS(CFLAGS, CPPFLAGS, LDFLAGS)
72 dnl Sets new global CFLAGS, CPPFLAGS and LDFLAG, the original
73 dnl setting could be restored by UL_RESTORE_FLAGS()
75 AC_DEFUN([UL_SET_FLAGS], [
77 old_CPPFLAGS="$CPPFLAGS"
78 old_LDFLAGS="$LDFLAGS"
80 CPPFLAGS="$CPPFLAGS $2"
84 dnl UL_RESTORE_FLAGS()
86 dnl Restores CFLAGS, CPPFLAGS and LDFLAG previously saved by UL_SET_FLAGS()
88 AC_DEFUN([UL_RESTORE_FLAGS], [
90 CPPFLAGS="$old_CPPFLAGS"
91 LDFLAGS="$old_LDFLAGS"
95 dnl UL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
97 dnl Only specify FALLBACK if the SYSCALL you're checking for is a "newish" one
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],
104 [_UL_SYSCALL_CHECK_DECL([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],
112 if test "x$linux_os" = xyes; then
114 _UL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
119 ul_cv_syscall_$1=$syscall
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.]) ;;
125 *) AC_DEFINE_UNQUOTED([SYS_$1], [$ul_cv_syscall_$1],
126 [Fallback syscall number for $1]) ;;
131 dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
133 dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
135 m4_define([_UL_SYSCALL_CHECK_DECL],
136 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
137 #include <sys/syscall.h>
139 ]], [[int test = $1;]])],
143 dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
145 dnl Helper macro to create the body for the above `case'.
147 m4_define([_UL_CHECK_SYSCALL_FALLBACK],
150 $1) syscall="$2" ;;dnl
151 _UL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
155 dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1])
157 dnl Modifies $build_<name> variable according to $enable_<name> and OS type. The
158 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
159 dnl all checks are skiped.
161 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
163 AC_DEFUN([UL_REQUIRES_LINUX], [
164 m4_define([suffix], m4_default([$2],$1))
165 if test "x$[build_]suffix" != xno; then
166 AC_REQUIRE([AC_CANONICAL_HOST])
167 case $[enable_]suffix:$linux_os in #(
171 [build_]suffix=yes ;;
173 AC_MSG_ERROR([$1 selected for non-linux system]);;
175 [build_]suffix=yes ;;
177 AC_MSG_WARN([non-linux system; not building $1])
184 dnl UL_EXCLUDE_ARCH(NAME, ARCH, VARSUFFIX = $1])
186 dnl Modifies $build_<name> variable according to $enable_<name> and $host. The
187 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
188 dnl all checks are skiped.
190 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
192 AC_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 #(
200 AC_MSG_ERROR([$1 selected for unsupported architecture]);;
202 [build_]suffix=yes ;;
204 AC_MSG_WARN([excluded for $host architecture; not building $1])
207 [build_]suffix=yes ;;
212 dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC [VARSUFFIX=$1])
214 dnl Modifies $build_<name> variable according to $enable_<name> and
215 dnl $have_<havename>. The <havedesc> is description used ifor warning/error
216 dnl message (e.g. "function").
218 dnl The <havename> maybe a list, then at least one of the items in the list
219 dnl have to exist, for example: [ncurses, tinfo] means that have_ncurser=yes
220 dnl *or* have_tinfo=yes must be defined.
222 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
224 AC_DEFUN([UL_REQUIRES_HAVE], [
225 m4_define([suffix], m4_default([$4],$1))
227 if test "x$[build_]suffix" != xno; then
229 [ul_haveone_]suffix=no
230 m4_foreach([onehave], [$2], [
231 if test "x$[have_]onehave" = xyes; then
232 [ul_haveone_]suffix=yes
236 case $[enable_]suffix:$[ul_haveone_]suffix in #(
240 [build_]suffix=yes ;;
242 AC_MSG_ERROR([$1 selected, but required $3 not available]);;
244 [build_]suffix=yes ;;
246 AC_MSG_WARN([$3 not found; not building $1])
254 dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC [VARSUFFIX=$1])
256 dnl - ends with error if $enable_<name> and $build_<another>
257 dnl are both set to 'yes'
258 dnl - sets $build_<name> to 'no' if $build_<another> is 'yes' and
259 dnl $enable_<name> is 'check' or 'no'
261 dnl The <havedesc> is description used for warning/error
262 dnl message (e.g. "function").
264 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
266 AC_DEFUN([UL_CONFLICTS_BUILD], [
267 m4_define([suffix], m4_default([$4],$1))
269 if test "x$[build_]suffix" != xno; then
270 case $[enable_]suffix:$[build_]$2 in #(
276 [build_]suffix=yes ;;
278 AC_MSG_ERROR([$1 selected, but it conflicts with $3]);;
284 dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1])
286 dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname.
288 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
290 AC_DEFUN([UL_REQUIRES_BUILD], [
291 m4_define([suffix], m4_default([$3],$1))
293 if test "x$[build_]suffix" != xno; then
294 case $[enable_]suffix:$[build_]$2 in #(
298 [build_]suffix=yes ;;
300 AC_MSG_ERROR([$2 is needed to build $1]);;
302 [build_]suffix=yes ;;
304 AC_MSG_WARN([$2 disabled; not building $1])
310 dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1])
312 dnl Modifies $build_<name> variable according to $enable_<name> and SYSCALL-TEST
313 dnl result. The $enable_<name> variable could be "yes", "no" and "check". If build_<name>
314 dnl is "no" then all checks are skiped.
316 dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see
317 dnl also UL_CHECK_SYSCALL().
319 dnl The default <name> for $build_ and $enable_ count be overwrited by option $4 and
320 dnl $ul_cv_syscall_ could be overwrited by $3.
322 AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
323 m4_define([suffix], m4_default([$4],$1))
324 m4_define([callname], m4_default([$3],$1))
326 dnl This is default, $3 will redefine the condition
328 dnl TODO: remove this junk, AM_CONDITIONAL should not be used for any HAVE_*
329 dnl variables, all we need is BUILD_* only.
331 AM_CONDITIONAL([HAVE_]m4_toupper(callname), [false])
333 if test "x$[build_]suffix" != xno; then
334 if test "x$[enable_]suffix" = xno; then
338 case $[enable_]suffix:$[ul_cv_syscall_]callname in #(
342 AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
344 AC_MSG_WARN([callname syscall not found; not building $1])
347 dnl default $ul_cv_syscall_ is SYS_ value
348 [build_]suffix=yes ;;
354 dnl UL_BUILD_INIT(NAME, [ENABLE_STATE], [VARSUFFIX = $1])
356 dnl Initializes $build_<name> variable according to $enable_<name>. If
357 dnl $enable_<name> is undefined then ENABLE_STATE is used and $enable_<name> is
358 dnl set to ENABLE_STATE.
360 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
362 AC_DEFUN([UL_BUILD_INIT], [
363 m4_define([suffix], m4_default([$3],$1))
365 [if test "x$enable_[]suffix" = xno; then
370 [if test "x$ul_default_estate" != x; then
371 enable_[]suffix=$ul_default_estate
373 if test "x$ul_default_estate" = xno; then
380 enable_[]suffix=check],
383 enable_[]suffix=yes],
390 dnl UL_DEFAULT_ENABLE(NAME, ENABLE_STATE)
392 dnl Initializes $enable_<name> variable according to ENABLE_STATE. The default
393 dnl setting is possible to override by global $ul_default_estate.
395 AC_DEFUN([UL_DEFAULT_ENABLE], [
396 m4_define([suffix], $1)
397 if test "x$ul_default_estate" != x; then
398 enable_[]suffix=$ul_default_estate