Whamcloud - gitweb
add a branch and its table named "b_iam" for "Index API Module" from #colibri
[fs/lustre-release.git] / build / lbuild
index af1590d..d6e95ca 100755 (executable)
@@ -6,7 +6,6 @@ TOPDIR=$PWD
 KERNELDIR=
 LINUX=
 LUSTRE=
-PUBLISH=0
 RELEASE=0
 DO_SRC=0
 DOWNLOAD=1
@@ -16,6 +15,7 @@ TARGET_ARCHS=
 CONFIGURE_FLAGS=
 EXTERNAL_PATCHES=
 EXTRA_VERSION=
+STAGEDIR=
 
 # from target file
 KERNEL=
@@ -73,11 +73,6 @@ fatal()
     exit $1
 }
 
-publishing()
-{
-    (( $PUBLISH )) || return 0
-}
-
 is_release()
 {
     (( $RELEASE )) || return 0
@@ -131,7 +126,7 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     tarball.
 
   --publish
-    Publish the packages, patches, and tarballs on the ftp server.
+    Unused.
 
   --release
     Specifies that the files generated do not include timestamps, and
@@ -140,6 +135,11 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
   --src
     Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
 
+  --stage=DIR
+    Directory used to stage packages for release.  RPMs will be placed
+    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.
 
@@ -199,6 +199,25 @@ check_options()
 #              usage 1 "Target '$TARGET' was not found."
     fi
 
+    case $TARGET in
+       2.6-rhel4)
+           CANONICAL_TARGET="rhel-2.6"
+           ;;
+       2.6-suse)
+           CANONICAL_TARGET="sles-2.6"
+           ;;
+       hp_pnnl-2.4)
+           CANONICAL_TARGET="hp-pnnl-2.4"
+           ;;
+       2.6-vanilla \
+           | suse-2.4.21-2 \
+           | rh-2.4 \
+           | rhel-2.4 \
+           | sles-2.4)
+               CANONICAL_TARGET="$TARGET"
+               ;;
+    esac
+
     TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M")
 
     RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
@@ -215,6 +234,38 @@ uniqify()
     echo $(echo "$*" | xargs -n 1 | sort -u)
 }
 
+download_and_build_tarball() {
+    local TARGET=$1
+    local KERNEL_FILE=$2
+
+    local SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
+
+    echo "Downloading http://ftp.lustre.org/kernels/$TARGET/old/$SRPM..."
+    if ! wget -nv "http://ftp.lustre.org/kernels/$TARGET/old/$SRPM" \
+        -O "$KERNELDIR/$SRPM" ; then
+        fatal 1 "Could not download target $TARGET's kernel SRPM $SRPM from ftp.lustre.org."
+    fi
+
+    if [ "$TARGET" = "rhel-2.6" ]; then
+       RPMTOPDIR=$(mktemp -d $KERNELDIR/rpm_XXXXXX)
+       mkdir $RPMTOPDIR/BUILD/
+        rpm -ivh $KERNELDIR/$SRPM --define "_topdir $RPMTOPDIR" || \
+           { rm -rf $RPMTOPDIR; fatal 1 "Error installing kernel SRPM."; }
+       $RPMBUILD -bp --nodeps --target i686 $RPMTOPDIR/SPECS/kernel-2.6.spec --define "_topdir $RPMTOPDIR"
+        pushd $RPMTOPDIR/BUILD/kernel-${lnxmaj}/linux-${lnxmaj} && {
+            make mrproper
+            cp configs/kernel-${lnxmaj}-i686-smp.config .config
+            make nonint_oldconfig > /dev/null
+            make include/linux/version.h 
+            rm -f .config
+            cd ..
+            tar cjf $KERNEL_FILE linux-${lnxmaj}
+        }
+        popd
+       rm -rf $RPMTOPDIR
+    fi
+}
+
 load_target()
 {
     EXTRA_VERSION_save="$EXTRA_VERSION"
@@ -237,30 +288,12 @@ load_target()
     if [ "$KERNELDIR" ] ; then
        KERNEL_FILE="$KERNELDIR/$KERNEL"
        if [ ! -r "$KERNELDIR/$KERNEL" ] ; then
-           case $TARGET in
-               2.6-rhel4)
-                   dldir="rhel-2.6"
-                   ;;
-               2.6-suse)
-                   dldir="suse-2.6"
-                   ;;
-               hp_pnnl-2.4)
-                   dldir="hp-pnnl-2.4"
-                   ;;
-               2.6-vanilla \
-               | suse-2.4.21-2 \
-               | rh-2.4 \
-               | rhel-2.4 \
-               | sles-2.4)
-                   dldir="$TARGET"
-                   ;;
-           esac
            if (( $DOWNLOAD )) ; then
-               echo "Downloading http://ftp.lustre.org/kernels/$dldir/old/$KERNEL..."
-               if ! wget -nv "http://ftp.lustre.org/kernels/$dldir/old/$KERNEL" \
-                   -O "$KERNELDIR/$KERNEL" ; then
-                   fatal 1 "Could not download target $TARGET's kernel file $KERNEL from ftp.lustre.org."
-               fi
+               echo "Downloading http://ftp.lustre.org/kernels/$CANONICAL_TARGET/old/$KERNEL..."
+               if ! wget -nv "http://ftp.lustre.org/kernels/$CANONICAL_TARGET/old/$KERNEL" -O "$KERNELDIR/$KERNEL" ; then
+                   # see if we can do it with an SRPM from the download site
+                   download_and_build_tarball $CANONICAL_TARGET $KERNEL_FILE
+               fi
            else
                fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
            fi
@@ -307,12 +340,15 @@ tarflags()
        '')
            fatal 1 "tarflags(): File name argument missing."
            ;;
-       *.tar.gz)
+       *.tar.gz | *.tgz)
            echo 'zxf'
            ;;
        *.tar.bz2)
            echo 'jxf'
            ;;
+       *.tar)
+           echo 'xf'
+           ;;
        *)
            fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
            ;;
@@ -516,14 +552,27 @@ build_lustre()
     popd >/dev/null
 }
 
-publish()
+stage()
 {
-    publishing || return 0
+    [ "$STAGEDIR" ] || return 0
+
+    for arch in $BUILD_ARCHS ; do
+       rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
+       echo "${0##*/}: Copying RPMs into ${rpmdir}"
+       mkdir -p "${rpmdir}"
+       cp -v RPMS/${arch}/*.rpm "${rpmdir}"
+       if [ -d RPMS/noarch ] ; then
+           cp -v RPMS/noarch/*.rpm "${rpmdir}"
+       fi
+    done
+
+    cp -v "$LUSTRE" "$STAGEDIR"
 }
 
 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
 
-options=$(getopt -o d:D:h -l external-patches:,extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,publish,release,tag:,target:,target-archs:,disable-datestamp -- "$@")
+options=$(getopt -o d:D:h -l disable-datestamp,external-patches:,extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,publish,release,stage:,tag:,target:,target-archs:,with-linux: -- "$@")
+
 if [ $? != 0 ] ; then
     usage 1
 fi
@@ -575,7 +624,6 @@ while [ "$1" ] ; do
            shift 1
            ;;
        --publish)
-           PUBLISH=1
            shift
            ;;
        --release)
@@ -586,6 +634,10 @@ while [ "$1" ] ; do
            DO_SRC=1
            shift 1
            ;;
+       --stage)
+           STAGEDIR=$2
+           shift 2
+           ;;
        --tag)
            TAG=$2
            shift 2
@@ -636,4 +688,4 @@ else
     build_lustre
 fi
 
-publish
+stage