Whamcloud - gitweb
b=23721 disable rdac and mptlinux by default
[fs/lustre-release.git] / build / lbuild
1 #!/bin/bash
2
3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4
5 # this is an alternative FD for stdout, to be used especially when we are
6 # taking stdout from a function as it's return value.  i.e. foo=$(bar)
7 # this is a workaround until a version of bash where we can put xtrace
8 # on a specific FD
9 exec 3>&1; STDOUT=3
10
11 #set -x
12 xtrace="+x"
13 if [[ $SHELLOPTS = *xtrace* ]]; then
14     xtrace="-x"
15 fi
16 shopt -s extdebug
17
18 # include the exit_traps library
19 . ${0%/lbuild}/exit_traps.sh
20
21 # our children should die when we do
22 push_exit_trap "kill -INT -$$ || true" kill_children
23
24 TOPDIR=$PWD
25
26 # CVSROOT is inherited from the environment
27 KERNELDIR=
28 LINUX=
29 LUSTRE=
30 RELEASE=false
31 # XXX - some recent hacking has pretty much neutered this option.
32 #       search through this file (and lbuild.old_school -- but that will
33 #       be going away soon) for "-bb" and see how many places
34 #       simply don't account for this option
35 DO_SRC=true
36 DOWNLOAD=true
37 TAG=
38 CANONICAL_TARGET=
39 TARGET=
40 TARGET_ARCH=$(uname -m)
41 TARGET_ARCHS=
42 TARGET_ARCHS_ALL=$TARGET_ARCH
43 [ "$TARGET_ARCH" = "i686" ] && TARGET_ARCHS_ALL="i686 i586 i386"
44 CONFIGURE_FLAGS=
45 EXTERNAL_PATCHES=
46 EXTRA_VERSION=
47 LUSTRE_EXTRA_VERSION=
48 STAGEDIR=
49 TMPDIR=${TMPDIR:-"/var/tmp"}
50 TIMESTAMP=
51 # this is a dir to try reuse old kernel RPMs in (although, it seems to be
52 # unused in any real manner
53 REUSERPM=
54 # this is the dir that should be used to store reuse products
55 REUSEBUILD=
56 # should cached products be used or force rebuilding?
57 USE_BUILD_CACHE=true
58 # what does this do exactly?  does it imply no kernel build?
59 NORPM=false
60 LDISKFSRPM=true
61 SKIPLDISKFSRPM="v1_4_* b1_4"
62 SMPTYPES="smp bigsmp default ''"
63 PATCHLESS=false
64 XEN=false
65 LINUXOBJ=
66 DISTRO=
67 KERNELTREE=
68 # default to not adding -lustre- into the kernel RPM package names
69 KERNEL_LUSTRE_NAMING=false
70
71 # patchless build
72 KERNELRPMSBASE=
73 RPMSMPTYPE=
74
75 # from target file
76 SERIES=
77 BASE_ARCHS=
78 BIGMEM_ARCHS=
79 BOOT_ARCHS=
80 JENSEN_ARCHS=
81 SMP_ARCHS=
82 BIGSMP_ARCHS=
83 PSERIES64_ARCHS=
84 UP_ARCHS=
85
86 # not in the target file any more
87 CONFIG=
88
89 # build the lustre-tests rpm?
90 LUSTRE_TESTS=true
91
92 # these are disabled by default, enabled with command line switches or by
93 # the calling environment
94 BUILD_MPTLINUX=${BUILD_MPTLINUX:-false}
95 BUILD_RDAC=${BUILD_RDAC:-false}
96
97 DATE=$(date)
98
99 USE_DATESTAMP=1
100 RPMBUILD=
101
102 OLD_SCHOOL=false
103
104 export CC=${CC:-gcc}
105
106 # Readlink is not present on some older distributions: emulate it.
107 readlink() {
108     local path=$1 ll
109
110     if [ -L "$path" ]; then
111         ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
112         echo "${ll/* -> }"
113     else
114         return 1
115     fi
116 }
117
118 cleanup() {
119
120     true
121 }
122
123 error() {
124     local msg="$1"
125
126     [ -n "$msg" ] && echo -e "\n${0##*/}: $msg" >&3
127
128 }
129
130 fatal() {
131
132     cleanup
133     error "$2"
134     exit $1
135
136 }
137
138 usage() {
139     cat <<EOF
140 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
141
142   -d CVSROOT
143     Specifies the CVS Root to use when pulling files from CVS.  The
144     environment variable \$CVSROOT is used if this option is not
145     present.
146
147   --external-patches=EXTERNAL_PATCHES
148     Directory similar to lustre/lustre/kernel_patches/ that lbuild should
149     look for seres and config files in before looking in the lustre
150     tree.
151
152   --extraversion=EXTRAVERSION
153     Text to use for the rpm release and kernel extraversion.
154
155   --timestamp=TIMESTAMP
156     Date of building lustre in format YYYYMMDDhhmmss
157
158   --reuserpm=DIR
159     Try to reuse old kernel RPMs from DIR
160
161   --reusebuild=DIR
162     Try to reuse old kernel builds from DIR
163
164   --kernelrpm=DIR
165     Path to distro kernel RPM collection
166
167   --ccache
168     Use ccache
169
170   --norpm
171     Do not build RPMs (compile only mode)
172
173   --patchless
174     Build lustre client only
175
176   --distro=DISTRO
177     Which distro using. Autodetect by default
178
179   --kerneldir=KERNELDIR
180     Directory containing Linux source tarballs referenced by target
181     files.
182
183   --kerneltree=KERNELTREE
184     Directory containing dirs with Linux source tarballs referenced by target
185     files. Dir names in format kernel version ('2.6.9', etc.)
186
187   --linux=LINUX --with-linux=LINUX
188     Directory of Linux kernel sources.  When this option is used, only
189     Lustre modules and userspace are built.
190
191   --lustre=LUSTRE
192     Path to an existing lustre source tarball to use instead of
193     pulling from CVS.
194
195   --nodownload
196     Do not try to download a kernel from downloads.lustre.org
197
198   --nosrc
199     Do not build a .src.rpm, a full kernel patch, or a patched kernel
200     tarball.
201
202   --ldiskfs
203     Do ldiskfs RPM. Now true by default
204
205   --publish
206     Unused.
207
208   --release
209     Specifies that the files generated do not include timestamps, and
210     that this is an official release.
211
212   --src
213     Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
214
215   --stage=DIR
216     Directory used to stage packages for release.  RPMs will be placed
217     more or less in DIR/<target>-<arch>, and the tarball will be
218     placed in DIR.
219
220   --tag=TAG
221     A CVS branch/tag name to build from when pulling from CVS.
222
223   --target=TARGET
224     The name of the target to build.  The available targets are listed
225     below.
226
227   --target-archs=TARGET_ARCHS
228     A (space delimited) list of architectures to build.  By default,
229     all of the archs supported by the TARGET will be built, in
230     addition to a .src.rpm.  This option can limit those, for machines
231     that can only build certain archs or if you only want a certain
232     arch built (for testing, or a one-off kernel).
233
234     Also note that by using a non-"base" arch (eg, i386) only kernels
235     will be built - there will be no lustre-lite-utils package.
236
237   --disable-datestamp
238     Prevents the datestamp flag (-D) from being passed to cvs for
239     checkouts. This is a workaround for a problem encountered when
240     using lbuild with tinderbox.
241
242   --xen
243     Builds a Xen domX kernel.
244
245   --enable-mptlinux
246     Enables the building of MPTLINUX with the same kernel Lustre is
247     built with.
248
249   --enable-rdac
250     Enables the building of MPTLINUX with the same kernel Lustre is
251     built with.
252 EOF
253
254 #   list_targets
255
256     fatal "$1" "$2"
257 }
258
259 # canonicalize a relative path
260 canon_path() {
261     local PATH="$1"
262
263     if [ ! -d "$PATH" ]; then
264         return 1
265     fi
266
267     pushd "$PATH" >/dev/null || return 1
268     local CANONPATH=$PWD
269     popd >/dev/null
270
271     echo "$CANONPATH"
272     return 0
273 }
274
275 check_options() {
276
277     if [ "$LUSTRE" ]; then
278         [ -r "$LUSTRE" ] || \
279             usage 1 "Could not find Lustre source tarball '$LUSTRE'."
280     else
281         [ "$CVSROOT" ] || \
282             usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
283         [ "$TAG" ] || \
284             usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
285     fi
286
287     if [ -z "$LINUX" ]; then
288         [ "$KERNELDIR" -o "$KERNELTREE" ] || \
289             usage 1 "A kernel directory must be specified with --kerneldir or --kerneltree."
290
291         [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
292             usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
293
294         if ! $RELEASE; then
295             [ "$TAG" ] || \
296                 usage 1 "When building a snapshot, a tag name must be used."
297         fi
298
299         [ "$TARGET" ] || usage 1 "A target must be specified with --target."
300 #       TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
301 #       [ -r "$TARGET_FILE" ] || \
302 #               usage 1 "Target '$TARGET' was not found."
303     fi
304
305     case $TARGET in
306         2.6-rhel5)
307             CANONICAL_TARGET="rhel5"
308             ;;
309         2.6-rhel4)
310             CANONICAL_TARGET="rhel-2.6"
311             ;;
312         2.6-suse)
313             CANONICAL_TARGET="sles-2.6"
314             ;;
315         2.6-sles10)
316             CANONICAL_TARGET="sles10-2.6"
317             ;;
318         2.6-sles11)
319             CANONICAL_TARGET="sles11"
320             ;;
321         2.6-oel5)
322             CANONICAL_TARGET="oel5"
323             ;;
324         hp_pnnl-2.4)
325             CANONICAL_TARGET="hp-pnnl-2.4"
326             ;;
327         2.6-vanilla \
328             | suse-2.4.21-2 \
329             | rh-2.4 \
330             | rhel-2.4 \
331             | sles-2.4 \
332             | 2.6-patchless)
333                 CANONICAL_TARGET="$TARGET"
334                 ;;
335     esac
336
337     local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
338     [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
339     local timestamplength="${#TIMESTAMP}"
340     if [ $timestamplength -eq 12 ]; then
341         TIMESTAMP="${TIMESTAMP}00"
342     elif [ $timestamplength -ne 14 ]; then
343         TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
344     fi
345
346     RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
347     if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
348         RPMBUILD=$(which rpm 2>/dev/null | head -1)
349         if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
350             usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
351         fi
352     fi
353
354     if [ -n "$CCACHE" ]; then
355         which "$DISTCC" &>/dev/null && export DISTCC RPM_BUILD_NCPUS
356
357         if which "$CCACHE" &>/dev/null; then
358             local ccache=$(which "$CCACHE")
359             local bindir="$TOPDIR/bin"
360
361             if [ ! -d $bindir ]; then
362                 mkdir -p $bindir || fatal 1 "error trying to create $bindir"
363             else
364                 rm ${bindir}/* > /dev/null 2>&1 || true
365             fi
366             ln -s "$ccache" ${bindir}/ccache
367             ln -s "$ccache" ${bindir}/cc
368             ln -s "$ccache" ${bindir}/$CC
369             export PATH=$bindir:$PATH
370             export CCACHE && export CC="ccache $CC"
371             # zero the cache so we can see how effective we are being with it
372             echo -n "ccache "
373             ccache -z
374
375             # get some ccache stats when we are done
376             push_exit_trap '[ -n "$CCACHE" ] && ccache -s' "ccache_summary"
377             # should remove the ccache trap if lbuild is interrupted
378             trap 'echo "Received an INT TERM or HUP signal, terminating."; delete_exit_trap "ccache_summary"; exit 1' INT TERM HUP
379         fi
380     fi
381
382     [ -z "$DISTRO" ] && DISTRO=$(autodetect_distro)
383
384     return 0
385
386 }
387
388 # autodetect used Distro
389 autodetect_distro() {
390
391     local name
392     local version
393
394     if [ -f /etc/SuSE-release ]; then
395         name=sles
396         version=$(grep ^VERSION /etc/SuSE-release)
397         version=${version#*= }
398     elif [ -f /etc/redhat-release ]; then
399         name=$(head -1 /etc/redhat-release)
400         version=$(echo "$distroname" |
401                   sed -e 's/^[^0-9.]*//g' | sed -e 's/[ \.].*//')
402     fi
403     if [ -z "$name" -o -z "$version" ]; then
404         fatal 1 "I don't know how to determine distro type/version.\nEither update autodetect_distro() or use the --distro argument"
405     fi
406
407     echo ${name}${version}
408     return 0
409
410 }
411
412 uniqify() {
413
414     echo $(echo "$*" | xargs -n 1 | sort -u)
415
416 }
417
418 download_srpm() {
419     local target=$1
420     local srpm=$2
421     local force="${3:-false}"
422
423     if $force || [ ! -r "$KERNELDIR/$srpm" ] ||
424        [ ! -s "$KERNELDIR/$srpm" ]; then
425         if $DOWNLOAD; then
426             local location="http://downloads.lustre.org/public/kernels/$target/old"
427             echo "Downloading $location/$srpm..."
428             if ! wget -nv "$location/$srpm" -O "$KERNELDIR/$srpm" 2>&1 ||
429                [ ! -s "$KERNELDIR/$srpm" ]; then
430                 rm -f $KERNELDIR/$srpm
431                 fatal 1 "Could not download target $target's kernel SRPM $srpm from $location."
432             fi
433         else
434             fatal 1 "$srpm not found in directory $KERNELDIR."
435         fi
436     fi
437
438 }
439
440 download_file() {
441     local from="$1"
442     local to="$2"
443     local force="$3"
444
445     local file=${from##*/}
446
447     if [ -d $to ]; then
448         to="$to/$file"
449     fi
450
451     local semaphore="$to-downloading"
452
453     is_downloading() {
454         if [ ! -f $semaphore ]; then
455             return 1
456         fi
457
458         # make sure the download has not been aborted
459         local now=$(date +%s)
460         local file_mtime=$(stat -c %Y "$to")
461         local staleness=$((now - file_mtime))
462         # let's assume an active download will write at least once a minute
463         if [ $staleness -gt 60 ]; then
464             return 1
465         fi
466
467         return 0
468     }
469
470     is_downloaded() {
471         # if the semaphore file exists, the file is either still downloading
472         # or a download was aborted and we cannot trust the target file
473         if [ -f $semaphore ]; then
474             return 1
475         fi
476
477         if ! is_downloading && [ -r "$to" ] && [ -s "$to" ]; then
478             return 0
479         fi
480
481         return 1
482     }
483
484     if $force || ! is_downloaded; then
485         if is_downloading; then
486             echo "Somebody else is downloading $from..."
487             while is_downloading; do
488                 echo "Waiting for $to to finish downloading"
489                 sleep 60
490             done
491             if is_downloaded; then
492                 return 0
493             else
494                 echo "The download we were waiting for seems to have been aborted"
495             fi
496
497         fi
498
499         if $DOWNLOAD; then
500             echo "Downloading $from..."
501             # flag others so they don't try to download also
502             push_exit_trap "rm -f $to $semaphore" "download"
503             touch $semaphore
504             if ! wget -nv "$from" -O "$to" || [ ! -s "$to" ]; then
505                 # the trap will remove the files via the fatal below
506                 fatal 1 "Could not download ${to##*/} from ${from%/*}/."
507             fi
508             rm -f $semaphore
509             delete_exit_trap "download"
510         else
511             fatal 1 "${to##*/} not found in directory ${to%/*}."
512         fi
513     fi
514
515     return 0
516
517 }
518
519 download_ofed() {
520     local force="${1:-false}"
521
522     local location="http://downloads.lustre.org/public/OFED/"
523
524     local Mmv daily
525     if [[ $OFED_VERSION = daily-* ]]; then
526         OFED_VERSION=${OFED_VERSION/daily-/}
527         Mmv=${OFED_VERSION%%-*}
528         daily=${OFED_VERSION##$Mmv-}
529         location="http://www.openfabrics.org/downloads/OFED/ofed-${Mmv}-daily/"
530         # find the filename for the version for the date specified
531         OFED_VERSION=$(curl -s "$location" | sed -nre "/${daily}-/s/.*href=\"OFED-(${Mmv//./\\.}-${daily}-[0-9]{4,4}).tgz.*$/\1/p" | tail -1)
532         if [ -z "$OFED_VERSION" ]; then
533             fatal 1 "Could not determine the filename of the OFED snapshot for ${daily}"
534         fi
535     fi
536
537     if [ -z "$OFED_VERSION" -o "$OFED_VERSION" = "inkernel" ]; then
538         return 0
539     fi
540
541     local file="OFED-${OFED_VERSION}.tgz"
542     download_file "$location/$file" "$KERNELTREE" "$force"
543
544 }
545
546 load_target() {
547
548     EXTRA_VERSION_save="$EXTRA_VERSION"
549     for patchesdir in "$EXTERNAL_PATCHES" \
550                       "$TOPDIR/lustre/lustre/kernel_patches"; do
551         TARGET_FILE="$patchesdir/targets/$TARGET.target"
552         [ -r "$TARGET_FILE" ] && break
553     done
554     [ -r "$TARGET_FILE" ] || fatal 1 "Target $TARGET was not found."
555
556     echo "Loading target config file $TARGET.target..."
557
558     # if the caller specified an OFED_VERSION it should override whatever
559     # the target file specifies
560     local env_OFED_VERSION="$OFED_VERSION"
561
562     . "$TARGET_FILE"
563
564     if [ -n "$env_OFED_VERSION" ]; then
565         OFED_VERSION="$env_OFED_VERSION"
566     fi
567
568     # doesn't make any sense to build OFED for xen domX's
569     if $XEN; then
570         OFED_VERSION=""
571     fi
572
573     # XXX - set_rpm_smp_type is an ugly undeterministic hack.  it needs to
574     #       go away and the target just specify the $RPMSMPTYPE
575     [ -z "$RPMSMPTYPE" ] && set_rpm_smp_type
576
577     # CC might have been overwriten in TARGET_FILE
578     if [[ $CC != ccache\ * ]] && which "$CCACHE" &>/dev/null; then
579         export CCACHE && export CC="ccache $CC"
580     fi
581
582     if [ ! "$KERNELTREE" = "" ] && [ -d "$KERNELTREE" ]; then
583         KERNELDIR="$KERNELTREE/${lnxmaj}"
584         [ -d "$KERNELDIR" ] || mkdir "$KERNELDIR"
585     fi
586
587     # verify the series is available
588     if [ "$SERIES" ]; then
589         for series in $SERIES; do
590             for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
591                 [ -r "$patchesdir/series/$series" ] && continue 2
592             done
593             fatal 1 "Target $TARGET's series $SERIES could not be found.\nSearched:\n\t$EXTERNAL_PATCHES/series\n\t$TOPDIR/lustre/lustre/kernel_patches/series."
594         done
595     fi
596
597     # set the location of the .config file
598     local XENPOSTFIX=""
599     if $XEN; then
600         XENPOSTFIX="-xen"
601     fi
602
603     if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
604         CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH${RPMSMPTYPE:+-}${RPMSMPTYPE}.config"
605     fi
606
607     local lnxrelnew=${lnxrel//-/_}
608
609     # remember the EXTRA_VERSION before we diddle it here
610     # XXX - we really should not diddle with any values read in from the
611     #       target file.  if we want to modify a value, we should create
612     #       a new variable.
613     PRISTINE_EXTRA_VERSION=$EXTRA_VERSION
614
615     if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
616         fatal 1 "Config file for target $TARGET missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
617     fi
618
619     if [ "$EXTRA_VERSION_save" ]; then
620         EXTRA_VERSION="$EXTRA_VERSION_save"
621     elif ! $RELEASE; then
622         # if there is no patch series, then this is not a lustre specific
623         # kernel.  don't make it look like one
624         if $PATCHLESS || [ -n "$SERIES" ]; then
625             EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
626 #            EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
627             EXTRA_VERSION="${EXTRA_VERSION}.${TIMESTAMP}"
628         fi
629     fi
630     # EXTRA_VERSION=${EXTRA_VERSION//-/_}
631
632     ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
633
634     BUILD_ARCHS=
635     for arch in $(uniqify "$ALL_ARCHS"); do
636         if [ -z "$TARGET_ARCHS" ] ||
637            [[ \ $TARGET_ARCHS\  = *\ $arch\ * ]]; then
638             BUILD_ARCHS="$BUILD_ARCHS $arch"
639         fi
640     done
641     [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
642     echo "Building for: $BUILD_ARCHS"
643 }
644
645 tarflags() {
646     local file="$1"
647
648     case "$file" in
649         '')
650             fatal 1 "tarflags(): File name argument missing."
651             ;;
652         *.tar.gz | *.tgz)
653             echo 'zxf'
654             ;;
655         *.tar.bz2)
656             echo 'jxf'
657             ;;
658         *.tar)
659             echo 'xf'
660             ;;
661         *)
662             fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
663             ;;
664     esac
665
666 }
667
668 untar() {
669     local tarfile="$1"
670     shift
671     local extractfile="$@"
672
673     echo "Untarring ${tarfile##*/}..."
674     tar $(tarflags "$tarfile") "$tarfile" $extractfile
675
676 }
677
678 unpack_ofed() {
679
680     if ! untar "$KERNELTREE/OFED-${OFED_VERSION}.tgz"; then
681         return 1
682     fi
683     [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
684
685 }
686
687 unpack_rdac() {
688
689     if ! untar "$KERNELTREE/rdac-LINUX-${RDAC_VERSION}-source.tar.gz"; then
690         return 1
691     fi
692     [ -d rdac-LINUX ] || ln -sf rdac-LINUX-[0-9][0-9].* rdac-LINUX
693
694 }
695
696 unpack_mptlinux() {
697
698     if ! untar $KERNELTREE/SUN_MPTLINUX_RHEL5_PH16-${MPTLINUX_VERSION}.tar.gz pkg1-rhel5/srpms-1/mptlinux-${MPTLINUX_VERSION}-1.src.rpm; then
699         return 1
700     fi
701     mv pkg1-rhel5/srpms-1/mptlinux-${MPTLINUX_VERSION}-1.src.rpm .
702
703 }
704
705 unpack_lustre() {
706
707     if [ -z "$LUSTRE" ]; then
708         local DATESTAMP=""
709
710         if [ -n "$USE_DATESTAMP" ]; then
711             DATESTAMP="-D '$DATE'"
712         fi
713
714         local DIRNAME="lustre-$TAG-$TIMESTAMP"
715
716         cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
717             fatal 1 "There was an error checking out toplevel Lustre from CVS."
718         pushd "$DIRNAME" > /dev/null
719         ./lustrecvs "$TAG" || \
720             fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
721         echo "Creating lustre tarball..."
722         sh autogen.sh || fatal 1 "There was an error running autogen.sh."
723         ./configure --disable-{modules,utils,liblustre,tests,doc} || \
724             fatal 1 "There was an error running ./configure to create makefiles."
725         make dist || fatal 1 "There was an error running 'make dist'."
726         LUSTRE=$PWD/lustre-*.tar.gz
727         popd > /dev/null
728     fi
729
730     untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
731     [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
732
733 }
734
735 do_patch_linux() {
736
737     local do_patch=${1:-true}
738
739     FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
740     [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
741     $do_patch && pushd linux >/dev/null
742     for series in $SERIES; do
743         echo -n "Applying series $series:"
744         for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
745             [ -r "$patchesdir/series/$series" ] || continue
746             SERIES_FILE="$patchesdir/series/$series"
747             for patch in $(<"$SERIES_FILE"); do
748                 echo -n " $patch"
749                 PATCH_FILE="$patchesdir/patches/$patch"
750                 [ -r "$PATCH_FILE" ] || \
751                     fatal 1 "Patch $patch does not exist in Lustre tree."
752                 cat "$PATCH_FILE" >> "$FULL_PATCH" || {
753                     rm -f $FULL_PATCH
754                     fatal 1 "Error adding patch $patch to full patch."
755                 }
756                 if $do_patch; then
757                     patch -s -p1 < "$PATCH_FILE" 2>&1 || {
758                         rm -f $FULL_PATCH
759                         fatal 1 "Error applying patch $patch."
760                     }
761                 fi
762             done
763             break
764         done
765         echo
766     done
767     $do_patch && popd >/dev/null
768     echo "Full patch has been saved in ${FULL_PATCH##*/}."
769
770 }
771
772 build_lustre() {
773     local linux="$1"
774     local linuxobj="$2"
775
776     cp "$LUSTRE" SOURCES
777
778     pushd lustre >/dev/null
779
780     echo "Building Lustre RPMs for: $BUILD_ARCHS..."
781     local targets arch
782     for arch in $BUILD_ARCHS; do
783         targets="--target $arch $targets"
784     done
785
786     local confoptions="--with-linux=${linux}"
787     if $PATCHLESS; then
788         confoptions="--with-linux=${linux} --disable-server"
789     fi
790     if [ "$linuxobj" != "" ]; then
791         confoptions="$confoptions --with-linux-obj=${linuxobj}"
792     fi
793
794     ./configure $confoptions ${CONFIGURE_FLAGS} 2>&1
795     if [ "$?" != "0" ]; then
796         local saved_config="../config.log.$(date +%s)"
797         cp config.log $saved_config
798         chmod a+r $saved_config
799         echo "Saved config.log is at $saved_config"
800         cat /proc/mounts
801         ls -l /proc/$$
802         pwd
803         echo "config.log contents:"
804         cat config.log
805         popd
806         return 255
807     fi
808
809     gen_lustre_version
810
811     # hack. Somebody move build/lustre.spec to lustre.spec for b1_6
812     local lustre_spec
813     [ -f lustre.spec ] && lustre_spec=lustre.spec
814     [ -f build/lustre.spec ] && lustre_spec=build/lustre.spec
815
816     [ -f "$lustre_spec" ] && sed \
817         -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
818         < $lustre_spec \
819         > ../lustre.spec
820
821     local rpmbuildopt='-bb'
822     if $NORPM; then
823         rpmbuildopt='-bc'
824         echo NORPM mode. Only compiling.
825     fi
826
827     # convert the $PATCHLESS boolean to an empty/not-empty boolean
828     # as silly as this seems, it makes the syntax of the rpmbuild command
829     # simpler and not need an eval to deal with the quotes in the quotes
830     local is_patchless=""
831     if $PATCHLESS; then
832         is_patchless="yes"
833     fi
834
835     # ditto for the lustre-tests boolean
836     local lustre_tests=""
837     if ! $LUSTRE_TESTS; then
838         lustre_tests="no"
839     fi
840
841     $RPMBUILD $targets $rpmbuildopt ../lustre.spec \
842         ${is_patchless:+--define "lustre_name lustre-client"} \
843         ${lustre_tests:+--define "build_lustre_tests 0"} \
844         ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
845         --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \
846         --define "_tmppath $TMPDIR" \
847         --define "_topdir $TOPDIR" 2>&1 || \
848         fatal 1 "Error building rpms for $BUILD_ARCHS."
849
850     popd >/dev/null
851     ( $(skeep_ldiskfs_rpm $TAG) ) && return
852
853     pushd lustre/ldiskfs || return 255
854     make dist 2>&1
855     if [ "$?" != "0" ]; then
856         popd
857         return 255
858     fi
859     cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES
860
861     gen_lustre_version
862
863     local ldiskfs_spec=lustre-ldiskfs.spec
864     [ -f "$ldiskfs_spec" ] && sed \
865     -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
866     < $ldiskfs_spec \
867     > ../lustre-ldiskfs.spec
868
869     if ! $RPMBUILD $targets $rpmbuildopt ../lustre-ldiskfs.spec \
870         --define "_tmppath /var/tmp" \
871         --define "_topdir $TOPDIR" 2>&1; then
872         popd
873         return 255
874     fi
875
876     if $DO_SRC; then
877         if ! $RPMBUILD -bs ../lustre-ldiskfs.spec \
878             --define "_tmppath /var/tmp" \
879             --define "_topdir $TOPDIR" 2>&1; then
880             popd
881             return 255
882         fi
883     fi
884     popd
885
886 }
887
888 stage() {
889
890     [ "$STAGEDIR" ] || return 0
891
892     for arch in $BUILD_ARCHS; do
893         rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
894         echo "${0##*/}: Copying RPMs into ${rpmdir}"
895         mkdir -p "${rpmdir}"
896         cp -v RPMS/${arch}/*.rpm "${rpmdir}"
897         if [ -d RPMS/noarch ]; then
898             cp -v RPMS/noarch/*.rpm "${rpmdir}"
899         fi
900     done
901
902     cp -v "$LUSTRE" "$STAGEDIR"
903
904 }
905
906 #check if we need to build separate ldiskfs RPM
907 skeep_ldiskfs_rpm() {
908         local tag="$1"
909
910         local skip=false
911
912         if ! $LDISKFSRPM; then
913             skip=true
914         elif $PATCHLESS; then
915             skip=true
916         else
917             for skiptag in $SKIPLDISKFSRPM; do
918                 [[ $tag == $skiptag ]] && skip=true && break
919             done
920         fi
921
922         pushd $TOPDIR/BUILD/lustre-[1-9]* >/dev/null
923         grep -q '^SERVER_TRUE[ \t]=[ \t]#$' autoMakefile && skip=true
924         popd >/dev/null
925
926         echo $skip
927
928 }
929
930 #generate LUSTRE_EXTRA_VERSION from EXTRA_VERSION
931 gen_lustre_version() {
932
933     LUSTRE_EXTRA_VERSION="${lnxmaj}-${EXTRA_VERSION}${FLAVOR_DELIMITER}${RPMSMPTYPE}"
934     LUSTRE_EXTRA_VERSION=${LUSTRE_EXTRA_VERSION//-/_}
935
936 }
937
938 set_rpm_smp_type() {
939
940     local infact_arch="${TARGET_ARCH}"
941
942     RPMSMPTYPE=""
943     [ "$infact_arch" == "i586" ] && infact_arch="i686"
944
945     local smp_type
946     for smp_type in $SMP_ARCHS; do
947         [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
948     done
949
950     for smp_type in $BIGSMP_ARCHS; do
951         [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
952     done
953
954     for smp_type in $PPC64_ARCHS; do
955         [ $infact_arch == $smp_type ] && RPMSMPTYPE=ppc64 && break
956     done
957
958     for smp_type in $DEFAULT_ARCHS; do
959         [ $infact_arch == $smp_type ] && RPMSMPTYPE=default && break
960     done
961
962 }
963
964 # This function takes a linux source pool and digs out the linux release
965 # from it
966 find_linux_release() {
967     local SRCDIR="$1"
968
969     local LINUXRELEASEHEADER=$SRCDIR/include/linux/version.h
970     if [ -s $SRCDIR/include/linux/utsrelease.h ]; then
971         LINUXRELEASEHEADER=$SRCDIR/include/linux/utsrelease.h
972     fi
973
974     sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
975
976 }
977
978 # XXX this needs to be re-written as a wrapper around find_rpm
979 #     or just gotten rid of.  :-)
980 find_linux_rpm() {
981     local prefix="$1"
982
983     local pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
984     [ -d $pathtorpms ] || return 255
985
986     local kernelbinaryrpm rpmfile
987     local wanted_kernel="${lnxmaj}${lnxmin}-${lnxrel}"
988
989     local arch ret=1
990     for arch in $TARGET_ARCHS_ALL; do
991         local found_rpm="" rpm
992         for rpm in ${pathtorpms}/${arch}/*.rpm; do
993             if rpm -q --provides -p "$rpm" 2>&3 | grep -q "kernel${prefix} = $wanted_kernel" 2>&3; then
994
995                 found_rpm="$rpm"
996                 ret=0
997                 break
998             fi
999         done
1000         [ -f "$found_rpm" ] && break
1001     done
1002
1003     echo "$found_rpm"
1004     return $ret
1005
1006 }
1007
1008 # unpack kernel(/source/devel) RPM
1009 #
1010 # This function and it's setting of $LINUX and $LINUXOBJ is a total hack that
1011 # needs to completely refactored.  It completely ingores that $BUILD_ARCHS may
1012 # contain a list of arches for which rpmbuild commands (including the one for
1013 # lustre itself)
1014 unpack_linux_devel_rpm() {
1015     local kernelrpm="${1}"
1016
1017     [ -f "$kernelrpm" ] || return 255
1018     [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused || return 255
1019
1020     pushd $TOPDIR/reused &>/dev/null || return 255
1021
1022     if ! rpm2cpio < "$kernelrpm" | cpio -id > /dev/null 2>&1; then
1023         return 255
1024     fi
1025
1026     # call a distro specific hook, if available
1027     if type -p unpack_linux_devel_rpm-$DISTRO; then
1028         if ! unpack_linux_devel_rpm-$DISTRO "$kernelrpm"; then
1029             return 255
1030         fi
1031     fi
1032
1033     popd &>/dev/null
1034
1035     find_linux_devel_paths $TOPDIR/reused
1036
1037     return 0
1038
1039 }
1040
1041 build_kernel_ib() {
1042     local linux="$1"
1043
1044     # build kernel-ib{,-devel}
1045     local K_SRC="K_SRC"
1046     # ofed 1.3 had a bug in the rpm spec
1047     if [ "$OFED_VERSION" = "1.3" ]; then
1048         K_SRC="KSRC"
1049     fi
1050
1051     local OFED_CORE="--with-core-mod --with-ipoib-mod --with-sdp-mod --with-user_mad-mod --with-user_access-mod --with-addr_trans-mod --with-rds-mod --with-qlgc_vnic-mod --with-madeye-mod"
1052     local OFED_HARDWARE="--with-mthca-mod --with-mlx4-mod --with-mlx4_en-mod --with-cxgb3-mod --with-nes-mod"
1053     # some I/B drivers are architecture dependent and kernel-ib's configure
1054     # does not figure it out for us ~sigh~
1055     case "$TARGET_ARCH" in
1056         ppc64)
1057             OFED_HARDWARE="$OFED_HARDWARE --with-ehca-mod"
1058             ;;
1059     esac
1060     # we're no longer shipping the OFED iSCSI
1061     #OFED_ISCSI="--with-srp-mod --with-srp-target-mod"
1062     ## ISER module has no backport support as of OFED 1.5 (i.e. only builds on
1063     ##kernels >= 2.6.30)
1064     #if [[ $OFED_VERSION = 1.[0-4]* ]]; then
1065     #   OFED_ISCSI="$OFED_ISCSI --with-iser-mod"
1066     #fi
1067
1068     # assume we are just rebuilding the SRPM
1069     local BUILD_TYPE=${BUILD_TYPE:-"--rebuild"}
1070     local SOURCE="${TOPDIR}/OFED/SRPMS/ofa_kernel-*.src.rpm"
1071
1072     # but switch to building from the SPEC if we need to apply patches
1073     if ls ${TOPDIR}/lustre/build/patches/ofed/* >/dev/null; then
1074         BUILD_TYPE="-bb"
1075         rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
1076         SOURCE="${TOPDIR}/SPECS/ofa_kernel.spec"
1077         local file ed_fragment1 ed_fragment2 n=1
1078         for file in $(ls ${TOPDIR}/lustre/build/patches/ofed/*); do
1079             ed_fragment1="$ed_fragment1
1080 Patch$n: ${file%%*/}"
1081             ed_fragment2="$ed_fragment2
1082 %patch$n -p0"
1083             cp $file ${TOPDIR}/SOURCES
1084             let n=$n+1
1085         done
1086
1087         if [ $n -gt 1 ]; then
1088             ed $SOURCE <<EOF
1089 /^Source: /a
1090 $ed_fragment1
1091 .
1092 /^%setup /a
1093 $ed_fragment2
1094 .
1095 wq
1096 EOF
1097         fi
1098     fi
1099
1100     local linuxrelease=$(find_linux_release "$linux")
1101     if ! $RPMBUILD $BUILD_TYPE --define 'build_kernel_ib 1' --define 'build_kernel_ib_devel 1' \
1102                   ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1103                   --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1104                   --define "KVERSION ${linuxrelease}" \
1105                   --define "$K_SRC ${linux}" \
1106                   --define "LIB_MOD_DIR /lib/modules/${linuxrelease}/updates" \
1107                   ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1108                   --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
1109                   ${SOURCE} 2>&1; then
1110         fatal 1 "Error building kernel-ib"
1111     fi
1112
1113 }
1114
1115 store_for_reuse() {
1116         local articles="$1"
1117         local module="$2"
1118         local location="$3"
1119         local signature="$4"
1120         local use_links="$5"
1121
1122         local linkflag=""
1123         if $use_links; then
1124             linkflag="l"
1125         fi
1126
1127         location="$location"/"$signature"/"$module"
1128         mkdir -p "$location"
1129         # the cleanup script removes any directory that doesn't have a
1130         # .lastused, so let's try to prevent that as soon as we can
1131         # this solution still slightly racy with the cleanup script
1132         # but the race is a lot tighter now
1133         touch -t 197001010000 "$location/.lastused"
1134         ## use eval/echo here to make sure shell expansions are performed
1135         #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
1136         local article
1137         for article in $(eval echo $articles); do
1138             if ! cp -a${linkflag} "$article" "$location"; then
1139                 error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
1140                 # rename the cache location so that it's not cached
1141                 # product, but is around for analysis
1142                 mv "$location"{,-bad-$(date +%s)} ||
1143                     error "failed to clean up a failed cache attempt" \
1144                           "in \"$location\" -- manual cleanup will be" \
1145                           "necessary"
1146                 return 1
1147             fi
1148         done
1149
1150         # flag the cache as complete (i.e. in case lbuild was previously
1151         # interrupted while caching)
1152         touch "$location/.lastused"
1153
1154         return 0
1155
1156 }
1157
1158 reuse() {
1159     local module="$1"
1160     local dest="$2"
1161     local use_links="${3:-false}"
1162     local signature="$4"
1163
1164     if [ -n "$REUSEBUILD" ] && [ -d "$REUSEBUILD/$signature/$module" ]; then
1165         if [ ! -f "$REUSEBUILD/$signature/$module/.lastused" ]; then
1166             # the .lastused flag is populated at the end of the caching to
1167             # signal that the caching was completed.  if that flag is not
1168             # there, then the cache is invalid (and should be removed in fact)
1169             mv "$REUSEBUILD/$signature/$module"{,-bad-$(date +%s)} ||
1170                 fatal 1 "failed to clean up a bad cache in location $REUSEBUILD/$signature/$module\" -- manual cleanup will be necessary"
1171             return 1
1172         fi
1173
1174         # so that we know how stale this entry is
1175         touch $REUSEBUILD/$signature/$module/.lastused
1176
1177         if $use_links; then
1178             if ls $REUSEBUILD/$signature/$module/* >/dev/null 2>&1; then
1179                 cp -al $REUSEBUILD/$signature/$module/* $dest/
1180             fi
1181         else
1182             # copying is pretty heavy
1183             # cp -a $REUSEBUILD/$signature/$module/* $dest/
1184             # do some creative symlinking instead
1185             local dir
1186             for dir in BUILD SRPMS SPECS; do
1187                 if ls $REUSEBUILD/$signature/$module/$dir/* >/dev/null 2>&1; then
1188                     ln -s $REUSEBUILD/$signature/$module/$dir/* $dest/$dir
1189                 fi
1190             done
1191             # sources have to be copied by file because we need SOURCES to
1192             # be a dir we can write into
1193 # could overrun ls's arg list here
1194             #ls $REUSEBUILD/$signature/$module/SOURCES/* |
1195             find $REUSEBUILD/$signature/$module/SOURCES/ -type f |
1196                 xargs ln -t $dest/SOURCES -s
1197
1198             # same for RPMS/* dirs
1199 # could overrun ls's arg list here
1200             #ls $REUSEBUILD/$signature/$module/RPMS/$TARGET_ARCH/* |
1201             local dir
1202             for dir in $REUSEBUILD/$signature/$module/RPMS/*; do
1203                 mkdir -p $dest/RPMS/${dir##*/}
1204                 find $dir -type f |
1205                   xargs ln -t $dest/RPMS/${dir##*/} -s
1206             done
1207
1208         fi
1209         return 0
1210     else
1211         return 1
1212     fi
1213 }
1214
1215 basearch() {
1216     local arch="$1"
1217
1218     if [[ $arch = i[3456]86 ]]; then
1219         echo "i386"
1220     else
1221         echo "$arch"
1222     fi
1223
1224 }
1225
1226 #
1227 # in a given directory, find the first rpm matching given requirements
1228 #
1229 find_rpm() {
1230     local dir="$1"
1231     local match_type="$2"
1232     local match="$3"
1233
1234     pushd "$dir" > /dev/null || \
1235         fatal 1 "Unable to chdir to directory \"$dir\" in find_rpm()"
1236
1237     local file
1238     for file in $(ls *.rpm); do
1239         if [ ! -f "$file" ]; then
1240             continue
1241         fi
1242         case "$match_type" in
1243             provides)
1244                 # match is any valid ERE (i.e. given to egrep) match
1245                 if rpm -q --provides -p "$file" 2>&3 | egrep -q "$match"; then
1246                     echo "$file"
1247                     popd >/dev/null
1248                     return 0
1249                 fi
1250                 ;;
1251             *)
1252                 popd >/dev/null
1253                 fatal 1 "Unknown match type \"$match_type\" given to find_rpm()"
1254                 ;;
1255         esac
1256     done
1257
1258     popd >/dev/null
1259     return 1
1260 }
1261
1262 build_kernel_with_srpm() {
1263     local outfd=$1
1264
1265     if [ -z "$outfd" ] || [ $outfd = 1 ]; then
1266         fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
1267     fi
1268
1269     # need to generate the patch for this target
1270     do_patch_linux false >&${outfd}    # sets global $FULL_PATCH (yeah, yuck)
1271
1272     # get an md5sum of the kernel patch + config for reuse check
1273     # XXX really, there needs to be a signature and a CONFIG_FILE per arch
1274     #     in BUILD_ARCHS
1275     local release_str
1276     if $RELEASE; then
1277         local release_str="RELEASE=$RELEASE\n"
1278     fi
1279
1280     if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1281         local REUSE_SIGNATURE=$({ echo -en $release_str;
1282                                   echo $BUILD_GEN;
1283                                   cat $CONFIG_FILE $TARGET_FILE $FULL_PATCH; } |
1284                                 md5sum | cut -d" " -f1)
1285         # see if we can link to the reuse pool
1286         # XXX - hrm.  i'm not convinced this doesn't belong in the reuse
1287         #       "library"
1288         local CAN_LINK_FOR_REUSE=false
1289         touch $REUSEBUILD/$$
1290         if cp -al $REUSEBUILD/$$ $TOPDIR/ 2>/dev/null; then
1291             CAN_LINK_FOR_REUSE=true
1292         fi
1293         rm $REUSEBUILD/$$
1294     fi
1295
1296     # the extra version string to use for the kernel (which might be a reused
1297     # kernel, remember)
1298     local kernel_extra_version=""
1299     if ! $USE_BUILD_CACHE || ! reuse kernel "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1300                                    "$REUSE_SIGNATURE"; then
1301         # nothing cached, build from scratch
1302         if [ ! -r "$KERNELDIR/$KERNEL_SRPM" ]; then
1303             echo "Downloading kernel SRPM"
1304             download_srpm "$CANONICAL_TARGET" "$KERNEL_SRPM" >&${outfd}
1305         fi
1306
1307         if ! rpm -ivh $KERNELDIR/$KERNEL_SRPM \
1308                   --define "_topdir $TOPDIR" >&${outfd} 2>&1; then
1309             # should we clean this up or leave it for analysis?
1310             #rm -rf $RPMTOPDIR
1311             fatal 1 "Error installing kernel SRPM."
1312         fi
1313
1314         # put the Lustre kernel patch into the RPM build tree
1315         cp $FULL_PATCH $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch
1316         prepare_and_build_srpm >&${outfd} ||
1317             fatal 1 "failed to prepare_and_build_srpm"
1318
1319         if [ -z "$REUSE_SIGNATURE" ]; then
1320             echo "No reuse signature was caculated so not storing the built kernel" >&${outfd}
1321         else
1322             # store the resulting kernel RPM build tree for future use
1323             echo "Storing the built kernel for future reuse" >&${outfd}
1324             if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1325                                  "kernel" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1326                                  "$CAN_LINK_FOR_REUSE"; then
1327                 error "Failed to store kernel RPMS for reuse"
1328                 echo "unknown"
1329                 return 1
1330             fi
1331         fi
1332     fi  # build reuse
1333
1334     # figure out the EXTRA_VERSION of the kernel we built or are re-using
1335     local KERNEL_RPM
1336     if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel ="); then
1337         fatal 1 "Failed to find a kernel RPM in $TOPDIR/RPMS/$TARGET_ARCH/"
1338     fi
1339     kernel_extra_version=$(rpm -q --queryformat "%{RELEASE}" -p $TOPDIR/RPMS/$TARGET_ARCH/$KERNEL_RPM)
1340
1341     # should now have the following RPMs
1342     # $TOPDIR/RPMS/$arch/kernel-lustre-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1343     # $TOPDIR/RPMS/$arch/kernel-lustre-devel-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1344     # $TOPDIR/RPMS/$arch/kernel-lustre-headers-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1345     # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-common-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1346     # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1347
1348     echo $kernel_extra_version
1349     return 0
1350
1351 }
1352
1353 build_mptlinux() {
1354     local linux="$1"
1355     local version="$2"
1356
1357     if ! $BUILD_RDAC || [ -z "$version" -o "$version" = "inkernel" ]; then
1358         return 0
1359     fi
1360
1361     local targets arch
1362     for arch in $BUILD_ARCHS; do
1363         targets="--target $arch $targets"
1364     done
1365
1366     local rpmbuildopt='-bb'
1367     if $NORPM; then
1368         rpmbuildopt='-bc'
1369         echo NORPM mode. Only compiling.
1370     fi
1371
1372     # if only we could just rebuild the src.rpm.  but the included spec
1373     # is a real pig's breakfast.  just check out the patch we need to
1374     # apply to it to make it useful.
1375     #$RPMBUILD --rebuild \
1376     #          --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1377     #          ${TOPDIR}/mptlinux-*.src.rpm
1378     rpm -ivh --define "_topdir ${TOPDIR}" ${TOPDIR}/mptlinux-*.src.rpm
1379
1380     # now the big honkin' patch to the spec file
1381     pushd ${TOPDIR}/SPECS
1382     # to regen this patch use:
1383     # !!cd ~/rpm/SPECS/ && diff -u mptlinux.spec{.dist,}
1384     patch -p0 < ${TOPDIR}/lustre/build/mptlinux.spec.patch || fatal 1 "failed to patch mptlinux.spec"
1385     popd
1386
1387     local targets arch
1388         for arch in $BUILD_ARCHS; do
1389         targets="--target $arch $targets"
1390     done
1391
1392     local rpmbuildopt='-bb'
1393     if $NORPM; then
1394         rpmbuildopt='-bc'
1395         echo NORPM mode. Only compiling.
1396     fi
1397
1398     if ! $RPMBUILD $targets $rpmbuildopt \
1399                   ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1400                   --define "_tmppath /var/tmp" \
1401                   --define "_topdir ${TOPDIR}" \
1402                   --define "kernel_obj $linux" \
1403                   ${TOPDIR}/SPECS/mptlinux.spec 2>&1; then
1404         return 1
1405     fi
1406     if $DO_SRC; then
1407         if ! $RPMBUILD -bs \
1408                       ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1409                       --define "_tmppath /var/tmp" \
1410                       --define "_topdir ${TOPDIR}" \
1411                       --define "kernel_obj $linux" \
1412                       ${TOPDIR}/SPECS/mptlinux.spec 2>&1; then
1413             return 1
1414         fi
1415     fi
1416
1417     return 0
1418
1419 }
1420
1421 # build RDAC
1422 build_rdac() {
1423     local linux="$1"
1424     local version="$2"
1425
1426     if ! $BUILD_MPTLINUX || [ -z "$version" -o "$version" = "inkernel" ]; then
1427         return 0
1428     fi
1429
1430     # note that we use an _, not a . before the spec on purpose.  we are not
1431     # allowed to have more than one file with a .spec trailer in a tarball
1432     # that is supposed to be usable with rpmbuild
1433     cp lustre/build/rdac_spec ${TOPDIR}/SPECS/rdac.spec || fatal 1 "Could not find rdac.spec in lustre/build" 
1434
1435     local targets arch
1436     for arch in $BUILD_ARCHS; do
1437         targets="--target $arch $targets"
1438     done
1439
1440     local rpmbuildopt='-bb'
1441     if $NORPM; then
1442         rpmbuildopt='-bc'
1443         echo NORPM mode. Only compiling.
1444     fi
1445
1446     local distro
1447     case $DISTRO in
1448      rhel5)     distro="REDHAT"
1449                 ;;
1450     sles1*)     distro="SUSE"
1451                 ;;
1452          *)     echo "$DISTRO not supported by RDAC, skipping"
1453                 return 0
1454                 ;;
1455     esac
1456     if ! $RPMBUILD $targets $rpmbuildopt --define "dist $distro" \
1457                   ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1458                   --define "_tmppath /var/tmp" \
1459                   --define "_topdir ${TOPDIR}" \
1460                   --define "kernel_obj $linux" \
1461                   ${TOPDIR}/SPECS/rdac.spec 2>&1; then
1462         return 1
1463     fi
1464     if $DO_SRC; then
1465         if ! $RPMBUILD -bs --define "dist $distro" \
1466                       ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1467                       --define "_tmppath /var/tmp" \
1468                       --define "_topdir ${TOPDIR}" \
1469                       --define "kernel_obj $linux" \
1470                       ${TOPDIR}/SPECS/rdac.spec 2>&1; then
1471             return 1
1472         fi
1473     fi
1474
1475     return 0
1476 }
1477
1478 # build OFED
1479 # globals used:
1480 #    TOPDIR
1481 #    REUSEBUILD, USE_BUILD_CACHE
1482 #    CONFIGURE_FLAGS
1483
1484 build_ofed() {
1485     local linux="$1"
1486     local ofed_version="$2"
1487
1488     # before lustre, build kernel-ib
1489     if [ -z "$ofed_version" -o "$ofed_version" = "inkernel" ]; then
1490         return 0
1491     fi
1492
1493     if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1494         local REUSE_SIGNATURE=$({ echo "$ofed_version";
1495                                   echo "$(find_linux_release ${linux})";
1496                                   cat "${linux}/include/linux/autoconf.h"; } |
1497                                 md5sum | cut -d" " -f1)
1498         # see if we can link to the reuse pool
1499         # XXX - hrm.  i'm not convinced this doesn't belong in the reuse
1500         #       "library"
1501         local CAN_LINK_FOR_REUSE=false
1502         touch $REUSEBUILD/$$
1503         if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1504             CAN_LINK_FOR_REUSE=true
1505         fi
1506         rm $REUSEBUILD/$$
1507     fi
1508
1509     if ! $USE_BUILD_CACHE || ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1510                                    "$REUSE_SIGNATURE"; then
1511         if [ -n "$REUSE_SIGNATURE" ]; then
1512             # stash away the existing built articles for a moment
1513             mkdir bak
1514             mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
1515             function mv_back {
1516                 pushd bak
1517                 find . | cpio -pudlm ..
1518                 popd
1519                 rm -rf bak
1520             }
1521             create_rpmbuild_dirs
1522         fi
1523         # build it
1524         build_kernel_ib "${linux}"
1525
1526         if [ -z "$REUSE_SIGNATURE" ]; then
1527             echo "No reuse signature was caculated so not storing the built ofed"
1528         else
1529             # store the resulting RPM build tree for future use
1530             echo "Storing the built ofed for future reuse"
1531             if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1532                                  "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1533                                  "$CAN_LINK_FOR_REUSE"; then
1534                 error "Failed to store OFED RPMS for reuse"
1535                 mv_back
1536                 return 1
1537             fi
1538             # put the stuff we stashed away back
1539             mv_back
1540         fi
1541     fi
1542
1543     pushd "$TOPDIR" >/dev/null
1544     rm -rf kernel-ib-devel
1545     mkdir kernel-ib-devel
1546     cd kernel-ib-devel
1547     # the actual ofed RPMs don't have the -rc$n or -$date string appened that
1548     # might be present on the file
1549     local linuxrelease=$(find_linux_release "$linux")
1550     ofed_version=$(echo $ofed_version |
1551                    sed -re 's/-(20[0-9]{6,6}-[0-9]{4,4}|rc[0-9]*)$//')
1552     local rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version}-${linuxrelease//-/_}.*.rpm)
1553     rpm2cpio -itv < $rpm | cpio -id
1554     CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
1555     popd >/dev/null
1556
1557 }
1558
1559 build_with_srpm() {
1560
1561     if ! $PATCHLESS; then
1562         local kernel_extra_version
1563         if ! kernel_extra_version=$(build_kernel_with_srpm ${STDOUT}); then
1564             fatal 1 "Failed to build the kernel from it's SRPM"
1565         fi
1566
1567         for arch in $BUILD_ARCHS; do
1568             local kernel_devel_rpm
1569             if ! kernel_devel_rpm=$(find_rpm "$TOPDIR/RPMS/$arch/" provides "^$(devel_kernel_name $KERNEL_LUSTRE_NAMING) ="); then
1570                 fatal 1 "Failed to find a kernel development RPM in $TOPDIR/RPMS/$arch/"
1571             fi
1572
1573             # install the -devel RPM in preparation for modules builds
1574             if ! lnxrel="$kernel_extra_version" unpack_linux_devel_rpm \
1575                            "$TOPDIR/RPMS/$arch/$kernel_devel_rpm"; then
1576                 fatal 1 "Could not find the Linux tree in $TOPDIR/RPMS/$arch/$kernel_devel_rpm"
1577             fi
1578         done
1579     else
1580         # need to find and unpack the vendor's own kernel-devel for patchless
1581         # client build
1582         local kernelrpm
1583         if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1584             fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in ${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
1585         fi
1586         if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1587             fatal 1 "Could not find the Linux tree in $kernelrpm"
1588         fi
1589     fi
1590
1591     # ~sigh~  have to make copies of and modify some of the rpm
1592     # infrastructure files so that find-requires can find our unpacked
1593     # kernel-devel artifacts
1594     cp $RPM_HELPERS_DIR/{symset-table,find-requires{,.ksyms}} .
1595     FIND_REQUIRES="$(pwd)/find-requires"
1596     chmod 755 {symset-table,find-requires{,.ksyms}}
1597     local tmp="$(pwd)"
1598     tmp="${tmp//\//\\/}"
1599     ed find-requires <<EOF
1600 1a
1601 set -x
1602 .
1603 /|.*find-requires.ksyms/s/|/| bash -x/
1604 g/ [^ ]*\/\(find-requires\.ksyms\)/s// $tmp\/\1/g
1605 wq
1606 EOF
1607     ed find-requires.ksyms <<EOF
1608 1a
1609 set -x
1610 .
1611 g/\/.*\/\(symset-table\)/s//$tmp\/\1/g
1612 wq
1613 EOF
1614     ed symset-table <<EOF
1615 1a
1616 set -x
1617 .
1618 g/\(\/boot\/\)/s//$tmp\/reused\1/g
1619 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1620 wq
1621 EOF
1622
1623     build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_VERSION" ||
1624         fatal 1 "error building OFED"
1625
1626     if ! $PATCHLESS; then
1627         # only need RDAC for the server
1628         build_rdac "${LINUXOBJ:-$LINUX}" "$RDAC_VERSION" ||
1629             fatal 1 "error building RDAC"
1630     fi
1631
1632     build_mptlinux "${LINUXOBJ:-$LINUX}" "$MPTLINUX_VERSION" ||
1633         fatal 1 "error building mptlinux"
1634
1635     # now build Lustre
1636     if build_lustre "$LINUX" "$LINUXOBJ"; then
1637         # the build worked.  resolve any symlinked files (i.e. from reuse)
1638         # in RPMS/$arch to real files so that that that huge mess of
1639         # complication known as LTS can copy them yet somewhere else.
1640         # is it any wonder this whole process is so damn so?  anyone ever
1641         # heard of hardlinks?  it this cool new thing that allows you save
1642         # tons of time and space by creating... well you can go read about
1643         # them if you have not heard about them yet.
1644         # can i say how much the implemenation of all of this really impedes
1645         # RPM reuse?
1646         pushd RPMS/$TARGET_ARCH
1647             for file in *; do
1648                 if [ -h $file ]; then
1649                     cp $file foo
1650                     mv foo $file
1651                 fi
1652             done
1653         popd
1654     else
1655         return 1
1656     fi
1657
1658 }
1659
1660 create_rpmbuild_dirs() {
1661
1662     [ -d RPMS ] || mkdir RPMS
1663     for arch in $BUILD_ARCHS; do
1664         if [[ $arch = i?86 ]]; then
1665             # some stupidity in the sles11 kernel spec requires an RPMS/i386
1666             # even if the target arch is i686
1667             [ -d RPMS/i386 ] || mkdir RPMS/i386
1668         fi
1669         [ -d RPMS/$arch ] || mkdir RPMS/$arch
1670     done
1671     [ -d BUILD ] || mkdir BUILD
1672     [ -d SOURCES ] || mkdir SOURCES
1673     [ -d SPECS ] || mkdir SPECS
1674     [ -d SRPMS ] || mkdir SRPMS
1675
1676 }
1677
1678 new_list() {
1679
1680     echo ""
1681
1682 }
1683
1684 add_list() {
1685     local list="$1"
1686     local item="$2"
1687
1688     echo "$list $item"
1689
1690 }
1691
1692 is_list_member() {
1693     local list="$1"
1694     local item="$2"
1695
1696     [[ $list\  == *\ $item\ * ]]
1697
1698 }
1699
1700 #########################################################################
1701 # Generate a backtrace through the call stack.
1702 #
1703 # Input: None
1704 # Output: None
1705 #########################################################################
1706 backtrace() {
1707     local strip=${1:-1}
1708
1709     local funcname="" sourcefile="" lineno="" n
1710
1711     echo "Call stack: (most recent first)"
1712     for (( n = $strip ; n < ${#FUNCNAME[@]} ; ++n )) ; do
1713         funcname=${FUNCNAME[$n - 1]}
1714         sourcefile=$(basename ${BASH_SOURCE[$n]})
1715         lineno=${BASH_LINENO[$n - 1]}
1716         if [ $n = 1 ]; then
1717             let lineno-=11
1718         fi
1719         # Display function arguments
1720         if [[ ! -z "${BASH_ARGV[@]}" ]]; then
1721             local args newarg j p=0
1722             for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do
1723                 newarg=${BASH_ARGV[$j + $p - 1]}
1724                 args="${args:+${args} }'${newarg}'"
1725             done
1726             let p+=${BASH_ARGC[$n - 1]}
1727         fi
1728         echo "  ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}"
1729     done
1730
1731     echo
1732     echo "BEGIN BACKTRACE"
1733
1734     #echo ${BASH_LINENO[*]}
1735     #echo ${BASH_SOURCE[*]}
1736     #echo ${FUNCNAME[*]}
1737     local i=$((${#FUNCNAME[@]} - 1))
1738     while [ $i -ge 0 ]; do
1739         local lineno=${BASH_LINENO[$i]}
1740         if [ $i = 0 ]; then
1741             let lineno-=11
1742         fi
1743         local SOURCELINE="${BASH_SOURCE[$i + 1]}:${lineno}"
1744         # Can't figure out how to get function args from other frames...
1745         local FUNCTION="${FUNCNAME[$i]}()"
1746         echo "$SOURCELINE:$FUNCTION"
1747         i=$((i - 1))
1748     done
1749
1750     echo "END BACKTRACE"
1751
1752     echo $BACKTRACE
1753
1754 }
1755
1756 seen_list=$(new_list)
1757 trap 'set +x;
1758 echo "An unexpected error has occurred at ${BASH_SOURCE[0]##*/}:$((LINENO-1)).
1759 Unfortunately the above line number in the message may or may not be correct,
1760 but details have been send to the lbuild maintainer.  Attempting to continue."; (echo "Untrapped error"
1761 echo
1762 # have we seen this one
1763 echo "checking seen list for ${BASH_SOURCE[0]}:${BASH_LINENO[0]}"
1764
1765 if is_list_member "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"; then
1766   echo "seen this one already"
1767 else
1768   seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
1769 fi
1770 backtrace
1771 echo
1772 echo "Environment:"
1773 set
1774 ) | mail -s "Untrapped error at ${BASH_SOURCE[0]##*/}:$((LINENO-15)) on $HOSTNAME" brian@sun.com >&2; set $xtrace' ERR
1775 set -E
1776
1777 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1778
1779 options=$(getopt -o d:D:h -l kerneltree:,distro:,kernelrpm:,reusebuild:,patchless,ldiskfs,ccache,reuse:,norpm,disable-datestamp,external-patches:,timestamp:,extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,ofed-version:,publish,release,set-value:,src,stage:,tag:,target:,target-archs:,with-linux:,xen,enable-mptlinux,enable-rdac -- "$@")
1780
1781 if [ $? != 0 ]; then
1782     usage 1
1783 fi
1784
1785 eval set -- "$options"
1786
1787 while [ "$1" ]; do
1788     case "$1" in
1789         '')
1790             usage 1
1791             ;;
1792         --ccache)
1793             CCACHE='ccache'
1794             shift
1795             ;;
1796         -d)
1797             CVSROOT=$2
1798             shift 2
1799             ;;
1800         -D)
1801             DATE=$2
1802             shift 2
1803             ;;
1804         --external-patches)
1805             EXTERNAL_PATCHES=$2
1806             shift 2
1807             ;;
1808         --extraversion)
1809             EXTRA_VERSION=$2
1810             shift 2
1811             ;;
1812         --help | -h)
1813             usage 0
1814             ;;
1815         --kerneldir)
1816             KERNELDIR=$2
1817             shift 2
1818             ;;
1819         --kerneltree)
1820             if ! KERNELTREE=$(canon_path "$2"); then
1821                 fatal 1 "Could not determine the canonical location of $2"
1822             fi
1823             shift 2
1824             ;;
1825         --linux | --with-linux)
1826             if ! LINUX=$(canon_path "$2"); then
1827                 fatal 1 "Could not determine the canonical location of $2"
1828             fi
1829             shift 2
1830             ;;
1831         --distro)
1832             DISTRO=$2
1833             shift 2
1834             ;;
1835         --reuserpm)
1836             REUSERPM=$2
1837             shift 2
1838             ;;
1839         --reusebuild)
1840             if ! REUSEBUILD=$(canon_path "$2"); then
1841                 fatal 1 "Could not determine the canonical location of $2"
1842             fi
1843             shift 2
1844             ;;
1845         --norpm)
1846             NORPM=true
1847             shift
1848             ;;
1849         --ldiskfs)
1850             LDISKFSRPM=true
1851             shift
1852             ;;
1853         --patchless)
1854             PATCHLESS=true
1855             shift
1856             ;;
1857         --kernelrpm)
1858             if ! KERNELRPMSBASE=$(canon_path "$2"); then
1859                 fatal 1 "Could not determine the canonical location of $2"
1860             fi
1861             shift 2
1862             ;;
1863         --timestamp)
1864             TIMESTAMP=$2
1865             shift 2
1866             ;;
1867         --lustre)
1868             LUSTRE=$2
1869             shift 2
1870             ;;
1871         --nodownload)
1872             DOWNLOAD=false
1873             shift 1
1874             ;;
1875         --nosrc)
1876             DO_SRC=false
1877             shift 1
1878             ;;
1879         --ofed-version)
1880             OFED_VERSION="$2"
1881             shift 2
1882             ;;
1883         --publish)
1884             shift
1885             ;;
1886         --release)
1887             RELEASE=true
1888             shift
1889             ;;
1890         --src)
1891             DO_SRC=true
1892             shift 1
1893             ;;
1894         --stage)
1895             STAGEDIR=$2
1896             shift 2
1897             ;;
1898         --tag)
1899             TAG=$2
1900             shift 2
1901             ;;
1902         --target)
1903             TARGET=$2
1904             shift 2
1905             ;;
1906         --target-archs)
1907             TARGET_ARCHS=$2
1908             shift 2
1909             ;;
1910         --disable-datestamp)
1911             USE_DATESTAMP=
1912             shift
1913             ;;
1914         --xen)
1915             XEN=true
1916             shift
1917             ;;
1918         --set-value)
1919             eval $2
1920             shift 2
1921             ;;
1922         --enable-mptlinux)
1923             BUILD_MPTLINUX=true
1924             shift
1925             ;;
1926         --enable-rdac)
1927             BUILD_RDAC=true
1928             shift
1929             ;;
1930         --)
1931             shift
1932             # there are actually some lustre configure flags that we need to
1933             # handle ourselves (but we still give them to configure)
1934             if [[ \ $@\  == *\ --disable-tests\ * ]]; then
1935                 LUSTRE_TESTS=false
1936             fi
1937             CONFIGURE_FLAGS=$@
1938             CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-liblustre --enable-liblustre-tests"
1939             break
1940             ;;
1941         *)
1942             usage 1 "Unrecognized option: $1"
1943             ;;
1944     esac
1945 done
1946
1947 check_options
1948
1949 unpack_lustre
1950
1951 load_target
1952
1953 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
1954     download_ofed
1955     unpack_ofed || fatal 1 "Error unpacking OFED tarball"
1956 fi
1957
1958 if $BUILD_MPTLINUX && [ -n "$MPTLINUX_VERSION" -a "$MPTLINUX_VERSION" != "inkernel" ]; then
1959     unpack_mptlinux || fatal 1 "Error unpacking MPTLINUX distribution"
1960 fi
1961
1962 # make sure the RPM build environment is set up
1963 create_rpmbuild_dirs
1964
1965 if $BUILD_RDAC && [ -n "$RDAC_VERSION" -a "$RDAC_VERSION" != "inkernel" ]; then
1966     # we don't actually need to unpack this.  just put it in the SOURCES dir
1967     #unpack_rdac || fatal 1 "Error unpacking RDAC tarball"
1968     cp "$KERNELTREE/rdac-LINUX-${RDAC_VERSION}-source.tar.gz" ${TOPDIR}/SOURCES/ ||
1969         fatal 1 "Error copying RDAC source tarball to RPM SOURCES dir"
1970 fi
1971
1972 # if an unpacked kernel source tree was given on the command line
1973 # just build lustre with it (nothing distro kernel specific here)
1974 if [ -n "$LINUX" ]; then
1975     build_mptlinux "${LINUXOBJ:-$LINUX}" "$MPTLINUX_VERSION" ||
1976         fatal 1 "error building mptlinux"
1977     build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_VERSION" ||
1978         fatal 1 "error building OFED"
1979     if ! $PATCHLESS; then
1980         build_rdac "${LINUXOBJ:-$LINUX}" "$RDAC_VERSION" ||
1981             fatal 1 "error building RDAC"
1982     fi
1983     build_lustre "$LINUX" "$LINUXOBJ"
1984 else
1985     if [ -f "${0%/*}/lbuild-$DISTRO" ]; then
1986         source ${0%/*}/lbuild-$DISTRO
1987
1988         build_with_srpm || fatal 1 "Failed to build_with_srpm"
1989     else
1990         EXTRA_VERSION_DELIMITER=${EXTRA_VERSION_DELIMITER:-"-"}
1991         source ${0%/*}/lbuild.old_school
1992
1993         old_school_download_kernel
1994
1995         build_success=false
1996         if $PATCHLESS; then
1997             patchless_build_sequence && build_success=true
1998         else
1999             [ "$DISTRO" = "sles9" ] && build_sequence_rpm_reuse && build_success=true
2000             if ! $build_success; then
2001                 build_sequence_reuse && build_success=true
2002                 if ! $build_success; then
2003                     build_sequence && build_success=true
2004                     if $build_success; then
2005                         store_for_reuse || echo "Cannot store for future reuse"
2006                     fi
2007                 fi
2008             fi
2009         fi
2010         ( $build_success ) || fatal 1 "Cannot build lustre"
2011     fi
2012 fi
2013
2014 stage