Whamcloud - gitweb
Lustre support needed to be able to build a 2.6 patchless kernel. This
[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             | 2.6-patchless)
220                 CANONICAL_TARGET="$TARGET"
221                 ;;
222     esac
223
224     TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M")
225
226     RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
227     if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
228         RPMBUILD=$(which rpm 2>/dev/null | head -1)
229         if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
230             usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
231         fi
232     fi
233 }
234
235 uniqify()
236 {
237     echo $(echo "$*" | xargs -n 1 | sort -u)
238 }
239
240 build_tarball() {
241     local TARGET=$1
242     local SRPM=$2
243
244     if [ "$TARGET" = "rhel-2.6" -o "$TARGET" = "rhel-2.4" ]; then
245         local SPEC=""
246         if [ "$TARGET" = "rhel-2.6" ]; then
247             SPEC=kernel-2.6.spec
248             OLDCONFIG=nonint_oldconfig
249         elif [ "$TARGET" = "rhel-2.4" ]; then
250             SPEC=kernel-2.4.spec
251             OLDCONFIG=oldconfig
252         fi
253
254         RPMTOPDIR=$(mktemp -d $KERNELDIR/rpm_XXXXXX)
255         mkdir $RPMTOPDIR/BUILD/
256         rpm -ivh $KERNELDIR/$SRPM --define "_topdir $RPMTOPDIR" || \
257             { rm -rf $RPMTOPDIR; fatal 1 "Error installing kernel SRPM."; }
258         $RPMBUILD -bp --nodeps --target i686 $RPMTOPDIR/SPECS/$SPEC --define "_topdir $RPMTOPDIR"
259         pushd $RPMTOPDIR/BUILD/kernel-${lnxmaj}/linux-${lnxmaj} && {
260             make mrproper
261             cp configs/kernel-${lnxmaj}-i686-smp.config .config
262             if ! make $OLDCONFIG > /dev/null; then
263                 fatal 1 "error trying to make $OLDCONFIG while building a tarball from SRPM."
264             fi
265             make include/linux/version.h 
266             rm -f .config
267             cd ..
268             tar cjf $KERNEL_FILE linux-${lnxmaj}
269         }
270         popd
271         rm -rf $RPMTOPDIR
272     fi
273 }
274
275 download_and_build_tarball() {
276     local TARGET=$1
277     local KERNEL_FILE=$2
278
279     local SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
280
281     echo "Downloading http://ftp.lustre.org/kernels/$TARGET/old/$SRPM..."
282     if ! wget -nv "http://ftp.lustre.org/kernels/$TARGET/old/$SRPM" \
283         -O "$KERNELDIR/$SRPM" ; then
284         fatal 1 "Could not download target $TARGET's kernel SRPM $SRPM from ftp.lustre.org."
285     fi
286
287     build_tarball $TARGET $SRPM
288 }
289
290 load_target()
291 {
292     EXTRA_VERSION_save="$EXTRA_VERSION"
293     for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
294         TARGET_FILE="$patchesdir/targets/$TARGET.target"
295         [ -r "$TARGET_FILE" ] && break
296     done
297     [ -r "$TARGET_FILE" ] || \
298         fatal 1 "Target $TARGET was not found."
299
300     echo "Loading target config file $TARGET.target..."        
301
302     . "$TARGET_FILE"
303
304     [ "$KERNEL"  ] || fatal 1 "Target $TARGET did not specify a kernel."
305     [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify a kernel version."
306
307     if [ "$KERNELDIR" ] ; then
308         KERNEL_FILE="$KERNELDIR/$KERNEL"
309         if [ ! -r "$KERNELDIR/$KERNEL" ] ; then
310             # see if we have an SRPM we can build a tarball for
311             KERNEL_SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
312             if [ -r "$KERNELDIR/$KERNEL_SRPM" ] ; then
313                 build_tarball $CANONICAL_TARGET $KERNEL_SRPM
314             else
315                 if (( $DOWNLOAD )) ; then
316                     echo "Downloading http://ftp.lustre.org/kernels/$CANONICAL_TARGET/old/$KERNEL..."
317                     if ! wget -nv "http://ftp.lustre.org/kernels/$CANONICAL_TARGET/old/$KERNEL" -O "$KERNELDIR/$KERNEL" ; then
318                         # see if we can do it with an SRPM from the download site
319                         download_and_build_tarball $CANONICAL_TARGET $KERNEL_FILE
320                     fi
321                 else
322                     fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
323                 fi
324             fi
325         fi
326     fi
327
328     if [ "$SERIES" ] ; then
329         for series in $SERIES ; do
330             for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
331                 [ -r "$patchesdir/series/$series" ] && continue 2
332             done
333             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."
334         done
335     fi
336
337     CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/$CONFIG"
338     [ -r "$CONFIG_FILE" ] || \
339         fatal 1 "Target $TARGET's config file $CONFIG missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
340
341     if [ "$EXTRA_VERSION_save" ] ; then
342         EXTRA_VERSION="$EXTRA_VERSION_save"
343     elif ! (( $RELEASE )) ; then
344         #remove the @VERSION@ (lustre version)
345         EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
346         EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
347     fi
348     # EXTRA_VERSION=${EXTRA_VERSION//-/_}
349
350     ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
351
352     BUILD_ARCHS=
353     for arch in $(uniqify "$ALL_ARCHS") ; do
354         if [ -z "$TARGET_ARCHS" ] || echo "$TARGET_ARCHS" | grep "$arch" >/dev/null 2>/dev/null ; then
355             BUILD_ARCHS="$BUILD_ARCHS $arch"
356         fi
357     done
358     [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
359     echo "Building for: $BUILD_ARCHS"
360 }
361
362 tarflags()
363 {
364     case "$1" in
365         '')
366             fatal 1 "tarflags(): File name argument missing."
367             ;;
368         *.tar.gz | *.tgz)
369             echo 'zxf'
370             ;;
371         *.tar.bz2)
372             echo 'jxf'
373             ;;
374         *.tar)
375             echo 'xf'
376             ;;
377         *)
378             fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
379             ;;
380     esac
381 }
382
383 untar()
384 {
385     echo "Untarring ${1##*/}..."
386     tar $(tarflags "$1") "$1"
387 }
388
389 unpack_lustre()
390 {
391     DIRNAME="lustre-$TAG-$TIMESTAMP"
392     if [ "$LUSTRE" ] ; then
393         untar "$LUSTRE"
394         [ -d lustre ] || ln -sf lustre* lustre
395     else
396         if [ "$USE_DATESTAMP" ]; then
397             DATESTAMP="-D '$DATE'"
398         else
399             DATESTAMP=""
400         fi            
401
402         cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
403             fatal 1 "There was an error checking out toplevel Lustre from CVS."
404         pushd "$DIRNAME" > /dev/null
405         ./lustrecvs "$TAG" || \
406             fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
407         echo "Creating lustre tarball..."
408         sh autogen.sh || fatal 1 "There was an error running autogen.sh."
409         ./configure --disable-{modules,utils,liblustre,tests,doc} || \
410             fatal 1 "There was an error running ./configure to create makefiles."
411         make dist || fatal 1 "There was an error running 'make dist'."
412         popd > /dev/null
413         fname=`basename $DIRNAME/lustre-*.tar.gz`
414         cp $DIRNAME/$fname . || fatal 1 "There was an error copying lustre tarball."
415         LUSTRE="$PWD/$fname"
416         ln -sf "$DIRNAME" lustre
417     fi
418 }
419
420 unpack_linux()
421 {
422     untar "$KERNEL_FILE"
423     [ -d linux ] || ln -sf linux* linux
424 }
425
426 patch_linux()
427 {
428     [ "$SERIES" ] || return 0
429     FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
430     [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
431     pushd linux >/dev/null
432     for series in $SERIES ; do
433         echo -n "Applying series $series:"
434         for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
435             [ -r "$patchesdir/series/$series" ] || continue
436             SERIES_FILE="$patchesdir/series/$series"
437             for patch in $(<"$SERIES_FILE") ; do
438                 echo -n " $patch"
439                 PATCH_FILE="$patchesdir/patches/$patch"
440                 [ -r "$PATCH_FILE" ] || \
441                     fatal 1 "Patch $patch does not exist in Lustre tree."
442                 cat "$PATCH_FILE" >> "$FULL_PATCH" || \
443                     fatal 1 "Error adding patch $patch to full patch."
444                 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
445             done
446             break
447         done
448         echo
449     done
450     popd >/dev/null
451     echo "Full patch has been saved in ${FULL_PATCH##*/}."
452     echo "Replacing .config files..."
453     [ -d linux/configs ] || mkdir linux/configs || \
454         fatal 1 "Error creating configs directory."
455     rm -f linux/configs/*
456     copysuccess=0
457     for patchesdir in "$EXTERNAL_PATCHES" "lustre/lustre/kernel_patches" ; do
458         [ "$patchesdir" ] && \
459             cp -v $patchesdir/kernel_configs/kernel-${VERSION}-${TARGET}*.config linux/configs/ >/dev/null && copysuccess=1
460     done
461     [ "$copysuccess" = "1" ] || \
462         fatal 1 "Error copying in kernel configs."
463 }
464
465 pack_linux()
466 {
467     TARBALL="$(readlink linux)-$EXTRA_VERSION.tar.gz"
468     echo "Creating patched linux tarball $TARBALL..."
469     tar zcf "$TARBALL" "$(readlink linux)" \
470         --exclude "CVS" --exclude ".cvsignore" || \
471         --exclude "*.orig" --exclude "*~" --exclude "*.rej" || \
472         fatal 1 "Error creating patched Linux tarball."
473 }
474
475 clean_linux()
476 {
477     [ -d linux ] || return 0
478     echo "Cleaning linux..."
479     [ -L linux ] && rm -rf $(readlink linux)
480     rm -rf linux
481 }
482
483 prep_kernel_build()
484 {
485     # make .spec file
486     ENABLE_INIT_SCRIPTS=""
487     sed \
488         -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
489         -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
490         -e "s^@BIGSMP_ARCHS@^$BIGSMP_ARCHS^g" \
491         -e "s^@BOOT_ARCHS@^$BOOT_ARCHS^g" \
492         -e "s^@CONFIGURE_FLAGS@^$CONFIGURE_FLAGS^g" \
493         -e "s^@ENABLE_INIT_SCRIPTS@^$ENABLE_INIT_SCRIPTS^g" \
494         -e "s^@JENSEN_ARCHS@^$BOOT_ARCHS^g" \
495         -e "s^@KERNEL_EXTRA_VERSION@^$EXTRA_VERSION^g" \
496         -e "s^@KERNEL_RELEASE@^${EXTRA_VERSION//-/_}^g" \
497         -e "s^@KERNEL_SOURCE@^$KERNEL^g" \
498         -e "s^@KERNEL_VERSION@^$VERSION^g" \
499         -e "s^@LINUX26@^$LINUX26^g" \
500         -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
501         -e "s^@LUSTRE_TARGET@^$TARGET^g" \
502         -e "s^@PSERIES64_ARCHS@^$PSERIES64_ARCHS^g" \
503         -e "s^@RHBUILD@^$RHBUILD^g" \
504         -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
505         -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
506         -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
507         -e "s^@UP_ARCHS@^$UP_ARCHS^g" \
508         < $TOPDIR/lustre/build/lustre-kernel-2.4.spec.in \
509         > lustre-kernel-2.4.spec
510     [ -d SRPMS ] || mkdir SRPMS
511     [ -d RPMS ] || mkdir RPMS
512     [ -d BUILD ] || mkdir BUILD
513     [ -d SOURCES ] || mkdir SOURCES
514     for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
515         suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} \
516         sles8-{pre,post,postun,update_{INITRD_MODULES,rcfile_setting}}.sh ; do
517         cp $TOPDIR/lustre/build/$script SOURCES
518     done
519     cp "$LUSTRE" "$KERNEL_FILE" SOURCES
520     if [ "$EXTERNAL_PATCHES" -a -d "$EXTERNAL_PATCHES" ] ; then
521         tar zcf SOURCES/external-patches.tar.gz -C "$EXTERNAL_PATCHES" series targets patches kernel_configs
522     else
523         touch SOURCES/external-patches.tar.gz
524     fi
525 }
526
527 clean_lustre()
528 {
529     [ -d lustre ] || return 0
530     echo "Cleaning Lustre..."
531     [ -L lustre ] && rm -rf $(readlink lustre)
532     rm -rf lustre
533 }
534
535 build_kernel()
536 {
537     echo "Building kernel + Lustre RPMs for: $BUILD_ARCHS..."
538     targets=
539     for arch in $BUILD_ARCHS ; do
540         targets="--target $arch $targets"
541     done
542
543     $RPMBUILD $targets -bb lustre-kernel-2.4.spec \
544         --define "_topdir $TOPDIR" || \
545         fatal 1 "Error building rpms for $BUILD_ARCHS."
546
547     if (( $DO_SRC )) ; then
548         $RPMBUILD -bs lustre-kernel-2.4.spec \
549             --define "_topdir $TOPDIR" || \
550             fatal 1 "Error building .src.rpm."
551     fi
552 }
553
554 build_lustre()
555 {
556     [ -d SRPMS ] || mkdir SRPMS
557     [ -d RPMS ] || mkdir RPMS
558     [ -d BUILD ] || mkdir BUILD
559     [ -d SOURCES ] || mkdir SOURCES
560
561     cp "$LUSTRE" SOURCES
562
563     pushd lustre >/dev/null
564
565     echo "Building Lustre RPMs for: $BUILD_ARCHS..."
566     targets=
567     for arch in $BUILD_ARCHS ; do
568         targets="--target $arch $targets"
569     done
570
571     ./configure "--with-linux=${LINUX}" ${CONFIGURE_FLAGS}
572
573     $RPMBUILD $targets -bb build/lustre.spec \
574         --define "_topdir $TOPDIR" || \
575         fatal 1 "Error building rpms for $BUILD_ARCHS."
576
577     popd >/dev/null
578 }
579
580 stage()
581 {
582     [ "$STAGEDIR" ] || return 0
583
584     for arch in $BUILD_ARCHS ; do
585         rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
586         echo "${0##*/}: Copying RPMs into ${rpmdir}"
587         mkdir -p "${rpmdir}"
588         cp -v RPMS/${arch}/*.rpm "${rpmdir}"
589         if [ -d RPMS/noarch ] ; then
590             cp -v RPMS/noarch/*.rpm "${rpmdir}"
591         fi
592     done
593
594     cp -v "$LUSTRE" "$STAGEDIR"
595 }
596
597 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
598
599 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: -- "$@")
600
601 if [ $? != 0 ] ; then
602     usage 1
603 fi
604
605 eval set -- "$options"
606     
607 while [ "$1" ] ; do
608     case "$1" in
609         '')
610             usage 1
611             ;;
612         -d)
613             CVSROOT=$2
614             shift 2
615             ;;
616         -D)
617             DATE=$2
618             shift 2
619             ;;
620         --external-patches)
621             EXTERNAL_PATCHES=$2
622             shift 2
623             ;;
624         --extraversion)
625             EXTRA_VERSION=$2
626             shift 2
627             ;;
628         --help | -h)
629             usage 0
630             ;;
631         --kerneldir)
632             KERNELDIR=$2
633             shift 2
634             ;;
635         --linux | --with-linux)
636             LINUX=$2
637             shift 2
638             ;;
639         --lustre)
640             LUSTRE=$2
641             shift 2
642             ;;
643         --nodownload)
644             DOWNLOAD=0
645             shift 1
646             ;;
647         --nosrc)
648             DO_SRC=0
649             shift 1
650             ;;
651         --publish)
652             shift
653             ;;
654         --release)
655             RELEASE=1
656             shift
657             ;;
658         --src)
659             DO_SRC=1
660             shift 1
661             ;;
662         --stage)
663             STAGEDIR=$2
664             shift 2
665             ;;
666         --tag)
667             TAG=$2
668             shift 2
669             ;;
670         --target)
671             TARGET=$2
672             shift 2
673             ;;
674         --target-archs)
675             TARGET_ARCHS=$2
676             shift 2
677             ;;
678         --disable-datestamp)
679             USE_DATESTAMP=
680             shift
681             ;;
682         --)
683             shift
684             CONFIGURE_FLAGS=$@
685             break
686             ;; 
687         *)
688             usage 1 "Unrecognized option: $1"
689             ;;
690     esac
691 done
692
693 check_options
694
695 unpack_lustre
696
697 # prep_build needs the .spec.in from the lustre source
698 if [ -z "$LINUX" ] ; then
699     load_target
700     if (( $DO_SRC )) ; then
701         unpack_linux
702         patch_linux
703         pack_linux
704         clean_linux
705     fi
706
707     prep_kernel_build
708     clean_lustre
709
710     build_kernel
711 else
712     build_lustre
713 fi
714
715 stage