Whamcloud - gitweb
move AC_SUBST into lustre-build.m4 (b=7126)
[fs/lustre-release.git] / build / autoconf / lustre-build.m4
1 #
2 # LB_CHECK_VERSION
3 #
4 # Verify that LUSTRE_VERSION was defined properly
5 #
6 AC_DEFUN([LB_CHECK_VERSION],
7 [if test "LUSTRE_VERSION" = "LUSTRE""_VERSION" ; then
8         AC_MSG_ERROR([This script was not built with a version number.])
9 fi
10 ])
11
12 #
13 # LB_CANONICAL_SYSTEM
14 #
15 # fixup $target_os for use in other places
16 #
17 AC_DEFUN([LB_CANONICAL_SYSTEM],
18 [case $target_os in
19         linux*)
20                 lb_target_os="linux"
21                 ;;
22         darwin*)
23                 lb_target_os="darwin"
24                 ;;
25 esac
26 AC_SUBST(lb_target_os)
27 ])
28
29 #
30 # LB_CHECK_FILE
31 #
32 # Check for file existance even when cross compiling
33 #
34 AC_DEFUN([LB_CHECK_FILE],
35 [AS_VAR_PUSHDEF([lb_File], [lb_cv_file_$1])dnl
36 AC_CACHE_CHECK([for $1], lb_File,
37 [if test -r "$1"; then
38   AS_VAR_SET(lb_File, yes)
39 else
40   AS_VAR_SET(lb_File, no)
41 fi])
42 AS_IF([test AS_VAR_GET(lb_File) = yes], [$2], [$3])[]dnl
43 AS_VAR_POPDEF([lb_File])dnl
44 ])# LB_CHECK_FILE
45
46 #
47 # LB_CHECK_FILES
48 #
49 # LB_CHECK_FILE over multiple files
50 #
51 AC_DEFUN([LB_CHECK_FILES],
52 [AC_FOREACH([AC_FILE_NAME], [$1],
53   [LB_CHECK_FILE(AC_FILE_NAME,
54                  [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]AC_FILE_NAME), 1,
55                                     [Define to 1 if you have the
56                                      file `]AC_File['.])
57 $2],
58                  [$3])])])
59
60 #
61 # LB_ARG_LIBS_INCLUDES
62 #
63 # support for --with-foo, --with-foo-includes, and --with-foo-libs in
64 # a single magical macro
65 #
66 AC_DEFUN([LB_ARG_LIBS_INCLUDES],
67 [lb_pathvar="m4_bpatsubst([$2], -, _)"
68 AC_MSG_CHECKING([for $1])
69 AC_ARG_WITH([$2],
70         AC_HELP_STRING([--with-$2=path],
71                 [path to $1]),
72         [],[withval=$4])
73
74 if test x$withval = xyes ; then
75         eval "$lb_pathvar='$3'"
76 else
77         eval "$lb_pathvar='$withval'"
78 fi
79 AC_MSG_RESULT([${!lb_pathvar:-no}])
80
81 if test x${!lb_pathvar} != x -a x${!lb_pathvar} != xno ; then
82         AC_MSG_CHECKING([for $1 includes])
83         AC_ARG_WITH([$2-includes],
84                 AC_HELP_STRING([--with-$2-includes=path],
85                         [path to $1 includes]),
86                 [],[withval='yes'])
87
88         lb_includevar="${lb_pathvar}_includes"
89         if test x$withval = xyes ; then
90                 eval "${lb_includevar}='${!lb_pathvar}/include'"
91         else
92                 eval "${lb_includevar}='$withval'"
93         fi
94         AC_MSG_RESULT([${!lb_includevar}])
95
96         AC_MSG_CHECKING([for $1 libs])
97         AC_ARG_WITH([$2-libs],
98                 AC_HELP_STRING([--with-$2-libs=path],
99                         [path to $1 libs]),
100                 [],[withval='yes'])
101
102         lb_libvar="${lb_pathvar}_libs"
103         if test x$withval = xyes ; then
104                 eval "${lb_libvar}='${!lb_pathvar}/lib'"
105         else
106                 eval "${lb_libvar}='$withval'"
107         fi
108         AC_MSG_RESULT([${!lb_libvar}])
109 fi
110 ])
111 ])
112
113 #
114 # LB_PATH_LIBSYSIO
115 #
116 # Handle internal/external libsysio
117 #
118 AC_DEFUN([LB_PATH_LIBSYSIO],
119 [AC_ARG_WITH([sysio],
120         AC_HELP_STRING([--with-sysio=path],
121                         [set path to libsysio source (default is included libsysio)]),
122         [],[
123                 case $lb_target_os in
124                         linux)
125                                 with_sysio='yes'
126                                 ;;
127                         *)
128                                 with_sysio='no'
129                                 ;;
130                 esac
131         ])
132 AC_MSG_CHECKING([location of libsysio])
133 enable_sysio="$with_sysio"
134 case x$with_sysio in
135         xyes)
136                 AC_MSG_RESULT([internal])
137                 LB_CHECK_FILE([$srcdir/libsysio/src/rmdir.c],[],[
138                         AC_MSG_ERROR([A complete internal libsysio was not found.])
139                 ])
140                 LIBSYSIO_SUBDIR="libsysio"
141                 SYSIO="$PWD/libsysio"
142                 ;;
143         xno)
144                 AC_MSG_RESULT([disabled])
145                 ;;
146         *)
147                 AC_MSG_RESULT([$with_sysio])
148                 LB_CHECK_FILE([$with_sysio/lib/libsysio.a],[],[
149                         AC_MSG_ERROR([A complete (built) external libsysio was not found.])
150                 ])
151                 SYSIO=$with_sysio
152                 with_sysio="yes"
153                 ;;
154 esac
155
156 # We have to configure even if we don't build here for make dist to
157 # work
158 AC_CONFIG_SUBDIRS(libsysio)
159 ])
160
161 #
162 # LB_PATH_CRAY_PORTALS
163 #
164 # Support for external Cray portals
165 #
166 AC_DEFUN([LB_PATH_CRAY_PORTALS],
167 [LB_ARG_LIBS_INCLUDES([Cray Portals],[cray-portals])
168
169 if test x$cray_portals_includes != x ; then
170         if test ! -r $cray_portals_includes/portals/api.h ; then
171                 AC_MSG_ERROR([Cray portals headers were not found in $cray_portals_includes.  Please check the paths passed to --with-cray-portals or --with-cray-portals-includes.])
172         fi
173 fi
174 if test x$cray_portals_libs != x ; then
175         if test ! -r $cray_portals_libs/libportals.a ; then
176                 AC_MSG_ERROR([Cray portals libraries were not found in $cray_portals_libs.  Please check the paths passed to --with-cray-portals or --with-cray-portals-libs.])
177         fi
178 fi
179
180 if test x$cray_portals_includes != x -a x$cray_portals_libs != x ; then
181         cray_portals=yes
182         AC_DEFINE(CRAY_PORTALS, 1, [Building with Cray Portals])
183         CPPFLAGS="-I$cray_portals_includes $CPPFLAGS"
184         EXTRA_KCFLAGS="-I$cray_portals_includes $EXTRA_KCFLAGS"
185         # for liblustre + b_cray
186         CRAY_PORTALS_LIBS="$cray_portals_libs"
187         AC_SUBST(CRAY_PORTALS_LIBS)
188 else
189         cray_portals=no
190 fi
191 ])
192
193 #
194 # LB_PATH_SNMP
195 #
196 # check for in-tree snmp support
197 #
198 AC_DEFUN([LB_PATH_SNMP],
199 [LB_CHECK_FILE([$srcdir/snmp/lustre-snmp.c],[SNMP_DIST_SUBDIR="snmp"])
200 AC_SUBST(SNMP_DIST_SUBDIR)
201 AC_SUBST(SNMP_SUBDIR)
202 ])
203
204 #
205 # LB_CONFIG_MODULES
206 #
207 # Build kernel modules?
208 #
209 AC_DEFUN([LB_CONFIG_MODULES],
210 [AC_MSG_CHECKING([whether to build kernel modules])
211 AC_ARG_ENABLE([modules],
212         AC_HELP_STRING([--disable-modules],
213                         [disable building of Lustre kernel modules]),
214         [],[
215                 LC_TARGET_SUPPORTED([
216                         enable_modules='yes'
217                 ],[
218                         enable_modules='no'
219                 ])
220         ])
221 AC_MSG_RESULT([$enable_modules ($target_os)])
222
223 if test x$enable_modules = xyes ; then
224         case $target_os in
225                 linux*)
226                         LB_PROG_LINUX
227                         ;;
228                 darwin*)
229                         LB_PROG_DARWIN
230                         ;;
231                 *)
232                         # This is strange - Lustre supports a target we don't
233                         AC_MSG_ERROR([Modules are not supported on $target_os])
234                         ;;
235         esac
236 fi
237 ])
238
239 #
240 # LB_CONFIG_UTILS
241 #
242 # Build utils?
243 #
244 AC_DEFUN([LB_CONFIG_UTILS],
245 [AC_MSG_CHECKING([whether to build utilities])
246 AC_ARG_ENABLE([utils],
247         AC_HELP_STRING([--disable-utils],
248                         [disable building of Lustre utility programs]),
249         [],[enable_utils='yes'])
250 AC_MSG_RESULT([$enable_utils])
251 if test x$enable_utils = xyes ; then 
252         LB_CONFIG_INIT_SCRIPTS
253 fi
254 ])
255
256 #
257 # LB_CONFIG_TESTS
258 #
259 # Build tests?
260 #
261 AC_DEFUN([LB_CONFIG_TESTS],
262 [AC_MSG_CHECKING([whether to build Lustre tests])
263 AC_ARG_ENABLE([tests],
264         AC_HELP_STRING([--disable-tests],
265                         [disable building of Lustre tests]),
266         [],[enable_tests='yes'])
267 if test x$cray_portals = xyes ; then
268         enable_tests='no'
269 fi
270 AC_MSG_RESULT([$enable_tests])
271 ])
272
273 #
274 # LB_CONFIG_DOCS
275 #
276 # Build docs?
277 #
278 AC_DEFUN([LB_CONFIG_DOCS],
279 [AC_MSG_CHECKING([whether to build docs])
280 AC_ARG_ENABLE(doc,
281         AC_HELP_STRING([--disable-doc],
282                         [skip creation of pdf documentation]),
283         [
284                 if test x$enable_doc = xyes ; then
285                     ENABLE_DOC=1           
286                 else
287                     ENABLE_DOC=0
288                 fi
289         ],[
290                 ENABLE_DOC=0
291                 enable_doc='no'
292         ])
293 AC_MSG_RESULT([$enable_doc])
294 AC_SUBST(ENABLE_DOC)
295 ])
296
297 #
298 # LB_CONFIG_INIT_SCRIPTS
299 #
300 # our init scripts only work on red hat linux
301 #
302 AC_DEFUN([LB_CONFIG_INIT_SCRIPTS],
303 [ENABLE_INIT_SCRIPTS=0
304 if test x$enable_utils = xyes ; then
305         AC_MSG_CHECKING([whether to install init scripts])
306         # our scripts only work on red hat systems
307         if test -f /etc/init.d/functions -a -f /etc/sysconfig/network ; then
308                 ENABLE_INIT_SCRIPTS=1
309                 AC_MSG_RESULT([yes])
310         else
311                 AC_MSG_RESULT([no])
312         fi
313 fi
314 AC_SUBST(ENABLE_INIT_SCRIPTS)
315 ])
316
317 #
318 # LB_CONFIG_HEADERS
319 #
320 # add -include config.h
321 #
322 AC_DEFUN([LB_CONFIG_HEADERS],
323 [AC_CONFIG_HEADERS([config.h])
324 CPPFLAGS="-include \$(top_builddir)/config.h $CPPFLAGS"
325 EXTRA_KCFLAGS="-include $PWD/config.h $EXTRA_KCFLAGS"
326 AC_SUBST(EXTRA_KCFLAGS)
327 ])
328
329 #
330 # LB_INCLUDE_RULES
331 #
332 # defines for including the toplevel Rules
333 #
334 AC_DEFUN([LB_INCLUDE_RULES],
335 [INCLUDE_RULES="include $PWD/build/Rules"
336 AC_SUBST(INCLUDE_RULES)
337 ])
338
339 #
340 # LB_PATH_DEFAULTS
341 #
342 # 'fixup' default paths
343 #
344 AC_DEFUN([LB_PATH_DEFAULTS],
345 [# directories for binaries
346 AC_PREFIX_DEFAULT([/usr])
347
348 sysconfdir='/etc'
349 AC_SUBST(sysconfdir)
350
351 # Directories for documentation and demos.
352 docdir='${datadir}/doc/$(PACKAGE)'
353 AC_SUBST(docdir)
354
355 LP_PATH_DEFAULTS
356 LC_PATH_DEFAULTS
357 ])
358
359 #
360 # LB_PROG_CC
361 #
362 # checks on the C compiler
363 #
364 AC_DEFUN([LB_PROG_CC],
365 [AC_PROG_RANLIB
366 AC_MSG_CHECKING([for buggy compiler])
367 CC_VERSION=`$CC -v 2>&1 | grep "^gcc version"`
368 bad_cc() {
369         AC_MSG_RESULT([buggy compiler found!])
370         echo
371         echo "   '$CC_VERSION'"
372         echo "  has been known to generate bad code, "
373         echo "  please get an updated compiler."
374         AC_MSG_ERROR([sorry])
375 }
376 case "$CC_VERSION" in
377         "gcc version 2.95"*)
378                 bad_cc
379                 ;;
380         # ost_pack_niobuf putting 64bit NTOH temporaries on the stack
381         # without "sub    $0xc,%esp" to protect the stack from being
382         # stomped on by interrupts (bug 606)
383         "gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)")
384                 bad_cc
385                 ;;
386         # mandrake's similar sub 0xc compiler bug
387         # http://marc.theaimsgroup.com/?l=linux-kernel&m=104748366226348&w=2
388         "gcc version 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)")
389                 bad_cc
390                 ;;
391         *)
392                 AC_MSG_RESULT([no known problems])
393                 ;;
394 esac
395
396 # ---------  unsigned long long sane? -------
397 AC_CHECK_SIZEOF(unsigned long long, 0)
398 echo "---> size SIZEOF $SIZEOF_unsigned_long_long"
399 echo "---> size SIZEOF $ac_cv_sizeof_unsigned_long_long"
400 if test $ac_cv_sizeof_unsigned_long_long != 8 ; then
401         AC_MSG_ERROR([** we assume that sizeof(long long) == 8.  Tell phil@clusterfs.com])
402 fi
403
404 AC_MSG_CHECKING([if $CC accepts -m64])
405 CC_save="$CC"
406 CC="$CC -m64"
407 AC_TRY_COMPILE([],[],[
408         AC_MSG_RESULT([yes])
409 ],[
410         AC_MSG_RESULT([no])
411         CC="$CC_save"
412 ])
413
414 CPPFLAGS="-I\$(top_builddir)/portals/include -I\$(top_srcdir)/portals/include -I\$(top_builddir)/lustre/include -I\$(top_srcdir)/lustre/include $CPPFLAGS"
415
416 LLCPPFLAGS="-D__arch_lib__ -D_LARGEFILE64_SOURCE=1"
417 AC_SUBST(LLCPPFLAGS)
418
419 LLCFLAGS="-g -Wall -fPIC"
420 AC_SUBST(LLCFLAGS)
421
422 # everyone builds against portals and lustre
423 EXTRA_KCFLAGS="$EXTRA_KCFLAGS -g -I$PWD/portals/include -I$PWD/lustre/include"
424 AC_SUBST(EXTRA_KCFLAGS)
425 ])
426
427 #
428 # LB_CONTITIONALS
429 #
430 # AM_CONDITIONAL instances for everything
431 # (so that portals/lustre can disable some if needed)
432 AC_DEFUN([LB_CONDITIONALS],
433 [AM_CONDITIONAL(MODULES, test x$enable_modules = xyes)
434 AM_CONDITIONAL(UTILS, test x$enable_utils = xyes)
435 AM_CONDITIONAL(TESTS, test x$enable_tests = xyes)
436 AM_CONDITIONAL(DOC, test x$ENABLE_DOC = x1)
437 AM_CONDITIONAL(CRAY_PORTALS, test x$cray_portals != xno)
438 AM_CONDITIONAL(INIT_SCRIPTS, test x$ENABLE_INIT_SCRIPTS = "x1")
439 AM_CONDITIONAL(LINUX, test x$lb_target_os = "xlinux")
440 AM_CONDITIONAL(DARWIN, test x$lb_target_os = "xdarwin")
441
442 # this lets lustre cancel libsysio, per-branch or if liblustre is
443 # disabled
444 if test "x$LIBSYSIO_SUBDIR" = xlibsysio ; then
445         if test "x$with_sysio" != xyes ; then
446                 SYSIO=""
447                 LIBSYSIO_SUBDIR=""
448         fi
449 fi
450 AC_SUBST(LIBSYSIO_SUBDIR)
451 AC_SUBST(SYSIO)
452
453 LB_LINUX_CONDITIONALS
454 LB_DARWIN_CONDITIONALS
455
456 LP_CONDITIONALS
457 LC_CONDITIONALS
458 ])
459
460 #
461 # LB_CONFIGURE
462 #
463 # main configure steps
464 #
465 AC_DEFUN([LB_CONFIGURE],
466 [LB_CANONICAL_SYSTEM
467
468 LB_INCLUDE_RULES
469
470 LB_PATH_DEFAULTS
471
472 LB_PROG_CC
473
474 LB_PATH_LIBSYSIO
475 LB_PATH_CRAY_PORTALS
476 LB_PATH_SNMP
477
478 LB_CONFIG_DOCS
479 LB_CONFIG_UTILS
480 LB_CONFIG_TESTS
481 LC_CONFIG_CLIENT_SERVER
482
483 LB_CONFIG_MODULES
484
485 LC_CONFIG_LIBLUSTRE
486
487 LP_CONFIGURE
488 LC_CONFIGURE
489 if test "$SNMP_DIST_SUBDIR" ; then
490         LS_CONFIGURE
491 fi
492
493 LB_CONDITIONALS
494 LB_CONFIG_HEADERS
495
496 AC_CONFIG_FILES(
497 [Makefile:build/Makefile.in.toplevel]
498 [autoMakefile
499 build/autoMakefile
500 build/autoconf/Makefile
501 build/Rules
502 build/lustre.spec
503 ])
504
505 LP_CONFIG_FILES
506 LC_CONFIG_FILES
507 if test "$SNMP_DIST_SUBDIR" ; then
508         LS_CONFIG_FILES
509 fi
510
511 AC_SUBST(ac_configure_args)
512
513 MOSTLYCLEANFILES='.*.cmd .*.flags *.o *.ko *.mod.c .depend .*.1.*'
514 AC_SUBST(MOSTLYCLEANFILES)
515
516 AC_OUTPUT
517
518 cat <<_ACEOF
519
520 CC:            $CC
521 LD:            $LD
522 CPPFLAGS:      $CPPFLAGS
523 LLCPPFLAGS:    $LLCPPFLAGS
524 CFLAGS:        $CFLAGS
525 EXTRA_KCFLAGS: $EXTRA_KCFLAGS
526 LLCFLAGS:      $LLCFLAGS
527
528 Type 'make' to build Lustre.
529 _ACEOF
530 ])