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