Whamcloud - gitweb
r=jacob
[fs/lustre-release.git] / build / lbuild
index fff2778..49888f7 100755 (executable)
@@ -4,10 +4,12 @@ TOPDIR=$PWD
 
 # CVSROOT is inherited from the environment
 KERNELDIR=
 
 # CVSROOT is inherited from the environment
 KERNELDIR=
+LINUX=
 LUSTRE=
 PUBLISH=0
 RELEASE=0
 LUSTRE=
 PUBLISH=0
 RELEASE=0
-DO_SRC=1
+DO_SRC=0
+DOWNLOAD=1
 TAG=
 TARGET=
 TARGET_ARCHS=
 TAG=
 TARGET=
 TARGET_ARCHS=
@@ -32,6 +34,7 @@ BOOT_ARCHS=
 JENSEN_ARCHS=
 SMP_ARCHS=
 BIGSMP_ARCHS=
 JENSEN_ARCHS=
 SMP_ARCHS=
 BIGSMP_ARCHS=
+PSERIES64_ARCHS=
 UP_ARCHS=
 
 DATE=$(date)
 UP_ARCHS=
 
 DATE=$(date)
@@ -39,6 +42,20 @@ DATE=$(date)
 USE_DATESTAMP=1
 RPMBUILD=
 
 USE_DATESTAMP=1
 RPMBUILD=
 
+export CC=${CC:-gcc}
+
+# Readlink is not present on some older distributions: emulate it.
+readlink() {
+    local path=$1 ll
+
+    if [ -L "$path" ]; then
+       ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
+       echo "${ll/* -> }"
+    else
+       return 1
+    fi
+}
+
 cleanup()
 {
     true
 cleanup()
 {
     true
@@ -98,10 +115,17 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     Directory containing Linux source tarballs referenced by target
     files.
 
     Directory containing Linux source tarballs referenced by target
     files.
 
+  --linux=LINUX
+    Directory of Linux kernel sources.  When this option is used, only
+    Lustre modules and userspace are built.
+
   --lustre=LUSTRE
     Path to an existing lustre source tarball to use instead of
     pulling from CVS.
 
   --lustre=LUSTRE
     Path to an existing lustre source tarball to use instead of
     pulling from CVS.
 
+  --nodownload
+    Do not try to download a kernel from ftp.lustre.org
+
   --nosrc
     Do not build a .src.rpm, a full kernel patch, or a patched kernel
     tarball.
   --nosrc
     Do not build a .src.rpm, a full kernel patch, or a patched kernel
     tarball.
@@ -113,6 +137,9 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     Specifies that the files generated do not include timestamps, and
     that this is an official release.
 
     Specifies that the files generated do not include timestamps, and
     that this is an official release.
 
+  --src
+    Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
+
   --tag=TAG
     A CVS branch/tag name to build from when pulling from CVS.
 
   --tag=TAG
     A CVS branch/tag name to build from when pulling from CVS.
 
@@ -154,24 +181,26 @@ check_options()
            usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
     fi
 
            usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
     fi
 
-    [ "$KERNELDIR" ] || \
-       usage 1 "A kernel directory must be specified with --kerneldir."
+    if [ -z "$LINUX" ] ; then
+       [ "$KERNELDIR" ] || \
+           usage 1 "A kernel directory must be specified with --kerneldir."
 
 
-    [ -d "$KERNELDIR" ] || \
-       usage 1 "$KERNELDIR is not a directory."
+       [ -d "$KERNELDIR" ] || \
+           usage 1 "$KERNELDIR is not a directory."
 
 
-    if ! (( $RELEASE )) ; then
-       [ "$TAG" ] || \
-           usage 1 "When building a snapshot, a tag name must be used."
+       if ! (( $RELEASE )) ; then
+           [ "$TAG" ] || \
+               usage 1 "When building a snapshot, a tag name must be used."
+       fi
+
+       [ "$TARGET" ] || usage 1 "A target must be specified with --target."
+#       TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
+#       [ -r "$TARGET_FILE" ] || \
+#              usage 1 "Target '$TARGET' was not found."
     fi
 
     TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M")
 
     fi
 
     TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M")
 
-    [ "$TARGET" ] || usage 1 "A target must be specified with --target."
-#    TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
-#    [ -r "$TARGET_FILE" ] || \
-#      usage 1 "Target '$TARGET' was not found."
-
     RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
     if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
        RPMBUILD=$(which rpm 2>/dev/null | head -1)
     RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
     if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
        RPMBUILD=$(which rpm 2>/dev/null | head -1)
@@ -207,8 +236,35 @@ load_target()
 
     if [ "$KERNELDIR" ] ; then
        KERNEL_FILE="$KERNELDIR/$KERNEL"
 
     if [ "$KERNELDIR" ] ; then
        KERNEL_FILE="$KERNELDIR/$KERNEL"
-       [ -r "$KERNELDIR/$KERNEL" ] || \
-           fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
+       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
+           else
+               fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
+           fi
+       fi
     fi
 
     if [ "$SERIES" ] ; then
     fi
 
     if [ "$SERIES" ] ; then
@@ -227,11 +283,13 @@ load_target()
     if [ "$EXTRA_VERSION_save" ] ; then
        EXTRA_VERSION="$EXTRA_VERSION_save"
     elif ! (( $RELEASE )) ; then
     if [ "$EXTRA_VERSION_save" ] ; then
        EXTRA_VERSION="$EXTRA_VERSION_save"
     elif ! (( $RELEASE )) ; then
+       #remove the @VERSION@ (lustre version)
+       EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
        EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
     fi
     # EXTRA_VERSION=${EXTRA_VERSION//-/_}
 
        EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
     fi
     # EXTRA_VERSION=${EXTRA_VERSION//-/_}
 
-    ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $UP_ARCHS"
+    ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
 
     BUILD_ARCHS=
     for arch in $(uniqify "$ALL_ARCHS") ; do
 
     BUILD_ARCHS=
     for arch in $(uniqify "$ALL_ARCHS") ; do
@@ -255,6 +313,9 @@ tarflags()
        *.tar.bz2)
            echo 'jxf'
            ;;
        *.tar.bz2)
            echo 'jxf'
            ;;
