3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
7 # CVSROOT is inherited from the environment
49 # Readlink is not present on some older distributions: emulate it.
53 if [ -L "$path" ]; then
54 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
68 [ "$1" ] && echo -e "\n${0##*/}: $1"
80 (( $RELEASE )) || return 0
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}"
96 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
99 Specifies the CVS Root to use when pulling files from CVS. The
100 environment variable \$CVSROOT is used if this option is not
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
108 --extraversion=EXTRAVERSION
109 Text to use for the rpm release and kernel extraversion.
111 --kerneldir=KERNELDIR
112 Directory containing Linux source tarballs referenced by target
116 Directory of Linux kernel sources. When this option is used, only
117 Lustre modules and userspace are built.
120 Path to an existing lustre source tarball to use instead of
124 Do not try to download a kernel from ftp.lustre.org
127 Do not build a .src.rpm, a full kernel patch, or a patched kernel
134 Specifies that the files generated do not include timestamps, and
135 that this is an official release.
138 Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
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
146 A CVS branch/tag name to build from when pulling from CVS.
149 The name of the target to build. The available targets are listed
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).
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.
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.
176 if [ "$LUSTRE" ] ; then
177 [ -r "$LUSTRE" ] || \
178 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
181 usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
183 usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
186 if [ -z "$LINUX" ] ; then
187 [ "$KERNELDIR" ] || \
188 usage 1 "A kernel directory must be specified with --kerneldir."
190 [ -d "$KERNELDIR" ] || \
191 usage 1 "$KERNELDIR is not a directory."
193 if ! (( $RELEASE )) ; then
195 usage 1 "When building a snapshot, a tag name must be used."
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."
206 CANONICAL_TARGET="rhel-2.6"
209 CANONICAL_TARGET="sles-2.6"
212 CANONICAL_TARGET="hp-pnnl-2.4"
219 CANONICAL_TARGET="$TARGET"
223 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M")
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)."
236 echo $(echo "$*" | xargs -n 1 | sort -u)
243 if [ "$TARGET" = "rhel-2.6" -o "$TARGET" = "rhel-2.4" ]; then
245 if [ "$TARGET" = "rhel-2.6" ]; then
247 OLDCONFIG=nonint_oldconfig
248 elif [ "$TARGET" = "rhel-2.4" ]; then
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} && {
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."
264 make include/linux/version.h
267 tar cjf $KERNEL_FILE linux-${lnxmaj}
274 download_and_build_tarball() {
278 local SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
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."
286 build_tarball $TARGET $SRPM
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
296 [ -r "$TARGET_FILE" ] || \
297 fatal 1 "Target $TARGET was not found."
299 echo "Loading target config file $TARGET.target..."
303 [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
304 [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify a kernel version."
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
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
321 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
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
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."
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/."
340 if [ "$EXTRA_VERSION_save" ] ; then
341 EXTRA_VERSION="$EXTRA_VERSION_save"
342 elif ! (( $RELEASE )) ; then
343 #remove the @VERSION@ (lustre version)
344 EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
345 EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
347 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
349 ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
352 for arch in $(uniqify "$ALL_ARCHS") ; do
353 if [ -z "$TARGET_ARCHS" ] || echo "$TARGET_ARCHS" | grep "$arch" >/dev/null 2>/dev/null ; then
354 BUILD_ARCHS="$BUILD_ARCHS $arch"
357 [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
358 echo "Building for: $BUILD_ARCHS"
365 fatal 1 "tarflags(): File name argument missing."
377 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
384 echo "Untarring ${1##*/}..."
385 tar $(tarflags "$1") "$1"
390 DIRNAME="lustre-$TAG-$TIMESTAMP"
391 if [ "$LUSTRE" ] ; then
393 [ -d lustre ] || ln -sf lustre* lustre
395 if [ "$USE_DATESTAMP" ]; then
396 DATESTAMP="-D '$DATE'"
401 cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
402 fatal 1 "There was an error checking out toplevel Lustre from CVS."
403 pushd "$DIRNAME" > /dev/null
404 ./lustrecvs "$TAG" || \
405 fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
406 echo "Creating lustre tarball..."
407 sh autogen.sh || fatal 1 "There was an error running autogen.sh."
408 ./configure --disable-{modules,utils,liblustre,tests,doc} || \
409 fatal 1 "There was an error running ./configure to create makefiles."
410 make dist || fatal 1 "There was an error running 'make dist'."
412 fname=`basename $DIRNAME/lustre-*.tar.gz`
413 cp $DIRNAME/$fname . || fatal 1 "There was an error copying lustre tarball."
415 ln -sf "$DIRNAME" lustre
422 [ -d linux ] || ln -sf linux* linux
427 [ "$SERIES" ] || return 0
428 FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
429 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
430 pushd linux >/dev/null
431 for series in $SERIES ; do
432 echo -n "Applying series $series:"
433 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
434 [ -r "$patchesdir/series/$series" ] || continue
435 SERIES_FILE="$patchesdir/series/$series"
436 for patch in $(<"$SERIES_FILE") ; do
438 PATCH_FILE="$patchesdir/patches/$patch"
439 [ -r "$PATCH_FILE" ] || \
440 fatal 1 "Patch $patch does not exist in Lustre tree."
441 cat "$PATCH_FILE" >> "$FULL_PATCH" || \
442 fatal 1 "Error adding patch $patch to full patch."
443 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
450 echo "Full patch has been saved in ${FULL_PATCH##*/}."
451 echo "Replacing .config files..."
452 [ -d linux/configs ] || mkdir linux/configs || \
453 fatal 1 "Error creating configs directory."
454 rm -f linux/configs/*
456 for patchesdir in "$EXTERNAL_PATCHES" "lustre/lustre/kernel_patches" ; do
457 [ "$patchesdir" ] && \
458 cp -v $patchesdir/kernel_configs/kernel-${VERSION}-${TARGET}*.config linux/configs/ >/dev/null && copysuccess=1
460 [ "$copysuccess" = "1" ] || \
461 fatal 1 "Error copying in kernel configs."
466 TARBALL="$(readlink linux)-$EXTRA_VERSION.tar.gz"
467 echo "Creating patched linux tarball $TARBALL..."
468 tar zcf "$TARBALL" "$(readlink linux)" \
469 --exclude "CVS" --exclude ".cvsignore" || \
470 --exclude "*.orig" --exclude "*~" --exclude "*.rej" || \
471 fatal 1 "Error creating patched Linux tarball."
476 [ -d linux ] || return 0
477 echo "Cleaning linux..."
478 [ -L linux ] && rm -rf $(readlink linux)
485 ENABLE_INIT_SCRIPTS=""
487 -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
488 -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
489 -e "s^@BIGSMP_ARCHS@^$BIGSMP_ARCHS^g" \
490 -e "s^@BOOT_ARCHS@^$BOOT_ARCHS^g" \
491 -e "s^@CONFIGURE_FLAGS@^$CONFIGURE_FLAGS^g" \
492 -e "s^@ENABLE_INIT_SCRIPTS@^$ENABLE_INIT_SCRIPTS^g" \
493 -e "s^@JENSEN_ARCHS@^$BOOT_ARCHS^g" \
494 -e "s^@KERNEL_EXTRA_VERSION@^$EXTRA_VERSION^g" \
495 -e "s^@KERNEL_RELEASE@^${EXTRA_VERSION//-/_}^g" \
496 -e "s^@KERNEL_SOURCE@^$KERNEL^g" \
497 -e "s^@KERNEL_VERSION@^$VERSION^g" \
498 -e "s^@LINUX26@^$LINUX26^g" \
499 -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
500 -e "s^@LUSTRE_TARGET@^$TARGET^g" \
501 -e "s^@PSERIES64_ARCHS@^$PSERIES64_ARCHS^g" \
502 -e "s^@RHBUILD@^$RHBUILD^g" \
503 -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
504 -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
505 -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
506 -e "s^@UP_ARCHS@^$UP_ARCHS^g" \
507 < $TOPDIR/lustre/build/lustre-kernel-2.4.spec.in \
508 > lustre-kernel-2.4.spec
509 [ -d SRPMS ] || mkdir SRPMS
510 [ -d RPMS ] || mkdir RPMS
511 [ -d BUILD ] || mkdir BUILD
512 [ -d SOURCES ] || mkdir SOURCES
513 for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
514 suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} \
515 sles8-{pre,post,postun,update_{INITRD_MODULES,rcfile_setting}}.sh ; do
516 cp $TOPDIR/lustre/build/$script SOURCES
518 cp "$LUSTRE" "$KERNEL_FILE" SOURCES
519 if [ "$EXTERNAL_PATCHES" -a -d "$EXTERNAL_PATCHES" ] ; then
520 tar zcf SOURCES/external-patches.tar.gz -C "$EXTERNAL_PATCHES" series targets patches kernel_configs
522 touch SOURCES/external-patches.tar.gz
528 [ -d lustre ] || return 0
529 echo "Cleaning Lustre..."
530 [ -L lustre ] && rm -rf $(readlink lustre)
536 echo "Building kernel + Lustre RPMs for: $BUILD_ARCHS..."
538 for arch in $BUILD_ARCHS ; do
539 targets="--target $arch $targets"
542 $RPMBUILD $targets -bb lustre-kernel-2.4.spec \
543 --define "_topdir $TOPDIR" || \
544 fatal 1 "Error building rpms for $BUILD_ARCHS."
546 if (( $DO_SRC )) ; then
547 $RPMBUILD -bs lustre-kernel-2.4.spec \
548 --define "_topdir $TOPDIR" || \
549 fatal 1 "Error building .src.rpm."
555 [ -d SRPMS ] || mkdir SRPMS
556 [ -d RPMS ] || mkdir RPMS
557 [ -d BUILD ] || mkdir BUILD
558 [ -d SOURCES ] || mkdir SOURCES
562 pushd lustre >/dev/null
564 echo "Building Lustre RPMs for: $BUILD_ARCHS..."
566 for arch in $BUILD_ARCHS ; do
567 targets="--target $arch $targets"
570 ./configure "--with-linux=${LINUX}" ${CONFIGURE_FLAGS}
572 $RPMBUILD $targets -bb build/lustre.spec \
573 --define "_topdir $TOPDIR" \
574 --define "configure_flags --with-linux=${LINUX}" || \
575 fatal 1 "Error building rpms for $BUILD_ARCHS."
582 [ "$STAGEDIR" ] || return 0
584 for arch in $BUILD_ARCHS ; do
585 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
586 echo "${0##*/}: Copying RPMs into ${rpmdir}"
588 cp -v RPMS/${arch}/*.rpm "${rpmdir}"
589 if [ -d RPMS/noarch ] ; then
590 cp -v RPMS/noarch/*.rpm "${rpmdir}"
594 cp -v "$LUSTRE" "$STAGEDIR"
597 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
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: -- "$@")
601 if [ $? != 0 ] ; then
605 eval set -- "$options"
635 --linux | --with-linux)
688 usage 1 "Unrecognized option: $1"
697 # prep_build needs the .spec.in from the lustre source
698 if [ -z "$LINUX" ] ; then
701 if [ "$SERIES" ] ; then
702 if (( $DO_SRC )) ; then
714 # can't build a kernel if we have no series for it (i.e. patchless)
715 # but we still need the headers
719 # need a .config -- like a user would do
720 cp /boot/config-${lnxmaj}-${lnxrel}smp .config
723 make include/linux/version.h