3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
10 # CVSROOT is inherited from the environment
15 # XXX - some recent hacking has pretty much neutered this option.
16 # search through this file (and lbuild.old_school -- but that will
17 # be going away soon) for "-bb" and see how many places
18 # simply don't account for this option
24 TARGET_ARCH=$(uname -m)
26 TARGET_ARCHS_ALL=$TARGET_ARCH
27 [ "$TARGET_ARCH" = "i686" ] && TARGET_ARCHS_ALL="i686 i586 i386"
33 TMPDIR=${TMPDIR:-"/var/tmp"}
35 # XXX - i think these two parameters/arguments/variables need to be
36 # cleaned up and merged. they effectively do the same thing
39 # what does this do exactly? does it imply no kernel build?
42 SKIPLDISKFSRPM="v1_4_* b1_4"
43 SMPTYPES="smp bigsmp default ''"
66 # not in the target file any more
78 # Readlink is not present on some older distributions: emulate it.
82 if [ -L "$path" ]; then
83 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
98 [ -n "$msg" ] && echo -e "\n${0##*/}: $msg" >&2
112 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
115 Specifies the CVS Root to use when pulling files from CVS. The
116 environment variable \$CVSROOT is used if this option is not
119 --external-patches=EXTERNAL_PATCHES
120 Directory similar to lustre/lustre/kernel_patches/ that lbuild should
121 look for seres and config files in before looking in the lustre
124 --extraversion=EXTRAVERSION
125 Text to use for the rpm release and kernel extraversion.
127 --timestamp=TIMESTAMP
128 Date of building lustre in format YYYYMMDDhhmmss
131 Try to reuse old kernel RPMs from DIR
134 Try to reuse old kernel builds from DIR
137 Path to distro kernel RPM collection
143 Do not build RPMs (compile only mode)
146 Build lustre client only
149 Which distro using. Autodetect by default
151 --kerneldir=KERNELDIR
152 Directory containing Linux source tarballs referenced by target
155 --kerneltree=KERNELTREE
156 Directory containing dirs with Linux source tarballs referenced by target
157 files. Dir names in format kernel version ('2.6.9', etc.)
159 --linux=LINUX --with-linux=LINUX
160 Directory of Linux kernel sources. When this option is used, only
161 Lustre modules and userspace are built.
164 Path to an existing lustre source tarball to use instead of
168 Do not try to download a kernel from downloads.lustre.org
171 Do not build a .src.rpm, a full kernel patch, or a patched kernel
175 Do ldiskfs RPM. Now true by default
181 Specifies that the files generated do not include timestamps, and
182 that this is an official release.
185 Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
188 Directory used to stage packages for release. RPMs will be placed
189 more or less in DIR/<target>-<arch>, and the tarball will be
193 A CVS branch/tag name to build from when pulling from CVS.
196 The name of the target to build. The available targets are listed
199 --target-archs=TARGET_ARCHS
200 A (space delimited) list of architectures to build. By default,
201 all of the archs supported by the TARGET will be built, in
202 addition to a .src.rpm. This option can limit those, for machines
203 that can only build certain archs or if you only want a certain
204 arch built (for testing, or a one-off kernel).
206 Also note that by using a non-"base" arch (eg, i386) only kernels
207 will be built - there will be no lustre-lite-utils package.
210 Prevents the datestamp flag (-D) from being passed to cvs for
211 checkouts. This is a workaround for a problem encountered when
212 using lbuild with tinderbox.
215 Builds a Xen domX kernel.
224 # canonicalize a relative path
228 if [ ! -d "$PATH" ]; then
232 pushd "$PATH" >/dev/null || return 1
242 if [ "$LUSTRE" ]; then
243 [ -r "$LUSTRE" ] || \
244 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
247 usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
249 usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
252 if [ -z "$LINUX" ]; then
253 [ "$KERNELDIR" -o "$KERNELTREE" ] || \
254 usage 1 "A kernel directory must be specified with --kerneldir or --kerneltree."
256 [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
257 usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
261 usage 1 "When building a snapshot, a tag name must be used."
264 [ "$TARGET" ] || usage 1 "A target must be specified with --target."
265 # TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
266 # [ -r "$TARGET_FILE" ] || \
267 # usage 1 "Target '$TARGET' was not found."
272 CANONICAL_TARGET="rhel5"
275 CANONICAL_TARGET="rhel-2.6"
278 CANONICAL_TARGET="sles-2.6"
281 CANONICAL_TARGET="sles10-2.6"
284 CANONICAL_TARGET="hp-pnnl-2.4"
292 CANONICAL_TARGET="$TARGET"
296 local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
297 [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
298 local timestamplength="${#TIMESTAMP}"
299 if [ $timestamplength -eq 12 ]; then
300 TIMESTAMP="${TIMESTAMP}00"
301 elif [ $timestamplength -ne 14 ]; then
302 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
305 RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
306 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
307 RPMBUILD=$(which rpm 2>/dev/null | head -1)
308 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
309 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
313 if [ -n "$CCACHE" ]; then
314 which "$DISTCC" 2>/dev/null && export DISTCC RPM_BUILD_NCPUS
316 if which "$CCACHE" 2>/dev/null; then
317 local ccache=$(which "$CCACHE")
318 local bindir="$TOPDIR/bin"
320 [ -d $bindir ] || mkdir -p $bindir
321 if [ -d $bindir ]; then
322 rm ${bindir}/* > /dev/null 2>&1
323 ln -s "$ccache" ${bindir}/ccache
324 ln -s "$ccache" ${bindir}/cc
325 ln -s "$ccache" ${bindir}/$CC
326 export PATH=$bindir:$PATH
328 export CCACHE && export CC="ccache $CC"
329 # zero the cache so we can see how effective we are being with it
334 [ -z "$DISTRO" ] && DISTRO=$(autodetect_distro)
337 # autodetect used Distro
338 autodetect_distro() {
343 if [ -f /etc/SuSE-release ]; then
345 version=$(grep ^VERSION /etc/SuSE-release)
346 version=${version#*= }
347 elif [ -f /etc/redhat-release ]; then
348 name=$(head -1 /etc/redhat-release)
349 version=$(echo "$distroname" |
350 sed -e 's/^[^0-9.]*//g' | sed -e 's/[ \.].*//')
352 if [ -z "$name" -o -z "$version" ]; then
353 fatal 1 "I don't know how to determine distro type/version.\n" \
354 "Either update autodetect_distro() or use the --distro argument"
357 echo ${name}${version}
364 echo $(echo "$*" | xargs -n 1 | sort -u)
372 # ~sigh~ the download site doesn't actually have these kernels
373 echo "Downloading http://downloads.lustre.org/public/kernels/$target/old/$srpm..."
374 if ! wget -nv "http://downloads.lustre.org/public/kernels/$target/old/$srpm" \
375 -O "$KERNELDIR/$srpm"; then
376 fatal 1 "Could not download target $target's kernel SRPM $srpm from downloads.lustre.org."
378 [ -s "$KERNELDIR/$srpm" ] || {
379 rm -rf $KERNELDIR/$srpm
380 fatal 1 "Could not download target $target's kernel SRPM $srpm from downloads.lustre.org."
387 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ] && \
388 [ ! -r "$KERNELTREE/OFED-${OFED_VERSION}.tgz" ]; then
390 local location="http://downloads.lustre.org/public/OFED/"
391 echo "Downloading $location/OFED-${OFED_VERSION}.tgz..."
392 if ! wget -nv "$location/OFED-${OFED_VERSION}.tgz" \
393 -O "$KERNELTREE/OFED-${OFED_VERSION}.tgz"; then
394 fatal 1 "Could not download OFED-${OFED_VERSION}.tgz" \
395 "from downloads.lustre.org."
398 fatal 1 "OFED-${OFED_VERSION}.tgz not found in kernel" \
399 "directory $KERNELTREE."
407 EXTRA_VERSION_save="$EXTRA_VERSION"
408 for patchesdir in "$EXTERNAL_PATCHES" \
409 "$TOPDIR/lustre/lustre/kernel_patches"; do
410 TARGET_FILE="$patchesdir/targets/$TARGET.target"
411 [ -r "$TARGET_FILE" ] && break
413 [ -r "$TARGET_FILE" ] || fatal 1 "Target $TARGET was not found."
415 echo "Loading target config file $TARGET.target..."
419 # doesn't make any sense to build OFED for xen domX's
424 # XXX - set_rpm_smp_type is an ugly undeterministic hack. it needs to
425 # go away and the target just specify the $RPMSMPTYPE
426 [ -z "$RPMSMPTYPE" ] && set_rpm_smp_type
428 # CC might have been overwriten in TARGET_FILE
429 if [[ $CC != ccache\ * ]] && which "$CCACHE" 2>/dev/null; then
430 export CCACHE && export CC="ccache $CC"
433 if [ ! "$KERNELTREE" = "" ] && [ -d "$KERNELTREE" ]; then
434 KERNELDIR="$KERNELTREE/${lnxmaj}"
435 [ -d "$KERNELDIR" ] || mkdir "$KERNELDIR"
438 # verify the series is available
439 if [ "$SERIES" ]; then
440 for series in $SERIES; do
441 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
442 [ -r "$patchesdir/series/$series" ] && continue 2
444 fatal 1 "Target $TARGET's series $SERIES could not be" \
445 "found.\nSearched:\n\t$EXTERNAL_PATCHES/series\n" \
446 "\t$TOPDIR/lustre/lustre/kernel_patches/series."
450 # set the location of the .config file
455 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
456 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config"
459 # figure out our smp kernel type and set the .config if we have one
461 for smptype in $SMPTYPES; do
462 [ "$smptype" = "''" ] && smptype=
463 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH-${smptype}.config ]; then
464 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH-${smptype}.config"
465 KERNCONFSMPTYPE=$smptype
469 local lnxrelnew=${lnxrel//-/_}
471 # remember the EXTRA_VERSION before we diddle it here
472 # XXX - we really should not diddle with any values read in from the
473 # target file. if we want to modify a value, we should create
475 PRISTINE_EXTRA_VERSION=$EXTRA_VERSION
477 if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
478 fatal 1 "Config file for target $TARGET missing from" \
479 "$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
482 if [ "$EXTRA_VERSION_save" ]; then
483 EXTRA_VERSION="$EXTRA_VERSION_save"
484 elif ! $RELEASE; then
485 # if there is no patch series, then this is not a lustre specific
486 # kernel. don't make it look like one
487 if [ -n "$SERIES" ]; then
488 #remove the @VERSION@ (lustre version)
489 # EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
490 # EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
491 ! ( $PATCHLESS ) && EXTRA_VERSION="${EXTRA_VERSION}.${TIMESTAMP}"
494 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
496 ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
499 for arch in $(uniqify "$ALL_ARCHS"); do
500 if [ -z "$TARGET_ARCHS" ] ||
501 [[ \ $TARGET_ARCHS\ = *\ $arch\ * ]]; then
502 BUILD_ARCHS="$BUILD_ARCHS $arch"
505 [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
506 echo "Building for: $BUILD_ARCHS"
514 fatal 1 "tarflags(): File name argument missing."
526 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
535 echo "Untarring ${file##*/}..."
536 tar $(tarflags "$file") "$file"
542 untar "$KERNELTREE/OFED-${OFED_VERSION}.tgz" || fatal 1 "Error unpacking OFED tarball"
543 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
549 if [ -z "$LUSTRE" ]; then
552 if [ -n "$USE_DATESTAMP" ]; then
553 DATESTAMP="-D '$DATE'"
556 local DIRNAME="lustre-$TAG-$TIMESTAMP"
558 cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
559 fatal 1 "There was an error checking out toplevel Lustre from CVS."
560 pushd "$DIRNAME" > /dev/null
561 ./lustrecvs "$TAG" || \
562 fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
563 echo "Creating lustre tarball..."
564 sh autogen.sh || fatal 1 "There was an error running autogen.sh."
565 ./configure --disable-{modules,utils,liblustre,tests,doc} || \
566 fatal 1 "There was an error running ./configure to create makefiles."
567 make dist || fatal 1 "There was an error running 'make dist'."
568 LUSTRE=$PWD/lustre-*.tar.gz
572 untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
573 [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
579 local do_patch=${1:-true}
581 FULL_PATCH="$PWD/lustre-kernel-${TARGET}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}.patch"
582 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
583 $do_patch && pushd linux >/dev/null
584 for series in $SERIES; do
585 echo -n "Applying series $series:"
586 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
587 [ -r "$patchesdir/series/$series" ] || continue
588 SERIES_FILE="$patchesdir/series/$series"
589 for patch in $(<"$SERIES_FILE"); do
591 PATCH_FILE="$patchesdir/patches/$patch"
592 [ -r "$PATCH_FILE" ] || \
593 fatal 1 "Patch $patch does not exist in Lustre tree."
594 cat "$PATCH_FILE" >> "$FULL_PATCH" || {
596 fatal 1 "Error adding patch $patch to full patch."
599 patch -s -p1 < "$PATCH_FILE" || {
601 fatal 1 "Error applying patch $patch."
609 $do_patch && popd >/dev/null
610 echo "Full patch has been saved in ${FULL_PATCH##*/}."
618 pushd lustre >/dev/null
620 echo "Building Lustre RPMs for: $BUILD_ARCHS..."
622 for arch in $BUILD_ARCHS; do
623 targets="--target $arch $targets"
626 local confoptions="--with-linux=${LINUX}"
628 confoptions="--with-linux=${LINUX} --disable-server"
630 if [ ! "$LINUXOBJ" = "" ]; then
631 confoptions="$confoptions --with-linux-obj=${LINUXOBJ}"
634 ./configure $confoptions ${CONFIGURE_FLAGS}
635 if [ "$?" != "0" ]; then
636 local saved_config="../config.log.$(date +%s)"
637 cp config.log $saved_config
638 chmod a+r $saved_config
639 echo "Saved config.log is at $saved_config"
646 # hack. Somebody move build/lustre.spec to lustre.spec for b1_6
648 [ -f lustre.spec ] && lustre_spec=lustre.spec
649 [ -f build/lustre.spec ] && lustre_spec=build/lustre.spec
651 [ -f "$lustre_spec" ] && sed \
652 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
656 local rpmbuildopt='-bb'
659 echo NORPM mode. Only compiling.
662 $RPMBUILD $targets $rpmbuildopt ../lustre.spec \
663 ${PATCHLESS:+--define "lustre_name lustre-client"} \
664 --define "_tmppath $TMPDIR" \
665 --define "_topdir $TOPDIR" || \
666 fatal 1 "Error building rpms for $BUILD_ARCHS."
669 ( $(skeep_ldiskfs_rpm $TAG) ) && return
671 pushd lustre/ldiskfs || return 255
673 if [ "$?" != "0" ]; then
677 cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES
681 local ldiskfs_spec=lustre-ldiskfs.spec
682 [ -f "$ldiskfs_spec" ] && sed \
683 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
685 > ../lustre-ldiskfs.spec
687 $RPMBUILD $targets $rpmbuildopt ../lustre-ldiskfs.spec \
688 --define "_tmppath /var/tmp" \
689 --define "_topdir $TOPDIR"
690 if [ "$?" != "0" ]; then
696 $RPMBUILD -bs ../lustre-ldiskfs.spec \
697 --define "_tmppath /var/tmp" \
698 --define "_topdir $TOPDIR"
699 if [ "$?" != "0" ]; then
710 [ "$STAGEDIR" ] || return 0
712 for arch in $BUILD_ARCHS; do
713 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
714 echo "${0##*/}: Copying RPMs into ${rpmdir}"
716 cp -v RPMS/${arch}/*.rpm "${rpmdir}"
717 if [ -d RPMS/noarch ]; then
718 cp -v RPMS/noarch/*.rpm "${rpmdir}"
722 cp -v "$LUSTRE" "$STAGEDIR"
725 #check if we need to build separate ldiskfs RPM
726 skeep_ldiskfs_rpm() {
731 if ! $LDISKFSRPM; then
733 elif $PATCHLESS; then
736 for skiptag in $SKIPLDISKFSRPM; do
737 [[ $tag == $skiptag ]] && skip=true && break
744 #generate LUSTRE_EXTRA_VERSION from EXTRA_VERSION
745 gen_lustre_version() {
747 LUSTRE_EXTRA_VERSION="${lnxmaj}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}${TARGET_DELIMITER}${RPMSMPTYPE:-${KERNCONFSMPTYPE:-"smp"}}"
748 LUSTRE_EXTRA_VERSION=${LUSTRE_EXTRA_VERSION//-/_}
754 local infact_arch="${TARGET_ARCH}"
757 [ "$infact_arch" == "i586" ] && infact_arch="i686"
760 for smp_type in $SMP_ARCHS; do
761 [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
764 for smp_type in $BIGSMP_ARCHS; do
765 [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
770 # This function takes a linux source pool and digs out the linux release
772 find_linux_release() {
775 local LINUXRELEASEHEADER=$SRCDIR/include/linux/version.h
776 if [ -s $SRCDIR/include/linux/utsrelease.h ]; then
777 LINUXRELEASEHEADER=$SRCDIR/include/linux/utsrelease.h
780 sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
786 local delimiter=${2:-"-"}
788 local pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
789 [ -d $pathtorpms ] || return 255
791 local kernelbinaryrpm rpmfile
792 local wanted_kernel="${lnxmaj}${delimiter}${lnxrel}"
795 for arch in $TARGET_ARCHS_ALL; do
796 local found_rpm="" rpm
797 for rpm in ${pathtorpms}/${arch}/*.rpm; do
798 if rpm -q --provides -p "$rpm" | grep -q "kernel${prefix} = $wanted_kernel"; then
804 [ -f "$found_rpm" ] && TARGET_ARCH="$arch" && BUILD_ARCHS="$arch" && break
812 #unpack kernel(/source/devel) RPM
814 # This function and it's setting of $LINUX and $LINUXOBJ is a total hack that
815 # needs to completely refactored. It completely ingores that $BUILD_ARCHS may
816 # contain a list of arches for which rpmbuild commands (including the one for
819 local kernelrpm="${1}"
820 local delimiter=${2:-"-"}
822 [ -f "$kernelrpm" ] || return 255
823 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused
825 pushd $TOPDIR/reused || return 255
829 rpm2cpio < "$kernelrpm" | cpio -id > /dev/null 2>&1
830 if [ ${PIPESTATUS[0]} -eq 0 ]; then
831 # RHEL-style and SLES-style rpms
832 local paths="kernels/${lnxmaj}${delimiter}${lnxrel}-${TARGET_ARCH} linux-${lnxmaj}${delimiter}${lnxrel}"
835 for path in $paths; do
838 if [ -d "$src/$path/" ]; then
839 LINUX="$(pwd)/$src/$path"
841 # SLES has a separate -obj tree
842 if [ -d "$src/${path}-obj" ]; then
843 local src="$src/${path}-obj"
844 local objects="$TARGET_ARCH/$RPMSMPTYPE"
846 # Novell, are you *TRYING* to make life hard for me?
847 if [ -d "$src/powerpc" ]; then
848 objects="powerpc/$TARGET_ARCH"
849 elif [ $TARGET_ARCH == 'i686' ]; then
850 objects="i386/$RPMSMPTYPE"
853 LINUXOBJ="$(pwd)/$src/$objects"
856 if [ -z "$LINUX" ]; then
859 # dig out the release version
860 LINUXRELEASE=$(find_linux_release ${LINUXOBJ:-$LINUX})
861 if [ -z "$LINUXRELEASE" ]; then
862 echo "Failed to find linux release in ${LINUXOBJ:-$LINUX}"
874 # build kernel-ib{,-devel}
875 # some I/B drivers are architecture dependent and kernel-ib's configure
876 # does not figure it out for us ~sigh~
877 local configure_options=""
878 case "$TARGET_ARCH" in
880 configure_options="--with-ipath_inf-mod"
883 configure_options="--with-ipath_inf-mod --with-ehca-mod"
887 # ofed 1.3 had a bug in the rpm spec
888 if [ "$OFED_VERSION" = "1.3" ]; then
891 $RPMBUILD --rebuild --define 'build_kernel_ib 1' --define 'build_kernel_ib_devel 1' \
892 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
893 --define "KVERSION ${LINUXRELEASE}" \
894 --define "$K_SRC ${LINUXOBJ:-${LINUX}}" \
895 --define "LIB_MOD_DIR /lib/modules/${LINUXRELEASE}/updates" \
896 --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" ${TOPDIR}/OFED/SRPMS/ofa_kernel-${OFED_VERSION}-ofed${OFED_VERSION}.src.rpm
898 if [ ${PIPESTATUS[0]} != 0 ]; then
899 fatal 1 "Error building kernel-ib"
902 pushd "$TOPDIR" >/dev/null
903 rm -rf kernel-ib-devel
904 mkdir kernel-ib-devel
906 local rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${OFED_VERSION}-${LINUXRELEASE//-/_}.*.rpm)
907 rpm2cpio -itv < $rpm | cpio -id
908 CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
924 location="$location"/"$signature"/"$module"
926 ## use eval/echo here to make sure shell expansions are performed
927 #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
929 for article in $(eval echo $articles); do
930 if ! cp -a${linkflag} "$article" "$location"; then
931 error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
943 local use_links="${3:-false}"
946 if [ -n "$REUSEBUILD" ] && [ -d $REUSEBUILD/$signature/$module ]; then
947 # so that we know how stale this entry is
948 touch $REUSEBUILD/$signature/$module/.lastused
950 if ls $REUSEBUILD/$signature/$module/* >/dev/null 2>&1; then
951 cp -al $REUSEBUILD/$signature/$module/* $dest/
954 # copying is pretty heavy
955 # cp -a $REUSEBUILD/$signature/$module/* $dest/
956 # do some creative symlinking instead
958 for dir in BUILD SRPMS SPECS; do
959 if ls $REUSEBUILD/$signature/$module/$dir/* >/dev/null 2>&1; then
960 ln -s $REUSEBUILD/$signature/$module/$dir/* $dest/$dir
963 # sources have to be copied by file because we need SOURCES to
964 # be a dir we can write into
965 # could overrun ls's arg list here
966 #ls $REUSEBUILD/$signature/$module/SOURCES/* |
967 find $REUSEBUILD/$signature/$module/SOURCES/ -type f |
968 xargs ln -t $dest/SOURCES -s
970 # same for RPMS/* dirs
971 # could overrun ls's arg list here
972 #ls $REUSEBUILD/$signature/$module/RPMS/$TARGET_ARCH/* |
974 for dir in $REUSEBUILD/$signature/$module/RPMS/*; do
975 mkdir -p $dest/RPMS/${dir##*/}
977 xargs ln -t $dest/RPMS/${dir##*/} -s
990 if [[ $arch = i[3456]86 ]]; then
998 build_kernel_with_srpm() {
1000 # need to generate the patch for this target
1001 do_patch_linux false >&2 # sets global $FULL_PATCH (yeah, yuck)
1003 # get an md5sum of the kernel patch + config for reuse check
1004 # XXX really, there needs to be a signature and a CONFIG_FILE per arch
1006 local REUSE_SIGNATURE=$(cat $CONFIG_FILE $TARGET_FILE $FULL_PATCH | md5sum | cut -d" " -f1)
1008 # see if we can link to the reuse pool
1009 # XXX - hrm. i'm not convinced this doesn't belong in the reuse "library"
1010 local CAN_LINK_FOR_REUSE=false
1011 touch $REUSEBUILD/$$
1012 if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1013 CAN_LINK_FOR_REUSE=true
1017 # the extra version string to use for the kernel (which might be a reused
1019 local kernel_extra_version=""
1020 if $REUSERPM && reuse kernel "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1021 "$REUSE_SIGNATURE"; then
1022 # figure out the EXTRA_VERSION of the kernel we are re-using
1023 kernel_extra_version=$(ls $TOPDIR/RPMS/$TARGET_ARCH/kernel-lustre-*${lnxmaj}${EXTRA_VERSION_DELIMITER}${PRISTINE_EXTRA_VERSION}.*.$TARGET_ARCH.rpm)
1024 kernel_extra_version=${kernel_extra_version##*kernel-lustre-*${lnxmaj}${EXTRA_VERSION_DELIMITER}}
1025 kernel_extra_version=${kernel_extra_version%%.$TARGET_ARCH.rpm}
1027 # nothing cached, build from scratch
1028 if [ ! -r "$KERNELDIR/$KERNEL_SRPM" ]; then
1029 download_srpm "$CANONICAL_TARGET" "$KERNEL_SRPM"
1032 rpm -ivh $KERNELDIR/$KERNEL_SRPM --define "_topdir $TOPDIR" >&2 || {
1033 # should we clean this up or leave it for analysis?
1035 fatal 1 "Error installing kernel SRPM."
1038 # put the Lustre kernel patch into the RPM build tree
1039 cp $FULL_PATCH $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch
1040 prepare_and_build_srpm
1042 # store the resulting kernel RPM build tree for future use
1043 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1044 "kernel" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1045 "$CAN_LINK_FOR_REUSE"; then
1046 error "Failed to store kernel RPMS for reuse"
1050 kernel_extra_version=$EXTRA_VERSION
1053 # should now have the following RPMs
1054 # $TOPDIR/RPMS/$arch/kernel-lustre-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1055 # $TOPDIR/RPMS/$arch/kernel-lustre-devel-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1056 # $TOPDIR/RPMS/$arch/kernel-lustre-headers-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1057 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-common-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1058 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1060 echo $kernel_extra_version
1067 if ! $PATCHLESS; then
1068 local kernel_extra_version
1069 if ! kernel_extra_version=$(build_kernel_with_srpm); then
1070 fatal 1 "Failed to build the kernel from it's SRPM"
1072 #local kernel_extra_version="60-0.33_lustre.1.8.0.50.20090311172757"
1074 for arch in $BUILD_ARCHS; do
1076 local kernel_devel_rpm="$TOPDIR/RPMS/$arch/$(devel_kernel_name true)-$lnxmaj$EXTRA_VERSION_DELIMITER$kernel_extra_version.$arch.rpm"
1078 # install the -devel RPM in preparation for the lustre build
1079 if ! lnxrel="$kernel_extra_version" unpack_linux_rpm \
1080 $kernel_devel_rpm $EXTRA_VERSION_DELIMITER; then
1081 fatal 1 "Could not find the Linux tree in $kernel_devel_rpm"
1084 # XXX - superhack of all superhacks! kernel-lustre-devel doesn't
1085 # have have sources in it, so we need to pull them out of
1088 cp BUILD/kernel-lustre-${lnxmaj}/linux-${lnxmaj}.$arch/fs/ext3/*.[ch] \
1089 $TOPDIR/reused/usr/src/kernels/${lnxmaj}${EXTRA_VERSION_DELIMITER}${kernel_extra_version}-${arch}/fs/ext3
1092 # need to find and unpack the vendor's own kernel-devel for patchless
1095 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE" ${EXTRA_VERSION_DELIMITER:-"-"}); then
1096 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in ${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
1098 if ! lnxrel="$lnxrel" unpack_linux_rpm "$kernelrpm" \
1099 "${EXTRA_VERSION_DELIMITER:--}"; then
1100 fatal 1 "Could not find the Linux tree in $kernelrpm"
1104 # before lustre, build kernel-ib
1105 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
1106 # see if we can link to the reuse pool
1107 # XXX - hrm. i'm not convinced this doesn't belong in the reuse "library"
1108 local CAN_LINK_FOR_REUSE=false
1109 touch $REUSEBUILD/$$
1110 if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1111 CAN_LINK_FOR_REUSE=true
1115 local REUSE_SIGNATURE=$({ echo "$OFED_VERSION"; echo "$(find_linux_release ${LINUXOBJ:-$LINUX})"; cat "${LINUXOBJ:-${LINUX}}/include/linux/autoconf.h"; } | md5sum | cut -d" " -f1)
1116 if ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1117 "$REUSE_SIGNATURE"; then
1118 # stash away the existing built articles for a moment
1120 mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
1123 find . | cpio -pudlm ..
1127 create_rpmbuild_dirs
1130 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1131 "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1132 "$CAN_LINK_FOR_REUSE"; then
1133 error "Failed to store OFED RPMS for reuse"
1137 # put the stuff we stashed away back
1143 if build_lustre; then
1144 # the build worked. resolve any symlinked files (i.e. from reuse)
1145 # in RPMS/$arch to real files so that that that huge mess of
1146 # complication knows as LTS can copy them yet somewhere else.
1147 # is it any wonder this whole process is so damn so? anyone ever
1148 # heard of hardlinks? it this cool new thing that allows you save
1149 # tons of time and space by creating... well you can go read about
1150 # them if you have not heard about them yet.
1151 # can i say how much the implemenation of all of this really impedes
1153 pushd RPMS/$TARGET_ARCH
1155 if [ -h $file ]; then
1164 create_rpmbuild_dirs() {
1166 if [ ! -d RPMS ]; then
1168 for arch in $BUILD_ARCHS; do
1172 [ -d BUILD ] || mkdir BUILD
1173 [ -d SOURCES ] || mkdir SOURCES
1174 [ -d SPECS ] || mkdir SPECS
1175 [ -d SRPMS ] || mkdir SRPMS
1197 [[ $list\ == *\ $item\ * ]]
1201 #########################################################################
1202 # Generate a backtrace through the call stack.
1206 #########################################################################
1210 local funcname="" sourcefile="" lineno="" n
1212 echo "Call stack: (most recent first)"
1213 for (( n = $strip ; n < ${#FUNCNAME[@]} ; ++n )) ; do
1214 funcname=${FUNCNAME[$n - 1]}
1215 sourcefile=$(basename ${BASH_SOURCE[$n]})
1216 lineno=${BASH_LINENO[$n - 1]}
1217 # Display function arguments
1218 if [[ ! -z "${BASH_ARGV[@]}" ]]; then
1219 local args newarg j p=0
1220 for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do
1221 newarg=${BASH_ARGV[$j + $p - 1]}
1222 args="${args:+${args} }'${newarg}'"
1224 let p+=${BASH_ARGC[$n - 1]}
1226 echo " ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}"
1230 echo "BEGIN BACKTRACE"
1232 #echo ${BASH_LINENO[*]}
1233 #echo ${BASH_SOURCE[*]}
1234 #echo ${FUNCNAME[*]}
1235 local i=$((${#FUNCNAME[@]} - 1))
1236 while [ $i -ge 0 ]; do
1237 local SOURCELINE="${BASH_SOURCE[$i + 1]}:${BASH_LINENO[$i]}"
1238 # Can't figure out how to get function args from other frames...
1239 local FUNCTION="${FUNCNAME[$i]}()"
1240 echo "$SOURCELINE:$FUNCTION"
1244 echo "END BACKTRACE"
1250 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1252 options=$(getopt -o d:D:h -l kerneltree:,distro:,kernelrpm:,reusebuild:,patchless,ldiskfs,ccache,reuse:,norpm,disable-datestamp,external-patches:,timestamp:,extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,publish,release,src,stage:,tag:,target:,target-archs:,with-linux:,xen -- "$@")
1254 if [ $? != 0 ]; then
1258 eval set -- "$options"
1293 if ! KERNELTREE=$(canon_path "$2"); then
1294 fatal 1 "Could not determine the canonical location of $2"
1298 --linux | --with-linux)
1299 if ! LINUX=$(canon_path "$2"); then
1300 fatal 1 "Could not determine the canonical location of $2"
1313 if ! REUSEBUILD=$(canon_path "$2"); then
1314 fatal 1 "Could not determine the canonical location of $2"
1331 if ! KERNELRPMSBASE=$(canon_path "$2"); then
1332 fatal 1 "Could not determine the canonical location of $2"
1379 --disable-datestamp)
1390 CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-liblustre --enable-liblustre-tests"
1394 usage 1 "Unrecognized option: $1"
1404 EXTRA_VERSION_DELIMITER=${EXTRA_VERSION_DELIMITER:-"-"}
1406 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
1411 # make sure the RPM build environment is set up
1412 create_rpmbuild_dirs
1414 trap '[ -n "$CCACHE" ] && ccache -s' EXIT
1416 # if an unpacked kernel source tree was given on the command line
1417 # just build lustre with it (nothing distro kernel specific here)
1418 if [ -n "$LINUX" ]; then
1421 if [ -f "${0%/*}/lbuild-$DISTRO" ]; then
1422 seen_list=$(new_list)
1423 trap '(echo "Untrapped error"
1425 # have we seen this one
1426 echo "checking seen list for ${BASH_SOURCE[0]}:${BASH_LINENO[0]}"
1428 if is_list_member "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"; then
1429 echo "seen this one already"
1431 seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
1437 ) | tee >(mail -s "Untrapped error in lbuild on $MACHINENAME" brian@sun.com) >&2' ERR
1440 source ${0%/*}/lbuild-$DISTRO
1442 build_with_srpm || fatal 1 "Failed to build_with_srpm"
1444 source ${0%/*}/lbuild.old_school
1446 old_school_download_kernel
1450 patchless_build_sequence && build_success=true
1452 [ "$DISTRO" = "sles9" ] && build_sequence_rpm_reuse && build_success=true
1453 if ! $build_success; then
1454 build_sequence_reuse && build_success=true
1455 if ! $build_success; then
1456 build_sequence && build_success=true
1457 if $build_success; then
1458 store_for_reuse || echo "Cannot store for future reuse"
1463 ( $build_success ) || fatal 1 "Cannot build lustre"