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