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