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