+build_mptlinux() {
+ local linux="$1"
+ local version="$2"
+
+ if [ -z "$version" -o "$version" = "inkernel" ]; then
+ return 0
+ fi
+
+ local targets arch
+ for arch in $BUILD_ARCHS; do
+ targets="--target $arch $targets"
+ done
+
+ local rpmbuildopt='-bb'
+ if $NORPM; then
+ rpmbuildopt='-bc'
+ echo NORPM mode. Only compiling.
+ fi
+
+ # if only we could just rebuild the src.rpm. but the included spec
+ # is a real pig's breakfast. just check out the patch we need to
+ # apply to it to make it useful.
+ #$RPMBUILD --rebuild \
+ # --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
+ # ${TOPDIR}/mptlinux-*.src.rpm
+ rpm -ivh --define "_topdir ${TOPDIR}" ${TOPDIR}/mptlinux-*.src.rpm
+
+ # now the big honkin' patch to the spec file
+ pushd ${TOPDIR}/SPECS
+ # to regen this patch use:
+ # !!cd ~/rpm/SPECS/ && diff -u mptlinux.spec{.dist,}
+ patch -p0 < ${TOPDIR}/lustre/build/mptlinux.spec.patch || fatal 1 "failed to patch mptlinux.spec"
+ popd
+
+ local targets arch
+ for arch in $BUILD_ARCHS; do
+ targets="--target $arch $targets"
+ done
+
+ local rpmbuildopt='-bb'
+ if $NORPM; then
+ rpmbuildopt='-bc'
+ echo NORPM mode. Only compiling.
+ fi
+
+ if ! $RPMBUILD $targets $rpmbuildopt \
+ --define "_tmppath /var/tmp" \
+ --define "_topdir ${TOPDIR}" \
+ --define "kernel_obj $linux" \
+ ${TOPDIR}/SPECS/mptlinux.spec 2>&1; then
+ return 1
+ fi
+ if $DO_SRC; then
+ if ! $RPMBUILD -bs \
+ --define "_tmppath /var/tmp" \
+ --define "_topdir ${TOPDIR}" \
+ --define "kernel_obj $linux" \
+ ${TOPDIR}/SPECS/mptlinux.spec 2>&1; then
+ return 1
+ fi
+ fi
+
+ return 0
+
+}
+
+# build RDAC
+build_rdac() {
+ local linux="$1"
+ local version="$2"
+
+ if [ -z "$version" -o "$version" = "inkernel" ]; then
+ return 0
+ fi
+
+ # note that we use an _, not a . before the spec on purpose. we are not
+ # allowed to have more than one file with a .spec trailer in a tarball
+ # that is supposed to be usable with rpmbuild
+ cp lustre/build/rdac_spec ${TOPDIR}/SPECS/rdac.spec || fatal 1 "Could not find rdac.spec in lustre/build"
+
+ local targets arch
+ for arch in $BUILD_ARCHS; do
+ targets="--target $arch $targets"
+ done
+
+ local rpmbuildopt='-bb'
+ if $NORPM; then
+ rpmbuildopt='-bc'
+ echo NORPM mode. Only compiling.
+ fi
+
+ local distro
+ case $DISTRO in
+ rhel5) distro="REDHAT"
+ ;;
+ sles1*) distro="SUSE"
+ ;;
+ *) echo "$DISTRO not supported by RDAC, skipping"
+ return 0
+ ;;
+ esac
+ if ! $RPMBUILD $targets $rpmbuildopt --define "dist $distro" \
+ --define "_tmppath /var/tmp" \
+ --define "_topdir ${TOPDIR}" \
+ --define "kernel_obj $linux" \
+ ${TOPDIR}/SPECS/rdac.spec 2>&1; then
+ return 1
+ fi
+ if $DO_SRC; then
+ if ! $RPMBUILD -bs --define "dist $distro" \
+ --define "_tmppath /var/tmp" \
+ --define "_topdir ${TOPDIR}" \
+ --define "kernel_obj $linux" \
+ ${TOPDIR}/SPECS/rdac.spec 2>&1; then
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+# build OFED
+# globals used:
+# TOPDIR
+# REUSEBUILD, REUSERPM
+# CONFIGURE_FLAGS
+
+build_ofed() {
+ local linux="$1"
+ local ofed_version="$2"
+
+ # before lustre, build kernel-ib
+ if [ -z "$ofed_version" -o "$ofed_version" = "inkernel" ]; then
+ return 0
+ fi
+
+ if [ -n "$REUSEBUILD" ]; then
+ # see if we can link to the reuse pool
+ # XXX - hrm. i'm not convinced this doesn't belong in the reuse
+ # "library"
+ local CAN_LINK_FOR_REUSE=false
+ touch $REUSEBUILD/$$
+ if cp -al $REUSEBUILD/$$ $TOPDIR/; then
+ CAN_LINK_FOR_REUSE=true
+ fi
+ rm $REUSEBUILD/$$
+ fi
+
+ local REUSE_SIGNATURE=$({ echo "$ofed_version";
+ echo "$(find_linux_release ${linux})";
+ cat "${linux}/include/linux/autoconf.h"; } |
+ md5sum | cut -d" " -f1)
+ if ! $REUSERPM || ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
+ "$REUSE_SIGNATURE"; then
+ # stash away the existing built articles for a moment
+ mkdir bak
+ mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
+ function mv_back {
+ pushd bak
+ find . | cpio -pudlm ..
+ popd
+ rm -rf bak
+ }
+ create_rpmbuild_dirs
+ # build it
+ build_kernel_ib "${linux}"
+ if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
+ "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
+ "$CAN_LINK_FOR_REUSE"; then
+ error "Failed to store OFED RPMS for reuse"
+ mv_back
+ return 1
+ fi
+ # put the stuff we stashed away back
+ mv_back
+ fi
+
+ pushd "$TOPDIR" >/dev/null
+ rm -rf kernel-ib-devel
+ mkdir kernel-ib-devel
+ cd kernel-ib-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")
+ ofed_version=$(echo $ofed_version |
+ sed -re 's/-(20[0-9]{6,6}-[0-9]{4,4}|rc[0-9]*)$//')
+ local rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version}-${linuxrelease//-/_}.*.rpm)
+ rpm2cpio -itv < $rpm | cpio -id
+ CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
+ popd >/dev/null
+
+}
+