Whamcloud - gitweb
Branch b1_6
[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 # LB_LINUX_PATH
105 #
106 # Find paths for linux, handling kernel-source rpms
107 #
108 AC_DEFUN([LB_LINUX_PATH],
109 [AC_MSG_CHECKING([for Linux sources])
110 AC_ARG_WITH([linux],
111         AC_HELP_STRING([--with-linux=path],
112                        [set path to Linux source (default=/usr/src/linux)]),
113         [LINUX=$with_linux],
114         [LINUX=/usr/src/linux])
115 AC_MSG_RESULT([$LINUX])
116 AC_SUBST(LINUX)
117
118 # -------- check for linux --------
119 LB_CHECK_FILE([$LINUX],[],
120         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
121
122 # -------- linux objects (for 2.6) --
123 AC_MSG_CHECKING([for Linux objects dir])
124 AC_ARG_WITH([linux-obj],
125         AC_HELP_STRING([--with-linux-obj=path],
126                         [set path to Linux objects dir (default=$LINUX)]),
127         [LINUX_OBJ=$with_linux_obj],
128         [LINUX_OBJ=$LINUX])
129 AC_MSG_RESULT([$LINUX_OBJ])
130 AC_SUBST(LINUX_OBJ)
131
132 # -------- check for .config --------
133 AC_ARG_WITH([linux-config],
134         [AC_HELP_STRING([--with-linux-config=path],
135                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
136         [LINUX_CONFIG=$with_linux_config],
137         [LINUX_CONFIG=$LINUX_OBJ/.config])
138 AC_SUBST(LINUX_CONFIG)
139
140 LB_CHECK_FILE([/boot/kernel.h],
141         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
142         [LB_CHECK_FILE([/var/adm/running-kernel.h],
143                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
144
145 AC_ARG_WITH([kernel-source-header],
146         AC_HELP_STRING([--with-kernel-source-header=path],
147                         [Use a different kernel version header.  Consult build/README.kernel-source for details.]),
148         [KERNEL_SOURCE_HEADER=$with_kernel_source_header])
149
150 # ------------ .config exists ----------------
151 LB_CHECK_FILE([$LINUX_CONFIG],[],
152         [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult build/README.kernel-source])])
153
154 # ----------- make dep run? ------------------
155 # at 2.6.19 # $LINUX/include/linux/config.h is removed
156 # and at more old has only one line
157 # include <autoconf.h>
158 LB_CHECK_FILES([$LINUX_OBJ/include/linux/autoconf.h
159                 $LINUX_OBJ/include/linux/version.h
160                 ],[],
161         [AC_MSG_ERROR([Run make config in $LINUX.])])
162 #
163 LB_CHECK_FILE([$LINUX_OBJ/include/linux/config.h],
164         [ AC_DEFINE(HAVE_KERNEL_CONFIG_H, 1,
165                 [kernel modules need to include config.h])
166         ]
167 )
168
169 # ------------ rhconfig.h includes runtime-generated bits --
170 # red hat kernel-source checks
171
172 # we know this exists after the check above.  if the user
173 # tarred up the tree and ran make dep etc. in it, then
174 # version.h gets overwritten with a standard linux one.
175
176 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
177         # This is a clean kernel-source tree, we need to
178         # enable extensive workarounds to get this to build
179         # modules
180         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
181                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
182                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
183                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
184                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
185                 fi],
186                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
187         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
188 fi
189
190 # this is needed before we can build modules
191 LB_LINUX_UML
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 build/README.kernel-source])
202         AC_MSG_ERROR([Kernel modules cannot be build.])
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_LANG_PROGRAM(C)([PROLOGUE], [BODY])
250 # --------------------------------------
251 m4_define([LB_LANG_PROGRAM],
252 [$1
253 int
254 main (void)
255 {
256 dnl Do *not* indent the following line: there may be CPP directives.
257 dnl Don't move the `;' right after for the same reason.
258 $2
259   ;
260   return 0;
261 }])
262
263 #
264 # LB_LINUX_COMPILE_IFELSE
265 #
266 # like AC_COMPILE_IFELSE
267 #
268 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
269 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
270 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
271 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])],
272         [$4],
273         [_AC_MSG_LOG_CONFTEST
274 m4_ifvaln([$5],[$5])dnl])dnl
275 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
276 ])
277
278 #
279 # LB_LINUX_TRY_COMPILE
280 #
281 # like AC_TRY_COMPILE
282 #
283 AC_DEFUN([LB_LINUX_TRY_COMPILE],
284 [LB_LINUX_COMPILE_IFELSE(
285         [AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])],
286         [modules],
287         [test -s build/conftest.o],
288         [$3], [$4])])
289
290 #
291 # LB_LINUX_CONFIG
292 #
293 # check if a given config option is defined
294 #
295 AC_DEFUN([LB_LINUX_CONFIG],
296 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
297 LB_LINUX_TRY_COMPILE([
298 #ifdef HAVE_KERNEL_CONFIG_H
299 #include <linux/config.h>
300 #endif
301 ],[
302 #ifndef CONFIG_$1
303 #error CONFIG_$1 not #defined
304 #endif
305 ],[
306 AC_MSG_RESULT([yes])
307 $2
308 ],[
309 AC_MSG_RESULT([no])
310 $3
311 ])
312 ])
313
314 #
315 # LB_LINUX_CONFIG_IM
316 #
317 # check if a given config option is builtin or as module
318 #
319 AC_DEFUN([LB_LINUX_CONFIG_IM],
320 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1 in or as module])
321 LB_LINUX_TRY_COMPILE([#include <linux/config.h>],[
322 #if !(defined(CONFIG_$1) || defined(CONFIG_$1_MODULE))
323 #error CONFIG_$1 and CONFIG_$1_MODULE not #defined
324 #endif
325 ],[
326 AC_MSG_RESULT([yes])
327 $2
328 ],[
329 AC_MSG_RESULT([no])
330 $3
331 ])
332 ])
333
334 #
335 # LB_LINUX_TRY_MAKE
336 #
337 # like LB_LINUX_TRY_COMPILE, but with different arguments
338 #
339 AC_DEFUN([LB_LINUX_TRY_MAKE],
340 [LB_LINUX_COMPILE_IFELSE([AC_LANG_SOURCE([LB_LANG_PROGRAM([[$1]], [[$2]])])], [$3], [$4], [$5], [$6])])
341
342 #
343 # LB_LINUX_CONFIG_BIG_STACK
344 #
345 # check for big stack patch
346 #
347 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
348 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
349         case $target_cpu in
350                 i?86 | x86_64)
351                         LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
352                                 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
353                                         LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
354                                                 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
355                                         ])
356                                 ])
357                         ])
358                         ;;
359         esac
360 fi
361 ])
362
363 #
364 # LB_PROG_LINUX
365 #
366 # linux tests
367 #
368 AC_DEFUN([LB_PROG_LINUX],
369 [LB_LINUX_PATH
370
371 LB_LINUX_CONFIG([MODULES],[],[
372         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
373 ])
374
375 LB_LINUX_CONFIG([MODVERSIONS])
376
377 LB_LINUX_CONFIG([PREEMPT],[
378         AC_MSG_ERROR([Lustre does not support kernels with preempt enabled.])
379 ])
380
381 LB_LINUX_CONFIG([KALLSYMS],[],[
382 if test "x$ARCH_UM" = "x" ; then
383         AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
384 fi
385 ])
386
387 LB_LINUX_CONFIG([KMOD],[],[
388         AC_MSG_WARN([])
389         AC_MSG_WARN([Kernel module loading support is highly recommended.])
390         AC_MSG_WARN([])
391 ])
392
393 #LB_LINUX_CONFIG_BIG_STACK
394
395 ])
396
397 #
398 # LB_LINUX_CONDITIONALS
399 #
400 # AM_CONDITIONALS for linux
401 #
402 AC_DEFUN([LB_LINUX_CONDITIONALS],
403 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
404 ])
405