Whamcloud - gitweb
LU-3466 iokit: Make lustre-iokit a subpackage of lustre
[fs/lustre-release.git] / contrib / lbuild / lbuild
index bf424ee..575bd37 100755 (executable)
@@ -33,11 +33,11 @@ push_exit_trap "kill -INT -$$ || true" kill_children
 #BUILD_GEN=2   # bz19952: remove -lustre tag from kernel RPM names
 #BUILD_GEN=3   # bz19975: enable the building of src.rpms by default
 #BUILD_GEN=4   # bz22281: use the git hash in the kernel extra version
-BUILD_GEN=5    # TT-107: don't cache the BUILD dir
+#BUILD_GEN=5   # TT-107: don't cache the BUILD dir
+BUILD_GEN=6    # TT-1092: don't cache the BUILD dir, to rebuild external OFED
 
 TOPDIR=$PWD
 
-# CVSROOT is inherited from the environment
 KERNELDIR=
 LINUX=
 LUSTRE=
@@ -47,7 +47,6 @@ RELEASE=false
 #       simply don't account for this option
 DO_SRC=true
 DOWNLOAD=true
-TAG=
 CANONICAL_TARGET=
 TARGET=
 TARGET_ARCH="$(uname -m)"
@@ -71,10 +70,8 @@ USE_BUILD_CACHE=true
 # what does this do exactly?  does it imply no kernel build?
 NORPM=false
 IOKITRPM=true
-LDISKFSRPM=true
 OSDLDISKFSRPM=true
 OSDZFSRPM=false
-SKIPLDISKFSRPM="v1_4_* b1_4"
 SMPTYPES="smp bigsmp default ''"
 PATCHLESS=false
 XEN=false
@@ -109,7 +106,6 @@ LUSTRE_TESTS=true
 
 DATE=$(date)
 
-USE_DATESTAMP=1
 RPMBUILD=
 
 export CC=${CC:-gcc}
