Whamcloud - gitweb
Branch HEAD
[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 LB_LINUX_TRY_MAKE([
59         #include <linux/version.h>
60 ],[
61         char *LINUXRELEASE;
62         LINUXRELEASE=UTS_RELEASE;
63 ],[
64         $makerule LUSTRE_KERNEL_TEST=conftest.i
65 ],[
66         test -s build/conftest.i
67 ],[
68         # LINUXRELEASE="UTS_RELEASE"
69         eval $(grep "LINUXRELEASE=" build/conftest.i)
70 ],[
71         AC_MSG_RESULT([unknown])
72         AC_MSG_ERROR([Could not preprocess test program.  Consult config.log for details.])
73 ])
74 rm -f build/conftest.i
75 if test x$LINUXRELEASE = x ; then
76         AC_MSG_RESULT([unknown])
77         AC_MSG_ERROR([Could not determine Linux release version from linux/version.h.])
78 fi
79 AC_MSG_RESULT([$LINUXRELEASE])
80 AC_SUBST(LINUXRELEASE)
81
82 moduledir='/lib/modules/'$LINUXRELEASE/kernel
83 AC_SUBST(moduledir)
84
85 modulefsdir='$(moduledir)/fs/$(PACKAGE)'
86 AC_SUBST(modulefsdir)
87
88 modulenetdir='$(moduledir)/net/$(PACKAGE)'
89 AC_SUBST(modulenetdir)
90
91 # ------------ RELEASE --------------------------------
92 AC_MSG_CHECKING([for Lustre release])
93 RELEASE="`echo ${LINUXRELEASE} | tr '-' '_'`_`date +%Y%m%d%H%M`"
94 AC_MSG_RESULT($RELEASE)
95 AC_SUBST(RELEASE)
96 ])
97
98 #
99 # LB_LINUX_PATH
100 #
101 # Find paths for linux, handling kernel-source rpms
102 #
103 AC_DEFUN([LB_LINUX_PATH],
104 [AC_MSG_CHECKING([for Linux sources])
105 AC_ARG_WITH([linux],
106         AC_HELP_STRING([--with-linux=path],
107                        [set path to Linux source (default=/usr/src/linux)]),
108         [LINUX=$with_linux],
109         [LINUX=/usr/src/linux])
110 AC_MSG_RESULT([$LINUX])
111 AC_SUBST(LINUX)
112
113 # -------- check for linux --------
114 LB_CHECK_FILE([$LINUX],[],
115         [AC_MSG_ERROR([Kernel source $LINUX could not be found.])])
116
117 # -------- linux objects (for 2.6) --
118 AC_MSG_CHECKING([for Linux objects dir])
119 AC_ARG_WITH([linux-obj],
120         AC_HELP_STRING([--with-linux-obj=path],
121                         [set path to Linux objects dir (default=$LINUX)]),
122         [LINUX_OBJ=$with_linux_obj],
123         [LINUX_OBJ=$LINUX])
124 AC_MSG_RESULT([$LINUX_OBJ])
125 AC_SUBST(LINUX_OBJ)
126
127 # -------- check for .config --------
128 AC_ARG_WITH([linux-config],
129         [AC_HELP_STRING([--with-linux-config=path],
130                         [set path to Linux .conf (default=$LINUX_OBJ/.config)])],
131         [LINUX_CONFIG=$with_linux_config],
132         [LINUX_CONFIG=$LINUX_OBJ/.config])
133 AC_SUBST(LINUX_CONFIG)
134
135 LB_CHECK_FILE([/boot/kernel.h],
136         [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
137         [LB_CHECK_FILE([/var/adm/running-kernel.h],
138                 [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h'])])
139
140 AC_ARG_WITH([kernel-source-header],
141         AC_HELP_STRING([--with-kernel-source-header=path],
142                         [Use a different kernel version header.  Consult build/README.kernel-source for details.]),
143         [KERNEL_SOURCE_HEADER=$with_kernel_source_header])
144
145 # ------------ .config exists ----------------
146 LB_CHECK_FILE([$LINUX_CONFIG],[],
147         [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult build/README.kernel-source])])
148
149 # ----------- make dep run? ------------------
150 LB_CHECK_FILES([$LINUX_OBJ/include/linux/autoconf.h
151                 $LINUX_OBJ/include/linux/version.h
152                 $LINUX/include/linux/config.h],[],
153         [AC_MSG_ERROR([Run make config in $LINUX.])])
154
155 # ------------ rhconfig.h includes runtime-generated bits --
156 # red hat kernel-source checks
157
158 # we know this exists after the check above.  if the user
159 # tarred up the tree and ran make dep etc. in it, then
160 # version.h gets overwritten with a standard linux one.
161
162 if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
163         # This is a clean kernel-source tree, we need to
164         # enable extensive workarounds to get this to build
165         # modules
166         LB_CHECK_FILE([$KERNEL_SOURCE_HEADER],
167                 [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
168                         AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
169                         AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
170                         AC_MSG_WARN([Consult build/README.kernel-source for details.])
171                 fi],
172                 [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult build/README.kernel-source for details.])])
173         EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
174 fi
175
176 # this is needed before we can build modules
177 LB_LINUX_UML
178 LB_LINUX_VERSION
179
180 # --- check that we can build modules at all
181 AC_MSG_CHECKING([that modules can be built at all])
182 LB_LINUX_TRY_COMPILE([],[],[
183         AC_MSG_RESULT([yes])
184 ],[
185         AC_MSG_RESULT([no])
186         AC_MSG_WARN([Consult config.log for details.])
187         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult build/README.kernel-source])
188         AC_MSG_ERROR([Kernel modules cannot be build.])
189 ])
190
191 LB_LINUX_RELEASE
192 ])
193
194 #
195 # LB_LINUX_UML
196 #
197 # check for a uml kernel
198 #
199 AC_DEFUN([LB_LINUX_UML],
200 [ARCH_UM=
201 UML_CFLAGS=
202
203 AC_MSG_CHECKING([if you are running user mode linux for $target_cpu])
204 if test -e $LINUX/include/asm-um ; then
205         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
206                 ARCH_UM='ARCH=um'
207                 # see notes in Rules.in
208                 UML_CFLAGS='-O0'
209                 AC_MSG_RESULT(yes)
210         else
211                 AC_MSG_RESULT([no (asm doesn't point at asm-um)])
212         fi
213 else
214         AC_MSG_RESULT([no (asm-um missing)])
215 fi
216 AC_SUBST(ARCH_UM)
217 AC_SUBST(UML_CFLAGS)
218 ])
219
220 # these are like AC_TRY_COMPILE, but try to build modules against the
221 # kernel, inside the build directory
222
223 #
224 # LB_LINUX_CONFTEST
225 #
226 # create a conftest.c file
227 #
228 AC_DEFUN([LB_LINUX_CONFTEST],
229 [cat >conftest.c <<_ACEOF
230 $1
231 _ACEOF
232 ])
233
234 #
235 # LB_LINUX_COMPILE_IFELSE
236 #
237 # like AC_COMPILE_IFELSE
238 #
239 AC_DEFUN([LB_LINUX_COMPILE_IFELSE],
240 [m4_ifvaln([$1], [LB_LINUX_CONFTEST([$1])])dnl
241 rm -f build/conftest.o build/conftest.mod.c build/conftest.ko
242 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])],
243         [$4],
244         [_AC_MSG_LOG_CONFTEST
245 m4_ifvaln([$5],[$5])dnl])dnl
246 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
247 ])
248
249 #
250 # LB_LINUX_TRY_COMPILE
251 #
252 # like AC_TRY_COMPILE
253 #
254 AC_DEFUN([LB_LINUX_TRY_COMPILE],
255 [LB_LINUX_COMPILE_IFELSE(
256         [AC_LANG_PROGRAM([[$1]], [[$2]])],
257         [modules],
258         [test -s build/conftest.o],
259         [$3], [$4])])
260
261 #
262 # LB_LINUX_CONFIG
263 #
264 # check if a given config option is defined
265 #
266 AC_DEFUN([LB_LINUX_CONFIG],
267 [AC_MSG_CHECKING([if Linux was built with CONFIG_$1])
268 LB_LINUX_TRY_COMPILE([#include <linux/config.h>],[
269 #ifndef CONFIG_$1
270 #error CONFIG_$1 not #defined
271 #endif
272 ],[
273 AC_MSG_RESULT([yes])
274 $2
275 ],[
276 AC_MSG_RESULT([no])
277 $3
278 ])
279 ])
280
281 #
282 # LB_LINUX_TRY_MAKE
283 #
284 # like LB_LINUX_TRY_COMPILE, but with different arguments
285 #
286 AC_DEFUN([LB_LINUX_TRY_MAKE],
287 [LB_LINUX_COMPILE_IFELSE([AC_LANG_PROGRAM([[$1]], [[$2]])], [$3], [$4], [$5], [$6])])
288
289 #
290 # LB_LINUX_CONFIG_BIG_STACK
291 #
292 # check for big stack patch
293 #
294 AC_DEFUN([LB_LINUX_CONFIG_BIG_STACK],
295 [if test "x$ARCH_UM" = "x" -a "x$linux25" = "xno" ; then
296         case $target_cpu in
297                 i?86 | x86_64)
298                         LB_LINUX_CONFIG([STACK_SIZE_16KB],[],[
299                                 LB_LINUX_CONFIG([STACK_SIZE_32KB],[],[
300                                         LB_LINUX_CONFIG([STACK_SIZE_64KB],[],[
301                                                 AC_MSG_ERROR([Lustre requires that Linux is configured with at least a 16KB stack.])
302                                         ])
303                                 ])
304                         ])
305                         ;;
306         esac
307 fi
308 ])
309
310 #
311 # LB_PROG_LINUX
312 #
313 # linux tests
314 #
315 AC_DEFUN([LB_PROG_LINUX],
316 [LB_LINUX_PATH
317
318 LB_LINUX_CONFIG([MODULES],[],[
319         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
320 ])
321
322 LB_LINUX_CONFIG([MODVERSIONS])
323
324 LB_LINUX_CONFIG([PREEMPT],[
325         AC_MSG_ERROR([Lustre does not support kernels with preempt enabled.])
326 ])
327
328 LB_LINUX_CONFIG([KALLSYMS],[],[
329 if test "x$ARCH_UM" = "x" ; then
330         AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
331 fi
332 ])
333
334 LB_LINUX_CONFIG([KMOD],[],[
335         AC_MSG_WARN([])
336         AC_MSG_WARN([Kernel module loading support is highly recommended.])
337         AC_MSG_WARN([])
338 ])
339
340 #LB_LINUX_CONFIG_BIG_STACK
341
342 # LNet tests
343 LN_PROG_LINUX
344
345 # Lustre tests
346 LC_PROG_LINUX
347
348 # Portals tests
349 if test "$PORTALS" ; then
350         LP_PROG_LINUX
351 fi
352 ])
353
354 #
355 # LB_LINUX_CONDITIONALS
356 #
357 # AM_CONDITIONALS for linux
358 #
359 AC_DEFUN([LB_LINUX_CONDITIONALS],
360 [AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
361 ])