Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / build / lmake
index 3bc75a9..0acce67 100755 (executable)
@@ -10,6 +10,7 @@ TARGET_ARCH=
 TARGET_CONFIG=
 JOBS=1
 CONFIGURE_FLAGS=
+TMPDIR=${TMPDIR:-"/var/tmp"}
 
 # commands to run
 BUILD_LUSTRE=0
@@ -260,6 +261,25 @@ load_target()
     fi
 }
 
+# do these after load_target(), which maybe export CC
+setup_ccache_distcc()
+{
+    # distcc can't handle ".incbin"
+    if [ "$TARGET" == "2.6-suse" -o "$TARGET" == "2.6-rhel4" ]; then
+        if [ "$TARGET_ARCH" == "x86_64" ]; then
+            unset DISTCC
+        fi
+    fi
+    
+    CC=${CC:-gcc}
+    if [ "$CCACHE" ]; then
+        CC="$CCACHE $CC"
+        [ "$DISTCC" ] && export CCACHE_PREFIX="$DISTCC"
+    else
+        [ "$DISTCC" ] && CC="$DISTCC $CC"
+    fi
+}
+
 tarflags()
 {
     case "$1" in
@@ -360,7 +380,7 @@ timed_run() {
 
     wait $child_pid
     # status will be set to 143 if the process had to be killed due to timeout
-    status=$?
+    status=${PIPESTATUS[0]}
     kill -KILL -$dog_pid
     return $status
 }
@@ -373,35 +393,76 @@ depend_kernel()
     set_make
     pushd "$TOPDIR/linux" >/dev/null
     echo "Overriding EXTRAVERSION in kernel..."
-    perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${EXTRA_VERSION}${TARGET_CONFIG}/" Makefile
+    local extra_version="${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
+    if [ -n "${TARGET_CONFIG}" ]; then
+       extra_version="${extra_version}${TARGET_DELIMITER}${TARGET_CONFIG}"
+    fi
+    perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = ${extra_version}/" Makefile
     echo "Making depend in $PWD..."
     $MAKE "$MAKE_CC" mrproper || fatal 1 "Error running make mrproper"
     rm -f rpm-release
+    # remove localversion-* files to avoid kernel release string 
+    # srewing up by the top-level Makefile
+    rm -f localversion-*
     cp "$CONFIG_FILE" .config
-    # use the expect script to "make oldconfig" and answer the questions for
-    # new items conservatively.  QA will get notified on anything newly added
-    # for them to review and adjust accordingly.
-    timed_run 300 $TOPDIR/build/update_oldconfig
-    if [ $? -eq 143 ]; then
-        fatal 1 "update_oldconfig timed out"
+    local UPDATE_OLDCONFIG=
+    for oc in oldconfig_nonint silentoldconfig oldconfig ; do                   
+        if grep -q "$oc" Makefile ; then                                        
+            timed_run 300 $MAKE "$MAKE_CC" $oc || UPDATE_OLDCONFIG=1
+            break
+        fi
+    done
+
+    if [ "$UPDATE_OLDCONFIG" ] ; then
+        # use the expect script to "make oldconfig" and answer the questions for
+        # new items conservatively.  QA will get notified on anything newly added
+        # for them to review and adjust accordingly.
+        local logfile=$(mktemp /tmp/XXXXXX)
+        #timed_run 300 $TOPDIR/build/update_oldconfig $logfile
+        #local RC=${PIPESTATUS[0]}
+        #local RC=$(strace -f -o update_oldconfig.strace bash -c "$TOPDIR/build/update_oldconfig $logfile; echo \$?")
+        $TOPDIR/build/update_oldconfig $logfile
+        local RC=${PIPESTATUS[0]}
+        #$TOPDIR/build/update_oldconfig $logfile
+        #local RC=${PIPESTATUS[0]}
+        if [ $RC -eq 143 ]; then
+            fatal 1 "update_oldconfig timed out"
+        elif [ $RC -ne 0 ]; then
+           # dump the log
+            cat $logfile
+            rm -f $logfile
+           if [ -f update_oldconfig.strace ]; then
+               cat update_oldconfig.strace
+               rm -f update_oldconfig.strace
+            fi
+            fatal 1 "update_oldconfig failed: $RC. See log above."
+        fi
     fi
+    rm -f $logfile
     # now notify if resulting .config is different than $CONFIG_FILE
     local tmpfile=$(mktemp /tmp/XXXXXX)
     diff -I '^#.*' -u "$CONFIG_FILE" .config >$tmpfile
     if [ -s $tmpfile ]; then
         { cat <<EOF
+To: lustre-qa-team@sun.com
+Subject: kernel_config change 
+
 The result of a make oldconfig on file $CONFIG_FILE resulted in a
 difference when compared to .config in the following way:
 
 EOF
         cat $tmpfile
-        echo -e "\n\nPlease consider updating $CONFIG_FILE."
-       # not sure these are entirely useful.  the above and "patch" are good
-       #echo -e "\nThe entire new .config file:\n"
+        echo -e "\n\nPlease consider updating $CONFIG_FILE for version: $extra_version."
+        # not sure these are entirely useful.  the above and "patch" are good
+        #echo -e "\nThe entire new .config file:\n"
         #cat .config
-        } | mail -s "kernel_config change" qa@lists.clusterfs.com
+        # sadly, the build roots can't e-mail out, so we can only display this
+        # to stderr for an interested party to inspect
+        #} | sendmail -flustre-qa-team@sun.com -t
+        } >&2
     fi
     rm -f $tmpfile