+       *.tar)
+           echo 'xf'
+           ;;
        *)
            fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
            ;;
        *)
            fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
            ;;
@@ -361,14 +422,10 @@ clean_linux()
     rm -rf linux
 }
 
     rm -rf linux
 }
 
-prep_build()
+prep_kernel_build()
 {
     # make .spec file
 {
     # make .spec file
-    if [ -f /etc/init.d/functions -a -f /etc/sysconfig/network ] ; then
-        ENABLE_INIT_SCRIPTS=""
-    else
-        ENABLE_INIT_SCRIPTS="# "
-    fi
+    ENABLE_INIT_SCRIPTS=""
     sed \
        -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
        -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
     sed \
        -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
        -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
@@ -384,6 +441,7 @@ prep_build()
        -e "s^@LINUX26@^$LINUX26^g" \
        -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
        -e "s^@LUSTRE_TARGET@^$TARGET^g" \
        -e "s^@LINUX26@^$LINUX26^g" \
        -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
        -e "s^@LUSTRE_TARGET@^$TARGET^g" \
+       -e "s^@PSERIES64_ARCHS@^$PSERIES64_ARCHS^g" \
        -e "s^@RHBUILD@^$RHBUILD^g" \
        -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
        -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
        -e "s^@RHBUILD@^$RHBUILD^g" \
        -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
        -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
@@ -396,7 +454,8 @@ prep_build()
     [ -d BUILD ] || mkdir BUILD
     [ -d SOURCES ] || mkdir SOURCES
     for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
     [ -d BUILD ] || mkdir BUILD
     [ -d SOURCES ] || mkdir SOURCES
     for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
-       suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} ; do
+       suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} \
+       sles8-{pre,post,postun,update_{INITRD_MODULES,rcfile_setting}}.sh ; do
        cp $TOPDIR/lustre/build/$script SOURCES
     done
     cp "$LUSTRE" "$KERNEL_FILE" SOURCES
        cp $TOPDIR/lustre/build/$script SOURCES
     done
     cp "$LUSTRE" "$KERNEL_FILE" SOURCES
@@ -410,14 +469,14 @@ prep_build()
 clean_lustre()
 {
     [ -d lustre ] || return 0
 clean_lustre()
 {
     [ -d lustre ] || return 0
-    echo "Cleaning lustre..."
+    echo "Cleaning Lustre..."
     [ -L lustre ] && rm -rf $(readlink lustre)
     rm -rf lustre
 }
 
     [ -L lustre ] && rm -rf $(readlink lustre)
     rm -rf lustre
 }
 
