Whamcloud - gitweb
finish last commit
[fs/lustre-release.git] / build / build.ac
1 # Four main targets: lustre kernel modules, utilities, tests, and liblustre
2 AC_MSG_CHECKING([whether to build kernel modules])
3 AC_ARG_ENABLE([modules],
4         AC_HELP_STRING([--disable-modules],
5                         [disable building of Lustre kernel modules]),
6         [],[enable_modules='yes'])
7 AC_MSG_RESULT([$enable_modules])
8 AM_CONDITIONAL(MODULES, test x$enable_modules = xyes)
9
10 AC_MSG_CHECKING([whether to build utilities])
11 AC_ARG_ENABLE([utils],
12         AC_HELP_STRING([--disable-utils],
13                         [disable building of Lustre utility programs]),
14         [],[enable_utils='yes'])
15 AC_MSG_RESULT([$enable_utils])
16
17 AC_MSG_CHECKING([whether to build Lustre tests])
18 AC_ARG_ENABLE([tests],
19         AC_HELP_STRING([--disable-tests],
20                         [disable building of Lustre tests]),
21         [],[enable_tests='yes'])
22 AC_MSG_RESULT([$enable_tests])
23
24 # specify wether to build doc or not
25 AC_MSG_CHECKING([whether to build docs])
26 AC_ARG_ENABLE(doc,
27         AC_HELP_STRING([--disable-doc],
28                         [skip creation of pdf documentation]),
29         [
30                 if test x$enable_doc = xyes ; then
31                     ENABLE_DOC=1           
32                 else
33                     ENABLE_DOC=0
34                 fi
35         ],[
36                 ENABLE_DOC=0
37                 enable_doc='no'
38         ])
39 AC_MSG_RESULT([$enable_doc])
40 AM_CONDITIONAL(DOC, test x$ENABLE_DOC = x1)
41 AC_SUBST(ENABLE_DOC)
42
43 # we need to pass a full path here for kernel makefiles
44 INCLUDE_RULES="include $PWD/build/Rules"
45 AC_SUBST(INCLUDE_RULES)
46
47 # directories for binaries
48 AC_PREFIX_DEFAULT([/usr])
49
50 sysconfdir='/etc'
51 AC_SUBST(sysconfdir)
52
53 # Directories for documentation and demos.
54 docdir='${datadir}/doc/$(PACKAGE)'
55 AC_SUBST(docdir)
56
57 # ----------  BAD gcc? ------------
58 AC_PROG_RANLIB
59 AC_PROG_CC
60 AC_MSG_CHECKING([for buggy compiler])
61 CC_VERSION=`$CC -v 2>&1 | grep "^gcc version"`
62 bad_cc() {
63         AC_MSG_RESULT([buggy compiler found!])
64         echo
65         echo "   '$CC_VERSION'"
66         echo "  has been known to generate bad code, "
67         echo "  please get an updated compiler."
68         AC_MSG_ERROR([sorry])
69 }
70 TMP_VERSION=`echo $CC_VERSION | cut -c 1-16`
71 if test "$TMP_VERSION" = "gcc version 2.95"; then
72         bad_cc
73 fi
74 case "$CC_VERSION" in 
75         # ost_pack_niobuf putting 64bit NTOH temporaries on the stack
76         # without "sub    $0xc,%esp" to protect the stack from being
77         # stomped on by interrupts (bug 606)
78         "gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)")
79                 bad_cc
80                 ;;
81         # mandrake's similar sub 0xc compiler bug
82         # http://marc.theaimsgroup.com/?l=linux-kernel&m=104748366226348&w=2
83         "gcc version 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)")
84                 bad_cc
85                 ;;
86         *)
87                 AC_MSG_RESULT([no known problems])
88                 ;;
89 esac
90 # end ------  BAD gcc? ------------
91
92 # ---------  unsigned long long sane? -------
93
94 AC_CHECK_SIZEOF(unsigned long long, 0)
95 echo "---> size SIZEOF $SIZEOF_unsigned_long_long"
96 echo "---> size SIZEOF $ac_cv_sizeof_unsigned_long_long"
97 if test $ac_cv_sizeof_unsigned_long_long != 8 ; then
98         AC_MSG_ERROR([** we assume that sizeof(long long) == 8.  Tell phil@clusterfs.com])
99 fi
100
101 # -------- we can't build modules unless srcdir = builddir
102 if test x$enable_modules != xno ; then
103         AC_CHECK_FILE([autoMakefile.am],[],
104                 [AC_MSG_ERROR([At this time, Lustre does not support building kernel modules with srcdir != buildir.])])
105 fi
106
107 # -------- in kernel compilation? (2.5 only) -------------
108 AC_MSG_CHECKING([if inkernel build support is requested])
109 AC_ARG_ENABLE([inkernel],
110         AC_HELP_STRING([--enable-inkernel],
111                        [set up 2.5 kernel makefiles]),
112         [],[enable_inkernel=no])
113 AC_MSG_RESULT([$enable_inkernel])
114 AM_CONDITIONAL(INKERNEL, test x$enable_inkernel = xyes)
115
116 if test x$enable_inkernel = xyes ; then
117         find portals lustre -name Makefile.mk | sed 's/.mk$//' | xargs -n 1 \
118                 sh -e -x -c '(cp -f $0.mk $0.in)'
119 fi
120
121 if test x$enable_modules != xno ; then
122         # -------- set linuxdir ------------
123         AC_MSG_CHECKING([for Linux sources])
124         AC_ARG_WITH([linux],
125                 AC_HELP_STRING([--with-linux=path],
126                                [set path to Linux source (default=/usr/src/linux)]),
127                 [LINUX=$with_linux],
128                 [LINUX=/usr/src/linux])
129         AC_MSG_RESULT([$LINUX])
130         AC_SUBST(LINUX)
131         if test x$enable_inkernel = xyes ; then
132                 echo ln -s `pwd` $LINUX/fs/lustre
133                 rm $LINUX/fs/lustre
134                 ln -s `pwd` $LINUX/fs/lustre
135         fi
136
137         # -------- linux objects (for 2.6) --
138         AC_MSG_CHECKING([for Linux objects dir])
139         AC_ARG_WITH([linux-obj],
140                 AC_HELP_STRING([--with-linux-obj=path],
141                                 [set path to Linux objects dir (default=\$LINUX)]),
142                 [LINUX_OBJ=$with_linux_obj],
143                 [LINUX_OBJ=$LINUX])
144         AC_MSG_RESULT([$LINUX_OBJ])
145         AC_SUBST(LINUX_OBJ)
146
147         # -------- check for .confg --------
148         AC_ARG_WITH([linux-config],
149                 [AC_HELP_STRING([--with-linux-config=path],
150                                 [set path to Linux .conf (default=\$LINUX_OBJ/.config)])],
151                 [LINUX_CONFIG=$with_linux_config],
152                 [LINUX_CONFIG=$LINUX_OBJ/.config])
153         AC_SUBST(LINUX_CONFIG)
154
155         AC_CHECK_FILE([/boot/kernel.h],
156                 [KERNEL_SOURCE_HEADER='/boot/kernel.h'],
157                 [AC_CHECK_FILE([/var/adm/running-kernel.h]),
158                         [KERNEL_SOURCE_HEADER='/var/adm/running-kernel.h']])
159
160         AC_ARG_WITH([kernel-source-header],
161                 AC_HELP_STRING([--with-kernel-source-header=path],
162                                 [Use a different kernel version header.  Consult README.kernel-source for details.]),
163                 [KERNEL_SOURCE_HEADER=$with_kernel_source_header])
164
165         #  --------------------
166         ARCH_UM=
167         UML_CFLAGS=
168
169         AC_MSG_CHECKING([if you are running user mode linux for $host_cpu])
170         if test -e $LINUX/include/asm-um ; then
171                 if test  X`ls -id $LINUX/include/asm/ | awk '{print $1}'` = X`ls -id $LINUX/include/asm-um | awk '{print $1}'` ; then
172                         ARCH_UM='ARCH=um'
173                         # see notes in Rules.in
174                         UML_CFLAGS='-O0'
175                         AC_MSG_RESULT(yes)
176                 else
177                         AC_MSG_RESULT([no (asm doesn't point at asm-um)])
178                 fi
179         else
180                 AC_MSG_RESULT([no (asm-um missing)])
181         fi
182
183         AC_SUBST(ARCH_UM)
184         AC_SUBST(UML_CFLAGS)
185
186         # --------- Linux 25 ------------------
187         AC_CHECK_FILE([$LINUX/include/linux/namei.h],
188                 [
189                         linux25="yes"
190                         KMODEXT=".ko"
191                 ],[
192                         KMODEXT=".o"
193                         linux25="no"
194                 ])
195         AC_MSG_CHECKING([if you are using Linux 2.6])
196         AC_MSG_RESULT([$linux25])
197
198         AC_SUBST(LINUX25)
199         AC_SUBST(KMODEXT)
200 fi
201 AM_CONDITIONAL(LINUX25, test x$linux25 = xyes)
202
203
204 # -------  Makeflags ------------------
205
206 CPPFLAGS="$CPPFLAGS $CRAY_PORTALS_INCLUDES -I\$(top_srcdir)/lustre/include -I\$(top_srcdir)/portals/include"
207
208 # liblustre are all the same
209 LLCPPFLAGS="-D__arch_lib__ -D_LARGEFILE64_SOURCE=1"
210 AC_SUBST(LLCPPFLAGS)
211
212 LLCFLAGS="-g -Wall -fPIC"
213 AC_SUBST(LLCFLAGS)
214
215 # everyone builds against portals and lustre
216
217 EXTRA_KCFLAGS="-g $CRAY_PORTALS_INCLUDES -I$PWD/portals/include -I$PWD/lustre/include"
218
219 # these are like AC_TRY_COMPILE, but try to build modules against the
220 # kernel, inside the kernel-tests directory
221
222 AC_DEFUN([LUSTRE_MODULE_CONFTEST],
223 [cat >conftest.c <<_ACEOF
224 $1
225 _ACEOF
226 ])
227
228 AC_DEFUN([LUSTRE_MODULE_COMPILE_IFELSE],
229 [m4_ifvaln([$1], [LUSTRE_MODULE_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 AC_DEFUN([LUSTRE_MODULE_TRY_COMPILE],
239 [LUSTRE_MODULE_COMPILE_IFELSE(
240         [AC_LANG_PROGRAM([[$1]], [[$2]])],
241         [modules],
242         [test -s build/conftest.o],
243         [$3], [$4])])
244
245 AC_DEFUN([LUSTRE_MODULE_TRY_MAKE],
246 [LUSTRE_MODULE_COMPILE_IFELSE([AC_LANG_PROGRAM([[$1]], [[$2]])], [$3], [$4], [$5], [$6])])
247
248 # ------------ include paths ------------------
249
250 if test x$enable_modules != xno ; then
251         # ------------ .config exists ----------------
252         AC_CHECK_FILE([$LINUX_CONFIG],[],
253                 [AC_MSG_ERROR([Kernel config could not be found.  If you are building from a kernel-source rpm consult README.kernel-source])])
254
255         # ----------- make dep run? ------------------
256         AC_CHECK_FILES([$LINUX_OBJ/include/linux/autoconf.h
257                         $LINUX_OBJ/include/linux/version.h
258                         $LINUX/include/linux/config.h],[],
259                 [AC_MSG_ERROR([Run make config in $LINUX.])])
260
261         # ------------ rhconfig.h includes runtime-generated bits --
262         # red hat kernel-source checks
263
264         # we know this exists after the check above.  if the user
265         # tarred up the tree and ran make dep etc. in it, then
266         # version.h gets overwritten with a standard linux one.
267
268         if grep rhconfig $LINUX_OBJ/include/linux/version.h >/dev/null ; then
269                 # This is a clean kernel-source tree, we need to
270                 # enable extensive workarounds to get this to build
271                 # modules
272                 AC_CHECK_FILE([$KERNEL_SOURCE_HEADER],
273                         [if test $KERNEL_SOURCE_HEADER = '/boot/kernel.h' ; then
274                                 AC_MSG_WARN([Using /boot/kernel.h from RUNNING kernel.])
275                                 AC_MSG_WARN([If this is not what you want, use --with-kernel-source-header.])
276                                 AC_MSG_WARN([Consult README.kernel-source for details.])
277                         fi],
278                         [AC_MSG_ERROR([$KERNEL_SOURCE_HEADER not found.  Consult README.kernel-source for details.])])
279                 EXTRA_KCFLAGS="-include $KERNEL_SOURCE_HEADER $EXTRA_KCFLAGS"
280         fi
281
282         # ------------ external module support ---------------------
283         MODULE_TARGET="SUBDIRS"
284         if test $linux25 = 'yes' ; then
285                 makerule="$PWD/build"
286                 AC_MSG_CHECKING([for external module build support])
287                 rm -f build/conftest.i
288                 LUSTRE_MODULE_TRY_MAKE([],[],
289                         [$makerule LUSTRE_KERNEL_TEST=conftest.i],
290                         [test -s build/conftest.i],
291                         [
292                                 AC_MSG_RESULT([no])
293                         ],[
294                                 AC_MSG_RESULT([yes])
295                                 makerule="_module_$makerule"
296                                 MODULE_TARGET="M"
297                         ])
298         else
299                 makerule="_dir_$PWD/build"
300         fi
301         AC_SUBST(MODULE_TARGET)
302
303         # --- check that we can build modules at all
304         AC_MSG_CHECKING([that modules can be built])
305         LUSTRE_MODULE_TRY_COMPILE([],[],
306                 [
307                         AC_MSG_RESULT([yes])
308                 ],[
309                         AC_MSG_RESULT([no])
310                         AC_MSG_WARN([Consult config.log for details.])
311                         AC_MSG_WARN([If you are trying to build with a kernel-source rpm, consult README.kernel-source])
312                         AC_MSG_ERROR([Kernel modules could not be built.])
313                 ])
314
315         # ------------ LINUXRELEASE and moduledir ------------------
316         LINUXRELEASE=
317         rm -f build/conftest.i
318         AC_MSG_CHECKING([for Linux release])
319         LUSTRE_MODULE_TRY_MAKE(
320                 [#include <linux/version.h>],
321                 [char *LINUXRELEASE;
322                  LINUXRELEASE=UTS_RELEASE;],
323                 [$makerule LUSTRE_KERNEL_TEST=conftest.i],
324                 [test -s build/conftest.i],
325                 [
326                         # LINUXRELEASE="UTS_RELEASE"
327                         eval $(grep "LINUXRELEASE=" build/conftest.i)
328                 ],[
329                         AC_MSG_RESULT([unknown])
330                         AC_MSG_ERROR([Could not preprocess test program.  Consult config.log for details.])
331                 ])
332         rm -f build/conftest.i
333         if test x$LINUXRELEASE = x ; then
334                 AC_MSG_RESULT([unknown])
335                 AC_MSG_ERROR([Could not determine Linux release version from linux/version.h.])
336         fi
337         AC_MSG_RESULT([$LINUXRELEASE])
338         AC_SUBST(LINUXRELEASE)
339
340         moduledir='/lib/modules/'$LINUXRELEASE/kernel
341         modulefsdir='$(moduledir)/fs/$(PACKAGE)'
342         modulenetdir='$(moduledir)/net/$(PACKAGE)'
343
344         AC_SUBST(moduledir)
345         AC_SUBST(modulefsdir)
346         AC_SUBST(modulenetdir)
347
348         # ------------ RELEASE --------------------------------
349         AC_MSG_CHECKING([for Lustre release])
350         RELEASE="`echo ${LINUXRELEASE} | tr '-' '_'`_`date +%Y%m%d%H%M`"
351         AC_MSG_RESULT($RELEASE)
352         AC_SUBST(RELEASE)
353
354         # ---------- modules? ------------------------
355         AC_MSG_CHECKING([for module support])
356         LUSTRE_MODULE_TRY_COMPILE(
357                 [
358                         #include <linux/config.h>
359                 ],[
360                         #ifndef CONFIG_MODULES
361                         #error CONFIG_MODULES not #defined
362                         #endif
363                 ],[
364                         AC_MSG_RESULT([yes])
365                 ],[
366                         AC_MSG_RESULT([no])
367                         AC_MSG_ERROR([module support is required to build Lustre kernel modules.])
368                 ])
369
370         # ---------- modversions? --------------------
371         AC_MSG_CHECKING([for MODVERSIONS])
372         LUSTRE_MODULE_TRY_COMPILE(
373                 [
374                         #include <linux/config.h>
375                 ],[
376                         #ifndef CONFIG_MODVERSIONS
377                         #error CONFIG_MODVERSIONS not #defined
378                         #endif
379                 ],[
380                         AC_MSG_RESULT([yes])
381                 ],[
382                         AC_MSG_RESULT([no])
383                 ])
384
385         # ------------ preempt -----------------------
386         AC_MSG_CHECKING([if preempt is enabled])
387         LUSTRE_MODULE_TRY_COMPILE(
388                 [
389                         #include <linux/config.h>
390                 ],[
391                         #ifndef CONFIG_PREEMPT
392                         #error CONFIG_PREEMPT is not #defined
393                         #endif
394                 ],[
395                         AC_MSG_RESULT([yes])
396                         AC_MSG_ERROR([Lustre does not support kernels with preempt enabled.])
397                 ],[
398                         AC_MSG_RESULT([no])
399                 ])
400
401         # ------------ kallsyms (so software watchdogs produce useful stacks)
402         AC_MSG_CHECKING([if kallsyms is enabled])
403         LUSTRE_MODULE_TRY_COMPILE(
404                 [
405                         #include <linux/config.h>
406                 ],[
407                         #ifndef CONFIG_KALLSYMS
408                         #error CONFIG_KALLSYMS is not #defined
409                         #endif
410                 ],[
411                         AC_MSG_RESULT([yes])
412                 ],[
413                         AC_MSG_RESULT([no])
414                         if test "x$ARCH_UM" = "x" ; then
415                                 AC_MSG_ERROR([Lustre requires that CONFIG_KALLSYMS is enabled in your kernel.])
416                         fi
417                 ])
418 fi
419
420 ENABLE_INIT_SCRIPTS=0
421 if test x$enable_utils = xyes ; then
422         AC_MSG_CHECKING([whether to install init scripts])
423         # our scripts only work on red hat systems
424         if test -f /etc/init.d/functions -a -f /etc/sysconfig/network ; then
425                 ENABLE_INIT_SCRIPTS=1
426                 AC_MSG_RESULT([yes])
427         else
428                 AC_MSG_RESULT([no])
429         fi
430 fi
431 AM_CONDITIONAL(INIT_SCRIPTS, test x$ENABLE_INIT_SCRIPTS = "x1")
432 AC_SUBST(ENABLE_INIT_SCRIPTS)
433
434 AC_CONFIG_FILES([
435 build/autoMakefile
436 build/Rules
437 build/lustre.spec
438 ])