Whamcloud - gitweb
8ffd5e956ed86bedde9c856481f1f571fb0a1f8f
[fs/lustre-release.git] / build / autoconf / lustre-build-ldiskfs.m4
1 #
2 # LB_PATH_LDISKFS
3 #
4 # --without-ldiskfs   - Disable ldiskfs support.
5 # --with-ldiskfs=no
6 #
7 # --with-ldiskfs      - Enable ldiskfs support and attempt to autodetect the
8 # --with-ldiskfs=yes    headers in one of the following places in this order:
9 #                       * ./ldiskfs
10 #                       * /usr/src/ldiskfs-*/$LINUXRELEASE
11 #                       * ../ldiskfs
12 #
13 # --with-ldiskfs=path - Enable ldiskfs support and use the headers in the
14 #                       provided path.  No autodetection is performed.
15 #
16 # --with-ldiskfs-obj  - When ldiskfs support is enabled the object directory
17 #                       will be based on the --with-ldiskfs directory.  If
18 #                       this is detected incorrectly it can be explicitly
19 #                       specified using this option.
20 #
21 # NOTE: As with all external packages ldiskfs is expected to already be
22 # configured and built.  However, if the ldiskfs tree is located in-tree
23 # (./ldiskfs) then it will be configured and built recursively as part of
24 # the lustre build system.
25 #
26 # NOTE: The lustre and in-tree ldiskfs build systems both make use these
27 # macros.  This is undesirable and confusing at best, it is potentially
28 # danagerous at worst.  The ldiskfs build system should be entirely stand
29 # alone without dependency on the lustre build system.
30 #
31 AC_DEFUN([LB_PATH_LDISKFS],
32 [
33 AC_ARG_WITH([ldiskfs],
34         AC_HELP_STRING([--with-ldiskfs=path], [set path to ldiskfs source]),
35         [],[
36                 if test x$enable_server = xyes && test x$enable_dist = xno; then
37                         with_ldiskfs='yes'
38                 else
39                         with_ldiskfs='no'
40                 fi
41         ])
42
43 case x$with_ldiskfs in
44         xno)
45                 LDISKFS_DIR=
46                 ;;
47         xyes)
48                 LDISKFS_DIR=
49
50                 # Check ./ldiskfs
51                 ldiskfs_src=$PWD/ldiskfs
52                 if test -e "$ldiskfs_src"; then
53                         LDISKFS_DIR=$(readlink -f $ldiskfs_src)
54                 else
55                         # Check /usr/src/ldiskfs-*/$LINUXRELEASE
56                         ldiskfs_src=$(ls -1d \
57                                 /usr/src/ldiskfs-*/$LINUXRELEASE \
58                                 2>/dev/null | tail -1)
59                         if test -e "$ldiskfs_src"; then
60                                 LDISKFS_DIR=$(readlink -f $ldiskfs_src)
61                         else
62                                 # Check ../ldiskfs
63                                 ldiskfs_src=$PWD/../ldiskfs
64                                 if test -e "$ldiskfs_src"; then
65                                         LDISKFS_DIR=$(readlink -f $ldiskfs_src)
66                                 else
67                                         # Disable ldiskfs failed to detect
68                                         with_ldiskfs='no'
69                                 fi
70                         fi
71                 fi
72
73                 ;;
74         *)
75                 LDISKFS_DIR=$(readlink -f $with_ldiskfs)
76                 with_ldiskfs='yes'
77                 ;;
78 esac
79
80 AC_MSG_CHECKING([whether to enable ldiskfs])
81 AC_MSG_RESULT([$with_ldiskfs])
82
83 AC_ARG_WITH([ldiskfs-obj],
84         AC_HELP_STRING([--with-ldiskfs-obj=path],[set path to ldiskfs objects]),
85         [
86                 if test x$with_ldiskfs = xyes; then
87                         LDISKFS_OBJ="$withval"
88                 fi
89         ],[
90                 if test x$with_ldiskfs = xyes; then
91                         LDISKFS_OBJ=$LDISKFS_DIR
92                 fi
93         ])
94
95 if test x$with_ldiskfs = xyes; then
96         AC_MSG_CHECKING([ldiskfs source directory])
97         AC_MSG_RESULT([$LDISKFS_DIR])
98         AC_SUBST(LDISKFS_DIR)
99
100         AC_MSG_CHECKING([ldiskfs object directory])
101         AC_MSG_RESULT([$LDISKFS_OBJ])
102         AC_SUBST(LDISKFS_OBJ)
103
104         LB_LDISKFS_SYMVERS
105         LB_LDISKFS_RELEASE
106         LB_LDISKFS_EXT_RELEASE
107         LB_LDISKFS_EXT_DIR
108         LB_LDISKFS_BUILD
109         LB_LDISKFS_DEFINE_OPTIONS
110 fi
111
112 #
113 # LDISKFS_DEVEL is required because when using the ldiskfs-devel package the
114 # ext3/4 source will be fully patched to ldiskfs.  When building with the
115 # in-tree ldiskfs this patching this will occur after the configure step.
116 # We needed a way to determine if we should check the patched or unpatched
117 # source files.
118 #
119 # Longer term this could be removed by moving the ldiskfs patching in to
120 # the configure phase.  Or better yet ldiskfs could be updated to generate
121 # a ldiskfs_config.h which clearly defines how it was built.  This can
122 # then be directly included by Lustre to avoid all the autoconf guess work.
123 # For an example of this behavior consult the lustre/zfs build integration.
124 #
125 AM_CONDITIONAL(LDISKFS_DEVEL, \
126         test x$LDISKFS_DIR = x$(readlink -f $PWD/ldiskfs) || \
127         test x$LDISKFS_DIR = x$(readlink -f $PWD/../ldiskfs))
128
129 AM_CONDITIONAL(LDISKFS_BUILD, test x$enable_ldiskfs_build = xyes)
130 AM_CONDITIONAL(LDISKFS_ENABLED, test x$with_ldiskfs = xyes)
131
132 if test -e "$PWD/ldiskfs"; then
133         LDISKFS_DIST_SUBDIR="ldiskfs"
134         AC_SUBST(LDISKFS_DIST_SUBDIR)
135         AC_CONFIG_SUBDIRS("ldiskfs")
136 fi
137 ])
138
139 #
140 # LB_LDISKFS_EXT_RELEASE
141 #
142 # Determine if ext3 or ext4 sources should be used for ldiskfs.
143 #
144 AC_DEFUN([LB_LDISKFS_EXT_RELEASE],
145 [
146 AC_ARG_ENABLE([ext4],
147          AC_HELP_STRING([--enable-ext4], [enable ldiskfs build using ext4]),
148         [],
149         [
150                 if test x$RHEL_KERNEL = xyes; then
151                         enable_ext4='yes'
152                 else
153                         # 2.6.22-2.6.26 ext4 available but unstable
154                         case x$LINUXRELEASE in
155                         x2.6.2[[0-6]]*)
156                                 enable_ext4='no' ;;
157                         *)
158                                 enable_ext4='yes' ;;
159                         esac
160                 fi
161         ])
162
163 if test x$enable_ext4 = xyes; then
164         LDISKFS_BACKFS='ext4'
165 else
166         LDISKFS_BACKFS='ext3'
167 fi
168
169 AC_MSG_CHECKING([whether to use ext3 or ext4 source])
170 AC_MSG_RESULT([$LDISKFS_BACKFS])
171 AC_SUBST(LDISKFS_BACKFS)
172 ])
173
174 #
175 # LB_LDISKFS_EXT_DIR
176 #
177 # Determine the location of the ext3/ext4 source code.  It it required
178 # for several configure tests and to build ldiskfs.
179 #
180 AC_DEFUN([LB_LDISKFS_EXT_DIR],
181 [
182 # Kernel ext source located with devel headers
183 linux_src=$LINUX
184 if test -e "$linux_src/fs/$LDISKFS_BACKFS/super.c"; then
185         EXT_DIR=$linux_src/fs/$LDISKFS_BACKFS
186 else
187         # Kernel ext source provided by kernel-debuginfo-common package
188         linux_src=$(ls -1d /usr/src/debug/*/linux-$LINUXRELEASE \
189                 2>/dev/null | tail -1)
190         if test -e "$linux_src/fs/$LDISKFS_BACKFS/super.c"; then
191                 EXT_DIR=$linux_src/fs/$LDISKFS_BACKFS
192         else
193                 EXT_DIR=
194         fi
195 fi
196
197 AC_MSG_CHECKING([$LDISKFS_BACKFS source directory])
198 AC_MSG_RESULT([$EXT_DIR])
199 AC_SUBST(EXT_DIR)
200 ])
201
202 #
203 # LB_LDISKFS_EXT_SOURCE
204 #
205 # Spot check the existance of several source files common to ext3/ext4.
206 # Detecting this at configure time allows us to avoid a potential build
207 # failure and provide a useful error message to explain what is wrong.
208 #
209 AC_DEFUN([LB_LDISKFS_EXT_SOURCE],
210 [
211 if test x$EXT_DIR = x; then
212         enable_ldiskfs_build='no'
213 else
214         LB_CHECK_FILE([$EXT_DIR/dir.c], [], [
215                 enable_ldiskfs_build='no'
216                 AC_MSG_WARN([$LDISKFS_BACKFS must exist for ldiskfs build])])
217         LB_CHECK_FILE([$EXT_DIR/file.c], [], [
218                 enable_ldiskfs_build='no'
219                 AC_MSG_WARN([$LDISKFS_BACKFS must exist for ldiskfs build])])
220         LB_CHECK_FILE([$EXT_DIR/inode.c], [], [
221                 enable_ldiskfs_build='no'
222                 AC_MSG_WARN([$LDISKFS_BACKFS must exist for ldiskfs build])])
223         LB_CHECK_FILE([$EXT_DIR/super.c], [], [
224                 enable_ldiskfs_build='no'
225                 AC_MSG_WARN([$LDISKFS_BACKFS must exist for ldiskfs build])])
226 fi
227
228 if test x$enable_ldiskfs_build = xno; then
229         enable_server='no'
230         enable_ldiskfs_build='no'
231         with_ldiskfs='no'
232         LDISKFS_SUBDIR=
233
234         AC_MSG_WARN([
235
236 Disabling server because complete $LDISKFS_BACKFS source does not exist.
237
238 If you are building using kernel-devel packages and require ldiskfs
239 server support then ensure that the matching kernel-debuginfo-common
240 and kernel-debuginfo-common-<arch> packages are installed.
241
242 ])
243
244 fi
245 ])
246
247 #
248 # LB_LDISKFS_DEFINE_OPTIONS
249 #
250 # Enable config options related to ldiskfs.  These are used by ldiskfs,
251 # lvfs, and the osd-ldiskfs code (which includes ldiskfs headers.)
252 #
253 AC_DEFUN([LB_LDISKFS_DEFINE_OPTIONS],
254 [
255 AC_DEFINE(HAVE_LDISKFS_OSD, 1, Enable ldiskfs osd)
256
257 with_ldiskfs_pdo=no
258 if test $LDISKFS_BACKFS = 'ext4'; then
259         AC_DEFINE(HAVE_EXT4_LDISKFS, 1, [build ext4 based ldiskfs])
260         case $LINUXRELEASE in
261         2.6.32*)
262                 if test x$RHEL_KERNEL = xyes; then
263                         with_ldiskfs_pdo=yes
264                         AC_DEFINE(HAVE_LDISKFS_PDO, 1, [have ldiskfs PDO patch])
265                 fi
266                 if test x$SUSE_KERNEL = xyes; then
267                         with_ldiskfs_pdo=yes
268                         AC_DEFINE(HAVE_LDISKFS_PDO, 1, [have ldiskfs PDO patch])
269                 fi
270         ;;
271         esac
272 fi
273
274 LB_LDISKFS_JBD2_JOURNAL_CALLBACK_SET
275
276 AC_DEFINE(CONFIG_LDISKFS_FS_XATTR, 1,
277         [enable extended attributes for ldiskfs])
278 AC_DEFINE(CONFIG_LDISKFS_FS_POSIX_ACL, 1,
279         [enable posix acls for ldiskfs])
280 AC_DEFINE(CONFIG_LDISKFS_FS_SECURITY, 1,
281         [enable fs security for ldiskfs])
282 AC_DEFINE(CONFIG_LDISKFSDEV_FS_POSIX_ACL, 1,
283         [enable posix acls for ldiskfs])
284 AC_DEFINE(CONFIG_LDISKFSDEV_FS_XATTR, 1,
285         [enable extented attributes for ldiskfs])
286 AC_DEFINE(CONFIG_LDISKFSDEV_FS_SECURITY, 1,
287         [enable fs security for ldiskfs])
288 ])
289
290 #
291 # Check for jbd2_journal_callback_set(), which is needed for commit
292 # callbacks.  When LU-433 lands jbd2_journal_callback_set() will only
293 # remain for legacy reasons and AC_MSG_ERROR can be removed.
294 #
295 # 2.6.18 with ext3 still uses journal_callback_set() for commit callbacks.
296 #
297 AC_DEFUN([LB_LDISKFS_JBD2_JOURNAL_CALLBACK_SET],
298 [
299         LB_CHECK_SYMBOL_EXPORT([jbd2_journal_callback_set],
300         [fs/jbd2/journal.c],
301         [AC_DEFINE(HAVE_JBD2_JOURNAL_CALLBACK_SET, 1,
302                 [kernel exports jbd2_journal_callback_set])],
303         [LB_CHECK_SYMBOL_EXPORT([journal_callback_set],
304                 [fs/jbd/journal.c],
305                 [AC_DEFINE(HAVE_JOURNAL_CALLBACK_SET, 1,
306                         [kernel exports journal_callback_set])])])
307 ])
308
309 #
310 # Optionally configure/make the ldiskfs sources.  If the sources are
311 # determined to reside in-tree this feature will automatically be
312 # enabled.  If the sources are not in-tree it will be disabled.
313 # Use --enable-ldiskfs-build or --disable-ldiskfs-build if you need
314 # to override this behavior.
315 #
316 AC_DEFUN([LB_LDISKFS_BUILD],
317 [
318 AC_ARG_ENABLE([ldiskfs-build],
319         AC_HELP_STRING([--enable-ldiskfs-build],
320                 [enable ldiskfs configure/make]),
321         [], [
322                 LDISKFS_DIR_INTREE=$(readlink -f $PWD/ldiskfs)
323                 if test x$LDISKFS_DIR = x$LDISKFS_DIR_INTREE; then
324                         enable_ldiskfs_build='yes'
325                 else
326                         enable_ldiskfs_build='no'
327                 fi
328         ])
329
330 AC_MSG_CHECKING([whether to build ldiskfs])
331 if test x$enable_ldiskfs_build = xyes; then
332         AC_MSG_RESULT([$enable_ldiskfs_build])
333         LDISKFS_SUBDIR="ldiskfs"
334
335         LB_CHECK_FILE([$LDISKFS_DIR/configure], [], [
336                 AC_MSG_ERROR([Complete ldiskfs build system must exist])])
337         LB_LDISKFS_EXT_SOURCE
338
339         AC_SUBST(LDISKFS_SUBDIR)
340 else
341         enable_ldiskfs_build='no'
342         AC_MSG_RESULT([$enable_ldiskfs_build])
343 fi
344 ])
345
346 AC_DEFUN([LB_LDISKFS_SYMVERS],
347 [
348 AC_MSG_CHECKING([ldiskfs module symbols])
349 if test -r $LDISKFS_OBJ/Module.symvers; then
350         LDISKFS_SYMBOLS=Module.symvers
351 elif test -r $LDISKFS_OBJ/Modules.symvers; then
352         LDISKFS_SYMBOLS=Modules.symvers
353 elif test -r $LDISKFS_OBJ/ldiskfs/Module.symvers; then
354         LDISKFS_SYMBOLS=Module.symvers
355 elif test -r $LDISKFS_OBJ/ldiskfs/Modules.symvers; then
356         LDISKFS_SYMBOLS=Modules.symvers
357 else
358         LDISKFS_SYMBOLS=$SYMVERFILE
359 fi
360
361 AC_MSG_RESULT([$LDISKFS_SYMBOLS])
362 AC_SUBST(LDISKFS_SYMBOLS)
363 ])
364
365 AC_DEFUN([LB_LDISKFS_RELEASE],
366 [
367 AC_MSG_CHECKING([ldiskfs source release])
368 if test -r $LDISKFS_OBJ/config.h; then
369         tmp_flags="$EXTRA_KCFLAGS"
370         EXTRA_KCFLAGS="-I$LDISKFS_DIR $EXTRA_KCFLAGS"
371         LB_LINUX_TRY_MAKE([
372                 #undef PACKAGE_NAME
373                 #undef PACKAGE_TARNAME
374                 #undef PACKAGE_VERSION
375                 #undef PACKAGE_STRING
376                 #undef PACKAGE_BUGREPORT
377                 #undef PACKAGE
378                 #undef VERSION
379                 #undef STDC_HEADERS
380
381                 #include <$LDISKFS_OBJ/config.h>
382         ],[
383                 char *LDISKFS_RELEASE;
384                 LDISKFS_RELEASE=VERSION;
385         ],[
386                 $makerule LUSTRE_KERNEL_TEST=conftest.i
387         ],[
388                 test -s build/conftest.i
389         ],[
390                 eval $(grep "LDISKFS_RELEASE=" build/conftest.i)
391         ],[
392                 AC_MSG_RESULT([unknown])
393                 AC_MSG_ERROR([Could not preprocess test program.])
394         ])
395         EXTRA_KCFLAGS="$tmp_flags"
396         rm build/conftest.i
397 elif test -r $LDISKFS_DIR/configure.ac; then
398         LDISKFS_RELEASE=$(awk '/AC\_INIT/ { print [$]3 }' \
399                  $LDISKFS_DIR/configure.ac | tr ',' '\n')
400 else
401         AC_MSG_RESULT([unknown])
402         AC_MSG_ERROR([Could not locate config.h, META, or configure.ac to check release.])
403 fi
404
405 if test x$LDISKFS_RELEASE = x; then
406         AC_MSG_RESULT([unknown])
407         AC_MSG_ERROR([Could not determine ldiskfs release.])
408 fi
409
410 AC_MSG_RESULT([$LDISKFS_RELEASE])
411 AC_SUBST(LDISKFS_RELEASE)
412 ])
413
414 #
415 # LB_DEFINE_E2FSPROGS_NAMES
416 #
417 # Enable the use of alternate naming of ldiskfs-enabled e2fsprogs package.
418 #
419 AC_DEFUN([LB_DEFINE_E2FSPROGS_NAMES],
420 [
421 AC_ARG_WITH([ldiskfsprogs],
422         AC_HELP_STRING([--with-ldiskfsprogs],
423                        [use alternate names for ldiskfs-enabled e2fsprogs]),
424         [],[withval='no'])
425
426 AC_MSG_CHECKING([whether to use alternate names for e2fsprogs])
427 if test x$withval = xyes ; then
428         AC_DEFINE(HAVE_LDISKFSPROGS, 1, [enable use of ldiskfsprogs package])
429         E2FSPROGS="ldiskfsprogs"
430         MKE2FS="mkfs.ldiskfs"
431         DEBUGFS="debugfs.ldiskfs"
432         TUNE2FS="tunefs.ldiskfs"
433         E2LABEL="label.ldiskfs"
434         DUMPE2FS="dumpfs.ldiskfs"
435         E2FSCK="fsck.ldiskfs"
436         PFSCK="pfsck.ldiskfs"
437         AC_MSG_RESULT([enabled])
438 else
439         E2FSPROGS="e2fsprogs"
440         MKE2FS="mke2fs"
441         DEBUGFS="debugfs"
442         TUNE2FS="tune2fs"
443         E2LABEL="e2label"
444         DUMPE2FS="dumpe2fs"
445         E2FSCK="e2fsck"
446         PFSCK="fsck"
447         AC_MSG_RESULT([disabled])
448 fi
449
450 AC_DEFINE_UNQUOTED(E2FSPROGS, "$E2FSPROGS", [name of ldiskfs e2fsprogs package])
451 AC_DEFINE_UNQUOTED(MKE2FS, "$MKE2FS", [name of ldiskfs mkfs program])
452 AC_DEFINE_UNQUOTED(DEBUGFS, "$DEBUGFS", [name of ldiskfs debug program])
453 AC_DEFINE_UNQUOTED(TUNE2FS, "$TUNE2FS", [name of ldiskfs tune program])
454 AC_DEFINE_UNQUOTED(E2LABEL, "$E2LABEL", [name of ldiskfs label program])
455 AC_DEFINE_UNQUOTED(DUMPE2FS,"$DUMPE2FS", [name of ldiskfs dump program])
456 AC_DEFINE_UNQUOTED(E2FSCK, "$E2FSCK", [name of ldiskfs fsck program])
457 AC_DEFINE_UNQUOTED(PFSCK, "$PFSCK", [name of parallel fsck program])
458
459 AC_SUBST([E2FSPROGS], [$E2FSPROGS])
460 AC_SUBST([MKE2FS], [$MKE2FS])
461 AC_SUBST([DEBUGFS], [$DEBUGFS])
462 AC_SUBST([TUNE2FS], [$TUNE2FS])
463 AC_SUBST([E2LABEL], [$E2LABEL])
464 AC_SUBST([DUMPE2FS], [$DUMPE2FS])
465 AC_SUBST([E2FSCK], [$E2FSCK])
466 AC_SUBST([PFSCK], [$PFSCK])
467 ])
468
469 AC_DEFUN([LB_LDISKFS_SERIES],
470 [
471 if $1; then
472         AC_MSG_CHECKING([which ldiskfs series to use])
473         case $LINUXRELEASE in
474         2.6.18*)
475                 if test x$RHEL_KERNEL = xyes; then
476                         LDISKFS_SERIES="2.6-rhel5-ext4.series"
477                 fi
478                 ;;
479         2.6.32*)
480                 if test x$RHEL_KERNEL = xyes; then
481                         LDISKFS_SERIES="2.6-rhel6.series"
482                 fi
483                 if test x$SUSE_KERNEL = xyes; then
484                         LDISKFS_SERIES="2.6-sles11.series"
485                 fi
486                 ;;
487         *)
488                 AC_MSG_WARN([Unknown kernel version $LINUXRELEASE])
489                 LDISKFS_SERIES=
490                 ;;
491         esac
492         AC_MSG_RESULT([$LDISKFS_SERIES])
493 else
494         LDISKFS_SERIES=
495 fi
496 AC_SUBST(LDISKFS_SERIES)
497 ])