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