2 dnl UL_PKG_STATIC(VARIABLE, MODULES)
4 dnl Calls pkg-config --static
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"`
10 AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
14 dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1]))
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
20 AC_DEFUN([UL_CHECK_LIB], [
21 m4_define([suffix], m4_default([$3],$1))
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])
30 dnl UL_SET_ARCH(ARCHNAME, PATTERN)
32 dnl Define ARCH_<archname> condition if the pattern match with the current
35 AC_DEFUN([UL_SET_ARCH], [
40 AM_CONDITIONAL(AS_TR_CPP(ARCH_$1), [test "x$cpu_$1" = xtrue])
44 dnl UL_SET_FLAGS(CFLAGS, CPPFLAGS, LDFLAGS)
46 dnl Sets new global CFLAGS, CPPFLAGS and LDFLAG, the original
47 dnl setting could be restored by UL_RESTORE_FLAGS()
49 AC_DEFUN([UL_SET_FLAGS], [
51 old_CPPFLAGS="$CPPFLAGS"
52 old_LDFLAGS="$LDFLAGS"
54 CPPFLAGS="$CPPFLAGS $2"
58 dnl UL_RESTORE_FLAGS()
60 dnl Restores CFLAGS, CPPFLAGS and LDFLAG previously saved by UL_SET_FLAGS()
62 AC_DEFUN([UL_RESTORE_FLAGS], [
64 CPPFLAGS="$old_CPPFLAGS"
65 LDFLAGS="$old_LDFLAGS"
69 dnl UL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
71 dnl Only specify FALLBACK if the SYSCALL you're checking for is a "newish" one
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],
78 [_UL_SYSCALL_CHECK_DECL([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],
86 if test "x$linux_os" = xyes; then
88 _UL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
93 ul_cv_syscall_$1=$syscall
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.]) ;;
99 *) AC_DEFINE_UNQUOTED([SYS_$1], [$ul_cv_syscall_$1],
100 [Fallback syscall number for $1]) ;;
105 dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
107 dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
109 m4_define([_UL_SYSCALL_CHECK_DECL],
110 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
111 #include <sys/syscall.h>
113 ]], [[int test = $1;]])],
117 dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
119 dnl Helper macro to create the body for the above `case'.
121 m4_define([_UL_CHECK_SYSCALL_FALLBACK],
124 $1) syscall="$2" ;;dnl
125 _UL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
129 dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1])
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.
135 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
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 #(
145 [build_]suffix=yes ;;
147 AC_MSG_ERROR([$1 selected for non-linux system]);;
149 [build_]suffix=yes ;;
151 AC_MSG_WARN([non-linux system; not building $1])
158 dnl UL_EXCLUDE_ARCH(NAME, ARCH, VARSUFFIX = $1])
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.
164 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
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 #(
174 AC_MSG_ERROR([$1 selected for unsupported architecture]);;
176 [build_]suffix=yes ;;
178 AC_MSG_WARN([excluded for $host architecture; not building $1])
181 [build_]suffix=yes ;;
186 dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC [VARSUFFIX=$1])
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").
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.
196 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
198 AC_DEFUN([UL_REQUIRES_HAVE], [
199 m4_define([suffix], m4_default([$4],$1))
201 if test "x$[build_]suffix" != xno; then
203 [ul_haveone_]suffix=no
204 m4_foreach([onehave], [$2], [
205 if test "x$[have_]onehave" = xyes; then
206 [ul_haveone_]suffix=yes
210 case $[enable_]suffix:$[ul_haveone_]suffix in #(
214 [build_]suffix=yes ;;
216 AC_MSG_ERROR([$1 selected, but required $3 not available]);;
218 [build_]suffix=yes ;;
220 AC_MSG_WARN([$3 not found; not building $1])
228 dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC [VARSUFFIX=$1])
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'
235 dnl The <havedesc> is description used for warning/error
236 dnl message (e.g. "function").
238 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
240 AC_DEFUN([UL_CONFLICTS_BUILD], [
241 m4_define([suffix], m4_default([$4],$1))
243 if test "x$[build_]suffix" != xno; then
244 case $[enable_]suffix:$[build_]$2 in #(
250 [build_]suffix=yes ;;
252 AC_MSG_ERROR([$1 selected, but it conflicts with $3]);;
258 dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1])
260 dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname.
262 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
264 AC_DEFUN([UL_REQUIRES_BUILD], [
265 m4_define([suffix], m4_default([$3],$1))
267 if test "x$[build_]suffix" != xno; then
268 case $[enable_]suffix:$[build_]$2 in #(
272 [build_]suffix=yes ;;
274 AC_MSG_ERROR([$2 is needed to build $1]);;
276 [build_]suffix=yes ;;
278 AC_MSG_WARN([$2 disabled; not building $1])
284 dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1])
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.
290 dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see
291 dnl also UL_CHECK_SYSCALL().
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.
296 AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
297 m4_define([suffix], m4_default([$4],$1))
298 m4_define([callname], m4_default([$3],$1))
300 dnl This is default, $3 will redefine the condition
302 dnl TODO: remove this junk, AM_CONDITIONAL should not be used for any HAVE_*
303 dnl variables, all we need is BUILD_* only.
305 AM_CONDITIONAL([HAVE_]m4_toupper(callname), [false])
307 if test "x$[build_]suffix" != xno; then
308 if test "x$[enable_]suffix" = xno; then
312 case $[enable_]suffix:$[ul_cv_syscall_]callname in #(
316 AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
318 AC_MSG_WARN([callname syscall not found; not building $1])
321 dnl default $ul_cv_syscall_ is SYS_ value
322 [build_]suffix=yes ;;
328 dnl UL_BUILD_INIT(NAME, [ENABLE_STATE], [VARSUFFIX = $1])
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.
334 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
336 AC_DEFUN([UL_BUILD_INIT], [
337 m4_define([suffix], m4_default([$3],$1))
339 [if test "x$enable_[]suffix" = xno; then
344 [if test "x$ul_default_estate" != x; then
345 enable_[]suffix=$ul_default_estate
347 if test "x$ul_default_estate" = xno; then
354 enable_[]suffix=check],
357 enable_[]suffix=yes],
364 dnl UL_DEFAULT_ENABLE(NAME, ENABLE_STATE)
366 dnl Initializes $enable_<name> variable according to ENABLE_STATE. The default
367 dnl setting is possible to override by global $ul_default_estate.
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