]> git.proxmox.com Git - mirror_spl-debian.git/blob - config/spl-build.m4
New upstream version 0.7.9
[mirror_spl-debian.git] / config / spl-build.m4
1 ###############################################################################
2 # Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 # Copyright (C) 2007 The Regents of the University of California.
4 # Written by Brian Behlendorf <behlendorf1@llnl.gov>.
5 ###############################################################################
6 # SPL_AC_CONFIG_KERNEL: Default SPL kernel configuration.
7 ###############################################################################
8
9 AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
10 SPL_AC_KERNEL
11
12 if test "${LINUX_OBJ}" != "${LINUX}"; then
13 KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
14 fi
15 AC_SUBST(KERNELMAKE_PARAMS)
16
17 KERNELCPPFLAGS="$KERNELCPPFLAGS -Wstrict-prototypes"
18 AC_SUBST(KERNELCPPFLAGS)
19
20 SPL_AC_TEST_MODULE
21 SPL_AC_ATOMIC_SPINLOCK
22 SPL_AC_SHRINKER_CALLBACK
23 SPL_AC_CTL_NAME
24 SPL_AC_CONFIG_TRIM_UNUSED_KSYMS
25 SPL_AC_PDE_DATA
26 SPL_AC_SET_FS_PWD_WITH_CONST
27 SPL_AC_2ARGS_VFS_FSYNC
28 SPL_AC_INODE_TRUNCATE_RANGE
29 SPL_AC_FS_STRUCT_SPINLOCK
30 SPL_AC_KUIDGID_T
31 SPL_AC_KERNEL_FALLOCATE
32 SPL_AC_CONFIG_ZLIB_INFLATE
33 SPL_AC_CONFIG_ZLIB_DEFLATE
34 SPL_AC_2ARGS_ZLIB_DEFLATE_WORKSPACESIZE
35 SPL_AC_SHRINK_CONTROL_STRUCT
36 SPL_AC_RWSEM_SPINLOCK_IS_RAW
37 SPL_AC_RWSEM_ACTIVITY
38 SPL_AC_RWSEM_ATOMIC_LONG_COUNT
39 SPL_AC_SCHED_RT_HEADER
40 SPL_AC_SCHED_SIGNAL_HEADER
41 SPL_AC_4ARGS_VFS_GETATTR
42 SPL_AC_3ARGS_VFS_GETATTR
43 SPL_AC_2ARGS_VFS_GETATTR
44 SPL_AC_USLEEP_RANGE
45 SPL_AC_KMEM_CACHE_ALLOCFLAGS
46 SPL_AC_WAIT_ON_BIT
47 SPL_AC_INODE_LOCK
48 SPL_AC_GROUP_INFO_GID
49 SPL_AC_KMEM_CACHE_CREATE_USERCOPY
50 SPL_AC_WAIT_QUEUE_ENTRY_T
51 SPL_AC_WAIT_QUEUE_HEAD_ENTRY
52 SPL_AC_IO_SCHEDULE_TIMEOUT
53 SPL_AC_KERNEL_WRITE
54 SPL_AC_KERNEL_READ
55 SPL_AC_KERNEL_TIMER_FUNCTION_TIMER_LIST
56 ])
57
58 AC_DEFUN([SPL_AC_MODULE_SYMVERS], [
59 modpost=$LINUX/scripts/Makefile.modpost
60 AC_MSG_CHECKING([kernel file name for module symbols])
61 if test "x$enable_linux_builtin" != xyes -a -f "$modpost"; then
62 if grep -q Modules.symvers $modpost; then
63 LINUX_SYMBOLS=Modules.symvers
64 else
65 LINUX_SYMBOLS=Module.symvers
66 fi
67
68 if ! test -f "$LINUX_OBJ/$LINUX_SYMBOLS"; then
69 AC_MSG_ERROR([
70 *** Please make sure the kernel devel package for your distribution
71 *** is installed. If you are building with a custom kernel, make sure the
72 *** kernel is configured, built, and the '--with-linux=PATH' configure
73 *** option refers to the location of the kernel source.])
74 fi
75 else
76 LINUX_SYMBOLS=NONE
77 fi
78 AC_MSG_RESULT($LINUX_SYMBOLS)
79 AC_SUBST(LINUX_SYMBOLS)
80 ])
81
82 AC_DEFUN([SPL_AC_KERNEL], [
83 AC_ARG_WITH([linux],
84 AS_HELP_STRING([--with-linux=PATH],
85 [Path to kernel source]),
86 [kernelsrc="$withval"])
87
88 AC_ARG_WITH([linux-obj],
89 AS_HELP_STRING([--with-linux-obj=PATH],
90 [Path to kernel build objects]),
91 [kernelbuild="$withval"])
92
93 AC_MSG_CHECKING([kernel source directory])
94 if test -z "$kernelsrc"; then
95 if test -e "/lib/modules/$(uname -r)/source"; then
96 headersdir="/lib/modules/$(uname -r)/source"
97 sourcelink=$(readlink -f "$headersdir")
98 elif test -e "/lib/modules/$(uname -r)/build"; then
99 headersdir="/lib/modules/$(uname -r)/build"
100 sourcelink=$(readlink -f "$headersdir")
101 else
102 sourcelink=$(ls -1d /usr/src/kernels/* \
103 /usr/src/linux-* \
104 2>/dev/null | grep -v obj | tail -1)
105 fi
106
107 if test -n "$sourcelink" && test -e ${sourcelink}; then
108 kernelsrc=`readlink -f ${sourcelink}`
109 else
110 kernelsrc="[Not found]"
111 fi
112 else
113 if test "$kernelsrc" = "NONE"; then
114 kernsrcver=NONE
115 fi
116 withlinux=yes
117 fi
118
119 AC_MSG_RESULT([$kernelsrc])
120 if test ! -d "$kernelsrc"; then
121 AC_MSG_ERROR([
122 *** Please make sure the kernel devel package for your distribution
123 *** is installed and then try again. If that fails, you can specify the
124 *** location of the kernel source with the '--with-linux=PATH' option.])
125 fi
126
127 AC_MSG_CHECKING([kernel build directory])
128 if test -z "$kernelbuild"; then
129 if test x$withlinux != xyes -a -e "/lib/modules/$(uname -r)/build"; then
130 kernelbuild=`readlink -f /lib/modules/$(uname -r)/build`
131 elif test -d ${kernelsrc}-obj/${target_cpu}/${target_cpu}; then
132 kernelbuild=${kernelsrc}-obj/${target_cpu}/${target_cpu}
133 elif test -d ${kernelsrc}-obj/${target_cpu}/default; then
134 kernelbuild=${kernelsrc}-obj/${target_cpu}/default
135 elif test -d `dirname ${kernelsrc}`/build-${target_cpu}; then
136 kernelbuild=`dirname ${kernelsrc}`/build-${target_cpu}
137 else
138 kernelbuild=${kernelsrc}
139 fi
140 fi
141 AC_MSG_RESULT([$kernelbuild])
142
143 AC_MSG_CHECKING([kernel source version])
144 utsrelease1=$kernelbuild/include/linux/version.h
145 utsrelease2=$kernelbuild/include/linux/utsrelease.h
146 utsrelease3=$kernelbuild/include/generated/utsrelease.h
147 if test -r $utsrelease1 && fgrep -q UTS_RELEASE $utsrelease1; then
148 utsrelease=linux/version.h
149 elif test -r $utsrelease2 && fgrep -q UTS_RELEASE $utsrelease2; then
150 utsrelease=linux/utsrelease.h
151 elif test -r $utsrelease3 && fgrep -q UTS_RELEASE $utsrelease3; then
152 utsrelease=generated/utsrelease.h
153 fi
154
155 if test "$utsrelease"; then
156 kernsrcver=`(echo "#include <$utsrelease>";
157 echo "kernsrcver=UTS_RELEASE") |
158 cpp -I $kernelbuild/include |
159 grep "^kernsrcver=" | cut -d \" -f 2`
160
161 if test -z "$kernsrcver"; then
162 AC_MSG_RESULT([Not found])
163 AC_MSG_ERROR([*** Cannot determine kernel version.])
164 fi
165 else
166 AC_MSG_RESULT([Not found])
167 if test "x$enable_linux_builtin" != xyes; then
168 AC_MSG_ERROR([*** Cannot find UTS_RELEASE definition.])
169 else
170 AC_MSG_ERROR([
171 *** Cannot find UTS_RELEASE definition.
172 *** Please run 'make prepare' inside the kernel source tree.])
173 fi
174 fi
175
176 AC_MSG_RESULT([$kernsrcver])
177
178 LINUX=${kernelsrc}
179 LINUX_OBJ=${kernelbuild}
180 LINUX_VERSION=${kernsrcver}
181
182 AC_SUBST(LINUX)
183 AC_SUBST(LINUX_OBJ)
184 AC_SUBST(LINUX_VERSION)
185
186 SPL_AC_MODULE_SYMVERS
187 ])
188
189 dnl #
190 dnl # Default SPL user configuration
191 dnl #
192 AC_DEFUN([SPL_AC_CONFIG_USER], [])
193
194 dnl #
195 dnl # Check for rpm+rpmbuild to build RPM packages. If these tools
196 dnl # are missing, it is non-fatal, but you will not be able to build
197 dnl # RPM packages and will be warned if you try too.
198 dnl #
199 dnl # By default, the generic spec file will be used because it requires
200 dnl # minimal dependencies. Distribution specific spec files can be
201 dnl # placed under the 'rpm/<distribution>' directory and enabled using
202 dnl # the --with-spec=<distribution> configure option.
203 dnl #
204 AC_DEFUN([SPL_AC_RPM], [
205 RPM=rpm
206 RPMBUILD=rpmbuild
207
208 AC_MSG_CHECKING([whether $RPM is available])
209 AS_IF([tmp=$($RPM --version 2>/dev/null)], [
210 RPM_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
211 HAVE_RPM=yes
212 AC_MSG_RESULT([$HAVE_RPM ($RPM_VERSION)])
213 ],[
214 HAVE_RPM=no
215 AC_MSG_RESULT([$HAVE_RPM])
216 ])
217
218 AC_MSG_CHECKING([whether $RPMBUILD is available])
219 AS_IF([tmp=$($RPMBUILD --version 2>/dev/null)], [
220 RPMBUILD_VERSION=$(echo $tmp | $AWK '/RPM/ { print $[3] }')
221 HAVE_RPMBUILD=yes
222 AC_MSG_RESULT([$HAVE_RPMBUILD ($RPMBUILD_VERSION)])
223 ],[
224 HAVE_RPMBUILD=no
225 AC_MSG_RESULT([$HAVE_RPMBUILD])
226 ])
227
228 RPM_DEFINE_COMMON='--define "$(DEBUG_SPL) 1"'
229 RPM_DEFINE_COMMON+=' --define "$(DEBUG_KMEM) 1"'
230 RPM_DEFINE_COMMON+=' --define "$(DEBUG_KMEM_TRACKING) 1"'
231 RPM_DEFINE_UTIL=
232 RPM_DEFINE_KMOD='--define "kernels $(LINUX_VERSION)"'
233 RPM_DEFINE_KMOD+=' --define "_wrong_version_format_terminate_build 0"'
234 RPM_DEFINE_DKMS=
235
236 SRPM_DEFINE_COMMON='--define "build_src_rpm 1"'
237 SRPM_DEFINE_UTIL=
238 SRPM_DEFINE_KMOD=
239 SRPM_DEFINE_DKMS=
240
241 RPM_SPEC_DIR="rpm/generic"
242 AC_ARG_WITH([spec],
243 AS_HELP_STRING([--with-spec=SPEC],
244 [Spec files 'generic|redhat']),
245 [RPM_SPEC_DIR="rpm/$withval"])
246
247 AC_MSG_CHECKING([whether spec files are available])
248 AC_MSG_RESULT([yes ($RPM_SPEC_DIR/*.spec.in)])
249
250 AC_SUBST(HAVE_RPM)
251 AC_SUBST(RPM)
252 AC_SUBST(RPM_VERSION)
253
254 AC_SUBST(HAVE_RPMBUILD)
255 AC_SUBST(RPMBUILD)
256 AC_SUBST(RPMBUILD_VERSION)
257
258 AC_SUBST(RPM_SPEC_DIR)
259 AC_SUBST(RPM_DEFINE_UTIL)
260 AC_SUBST(RPM_DEFINE_KMOD)
261 AC_SUBST(RPM_DEFINE_DKMS)
262 AC_SUBST(RPM_DEFINE_COMMON)
263 AC_SUBST(SRPM_DEFINE_UTIL)
264 AC_SUBST(SRPM_DEFINE_KMOD)
265 AC_SUBST(SRPM_DEFINE_DKMS)
266 AC_SUBST(SRPM_DEFINE_COMMON)
267 ])
268
269 dnl #
270 dnl # Check for dpkg+dpkg-buildpackage to build DEB packages. If these
271 dnl # tools are missing it is non-fatal but you will not be able to build
272 dnl # DEB packages and will be warned if you try too.
273 dnl #
274 AC_DEFUN([SPL_AC_DPKG], [
275 DPKG=dpkg
276 DPKGBUILD=dpkg-buildpackage
277
278 AC_MSG_CHECKING([whether $DPKG is available])
279 AS_IF([tmp=$($DPKG --version 2>/dev/null)], [
280 DPKG_VERSION=$(echo $tmp | $AWK '/Debian/ { print $[7] }')
281 HAVE_DPKG=yes
282 AC_MSG_RESULT([$HAVE_DPKG ($DPKG_VERSION)])
283 ],[
284 HAVE_DPKG=no
285 AC_MSG_RESULT([$HAVE_DPKG])
286 ])
287
288 AC_MSG_CHECKING([whether $DPKGBUILD is available])
289 AS_IF([tmp=$($DPKGBUILD --version 2>/dev/null)], [
290 DPKGBUILD_VERSION=$(echo $tmp | \
291 $AWK '/Debian/ { print $[4] }' | cut -f-4 -d'.')
292 HAVE_DPKGBUILD=yes
293 AC_MSG_RESULT([$HAVE_DPKGBUILD ($DPKGBUILD_VERSION)])
294 ],[
295 HAVE_DPKGBUILD=no
296 AC_MSG_RESULT([$HAVE_DPKGBUILD])
297 ])
298
299 AC_SUBST(HAVE_DPKG)
300 AC_SUBST(DPKG)
301 AC_SUBST(DPKG_VERSION)
302
303 AC_SUBST(HAVE_DPKGBUILD)
304 AC_SUBST(DPKGBUILD)
305 AC_SUBST(DPKGBUILD_VERSION)
306 ])
307
308 dnl #
309 dnl # Until native packaging for various different packing systems
310 dnl # can be added the least we can do is attempt to use alien to
311 dnl # convert the RPM packages to the needed package type. This is
312 dnl # a hack but so far it has worked reasonable well.
313 dnl #
314 AC_DEFUN([SPL_AC_ALIEN], [
315 ALIEN=alien
316
317 AC_MSG_CHECKING([whether $ALIEN is available])
318 AS_IF([tmp=$($ALIEN --version 2>/dev/null)], [
319 ALIEN_VERSION=$(echo $tmp | $AWK '{ print $[3] }')
320 HAVE_ALIEN=yes
321 AC_MSG_RESULT([$HAVE_ALIEN ($ALIEN_VERSION)])
322 ],[
323 HAVE_ALIEN=no
324 AC_MSG_RESULT([$HAVE_ALIEN])
325 ])
326
327 AC_SUBST(HAVE_ALIEN)
328 AC_SUBST(ALIEN)
329 AC_SUBST(ALIEN_VERSION)
330 ])
331
332 dnl #
333 dnl # Using the VENDOR tag from config.guess set the default
334 dnl # package type for 'make pkg': (rpm | deb | tgz)
335 dnl #
336 AC_DEFUN([SPL_AC_DEFAULT_PACKAGE], [
337 AC_MSG_CHECKING([linux distribution])
338 if test -f /etc/toss-release ; then
339 VENDOR=toss ;
340 elif test -f /etc/fedora-release ; then
341 VENDOR=fedora ;
342 elif test -f /etc/redhat-release ; then
343 VENDOR=redhat ;
344 elif test -f /etc/gentoo-release ; then
345 VENDOR=gentoo ;
346 elif test -f /etc/arch-release ; then
347 VENDOR=arch ;
348 elif test -f /etc/SuSE-release ; then
349 VENDOR=sles ;
350 elif test -f /etc/slackware-version ; then
351 VENDOR=slackware ;
352 elif test -f /etc/lunar.release ; then
353 VENDOR=lunar ;
354 elif test -f /etc/lsb-release ; then
355 VENDOR=ubuntu ;
356 elif test -f /etc/debian_version ; then
357 VENDOR=debian ;
358 else
359 VENDOR= ;
360 fi
361 AC_MSG_RESULT([$VENDOR])
362 AC_SUBST(VENDOR)
363
364 AC_MSG_CHECKING([default package type])
365 case "$VENDOR" in
366 toss) DEFAULT_PACKAGE=rpm ;;
367 redhat) DEFAULT_PACKAGE=rpm ;;
368 fedora) DEFAULT_PACKAGE=rpm ;;
369 gentoo) DEFAULT_PACKAGE=tgz ;;
370 arch) DEFAULT_PACKAGE=tgz ;;
371 sles) DEFAULT_PACKAGE=rpm ;;
372 slackware) DEFAULT_PACKAGE=tgz ;;
373 lunar) DEFAULT_PACKAGE=tgz ;;
374 ubuntu) DEFAULT_PACKAGE=deb ;;
375 debian) DEFAULT_PACKAGE=deb ;;
376 *) DEFAULT_PACKAGE=rpm ;;
377 esac
378
379 AC_MSG_RESULT([$DEFAULT_PACKAGE])
380 AC_SUBST(DEFAULT_PACKAGE)
381 ])
382
383 dnl #
384 dnl # Default SPL user configuration
385 dnl #
386 AC_DEFUN([SPL_AC_PACKAGE], [
387 SPL_AC_DEFAULT_PACKAGE
388 SPL_AC_RPM
389 SPL_AC_DPKG
390 SPL_AC_ALIEN
391 ])
392
393 AC_DEFUN([SPL_AC_LICENSE], [
394 AC_MSG_CHECKING([spl author])
395 AC_MSG_RESULT([$SPL_META_AUTHOR])
396
397 AC_MSG_CHECKING([spl license])
398 AC_MSG_RESULT([$SPL_META_LICENSE])
399 ])
400
401 AC_DEFUN([SPL_AC_CONFIG], [
402 SPL_CONFIG=all
403 AC_ARG_WITH([config],
404 AS_HELP_STRING([--with-config=CONFIG],
405 [Config file 'kernel|user|all|srpm']),
406 [SPL_CONFIG="$withval"])
407 AC_ARG_ENABLE([linux-builtin],
408 [AC_HELP_STRING([--enable-linux-builtin],
409 [Configure for builtin in-tree kernel modules @<:@default=no@:>@])],
410 [],
411 [enable_linux_builtin=no])
412
413 AC_MSG_CHECKING([spl config])
414 AC_MSG_RESULT([$SPL_CONFIG]);
415 AC_SUBST(SPL_CONFIG)
416
417 case "$SPL_CONFIG" in
418 kernel) SPL_AC_CONFIG_KERNEL ;;
419 user) SPL_AC_CONFIG_USER ;;
420 all) SPL_AC_CONFIG_KERNEL
421 SPL_AC_CONFIG_USER ;;
422 srpm) ;;
423 *)
424 AC_MSG_RESULT([Error!])
425 AC_MSG_ERROR([Bad value "$SPL_CONFIG" for --with-config,
426 user kernel|user|all|srpm]) ;;
427 esac
428
429 AM_CONDITIONAL([CONFIG_USER],
430 [test "$SPL_CONFIG" = user -o "$SPL_CONFIG" = all])
431 AM_CONDITIONAL([CONFIG_KERNEL],
432 [test "$SPL_CONFIG" = kernel -o "$SPL_CONFIG" = all] &&
433 [test "x$enable_linux_builtin" != xyes ])
434 ])
435
436 dnl #
437 dnl # Enable if the SPL should be compiled with internal debugging enabled.
438 dnl # By default this support is disabled.
439 dnl #
440 AC_DEFUN([SPL_AC_DEBUG], [
441 AC_MSG_CHECKING([whether debugging is enabled])
442 AC_ARG_ENABLE([debug],
443 [AS_HELP_STRING([--enable-debug],
444 [Enable generic debug support @<:@default=no@:>@])],
445 [],
446 [enable_debug=no])
447
448 AS_IF([test "x$enable_debug" = xyes],
449 [
450 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG -Werror"
451 DEBUG_CFLAGS="-DDEBUG -Werror"
452 DEBUG_SPL="_with_debug"
453 ], [
454 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DNDEBUG"
455 DEBUG_CFLAGS="-DNDEBUG"
456 DEBUG_SPL="_without_debug"
457 ])
458
459 AC_SUBST(DEBUG_CFLAGS)
460 AC_SUBST(DEBUG_SPL)
461 AC_MSG_RESULT([$enable_debug])
462 ])
463
464 dnl #
465 dnl # Enabled by default it provides a minimal level of memory tracking.
466 dnl # A total count of bytes allocated is kept for each alloc and free.
467 dnl # Then at module unload time a report to the console will be printed
468 dnl # if memory was leaked.
469 dnl #
470 AC_DEFUN([SPL_AC_DEBUG_KMEM], [
471 AC_ARG_ENABLE([debug-kmem],
472 [AS_HELP_STRING([--enable-debug-kmem],
473 [Enable basic kmem accounting @<:@default=no@:>@])],
474 [],
475 [enable_debug_kmem=no])
476
477 AS_IF([test "x$enable_debug_kmem" = xyes],
478 [
479 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM"
480 DEBUG_KMEM="_with_debug_kmem"
481 AC_DEFINE([DEBUG_KMEM], [1],
482 [Define to 1 to enable basic kmem accounting])
483 ], [
484 DEBUG_KMEM="_without_debug_kmem"
485 ])
486
487 AC_SUBST(DEBUG_KMEM)
488 AC_MSG_CHECKING([whether basic kmem accounting is enabled])
489 AC_MSG_RESULT([$enable_debug_kmem])
490 ])
491
492 dnl #
493 dnl # Disabled by default it provides detailed memory tracking. This
494 dnl # feature also requires --enable-debug-kmem to be set. When enabled
495 dnl # not only will total bytes be tracked but also the location of every
496 dnl # alloc and free. When the SPL module is unloaded a list of all leaked
497 dnl # addresses and where they were allocated will be dumped to the console.
498 dnl # Enabling this feature has a significant impact on performance but it
499 dnl # makes finding memory leaks pretty straight forward.
500 dnl #
501 AC_DEFUN([SPL_AC_DEBUG_KMEM_TRACKING], [
502 AC_ARG_ENABLE([debug-kmem-tracking],
503 [AS_HELP_STRING([--enable-debug-kmem-tracking],
504 [Enable detailed kmem tracking @<:@default=no@:>@])],
505 [],
506 [enable_debug_kmem_tracking=no])
507
508 AS_IF([test "x$enable_debug_kmem_tracking" = xyes],
509 [
510 KERNELCPPFLAGS="${KERNELCPPFLAGS} -DDEBUG_KMEM_TRACKING"
511 DEBUG_KMEM_TRACKING="_with_debug_kmem_tracking"
512 AC_DEFINE([DEBUG_KMEM_TRACKING], [1],
513 [Define to 1 to enable detailed kmem tracking])
514 ], [
515 DEBUG_KMEM_TRACKING="_without_debug_kmem_tracking"
516 ])
517
518 AC_SUBST(DEBUG_KMEM_TRACKING)
519 AC_MSG_CHECKING([whether detailed kmem tracking is enabled])
520 AC_MSG_RESULT([$enable_debug_kmem_tracking])
521 ])
522
523 dnl #
524 dnl # SPL_LINUX_CONFTEST
525 dnl #
526 AC_DEFUN([SPL_LINUX_CONFTEST], [
527 cat confdefs.h - <<_ACEOF >conftest.c
528 $1
529 _ACEOF
530 ])
531
532 dnl #
533 dnl # SPL_LANG_PROGRAM(C)([PROLOGUE], [BODY])
534 dnl #
535 m4_define([SPL_LANG_PROGRAM], [
536 $1
537 int
538 main (void)
539 {
540 dnl Do *not* indent the following line: there may be CPP directives.
541 dnl Don't move the `;' right after for the same reason.
542 $2
543 ;
544 return 0;
545 }
546 ])
547
548 dnl #
549 dnl # SPL_LINUX_COMPILE_IFELSE / like AC_COMPILE_IFELSE
550 dnl #
551 AC_DEFUN([SPL_LINUX_COMPILE_IFELSE], [
552 m4_ifvaln([$1], [SPL_LINUX_CONFTEST([$1])])
553 rm -Rf build && mkdir -p build && touch build/conftest.mod.c
554 echo "obj-m := conftest.o" >build/Makefile
555 modpost_flag=''
556 test "x$enable_linux_builtin" = xyes && modpost_flag='modpost=true' # fake modpost stage
557 AS_IF(
558 [AC_TRY_COMMAND(cp conftest.c build && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build $modpost_flag) >/dev/null && AC_TRY_COMMAND([$3])],
559 [$4],
560 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
561 )
562 rm -Rf build
563 ])
564
565 dnl #
566 dnl # SPL_LINUX_TRY_COMPILE like AC_TRY_COMPILE
567 dnl #
568 AC_DEFUN([SPL_LINUX_TRY_COMPILE],
569 [SPL_LINUX_COMPILE_IFELSE(
570 [AC_LANG_SOURCE([SPL_LANG_PROGRAM([[$1]], [[$2]])])],
571 [modules],
572 [test -s build/conftest.o],
573 [$3], [$4])
574 ])
575
576 dnl #
577 dnl # SPL_CHECK_SYMBOL_EXPORT
578 dnl # check symbol exported or not
579 dnl #
580 AC_DEFUN([SPL_CHECK_SYMBOL_EXPORT], [
581 grep -q -E '[[[:space:]]]$1[[[:space:]]]' \
582 $LINUX_OBJ/Module*.symvers 2>/dev/null
583 rc=$?
584 if test $rc -ne 0; then
585 export=0
586 for file in $2; do
587 grep -q -E "EXPORT_SYMBOL.*($1)" \
588 "$LINUX_OBJ/$file" 2>/dev/null
589 rc=$?
590 if test $rc -eq 0; then
591 export=1
592 break;
593 fi
594 done
595 if test $export -eq 0; then :
596 $4
597 else :
598 $3
599 fi
600 else :
601 $3
602 fi
603 ])
604
605 dnl #
606 dnl # SPL_LINUX_TRY_COMPILE_SYMBOL
607 dnl # like SPL_LINUX_TRY_COMPILE, except SPL_CHECK_SYMBOL_EXPORT
608 dnl # is called if not compiling for builtin
609 dnl #
610 AC_DEFUN([SPL_LINUX_TRY_COMPILE_SYMBOL], [
611 SPL_LINUX_TRY_COMPILE([$1], [$2], [rc=0], [rc=1])
612 if test $rc -ne 0; then :
613 $6
614 else
615 if test "x$enable_linux_builtin" != xyes; then
616 SPL_CHECK_SYMBOL_EXPORT([$3], [$4], [rc=0], [rc=1])
617 fi
618 if test $rc -ne 0; then :
619 $6
620 else :
621 $5
622 fi
623 fi
624 ])
625
626 dnl #
627 dnl # SPL_CHECK_SYMBOL_HEADER
628 dnl # check if a symbol prototype is defined in listed headers.
629 dnl #
630 AC_DEFUN([SPL_CHECK_SYMBOL_HEADER], [
631 AC_MSG_CHECKING([whether symbol $1 exists in header])
632 header=0
633 for file in $3; do
634 grep -q "$2" "$LINUX/$file" 2>/dev/null
635 rc=$?
636 if test $rc -eq 0; then
637 header=1
638 break;
639 fi
640 done
641 if test $header -eq 0; then
642 AC_MSG_RESULT([no])
643 $5
644 else
645 AC_MSG_RESULT([yes])
646 $4
647 fi
648 ])
649
650 dnl #
651 dnl # SPL_CHECK_HEADER
652 dnl # check whether header exists and define HAVE_$2_HEADER
653 dnl #
654 AC_DEFUN([SPL_CHECK_HEADER],
655 [AC_MSG_CHECKING([whether header $1 exists])
656 SPL_LINUX_TRY_COMPILE([
657 #include <$1>
658 ],[
659 return 0;
660 ],[
661 AC_DEFINE(HAVE_$2_HEADER, 1, [$1 exists])
662 AC_MSG_RESULT(yes)
663 $3
664 ],[
665 AC_MSG_RESULT(no)
666 $4
667 ])
668 ])
669
670 dnl #
671 dnl # Basic toolchain sanity check. Verify that kernel modules can
672 dnl # be built and which symbols can be used.
673 dnl #
674 AC_DEFUN([SPL_AC_TEST_MODULE],
675 [AC_MSG_CHECKING([whether modules can be built])
676 SPL_LINUX_TRY_COMPILE([],[],[
677 AC_MSG_RESULT([yes])
678 ],[
679 AC_MSG_RESULT([no])
680 if test "x$enable_linux_builtin" != xyes; then
681 AC_MSG_ERROR([*** Unable to build an empty module.])
682 else
683 AC_MSG_ERROR([
684 *** Unable to build an empty module.
685 *** Please run 'make scripts' inside the kernel source tree.])
686 fi
687 ])
688
689 AS_IF([test "x$cross_compiling" != xyes], [
690 AC_RUN_IFELSE([
691 AC_LANG_PROGRAM([
692 #include "$LINUX/include/linux/license.h"
693 ], [
694 return !license_is_gpl_compatible(
695 "$SPL_META_LICENSE");
696 ])
697 ], [
698 AC_DEFINE([SPL_IS_GPL_COMPATIBLE], [1],
699 [Define to 1 if GPL-only symbols can be used])
700 ], [
701 ])
702 ])
703 ])
704
705 dnl #
706 dnl # Use the atomic implemenation based on global spinlocks. This
707 dnl # should only be needed by 32-bit kernels which do not provide
708 dnl # the atomic64_* API. It may be optionally enabled as a fallback
709 dnl # if problems are observed with the direct mapping to the native
710 dnl # Linux atomic operations. You may not disable atomic spinlocks
711 dnl # if you kernel does not an atomic64_* API.
712 dnl #
713 AC_DEFUN([SPL_AC_ATOMIC_SPINLOCK], [
714 AC_ARG_ENABLE([atomic-spinlocks],
715 [AS_HELP_STRING([--enable-atomic-spinlocks],
716 [Atomic types use spinlocks @<:@default=check@:>@])],
717 [],
718 [enable_atomic_spinlocks=check])
719
720 SPL_LINUX_TRY_COMPILE([
721 #include <linux/fs.h>
722 ],[
723 atomic64_t *ptr __attribute__ ((unused));
724 ],[
725 have_atomic64_t=yes
726 AC_DEFINE(HAVE_ATOMIC64_T, 1,
727 [kernel defines atomic64_t])
728 ],[
729 have_atomic64_t=no
730 ])
731
732 AS_IF([test "x$enable_atomic_spinlocks" = xcheck], [
733 AS_IF([test "x$have_atomic64_t" = xyes], [
734 enable_atomic_spinlocks=no
735 ],[
736 enable_atomic_spinlocks=yes
737 ])
738 ])
739
740 AS_IF([test "x$enable_atomic_spinlocks" = xyes], [
741 AC_DEFINE([ATOMIC_SPINLOCK], [1],
742 [Atomic types use spinlocks])
743 ],[
744 AS_IF([test "x$have_atomic64_t" = xno], [
745 AC_MSG_FAILURE(
746 [--disable-atomic-spinlocks given but required atomic64 support is unavailable])
747 ])
748 ])
749
750 AC_MSG_CHECKING([whether atomic types use spinlocks])
751 AC_MSG_RESULT([$enable_atomic_spinlocks])
752
753 AC_MSG_CHECKING([whether kernel defines atomic64_t])
754 AC_MSG_RESULT([$have_atomic64_t])
755 ])