Whamcloud - gitweb
refine skeletal configure.ac
[fs/lustre-release.git] / build / autoconf / lustre-build-linux.m4
1 #
2 # LB_LINUX_INKERNEL
3 #
4 # in kernel compilation? (2.5 only)
5 #
6 AC_DEFUN([LB_LINUX_INKERNEL],
7 [AC_MSG_CHECKING([if inkernel build support is requested])
8 AC_ARG_ENABLE([inkernel],
9         AC_HELP_STRING([--enable-inkernel],
10                        [set up 2.5 kernel makefiles]),
11         [],[enable_inkernel=no])
12 AC_MSG_RESULT([$enable_inkernel])
13
14 if test x$enable_inkernel = xyes ; then
15         echo ln -s `pwd` $LINUX/fs/lustre
16         rm $LINUX/fs/lustre
17         ln -s `pwd` $LINUX/fs/lustre
18         find portals lustre -name Makefile.mk | sed 's/.mk$//' | xargs -n 1 \
19                 sh -e -x -c '(cp -f $0.mk $0.in)'
20 fi
21 ])
22
23
24 #
25 # LB_LINUX_VERSION
26 #
27 # Set things accordingly for a 2.5 kernel
28 #
29 AC_DEFUN([LB_LINUX_VERSION],
30 [AC_CHECK_FILE([$LINUX/include/linux/namei.h],
31         [
32                 linux25="yes"
33                 KMODEXT=".ko"
34         ],[
35                 KMODEXT=".o"
36                 linux25="no"
37         ])
38 AC_MSG_CHECKING([if you are using Linux 2.6])
39 AC_MSG_RESULT([$linux25])
40
41 MODULE_TARGET="SUBDIRS"
42 if test $linux25 = "yes" ; then
43         LB_CONFIG_INKERNEL
44
45         makerule="$PWD/build"
46         AC_MSG_CHECKING([for external module build support])
47         rm -f build/conftest.i
48         LB_LINUX_TRY_MAKE([],[],
49                 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
50                 [test -s build/conftest.i],
51                 [
52                         AC_MSG_RESULT([no])
53                 ],[
54                         AC_MSG_RESULT([yes])
55                         makerule="_module_$makerule"
56                         MODULE_TARGET="M"
57                 ])
58
59 else
60         makerule="_dir_$PWD/build"
61 fi
62
63 AC_SUBST(MODULE_TARGET)
64 AC_SUBST(LINUX25)
65 AC_SUBST(KMODEXT)
66 ])
67
68 #
69 # LB_LINUX_PATH
70 #
71 # Find paths for linux, handling kernel-source rpms
72 #
73 AC_DEFUN([LB_LINUX_PATH],
74 [AC_MSG_CHECKING([for Linux sources])
75 AC_ARG_WITH([linux],
76         AC_HELP_STRING([--with-linux=path],
77                        [set path to Linux source (default=/usr/src/linux)]),
78         [LINUX=$with_linux],
79         [LINUX=/usr/src/linux])
80 AC_MSG_RESULT([$LINUX])
81 AC_SUBST(LINUX)
82
83 # -------- linux objects (for 2.6) --
84 AC_MSG_CHECKING([for Linux objects dir])
85 AC_ARG_WITH([linux-obj],
86         AC_HELP_STRING([--with-linux-obj=path],
87                         [set path to Linux objects dir (default=$LINUX)]),
88         [LINUX_OBJ=$with_linux_obj],
89         [LINUX_OBJ=$LINUX])
90 AC_MSG_RESULT([$LINUX_OBJ])
91 AC_SUBST(LINUX_OBJ)
92
93 # -------- check for .confg --------
94 AC_ARG_WITH([linux-config],
95         [AC_HELP_STRING([--with-linux-config=path],
96                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
97         [LINUX_CONFIG=$with_linux_config],
98         [LINUX_CONFIG=$LINUX_OBJ/.config])
99 AC_SUBST(LINUX_CONFIG)
100
101 AC_CHECK_FILE([/boot/kernel.h],
102         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
103         [AC_CHECK_FILE([/var/adm/running-kernel.h]),
104                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h']])
105
106 AC_ARG_WITH([kernel-source-header],
107         AC_HELP_STRING([--with-kernel-source-header=path],
108                         [Use a different kernel version header.  Consult README.kernel-source for details.]),
109         [KERNEL_SOURCE_HEADER=$with_kernel_source_header])
110
111 # ------------ .config exists ----------------
112 AC_CHECK_FILE([$LINUX_CONFIG],[],
113         [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult README.kernel-source])])
114
115 # ----------- make dep run? ------------------
116 AC_CHECK_FILES([$LINUX_OBJ/include/linux/autoconf.h
117                 $LINUX_OBJ/include/linux/version.h
118                 $LINUX/include/linux/config.h],[],
119         [AC_MSG_ERROR([Run make config in $LINUX.])])
120
121 # ------------ rhconfig.h includes runtime-generated bits --
122 # red hat kernel-source checks
123
124 # we know this exists after the check above.  if the user
125 # tarred up the tree and ran make dep etc. in it, then
126 # version.h gets overwritten with a standard linux one.
127
128 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
129         # This is a clean kernel-source tree, we need to
130         # enable extensive workarounds to get this to build
131         # modules
132         AC_CHECK_FILE([$KERNEL_SOURCE_HEADER],
133                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
134                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
135                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
136                         AC_MSG_WARN([Consult README.kernel-source for details.])
137                 fi],
138                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult README.kernel-source for details.])])
139         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
140 fi
141
142 # this is needed before we can build modules
143 LB_LINUX_VERSION
144
145 # --- check that we can build modules at all
146 AC_MSG_CHECKING([that modules can be built at all])
147 LB_LINUX_TRY_COMPILE([],[],[
148         AC_MSG_RESULT([yes])
149 ],[
150         AC_MSG_RESULT([no])
151         AC_MSG_WARN([Consult config.log for details.])
152         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult README.kernel-source])
153         AC_MSG_ERROR([Kernel modules could not be built.])
154 ])
155 ])
156
157 #
158 # LB_LINUX_UML
159 #
160 # check for a uml kernel
161 #
162 AC_DEFUN([LB_LINUX_UML],
163 [ARCH_UM=
164 UML_CFLAGS=
165
166 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
167 if test -e $LINUX/include/asm-um ; then
168         if test  X`ls -id $LINUX/include/asm/ 2>/dev/null | awk '{print [$]1}'` = X`ls -id $LINUX/include/asm-um 2>/dev/null | awk '{print [$]1}'` ; then
169                 ARCH_UM='ARCH=um'
170                 # see notes in Rules.in
171                 UML_CFLAGS='-O0'
172                 AC_MSG_RESULT(yes)
173         else
174                 AC_MSG_RESULT([no (asm doesn't point at asm-um)])
175         fi
176 else
177         AC_MSG_RESULT([no (asm-um missing)])
178 fi
179 AC_SUBST(ARCH_UM)
180 AC_SUBST(UML_CFLAGS)
181 ])
182
183 # these are like AC_TRY_COMPILE, but try to build modules against the
184 # kernel, inside the build directory
185
186 #
187 # LB_LINUX_CONFTEST
188 #
189 # create a conftest.c file
190 #
191 AC_DEFUN([LB_LINUX_CONFTEST],
192 [cat >conftest.c <<_ACEOF
193 $1
194 _ACEOF
195 ])
196
197 #
198 # LB_LINUX_COMPILE_IFELSE
199 #
200 # like AC_COMPILE_IFELSE
201 #
202 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
203 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
204 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
205 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -o tmp_include_depends -o scripts -o include/config/MARKER -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM $MODULE_TARGET=$PWD/build) >/dev/null && AC_TRY_COMMAND([$3])],
206         [$4],
207         [_AC_MSG_LOG_CONFTEST
208 m4_ifvaln([$5],[$5])dnl])dnl
209 rm -f build/conftest.o build/conftest.mod.c build/conftest.mod.o build/conftest.ko m4_ifval([$1], [build/conftest.c conftest.c])[]dnl
210 ])
211
212 #
213 # LB_LINUX_TRY_COMPILE
214 #
215 # like AC_TRY_COMPILE
216 #
217 AC_DEFUN([LB_LINUX_TRY_COMPILE],
218 [LB_LINUX_COMPILE_IFELSE(
219         [AC_LANG_PROGRAM([[$1]], [[$2]])],
220         [modules],
221         [test -s build/conftest.o],
222         [$3], [$4])])
223
224 #
225 # LB_LINUX_CONFIG
226 #
227 # check if a given config option is defined
228 #
229 AC_DEFUN([LB_LINUX_CONFIG],
230 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
231 LB_LINUX_TRY_COMPILE([#include <linux/config.h>],[
232 #ifndef CONFIG_$1
233 #error CONFIG_$1 not #defined
234 #endif
235 ],[
236 AC_MSG_RESULT([yes])
237 $2
238 ],[
239 AC_MSG_RESULT([no])
240 $3
241 ])
242 ])
243
244 #
245 # LB_LINUX_TRY_MAKE
246 #
247 # like LB_LINUX_TRY_COMPILE, but with different arguments
248 #
249 AC_DEFUN([LB_LINUX_TRY_MAKE],
250 [LB_LINUX_COMPILE_IFELSE([AC_LANG_PROGRAM([[$1]], [[$2]])], [$3], [$4], [$5], [$6])])
251
252 #
253 # LB_PROG_LINUX
254 #
255 # linux tests
256 #
257 AC_DEFUN([LB_PROG_LINUX],
258 [LB_LINUX_PATH
259 LB_LINUX_UML
260
261 LB_LINUX_CONFIG([MODULES],[],[
262         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
263 ])
264
265 LB_LINUX_CONFIG([MODVERSIONS])
266
267 LB_LINUX_CONFIG([PREEMPT],[
268         AC_MSG_ERROR([Lustre does not support kernels with preempt enabled.])
269 ])
270
271 LB_LINUX_CONFIG([KALLSYMS],[],[
272 if test "x$ARCH_UM" = "x" ; then
273         AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
274 fi
275 ])
276
277 # Portals tests
278 LP_PROG_LINUX
279
280 # Lustre tests
281 LC_PROG_LINUX
282 ])
283
284 #
285 # LB_LINUX_CONDITIONALS
286 #
287 # AM_CONDITIONALS for linux
288 #
289 AC_DEFUN([LB_LINUX_CONDITIONALS],
290 [AM_CONDITIONAL(INKERNEL, test x$enable_inkernel = xyes)
291 AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
292 ])
293
294 #
295 # LB_LINUX_STRUCT_PAGE_LIST
296 #
297 # 2.6.4 no longer has page->list
298 #
299 AC_DEFUN([LB_LINUX_STRUCT_PAGE_LIST],
300 [AC_MSG_CHECKING([if struct page has a list field])
301 LB_LINUX_TRY_COMPILE([
302         #include <linux/mm.h>
303 ],[
304         struct page page;
305         &page.list;
306 ],[
307         AC_MSG_RESULT([yes])
308         AC_DEFINE(HAVE_PAGE_LIST, 1, [struct page has a list field])
309 ],[
310         AC_MSG_RESULT([no])
311 ])
312 ])
313
314 #
315 # LB_LINUX_STRUCT_SIGHAND
316 #
317 # red hat 2.4 adds sighand to struct task_struct
318 #
319 AC_DEFUN([LB_LINUX_STRUCT_SIGHAND],
320 [AC_MSG_CHECKING([if task_struct has a sighand field])
321 LB_LINUX_TRY_COMPILE([
322         #include <linux/sched.h>
323 ],[
324         struct task_struct p;
325         p.sighand = NULL;
326 ],[
327         AC_DEFINE(CONFIG_RH_2_4_20, 1, [this kernel contains Red Hat 2.4.20 patches])
328         AC_MSG_RESULT([yes])
329 ],[
330         AC_MSG_RESULT([no])
331 ])
332 ])
333
334 #
335 # LB_LINUX_FUNC_CPU_ONLINE
336 #
337 # cpu_online is different in rh 2.4, vanilla 2.4, and 2.6
338 #
339 AC_DEFUN([LB_LINUX_FUNC_CPU_ONLINE],
340 [AC_MSG_CHECKING([if kernel defines cpu_online()])
341 LB_LINUX_TRY_COMPILE([
342         #include <linux/sched.h>
343 ],[
344         cpu_online(0);
345 ],[
346         AC_MSG_RESULT([yes])
347         AC_DEFINE(HAVE_CPU_ONLINE, 1, [cpu_online found])
348 ],[
349         AC_MSG_RESULT([no])
350 ])
351 ])
352
353 #
354 # LB_LINUX_TYPE_CPUMASK_T
355 #
356 # same goes for cpumask_t
357 #
358 AC_DEFUN([LB_LINUX_TYPE_CPUMASK_T],
359 [AC_MSG_CHECKING([if kernel defines cpumask_t])
360 LB_LINUX_TRY_COMPILE([
361         #include <linux/sched.h>
362 ],[
363         return sizeof (cpumask_t);
364 ],[
365         AC_MSG_RESULT([yes])
366         AC_DEFINE(HAVE_CPUMASK_T, 1, [cpumask_t found])
367 ],[
368         AC_MSG_RESULT([no])
369 ])
370 ])
371
372 #
373 # LB_LINUX_FUNC_SHOW_TASK
374 #
375 # we export show_task(), but not all kernels have it (yet)
376 #
377 AC_DEFUN([LB_LINUX_FUNC_SHOW_TASK],
378 [AC_MSG_CHECKING([if kernel exports show_task])
379 have_show_task=0
380 for file in ksyms sched ; do
381         if grep -q "EXPORT_SYMBOL(show_task)" \
382                  "$LINUX/kernel/$file.c" 2>/dev/null ; then
383                 have_show_task=1
384                 break
385         fi
386 done
387 if test x$have_show_task = x1 ; then
388         AC_DEFINE(HAVE_SHOW_TASK, 1, [show_task is exported])
389         AC_MSG_RESULT([yes])
390 else
391         AC_MSG_RESULT([no])
392 fi
393 ])
394
395 #
396 # LB_LINUX_CONFIG_EXT3
397 #
398 # that ext3 is enabled in the kernel
399 #
400 AC_DEFUN([LB_LINUX_CONFIG_EXT3],
401 [LB_LINUX_CONFIG([EXT3_FS],[],[
402         LB_LINUX_CONFIG([EXT3_FS_MODULE],[],[$2])
403 ])
404 LB_LINUX_CONFIG([EXT3_FS_XATTR],[$1],[$3])
405 ])
406
407 #
408 # LB_LINUX_FSHOOKS
409 #
410 # If we have (and can build) fshooks.h
411 #
412 AC_DEFUN([LB_LINUX_FSHOOKS],
413 [AC_MSG_CHECKING([if this compiler can build a SuSE 2.6 kernel])
414 # an excerpt from fshooks.h, which doesn't build with fedora's gcc 3.4
415 LB_LINUX_TRY_COMPILE([
416         /* for the lack of a kernel-wide definition */
417         typedef enum {
418                 false,
419                 true
420         } boolean_t __attribute__((__mode__(__QI__)));
421 ],[],[
422         AC_MSG_RESULT([yes])
423 ],[
424         AC_MSG_RESULT([no])
425         AC_MSG_WARN([We suggest trying gcc 3.3.x.])
426         AC_MSG_WARN([You can set CC=gcc33 before running configure.])
427         AC_MSG_ERROR([Your compiler cannot build a SuSE 2.6 kernel.])
428 ])
429 AC_MSG_CHECKING([if fshooks are present])
430 LB_LINUX_TRY_COMPILE([
431         #include <linux/fshooks.h>
432 ],[],[
433         AC_MSG_RESULT([yes])
434 $1
435 ],[
436         AC_MSG_RESULT([no])
437 $2
438 ])
439 ])
440
441 #
442 # LB_LINUX_STRUCT_KIOBUF
443 #
444 # rh 2.4.18 has iobuf->dovary, but other kernels do not
445 #
446 AC_DEFUN([LB_LINUX_STRUCT_KIOBUF],
447 [AC_MSG_CHECKING([if struct kiobuf has a dovary field])
448 LB_LINUX_TRY_COMPILE([
449         #include <linux/iobuf.h>
450 ],[
451         struct kiobuf iobuf;
452         iobuf.dovary = 1;
453 ],[
454         AC_MSG_RESULT([yes])
455         AC_DEFINE(HAVE_KIOBUF_DOVARY, 1, [struct kiobuf has a dovary field])
456 ],[
457         AC_MSG_RESULT([no])
458 ])
459 ])
460
461 #
462 # LB_LINUX_FUNC_COND_RESCHED
463 #
464 # cond_resched() was introduced in 2.4.20
465 #
466 AC_DEFUN([LB_LINUX_FUNC_COND_RESCHED],
467 [AC_MSG_CHECKING([if kernel offers cond_resched])
468 LB_LINUX_TRY_COMPILE([
469         #include <linux/sched.h>
470 ],[
471         cond_resched();
472 ],[
473         AC_MSG_RESULT([yes])
474         AC_DEFINE(HAVE_COND_RESCHED, 1, [cond_resched found])
475 ],[
476         AC_MSG_RESULT([no])
477 ])
478 ])
479
480 #
481 # LB_LINUX_FUNC_ZAP_PAGE_RANGE
482 #
483 # if zap_page_range() taks a vma arg
484 #
485 AC_DEFUN([LB_LINUX_FUNC_ZAP_PAGE_RANGE],
486 [AC_MSG_CHECKING([if zap_pag_range with vma parameter])
487 ZAP_PAGE_RANGE_VMA="`grep -c 'zap_page_range.*struct vm_area_struct' $LINUX/include/linux/mm.h`"
488 if test "$ZAP_PAGE_RANGE_VMA" != 0 ; then
489         AC_DEFINE(ZAP_PAGE_RANGE_VMA, 1, [zap_page_range with vma parameter])
490         AC_MSG_RESULT([yes])
491 else
492         AC_MSG_RESULT([no])
493 fi
494 ])
495
496 #
497 # LB_LINUX_FUNC_PDE
498 #
499 # if proc_fs.h defines PDE()
500 #
501 AC_DEFUN([LB_LINUX_FUNC_PDE],
502 [AC_MSG_CHECKING([if kernel defines PDE])
503 HAVE_PDE="`grep -c 'proc_dir_entry..PDE' $LINUX/include/linux/proc_fs.h`"
504 if test "$HAVE_PDE" != 0 ; then
505         AC_DEFINE(HAVE_PDE, 1, [the kernel defines PDE])
506         AC_MSG_RESULT([yes])
507 else
508         AC_MSG_RESULT([no])
509 fi
510 ])
511
512 #
513 # LB_LINUX_FUNC_DIRECT_IO
514 #
515 # if direct_IO takes a struct file argument
516 #
517 AC_DEFUN([LB_LINUX_FUNC_DIRECT_IO],
518 [AC_MSG_CHECKING([if kernel passes struct file to direct_IO])
519 HAVE_DIO_FILE="`grep -c 'direct_IO.*struct file' $LINUX/include/linux/fs.h`"
520 if test "$HAVE_DIO_FILE" != 0 ; then
521         AC_DEFINE(HAVE_DIO_FILE, 1, [the kernel passes struct file to direct_IO])
522         AC_MSG_RESULT(yes)
523 else
524         AC_MSG_RESULT(no)
525 fi
526 ])
527
528 #
529 # LB_LINUX_HEADER_MM_INLINE
530 #
531 # RHEL kernels define page_count in mm_inline.h
532 #
533 AC_DEFUN([LB_LINUX_HEADER_MM_INLINE],
534 [AC_MSG_CHECKING([if kernel has mm_inline.h header])
535 LB_LINUX_TRY_COMPILE([
536         #include <linux/mm_inline.h>
537 ],[
538         #ifndef page_count
539         #error mm_inline.h does not define page_count
540         #endif
541 ],[
542         AC_MSG_RESULT([yes])
543         AC_DEFINE(HAVE_MM_INLINE, 1, [mm_inline found])
544 ],[
545         AC_MSG_RESULT([no])
546 ])
547 ])
548
549 #
550 # LB_LINUX_STRUCT_INODE
551 #
552 # if inode->i_alloc_sem exists
553 #
554 AC_DEFUN([LB_LINUX_STRUCT_INODE],
555 [AC_MSG_CHECKING([if struct inode has i_alloc_sem])
556 LB_LINUX_TRY_COMPILE([
557         #include <linux/fs.h>
558         #include <linux/version.h>
559 ],[
560         #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,24))
561         #error "down_read_trylock broken before 2.4.24"
562         #endif
563         struct inode i;
564         return (char *)&i.i_alloc_sem - (char *)&i;
565 ],[
566         AC_MSG_RESULT([yes])
567         AC_DEFINE(HAVE_I_ALLOC_SEM, 1, [struct inode has i_alloc_sem])
568 ],[
569         AC_MSG_RESULT([no])
570 ])
571 ])