]>
Commit | Line | Data |
---|---|---|
a8afc8c6 KK |
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. | |
3 | dnl | |
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: | |
12 | dnl macro( | |
13 | dnl [] | |
14 | dnl ) | |
15 | dnl | |
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])])]) | |
22 | ||
23 | ifdef([m4_ifnblank],[],[ | |
24 | m4_define([m4_ifnblank], | |
25 | [m4_if(m4_translit([[$1]], [ ][ ][ | |
26 | ]), [], [$3], [$2])])]) | |
132ea941 KZ |
27 | |
28 | dnl UL_PKG_STATIC(VARIABLE, MODULES) | |
29 | dnl | |
30 | dnl Calls pkg-config --static | |
31 | dnl | |
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"` | |
35 | else | |
36 | AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available]) | |
37 | fi | |
38 | ]) | |
39 | ||
40 | dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1])) | |
41 | dnl | |
ee312c65 | 42 | dnl The VARSUFFIX is optional and overrides the default behavior. For example: |
132ea941 KZ |
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 | |
45 | dnl | |
46 | AC_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 | ||
56 | dnl UL_SET_ARCH(ARCHNAME, PATTERN) | |
57 | dnl | |
58 | dnl Define ARCH_<archname> condition if the pattern match with the current | |
59 | dnl architecture | |
60 | dnl | |
61 | AC_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 | ||
70 | dnl UL_SET_FLAGS(CFLAGS, CPPFLAGS, LDFLAGS) | |
71 | dnl | |
72 | dnl Sets new global CFLAGS, CPPFLAGS and LDFLAG, the original | |
73 | dnl setting could be restored by UL_RESTORE_FLAGS() | |
74 | dnl | |
75 | AC_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 | ||
84 | dnl UL_RESTORE_FLAGS() | |
85 | dnl | |
86 | dnl Restores CFLAGS, CPPFLAGS and LDFLAG previously saved by UL_SET_FLAGS() | |
87 | dnl | |
88 | AC_DEFUN([UL_RESTORE_FLAGS], [ | |
89 | CFLAGS="$old_CFLAGS" | |
90 | CPPFLAGS="$old_CPPFLAGS" | |
91 | LDFLAGS="$old_LDFLAGS" | |
92 | ]) | |
93 | ||
94 | ||
95 | dnl UL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...) | |
96 | dnl | |
97 | dnl Only specify FALLBACK if the SYSCALL you're checking for is a "newish" one | |
98 | dnl | |
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], | |
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 | ||
131 | dnl _UL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) | |
132 | dnl | |
133 | dnl Check if SYMBOL is declared, using the headers needed for syscall checks. | |
134 | dnl | |
135 | m4_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 | ||
143 | dnl _UL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...) | |
144 | dnl | |
145 | dnl Helper macro to create the body for the above `case'. | |
146 | dnl | |
147 | m4_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 | ||
155 | dnl UL_REQUIRES_LINUX(NAME, [VARSUFFIX = $1]) | |
156 | dnl | |
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. | |
160 | dnl | |
161 | dnl The default <name> for $build_ and $enable_ could be overwrited by option $2. | |
162 | dnl | |
163 | AC_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 | |
184 | dnl UL_EXCLUDE_ARCH(NAME, ARCH, VARSUFFIX = $1]) | |
185 | dnl | |
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. | |
189 | dnl | |
190 | dnl The default <name> for $build_ and $enable_ could be overwrited by option $3. | |
191 | dnl | |
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 #( | |
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 |
212 | dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC [VARSUFFIX=$1]) |
213 | dnl | |
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"). | |
217 | dnl | |
91626822 KZ |
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. | |
221 | dnl | |
b17e8206 KZ |
222 | dnl The default <name> for $build_ and $enable_ could be overwrited by option $3. |
223 | dnl | |
224 | AC_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 | |
253 | dnl | |
254 | dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC [VARSUFFIX=$1]) | |
255 | dnl | |
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' | |
260 | dnl | |
261 | dnl The <havedesc> is description used for warning/error | |
262 | dnl message (e.g. "function"). | |
263 | dnl | |
264 | dnl The default <name> for $build_ and $enable_ could be overwrited by option $3. | |
265 | dnl | |
266 | AC_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 |
284 | dnl UL_REQUIRES_BUILD(NAME, BUILDNAME, [VARSUFFIX=$1]) |
285 | dnl | |
286 | dnl Modifies $build_<name> variable according to $enable_<name> and $have_funcname. | |
287 | dnl | |
288 | dnl The default <name> for $build_ and $enable_ could be overwrited by option $3. | |
289 | dnl | |
290 | AC_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 | ||
310 | dnl UL_REQUIRES_SYSCALL_CHECK(NAME, SYSCALL-TEST, [SYSCALLNAME=$1], [VARSUFFIX=$1]) | |
311 | dnl | |
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. | |
315 | dnl | |
316 | dnl Note that SYSCALL-TEST has to define $ul_cv_syscall_<name> variable, see | |
317 | dnl also UL_CHECK_SYSCALL(). | |
318 | dnl | |
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. | |
321 | dnl | |
322 | AC_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 | 354 | dnl UL_BUILD_INIT(NAME, [ENABLE_STATE], [VARSUFFIX = $1]) |
61a074f7 KZ |
355 | dnl |
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. | |
359 | dnl | |
360 | dnl The default <name> for $build_ and $enable_ could be overwrited by option $2. | |
361 | dnl | |
362 | AC_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 | |
367 | else | |
368 | build_[]suffix=yes | |
369 | fi], | |
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 |
376 | else[] |
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 |
387 | fi]) |
388 | ]) | |
61a074f7 | 389 | |
50d096ac KZ |
390 | dnl UL_DEFAULT_ENABLE(NAME, ENABLE_STATE) |
391 | dnl | |
392 | dnl Initializes $enable_<name> variable according to ENABLE_STATE. The default | |
393 | dnl setting is possible to override by global $ul_default_estate. | |
394 | dnl | |
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 | |
399 | else | |
400 | enable_[]suffix=$2 | |
401 | fi | |
61a074f7 | 402 | ]) |