Whamcloud - gitweb
9759b493b0606e785d6ebc3e0b0c9b32b5491ba5
[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 # ------------ rhconfig.h includes runtime-generated bits --
165 # red hat kernel-source checks
166
167 # we know this exists after the check above.  if the user
168 # tarred up the tree and ran make dep etc. in it, then
169 # version.h gets overwritten with a standard linux one.
170
171 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
172         # This is a clean kernel-source tree, we need to
173         # enable extensive workarounds to get this to build
174         # modules
175         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
176                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
177                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
178                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
179                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
180                 fi],
181                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
182         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
183 fi
184
185 # this is needed before we can build modules
186 LB_LINUX_UML
187 LB_LINUX_VERSION
188
189 # --- check that we can build modules at all
190 AC_MSG_CHECKING([that modules can be built at all])
191 LB_LINUX_TRY_COMPILE([],[],[
192         AC_MSG_RESULT([yes])
193 ],[
194         AC_MSG_RESULT([no])
195         AC_MSG_WARN([Consult config.log for details.])
196         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
197         AC_MSG_ERROR([Kernel modules cannot be built.])
198 ])
199
200 LB_LINUX_RELEASE
201 ]) # end of LB_LINUX_PATH
202
203 #
204 #
205 # LB_LINUX_MODPOST
206 #
207 # Find modpost and check it
208 #
209 AC_DEFUN([LB_LINUX_MODPOST],
210 [
211 # Find the modpost utility
212 AC_CHECK_FILE([$LINUX_OBJ/scripts/mod/modpost],
213         [MODPOST=$LINUX_OBJ/scripts/mod/modpost],
214         [AC_CHECK_FILE([$LINUX_OBJ/scripts/modpost],
215                 [MODPOST=$LINUX_OBJ/scripts/modpost],
216                 AC_MSG_ERROR([modpost not found.])
217         )]
218 )
219 AC_SUBST(MODPOST)
220
221 # Ensure it can run
222 AC_MSG_CHECKING([if modpost can be run])
223 if $MODPOST ; then
224         AC_MSG_RESULT([yes])
225 else
226         AC_MSG_ERROR([modpost can not be run.])
227 fi
228
229 # Check if modpost supports (and therefore requires) -m
230 AC_MSG_CHECKING([if modpost supports -m])
231 if $MODPOST -m 2>/dev/null ; then
232         AC_MSG_RESULT([yes])
233         MODPOST_ARGS=-m
234 else
235         AC_MSG_RESULT([no])
236         MODPOST_ARGS=""
237 fi
238 AC_SUBST(MODPOST_ARGS)
239 ])
240
241 #
242 # LB_LINUX_UML
243 #
244 # check for a uml kernel
245 #
246 AC_DEFUN([LB_LINUX_UML],
247 [ARCH_UM=
248 UML_CFLAGS=
249
250 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
251 if test -e $LINUX/include/asm-um ; then
252         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
253                 ARCH_UM='ARCH=um'
254                 # see notes in Rules.in
255                 UML_CFLAGS='-O0'
256                 AC_MSG_RESULT(yes)
257         else
258                 AC_MSG_RESULT([no (asm doesn't point at asm-um)])
259         fi
260 else
261         AC_MSG_RESULT([no (asm-um missing)])
262 fi
263 AC_SUBST(ARCH_UM)
264 AC_SUBST(UML_CFLAGS)
265 ])
266
267 # these are like AC_TRY_COMPILE, but try to build modules against the
268 # kernel, inside the build directory
269
270 #
271 # LB_LINUX_CONFTEST
272 #
273 # create a conftest.c file
274 #
275 AC_DEFUN([LB_LINUX_CONFTEST],
276 [cat >conftest.c <<_ACEOF
277 $1
278 _ACEOF
279 ])
280
281
282 # LB_LANG_PROGRAM(C)([PROLOGUE], [BODY])
283 # --------------------------------------
284 m4_define([LB_LANG_PROGRAM],
285 [$1
286 int
287 main (void)
288 {
289 dnl Do *not* indent the following line: there may be CPP directives.
290 dnl Don't move the `;' right after for the same reason.
291 $2
292   ;
293   return 0;
294 }])
295
296 #
297 # LB_LINUX_COMPILE_IFELSE
298 #
299 # like AC_COMPILE_IFELSE
300 #
301 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
302 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
303 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
304 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 -I$LINUX/include -I$LINUX_OBJ/include -I$LINUX_OBJ/include2 -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])],
305         [$4],
306         [_AC_MSG_LOG_CONFTEST
307 m4_ifvaln([$5],[$5])dnl])dnl
308 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
309 ])
310
311 #
312 # LB_LINUX_ARCH
313 #
314 # Determine the kernel's idea of the current architecture
315 #
316 AC_DEFUN([LB_LINUX_ARCH],
317          [AC_MSG_CHECKING([Linux kernel architecture])
318           AS_IF([rm -f $PWD/build/arch
319                  make -s --no-print-directory echoarch -f $PWD/build/Makefile \
320                      LUSTRE_LINUX_CONFIG=$LINUX_CONFIG -C $LINUX_OBJ $ARCH_UM \
321                      ARCHFILE=$PWD/build/arch && LINUX_ARCH=`cat $PWD/build/arch`],
322                 [AC_MSG_RESULT([$LINUX_ARCH])],
323                 [AC_MSG_ERROR([Could not determine the kernel architecture.])])
324           rm -f build/arch])
325
326 #
327 # LB_LINUX_TRY_COMPILE
328 #
329 # like AC_TRY_COMPILE
330 #
331 AC_DEFUN([LB_LINUX_TRY_COMPILE],
332 [LB_LINUX_COMPILE_IFELSE(
333         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
334         [modules],
335         [test -s build/conftest.o],
336         [$3], [$4])])
337
338 #
339 # LB_LINUX_CONFIG
340 #
341 # check if a given config option is defined
342 #
343 AC_DEFUN([LB_LINUX_CONFIG],
344 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
345 LB_LINUX_TRY_COMPILE([
346 #ifndef AUTOCONF_INCLUDED
347 #include <linux/config.h>
348 #endif
349 ],[
350 #ifndef CONFIG_$1
351 #error CONFIG_$1 not #defined
352 #endif
353 ],[
354 AC_MSG_RESULT([yes])
355 $2
356 ],[
357 AC_MSG_RESULT([no])
358 $3
359 ])
360 ])
361
362 #
363 # LB_LINUX_CONFIG_IM
364 #
365 # check if a given config option is builtin or as module
366 #
367 AC_DEFUN([LB_LINUX_CONFIG_IM],
368 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
369 LB_LINUX_TRY_COMPILE([#include <linux/config.h>],[
370 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
371 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
372 #endif
373 ],[
374 AC_MSG_RESULT([yes])
375 $2
376 ],[
377 AC_MSG_RESULT([no])
378 $3
379 ])
380 ])
381
382 #
383 # LB_LINUX_TRY_MAKE
384 #
385 # like LB_LINUX_TRY_COMPILE, but with different arguments
386 #
387 AC_DEFUN([LB_LINUX_TRY_MAKE],
388 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
389
390 #
391 # LB_LINUX_CONFIG_BIG_STACK
392 #
393 # check for big stack patch
394 #
395 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
396 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
397         case $target_cpu in
398                 i?86 | x86_64)
399                         LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
400                                 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
401                                         LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
402                                                 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
403                                         ])
404                                 ])
405                         ])
406                         ;;
407         esac
408 fi
409 ])
410
411 #
412 # LB_PROG_LINUX
413 #
414 # linux tests
415 #
416 AC_DEFUN([LB_PROG_LINUX],
417 [LB_LINUX_PATH
418
419 LB_LINUX_CONFIG([MODULES],[],[
420         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
421 ])
422
423 LB_LINUX_CONFIG([MODVERSIONS])
424
425 LB_LINUX_CONFIG([PREEMPT],[
426         AC_MSG_ERROR([Lustre does not support kernels with preempt enabled.])
427 ])
428
429 LB_LINUX_CONFIG([KALLSYMS],[],[
430 if test "x$ARCH_UM" = "x" ; then
431         AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
432 fi
433 ])
434
435 LB_LINUX_CONFIG([KMOD],[],[
436         AC_MSG_WARN([])
437         AC_MSG_WARN([Kernel module loading support is highly recommended.])
438         AC_MSG_WARN([])
439 ])
440
441 #LB_LINUX_CONFIG_BIG_STACK
442
443 ])
444
445 #
446 # LB_LINUX_CONDITIONALS
447 #
448 # AM_CONDITIONALS for linux
449 #
450 AC_DEFUN([LB_LINUX_CONDITIONALS],
451 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
452 ])
453
454
455 #
456 # LB_CHECK_SYMBOL_EXPORT
457 # check symbol exported or not 
458 # $1 - symbol
459 # $2 - file(s) for find.
460 # $3 - do 'yes'
461 # $4 - do 'no'
462 #
463 # 2.6 based kernels - put modversion info into $LINUX/Module.modvers
464 # or check 
465 AC_DEFUN([LB_CHECK_SYMBOL_EXPORT],
466 [AC_MSG_CHECKING([if Linux was built with symbol $1 is exported])
467 grep -q -E '[[[:space:]]]$1[[[:space:]]]' $LINUX/Module.symvers 2>/dev/null
468 rc=$?
469 if test $rc -ne 0; then
470     export=0
471     for file in $2; do
472         grep -q -E "EXPORT_SYMBOL.*($1)" "$LINUX/$file" 2>/dev/null
473         rc=$?
474         if test $rc -eq 0; then
475                 export=1
476                 break;
477         fi
478     done
479     if test $export -eq 0; then
480         AC_MSG_RESULT([no])
481         $4
482     else
483         AC_MSG_RESULT([yes])
484         $3
485     fi
486 else
487     AC_MSG_RESULT([yes])
488     $3
489 fi
490 ])