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