@@ -130,11 +126,6 @@ usage() {
     cat <<EOF
 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
 
-  -d CVSROOT
-    Specifies the CVS Root to use when pulling files from CVS.  The
-    environment variable \$CVSROOT is used if this option is not
-    present.
-
   --external-patches=EXTERNAL_PATCHES
     Directory similar to lustre/lustre/kernel_patches/ that lbuild should
     look for seres and config files in before looking in the lustre
@@ -180,8 +171,7 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     Lustre modules and userspace are built.
 
   --lustre=LUSTRE
-    Path to an existing lustre source tarball to use instead of
-    pulling from CVS.
+    Path to an existing lustre source tarball to use.
 
   --nodownload
     Do not try to download a kernel from downloads.lustre.org
@@ -191,7 +181,7 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     tarball.
 
   --ldiskfs
-    Do ldiskfs RPM. Now true by default
+    Build with ldiskfs support. (Deprecated, always true)
 
   --noiokit
     Do not build lustre-iokit RPM. Now true by default
@@ -211,9 +201,6 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     more or less in DIR/<target>-<arch>, and the tarball will be
     placed in DIR.
 
-  --tag=TAG
-    A CVS branch/tag name to build from when pulling from CVS.
-
   --target=TARGET
     The name of the target to build.  The available targets are listed
     below.
@@ -228,16 +215,11 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     Also note that by using a non-"base" arch (eg, i386) only kernels
     will be built - there will be no lustre-lite-utils package.
 
-  --disable-datestamp
-    Prevents the datestamp flag (-D) from being passed to cvs for
-    checkouts. This is a workaround for a problem encountered when
-    using lbuild with tinderbox.
-
   --xen
     Builds a Xen domX kernel.
 
   --set-value
-    Set's a variable to a given value.
+    Sets a variable to a given value.
 
 EOF
 
@@ -279,14 +261,8 @@ canon_path() {
 
 check_options() {
 
-    if [ "$LUSTRE" ]; then
-        [ -r "$LUSTRE" ] || \
-            usage 1 "Could not find Lustre source tarball '$LUSTRE'."
-    else
-        [ "$CVSROOT" ] || \
-            usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
-        [ "$TAG" ] || \
-            usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
+    if [ -z "$LUSTRE" -o ! -r "$LUSTRE" ]; then
+        usage 1 "Could not find Lustre source tarball '$LUSTRE'."
     fi
 
     [ -z "$DISTRO" ] && DISTRO=$(autodetect_distro)
@@ -298,11 +274,6 @@ check_options() {
         [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
             usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
 
-        if ! $RELEASE; then
-            [ "$TAG" ] || \
-                usage 1 "When building a snapshot, a tag name must be used."
-        fi
-
         [ "$TARGET" ] || TARGET=$(autodetect_target "$DISTRO")
 #       TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
 #       [ -r "$TARGET_FILE" ] || \
@@ -567,9 +538,9 @@ download_ofed() {
 
     local location="http://www.openfabrics.org/downloads/OFED/ofed-${OFED_BASE_VERSION}/"
 
-    if [[ $OFED_VERSION = *-rc[0-9] ]]; then
+    if [[ $OFED_VERSION = *-[rR][cC][0-9] ]]; then
         local Mmv
-        Mmv=${OFED_VERSION%%-*}
+        Mmv=${OFED_VERSION%%-[rR][cC][0-9]}
         location="http://www.openfabrics.org/downloads/OFED/ofed-${Mmv}/"
     fi
 
@@ -649,7 +620,7 @@ load_target() {
     fi
 
     if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
-        CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH${RPMSMPTYPE:+-}${RPMSMPTYPE}.config"
+        CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config"
     fi
 
     local lnxrelnew=${lnxrel//-/_}
@@ -671,7 +642,6 @@ load_target() {
         # kernel.  don't make it look like one
         if $PATCHLESS || [ -n "$SERIES" ]; then
             EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
-#            EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
             if ! $PATCHLESS && [ -n "$BUILDID" ]; then
                 EXTRA_VERSION="${EXTRA_VERSION}.${BUILDID}"
             fi
@@ -736,29 +706,6 @@ unpack_ofed() {
 
 unpack_lustre() {
 
-    if [ -z "$LUSTRE" ]; then
-        local DATESTAMP=""
-
-        if [ -n "$USE_DATESTAMP" ]; then
-            DATESTAMP="-D '$DATE'"
-        fi
-
-        local DIRNAME="lustre-$TAG-$TIMESTAMP"
-
-        cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
-            fatal 1 "There was an error checking out toplevel Lustre from CVS."
-        pushd "$DIRNAME" > /dev/null
-        ./lustrecvs "$TAG" || \
-            fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
-        echo "Creating lustre tarball..."
-        sh autogen.sh || fatal 1 "There was an error running autogen.sh."
-        ./configure --enable-dist || \
-            fatal 1 "There was an error running ./configure to create makefiles."
-        make dist || fatal 1 "There was an error running 'make dist'."
-        LUSTRE=$PWD/lustre-*.tar.gz
-        popd > /dev/null
-    fi
-
     untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
     [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
 
@@ -801,39 +748,6 @@ do_patch_linux() {
 
 }
 
-build_iokit() {
-    local rpmbuildopt="$1"
-
-    pushd lustre-iokit > /dev/null || return 255
-
-    if ! ./configure; then
-        echo "failed to configure in lustre-iokit"
-        popd >/dev/null # pushd lustre-iokit
-        return 255
-    fi
-
-    if ! make dist; then
-        echo "failed to make dist in lustre-iokit"
-        popd >/dev/null # pushd lustre-iokit
-        return 255
-    fi
-
-    if ! $RPMBUILD $rpmbuildopt lustre-iokit*.tar.gz \
-        --define "_tmppath /var/tmp" \
-        --define "_topdir $TOPDIR" 2>&1; then
-        popd >/dev/null # pushd lustre-iokit
-        return 255
-    fi
-
-    if $DO_SRC && ! $RPMBUILD -ts lustre-iokit*.tar.gz \
-            --define "_tmppath /var/tmp" \
-            --define "_topdir $TOPDIR" 2>&1; then
-            popd >/dev/null # pushd lustre-iokit
-            return 255
-    fi
-    popd >/dev/null # pushd lustre-iokit
-}
-
 build_lustre() {
     local linux="$1"
     local linuxobj="$2"
@@ -871,67 +785,6 @@ build_lustre() {
         fi
     fi
 
-    ( $(skeep_ldiskfs_rpm $TAG) ) || {
-
-        pushd ldiskfs > /dev/null || return 255
-
-        if !  ./configure --enable-dist; then
-            echo "failed to configure in ldiskfs"
-            popd >/dev/null # pushd ldiskfs
-            popd >/dev/null # pushd lustre
-            return 255
-        fi
-
-        if ! make dist 2>&1; then
-            popd >/dev/null # pushd ldiskfs
-            popd >/dev/null # pushd lustre
-            return 255
-        fi
-
-        #cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES || \
-        #    fatal 1 "Could not copy lustre-ldiskfs*.tar.gz to $TOPDIR/SOURCES"
-
-        if ! $RPMBUILD $targets $rpmbuildopt lustre-ldiskfs*.tar.gz \
-            --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \
-            --define "kdir $linux" \
-            ${linuxobj:+--define "kobjdir $linuxobj"} \
-            --define "_tmppath /var/tmp" \
-            --define "_topdir $TOPDIR" 2>&1; then
-            popd >/dev/null # pushd ldiskfs
-            popd >/dev/null # pushd lustre
-            return 255
-        fi
-
-        if $DO_SRC; then
-            if ! $RPMBUILD -ts lustre-ldiskfs*.tar.gz \
-                --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \
-                --define "kdir $linux" \
-                ${linuxobj:+--define "kobjdir $linuxobj"} \
-                --define "_tmppath /var/tmp" \
-                --define "_topdir $TOPDIR" 2>&1; then
-                popd >/dev/null # pushd ldiskfs
-                popd >/dev/null # pushd lustre
-                return 255
-            fi
-        fi
-        popd >/dev/null # pushd ldiskfs
-
-        # tell lustre where ldiskfs is
-        # XXX - pointing to the RPM BUILD dir is a hack.  we need to flesh
-        #       out the ldiskfs RPM build so that it builds a
-        #       lustre-ldiskfs-devel RPM and install that and point lustre
-        #       to that instead
-        confoptions="$confoptions --with-ldiskfs=$(ls -d $TOPDIR/BUILD/lustre-ldiskfs-*)"
-    }
-
-    if $IOKITRPM; then
-        if ! build_iokit $rpmbuildopt; then
-            echo "failed to build lustre-iokit"
-            popd >/dev/null # pushd lustre
-            return 255
-        fi
-    fi
-
     # convert the $PATCHLESS boolean to an empty/not-empty boolean
     # as silly as this seems, it makes the syntax of the rpmbuild command
     # simpler and not need an eval to deal with the quotes in the quotes
@@ -946,6 +799,11 @@ build_lustre() {
         lustre_tests="no"
     fi
 
+    local lustre_iokit=""
+    if ! $IOKITRPM; then
+        lustre_iokit="no"
+    fi
+
     local osd_zfs=""
     if $OSDZFSRPM; then
         osd_zfs="yes"
@@ -957,10 +815,11 @@ build_lustre() {
     fi
 
     $RPMBUILD $targets $rpmbuildopt "$LUSTRE" \
-        ${is_patchless:+--define "lustre_name lustre-client"} \
-        ${lustre_tests:+--define "build_lustre_tests 0"} \
-        ${osd_zfs:+--define "build_lustre_osd_zfs 1"} \
-        ${osd_ldiskfs:+--define "build_lustre_osd_ldiskfs 1"} \
+        ${is_patchless:+--without servers} \
+        ${lustre_tests:+--without lustre_tests} \
+        ${lustre_iokit:+--without lustre_iokit} \
+        ${osd_zfs:+--with zfs} \
+        ${osd_ldiskfs:+--with ldiskfs} \
         ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
         --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \
         --define "kdir $linux" \
@@ -971,8 +830,9 @@ build_lustre() {
 
     if $DO_SRC; then
         if ! $RPMBUILD -ts "$LUSTRE" \
-                 ${is_patchless:+--define "lustre_name lustre-client"} \
-                 ${lustre_tests:+--define "build_lustre_tests 0"} \
+                 ${is_patchless:+--without servers} \
+                 ${lustre_tests:+--without lustre_tests} \
+                 ${lustre_iokit:+--without lustre_iokit} \
                  ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
                  --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \
                  --define "kdir $linux" \
@@ -992,36 +852,60 @@ build_lustre() {
 #
 # Fetch spl/zfs from the git repo and prepare for lustre build
 #
+# Overrides:
+#   SPLZFSGITREPO - URI of directory where spl.git and zfs.git are located
+#   SPLZFSTAG     - Tag to checkout of clone repositories
+#   SPLZFSVER     - Version to checkout of both (format zfs/spl-$SPLZFSVER)
+#
 # return 0 if successful, else 255
 build_spl_zfs() {
     # make sure the RPM build environment is set up
+    pushd $TOPDIR
     create_rpmbuild_dirs
+    popd
 
     # The spl/zfs spec files expect RPM_BUILD_ROOT to point to the root of the
     # destination for the rpms
     export RPM_BUILD_ROOT=$TOPDIR
+    SPLZFSVER=${SPLZFSVER:-0.6.2}
+    SPLZFSTAG=${SPLZFSTAG:-upstream-master}
 
     # The files expect a kver to be set to the kernel version .
-    kver=$(cat ${LINUX}/include/config/kernel.release)
+    local kver=$(find_linux_release)
 
     # build and install the spl and zfs (and -devel) RPMs for lustre to use
     local pkg
     for pkg in spl zfs; do
 
-        local rpmmod spldir
+        local rpmpkg
 
-        [ "$pkg" == "zfs" ] && spldir="$(ls -d $TOPDIR/usr/src/spl-*/*)"
-        rpmmod=$pkg-modules
+        [ "$pkg" == "zfs" ] && spldir="$(ls -d $TOPDIR/usr/src/spl-*/|tail -1)"
 
         # need to fetch the repo in order to build it.
         # default to github but allow override
         git clone ${SPLZFSGITREPO:-"https://github.com/zfsonlinux"}/$pkg.git $pkg 2>&1
 
         pushd $pkg || return 255
-
-        # XXX - _having_ to give a package a kernel just to have it configure
-        #       enough to do a "make dist" is truely bogus!
-        if  ! ./configure --with-linux=${LINUX} \
+       if [ -n "$SPLZFSTAG" ]; then
+           git checkout $SPLZFSTAG
+       else
+           git checkout -b lbuild $pkg-$SPLZFSVER
+       fi
+
+       # This differentiates between older zfs versions
+       if [ -f $pkg-modules.spec.in ]; then
+           rpmpkg=$pkg-modules
+           specdir=.
+           speclist="$pkg.spec $rpmpkg.spec"
+       else
+            rpmpkg=kmod-$pkg-devel
+           specdir=rpm/generic
+           speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec"
+       fi
+
+       sh autogen.sh || return 255
+
+        if  ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUXOBJ:-$LINUX} \
                           ${spldir:+--with-spl="${spldir}"} 2>&1 ||
             ! make dist 2>&1; then
             popd
@@ -1029,71 +913,67 @@ build_spl_zfs() {
         fi
         popd
 
-        # XXX - dirty hack time.  ~sigh~
-        #       because the spl tarball contains two .spec files, we cannot
-        #       simply rebuild the tarball
-        ln $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
-            error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
-
-        # First build the userspace tools RPMs
-        if ! $RPMBUILD $targets -bb $pkg/$pkg.spec \
-            --nodeps -v \
-            --define "configure_args ${CONFIGURE_FLAGS}" \
-            --define "_tmppath /var/tmp" \
-            --define "_topdir $TOPDIR" 2>&1; then
-            return 255
-        fi
-
-        if $DO_SRC; then
-            if ! $RPMBUILD -bs $pkg/$pkg.spec \
-                --nodeps -v \
-                --define "configure_args ${CONFIGURE_FLAGS}" \
-                --define "_tmppath /var/tmp" \
-                --define "_topdir $TOPDIR" 2>&1; then
-                return 255
+        ln -f $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
+           error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
+       if [ -f $pkg/scripts/kmodtool ]; then
+           ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/
+       fi
+
+       local rpmb
+       if $DO_SRC; then
+           rpmb=-ba
+       else
+           rpmb=-bb
+       fi
+
+       # set search dir for our own kmodtool to find correct
+       # directories
+       export KERNELSOURCE=$(dirname ${LINUX})
+       # Manually build rpms
+       for spec in $speclist; do
+           echo "Building RPMs from $pkg/$specdir/$spec"
+            if ! $RPMBUILD $rpmb $pkg/$specdir/$spec \
+               --nodeps -v \
+               --define "require_kdir ${LINUX}" \
+               ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \
+               ${spldir:+--define "require_spldir ${spldir}"} \
+               --define "kver $kver" \
+               --define "kernels $kver" \
+               --define "_tmppath /var/tmp" \
+               --define "kernelbuildroot $TOPDIR/reused" \
+               --define "_topdir $TOPDIR" 2>&1; then
+               return 255
             fi
-        fi
+       done
 
-        # Now the kernel module RPMs
-        # Need to provide pointers to the lustre kernel source, objects, usr/src
-        if ! $RPMBUILD $targets -bb $pkg/$rpmmod.spec \
-            --nodeps -v \
-            --define "require_kdir ${linux}" \
-            ${linuxobj:+--define "require_kobj ${linuxobj}"} \
-            ${spldir:+--define "require_spldir ${spldir}"} \
-            --define "configure_args ${CONFIGURE_FLAGS}" \
-            --define "_usrsrc $TOPDIR/usr/src" \
-            --define "kver $kver" \
-            --define "_tmppath /var/tmp" \
-            --define "_topdir $TOPDIR" 2>&1; then
-            return 255
-        fi
+#      $DO_SRC && mv $pkg*.src.rpm $TOPDIR/SRPMS/
+#      mv $pkg*.noarch.rpm $TOPDIR/RPMS/noarch/
+#      mv *$pkg*.$TARGET_ARCH.rpm $TOPDIR/RPMS/$(basearch $TARGET_ARCH)/
 
-        if $DO_SRC; then
-            if ! $RPMBUILD -bs $pkg/$rpmmod.spec \
-                --nodeps -v \
-                --define "require_kdir ${linux}" \
-                ${linuxobj:+--define "require_kobj ${linuxobj}"} \
-                ${spldir:+--define "require_spldir ${spldir}"} \
-                --define "configure_args ${CONFIGURE_FLAGS}" \
-                --define "_usrsrc $TOPDIR/usr/src" \
-                --define "kver $kver" \
-                --define "_tmppath /var/tmp" \
-                --define "_topdir $TOPDIR" 2>&1; then
-                return 255
-            fi
-        fi
-
-        # We have built the rpms for the package. No we need to extract the
+        # We have built the rpms for the package. Now we need to extract the
         # contained files so we can build further things against them
-        local rpm=$(ls $TOPDIR/RPMS/*/$rpmmod-devel-*.rpm)
+        local rpms=$(ls -1 $TOPDIR/RPMS/*/$rpmpkg-*.rpm)
 
         # cpio only extract to pwd so we need to go there.
         pushd $TOPDIR
-        rpm2cpio < $rpm | cpio -id
+       local rpm
+       for rpm in $rpms; do
+            rpm2cpio $rpm | cpio -id
+       done
+
+        if [ "$pkg" == "zfs" ]; then
+            mkdir -p $TOPDIR/zfsdevel
+            pushd $TOPDIR/zfsdevel
+            # We also need to extract zfs-devel rpm
+            local devel_rpm=$(ls -1 $TOPDIR/RPMS/*/$pkg-devel-*.rpm)
+            rpm2cpio $devel_rpm | cpio -id
+            popd
+            CONFIGURE_FLAGS="--with-$pkg-devel=$TOPDIR/zfsdevel ${CONFIGURE_FLAGS}"
+        fi
         popd
 
-        CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*/*) ${CONFIGURE_FLAGS}"
+        CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*/|tail -1) ${CONFIGURE_FLAGS}"
+        CONFIGURE_FLAGS="--with-$pkg-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
     done
 
     OSDZFSRPM=true
@@ -1119,26 +999,6 @@ stage() {
 
 }
 
-#check if we need to build separate ldiskfs RPM
-skeep_ldiskfs_rpm() {
-    local tag="$1"
-
-    local skip=false
-
-    if ! $LDISKFSRPM; then
-        skip=true
-    elif $PATCHLESS; then
-        skip=true
-    else
-        for skiptag in $SKIPLDISKFSRPM; do
-            [[ $tag == $skiptag ]] && skip=true && break
-        done
-    fi
-
-    echo $skip
-
-}
-
 set_rpm_smp_type() {
 
     local infact_arch="${TARGET_ARCH}"
@@ -1165,18 +1025,25 @@ set_rpm_smp_type() {
 
 }
 
-# This function takes a linux source pool and digs out the linux release
-# from it
-find_linux_release() {
-    local SRCDIR="$1"
+# This function takes a linux include tree and digs out the linux release
+# from it. It is never called directly, only called from the distro
+# specific function find_linux_release() in lbuild-{rhel,sles}.
+_find_linux_release() {
+    local SRC="$1"
+    local LINUXRELEASEHEADER=""
 
-    local LINUXRELEASEHEADER=$SRCDIR/include/linux/version.h
-    if [ -s $SRCDIR/include/linux/utsrelease.h ]; then
-        LINUXRELEASEHEADER=$SRCDIR/include/linux/utsrelease.h
+    LINUXRELEASEHEADER=$SRC/include/linux/version.h
+    if [ -s $SRC/include/generated/utsrelease.h ]; then
+        LINUXRELEASEHEADER=$SRC/include/generated/utsrelease.h
+    elif [ -s $SRC/include/linux/utsrelease.h ]; then
+        LINUXRELEASEHEADER=$SRC/include/linux/utsrelease.h
     fi
 
-    sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
+    if [ ! -s $LINUXRELEASEHEADER ]; then
+        fatal 1 "could not find UTS_RELEASE"
+    fi
 
+    sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
 }
 
 # unpack kernel(/source/devel) RPM
@@ -1254,12 +1121,12 @@ build_kernel_ib() {
     local SOURCE="${TOPDIR}/OFED/SRPMS/${kib_prefix}-*.src.rpm"
 
     # but switch to building from the SPEC if we need to apply patches
-    if ls ${TOPDIR}/lustre/build/patches/ofed/* >/dev/null; then
+    if ls ${TOPDIR}/lustre/contrib/patches/ofed/* >/dev/null; then
         BUILD_TYPE="-bb"
         rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
         SOURCE="${TOPDIR}/SPECS/${kib_prefix}.spec"
         local file ed_fragment1 ed_fragment2 n=1
-        for file in $(ls ${TOPDIR}/lustre/build/patches/ofed/*.patch); do
+        for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.patch); do
             ed_fragment1="$ed_fragment1
 Patch$n: ${file%%*/}"
             ed_fragment2="$ed_fragment2
@@ -1267,10 +1134,20 @@ Patch$n: ${file%%*/}"
             cp $file ${TOPDIR}/SOURCES
             let n=$n+1
         done
-        for file in $(ls ${TOPDIR}/lustre/build/patches/ofed/*.ed); do
-            ed_fragment3="$ed_fragment3
+        for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.ed); do
+            # Only apply the ed-scripts that should be used for the canonical target
+            # ed-files in ${TOPDIR}/lustre/contrib/patches/ofed/ have to follow the naming
+            # convention
+            # <two-digits>-<descriptive-name>:<canonical_target_1>: ...:<canonical_target_N>.ed
+            # To apply the same change to multiple canonical target simply specify
+            # a list of colon separated canoncial target names in the file name.
+            echo "$file" | grep -q -e ":${CANONICAL_TARGET}:" \
+                                   -e ":${CANONICAL_TARGET}.ed$"
+            if [ $? -eq 0 ] ; then
+                ed_fragment3="$ed_fragment3
 $(cat $file)"
-            let n=$n+1
+                let n=$n+1
+            fi
         done
 
         if [ $n -gt 1 ]; then
@@ -1287,7 +1164,7 @@ EOF
         fi
     fi
 
-    local linuxrelease=$(find_linux_release "$linux")
+    local linuxrelease=$(find_linux_release)
     if compare_version $OFED_VERSION 3.0; then
         local OFA_KERNEL_RELEASE=$(echo -n ${linuxrelease} | sed -e 's/-/_/g')
     fi
@@ -1451,7 +1328,8 @@ build_kernel_with_srpm() {
     if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
         local REUSE_SIGNATURE=$({ echo -en $release_str;
                                   echo $BUILD_GEN;
-                                  cat $CONFIG_FILE $TARGET_FILE $FULL_PATCH; } |
+                                  cat $CONFIG_FILE $TARGET_FILE $FULL_PATCH;
+                                  cat $LBUILD_DIR/lbuild $LBUILD_DIR/lbuild-${DISTRO}; } |
                                 md5sum | cut -d" " -f1)
         # see if we can link to the reuse pool
         # XXX - hrm.  i'm not convinced this doesn't belong in the reuse
@@ -1504,7 +1382,7 @@ build_kernel_with_srpm() {
 
     # figure out the EXTRA_VERSION of the kernel we built or are re-using
     local KERNEL_RPM
-    if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel ="); then
+    if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel(-default)? ="); then
         fatal 1 "Failed to find a kernel RPM in $TOPDIR/RPMS/$TARGET_ARCH/"
     fi
     kernel_extra_version=$(rpm -q --queryformat "%{RELEASE}" -p $TOPDIR/RPMS/$TARGET_ARCH/$KERNEL_RPM)
@@ -1565,8 +1443,11 @@ build_ofed() {
     # build kernel-ib/compat-rdma
     if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
         local REUSE_SIGNATURE=$({ echo "$ofed_version";
-                                  echo "$(find_linux_release ${linux})";
-                                  cat "${linux}/include/linux/autoconf.h"; } |
+                                  echo "$(find_linux_release;
+                                  echo "$BUILD_GEN")";
+                                  cat "${linux}/include/linux/autoconf.h";
+                                  cat "$LBUILD_DIR/lbuild" ;
+                                  cat "$LBUILD_DIR/lbuild-${DISTRO}"; } |
                                 md5sum | cut -d" " -f1)
         # see if we can link to the reuse pool
         # XXX - hrm.  i'm not convinced this doesn't belong in the reuse
@@ -1619,9 +1500,16 @@ build_ofed() {
     cd ${kib_rpm}-devel
     # the actual ofed RPMs don't have the -rc$n or -$date string appened that
     # might be present on the file
-    local linuxrelease=$(find_linux_release "$linux")
+    local linuxrelease=$(find_linux_release)
     ofed_version=$(echo $ofed_version |
                    sed -re 's/-(20[0-9]{6,6}-[0-9]{4,4}|rc[0-9]*)$//')
+    # FIXME
+    # OFED version will have 'hyphen' for minor release. (e.g. 3.5-1, instead
+    # of 3.5.1) compat-rdma and compat-rdma-devel could have same version
+    # number, but currectly not. Once OFED fix this in the future release, we
+    # can remove following filter.
+    ofed_version=$(echo $ofed_version |
+                   sed -re 's/-([0-9]*-[rR][cC][0-9]*)$//')
     local rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version}-${linuxrelease//-/_}.*.rpm)
     if ! rpm2cpio < $rpm | cpio -id; then
         fatal 1 "could not unpack the ${kib_rpm}-devel rpm."
@@ -1750,6 +1638,7 @@ create_rpmbuild_dirs() {
         fi
         [ -d RPMS/$arch ] || mkdir RPMS/$arch
     done
+    [ -d RPMS/noarch ] || mkdir RPMS/noarch
     [ -d BUILD ] || mkdir BUILD
     [ -d SOURCES ] || mkdir SOURCES
     [ -d SPECS ] || mkdir SPECS
@@ -1850,15 +1739,12 @@ else
   seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
 fi
 backtrace
-echo
-echo "Environment:"
-set
-) | mail -s "Untrapped error at ${BASH_SOURCE[0]##*/}:$((LINENO-15)) on $HOSTNAME" brian@whamcloud.com >&2; set $xtrace' ERR
+) ; set $xtrace' ERR
 set -E
 
 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
 
-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,ofed-version:,publish,release,set-value:,src,stage:,tag:,target:,target-archs:,with-linux:,xen -- "$@")
+options=$(getopt -o D:h -l kerneltree:,distro:,kernelrpm:,reusebuild:,patchless,ldiskfs,ccache,reuse:,norpm,disable-datestamp,external-patches:,timestamp:,extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,noiokit,ofed-version:,publish,release,set-value:,src,stage:,tag:,target:,target-archs:,with-linux:,xen -- "$@")
 
 if [ $? != 0 ]; then
     usage 1
@@ -1875,10 +1761,6 @@ while [ "$1" ]; do
             CCACHE='ccache'
             shift
             ;;
-        -d)
-            CVSROOT=$2
-            shift 2
-            ;;
         -D)
             DATE=$2
             shift 2
@@ -1929,7 +1811,7 @@ while [ "$1" ]; do
             shift
             ;;
         --ldiskfs)
-            LDISKFSRPM=true
+           echo "WARNING: \"--ldiskfs\" is deprecated" > 2
             shift
             ;;
         --noiokit)
@@ -1984,8 +1866,8 @@ while [ "$1" ]; do
             shift 2
             ;;
         --tag)
-            TAG=$2
             shift 2
+            echo "WARNING: \"--tag\" is deprecated" > 2
             ;;
         --target)
             TARGET=$2
@@ -1995,10 +1877,6 @@ while [ "$1" ]; do
             TARGET_ARCHS=$2
             shift 2
             ;;
-        --disable-datestamp)
-            USE_DATESTAMP=
-            shift
-            ;;
         --xen)
             XEN=true
             shift