-build()
+build_kernel()
 {
 {
-    echo "Building rpms for: $BUILD_ARCHS..."
+    echo "Building kernel + Lustre RPMs for: $BUILD_ARCHS..."
     targets=
     for arch in $BUILD_ARCHS ; do
        targets="--target $arch $targets"
     targets=
     for arch in $BUILD_ARCHS ; do
        targets="--target $arch $targets"
@@ -425,7 +484,7 @@ build()
 
     $RPMBUILD $targets -bb lustre-kernel-2.4.spec \
        --define "_topdir $TOPDIR" || \
 
     $RPMBUILD $targets -bb lustre-kernel-2.4.spec \
        --define "_topdir $TOPDIR" || \
-       fatal 1 "Error building rpms for $arch."
+       fatal 1 "Error building rpms for $BUILD_ARCHS."
 
     if (( $DO_SRC )) ; then
        $RPMBUILD -bs lustre-kernel-2.4.spec \
 
     if (( $DO_SRC )) ; then
        $RPMBUILD -bs lustre-kernel-2.4.spec \
@@ -434,6 +493,32 @@ build()
     fi
 }
 
     fi
 }
 
+build_lustre()
+{
+    [ -d SRPMS ] || mkdir SRPMS
+    [ -d RPMS ] || mkdir RPMS
+    [ -d BUILD ] || mkdir BUILD
+    [ -d SOURCES ] || mkdir SOURCES
+
+    cp "$LUSTRE" SOURCES
+
+    pushd lustre >/dev/null
+
+    echo "Building Lustre RPMs for: $BUILD_ARCHS..."
+    targets=
+    for arch in $BUILD_ARCHS ; do
+       targets="--target $arch $targets"
+    done
+
+    ./configure "--with-linux=${LINUX}" ${CONFIGURE_FLAGS}
+
+    $RPMBUILD $targets -bb build/lustre.spec \
+       --define "_topdir $TOPDIR" || \
+       fatal 1 "Error building rpms for $BUILD_ARCHS."
+
+    popd >/dev/null
+}
+
 publish()
 {
     publishing || return 0
 publish()
 {
     publishing || return 0
@@ -441,7 +526,11 @@ publish()
 
 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
 
 
 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
 
-options=$(getopt -o d:D:h -l external-patches:,extraversion:,kerneldir:,lustre:,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,tag:,target:,target-archs:,with-linux: -- "$@")
+
+if [ $? != 0 ] ; then
+    usage 1
+fi
 
 eval set -- "$options"
     
 
 eval set -- "$options"
     
@@ -473,10 +562,18 @@ while [ "$1" ] ; do
            KERNELDIR=$2
            shift 2
            ;;
            KERNELDIR=$2
            shift 2
            ;;
+       --linux | --with-linux)
+           LINUX=$2
+           shift 2
+           ;;
        --lustre)
            LUSTRE=$2
            shift 2
            ;;
        --lustre)
            LUSTRE=$2
            shift 2
            ;;
+       --nodownload)
+           DOWNLOAD=0
+           shift 1
+           ;;
        --nosrc)
            DO_SRC=0
            shift 1
        --nosrc)
            DO_SRC=0
            shift 1
@@ -489,6 +586,10 @@ while [ "$1" ] ; do
            RELEASE=1
            shift
            ;;
            RELEASE=1
            shift
            ;;
+       --src)
+           DO_SRC=1
+           shift 1
+           ;;
        --tag)
            TAG=$2
            shift 2
        --tag)
            TAG=$2
            shift 2
@@ -519,18 +620,24 @@ done
 check_options
 
 unpack_lustre
 check_options
 
 unpack_lustre
-load_target
-
-if (( $DO_SRC )) ; then
-    unpack_linux
-    patch_linux
-    pack_linux
-    clean_linux
-fi
 
 # prep_build needs the .spec.in from the lustre source
 
 # prep_build needs the .spec.in from the lustre source
-prep_build
-clean_lustre
+if [ -z "$LINUX" ] ; then
+    load_target
+
+    if (( $DO_SRC )) ; then
+       unpack_linux
+       patch_linux
+       pack_linux
+       clean_linux
+    fi
+
+    prep_kernel_build
+    clean_lustre
+
+    build_kernel
+else
+    build_lustre
+fi
 
 
-build
 publish
 publish