]> git.proxmox.com Git - mirror_spl.git/blame - autoconf/spl-build.m4
Breaking the world for a little bit. If anyone is going to continue
[mirror_spl.git] / autoconf / spl-build.m4
CommitLineData
57d86234 1AC_DEFUN([SPL_AC_KERNEL], [
2 ver=`uname -r`
3
4 AC_ARG_WITH([linux],
5 AS_HELP_STRING([--with-linux=PATH],
6 [Path to kernel source]),
7 [kernelsrc="$withval"; kernelbuild="$withval"])
8
9 AC_ARG_WITH([linux-obj],
10 AS_HELP_STRING([--with-linux-obj=PATH],
11 [Path to kernel build objects]),
12 [kernelbuild="$withval"])
13
14 AC_MSG_CHECKING([kernel source directory])
15 if test -z "$kernelsrc"; then
16 kernelbuild=
17 sourcelink=/lib/modules/${ver}/source
18 buildlink=/lib/modules/${ver}/build
19
20 if test -e $sourcelink; then
21 kernelsrc=`(cd $sourcelink; /bin/pwd)`
22 fi
23 if test -e $buildlink; then
24 kernelbuild=`(cd $buildlink; /bin/pwd)`
25 fi
26 if test -z "$kernelsrc"; then
27 kernelsrc=$kernelbuild
28 fi
29 if test -z "$kernelsrc" -o -z "$kernelbuild"; then
30 AC_MSG_RESULT([Not found])
31 AC_MSG_ERROR([
32 *** Please specify the location of the kernel source
33 *** with the '--with-kernel=PATH' option])
34 fi
35 fi
36
37 AC_MSG_RESULT([$kernelsrc])
38 AC_MSG_CHECKING([kernel build directory])
39 AC_MSG_RESULT([$kernelbuild])
40
41 AC_MSG_CHECKING([kernel source version])
42 if test -r $kernelbuild/include/linux/version.h &&
43 fgrep -q UTS_RELEASE $kernelbuild/include/linux/version.h; then
44
45 kernsrcver=`(echo "#include <linux/version.h>";
46 echo "kernsrcver=UTS_RELEASE") |
47 cpp -I $kernelbuild/include |
48 grep "^kernsrcver=" | cut -d \" -f 2`
49
50 elif test -r $kernelbuild/include/linux/utsrelease.h &&
51 fgrep -q UTS_RELEASE $kernelbuild/include/linux/utsrelease.h; then
52
53 kernsrcver=`(echo "#include <linux/utsrelease.h>";
54 echo "kernsrcver=UTS_RELEASE") |
55 cpp -I $kernelbuild/include |
56 grep "^kernsrcver=" | cut -d \" -f 2`
57 fi
58
59 if test -z "$kernsrcver"; then
60 AC_MSG_RESULT([Not found])
61 AC_MSG_ERROR([
62 *** Cannot determine the version of the linux kernel source.
63 *** Please prepare the kernel before running this script])
64 fi
65
66 AC_MSG_RESULT([$kernsrcver])
67
68 kmoduledir=${INSTALL_MOD_PATH}/lib/modules/$kernsrcver
69 LINUX=${kernelsrc}
70 LINUX_OBJ=${kernelbuild}
71
72 AC_SUBST(LINUX)
73 AC_SUBST(LINUX_OBJ)
74 AC_SUBST(kmoduledir)
75])
76
77AC_DEFUN([SPL_AC_DEBUG], [
78 AC_MSG_CHECKING([whether debugging is enabled])
79 AC_ARG_ENABLE( [debug],
80 AS_HELP_STRING([--enable-debug],
81 [Enable generic debug support (default off)]),
82 [ case "$enableval" in
83 yes) spl_ac_debug=yes ;;
84 no) spl_ac_debug=no ;;
85 *) AC_MSG_RESULT([Error!])
86 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug]) ;;
87 esac ]
88 )
89 if test "$spl_ac_debug" = yes; then
90 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG"
91 else
92 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
93 AC_DEFINE([NDEBUG], [1],
94 [Define to 1 to disable debug tracing])
95 fi
96 AC_MSG_RESULT([${spl_ac_debug=no}])
97])
98
99AC_DEFUN([SPL_AC_DEBUG_KMEM], [
100 AC_MSG_CHECKING([whether kmem debugging is enabled])
101 AC_ARG_ENABLE( [debug-kmem],
102 AS_HELP_STRING([--enable-debug-kmem],
103 [Enable kmem debug support (default off)]),
104 [ case "$enableval" in
105 yes) spl_ac_debug=yes ;;
106 no) spl_ac_debug=no ;;
107 *) AC_MSG_RESULT([Error!])
108 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kmem]) ;;
109 esac ]
110 )
111 if test "$spl_ac_debug" = yes; then
112 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
113 AC_DEFINE([DEBUG_KMEM], [1],
114 [Define to 1 to enable kmem debugging])
115 fi
116 AC_MSG_RESULT([${spl_ac_debug=no}])
117])
118
119AC_DEFUN([SPL_AC_DEBUG_MUTEX], [
120 AC_MSG_CHECKING([whether mutex debugging is enabled])
121 AC_ARG_ENABLE( [debug-mutex],
122 AS_HELP_STRING([--enable-debug-mutex],
123 [Enable mutex debug support (default off)]),
124 [ case "$enableval" in
125 yes) spl_ac_debug=yes ;;
126 no) spl_ac_debug=no ;;
127 *) AC_MSG_RESULT([Error!])
128 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-mutex]) ;;
129 esac ]
130 )
131 if test "$spl_ac_debug" = yes; then
132 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_MUTEX"
133 AC_DEFINE([DEBUG_MUTEX], [1],
134 [Define to 1 to enable mutex debugging])
135 fi
136 AC_MSG_RESULT([${spl_ac_debug=no}])
137])
138
139AC_DEFUN([SPL_AC_DEBUG_KSTAT], [
140 AC_MSG_CHECKING([whether kstat debugging is enabled])
141 AC_ARG_ENABLE( [debug-kstat],
142 AS_HELP_STRING([--enable-debug-kstat],
143 [Enable kstat debug support (default off)]),
144 [ case "$enableval" in
145 yes) spl_ac_debug=yes ;;
146 no) spl_ac_debug=no ;;
147 *) AC_MSG_RESULT([Error!])
148 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-kstat]) ;;
149 esac ]
150 )
151 if test "$spl_ac_debug" = yes; then
152 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KSTAT"
153 AC_DEFINE([DEBUG_KSTAT], [1],
154 [Define to 1 to enable kstat debugging])
155 fi
156 AC_MSG_RESULT([${spl_ac_debug=no}])
157])
158
159AC_DEFUN([SPL_AC_DEBUG_CALLB], [
160 AC_MSG_CHECKING([whether callb debugging is enabled])
161 AC_ARG_ENABLE( [debug-callb],
162 AS_HELP_STRING([--enable-debug-callb],
163 [Enable callb debug support (default off)]),
164 [ case "$enableval" in
165 yes) spl_ac_debug=yes ;;
166 no) spl_ac_debug=no ;;
167 *) AC_MSG_RESULT([Error!])
168 AC_MSG_ERROR([Bad value "$enableval" for --enable-debug-callb]) ;;
169 esac ]
170 )
171 if test "$spl_ac_debug" = yes; then
172 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_CALLB"
173 AC_DEFINE([DEBUG_CALLB], [1],
174 [Define to 1 to enable callb debugging])
175 fi
176 AC_MSG_RESULT([${spl_ac_debug=no}])
177])
178
179dnl #
180dnl # SPL_LINUX_CONFTEST
181dnl #
182AC_DEFUN([SPL_LINUX_CONFTEST], [
183cat >conftest.c <<_ACEOF
184$1
185_ACEOF
186])
187
188dnl #
189dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
190dnl #
191m4_define([SPL_LANG_PROGRAM], [
192$1
193int
194main (void)
195{
196dnl Do *not* indent the following line: there may be CPP directives.
197dnl Don't move the `;' right after for the same reason.
198$2
199 ;
200 return 0;
201}
202])
203
204dnl #
205dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
206dnl #
207AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
208m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])dnl
209rm -f build/conftest.o build/conftest.mod.c build/conftest.ko build/Makefile
210echo "obj-m := conftest.o" >build/Makefile
211dnl AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" -f $PWD/build/Makefile LINUXINCLUDE="-Iinclude -include include/linux/autoconf.h" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM SUBDIRS=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
212AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" LINUXINCLUDE="-Iinclude -include include/linux/autoconf.h" -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
213 [$4],
214 [_AC_MSG_LOG_CONFTEST
215m4_ifvaln([$5],[$5])dnl])dnl
216rm -f build/conftest.o build/conftest.mod.c build/conftest.mod.o build/conftest.ko m4_ifval([$1], [build/conftest.c conftest.c])[]dnl
217])
218
219dnl #
220dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
221dnl #
222AC_DEFUN([SPL_LINUX_TRY_COMPILE],
223 [SPL_LINUX_COMPILE_IFELSE(
224 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
225 [modules],
226 [test -s build/conftest.o],
227 [$3], [$4])
228])
229
230dnl #
231dnl # SPL_LINUX_CONFIG
232dnl #
233AC_DEFUN([SPL_LINUX_CONFIG],
234 [AC_MSG_CHECKING([whether Linux was built with CONFIG_$1])
235 SPL_LINUX_TRY_COMPILE([
236 #ifndef AUTOCONF_INCLUDED
237 #include <linux/config.h>
238 #endif
239 ],[
240 #ifndef CONFIG_$1
241 #error CONFIG_$1 not #defined
242 #endif
243 ],[
244 AC_MSG_RESULT([yes])
245 $2
246 ],[
247 AC_MSG_RESULT([no])
248 $3
249 ])
250])
251
252dnl #
253dnl # SPL_CHECK_SYMBOL_EXPORT
254dnl # check symbol exported or not
255dnl #
256AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT],
257 [AC_MSG_CHECKING([whether symbol $1 is exported])
258 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/Module.symvers 2>/dev/null
259 rc=$?
260 if test $rc -ne 0; then
261 export=0
262 for file in $2; do
263 grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
264 rc=$?
265 if test $rc -eq 0; then
266 export=1
267 break;
268 fi
269 done
270 if test $export -eq 0; then
271 AC_MSG_RESULT([no])
272 $4
273 else
274 AC_MSG_RESULT([yes])
275 $3
276 fi
277 else
278 AC_MSG_RESULT([yes])
279 $3
280 fi
281])
282
283dnl #
284dnl # 2.6.x API change
285dnl # check if uintptr_t typedef is defined
286dnl #
287AC_DEFUN([SPL_AC_TYPE_UINTPTR_T],
288 [AC_MSG_CHECKING([whether kernel defines uintptr_t])
289 SPL_LINUX_TRY_COMPILE([
290 #include <linux/types.h>
291 ],[
292 uintptr_t *ptr;
293 ],[
294 AC_MSG_RESULT([yes])
295 AC_DEFINE(HAVE_UINTPTR_T, 1,
296 [kernel defines uintptr_t])
297 ],[
298 AC_MSG_RESULT([no])
299 ])
300])
301
302dnl #
303dnl # 2.6.x API change
304dnl # check if kmem_cache_t typedef is defined
305dnl #
306AC_DEFUN([SPL_AC_TYPE_KMEM_CACHE_T],
307 [AC_MSG_CHECKING([whether kernel defines kmem_cache_t])
308 SPL_LINUX_TRY_COMPILE([
309 #include <linux/slab.h>
310 ],[
311 kmem_cache_t *cache;
312 ],[
313 AC_MSG_RESULT([yes])
314 AC_DEFINE(HAVE_KMEM_CACHE_T, 1,
315 [kernel defines kmem_cache_t])
316 ],[
317 AC_MSG_RESULT([no])
318 ])
319])
320
321dnl #
322dnl # 2.6.19 API change
323dnl # kmem_cache_destroy() return void instead of int
324dnl #
325AC_DEFUN([SPL_AC_KMEM_CACHE_DESTROY_INT],
326 [AC_MSG_CHECKING([whether kmem_cache_destroy() returns int])
327 SPL_LINUX_TRY_COMPILE([
328 #include <linux/slab.h>
329 ],[
330 int i = kmem_cache_destroy(NULL);
331 ],[
332 AC_MSG_RESULT(yes)
333 AC_DEFINE(HAVE_KMEM_CACHE_DESTROY_INT, 1,
334 [kmem_cache_destroy() returns int])
335 ],[
336 AC_MSG_RESULT(no)
337 ])
338])
339
340dnl #
341dnl # 2.6.19 API change
342dnl # panic_notifier_list use atomic_notifier operations
343dnl #
344
345AC_DEFUN([SPL_AC_ATOMIC_PANIC_NOTIFIER],
346 [AC_MSG_CHECKING([whether panic_notifier_list is atomic])
347 SPL_LINUX_TRY_COMPILE([
348 #include <linux/notifier.h>
349 #include <linux/kernel.h>
350 ],[
351 struct atomic_notifier_head panic_notifier_list;
352 ],[
353 AC_MSG_RESULT(yes)
354 AC_DEFINE(HAVE_ATOMIC_PANIC_NOTIFIER, 1,
355 [panic_notifier_list is atomic])
356 ],[
357 AC_MSG_RESULT(no)
358 ])
359])
360
361dnl #
362dnl # 2.6.20 API change
363dnl # INIT_WORK use 2 args and not store data inside
364dnl #
365AC_DEFUN([SPL_AC_3ARGS_INIT_WORK],
366 [AC_MSG_CHECKING([whether INIT_WORK wants 3 args])
367 SPL_LINUX_TRY_COMPILE([
368 #include <linux/workqueue.h>
369 ],[
370 struct work_struct work;
371
372 INIT_WORK(&work, NULL, NULL);
373 ],[
374 AC_MSG_RESULT(yes)
375 AC_DEFINE(HAVE_3ARGS_INIT_WORK, 1,
376 [INIT_WORK wants 3 args])
377 ],[
378 AC_MSG_RESULT(no)
379 ])
380])
381
382dnl #
383dnl # 2.6.21 api change.
384dnl # 'register_sysctl_table' use only one argument instead of two
385dnl #
386AC_DEFUN([SPL_AC_2ARGS_REGISTER_SYSCTL],
387 [AC_MSG_CHECKING([whether register_sysctl_table() wants 2 args])
388 SPL_LINUX_TRY_COMPILE([
389 #include <linux/sysctl.h>
390 ],[
391 return register_sysctl_table(NULL,0);
392 ],[
393 AC_MSG_RESULT(yes)
394 AC_DEFINE(HAVE_2ARGS_REGISTER_SYSCTL, 1,
395 [register_sysctl_table() wants 2 args])
396 ],[
397 AC_MSG_RESULT(no)
398 ])
399])
400
401dnl #
402dnl # 2.6.21 API change
403dnl # Use struct kmem_cache for missing kmem_cache_t
404dnl #
405AC_DEFUN([SPL_AC_KMEM_CACHE_T], [
406 AC_MSG_CHECKING([whether kernel has kmem_cache_t])
407 tmp_flags="$EXTRA_KCFLAGS"
408 EXTRA_KCFLAGS="-Werror"
409 SPL_LINUX_TRY_COMPILE([
410 #include <linux/slab.h>
411 ],[
412 kmem_cache_t *cachep = NULL;
413 kmem_cache_free(cachep, NULL);
414
415 ],[
416 AC_MSG_RESULT([yes])
417 AC_DEFINE(HAVE_KMEM_CACHE_T, 1,
418 [kernel has struct kmem_cache_t])
419 ],[
420 AC_MSG_RESULT([no])
421 ])
422 EXTRA_KCFLAGS="$tmp_flags"
423])
424
425dnl #
426dnl # 2.6.23 API change
427dnl # Slab no longer accepts a dtor argument
428dnl #
429AC_DEFUN([SPL_AC_KMEM_CACHE_CREATE_DTOR],
430 [AC_MSG_CHECKING([whether kmem_cache_create() has dtor arg])
431 SPL_LINUX_TRY_COMPILE([
432 #include <linux/slab.h>
433 ],[
434 kmem_cache_create(NULL, 0, 0, 0, NULL, NULL);
435 ],[
436 AC_MSG_RESULT(yes)
437 AC_DEFINE(HAVE_KMEM_CACHE_CREATE_DTOR, 1,
438 [kmem_cache_create() has dtor arg])
439 ],[
440 AC_MSG_RESULT(no)
441 ])
442])
443
444dnl #
445dnl # 2.6.x API change
446dnl # Slab ctor no longer takes 3 args
447dnl #
448AC_DEFUN([SPL_AC_3ARG_KMEM_CACHE_CREATE_CTOR],
449 [AC_MSG_CHECKING([whether slab ctor wants 3 args])
450 tmp_flags="$EXTRA_KCFLAGS"
451 EXTRA_KCFLAGS="-Werror"
452 SPL_LINUX_TRY_COMPILE([
453 #include <linux/slab.h>
454 ],[
455 void (*ctor)(void *,struct kmem_cache *,unsigned long) = NULL;
456
457 #ifdef HAVE_KMEM_CACHE_CREATE_DTOR
458 kmem_cache_create(NULL, 0, 0, 0, ctor, NULL);
459 #else
460 kmem_cache_create(NULL, 0, 0, 0, ctor);
461 #endif
462 ],[
463 AC_MSG_RESULT(yes)
464 AC_DEFINE(HAVE_3ARG_KMEM_CACHE_CREATE_CTOR, 1,
465 [slab ctor wants 3 args])
466 ],[
467 AC_MSG_RESULT(no)
468 ])
469 EXTRA_KCFLAGS="$tmp_flags"
470])
471
472dnl #
473dnl # 2.6.x API change
474dnl # Old set_shrinker API replaced with register_shrinker
475dnl #
476AC_DEFUN([SPL_AC_SET_SHRINKER], [
477 AC_MSG_CHECKING([whether set_shrinker() available])
478 SPL_LINUX_TRY_COMPILE([
479 #include <linux/mm.h>
480 ],[
481 return set_shrinker(DEFAULT_SEEKS, NULL);
482 ],[
483 AC_MSG_RESULT([yes])
484 AC_DEFINE(HAVE_SET_SHRINKER, 1,
485 [set_shrinker() available])
486 ],[
487 AC_MSG_RESULT([no])
488 ])
489])
490
491dnl #
492dnl # 2.6.x API change
493dnl # struct path entry added to struct nameidata
494dnl #
495AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
496 [AC_MSG_CHECKING([whether struct path used in struct nameidata])
497 SPL_LINUX_TRY_COMPILE([
498 #include <linux/namei.h>
499 ],[
500 struct nameidata nd;
501
502 nd.path.mnt = NULL;
503 nd.path.dentry = NULL;
504 ],[
505 AC_MSG_RESULT(yes)
506 AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
507 [struct path used in struct nameidata])
508 ],[
509 AC_MSG_RESULT(no)
510 ])
511])
512
513dnl #
514dnl # Custom SPL patch may export this system it is not required
515dnl #
516AC_DEFUN([SPL_AC_TASK_CURR], [
517 SPL_CHECK_SYMBOL_EXPORT([task_curr], [kernel/sched.c],
518 [AC_DEFINE(HAVE_TASK_CURR, 1, [task_curr() exported])],
519 [])
520])
521
522dnl #
523dnl # 2.6.x API change
524dnl # Use CTL_UNNUMBERED when binary sysctl is not required
525dnl #
526AC_DEFUN([SPL_AC_CTL_UNNUMBERED],
527 [AC_MSG_CHECKING([whether unnumbered sysctl support exists])
528 SPL_LINUX_TRY_COMPILE([
529 #include <linux/sysctl.h>
530 ],[
531 #ifndef CTL_UNNUMBERED
532 #error CTL_UNNUMBERED undefined
533 #endif
534 ],[
535 AC_MSG_RESULT(yes)
536 AC_DEFINE(HAVE_CTL_UNNUMBERED, 1,
537 [unnumbered sysctl support exists])
538 ],[
539 AC_MSG_RESULT(no)
540 ])
541])