]> git.ipfire.org Git - thirdparty/util-linux.git/blob - m4/ul.m4
merge coreutils' last GPL2 version of su.c
[thirdparty/util-linux.git] / m4 / ul.m4
1
2 dnl UL_PKG_STATIC(VARIABLE, MODULES)
3 dnl
4 dnl Calls pkg-config --static
5 dnl
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"`
9 else
10 AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
11 fi
12 ])
13
14 dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1]))
15 dnl
16 dnl The VARSUFFIX is optional and overrides the default behaviour. 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
19 dnl
20 AC_DEFUN([UL_CHECK_LIB], [
21 m4_define([suffix], m4_default([$3],$1))
22 [have_]suffix=yes
23 m4_ifdef([$3],
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])
27 ])
28
29
30 dnl UL_SET_ARCH(ARCHNAME, PATTERN)
31 dnl
32 dnl Define ARCH_<archname> condition if the pattern match with the current
33 dnl architecture
34 dnl
35 AC_DEFUN([UL_SET_ARCH], [
36 cpu_$1=false
37 case "$host" in
38 $2) cpu_$1=true ;;
39 esac
40 AM_CONDITIONAL(AS_TR_CPP(ARCH_$1), [test "x$cpu_$1" = xtrue])
41 ])
42
43
44 dnl UL_SET_FLAGS(CFLAGS, CPPFLAGS, LDFLAGS)
45 dnl
46 dnl Sets new global CFLAGS, CPPFLAGS and LDFLAG, the original
47 dnl setting could be restored by UL_RESTORE_FLAGS()
48 dnl
49 AC_DEFUN([UL_SET_FLAGS], [
50 old_CFLAGS="$CFLAGS"
51 old_CPPFLAGS="$CPPFLAGS"
52 old_LDFLAGS="$LDFLAGS"
53 CFLAGS="$CFLAGS $1"
54 CPPFLAGS="$CPPFLAGS $2"
55 LDFLAGS="$LDFLAGS $3"
56 ])
57
58 dnl UL_RESTORE_FLAGS()
59 dnl
60 dnl Restores CFLAGS, CPPFLAGS and LDFLAG previously saved by UL_SET_FLAGS()
61 dnl
62 AC_DEFUN([UL_RESTORE_FLAGS], [
63 CFLAGS="$old_CFLAGS"
64 CPPFLAGS="$old_CPPFLAGS"
65 LDFLAGS="$old_LDFLAGS"
66 ])
67
68
69 dnl UL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
70 dnl
71 dnl Only specify FALLBACK if the SYSCALL you're checking for is a "newish" one
72 dnl
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],
77 [ul_cv_syscall_$1],
78 [_UL_SYSCALL_CHECK_DECL([SYS_$1],
79 [syscall=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],
83 [syscall=_NR_$1],
84 [
85 syscall=no
86 if test "x$linux_os" = xyes; then
87 case $host_cpu in
88 _UL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
89 esac
90 fi
91 ])
92 ])
93 ul_cv_syscall_$1=$syscall
94 ])
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.]) ;;
98 SYS_*) ;;
99 *) AC_DEFINE_UNQUOTED([SYS_$1], [$ul_cv_syscall_$1],
100 [Fallback syscall number for $1]) ;;
101 esac
102 ])
103
104
105 dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
106 dnl
107 dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
108 dnl
109 m4_define([_UL_SYSCALL_CHECK_DECL],
110 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
111 #include <sys/syscall.h>
112 #include <unistd.h>
113 ]], [[int test = $1;]])],
114 [$2], [$3])
115 ])
116
117 dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
118 dnl
119 dnl Helper macro to create the body for the above `case'.
120 dnl
121 m4_define([_UL_CHECK_SYSCALL_FALLBACK],
122 [m4_ifval([$1],
123 [#(
124 $1) syscall="$2" ;;dnl
125 _UL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
126 ])
127
128
129 dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1])
130 dnl
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.
134 dnl
135 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
136 dnl
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 #(
142 no:*)
143 [build_]suffix=no ;;
144 yes:yes)
145 [build_]suffix=yes ;;
146 yes:*)
147 AC_MSG_ERROR([$1 selected for non-linux system]);;
148 check:yes)
149 [build_]suffix=yes ;;
150 check:*)
151 AC_MSG_WARN([non-linux system; do not build $1])
152 [build_]suffix=no ;;
153 esac
154 fi
155 ])
156
157 dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC [VARSUFFIX=$1])
158 dnl
159 dnl Modifies $build_<name> variable according to $enable_<name> and
160 dnl $have_<havename>. The <havedesc> is description used ifor warning/error
161 dnl message (e.g. "function").
162 dnl
163 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
164 dnl
165 AC_DEFUN([UL_REQUIRES_HAVE], [
166 m4_define([suffix], m4_default([$4],$1))
167
168 if test "x$[build_]suffix" != xno; then
169 case $[enable_]suffix:$[have_]$2 in #(
170 no:*)
171 [build_]suffix=no ;;
172 yes:yes)
173 [build_]suffix=yes ;;
174 yes:*)
175 AC_MSG_ERROR([$1 selected, but required $3 not available]);;
176 check:yes)
177 [build_]suffix=yes ;;
178 check:*)
179 AC_MSG_WARN([$3 not found; do not build $1])
180 [build_]suffix=no ;;
181 esac
182 fi
183 ])
184
185 dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1])
186 dnl
187 dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname.
188 dnl
189 dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
190 dnl
191 AC_DEFUN([UL_REQUIRES_BUILD], [
192 m4_define([suffix], m4_default([$3],$1))
193
194 if test "x$[build_]suffix" != xno; then
195 case $[enable_]suffix:$[build_]$2 in #(
196 no:*)
197 [build_]suffix=no ;;
198 yes:yes)
199 [build_]suffix=yes ;;
200 yes:*)
201 AC_MSG_ERROR([$2 is needed to build $1]);;
202 check:yes)
203 [build_]suffix=yes ;;
204 check:*)
205 AC_MSG_WARN([$2 disabled; do not build $1])
206 [build_]suffix=no ;;
207 esac
208 fi
209 ])
210
211 dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1])
212 dnl
213 dnl Modifies $build_<name> variable according to $enable_<name> and SYSCALL-TEST
214 dnl result. The $enable_<name> variable could be "yes", "no" and "check". If build_<name>
215 dnl is "no" then all checks are skiped.
216 dnl
217 dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see
218 dnl also UL_CHECK_SYSCALL().
219 dnl
220 dnl The default <name> for $build_ and $enable_ count be overwrited by option $4 and
221 dnl $ul_cv_syscall_ could be overwrited by $3.
222 dnl
223 AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
224 m4_define([suffix], m4_default([$4],$1))
225 m4_define([callname], m4_default([$3],$1))
226
227 dnl This is default, $3 will redefine the condition
228 dnl
229 dnl TODO: remove this junk, AM_CONDITIONAL should not be used for any HAVE_*
230 dnl variables, all we need is BUILD_* only.
231 dnl
232 AM_CONDITIONAL([HAVE_]m4_toupper(callname), [false])
233
234 if test "x$[build_]suffix" != xno; then
235 if test "x$[enable_]suffix" = xno; then
236 [build_]suffix=no
237 else
238 $2
239 case $[enable_]suffix:$[ul_cv_syscall_]callname in #(
240 no:*)
241 [build_]suffix=no ;;
242 yes:no)
243 AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
244 check:no)
245 AC_MSG_WARN([callname syscall not found; do not build $1])
246 [build_]suffix=no ;;
247 *)
248 dnl default $ul_cv_syscall_ is SYS_ value
249 [build_]suffix=yes ;;
250 esac
251 fi
252 fi
253 ])
254
255 dnl UL_INIT_BUILD(NAME, [ENABLE_STATE], [VARSUFFIX = $1])
256 dnl
257 dnl Initializes $build_<name> variable according to $enable_<name>. If
258 dnl $enable_<name> is undefined then ENABLE_STATE is used and $enable_<name> is
259 dnl set to ENABLE_STATE.
260 dnl
261 dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
262 dnl
263 AC_DEFUN([UL_BUILD_INIT], [
264 m4_define([suffix], m4_default([$3],$1))
265 m4_define([estate], m4_default([$2],$enable_[]suffix))
266
267 ifelse(estate, [check], [build_[]suffix='yes' enable_[]suffix='check'],
268 estate, [yes], [build_[]suffix='yes' enable_[]suffix='yes'],
269 estate, [no], [build_[]suffix='no' enable_[]suffix='no'],
270 [build_[]suffix=$enable_[]suffix])
271 ])