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