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