Whamcloud - gitweb
LU-1812 fsfilt: ext4_free_blocks() has changed slightly
[fs/lustre-release.git] / ldiskfs / config / ldiskfs-build.m4
1 AC_DEFUN([LDISKFS_AC_LINUX_VERSION], [
2         AC_MSG_CHECKING([kernel source version])
3
4         utsrelease1=${LINUX_OBJ}/include/linux/version.h
5         utsrelease2=${LINUX_OBJ}/include/linux/utsrelease.h
6         utsrelease3=${LINUX_OBJ}/include/generated/utsrelease.h
7         AS_IF([test -r ${utsrelease1} && fgrep -q UTS_RELEASE ${utsrelease1}], [
8                 utsrelease=linux/version.h
9         ], [test -r ${utsrelease2} && fgrep -q UTS_RELEASE ${utsrelease2}], [
10                 utsrelease=linux/utsrelease.h
11         ], [test -r ${utsrelease3} && fgrep -q UTS_RELEASE ${utsrelease3}], [
12                 utsrelease=generated/utsrelease.h
13         ])
14
15         AS_IF([test "${utsrelease}"], [
16                 kernsrcver=$((echo "#include <$utsrelease>";
17                              echo "kernsrcver=UTS_RELEASE") |
18                              cpp -I ${LINUX_OBJ}/include |
19                              grep "^kernsrcver=" | cut -d \" -f 2)
20
21                 AS_IF([test -z "$kernsrcver"], [
22                         AC_MSG_RESULT([Not found])
23                         AC_MSG_ERROR([*** Cannot determine kernel version.])
24                 ])
25         ], [
26                 AC_MSG_RESULT([Not found])
27                 AC_MSG_ERROR([
28         *** Cannot find UTS_RELEASE definition.
29         *** This is often provided by the kernel-devel package.])
30         ])
31
32         AC_MSG_RESULT([${kernsrcver}])
33
34         LINUX_VERSION=${kernsrcver}
35         AC_SUBST(LINUX_VERSION)
36         LINUXRELEASE=${kernsrcver}
37         AC_SUBST(LINUXRELEASE)
38 ])
39
40 #
41 # LB_LINUX_RELEASE
42 #
43 # get the release version of linux
44 #
45
46 AC_DEFUN([LB_LINUX_RELEASE],
47 [
48 LDISKFS_AC_LINUX_VERSION
49
50 # ------------ RELEASE --------------------------------
51 AC_MSG_CHECKING([for ldiskfs release])
52 AC_ARG_WITH([release],
53         AC_HELP_STRING([--with-release=string],
54                        [set the release string (default=$kvers_YYYYMMDDhhmm)]),
55         [RELEASE=$withval],
56         RELEASE=""
57         if test -n "$DOWNSTREAM_RELEASE"; then
58                 RELEASE="${DOWNSTREAM_RELEASE}_"
59         fi
60         RELEASE="$RELEASE`echo ${LINUXRELEASE} | tr '-' '_'`_$BUILDID")
61 AC_MSG_RESULT($RELEASE)
62 AC_SUBST(RELEASE)
63
64 # check is redhat/suse kernels
65 AC_MSG_CHECKING([that RedHat kernel])
66 LB_LINUX_TRY_COMPILE([
67                 #include <linux/version.h>
68         ],[
69                 #ifndef RHEL_RELEASE_CODE
70                 #error "not redhat kernel"
71                 #endif
72         ],[
73                 RHEL_KERNEL="yes"
74                 AC_MSG_RESULT([yes])
75         ],[
76                 AC_MSG_RESULT([no])
77 ])
78
79 LB_LINUX_CONFIG([SUSE_KERNEL],[SUSE_KERNEL="yes"],[])
80
81 ])
82
83 # LB_ARG_REPLACE_PATH(PACKAGE, PATH)
84 AC_DEFUN([LB_ARG_REPLACE_PATH],[
85         new_configure_args=
86         eval "set x $ac_configure_args"
87         shift
88         for arg; do
89                 case $arg in
90                         --with-[$1]=*)
91                                 arg=--with-[$1]=[$2]
92                                 ;;
93                         *\'*)
94                                 arg=$(printf %s\n ["$arg"] | \
95                                       sed "s/'/'\\\\\\\\''/g")
96                                 ;;
97                 esac
98                 dnl AS_VAR_APPEND([new_configure_args], [" '$arg'"])
99                 new_configure_args="$new_configure_args \"$arg\""
100         done
101         ac_configure_args=$new_configure_args
102 ])
103
104 # this is the work-horse of the next function
105 AC_DEFUN([__LB_ARG_CANON_PATH], [
106         [$3]=$(readlink -f $with_$2)
107         LB_ARG_REPLACE_PATH([$1], $[$3])
108 ])
109
110 # a front-end for the above function that transforms - and . in the
111 # PACKAGE portion of --with-PACKAGE into _ suitable for variable names
112 AC_DEFUN([LB_ARG_CANON_PATH], [
113         __LB_ARG_CANON_PATH([$1], m4_translit([$1], [-.], [__]), [$2])
114 ])
115
116 #
117 #
118 # LB_LINUX_PATH
119 #
120 # Find paths for linux, handling kernel-source rpms
121 #
122 AC_DEFUN([LB_LINUX_PATH],
123 [# prep some default values
124 for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do
125         if readlink -q -e $DEFAULT_LINUX; then
126                 break
127         fi
128 done
129 if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then
130         PATHS="/lib/modules/$(uname -r)/build"
131 fi
132 PATHS+=" $DEFAULT_LINUX"
133 for DEFAULT_LINUX_OBJ in $PATHS; do
134         if readlink -q -e $DEFAULT_LINUX_OBJ; then
135                 break
136         fi
137 done
138 AC_MSG_CHECKING([for Linux sources])
139 AC_ARG_WITH([linux],
140         AC_HELP_STRING([--with-linux=path],
141                        [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]),
142         [LB_ARG_CANON_PATH([linux], [LINUX])
143         DEFAULT_LINUX_OBJ=$LINUX],
144         [LINUX=$DEFAULT_LINUX])
145 AC_MSG_RESULT([$LINUX])
146 AC_SUBST(LINUX)
147
148 # -------- check for linux --------
149 LB_CHECK_FILE([$LINUX],[],
150         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
151
152 # -------- linux objects (for 2.6) --
153 AC_MSG_CHECKING([for Linux objects dir])
154 AC_ARG_WITH([linux-obj],
155         AC_HELP_STRING([--with-linux-obj=path],
156                         [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]),
157         [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])],
158         [LINUX_OBJ=$DEFAULT_LINUX_OBJ])
159
160 AC_MSG_RESULT([$LINUX_OBJ])
161 AC_SUBST(LINUX_OBJ)
162
163 # -------- check for .config --------
164 AC_ARG_WITH([linux-config],
165         [AC_HELP_STRING([--with-linux-config=path],
166                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
167         [LB_ARG_CANON_PATH([linux-config], [LINUX_CONFIG])],
168         [LINUX_CONFIG=$LINUX_OBJ/.config])
169 AC_SUBST(LINUX_CONFIG)
170
171 LB_CHECK_FILE([/boot/kernel.h],
172         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
173         [LB_CHECK_FILE([/var/adm/running-kernel.h],
174                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
175
176 AC_ARG_WITH([kernel-source-header],
177         AC_HELP_STRING([--with-kernel-source-header=path],
178                         [Use a different kernel version header.  Consult build/README.kernel-source for details.]),
179         [LB_ARG_CANON_PATH([kernel-source-header], [KERNEL_SOURCE_HEADER])])
180
181 # ------------ .config exists ----------------
182 LB_CHECK_FILE([$LINUX_CONFIG],[],
183         [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult build/README.kernel-source])])
184
185 # ----------- make dep run? ------------------
186 # at 2.6.19 # $LINUX/include/linux/config.h is removed
187 # and at more old has only one line
188 # include <autoconf.h>
189 LB_CHECK_FILE([$LINUX_OBJ/include/generated/autoconf.h],[AUTOCONF_HDIR=generated],
190         [LB_CHECK_FILE([$LINUX_OBJ/include/linux/autoconf.h],[AUTOCONF_HDIR=linux],
191         [AC_MSG_ERROR([Run make config in $LINUX.])])])
192         AC_SUBST(AUTOCONF_HDIR)
193 LB_CHECK_FILE([$LINUX_OBJ/include/linux/version.h],[],
194         [AC_MSG_ERROR([Run make config in $LINUX.])])
195
196 # ----------- kconfig.h exists ---------------
197 # kernel 3.1, $LINUX/include/linux/kconfig.h is added
198 # see kernel commit 2a11c8ea20bf850b3a2c60db8c2e7497d28aba99
199 LB_CHECK_FILE([$LINUX_OBJ/include/linux/kconfig.h],
200               [CONFIG_INCLUDE=include/linux/kconfig.h],
201               [CONFIG_INCLUDE=include/$AUTOCONF_HDIR/autoconf.h])
202         AC_SUBST(CONFIG_INCLUDE)
203
204 # ------------ rhconfig.h includes runtime-generated bits --
205 # red hat kernel-source checks
206
207 # we know this exists after the check above.  if the user
208 # tarred up the tree and ran make dep etc. in it, then
209 # version.h gets overwritten with a standard linux one.
210
211 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
212         # This is a clean kernel-source tree, we need to
213         # enable extensive workarounds to get this to build
214         # modules
215         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
216                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
217                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
218                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
219                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
220                 fi],
221                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
222         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
223 fi
224
225 # --- check that we can build modules at all
226 AC_MSG_CHECKING([that modules can be built at all])
227 LB_LINUX_TRY_COMPILE([],[],[
228         AC_MSG_RESULT([yes])
229 ],[
230         AC_MSG_RESULT([no])
231         AC_MSG_WARN([Consult config.log for details.])
232         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
233         AC_MSG_ERROR([Kernel modules cannot be built.])
234 ])
235
236 LB_LINUX_RELEASE
237 ]) # end of LB_LINUX_PATH
238
239 # LB_LINUX_SYMVERFILE
240 # SLES 9 uses a different name for this file - unsure about vanilla kernels
241 # around this version, but it matters for servers only.
242 AC_DEFUN([LB_LINUX_SYMVERFILE],
243         [AC_MSG_CHECKING([name of module symbol version file])
244         if grep -q Modules.symvers $LINUX/scripts/Makefile.modpost ; then
245                 SYMVERFILE=Modules.symvers
246         else
247                 SYMVERFILE=Module.symvers
248         fi
249         AC_MSG_RESULT($SYMVERFILE)
250         AC_SUBST(SYMVERFILE)
251 ])
252
253 # these are like AC_TRY_COMPILE, but try to build modules against the
254 # kernel, inside the build directory
255
256 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
257 # --------------------------------------
258 m4_define([LB_LANG_PROGRAM],
259 [
260 #include <linux/kernel.h>
261 $1
262 int
263 main (void)
264 {
265 dnl Do *not* indent the following line: there may be CPP directives.
266 dnl Don't move the `;' right after for the same reason.
267 $2
268   ;
269   return 0;
270 }])
271
272 #
273 # LB_LINUX_COMPILE_IFELSE
274 #
275 # like AC_COMPILE_IFELSE
276 #
277 AC_DEFUN([LB_LINUX_COMPILE_IFELSE], [
278         m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])
279         rm -Rf build-test && mkdir -p build-test
280         echo "obj-m := conftest.o" >build-test/Makefile
281         AS_IF(
282                 [AC_TRY_COMMAND(cp conftest.c build-test && make [$2] -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" M=$PWD/build-test) >/dev/null && AC_TRY_COMMAND([$3])],
283                 [$4],
284                 [_AC_MSG_LOG_CONFTEST m4_ifvaln([$5],[$5])]
285         )
286         rm -Rf build-test
287 ])
288
289
290 #
291 # LB_LINUX_TRY_COMPILE
292 #
293 # like AC_TRY_COMPILE
294 #
295 AC_DEFUN([LB_LINUX_TRY_COMPILE],
296 [LB_LINUX_COMPILE_IFELSE(
297         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
298         [modules],
299         [test -s build-test/conftest.o],
300         [$3], [$4])])
301
302 #
303 # LB_LINUX_CONFIG
304 #
305 # check if a given config option is defined
306 #
307 AC_DEFUN([LB_LINUX_CONFIG],[
308         AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
309         LB_LINUX_TRY_COMPILE([
310                 #include <$AUTOCONF_HDIR/autoconf.h>
311         ],[
312                 #ifndef CONFIG_$1
313                 #error CONFIG_$1 not #defined
314                 #endif
315         ],[
316                 AC_MSG_RESULT([yes])
317                 $2
318         ],[
319                 AC_MSG_RESULT([no])
320                 $3
321         ])
322 ])
323
324 #
325 # LB_LINUX_CONFIG_IM
326 #
327 # check if a given config option is builtin or as module
328 #
329 AC_DEFUN([LB_LINUX_CONFIG_IM],[
330         AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
331         LB_LINUX_TRY_COMPILE([
332                 #include <$AUTOCONF_HDIR/autoconf.h>
333         ],[
334                 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
335                 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
336                 #endif
337         ],[
338                 AC_MSG_RESULT([yes])
339                 $2
340         ],[
341                 AC_MSG_RESULT([no])
342                 $3
343         ])
344 ])
345
346 #
347 # LB_CHECK_SYMBOL_EXPORT
348 # check symbol exported or not
349 # $1 - symbol
350 # $2 - file(s) for find.
351 # $3 - do 'yes'
352 # $4 - do 'no'
353 #
354 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
355 # or check
356 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
357 [AC_MSG_CHECKING([if Linux was built with symbol $1 exported])
358 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/$SYMVERFILE 2>/dev/null
359 rc=$?
360 if test $rc -ne 0; then
361         export=0
362         for file in $2; do
363                 grep -q -E "EXPORT_SYMBOL.*\($1\)" "$LINUX/$file" 2>/dev/null
364                 rc=$?
365                 if test $rc -eq 0; then
366                         export=1
367                         break;
368                 fi
369         done
370         if test $export -eq 0; then
371                 AC_MSG_RESULT([no])
372                 $4
373         else
374                 AC_MSG_RESULT([yes])
375                 $3
376         fi
377 else
378         AC_MSG_RESULT([yes])
379         $3
380 fi
381 ])
382
383 #
384 # Like AC_CHECK_HEADER but checks for a kernel-space header
385 #
386 m4_define([LB_CHECK_LINUX_HEADER],
387 [AS_VAR_PUSHDEF([ac_Header], [ac_cv_header_$1])dnl
388 AC_CACHE_CHECK([for $1], ac_Header,
389                [LB_LINUX_COMPILE_IFELSE([LB_LANG_PROGRAM([@%:@include <$1>])],
390                                   [modules],
391                                   [test -s build-test/conftest.o],
392                                   [AS_VAR_SET(ac_Header, [yes])],
393                                   [AS_VAR_SET(ac_Header, [no])])])
394 AS_IF([test AS_VAR_GET(ac_Header) = yes], [$2], [$3])[]dnl
395 AS_VAR_POPDEF([ac_Header])dnl
396 ])
397 #
398 # LB_DOWNSTREAM_RELEASE
399 #
400 AC_DEFUN([LB_DOWNSTREAM_RELEASE],
401 [AC_ARG_WITH([downstream-release],
402         AC_HELP_STRING([--with-downstream-release=string],
403                        [set a string in the BUILD_VERSION and RPM Release: (default is nothing)]),
404         [DOWNSTREAM_RELEASE=$with_downstream_release],
405         [
406         # if not specified, see if it's in the META file
407         if test -f META; then
408                 DOWNSTREAM_RELEASE=$(sed -ne '/^LOCAL_VERSION =/s/.*= *//p' META)
409         fi
410         ])
411 AC_SUBST(DOWNSTREAM_RELEASE)
412 ])
413
414 #
415 # LB_BUILDID
416 #
417 # Check if the source is a GA release and if not, set a "BUILDID"
418 #
419 # Currently there are at least two ways/modes of/for doing this.  One
420 # is if we are in a valid git repository, the other is if we are in a
421 # non-git source tree of some form.  Building the latter from the former
422 # will be handled here.
423 AC_DEFUN([LB_BUILDID],
424 [
425 AC_MSG_CHECKING([for buildid])
426 BUILDID=""
427 if git branch >/dev/null 2>&1; then
428         ffw=0
429         hash=""
430         ver=$(git describe --match v[[0-9]]_*_[[0-9]]* --tags)
431         if [[[ $ver = *-*-* ]]]; then
432                 hash=${ver##*-}
433                 ffw=${ver#*-}
434                 ffw=${ffw%-*}
435                 ver=${ver%%-*}
436         fi
437         # it's tempting to use [[ $ver =~ ^v([0-9]+_)+([0-9]+|RC[0-9]+)$ ]]
438         # here but the portability of the regex on the right is dismal
439         # (thanx suse)
440         if echo "$ver" | egrep -q "^v([[0-9]]+_)+([[0-9]]+|RC[[0-9]]+)$"; then
441                 ver=$(echo $ver | sed -e 's/^v\(.*\)/\1/' \
442                                       -e 's/_RC[[0-9]].*$//' -e 's/_/./g')
443         fi
444
445         # a "lustre fix" value of .0 should be truncated
446         if [[[ $ver = *.*.*.0 ]]]; then
447                 ver=${ver%.0}
448         fi
449         # ditto for a "lustre fix" value of _0
450         if [[[ $ver = v*_*_*_0 ]]]; then
451                 ver=${ver%_0}
452         fi
453         if [[[ $ver = v*_*_* ]]]; then
454                 ver=${ver#v}
455                 ver=${ver//_/.}
456         fi
457
458         if test "$ffw" != "0"; then
459                 BUILDID="$hash"
460                 msg="$BUILDID (ahead by $ffw commits)"
461                 AC_MSG_RESULT([$msg])
462         else
463                 AC_MSG_RESULT([none... congratulations, you must be on a tag])
464         fi
465 elif test -f META; then
466         BUILDID=$(sed -ne '/^BUILDID =/s/.*= *//p' META)
467         msg="$BUILDID (from META file)"
468         AC_MSG_RESULT([$msg])
469 else
470         AC_MSG_WARN([FIXME: I don't know how to deal with source trees outside of git that don't have a META file.  Not setting a buildid.])
471 fi
472 AC_SUBST(BUILDID)
473 ])
474
475 #
476 # LB_CHECK_FILE
477 #
478 # Check for file existance even when cross compiling
479 #
480 AC_DEFUN([LB_CHECK_FILE],
481 [AS_VAR_PUSHDEF([lb_File], [lb_cv_file_$1])dnl
482 AC_CACHE_CHECK([for $1], lb_File,
483 [if test -r "$1"; then
484         AS_VAR_SET(lb_File, yes)
485 else
486         AS_VAR_SET(lb_File, no)
487 fi])
488 AS_IF([test AS_VAR_GET(lb_File) = yes], [$2], [$3])[]dnl
489 AS_VAR_POPDEF([lb_File])dnl
490 ])# LB_CHECK_FILE
491
492 #
493 # LB_CONFIG_HEADERS
494 #
495 # add -include config.h
496 #
497 AC_DEFUN([LB_CONFIG_HEADERS],[
498         AC_CONFIG_HEADERS([config.h ldiskfs/ldiskfs_config.h])
499         CPPFLAGS="-include $PWD/config.h $CPPFLAGS"
500         EXTRA_KCFLAGS="-include $PWD/config.h $EXTRA_KCFLAGS"
501         AC_SUBST(EXTRA_KCFLAGS)
502 ])
503
504 #
505 # LB_PROG_CC
506 #
507 # checks on the C compiler
508 #
509 AC_DEFUN([LB_PROG_CC],
510 [AC_PROG_RANLIB
511
512 # ---------  unsigned long long sane? -------
513 AC_CHECK_SIZEOF(unsigned long long, 0)
514 echo "---> size SIZEOF $SIZEOF_unsigned_long_long"
515 echo "---> size SIZEOF $ac_cv_sizeof_unsigned_long_long"
516 if test $ac_cv_sizeof_unsigned_long_long != 8 ; then
517         AC_MSG_ERROR([** we assume that sizeof(long long) == 8.])
518 fi
519
520 if test $target_cpu == "powerpc64"; then
521         AC_MSG_WARN([set compiler with -m64])
522         CFLAGS="$CFLAGS -m64"
523         CC="$CC -m64"
524 fi
525
526 LLCPPFLAGS="-D__arch_lib__ -D_LARGEFILE64_SOURCE=1"
527 AC_SUBST(LLCPPFLAGS)
528
529 # Add _GNU_SOURCE for strnlen on linux
530 LLCFLAGS="-g -Wall -fPIC -D_GNU_SOURCE"
531 AC_SUBST(LLCFLAGS)
532
533 CCASFLAGS="-Wall -fPIC -D_GNU_SOURCE"
534 AC_SUBST(CCASFLAGS)
535 ])
536
537
538 #
539 # LB_LDISKFS_EXT_DIR
540 #
541 # Determine the location of the ext4 source code.  It is required
542 # for several configure tests and to build ldiskfs.
543 #
544 AC_DEFUN([LB_LDISKFS_EXT_DIR],
545 [
546 # Kernel ext source located with devel headers
547 linux_src=$LINUX
548 if test -e "$linux_src/fs/ext4/super.c"; then
549         EXT_DIR=$linux_src/fs/ext4
550 else
551         # Kernel ext source provided by kernel-debuginfo-common package
552         linux_src=$(ls -1d /usr/src/debug/*/linux-$LINUXRELEASE \
553                 2>/dev/null | tail -1)
554         if test -e "$linux_src/fs/ext4/super.c"; then
555                 EXT_DIR=$linux_src/fs/ext4
556         else
557                 EXT_DIR=
558         fi
559 fi
560
561 AC_MSG_CHECKING([ext4 source directory])
562 AC_MSG_RESULT([$EXT_DIR])
563 AC_SUBST(EXT_DIR)
564 ])
565
566 #
567 # LB_LDISKFS_EXT_SOURCE
568 #
569 # Spot check the existance of several source files common to ext4.
570 # Detecting this at configure time allows us to avoid a potential build
571 # failure and provide a useful error message to explain what is wrong.
572 #
573 AC_DEFUN([LB_LDISKFS_EXT_SOURCE],
574 [
575 if test x$EXT_DIR = x; then
576         enable_ldiskfs_build='no'
577 else
578         LB_CHECK_FILE([$EXT_DIR/dir.c], [], [
579                 enable_ldiskfs_build='no'
580                 AC_MSG_WARN([ext4 must exist for ldiskfs build])])
581         LB_CHECK_FILE([$EXT_DIR/file.c], [], [
582                 enable_ldiskfs_build='no'
583                 AC_MSG_WARN([ext4 must exist for ldiskfs build])])
584         LB_CHECK_FILE([$EXT_DIR/inode.c], [], [
585                 enable_ldiskfs_build='no'
586                 AC_MSG_WARN([ext4 must exist for ldiskfs build])])
587         LB_CHECK_FILE([$EXT_DIR/super.c], [], [
588                 enable_ldiskfs_build='no'
589                 AC_MSG_WARN([ext4 must exist for ldiskfs build])])
590 fi
591
592 if test x$enable_ldiskfs_build = xno; then
593         enable_server='no'
594         enable_ldiskfs_build='no'
595         with_ldiskfs='no'
596         LDISKFS_SUBDIR=
597
598         AC_MSG_WARN([
599
600 Disabling server because complete ext4 source does not exist.
601
602 If you are building using kernel-devel packages and require ldiskfs
603 server support then ensure that the matching kernel-debuginfo-common
604 and kernel-debuginfo-common-<arch> packages are installed.
605
606 ])
607
608 fi
609 ])
610
611 AC_DEFUN([LB_LDISKFS_SYMVERS],
612 [
613 AC_MSG_CHECKING([ldiskfs module symbols])
614 if test -r $LDISKFS_OBJ/Module.symvers; then
615         LDISKFS_SYMBOLS=Module.symvers
616 elif test -r $LDISKFS_OBJ/Modules.symvers; then
617         LDISKFS_SYMBOLS=Modules.symvers
618 elif test -r $LDISKFS_OBJ/ldiskfs/Module.symvers; then
619         LDISKFS_SYMBOLS=Module.symvers
620 elif test -r $LDISKFS_OBJ/ldiskfs/Modules.symvers; then
621         LDISKFS_SYMBOLS=Modules.symvers
622 else
623         LDISKFS_SYMBOLS=$SYMVERFILE
624 fi
625
626 AC_MSG_RESULT([$LDISKFS_SYMBOLS])
627 AC_SUBST(LDISKFS_SYMBOLS)
628 ])
629
630 AC_DEFUN([LB_LDISKFS_RELEASE],
631 [
632 AC_MSG_CHECKING([ldiskfs source release])
633 if test -r $LDISKFS_OBJ/config.h; then
634         tmp_flags="$EXTRA_KCFLAGS"
635         EXTRA_KCFLAGS="-I$LDISKFS_DIR $EXTRA_KCFLAGS"
636         LB_LINUX_TRY_MAKE([
637                 #undef PACKAGE_NAME
638                 #undef PACKAGE_TARNAME
639                 #undef PACKAGE_VERSION
640                 #undef PACKAGE_STRING
641                 #undef PACKAGE_BUGREPORT
642                 #undef PACKAGE
643                 #undef VERSION
644                 #undef STDC_HEADERS
645
646                 #include <$LDISKFS_OBJ/config.h>
647         ],[
648                 char *LDISKFS_RELEASE;
649                 LDISKFS_RELEASE=VERSION;
650         ],[
651                 $makerule LUSTRE_KERNEL_TEST=conftest.i
652         ],[
653                 test -s build/conftest.i
654         ],[
655                 eval $(grep "LDISKFS_RELEASE=" build/conftest.i)
656         ],[
657                 AC_MSG_RESULT([unknown])
658                 AC_MSG_ERROR([Could not preprocess test program.])
659         ])
660         EXTRA_KCFLAGS="$tmp_flags"
661         rm build/conftest.i
662 elif test -r $LDISKFS_DIR/configure.ac; then
663         LDISKFS_RELEASE=$(awk '/AC\_INIT/ { print [$]3 }' \
664                  $LDISKFS_DIR/configure.ac | tr ',' '\n')
665 else
666         AC_MSG_RESULT([unknown])
667         AC_MSG_ERROR([Could not locate config.h, META, or configure.ac to check release.])
668 fi
669
670 if test x$LDISKFS_RELEASE = x; then
671         AC_MSG_RESULT([unknown])
672         AC_MSG_ERROR([Could not determine ldiskfs release.])
673 fi
674
675 AC_MSG_RESULT([$LDISKFS_RELEASE])
676 AC_SUBST(LDISKFS_RELEASE)
677 ])
678
679 AC_DEFUN([LB_LDISKFS_SERIES],
680 [
681 if $1; then
682         AC_MSG_CHECKING([which ldiskfs series to use])
683         case $LINUXRELEASE in
684         2.6.32*)
685                 if test x$RHEL_KERNEL = xyes; then
686                         LDISKFS_SERIES="2.6-rhel6.series"
687                 fi
688                 if test x$SUSE_KERNEL = xyes; then
689                         LDISKFS_SERIES="2.6-sles11.series"
690                 fi
691                 ;;
692         3.0.*)
693                 if test x$SUSE_KERNEL = xyes; then
694                         LDISKFS_SERIES="3.0-sles11.series"
695                 fi
696                 ;;
697         *)
698                 AC_MSG_WARN([Unknown kernel version $LINUXRELEASE])
699                 LDISKFS_SERIES=
700                 ;;
701         esac
702         AC_MSG_RESULT([$LDISKFS_SERIES])
703 else
704         LDISKFS_SERIES=
705 fi
706 AC_SUBST(LDISKFS_SERIES)
707 ])
708
709 #
710 # 2.6.32-rc7 ext4_free_blocks requires struct buffer_head
711 #
712 AC_DEFUN([LB_EXT_FREE_BLOCKS_WITH_BUFFER_HEAD],
713 [AC_MSG_CHECKING([if ext4_free_blocks needs struct buffer_head])
714  LB_LINUX_TRY_COMPILE([
715         #include <linux/fs.h>
716         #include "$EXT_DIR/ext4.h"
717 ],[
718         ext4_free_blocks(NULL, NULL, NULL, 0, 0, 0);
719 ],[
720         AC_MSG_RESULT([yes])
721         AC_DEFINE(HAVE_EXT_FREE_BLOCK_WITH_BUFFER_HEAD, 1,
722                   [ext4_free_blocks do not require struct buffer_head])
723 ],[
724         AC_MSG_RESULT([no])
725 ])
726 ])
727
728 #
729 # LDISKFS_AC_PATCH_PROGRAM
730 #
731 # Determine which program should be used to apply the patches to
732 # the ext4 source code to produce the ldiskfs source code.
733 #
734 AC_DEFUN([LDISKFS_AC_PATCH_PROGRAM], [
735         AC_ARG_ENABLE([quilt],
736                 [AC_HELP_STRING([--disable-quilt],
737                         [disable use of quilt for ldiskfs])],
738                 [AS_IF([test "x$enableval" = xno],
739                         [use_quilt=no],
740                         [use_quilt=maybe])],
741                 [use_quilt=maybe]
742         )
743
744         AS_IF([test x$use_quilt = xmaybe], [
745                 AC_PATH_PROG([quilt_avail], [quilt], [no])
746                 AS_IF([test x$quilt_avail = xno], [
747                         use_quilt=no
748                 ], [
749                         use_quilt=yes
750                 ])
751         ])
752
753         AS_IF([test x$use_quilt = xno], [
754                 AC_PATH_PROG([patch_avail], [patch], [no])
755                 AS_IF([test x$patch_avail = xno], [
756                         AC_MSG_ERROR([*** Need "quilt" or "patch" command])
757                 ])
758         ])
759
760         AM_CONDITIONAL([USE_QUILT], [test x$use_quilt = xyes])
761 ])