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