Whamcloud - gitweb
Merge with old CVS version; this should now contain the best of old CVS and 20051107...
[fs/lustre-release.git] / build / lbuild
1 #!/bin/sh
2
3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
4
5 TOPDIR=$PWD
6
7 # CVSROOT is inherited from the environment
8 KERNELDIR=
9 LINUX=
10 LUSTRE=
11 RELEASE=0
12 DO_SRC=0
13 DOWNLOAD=1
14 TAG=
15 TARGET=
16 TARGET_ARCHS=
17 CONFIGURE_FLAGS=
18 EXTERNAL_PATCHES=
19 EXTRA_VERSION=
20 STAGEDIR=
21
22 # from target file
23 KERNEL=
24 SERIES=
25 CONFIG=
26 VERSION=
27
28 RHBUILD=0
29 SUSEBUILD=0
30 LINUX26=0
31 SUSEBUILD=0
32
33 BASE_ARCHS=
34 BIGMEM_ARCHS=
35 BOOT_ARCHS=
36 JENSEN_ARCHS=
37 SMP_ARCHS=
38 BIGSMP_ARCHS=
39 PSERIES64_ARCHS=
40 UP_ARCHS=
41
42 DATE=$(date)
43
44 USE_DATESTAMP=1
45 RPMBUILD=
46
47 export CC=${CC:-gcc}
48
49 # Readlink is not present on some older distributions: emulate it.
50 readlink() {
51     local path=$1 ll
52
53     if [ -L "$path" ]; then
54         ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
55         echo "${ll/* -> }"
56     else
57         return 1
58     fi
59 }
60
61 cleanup()
62 {
63     true
64 }
65
66 error()
67 {
68     [ "$1" ] && echo -e "\n${0##*/}: $1"
69 }
70
71 fatal()
72 {
73     cleanup
74     error "$2"
75     exit $1
76 }
77
78 is_release()
79 {
80     (( $RELEASE )) || return 0
81 }
82
83 list_targets()
84 {
85     echo -n "Available targets:"
86     for target in $TOPDIR/lustre/lustre/kernel_patches/targets/*.target ; do
87         target_file=${target##*/}
88         echo -n " ${target_file%%.target}"
89     done
90     echo
91 }
92
93 usage()
94 {
95     cat <<EOF
96 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
97
98   -d CVSROOT
99     Specifies the CVS Root to use when pulling files from CVS.  The
100     environment variable \$CVSROOT is used if this option is not
101     present.
102
103   --external-patches=EXTERNAL_PATCHES
104     Directory similar to lustre/lustre/kernel_patches/ that lbuild should
105     look for seres and config files in before looking in the lustre
106     tree.
107
108   --extraversion=EXTRAVERSION
109     Text to use for the rpm release and kernel extraversion.
110
111   --kerneldir=KERNELDIR
112     Directory containing Linux source tarballs referenced by target
113     files.
114
115   --linux=LINUX
116     Directory of Linux kernel sources.  When this option is used, only
117     Lustre modules and userspace are built.
118
119   --lustre=LUSTRE
120     Path to an existing lustre source tarball to use instead of
121     pulling from CVS.
122
123   --nodownload
124     Do not try to download a kernel from ftp.lustre.org
125
126   --nosrc
127     Do not build a .src.rpm, a full kernel patch, or a patched kernel
128     tarball.
129
130   --publish
131     Unused.
132
133   --release
134     Specifies that the files generated do not include timestamps, and
135     that this is an official release.
136
137   --src
138     Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
139
140   --stage=DIR
141     Directory used to stage packages for release.  RPMs will be placed
142     more or less in DIR/<target>-<arch>, and the tarball will be
143     placed in DIR.
144
145   --tag=TAG
146     A CVS branch/tag name to build from when pulling from CVS.
147
148   --target=TARGET
149     The name of the target to build.  The available targets are listed
150     below.
151
152   --target-archs=TARGET_ARCHS
153     A (space delimited) list of architectures to build.  By default,
154     all of the archs supported by the TARGET will be built, in
155     addition to a .src.rpm.  This option can limit those, for machines
156     that can only build certain archs or if you only want a certain
157     arch built (for testing, or a one-off kernel).
158
159     Also note that by using a non-"base" arch (eg, i386) only kernels
160     will be built - there will be no lustre-lite-utils package.
161
162   --disable-datestamp
163     Prevents the datestamp flag (-D) from being passed to cvs for 
164     checkouts. This is a workaround for a problem encountered when 
165     using lbuild with tinderbox.
166
167 EOF
168
169 #   list_targets
170
171     fatal "$1" "$2"
172 }
173
174 check_options()
175 {
176     if [ "$LUSTRE" ] ; then
177         [ -r "$LUSTRE" ] || \
178             usage 1 "Could not find Lustre source tarball '$LUSTRE'."
179     else
180         [ "$CVSROOT" ] || \
181             usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
182         [ "$TAG" ] || \
183             usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
184     fi
185
186     if [ -z "$LINUX" ] ; then
187         [ "$KERNELDIR" ] || \
188             usage 1 "A kernel directory must be specified with --kerneldir."
189
190         [ -d "$KERNELDIR" ] || \
191             usage 1 "$KERNELDIR is not a directory."
192
193         if ! (( $RELEASE )) ; then
194             [ "$TAG" ] || \
195                 usage 1 "When building a snapshot, a tag name must be used."
196         fi
197
198         [ "$TARGET" ] || usage 1 "A target must be specified with --target."
199 #       TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
200 #       [ -r "$TARGET_FILE" ] || \
201 #               usage 1 "Target '$TARGET' was not found."
202     fi
203
204     case $TARGET in
205         2.6-rhel4)
206             CANONICAL_TARGET="rhel-2.6"
207             ;;
208         2.6-suse)
209             CANONICAL_TARGET="sles-2.6"
210             ;;
211         hp_pnnl-2.4)
212             CANONICAL_TARGET="hp-pnnl-2.4"
213             ;;
214         2.6-vanilla \
215             | suse-2.4.21-2 \
216             | rh-2.4 \
217             | rhel-2.4 \
218             | sles-2.4)
219                 CANONICAL_TARGET="$TARGET"
220                 ;;
221     esac
222
223     TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M")
224
225     RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
226     if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
227         RPMBUILD=$(which rpm 2>/dev/null | head -1)
228         if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
229             usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
230         fi
231     fi
232 }
233
234 uniqify()
235 {
236     echo $(echo "$*" | xargs -n 1 | sort -u)
237 }
238
239 build_tarball() {
240     local TARGET=$1
241     local SRPM=$2
242
243     if [ "$TARGET" = "rhel-2.6" -o "$TARGET" = "rhel-2.4" ]; then
244         local SPEC=""
245         if [ "$TARGET" = "rhel-2.6" ]; then
246             SPEC=kernel-2.6.spec
247             OLDCONFIG=nonint_oldconfig
248         elif [ "$TARGET" = "rhel-2.4" ]; then
249             SPEC=kernel-2.4.spec
250             OLDCONFIG=oldconfig
251         fi
252
253         RPMTOPDIR=$(mktemp -d $KERNELDIR/rpm_XXXXXX)
254         mkdir $RPMTOPDIR/BUILD/
255         rpm -ivh $KERNELDIR/$SRPM --define "_topdir $RPMTOPDIR" || \
256             { rm -rf $RPMTOPDIR; fatal 1 "Error installing kernel SRPM."; }
257         $RPMBUILD -bp --nodeps --target i686 $RPMTOPDIR/SPECS/$SPEC --define "_topdir $RPMTOPDIR"
258         pushd $RPMTOPDIR/BUILD/kernel-${lnxmaj}/linux-${lnxmaj} && {
259             make mrproper
260             cp configs/kernel-${lnxmaj}-i686-smp.config .config
261             if ! make $OLDCONFIG > /dev/null; then
262                 fatal 1 "error trying to make $OLDCONFIG while building a tarball from SRPM."
263             fi
264             make include/linux/version.h 
265             rm -f .config
266             cd ..
267             tar cjf $KERNEL_FILE linux-${lnxmaj}
268         }
269         popd
270         rm -rf $RPMTOPDIR
271     fi
272 }
273
274 download_and_build_tarball() {
275     local TARGET=$1
276     local KERNEL_FILE=$2
277
278     local SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
279
280     echo "Downloading http://ftp.lustre.org/kernels/$TARGET/old/$SRPM..."
281     if ! wget -nv "http://ftp.lustre.org/kernels/$TARGET/old/$SRPM" \
282         -O "$KERNELDIR/$SRPM" ; then
283         fatal 1 "Could not download target $TARGET's kernel SRPM $SRPM from ftp.lustre.org."
284     fi
285
286     build_tarball $TARGET $SRPM
287 }
288
289 load_target()
290 {
291     EXTRA_VERSION_save="$EXTRA_VERSION"
292     for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
293         TARGET_FILE="$patchesdir/targets/$TARGET.target"
294         [ -r "$TARGET_FILE" ] && break
295     done
296     [ -r "$TARGET_FILE" ] || \
297         fatal 1 "Target $TARGET was not found."
298
299     echo "Loading target config file $TARGET.target..."        
300
301     . "$TARGET_FILE"
302
303     [ "$KERNEL"  ] || fatal 1 "Target $TARGET did not specify a kernel."
304 #    [ "$SERIES"  ] || fatal 1 "Target $TARGET did not specify a kernel patch series."
305 #    [ "$CONFIG"  ] || fatal 1 "Target $TARGET did not specify a kernel config."
306     [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify a kernel version."
307
308     if [ "$KERNELDIR" ] ; then
309         KERNEL_FILE="$KERNELDIR/$KERNEL"
310         if [ ! -r "$KERNELDIR/$KERNEL" ] ; then
311             # see if we have an SRPM we can build a tarball for
312             KERNEL_SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
313             if [ -r "$KERNELDIR/$KERNEL_SRPM" ] ; then
314                 build_tarball $CANONICAL_TARGET $KERNEL_SRPM
315             else
316                 if (( $DOWNLOAD )) ; then
317                     echo "Downloading http://ftp.lustre.org/kernels/$CANONICAL_TARGET/old/$KERNEL..."
318                     if ! wget -nv "http://ftp.lustre.org/kernels/$CANONICAL_TARGET/old/$KERNEL" -O "$KERNELDIR/$KERNEL" ; then
319                         # see if we can do it with an SRPM from the download site
320                         download_and_build_tarball $CANONICAL_TARGET $KERNEL_FILE
321                     fi
322                 else
323                     fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
324                 fi
325             fi
326         fi
327     fi
328
329     if [ "$SERIES" ] ; then
330         for series in $SERIES ; do
331             for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
332                 [ -r "$patchesdir/series/$series" ] && continue 2
333             done
334             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."
335         done
336     fi
337
338     CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/$CONFIG"
339     [ -r "$CONFIG_FILE" ] || \
340         fatal 1 "Target $TARGET's config file $CONFIG missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
341
342     if [ "$EXTRA_VERSION_save" ] ; then
343         EXTRA_VERSION="$EXTRA_VERSION_save"
344     elif ! (( $RELEASE )) ; then
345         #remove the @VERSION@ (lustre version)
346         EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
347         EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
348     fi
349     # EXTRA_VERSION=${EXTRA_VERSION//-/_}
350
351     ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
352
353     BUILD_ARCHS=
354     for arch in $(uniqify "$ALL_ARCHS") ; do
355         if [ -z "$TARGET_ARCHS" ] || echo "$TARGET_ARCHS" | grep "$arch" >/dev/null 2>/dev/null ; then
356             BUILD_ARCHS="$BUILD_ARCHS $arch"
357         fi
358     done
359     [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
360     echo "Building for: $BUILD_ARCHS"
361 }
362
363 tarflags()
364 {
365     case "$1" in
366         '')
367             fatal 1 "tarflags(): File name argument missing."
368             ;;
369         *.tar.gz | *.tgz)
370             echo 'zxf'
371             ;;
372         *.tar.bz2)
373             echo 'jxf'
374             ;;
375         *.tar)
376             echo 'xf'
377             ;;
378         *)
379             fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
380             ;;
381     esac
382 }
383
384 untar()
385 {
386     echo "Untarring ${1##*/}..."
387     tar $(tarflags "$1") "$1"
388 }
389
390 unpack_lustre()
391 {
392     DIRNAME="lustre-$TAG-$TIMESTAMP"
393     if [ "$LUSTRE" ] ; then
394         untar "$LUSTRE"
395         [ -d lustre ] || ln -sf lustre* lustre
396     else
397         if [ "$USE_DATESTAMP" ]; then
398             DATESTAMP="-D '$DATE'"
399         else
400             DATESTAMP=""
401         fi            
402
403         cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
404             fatal 1 "There was an error checking out toplevel Lustre from CVS."
405         pushd "$DIRNAME" > /dev/null
406         ./lustrecvs "$TAG" || \
407             fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
408         echo "Creating lustre tarball..."
409         sh autogen.sh || fatal 1 "There was an error running autogen.sh."
410         ./configure --disable-{modules,utils,liblustre,tests,doc} || \
411             fatal 1 "There was an error running ./configure to create makefiles."
412         make dist || fatal 1 "There was an error running 'make dist'."
413         popd > /dev/null
414         fname=`basename $DIRNAME/lustre-*.tar.gz`
415         cp $DIRNAME/$fname . || fatal 1 "There was an error copying lustre tarball."
416         LUSTRE="$PWD/$fname"
417         ln -sf "$DIRNAME" lustre
418     fi
419 }
420
421 unpack_linux()
422 {
423     untar "$KERNEL_FILE"
424     [ -d linux ] || ln -sf linux* linux
425 }
426
427 patch_linux()
428 {
429     [ "$SERIES" ] || return 0
430     FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
431     [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
432     pushd linux >/dev/null
433     for series in $SERIES ; do
434         echo -n "Applying series $series:"
435         for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
436             [ -r "$patchesdir/series/$series" ] || continue
437             SERIES_FILE="$patchesdir/series/$series"
438             for patch in $(<"$SERIES_FILE") ; do
439                 echo -n " $patch"
440                 PATCH_FILE="$patchesdir/patches/$patch"
441                 [ -r "$PATCH_FILE" ] || \
442                     fatal 1 "Patch $patch does not exist in Lustre tree."
443                 cat "$PATCH_FILE" >> "$FULL_PATCH" || \
444                     fatal 1 "Error adding patch $patch to full patch."
445                 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
446             done
447             break
448         done
449         echo
450     done
451     popd >/dev/null
452     echo "Full patch has been saved in ${FULL_PATCH##*/}."
453     echo "Replacing .config files..."
454     [ -d linux/configs ] || mkdir linux/configs || \
455         fatal 1 "Error creating configs directory."
456     rm -f linux/configs/*
457     copysuccess=0
458     for patchesdir in "$EXTERNAL_PATCHES" "lustre/lustre/kernel_patches" ; do
459         [ "$patchesdir" ] && \
460             cp -v $patchesdir/kernel_configs/kernel-${VERSION}-${TARGET}*.config linux/configs/ >/dev/null && copysuccess=1
461     done
462     [ "$copysuccess" = "1" ] || \
463         fatal 1 "Error copying in kernel configs."
464 }
465
466 pack_linux()
467 {
468     TARBALL="$(readlink linux)-$EXTRA_VERSION.tar.gz"
469     echo "Creating patched linux tarball $TARBALL..."
470     tar zcf "$TARBALL" "$(readlink linux)" \
471         --exclude "CVS" --exclude ".cvsignore" || \
472         --exclude "*.orig" --exclude "*~" --exclude "*.rej" || \
473         fatal 1 "Error creating patched Linux tarball."
474 }
475
476 clean_linux()
477 {
478     [ -d linux ] || return 0
479     echo "Cleaning linux..."
480     [ -L linux ] && rm -rf $(readlink linux)
481     rm -rf linux
482 }
483
484 prep_kernel_build()
485 {
486     # make .spec file
487     ENABLE_INIT_SCRIPTS=""
488     sed \
489         -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
490         -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
491         -e "s^@BIGSMP_ARCHS@^$BIGSMP_ARCHS^g" \
492         -e "s^@BOOT_ARCHS@^$BOOT_ARCHS^g" \
493         -e "s^@CONFIGURE_FLAGS@^$CONFIGURE_FLAGS^g" \
494         -e "s^@ENABLE_INIT_SCRIPTS@^$ENABLE_INIT_SCRIPTS^g" \
495         -e "s^@JENSEN_ARCHS@^$BOOT_ARCHS^g" \
496         -e "s^@KERNEL_EXTRA_VERSION@^$EXTRA_VERSION^g" \
497         -e "s^@KERNEL_RELEASE@^${EXTRA_VERSION//-/_}^g" \
498         -e "s^@KERNEL_SOURCE@^$KERNEL^g" \
499         -e "s^@KERNEL_VERSION@^$VERSION^g" \
500         -e "s^@LINUX26@^$LINUX26^g" \
501         -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
502         -e "s^@LUSTRE_TARGET@^$TARGET^g" \
503         -e "s^@PSERIES64_ARCHS@^$PSERIES64_ARCHS^g" \
504         -e "s^@RHBUILD@^$RHBUILD^g" \
505         -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
506         -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
507         -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
508         -e "s^@UP_ARCHS@^$UP_ARCHS^g" \
509         < $TOPDIR/lustre/build/lustre-kernel-2.4.spec.in \
510         > lustre-kernel-2.4.spec
511     [ -d SRPMS ] || mkdir SRPMS
512     [ -d RPMS ] || mkdir RPMS
513     [ -d BUILD ] || mkdir BUILD
514     [ -d SOURCES ] || mkdir SOURCES
515     for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
516         suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} \
517         sles8-{pre,post,postun,update_{INITRD_MODULES,rcfile_setting}}.sh ; do
518         cp $TOPDIR/lustre/build/$script SOURCES
519     done
520     cp "$LUSTRE" "$KERNEL_FILE" SOURCES
521     if [ "$EXTERNAL_PATCHES" -a -d "$EXTERNAL_PATCHES" ] ; then
522         tar zcf SOURCES/external-patches.tar.gz -C "$EXTERNAL_PATCHES" series targets patches kernel_configs
523     else
524         touch SOURCES/external-patches.tar.gz
525     fi
526 }
527
528 clean_lustre()
529 {
530     [ -d lustre ] || return 0
531     echo "Cleaning Lustre..."
532     [ -L lustre ] && rm -rf $(readlink lustre)
533     rm -rf lustre
534 }
535
536 build_kernel()
537 {
538     echo "Building kernel + Lustre RPMs for: $BUILD_ARCHS..."
539     targets=
540     for arch in $BUILD_ARCHS ; do
541         targets="--target $arch $targets"
542     done
543
544     $RPMBUILD $targets -bb lustre-kernel-2.4.spec \
545         --define "_topdir $TOPDIR" || \
546         fatal 1 "Error building rpms for $BUILD_ARCHS."
547
548     if (( $DO_SRC )) ; then
549         $RPMBUILD -bs lustre-kernel-2.4.spec \
550             --define "_topdir $TOPDIR" || \
551             fatal 1 "Error building .src.rpm."
552     fi
553 }
554
555 build_lustre()
556 {
557     [ -d SRPMS ] || mkdir SRPMS
558     [ -d RPMS ] || mkdir RPMS
559     [ -d BUILD ] || mkdir BUILD
560     [ -d SOURCES ] || mkdir SOURCES
561
562     cp "$LUSTRE" SOURCES
563
564     pushd lustre >/dev/null
565
566     echo "Building Lustre RPMs for: $BUILD_ARCHS..."
567     targets=
568     for arch in $BUILD_ARCHS ; do
569         targets="--target $arch $targets"
570     done
571
572     ./configure "--with-linux=${LINUX}" ${CONFIGURE_FLAGS}
573
574     $RPMBUILD $targets -bb build/lustre.spec \
575         --define "_topdir $TOPDIR" || \
576         fatal 1 "Error building rpms for $BUILD_ARCHS."
577
578     popd >/dev/null
579 }
580
581 stage()
582 {
583     [ "$STAGEDIR" ] || return 0
584
585     for arch in $BUILD_ARCHS ; do
586         rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
587         echo "${0##*/}: Copying RPMs into ${rpmdir}"
588         mkdir -p "${rpmdir}"
589         cp -v RPMS/${arch}/*.rpm "${rpmdir}"
590         if [ -d RPMS/noarch ] ; then
591             cp -v RPMS/noarch/*.rpm "${rpmdir}"
592         fi
593     done
594
595     cp -v "$LUSTRE" "$STAGEDIR"
596 }
597
598 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
599
600 options=$(getopt -o d:D:h -l disable-datestamp,external-patches:,extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,publish,release,stage:,tag:,target:,target-archs:,with-linux: -- "$@")
601
602 if [ $? != 0 ] ; then
603     usage 1
604 fi
605
606 eval set -- "$options"
607     
608 while [ "$1" ] ; do
609     case "$1" in
610         '')
611             usage 1
612             ;;
613         -d)
614             CVSROOT=$2
615             shift 2
616             ;;
617         -D)
618             DATE=$2
619             shift 2
620             ;;
621         --external-patches)
622             EXTERNAL_PATCHES=$2
623             shift 2
624             ;;
625         --extraversion)
626             EXTRA_VERSION=$2
627             shift 2
628             ;;
629         --help | -h)
630             usage 0
631             ;;
632         --kerneldir)
633             KERNELDIR=$2
634             shift 2
635             ;;
636         --linux | --with-linux)
637             LINUX=$2
638             shift 2
639             ;;
640         --lustre)
641             LUSTRE=$2
642             shift 2
643             ;;
644         --nodownload)
645             DOWNLOAD=0
646             shift 1
647             ;;
648         --nosrc)
649             DO_SRC=0
650             shift 1
651             ;;
652         --publish)
653             shift
654             ;;
655         --release)
656             RELEASE=1
657             shift
658             ;;
659         --src)
660             DO_SRC=1
661             shift 1
662             ;;
663         --stage)
664             STAGEDIR=$2
665             shift 2
666             ;;
667         --tag)
668             TAG=$2
669             shift 2
670             ;;
671         --target)
672             TARGET=$2
673             shift 2
674             ;;
675         --target-archs)
676             TARGET_ARCHS=$2
677             shift 2
678             ;;
679         --disable-datestamp)
680             USE_DATESTAMP=
681             shift
682             ;;
683         --)
684             shift
685             CONFIGURE_FLAGS=$@
686             break
687             ;; 
688         *)
689             usage 1 "Unrecognized option: $1"
690             ;;
691     esac
692 done
693
694 check_options
695
696 unpack_lustre
697
698 # prep_build needs the .spec.in from the lustre source
699 if [ -z "$LINUX" ] ; then
700     load_target
701
702     if (( $DO_SRC )) ; then
703         unpack_linux
704         patch_linux
705         pack_linux
706         clean_linux
707     fi
708
709     prep_kernel_build
710     clean_lustre
711
712     build_kernel
713 else
714     build_lustre
715 fi
716
717 stage