Whamcloud - gitweb
0c040ecff1cedd5d30d57089869148f81356b27d
[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 [LB_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                         makerule="_module_$makerule"
30                         MODULE_TARGET="M"
31                         LB_LINUX_TRY_MAKE([],[],
32                                 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
33                                 [test -s build/conftest.i],
34                                 [
35                                         AC_MSG_RESULT([yes])
36                                 ],[
37                                         AC_MSG_ERROR([unknown; check config.log for details])
38                                 ])
39                 ])
40 else
41         makerule="_dir_$PWD/build"
42 fi
43
44 AC_SUBST(MODULE_TARGET)
45 AC_SUBST(linux25)
46 AC_SUBST(KMODEXT)
47 ])
48
49 #
50 # LB_LINUX_RELEASE
51 #
52 # get the release version of linux
53 #
54 AC_DEFUN([LB_LINUX_RELEASE],
55 [LINUXRELEASE=
56 rm -f build/conftest.i
57 AC_MSG_CHECKING([for Linux release])
58 if test -s $LINUX_OBJ/include/linux/utsrelease.h ; then
59         LINUXRELEASEHEADER=utsrelease.h
60 else
61         LINUXRELEASEHEADER=version.h
62 fi
63 LB_LINUX_TRY_MAKE([
64         #include <linux/$LINUXRELEASEHEADER>
65 ],[
66         char *LINUXRELEASE;
67         LINUXRELEASE=UTS_RELEASE;
68 ],[
69         $makerule LUSTRE_KERNEL_TEST=conftest.i
70 ],[
71         test -s build/conftest.i
72 ],[
73         # LINUXRELEASE="UTS_RELEASE"
74         eval $(grep "LINUXRELEASE=" build/conftest.i)
75 ],[
76         AC_MSG_RESULT([unknown])
77         AC_MSG_ERROR([Could not preprocess test program.  Consult config.log for details.])
78 ])
79 rm -f build/conftest.i
80 if test x$LINUXRELEASE = x ; then
81         AC_MSG_RESULT([unknown])
82         AC_MSG_ERROR([Could not determine Linux release version from linux/version.h.])
83 fi
84 AC_MSG_RESULT([$LINUXRELEASE])
85 AC_SUBST(LINUXRELEASE)
86
87 moduledir='/lib/modules/'$LINUXRELEASE/kernel
88 AC_SUBST(moduledir)
89
90 modulefsdir='$(moduledir)/fs/$(PACKAGE)'
91 AC_SUBST(modulefsdir)
92
93 modulenetdir='$(moduledir)/net/$(PACKAGE)'
94 AC_SUBST(modulenetdir)
95
96 # ------------ RELEASE --------------------------------
97 AC_MSG_CHECKING([for Lustre release])
98 RELEASE="`echo ${LINUXRELEASE} | tr '-' '_'`_`date +%Y%m%d%H%M`"
99 AC_MSG_RESULT($RELEASE)
100 AC_SUBST(RELEASE)
101 ])
102
103 #
104 #
105 # LB_LINUX_PATH
106 #
107 # Find paths for linux, handling kernel-source rpms
108 #
109 AC_DEFUN([LB_LINUX_PATH],
110 [AC_MSG_CHECKING([for Linux sources])
111 AC_ARG_WITH([linux],
112         AC_HELP_STRING([--with-linux=path],
113                        [set path to Linux source (default=/usr/src/linux)]),
114         [LINUX=$with_linux],
115         [LINUX=/usr/src/linux])
116 AC_MSG_RESULT([$LINUX])
117 AC_SUBST(LINUX)
118
119 # -------- check for linux --------
120 LB_CHECK_FILE([$LINUX],[],
121         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
122
123 # -------- linux objects (for 2.6) --
124 AC_MSG_CHECKING([for Linux objects dir])
125 AC_ARG_WITH([linux-obj],
126         AC_HELP_STRING([--with-linux-obj=path],
127                         [set path to Linux objects dir (default=$LINUX)]),
128         [LINUX_OBJ=$with_linux_obj],
129         [LINUX_OBJ=$LINUX])
130 AC_MSG_RESULT([$LINUX_OBJ])
131 AC_SUBST(LINUX_OBJ)
132
133 # -------- check for .config --------
134 AC_ARG_WITH([linux-config],
135         [AC_HELP_STRING([--with-linux-config=path],
136                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
137         [LINUX_CONFIG=$with_linux_config],
138         [LINUX_CONFIG=$LINUX_OBJ/.config])
139 AC_SUBST(LINUX_CONFIG)
140
141 LB_CHECK_FILE([/boot/kernel.h],
142         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
143         [LB_CHECK_FILE([/var/adm/running-kernel.h],
144                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
145
146 AC_ARG_WITH([kernel-source-header],
147         AC_HELP_STRING([--with-kernel-source-header=path],
148                         [Use a different kernel version header.  Consult build/README.kernel-source for details.]),
149         [KERNEL_SOURCE_HEADER=$with_kernel_source_header])
150
151 # ------------ .config exists ----------------
152 LB_CHECK_FILE([$LINUX_CONFIG],[],
153         [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult build/README.kernel-source])])
154
155 # ----------- make dep run? ------------------
156 # at 2.6.19 # $LINUX/include/linux/config.h is removed
157 # and at more old has only one line
158 # include <autoconf.h>
159 LB_CHECK_FILES([$LINUX_OBJ/include/linux/autoconf.h
160                 $LINUX_OBJ/include/linux/version.h
161                 ],[],
162         [AC_MSG_ERROR([Run make config in $LINUX.])])
163 #
164 LB_CHECK_FILE([$LINUX_OBJ/include/linux/config.h],
165         [ AC_DEFINE(HAVE_KERNEL_CONFIG_H, 1,
166                 [kernel modules need to include config.h])
167         ]
168 )
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         LB_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 build/README.kernel-source for details.])
186                 fi],
187                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/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_UML
193 LB_LINUX_VERSION
194
195 # --- check that we can build modules at all
196 AC_MSG_CHECKING([that modules can be built at all])
197 LB_LINUX_TRY_COMPILE([],[],[
198         AC_MSG_RESULT([yes])
199 ],[
200         AC_MSG_RESULT([no])
201         AC_MSG_WARN([Consult config.log for details.])
202         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
203         AC_MSG_ERROR([Kernel modules cannot be built.])
204 ])
205
206 LB_LINUX_RELEASE
207 ]) # end of LB_LINUX_PATH
208
209 #
210 #
211 # LB_LINUX_MODPOST
212 #
213 # Find modpost and check it
214 #
215 AC_DEFUN([LB_LINUX_MODPOST],
216 [
217 # Find the modpost utility
218 AC_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
219         [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
220         [AC_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
221                 [MODPOST=$LINUX_OBJ/scripts/modpost],
222                 AC_MSG_ERROR([modpost not found.])
223         )]
224 )
225 AC_SUBST(MODPOST)
226
227 # Ensure it can run
228 AC_MSG_CHECKING([if modpost can be run])
229 if $MODPOST ; then
230         AC_MSG_RESULT([yes])
231 else
232         AC_MSG_ERROR([modpost can not be run.])
233 fi
234
235 # Check if modpost supports (and therefore requires) -m
236 AC_MSG_CHECKING([if modpost supports -m])
237 if $MODPOST -m 2>/dev/null ; then
238         AC_MSG_RESULT([yes])
239         MODPOST_ARGS=-m
240 else
241         AC_MSG_RESULT([no])
242         MODPOST_ARGS=""
243 fi
244 AC_SUBST(MODPOST_ARGS)
245 ])
246
247 #
248 # LB_LINUX_UML
249 #
250 # check for a uml kernel
251 #
252 AC_DEFUN([LB_LINUX_UML],
253 [ARCH_UM=
254 UML_CFLAGS=
255
256 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
257 if test -e $LINUX/include/asm-um ; then
258         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
259                 ARCH_UM='ARCH=um'
260                 # see notes in Rules.in
261                 UML_CFLAGS='-O0'
262                 AC_MSG_RESULT(yes)
263         else
264                 AC_MSG_RESULT([no (asm doesn't point at asm-um)])
265         fi
266 else
267         AC_MSG_RESULT([no (asm-um missing)])
268 fi
269 AC_SUBST(ARCH_UM)
270 AC_SUBST(UML_CFLAGS)
271 ])
272
273 # these are like AC_TRY_COMPILE, but try to build modules against the
274 # kernel, inside the build directory
275
276 #
277 # LB_LINUX_CONFTEST
278 #
279 # create a conftest.c file
280 #
281 AC_DEFUN([LB_LINUX_CONFTEST],
282 [cat >conftest.c <<_ACEOF
283 $1
284 _ACEOF
285 ])
286
287
288 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
289 # --------------------------------------
290 m4_define([LB_LANG_PROGRAM],
291 [$1
292 int
293 main (void)
294 {
295 dnl Do *not* indent the following line: there may be CPP directives.
296 dnl Don't move the `;' right after for the same reason.
297 $2
298   ;
299   return 0;
300 }])
301
302 #
303 # LB_LINUX_COMPILE_IFELSE
304 #
305 # like AC_COMPILE_IFELSE
306 #
307 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
308 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
309 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
310 AS_IF([AC_TRY_COMMAND(cp conftest.c build && make [$2] CC="$CC" -f $PWD/build/Makefile LUSTRE_LINUX_CONFIG=$LINUX_CONFIG LINUXINCLUDE="$EXTRA_LNET_INCLUDE -Iinclude -include include/linux/autoconf.h" -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])],
311         [$4],
312         [_AC_MSG_LOG_CONFTEST
313 m4_ifvaln([$5],[$5])dnl])dnl
314 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
315 ])
316
317 #
318 # LB_LINUX_TRY_COMPILE
319 #
320 # like AC_TRY_COMPILE
321 #
322 AC_DEFUN([LB_LINUX_TRY_COMPILE],
323 [LB_LINUX_COMPILE_IFELSE(
324         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
325         [modules],
326         [test -s build/conftest.o],
327         [$3], [$4])])
328
329 #
330 # LB_LINUX_CONFIG
331 #
332 # check if a given config option is defined
333 #
334 AC_DEFUN([LB_LINUX_CONFIG],
335 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
336 LB_LINUX_TRY_COMPILE([
337 #ifdef HAVE_KERNEL_CONFIG_H
338 #include <linux/config.h>
339 #endif
340 ],[
341 #ifndef CONFIG_$1
342 #error CONFIG_$1 not #defined
343 #endif
344 ],[
345 AC_MSG_RESULT([yes])
346 $2
347 ],[
348 AC_MSG_RESULT([no])
349 $3
350 ])
351 ])
352
353 #
354 # LB_LINUX_CONFIG_IM
355 #
356 # check if a given config option is builtin or as module
357 #
358 AC_DEFUN([LB_LINUX_CONFIG_IM],
359 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
360 LB_LINUX_TRY_COMPILE([#include <linux/config.h>],[
361 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
362 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
363 #endif
364 ],[
365 AC_MSG_RESULT([yes])
366 $2
367 ],[
368 AC_MSG_RESULT([no])
369 $3
370 ])
371 ])
372
373 #
374 # LB_LINUX_TRY_MAKE
375 #
376 # like LB_LINUX_TRY_COMPILE, but with different arguments
377 #
378 AC_DEFUN([LB_LINUX_TRY_MAKE],
379 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
380
381 #
382 # LB_LINUX_CONFIG_BIG_STACK
383 #
384 # check for big stack patch
385 #
386 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
387 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
388         case $target_cpu in
389                 i?86 | x86_64)
390                         LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
391                                 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
392                                         LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
393                                                 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
394                                         ])
395                                 ])
396                         ])
397                         ;;
398         esac
399 fi
400 ])
401
402 #
403 # LB_PROG_LINUX
404 #
405 # linux tests
406 #
407 AC_DEFUN([LB_PROG_LINUX],
408 [LB_LINUX_PATH
409
410 LB_LINUX_CONFIG([MODULES],[],[
411         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
412 ])
413
414 LB_LINUX_CONFIG([MODVERSIONS])
415
416 LB_LINUX_CONFIG([PREEMPT],[
417         AC_MSG_ERROR([Lustre does not support kernels with preempt enabled.])
418 ])
419
420 LB_LINUX_CONFIG([KALLSYMS],[],[
421 if test "x$ARCH_UM" = "x" ; then
422         AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
423 fi
424 ])
425
426 LB_LINUX_CONFIG([KMOD],[],[
427         AC_MSG_WARN([])
428         AC_MSG_WARN([Kernel module loading support is highly recommended.])
429         AC_MSG_WARN([])
430 ])
431
432 #LB_LINUX_CONFIG_BIG_STACK
433
434 ])
435
436 #
437 # LB_LINUX_CONDITIONALS
438 #
439 # AM_CONDITIONALS for linux
440 #
441 AC_DEFUN([LB_LINUX_CONDITIONALS],
442 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
443 ])
444
445
446 #
447 # LB_CHECK_SYMBOL_EXPORT
448 # check symbol exported or not 
449 # $1 - symbol
450 # $2 - file(s) for find.
451 # $3 - do 'yes'
452 # $4 - do 'no'
453 #
454 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
455 # or check 
456 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
457 [AC_MSG_CHECKING([if Linux was built with symbol $1 is exported])
458 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/Module.symvers 2>/dev/null
459 rc=$?
460 if test $rc -ne 0; then
461     export=0
462     for file in $2; do
463         grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
464         rc=$?
465         if test $rc -eq 0; then
466                 export=1
467                 break;
468         fi
469     done
470     if test $export -eq 0; then
471         AC_MSG_RESULT([no])
472         $4
473     else
474         AC_MSG_RESULT([yes])
475         $3
476     fi
477 else
478     AC_MSG_RESULT([yes])
479     $3
480 fi
481 ])