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