+
     case "$VERSION" in
        2.6*)
             $MAKE "$MAKE_CC" include/asm
@@ -435,6 +496,48 @@ build_kernel()
     popd >/dev/null
 }
 
+build_kernel_ib()
+{
+    (( $BUILD_KERNEL )) || return 0
+    # build kernel-ib{,-devel}
+    # some I/B drivers are architecture dependent and kernel-ib's configure
+    # does not figure it out for us ~sigh~
+    local configure_options=""
+    case "$TARGET_ARCH" in
+       x86_64 | ia64)
+           configure_options="--with-ipath_inf-mod"
+           ;;
+       ppc64)
+           configure_options="--with-ipath_inf-mod --with-ehca-mod"
+           ;;
+    esac
+    local K_SRC="K_SRC"
+    # ofed 1.3 had a bug in the rpm spec
+    if [ "$OFED_VERSION" = "1.3" ]; then
+        K_SRC="KSRC"
+    fi
+    $RPMBUILD --rebuild --define 'build_kernel_ib 1' --define 'build_kernel_ib_devel 1' \
+             --define "_topdir $(lbuild_topdir)" --target ${TARGET_ARCH} \
+             --define "KVERSION ${FULL_VERSION}" \
+             --define "$K_SRC ${PWD}/linux" \
+             --define "LIB_MOD_DIR /lib/modules/${FULL_VERSION}" \
+             --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" $(lbuild_topdir)/OFED/SRPMS/ofa_kernel-${OFED_VERSION}-ofed${OFED_VERSION}.src.rpm
+
+    if [ ${PIPESTATUS[0]} != 0 ]; then
+        fatal 1 "Error building kernel-ib"
+    fi
+
+    pushd "$TOPDIR" >/dev/null
+    rm -rf kernel-ib-devel
+    mkdir kernel-ib-devel
+    cd kernel-ib-devel
+    local rpm=$(ls $(lbuild_topdir)/RPMS/*/kernel-ib-devel-${OFED_VERSION}-${FULL_VERSION//-/_}.*.rpm)
+    rpm2cpio -itv < $rpm | cpio -id
+    CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
+    popd >/dev/null
+}
+
+
 configure_lustre()
 {
     return 0
@@ -451,16 +554,16 @@ build_lustre()
 {
     (( $BUILD_LUSTRE )) || return 0
     set_make
-    FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
     pushd "$TOPDIR" >/dev/null
     sed \
        -e s^@VERSION@^${LUSTRE_VERSION}^g \
        -e s^@LINUXRELEASE@^${FULL_VERSION}^g \
        -e s^@RELEASE@^${FULL_VERSION//-/_}^g \
        -e s^@ac_configure_args@^"--with-linux=${PWD}/linux ${CONFIGURE_FLAGS}"^g \
-       < build/lustre.spec.in \
-       > build/lustre.spec
-    $RPMBUILD --target ${TARGET_ARCH} -bb build/lustre.spec \
+       < lustre.spec.in \
+       > lustre.spec
+    $RPMBUILD --target ${TARGET_ARCH} -bb lustre.spec \
+        --define "_tmppath $TMPDIR" \
        --define "_topdir $(lbuild_topdir)" || \
        fatal 1 "Error building Lustre rpms."
     # $MAKE_J "$MAKE_CC" || fatal 1 "Error building Lustre."
@@ -471,7 +574,6 @@ install_kernel()
 {
     (( $INSTALL_KERNEL )) || return 0
     set_make
-    FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
     pushd "$TOPDIR/linux" >/dev/null
     mkdir -p "$DESTDIR/boot"
 
@@ -528,8 +630,7 @@ cleanup_libmodules()
 {
     (( $INSTALL_LUSTRE )) || return 0
 
-    FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
-    KVERREL="${VERSION}-${EXTRA_VERSION}"
+    KVERREL="${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
     i="$DESTDIR/lib/modules/${FULL_VERSION}"
 
     rm -f $i/build
@@ -548,7 +649,6 @@ install_lustre()
     (( $INSTALL_LUSTRE )) || return 0
     return 0
     set_make
-    FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
     pushd "$TOPDIR" >/dev/null
     $MAKE "$MAKE_CC" -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
     popd >/dev/null
@@ -559,7 +659,6 @@ build_kms()
     (( $BUILD_KERNEL )) || return 0
     (( $SUSEBUILD )) || return 0
     set_make
-    FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
     mkdir -p "${TOPDIR}/modules-${FULL_VERSION}"
     for dir in /usr/src/kernel-modules/* ; do
        # we are replacing lustre-lite, so don't include it
@@ -584,12 +683,16 @@ install_kms()
     (( $INSTALL_KERNEL )) || return 0
     (( $LINUX26 )) || return 0
     set_make
-    FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
     for build_dir in "${TOPDIR}/modules-${FULL_VERSION}/*" ; do
        [ -d $build_dir ] || continue
         # these modules are terrible, and don't all build
        $MAKE "$MAKE_CC" -C $build_dir KERNEL_SOURCE="${TOPDIR}/linux" INSTALL_MOD_PATH="$DESTDIR" 
     done
+    local symvers_file="${DESTDIR}/boot/symvers-${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}-${TARGET_ARCH}"
+    if [ -n "$TARGET_CONFIG" ]; then
+       symvers_file="${symvers_file}${TARGET_DELIMITER}${TARGET_CONFIG}"
+    fi
+    symvers_file="$symvers_file.gz"
     (   symver vmlinux
        moddir="${DESTDIR}/lib/modules/${FULL_VERSION}"
        cd $moddir/kernel
@@ -601,8 +704,7 @@ install_kms()
                           -name '*.ko' -print); do
            symver $module
        done
-    ) | sort -u -k2 \
-       | gzip -c9 > "${DESTDIR}/boot/symvers-${VERSION}-${EXTRA_VERSION}-${TARGET_ARCH}${TARGET_CONFIG}.gz"
+    ) | sort -u -k2 | gzip -c9 > $symvers_file
 }
 
 save_headers()
@@ -612,7 +714,7 @@ save_headers()
     echo "Saving headers for ${TARGET_CONFIG:-up} ${TARGET_ARCH}..."
     pushd linux >/dev/null
 
-    KVERREL="${VERSION}-${EXTRA_VERSION}"
+    KVERREL="${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
     # deal with the kernel headers that are version specific
     
     saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/${TARGET_ARCH}/${TARGET_CONFIG:-up}"
@@ -754,6 +856,12 @@ done
 
 check_options
 load_target
+EXTRA_VERSION_DELIMITER=${EXTRA_VERSION_DELIMITER:-"-"}
+FULL_VERSION="${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
+if [ -n "$TARGET_CONFIG" ]; then
+    FULL_VERSION="${FULL_VERSION}${TARGET_DELIMITER}${TARGET_CONFIG}"
+fi
+setup_ccache_distcc
 
 extract_kernel
 patch_kernel
@@ -761,6 +869,10 @@ patch_kernel
 depend_kernel
 build_kernel
 
+if [ -n "$OFED_VERSION" ]; then
+    build_kernel_ib
+fi
+
 configure_lustre
 build_lustre