3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
9 # CVSROOT is inherited from the environment
19 TARGET_ARCH=$(uname -m)
21 TARGET_ARCHS_ALL=$TARGET_ARCH
22 [ "$TARGET_ARCH" = "i686" ] && TARGET_ARCHS_ALL="i686 i586 i386"
28 TMPDIR=${TMPDIR:-"/var/tmp"}
34 SKIPLDISKFSRPM="v1_4_* b1_4"
35 SMPTYPES="smp bigsmp default ''"
79 # Readlink is not present on some older distributions: emulate it.
83 if [ -L "$path" ]; then
84 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
98 [ "$1" ] && echo -e "\n${0##*/}: $1"
110 echo -n "Available targets:"
111 for target in $TOPDIR/lustre/lustre/kernel_patches/targets/*.target ; do
112 target_file=${target##*/}
113 echo -n " ${target_file%%.target}"
121 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
124 Specifies the CVS Root to use when pulling files from CVS. The
125 environment variable \$CVSROOT is used if this option is not
128 --external-patches=EXTERNAL_PATCHES
129 Directory similar to lustre/lustre/kernel_patches/ that lbuild should
130 look for seres and config files in before looking in the lustre
133 --extraversion=EXTRAVERSION
134 Text to use for the rpm release and kernel extraversion.
136 --kerneldir=KERNELDIR
137 Directory containing Linux source tarballs referenced by target
140 --timestamp=TIMESTAMP
141 Date of building lustre in format YYYYMMDDhhmmss
144 Try to reuse old kernel RPMs from DIR
147 Try to reuse old kernel builds from DIR
150 Path to distro kernel RPM collection
156 Do not build RPMs (compile only mode)
159 Build lustre client only
162 Which distro using. Autodetect by default
164 --kerneltree=KERNELTREE
165 Directory containing dirs with Linux source tarballs referenced by target
166 files. Dir names in format kernel version ('2.6.9', etc.)
169 Directory of Linux kernel sources. When this option is used, only
170 Lustre modules and userspace are built.
173 Path to an existing lustre source tarball to use instead of
177 Do not try to download a kernel from downloads.lustre.org
180 Do not build a .src.rpm, a full kernel patch, or a patched kernel
184 Do ldiskfs RPM. Now true by default
190 Specifies that the files generated do not include timestamps, and
191 that this is an official release.
194 Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
197 Directory used to stage packages for release. RPMs will be placed
198 more or less in DIR/<target>-<arch>, and the tarball will be
202 A CVS branch/tag name to build from when pulling from CVS.
205 The name of the target to build. The available targets are listed
208 --target-archs=TARGET_ARCHS
209 A (space delimited) list of architectures to build. By default,
210 all of the archs supported by the TARGET will be built, in
211 addition to a .src.rpm. This option can limit those, for machines
212 that can only build certain archs or if you only want a certain
213 arch built (for testing, or a one-off kernel).
215 Also note that by using a non-"base" arch (eg, i386) only kernels
216 will be built - there will be no lustre-lite-utils package.
219 Prevents the datestamp flag (-D) from being passed to cvs for
220 checkouts. This is a workaround for a problem encountered when
221 using lbuild with tinderbox.
232 if [ "$LUSTRE" ] ; then
233 [ -r "$LUSTRE" ] || \
234 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
237 usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
239 usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
242 if [ -z "$LINUX" ] ; then
243 [ "$KERNELDIR" -o "$KERNELTREE" ] || \
244 usage 1 "A kernel directory must be specified with --kerneldir or --kerneltree."
246 [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
247 usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
251 usage 1 "When building a snapshot, a tag name must be used."
254 [ "$TARGET" ] || usage 1 "A target must be specified with --target."
255 # TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
256 # [ -r "$TARGET_FILE" ] || \
257 # usage 1 "Target '$TARGET' was not found."
262 CANONICAL_TARGET="rhel5"
265 CANONICAL_TARGET="rhel-2.6"
268 CANONICAL_TARGET="sles-2.6"
271 CANONICAL_TARGET="sles10-2.6"
274 CANONICAL_TARGET="hp-pnnl-2.4"
282 CANONICAL_TARGET="$TARGET"
286 local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
287 [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
288 local timestamplength="${#TIMESTAMP}"
289 if [ $timestamplength -eq 12 ]; then
290 TIMESTAMP="${TIMESTAMP}00"
291 elif [ $timestamplength -ne 14 ]; then
292 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
295 RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
296 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
297 RPMBUILD=$(which rpm 2>/dev/null | head -1)
298 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
299 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
303 if [ -n "$CCACHE" ]; then
304 which "$CCACHE" 2>/dev/null && export CCACHE && export CC="ccache gcc"
305 which "$DISTCC" 2>/dev/null && export DISTCC RPM_BUILD_NCPUS
306 local bindir="/cache/build/bin"
307 [ -d $bindir ] || mkdir -p $bindir
308 [ -d $bindir ] && rm ${bindir}/* > /dev/null 2>&1
309 which "$CCACHE" 2>/dev/null && [ -d $bindir ] && ln -s `which "$CCACHE"` ${bindir}/ccache
310 which "$CCACHE" 2>/dev/null && [ -d $bindir ] && ln -s `which "$CCACHE"` ${bindir}/cc
311 which "$CCACHE" 2>/dev/null && [ -d $bindir ] && ln -s `which "$CCACHE"` ${bindir}/gcc
312 [ -d $bindir ] && export PATH=$bindir:$PATH
315 [ -z "$DISTRO" ] && autodetect_distro
318 #autodetect used Distro
321 if [ -f /etc/SuSE-release ]; then
323 elif [ -f /etc/redhat-release ]; then
324 local distroname=$(head -1 /etc/redhat-release | grep -e "CentOS\|Red")
325 if [ ! "$distroname" = "" ]; then
326 local version=$(echo "$distroname" | sed -e s/[^0-9.]*//g | sed -e s/\\..*// )
328 [ "$version" = "" ] || DISTRO="${distroname}${version}"
331 [ "$DISTRO" = "" ] && DISTRO="sles9" #default distro
336 echo $(echo "$*" | xargs -n 1 | sort -u)
343 if [ "$TARGET" = "rhel-2.6" -o "$TARGET" = "rhel-2.4" ]; then
345 if [ "$TARGET" = "rhel-2.6" ]; then
347 OLDCONFIG=nonint_oldconfig
348 elif [ "$TARGET" = "rhel-2.4" ]; then
353 RPMTOPDIR=$(mktemp -d $KERNELDIR/rpm_XXXXXX)
354 mkdir $RPMTOPDIR/BUILD/
355 rpm -ivh $KERNELDIR/$SRPM --define "_topdir $RPMTOPDIR" || \
356 { rm -rf $RPMTOPDIR; fatal 1 "Error installing kernel SRPM."; }
357 $RPMBUILD -bp --nodeps --target i686 $RPMTOPDIR/SPECS/$SPEC --define "_topdir $RPMTOPDIR"
358 pushd $RPMTOPDIR/BUILD/kernel-${lnxmaj}/linux-${lnxmaj} && {
360 cp configs/kernel-${lnxmaj}-i686-smp.config .config
361 if ! make $OLDCONFIG > /dev/null; then
362 fatal 1 "error trying to make $OLDCONFIG while building a tarball from SRPM."
364 make include/linux/version.h
367 tar cjf $KERNEL_FILE linux-${lnxmaj}
374 download_and_build_tarball() {
378 local srpm=kernel-${lnxmaj}-${lnxrel}.src.rpm
380 echo "Downloading http://downloads.lustre.org/public/kernels/$target/old/$srpm..."
381 if ! wget -nv "http://downloads.lustre.org/public/kernels/$target/old/$srpm" \
382 -O "$KERNELDIR/$srpm" ; then
383 fatal 1 "Could not download target $kernel_file's kernel SRPM $srpm from downloads.lustre.org."
385 [ -s "$KERNELDIR/$srpm" ] || {
386 rm -rf $KERNELDIR/$srpm
387 fatal 1 "Could not download target $kernel_file's kernel SRPM $srpm from downloads.lustre.org."
390 build_tarball $target $srpm
395 EXTRA_VERSION_save="$EXTRA_VERSION"
396 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
397 TARGET_FILE="$patchesdir/targets/$TARGET.target"
398 [ -r "$TARGET_FILE" ] && break
400 [ -r "$TARGET_FILE" ] || \
401 fatal 1 "Target $TARGET was not found."
403 echo "Loading target config file $TARGET.target..."
407 [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
408 [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify a kernel version."
410 #CC was overwriten in TARGET_FILE
411 which "$CCACHE" 2>/dev/null && export CCACHE && export CC="ccache gcc"
413 if [ ! "$KERNELTREE" = "" ] && [ -d "$KERNELTREE" ]; then
414 KERNELDIR="$KERNELTREE/${lnxmaj}"
415 [ -d "$KERNELDIR" ] || mkdir "$KERNELDIR"
418 if [ "$KERNELDIR" ] ; then
419 KERNEL_FILE="$KERNELDIR/$KERNEL"
420 if [ ! -r "$KERNEL_FILE" ] ; then
421 # see if we have an SRPM we can build a tarball for
422 KERNEL_SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
423 if [ -r "$KERNELDIR/$KERNEL_SRPM" ] ; then
424 build_tarball $CANONICAL_TARGET $KERNEL_SRPM
426 if (( $DOWNLOAD )) ; then
427 echo "Downloading http://downloads.lustre.org/public/kernels/$DISTRO/old/$KERNEL..."
428 if ! wget -nv "http://downloads.lustre.org/public/kernels/$DISTRO/old/$KERNEL" -O "$KERNELDIR/$KERNEL" ; then
429 # see if we can do it with an SRPM from the download site
430 download_and_build_tarball $CANONICAL_TARGET $KERNEL_FILE
432 [ -s "$KERNELDIR/$KERNEL" ] || {
433 rm -rf "$KERNELDIR/$KERNEL"
434 fatal 1 "Target $TARGET's kernel $KERNEL not found in directory $KERNELDIR."
438 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
442 if [ -n "$OFED_VERSION" ] && \
443 [ ! -r "$KERNELTREE/../OFED-${OFED_VERSION}.tgz" ] ; then
444 if (( $DOWNLOAD )) ; then
445 local location="http://downloads.lustre.org/public/OFED/"
446 echo "Downloading $location/OFED-${OFED_VERSION}.tgz..."
447 if ! wget -nv "$location/OFED-${OFED_VERSION}.tgz" \
448 -O "$KERNELTREE/../OFED-${OFED_VERSION}.tgz" ; then
449 fatal 1 "Could not download OFED-${OFED_VERSION}.tgz from downloads.lustre.org."
452 fatal 1 "OFED-${OFED_VERSION}.tgz not found in kernel directory $KERNELDIR."
457 if [ "$SERIES" ] ; then
458 for series in $SERIES ; do
459 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
460 [ -r "$patchesdir/series/$series" ] && continue 2
462 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."
466 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
467 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config"
470 for smptype in $SMPTYPES; do
471 [ "$smptype" = "''" ] && smptype=
472 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH-${smptype}.config ]; then
473 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH-${smptype}.config"
474 KERNCONFSMPTYPE=$smptype
478 local lnxrelnew=${lnxrel//-/_}
480 if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
481 fatal 1 "Config file for target $TARGET missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
484 if [ "$EXTRA_VERSION_save" ] ; then
485 EXTRA_VERSION="$EXTRA_VERSION_save"
486 elif ! $RELEASE; then
487 # if there is no patch series, then this is not a lustre specific
488 # kernel. don't make it look like one
489 if [ -n "$SERIES" ]; then
490 #remove the @VERSION@ (lustre version)
491 # EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
492 # EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
493 ! ( $PATCHLESS ) && EXTRA_VERSION="${EXTRA_VERSION}.${TIMESTAMP}"
496 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
498 [ -z $REUSEDKERNELMASK ] && \
499 # create mask for kernel RPM/builddir which could be reused
501 REUSEDKERNELMASK=${KERNCONFSMPTYPE}-${lnxmaj}-${lnxrelnew}_lustre.${LUSTRE_VERSION}.*${TARGET_ARCH}
503 REUSEDKERNELMASK=${KERNCONFSMPTYPE}-${lnxmaj}-${lnxrelnew}_lustre.${LUSTRE_VERSION}.${TARGET_ARCH}
505 REUSEDKERNELMASK=${KERNCONFSMPTYPE}-${lnxmaj}-${lnxrelnew}_lustre.${LUSTRE_VERSION}.${TIMESTAMP}.${TARGET_ARCH}
507 # kernel-lustre-smp-2.6.9-55.0.2.EL_lustre.1.6.1.i686.rpm
509 ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
512 for arch in $(uniqify "$ALL_ARCHS") ; do
513 if [ -z "$TARGET_ARCHS" ] || echo "$TARGET_ARCHS" | grep "$arch" >/dev/null 2>/dev/null ; then
514 BUILD_ARCHS="$BUILD_ARCHS $arch"
517 [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
518 echo "Building for: $BUILD_ARCHS"
525 fatal 1 "tarflags(): File name argument missing."
537 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
544 echo "Untarring ${1##*/}..."
545 tar $(tarflags "$1") "$1"
550 untar "$KERNELTREE/../OFED-${OFED_VERSION}.tgz"
551 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
553 ls -ld OFED OFED-[0-9].[0-9]*
554 ls -l OFED OFED-[0-9].[0-9]*
559 DIRNAME="lustre-$TAG-$TIMESTAMP"
560 if [ "$LUSTRE" ] ; then
562 [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
564 if [ "$USE_DATESTAMP" ]; then
565 DATESTAMP="-D '$DATE'"
570 cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
571 fatal 1 "There was an error checking out toplevel Lustre from CVS."
572 pushd "$DIRNAME" > /dev/null
573 ./lustrecvs "$TAG" || \
574 fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
575 echo "Creating lustre tarball..."
576 sh autogen.sh || fatal 1 "There was an error running autogen.sh."
577 ./configure --disable-{modules,utils,liblustre,tests,doc} || \
578 fatal 1 "There was an error running ./configure to create makefiles."
579 make dist || fatal 1 "There was an error running 'make dist'."
581 fname=$(basename $DIRNAME/lustre-*.tar.gz)
582 cp $DIRNAME/$fname . || fatal 1 "There was an error copying lustre tarball."
584 ln -sf "$DIRNAME" lustre
591 [ -d linux ] || ln -sf linux* linux
596 [ "$SERIES" ] || return 0
597 FULL_PATCH="$PWD/lustre-kernel-${TARGET}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}.patch"
598 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
599 pushd linux >/dev/null
600 for series in $SERIES ; do
601 echo -n "Applying series $series:"
602 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches" ; do
603 [ -r "$patchesdir/series/$series" ] || continue
604 SERIES_FILE="$patchesdir/series/$series"
605 for patch in $(<"$SERIES_FILE") ; do
607 PATCH_FILE="$patchesdir/patches/$patch"
608 [ -r "$PATCH_FILE" ] || \
609 fatal 1 "Patch $patch does not exist in Lustre tree."
610 cat "$PATCH_FILE" >> "$FULL_PATCH" || \
611 fatal 1 "Error adding patch $patch to full patch."
612 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
619 echo "Full patch has been saved in ${FULL_PATCH##*/}."
620 echo "Replacing .config files..."
621 [ -d linux/configs ] || mkdir linux/configs || \
622 fatal 1 "Error creating configs directory."
623 rm -f linux/configs/*
625 for patchesdir in "$EXTERNAL_PATCHES" "lustre/lustre/kernel_patches" ; do
626 [ "$patchesdir" ] && \
627 cp -v $patchesdir/kernel_configs/kernel-${VERSION}-${TARGET}*.config linux/configs/ >/dev/null && copysuccess=1
629 [ "$copysuccess" = "1" ] || \
630 fatal 1 "Error copying in kernel configs."
635 TARBALL="$(readlink linux)-$EXTRA_VERSION.tar.gz"
636 echo "Creating patched linux tarball $TARBALL..."
637 tar zcf "$TARBALL" "$(readlink linux)" \
638 --exclude "CVS" --exclude ".cvsignore" || \
639 --exclude "*.orig" --exclude "*~" --exclude "*.rej" || \
640 fatal 1 "Error creating patched Linux tarball."
645 [ -d linux ] || return 0
646 echo "Cleaning linux..."
647 [ -L linux ] && rm -rf $(readlink linux)
654 ENABLE_INIT_SCRIPTS=""
656 -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
657 -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
658 -e "s^@BIGSMP_ARCHS@^$BIGSMP_ARCHS^g" \
659 -e "s^@BOOT_ARCHS@^$BOOT_ARCHS^g" \
660 -e "s^@CONFIGURE_FLAGS@^$CONFIGURE_FLAGS^g" \
661 -e "s^@ENABLE_INIT_SCRIPTS@^$ENABLE_INIT_SCRIPTS^g" \
662 -e "s^@JENSEN_ARCHS@^$BOOT_ARCHS^g" \
663 -e "s^@KERNEL_EXTRA_VERSION@^$EXTRA_VERSION^g" \
664 -e "s^@KERNEL_EXTRA_VERSION_DELIMITER@^$EXTRA_VERSION_DELIMITER^g" \
665 -e "s^@KERNEL_TARGET_DELIMITER@^$TARGET_DELIMITER^g" \
666 -e "s^@KERNEL_RELEASE@^${EXTRA_VERSION//-/_}^g" \
667 -e "s^@KERNEL_SOURCE@^$KERNEL^g" \
668 -e "s^@KERNEL_VERSION@^$VERSION^g" \
669 -e "s^@LINUX26@^$LINUX26^g" \
670 -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
671 -e "s^@LUSTRE_TARGET@^$TARGET^g" \
672 -e "s^@PSERIES64_ARCHS@^$PSERIES64_ARCHS^g" \
673 -e "s^@RHBUILD@^$RHBUILD^g" \
674 -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
675 -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
676 -e "s^@UP_ARCHS@^$UP_ARCHS^g" \
677 < $TOPDIR/lustre/build/lustre-kernel-2.4.spec.in \
678 > lustre-kernel-2.4.spec
679 [ -d SRPMS ] || mkdir SRPMS
680 [ -d RPMS ] || mkdir RPMS
681 [ -d BUILD ] || mkdir BUILD
682 [ -d SOURCES ] || mkdir SOURCES
683 for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
684 suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} \
685 sles8-{pre,post,postun,update_{INITRD_MODULES,rcfile_setting}}.sh ; do
686 cp $TOPDIR/lustre/build/$script SOURCES
688 cp "$LUSTRE" "$KERNEL_FILE" SOURCES
689 if [ "$EXTERNAL_PATCHES" -a -d "$EXTERNAL_PATCHES" ] ; then
690 tar zcf SOURCES/external-patches.tar.gz -C "$EXTERNAL_PATCHES" series targets patches kernel_configs
692 touch SOURCES/external-patches.tar.gz
698 [ -d lustre ] || return 0
699 echo "Cleaning Lustre..."
700 [ -L lustre ] && rm -rf $(readlink lustre)
706 echo "Building kernel + Lustre RPMs for: $BUILD_ARCHS..."
708 for arch in $BUILD_ARCHS ; do
709 targets="--target $arch $targets"
712 local rpmbuildopt='-bb'
715 # echo NORPM mode. Only compiling.
716 # echo "XXX: need to fix lmake - add options to do rpmbuild -bc instead of -bb"
719 $RPMBUILD $targets $rpmbuildopt lustre-kernel-2.4.spec \
720 --define "_tmppath $TMPDIR" \
721 --define "_topdir $TOPDIR" || \
722 fatal 1 "Error building rpms for $BUILD_ARCHS."
724 if (( $DO_SRC )) ; then
725 $RPMBUILD -bs lustre-kernel-2.4.spec \
726 --define "_tmppath $TMPDIR" \
727 --define "_topdir $TOPDIR" || \
728 fatal 1 "Error building .src.rpm."
731 ( $(skeep_ldiskfs_rpm $TAG) ) && return
733 pushd $TOPDIR/BUILD/lustre*/ldiskfs || return 255
735 if [ "$?" != "0" ] ; then
739 cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES
743 local ldiskfs_spec=lustre-ldiskfs.spec
744 [ -f "$ldiskfs_spec" ] && sed \
745 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
747 > ../lustre-ldiskfs.spec
749 $RPMBUILD $targets $rpmbuildopt ../lustre-ldiskfs.spec \
750 --define "_tmppath /var/tmp" \
751 --define "_topdir $TOPDIR"
752 if [ "$?" != "0" ] ; then
757 if (( $DO_SRC )) ; then
758 $RPMBUILD -bs ../lustre-ldiskfs.spec \
759 --define "_tmppath /var/tmp" \
760 --define "_topdir $TOPDIR"
761 if [ "$?" != "0" ] ; then
771 [ -d SRPMS ] || mkdir SRPMS
772 [ -d RPMS ] || mkdir RPMS
773 [ -d BUILD ] || mkdir BUILD
774 [ -d SOURCES ] || mkdir SOURCES
778 pushd lustre >/dev/null
780 echo "Building Lustre RPMs for: $BUILD_ARCHS..."
782 for arch in $BUILD_ARCHS ; do
783 targets="--target $arch $targets"
786 local confoptions="--with-linux=${LINUX}"
788 confoptions="--with-linux=${LINUX} --disable-server"
790 if [ ! "$LINUXOBJ" = "" ]; then
791 confoptions="$confoptions --with-linux-obj=${LINUXOBJ}"
794 ./configure $confoptions ${CONFIGURE_FLAGS}
795 if [ "$?" != "0" ] ; then
796 local saved_config="../config.log.$(date +%s)"
797 cp config.log $saved_config
798 chmod a+r $saved_config
799 echo "Saved config.log is at $saved_config"
806 # hack. Somebody move build/lustre.spec to lustre.spec for b1_6
808 [ -f lustre.spec ] && lustre_spec=lustre.spec
809 [ -f build/lustre.spec ] && lustre_spec=build/lustre.spec
811 [ -f "$lustre_spec" ] && sed \
812 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
816 local rpmbuildopt='-bb'
819 echo NORPM mode. Only compiling.
822 $RPMBUILD $targets $rpmbuildopt ../lustre.spec \
823 --define "_tmppath $TMPDIR" \
824 --define "_topdir $TOPDIR" || \
825 fatal 1 "Error building rpms for $BUILD_ARCHS."
828 ( $(skeep_ldiskfs_rpm $TAG) ) && return
830 pushd lustre/ldiskfs || return 255
832 if [ "$?" != "0" ] ; then
836 cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES
840 local ldiskfs_spec=lustre-ldiskfs.spec
841 [ -f "$ldiskfs_spec" ] && sed \
842 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
844 > ../lustre-ldiskfs.spec
846 $RPMBUILD $targets $rpmbuildopt ../lustre-ldiskfs.spec \
847 --define "_tmppath /var/tmp" \
848 --define "_topdir $TOPDIR"
849 if [ "$?" != "0" ] ; then
854 if (( $DO_SRC )) ; then
855 $RPMBUILD -bs ../lustre-ldiskfs.spec \
856 --define "_tmppath /var/tmp" \
857 --define "_topdir $TOPDIR"
858 if [ "$?" != "0" ] ; then
868 [ "$STAGEDIR" ] || return 0
870 for arch in $BUILD_ARCHS ; do
871 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
872 echo "${0##*/}: Copying RPMs into ${rpmdir}"
874 cp -v RPMS/${arch}/*.rpm "${rpmdir}"
875 if [ -d RPMS/noarch ] ; then
876 cp -v RPMS/noarch/*.rpm "${rpmdir}"
880 cp -v "$LUSTRE" "$STAGEDIR"
883 #check if we need to build separate ldiskfs RPM
888 if ! $LDISKFSRPM; then
890 elif $PATCHLESS; then
893 for skiptag in $SKIPLDISKFSRPM; do
894 [[ $tag == $skiptag ]] && skip=true && break
900 #get date of last changed target/config/series/patches
901 get_last_source_date()
903 local filelist="${TOPDIR}/lustre/lustre/kernel_patches/series/${SERIES} \
905 local TOPDIRnew=$(echo ${TOPDIR} | sed -e s/\\//\\\\\\//g)
906 filelist="$filelist $( \
907 cat ${TOPDIR}/lustre/lustre/kernel_patches/series/${SERIES} | \
908 sed -e s/^/${TOPDIRnew}\\/lustre\\/lustre\\/kernel_patches\\/patches\\// 2>&1)"
909 local sourcelastdate=$( find ${filelist} -name CVS -prune -o \
910 -type f -printf "%T@\n" 2>&1 | sort | tail -1 )
911 is_integer $sourcelastdate && echo $sourcelastdate
914 #check if variable is integer
918 [ "$invariable" = "" ] && return 255
919 local invariableint=$( echo $invariable | sed -e s/[^0-9]//g )
920 [ "$invariable" = "$invariableint" ] || return 255
923 #generate LUSTRE_EXTRA_VERSION from EXTRA_VERSION
927 [ "$KERNCONFSMPTYPE" = "" ] || smptype=$KERNCONFSMPTYPE
928 [ "$RPMSMPTYPE" = "" ] || smptype=$RPMSMPTYPE
930 LUSTRE_EXTRA_VERSION="${lnxmaj}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}${TARGET_DELIMITER}${smptype}"
931 LUSTRE_EXTRA_VERSION=${LUSTRE_EXTRA_VERSION//-/_}
934 #store RPMs and/or BUILD dir for future reuse
938 if [ ! "$REUSEBUILD" = "" ] && [ -d "/$REUSEBUILD/" ] ; then
939 [ -d "${REUSEBUILD}/${TIMESTAMP}" ] || mkdir "${REUSEBUILD}/${TIMESTAMP}"
940 [ -d "${REUSEBUILD}/${TIMESTAMP}" ] || return 255
945 local lnxrelnew=${lnxrel//-/_}
946 local EXTRA_VERSIONnew=${EXTRA_VERSION//-/_}
947 local KERNELRPMnew=$(basename "$KERNELRPM")
948 if [ ! "$rpmonly" = "rpmonly" ]; then
950 if [ ! "$KERNELCOMPILEDIR" = "" ]; then
951 builddir="$KERNELCOMPILEDIR"
953 builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/linux-${lnxmaj}"
954 [ "$KERNELCOMPILEDIR" = "" ] || builddir="$KERNELCOMPILEDIR"
955 [ -d "$builddir" ] || builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/linux-${lnxmaj}.${lnxrel}"
956 [ -d "$builddir" ] || builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/linux-${lnxmaj}-${lnxrel}"
957 if [ ! -d "$builddir" ]; then
958 pushd "BUILD/lustre-kernel-${lnxmaj}/lustre/" || return 255
959 local basebuilddir=$(ls -d linux-${lnxmaj}* | head -1)
960 [ "$basebuilddir" = "" ] || builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/${basebuilddir}"
964 [ -d "$builddir" ] || return 255
965 local dstdir="${REUSEBUILD}/${TIMESTAMP}/linux-${KERNCONFSMPTYPE}-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}"
966 ( $PATCHLESS ) && dstdir="${REUSEBUILD}/${TIMESTAMP}/linux-$KERNELRPMnew" && \
967 dstdir="${dstdir%.rpm}"
968 [ -d "$dstdir" ] && rm -rf "$dstdir"
969 mv "${builddir}" "$dstdir" || return 255
970 if [ -n "$OFED_VERSION" ]; then
971 # move the OFED kernel-ib-devel tree as well
972 mv "${builddir%/*}/kernel-ib-devel/usr/src/ofa_kernel" "${dstdir%/*}" || return 255
976 local kernelrpmname="kernel-lustre-${KERNCONFSMPTYPE}-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}.rpm"
977 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] || kernelrpmname="kernel-${KERNCONFSMPTYPE}-${lnxmaj}-${EXTRA_VERSNnew}.${TARGET_ARCH}.rpm"
978 ( $PATCHLESS ) && [ -f "$KERNELRPM" ] && kernelrpmname="$KERNELRPMnew"
979 if [ "$rpmonly" = "rpmonly" ] && [ -f "${REUSEBUILD}/${TIMESTAMP}/${kernelrpmname}" ]; then
980 echo "RPM already exist in store directory tree"
982 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] && cp -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" "${REUSEBUILD}/${TIMESTAMP}/"
984 #store kernel source rpm
985 kernelrpmname="kernel-lustre-source-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}.rpm"
986 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] || kernelrpmname="kernel-source-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}.rpm"
987 ( $PATCHLESS ) && [ -f "$KERNELSOURCERPM" ] && kernelrpmname=$(basename "$KERNELSOURCERPM")
988 if [ "$rpmonly" = "rpmonly" ] && [ -f "${REUSEBUILD}/${TIMESTAMP}/${kernelrpmname}" ]; then
989 echo "RPM already exist in store directory tree"
991 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] && cp -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" "${REUSEBUILD}/${TIMESTAMP}/"
993 if [ -n "$OFED_VERSION" ]; then
994 # store kernel-ib RPMs
996 for rpmname in "kernel-ib" "kernel-ib-devel"; do
997 rpmname="${rpmname}-${OFED_VERSION}"
999 rpmname="${rpmname}-${LINUXRELEASE//-/_}"
1001 rpmname="${rpmname}-${lnxmaj}${EXTRA_VERSION_DELIMITER//-/_}${EXTRA_VERSIONnew}${TARGET_DELIMITER//-/_}${KERNCONFSMPTYPE}"
1003 rpmname="${rpmname}.${TARGET_ARCH}.rpm"
1004 if [ "$rpmonly" = "rpmonly" ] && [ -f "${REUSEBUILD}/${TIMESTAMP}/${rpmname}" ]; then
1005 echo "RPM already exist in store directory tree"
1007 [ -f "RPMS/${TARGET_ARCH}/${rpmname}" ] && cp -f "RPMS/${TARGET_ARCH}/${rpmname}" "${REUSEBUILD}/${TIMESTAMP}/"
1015 local infact_arch=${TARGET_ARCH}
1017 [ "$infact_arch" == "i586" ] && infact_arch="i686"
1018 for smp_type in $SMP_ARCHS; do
1019 [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
1021 for smp_type in $BIGSMP_ARCHS; do
1022 [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
1026 #unpack kernel(/source/devel) RPM
1030 local delimiter=${2:-"-"}
1031 local pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
1032 local kernelbinaryrpm=
1033 [ -d $pathtorpms ] || return 255
1035 local wanted_kernel="${lnxmaj}${delimiter}${lnxrel}"
1036 for arch in $TARGET_ARCHS_ALL; do
1037 for rpm in ${pathtorpms}/${arch}/*.rpm; do
1038 local provides=$(rpm -q --provides -p $rpm)
1039 if (echo $provides | grep -q "kernel${prefix} = $wanted_kernel"); then
1043 [ -f "$KERNELRPM" ] && TARGET_ARCH="$arch" && BUILD_ARCHS="$arch" && break
1049 [ -f "$KERNELRPM" ] || return 255
1050 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused
1051 pushd $TOPDIR/reused || return 255
1053 rpm2cpio < "$KERNELRPM" | cpio -idc > /dev/null 2>&1
1054 if [ ${PIPESTATUS[0]} -eq 0 ]; then
1055 # RHEL-style and SLES-style rpms
1056 local paths="kernels/${lnxmaj}${delimiter}${lnxrel}-${TARGET_ARCH} linux-${lnxmaj}${delimiter}${lnxrel}"
1058 for path in $paths; do
1061 if [ -d "$src/$path/" ]; then
1062 LINUX="$(pwd)/$src/$path"
1064 # SLES has a separate -obj tree
1065 if [ -d "$src/${path}-obj" ]; then
1066 src="$src/${path}-obj"
1067 local objects="$TARGET_ARCH/$RPMSMPTYPE"
1069 # Novell, are you *TRYING* to make life hard for me?
1070 if [ -d "$src/powerpc" ]; then
1071 objects="powerpc/$TARGET_ARCH"
1072 elif [ $TARGET_ARCH == 'i686' ]; then
1073 objects="i386/$RPMSMPTYPE"
1076 LINUXOBJ="$(pwd)/$src/$objects"
1079 if [ -z "$LINUX" ]; then
1082 # dig out the release version
1083 local LINUXRELEASEHEADER=version.h
1084 if test -s ${LINUXOBJ:-$LINUX}/include/linux/utsrelease.h ; then
1085 LINUXRELEASEHEADER=utsrelease.h
1087 LINUXRELEASE=$(sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' ${LINUXOBJ:-$LINUX}/include/linux/$LINUXRELEASEHEADER)
1088 if [ -z "$LINUXRELEASE" ]; then
1089 echo "Failed to find linux release in ${LINUXOBJ:-$LINUX}/include/linux/$LINUXRELEASEHEADER"
1100 #look for kernel source RPM
1101 find_linux_source_rpm()
1107 [ ! "$TARGET_ARCH" = "" ] && arch=$TARGET_ARCH && findarch=false
1109 if ! $findarch; then
1110 pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${arch}"
1111 [ -d $pathtorpms ] || return 255
1114 rpmfile="kernel-${lnxmaj}-${lnxrel}.src.rpm"
1117 rpmfile="kernel-source-${lnxmaj}.${lnxrel}.${arch}.rpm"
1120 rpmfile="kernel-source-${lnxmaj}-${lnxrel}.${arch}.rpm"
1123 [ -f "${pathtorpms}/${rpmfile}" ] || return 255
1124 KERNELSOURCERPM="${pathtorpms}/${rpmfile}"
1126 for arch in $TARGET_ARCHS_ALL; do
1127 pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${arch}"
1128 [ -d $pathtorpms ] || continue
1131 rpmfile="kernel-${lnxmaj}-${lnxrel}.src.rpm"
1134 rpmfile="kernel-source-${lnxmaj}.${lnxrel}.${arch}.rpm"
1137 rpmfile="kernel-source-${lnxmaj}-${lnxrel}.${arch}.rpm"
1140 [ -f "${pathtorpms}/${rpmfile}" ] || continue
1141 KERNELSOURCERPM="${pathtorpms}/${rpmfile}"
1146 [ -f "${KERNELSOURCERPM}" ] || return 255
1149 #unpack and make symlinks for reusing kernel RPM
1153 local pathtokernelibrpm=$2
1154 [ "$pathtorpm" = "" ] && return 255
1155 [ -f "$pathtorpm" ] || return 255
1156 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused
1157 pushd $TOPDIR/reused || return 255
1159 rpm2cpio < $pathtorpm | cpio -idc
1160 [ ${PIPESTATUS[0]} -eq 0 ] || return 255
1162 if [ -n "$pathtokernelibrpm" ] && [ -f "$pathtokernelibrpm" ]; then
1163 rpm2cpio < $pathtokernelibrpm | cpio -idc
1164 [ ${PIPESTATUS[0]} -eq 0 -o ${PIPESTATUS[1]} -eq 0 ] || return 255
1165 CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
1169 if pushd usr/src/linux-*-obj/${TARGET_ARCH}; then
1170 local smptypes="$SMPTYPES"
1171 [ "$RPMSMPTYPE" = "" ] || smptypes=$RPMSMPTYPE
1172 ( ! $PATCHLESS ) && [ ! "$KERNCONFSMPTYPE" = "" ] && smptypes="$KERNCONFSMPTYPE"
1174 for cursmptype in $smptypes; do
1175 [ "$cursmptype" = "''" ] && continue
1176 [ -d $cursmptype ] && smptype=$cursmptype
1177 [ -d $smptype ] && break
1181 if [ "${smptype}" = "" ]; then
1183 return 255 # cannot detect smp type
1185 if pushd usr/src/linux-*-obj/${TARGET_ARCH}/$smptype/include2; then
1186 local base=$(readlink asm)
1187 if [ ! -d "/${base}/" ]; then
1189 base=$(basename "$base")
1190 if pushd ../../../../linux-*/include; then
1193 [ -d "$lsrc/${base}" ] && ln -s $lsrc/${base} asm
1197 read a b < <(echo $(pwd)/usr/src/linux-*)
1198 if [[ $a == $(pwd)/* && $b = $(pwd)/* ]]; then
1199 cp -f $a/include/linux/config.h $b/${TARGET_ARCH}/$smptype/include/linux/
1200 cp $b/${TARGET_ARCH}/$smptype/.config $a/
1201 [ -f "$b/${TARGET_ARCH}/$smptype/.config" ] && KERNELRPMCONFIG="$b/${TARGET_ARCH}/$smptype/.config"
1202 cp $b/${TARGET_ARCH}/$smptype/.kernelrelease $a/
1203 [ -f "$b/${TARGET_ARCH}/$smptype/.kernelrelease" ] && KERNELRPMRELEASE="$b/${TARGET_ARCH}/$smptype/.kernelrelease"
1205 LINUXOBJ=$b/${TARGET_ARCH}/$smptype
1206 # local fname=$(basename $kernel_rpm)
1207 # KERNELRPMSDIR=${kernel_rpm%$fname}
1211 [ "$LINUX" = "" ] && return 255
1212 [ -d "$LINUX" ] || return 255
1215 #build linux kernel rpm
1218 pushd $LINUX || return 255
1219 make binrpm-pkg || ( popd ; return 255 )
1221 [ -f ".version" ] && addlnxrel="-$(cat .version)"
1224 for arch in $TARGET_ARCHS_ALL; do
1225 [ -f "/usr/src/rpm/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" ] && \
1226 KERNELRPM="/usr/src/rpm/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" && \
1228 [ -f "/usr/src/packages/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" ] && \
1229 KERNELRPM="/usr/src/packages/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" && \
1232 [ "$KERNELRPM" = "" ] || return
1240 local nocopykernel=$2
1241 pushd $LINUX || fatal 1 "Kernel source not found"
1242 [ "$nofullmake" = "nofullmake" ] || make mrproper
1243 [ "$nofullmake" = "nofullmake" ] || rm -f rpm-release
1244 # [ "$nocopykernel" = "copyrpmkernel" ] || rm -f localversion-*
1245 [ "$nocopykernel" = "copykernel" ] && [ -f "$CONFIG_FILE" ] && cp $CONFIG_FILE .config
1246 if [ "$nocopykernel" = "copyrpmkernel" ]; then
1247 [ -f "$KERNELRPMCONFIG" ] && cp $KERNELRPMCONFIG .config
1248 if [ -f "$KERNELRPMRELEASE" ]; then
1249 cp $KERNELRPMRELEASE .
1251 sed -e "s/^EXTRAVERSION\s\+=\s\+.*$/EXTRAVERSION = -${lnxrel}/" < Makefile > Makefile.new
1252 [ -f "Makefile.new" ] && mv Makefile.new Makefile
1255 [ -f ".config" ] || ( popd ; echo "Cannot find .config file"; return 255 )
1256 make oldconfig || ( popd ; return 255 )
1257 make include/linux/version.h
1258 if [ ! "$nofullmake" = "nofullmake" ]; then
1259 make || ( popd ; return 255 )
1267 # build kernel-ib{,-devel}
1268 # some I/B drivers are architecture dependent and kernel-ib's configure
1269 # does not figure it out for us ~sigh~
1270 local configure_options=""
1271 case "$TARGET_ARCH" in
1273 configure_options="--with-ipath_inf-mod"
1276 configure_options="--with-ipath_inf-mod --with-ehca-mod"
1279 $RPMBUILD --rebuild --define 'build_kernel_ib 1' --define 'build_kernel_ib_devel 1' \
1280 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1281 --define "KVERSION ${LINUXRELEASE}" \
1282 --define "KSRC ${LINUXOBJ:-${LINUX}}" \
1283 --define "LIB_MOD_DIR /lib/modules/${LINUXRELEASE}/updates" \
1284 --define "configure_options --without-quilt --with-core-mod --with-user_mad-mod --with-user_access-mod --with-addr_trans-mod --with-srp-target-mod --with-core-mod --with-mthca-mod --with-mlx4-mod --with-cxgb3-mod --with-nes-mod --with-ipoib-mod --with-sdp-mod --with-srp-mod --without-srp-target-mod --with-rds-mod --with-iser-mod --with-qlgc_vnic-mod --with-madeye-mod $configure_options" ${TOPDIR}/OFED/SRPMS/ofa_kernel-${OFED_VERSION}-ofed${OFED_VERSION}.src.rpm
1286 if [ ${PIPESTATUS[0]} != 0 ]; then
1287 fatal 1 "Error building kernel-ib"
1290 pushd "$TOPDIR" >/dev/null
1291 rm -rf kernel-ib-devel
1292 mkdir kernel-ib-devel
1294 local rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${OFED_VERSION}-${LINUXRELEASE//-/_}.*.rpm)
1295 rpm2cpio -itv < $rpm | cpio -id
1296 CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
1300 #build patchless lustre
1301 patchless_build_sequence()
1303 #try to build from kernel-devel RPM (RHEL)
1306 local rpmfound=false
1307 local buildsuccess=false
1308 local storeforreuse=false
1309 if [ "$KERNELRPMSBASE" = "" ] || [ ! -d "$KERNELRPMSBASE" ]; then
1312 [ -d $TOPDIR/reused ] && rm -rf $TOPDIR/reused
1314 local delimiter=${EXTRA_VERSION_DELIMITER:-"-"}
1315 # default to source type -source and special case below
1323 unpack_linux_rpm $type $delimiter && rpmfound=true
1325 [ -d SRPMS ] || mkdir SRPMS
1326 [ -d RPMS ] || mkdir RPMS
1327 [ -d BUILD ] || mkdir BUILD
1328 [ -d SOURCES ] || mkdir SOURCES
1330 # first build kernel-ib
1331 if [ -n "$OFED_VERSION" ]; then
1332 $rpmfound && build_kernel_ib
1334 ( $rpmfound ) && build_lustre && buildsuccess=true && find_linux_source_rpm
1336 if $buildsuccess; then
1337 [ -d "RPMS/${TARGET_ARCH}" ] && [ -f "$KERNELRPM" ] && \
1338 cp "$KERNELRPM" RPMS/${TARGET_ARCH}/
1339 [ -d "RPMS/${TARGET_ARCH}" ] && [ -f "$KERNELSOURCERPM" ] && \
1340 cp "$KERNELSOURCERPM" RPMS/${TARGET_ARCH}/
1341 KERNELCOMPILEDIR="$LINUX"
1342 if $storeforreuse; then
1343 store_for_reuse || echo "Cannot store for future reuse"
1347 elif ! $rpmfound; then
1348 echo "COULD NOT FIND VENDOR -devel or -source RPM for $DISTRO/$TARGET_ARCH: $lnxmaj-$lnxrel in $KERNELRPMSBASE"
1351 echo "Patchless build failed."
1356 #check timestamp value. should bi 14-digits string
1360 local timestampnodig=$(echo $invalue | sed -e s/[0-9]*//g)
1361 [ "$timestampnodig" = "" ] || return 255
1362 local timestamplength="${#invalue}"
1363 [ $timestamplength -eq 14 ] || return 255
1366 # get list of suitable directories with potential reused staff
1367 get_reuse_dir_list()
1370 local reusedkernelmasknew=$2
1371 local buildtimestamp=
1373 local sourcelastdate=$(get_last_source_date)
1374 for buildtimestamp in $(ls "$REUSEBUILD/" 2>&1); do
1375 [ -d "$REUSEBUILD/$buildtimestamp" ] || continue
1376 check_timestamp "$buildtimestamp" || continue
1377 local buildtimestampstr=$(echo $buildtimestamp | \
1378 sed -e "s^\(....\)\(..\)\(..\)\(..\)\(..\)\(..\)^\1-\2-\3 \4:\5:\6 GMT^g")
1379 local buildtimestampepoch=$(date --date="$buildtimestampstr" +%s )
1380 #check for suitable date
1381 if ! $PATCHLESS; then
1382 [ $buildtimestampepoch -ge $sourcelastdate ] || continue
1384 #check for suitable version
1385 if [ "$rpmonly" = "rpmonly" ]; then
1386 local reusedkernelprefix="kernel-lustre-"
1387 ( $PATCHLESS ) && reusedkernelprefix=
1388 local rpmmask="${reusedkernelprefix}${REUSEDKERNELMASK}"
1389 [ "$reusedkernelmasknew" = "" ] || rpmmask="$reusedkernelmasknew"
1390 [ -f $REUSEBUILD/$buildtimestamp/${rpmmask}.rpm ] && \
1391 dirsforreuse="$dirsforreuse $REUSEBUILD/$buildtimestamp"
1393 local rpmmask="$REUSEDKERNELMASK"
1394 [ "$reusedkernelmasknew" = "" ] || rpmmask="$reusedkernelmasknew"
1395 pushd $REUSEBUILD/$buildtimestamp/linux-${rpmmask} > /dev/null 2>&1 || continue
1397 dirsforreuse="$dirsforreuse $curdir"
1401 echo "$dirsforreuse"
1404 #try to reuse old RPM
1405 build_sequence_rpm_reuse()
1408 [ "$REUSERPM" = "" ] && [ "$REUSEBUILD" = "" ] && return 255
1410 if ! [ "$REUSEBUILD" = "" ] && [ -d "$REUSEBUILD" ]; then #try to reuse RPM
1411 local REUSEDKERNELMASKnew=$(echo $REUSEDKERNELMASK | sed -e "s/^[^0-9]*//")
1412 REUSEDKERNELMASKnew="kernel-lustre-source-${REUSEDKERNELMASKnew}"
1413 local dirsforreuse="$(get_reuse_dir_list rpmonly $REUSEDKERNELMASKnew)"
1414 local buildsuccess=false
1416 for curdir in $(echo $dirsforreuse); do
1417 [ -d "$curdir" ] || continue
1418 local reusedkernelprefix="kernel-lustre-"
1419 local reusedkernelrpm=
1420 [ -f ${curdir}/${reusedkernelprefix}${REUSEDKERNELMASK}.rpm ] && \
1421 reusedkernelrpm=$(ls ${curdir}/${reusedkernelprefix}${REUSEDKERNELMASK}.rpm | head -1 )
1422 [ -f "$reusedkernelrpm" ] || continue
1424 local reusedkernelsourcerpm=
1425 [ -f ${curdir}/${REUSEDKERNELMASKnew}.rpm ] && \
1426 reusedkernelsourcerpm=$(ls ${curdir}/${REUSEDKERNELMASKnew}.rpm | head -1 )
1427 [ -f "$reusedkernelsourcerpm" ] || continue
1429 # don't need to check for kernel-ib RPM reuse here because sles9 is not supported
1430 # by OFED >= 1.3.0 and this function appears to only be used for sles9
1432 [ -d $TOPDIR/reused ] && rm -rf $TOPDIR/reused
1433 reuse_kernel_rpm "$reusedkernelsourcerpm" "" && build_linux nofullmake copyrpmkernel && build_lustre && buildsuccess=true
1434 ( $buildsuccess ) || continue
1435 if ( ! $NORPM ) && ( ! $PATCHLESS ) ; then
1436 [ -f "$reusedkernelrpm" ] && \
1437 cp -f "$reusedkernelrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
1439 [ -f "$reusedkernelsourcerpm" ] && \
1440 cp -f "$reusedkernelsourcerpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1 && \
1441 touch RPMS/${TARGET_ARCH}/kernel_was_reused
1449 #try to reuse old BUILD dir
1450 build_sequence_reuse()
1453 [ "$REUSERPM" = "" ] && [ "$REUSEBUILD" = "" ] && return 255
1455 if [ ! "$REUSEBUILD" = "" ] && [ -d "$REUSEBUILD" ]; then #try to reuse old kernel build directory
1456 local dirsforreuse="$(get_reuse_dir_list)"
1457 local buildsuccess=false
1459 local REUSEDKERNELMASKnew=$(echo $REUSEDKERNELMASK | sed -e "s/^[^0-9]*//")
1460 for curdir in $(echo $dirsforreuse); do
1461 local reusedkernelrpm=
1462 local reusedkernelsourcerpm=
1463 local reusedkernelibrpm=
1464 [ -d "$curdir" ] || continue
1465 [ -n "$OFED_VERSION" -a ! -d "${curdir%/*}/ofa_kernel" ] && continue
1466 local reusedkernelprefix="kernel-lustre-"
1467 ( $PATCHLESS ) && reusedkernelprefix=
1468 [ -f ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASK}.rpm ] && \
1469 reusedkernelrpm=$(ls ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASK}.rpm | head -1 )
1470 reusedkernelprefix="kernel-lustre-source-"
1471 [ -f ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASKnew}.rpm ] && \
1472 reusedkernelsourcerpm=$(ls ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASKnew}.rpm | head -1 )
1473 if [ -n "$OFED_VERSION" ]; then
1475 reusedkernelprefix="kernel-ib-"
1476 [ -f ${curdir}/../${reusedkernelprefix}${OFED_VERSION}-${LUSTRE_EXTRA_VERSION}.${TARGET_ARCH}.rpm ] && \
1477 reusedkernelibrpm=$(ls ${curdir}/../${reusedkernelprefix}${OFED_VERSION}-${LUSTRE_EXTRA_VERSION}.${TARGET_ARCH}.rpm | head -1 )
1478 reusedkernelibdevelrpm=$(ls ${curdir}/../${reusedkernelprefix}devel-${OFED_VERSION}-${LUSTRE_EXTRA_VERSION}.${TARGET_ARCH}.rpm | head -1 )
1480 if ! ( $NORPM ) && ! [ -f "$reusedkernelrpm" ]; then #kernel rpm not found. Build all
1483 if ! ( $NORPM ) && ! [ -f "$reusedkernelsourcerpm" ]; then #kernel source rpm not found. Build all
1486 if [ -n "$OFED_VERSION" ]; then
1487 if ! ( $NORPM ) && [ ! -f "$reusedkernelibrpm" -o ! -f "$reusedkernelibdevelrpm"]; then #kernel-ib{,-devel} rpm not found. Build all
1490 CONFIGURE_FLAGS="--with-o2ib=${curdir%/*}/ofa_kernel ${CONFIGURE_FLAGS}"
1493 build_lustre || continue
1496 if ( ! $NORPM ) && ( ! $PATCHLESS ) ; then
1497 [ -f "$reusedkernelrpm" ] && \
1498 cp -f "$reusedkernelrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1 && \
1499 touch RPMS/${TARGET_ARCH}/kernel_was_reused
1500 [ -f "$reusedkernelsourcerpm" ] && \
1501 cp -f "$reusedkernelsourcerpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
1502 [ -f "$reusedkernelibrpm" ] && \
1503 cp -f "$reusedkernelibrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
1504 cp -f "$reusedkernelibdevelrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
1515 if (( $DO_SRC )) ; then
1521 prep_kernel_build || return 255
1522 clean_lustre || return 255
1524 build_kernel || return 255
1527 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1529 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,publish,release,src,stage:,tag:,target:,target-archs:,with-linux: -- "$@")
1531 if [ $? != 0 ] ; then
1535 eval set -- "$options"
1573 --linux | --with-linux)
1648 --disable-datestamp)
1655 CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-liblustre --enable-liblustre-tests"
1659 usage 1 "Unrecognized option: $1"
1669 EXTRA_VERSION_DELIMITER=${EXTRA_VERSION_DELIMITER:-"-"}
1671 if [ -n "$OFED_VERSION" ]; then
1677 patchless_build_sequence && build_success=true
1678 elif [ -z "$LINUX" ] ; then
1679 [ "$DISTRO" = "sles9" ] && build_sequence_rpm_reuse && build_success=true
1680 if ! $build_success; then
1681 build_sequence_reuse && build_success=true
1682 if ! $build_success; then
1683 build_sequence && build_success=true
1684 if $build_success; then
1685 store_for_reuse || echo "Cannot store for future reuse"
1690 build_lustre && build_success=true
1692 ( $build_success ) || fatal 1 "Cannot build lustre"