Whamcloud - gitweb
b=20744 hacks for Novell bug 639581
[fs/lustre-release.git] / build / lbuild-sles10
index d278e06..6330d1c 100644 (file)
@@ -8,6 +8,12 @@ BUILD_GEN=3    # bz19975 enable the building of src.rpms by default
 
 source ${0%/*}/lbuild-sles
 
+# the location of the ofed-devel-<version>.<arch>.rpm
+OFED_DEVEL_LOCATION="$KERNELTREE"
+
+# do we want to rebuild the OFED devel RPM or use the supplied one?
+REBUILD_OFED_DEVEL_RPM=${REBUILD_OFED_DEVEL_RPM:-false}
+
 edit_specs() {
 
     # edit the SPECs with our changes
@@ -53,13 +59,13 @@ unpack_linux_devel_rpm-sles10() {
     # get the Module.symvers out of the kenrel-flavor RPM
     local kernelrpm=${callers_rpm/-source-/-$RPMSMPTYPE-}
 
-    if ! rpm2cpio < "$kernelrpm" | cpio -id ./usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH)/$RPMSMPTYPE/Module.symvers ./boot/sym\* > /dev/null 2>&1; then
+    if ! rpm2cpio < "$kernelrpm" | cpio -id ./usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH $PATCHLESS true)/$RPMSMPTYPE/Module.symvers ./boot/sym\* > /dev/null 2>&1; then
         return 255
     fi
 
     # now just sanity check that everything needed to build properly versioned
     # modules is in place
-    if [ ! -f usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH)/$RPMSMPTYPE/Module.symvers ]; then
+    if [ ! -f usr/src/linux-${lnxmaj}${lnxmin}-${lnxrel}-obj/$(resolve_arch $TARGET_ARCH $PATCHLESS true)/$RPMSMPTYPE/Module.symvers ]; then
         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
     fi
     if [ ! -f boot/symsets-${lnxmaj}${lnxmin}-${lnxrel}-$RPMSMPTYPE.tar.gz ]; then
@@ -69,3 +75,165 @@ unpack_linux_devel_rpm-sles10() {
     return 0
 
 }
+
+build_sles_ofed_rpm() {
+    local variant="${1:+-$1}"
+    local add_spec_edit="$2"
+
+    if $REBUILD_OFED_DEVEL_RPM; then
+        #
+        # rebuild the $variant rpm
+        #
+
+        local SOURCE="${KERNELTREE}/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
+
+        # dirty hack until Novell make the kernel-source location overridable
+        # - unpack the src.rpm, patch the .spec and re-pack up the src.rpm
+        mkdir -p ofed-rpm/S{PEC,OURCE,RPM}S
+        pushd ofed-rpm
+        rpm2cpio < $KERNELTREE/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm | cpio -id
+        ed ofed${variant}.spec <<"EOF"
+/^%define kver /c
+%define kver %(flavors=($(ls %kobjdir/%_target_cpu/)); if test -s %kobjdir/%_target_cpu/${flavors[0]}/include/linux/utsrelease.h ; then LINUXRELEASEHEADER=utsrelease.h; else LINUXRELEASEHEADER=version.h; fi; sed -ne "/^#define UTS_RELEASE/s/.*\\"\\\(.*\\\)-${flavors[0]}\\"$/\\1/p" %kobjdir/%_target_cpu/${flavors[0]}/include/linux/$LINUXRELEASEHEADER)
+.
+/^             --kernel-version=%kver-$flavor --kernel-sources=\/usr\/src\/linux-obj\/%_target_cpu\/\$flavor/c
+               --kernel-version=%kver-$flavor --kernel-sources=%kobjdir/%_target_cpu/$flavor
+.
+/^     make -C \/usr\/src\/linux-obj\/%_target_cpu\/\$flavor modules_install \\/c
+     make -C %kobjdir/%_target_cpu/$flavor modules_install \
+.
+wq
+EOF
+        if type -p edit_spec_ofed${variant}; then
+            edit_spec_ofed${variant}
+        fi
+
+        mv ofed${variant}.spec SPECS
+        mv * SOURCES
+        mv SOURCES/S{PEC,RPM}S .
+        rpmbuild --bs --nodeps --define "_topdir $(pwd)" SPECS/ofed${variant}.spec 2>&1 || return 255
+        popd
+        mv ofed-rpm/SRPMS/* ${TOPDIR}/SRPMS/
+        rm -rf ofed-rpm
+        SOURCE="${TOPDIR}/SRPMS/ofed${variant}-${OFED_DEVEL_VERSION}.src.rpm"
+        # end of dirty hack
+
+        # dirty hack until Novell make the kernel-source location overridable
+        # when building kmps
+        # XXX - this is very racy.  let's hope we only ever have a single
+        #       instance of this running at a time
+        local tmpfile
+        if [ -f ~/.rpmmacros ]; then
+            tmpfile=$(mktemp ~/.rpmmacros.XXXXXX)
+            cp ~/.rpmmacros $tmpfile
+        fi
+        cat <<"EOF" >~/.rpmmacros
+# an overridable specification of where the linux-obj tree is located
+%{!?kobjdir: %define kobjdir /usr/src/linux-obj}
+
+# Defines %flavors_to_build and %kernel_source() as a side effect.
+%_kernel_module_package(n:v:r:s:f:Xp:) \
+%{expand:%( subpkg=%{-s*}%{!-s:/usr/lib/rpm/rpm-suse-kernel-module-subpackage} \
+        echo "%%define _suse_kernel_module_subpackage(n:v:r:f:p:) %%{expand:%%(cd %_sourcedir; cat $subpkg; echo %%%%nil)}" \
+        flavors="%{!-X:%*}%{-X:$(ls %kobjdir/%_target_cpu 2>/dev/null)}" \
+       a_flavor=($flavors)
+        flavors_to_build= \
+        if [ -s %kobjdir/%_target_cpu/${a_flavor}/include/linux/utsrelease.h ]; then
+            LINUXRELEASEHEADER=utsrelease.h
+        else
+            LINUXRELEASEHEADER=version.h
+        fi
+        kver=$(sed -ne "/^#define UTS_RELEASE/s/.*\\"\\\(.*\\\)-${a_flavor}\\"$/\\1/p" %kobjdir/%_target_cpu/${a_flavor}/include/linux/$LINUXRELEASEHEADER)
+        for flavor in $flavors; do \
+            if [ -n "%{-X}" ]; then \
+                case " %* " in \
+                (*" $flavor "*) \
+                    continue ;; \
+                esac \
+            fi \
+            krel=$(make -s -C %kobjdir/%_target_cpu/$flavor kernelrelease) \
+            [ -e %symsetsdir/symsets-$krel.tar.gz ] || continue \
+            flavors_to_build="$flavors_to_build $flavor" \
+            echo "%%_suse_kernel_module_subpackage -n %{-n*}%{!-n:%name}-kmp -v %{-v*}%{!-v:%version} -r %{-r*}%{!-r:%release} %{-p} $flavor $krel $kver" \
+        done \
+        echo "%%global flavors_to_build${flavors_to_build:-%%nil}" \
+        echo "%%global kernel_source() %kobjdir/%_target_cpu/%%%%{1}" \
+        \
+        echo "%package -n %{-n*}%{!-n:%name}-kmp-_dummy_" \
+        echo "Version: %version" \
+        echo "Summary: %summary" \
+        echo "Group: %group" \
+        echo "%description -n %{-n*}%{!-n:%name}-kmp-_dummy_" \
+        )}
+EOF
+        local targets
+        for arch in $BUILD_ARCHS; do
+            targets="--target $(resolve_arch $arch $PATCHLESS) $targets"
+        done
+        if ! $RPMBUILD --rebuild --nodeps $targets \
+                                 --define "symsetsdir ${TOPDIR}/reused/boot" \
+                                 --define "kobjdir ${LINUXOBJ%/*/*}" \
+                                 --define "_tmppath /var/tmp" \
+                                 --define "_topdir ${TOPDIR}" \
+                      ${SOURCE} 2>&1; then
+            rm ~/.rpmmacros
+            if [ -n "$tmpfile" ]; then
+                cp $tmpfile ~/.rpmmacros
+                rm $tmpfile
+            fi
+            return 255
+        fi
+        rm ~/.rpmmacros
+        if [ -n "$tmpfile" ]; then
+            cp $tmpfile ~/.rpmmacros
+            rm $tmpfile
+        fi
+    fi # $REBUILD_OFED_DEVEL_RPM; then
+
+}
+
+# additional edits need to the ofed spec
+edit_spec_ofed() {
+
+        ed ofed.spec <<"EOF"
+/^# we assume config.mk and the include files are same for all flavors/a
+built_flavors=(%flavors_to_build)
+.
+/^cp obj\/default\/config\.mk \$RPM_BUILD_ROOT\/%{_prefix}\/src\/kernel-modules-ofed/c
+cp obj/${built_flavors[0]}/config.mk $RPM_BUILD_ROOT/%{_prefix}/src/kernel-modules-ofed
+.
+/^for D in obj\/default\\\\include \$(sed 's@^.*-I\\\${CWD}\/@obj\/default\\\\@' obj\/default\/config.mk); do/c
+for D in obj/${built_flavors[0]}\\include $(sed "s@^.*-I\${CWD}/@obj/${built_flavors[0]}\\\@" obj/${built_flavors[0]}/config.mk); do
+.
+wq
+EOF
+
+}
+
+build_ofed-sles10() {
+    local outfd=$1
+
+    if [ -z "$outfd" ] || [ $outfd = 1 ]; then
+        fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
+    fi
+
+    if $REBUILD_OFED_DEVEL_RPM; then
+        build_sles_ofed_rpm cxgb3-NIC >&${outfd} || return ${PIPESTATUS[0]}
+        build_sles_ofed_rpm >&${outfd} || return ${PIPESTATUS[0]}
+        OFED_DEVEL_LOCATION="${TOPDIR}/RPMS/$(resolve_arch $TARGET_ARCH $PATCHLESS)"
+    fi # $REBUILD_OFED_DEVEL_RPM; then
+
+    # XXX I'm not convinced this belongs in here, but really, this is a
+    # temporary hack until we get a base O/S intalled ofed-devel
+    local arch=$TARGET_ARCH
+    if [ -n "$OFED_VERSION" -a "$OFED_VERSION" = "inkernel" ]; then
+        local ofed_devel="${OFED_DEVEL_LOCATION}/ofed-devel-${OFED_DEVEL_VERSION}.$(resolve_arch $TARGET_ARCH $PATCHLESS).rpm"
+        if ! rpm2cpio < $ofed_devel | cpio -id; then
+            fatal 1 "could not unpack the ofed-devel rpm."
+       fi
+        echo "$(pwd)/usr/src/kernel-modules-ofed/$(resolve_arch $TARGET_ARCH $PATCHLESS)/$RPMSMPTYPE"
+    fi
+
+    return 0
+
+}