3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
5 # this is an alternative FD for stdout, to be used especially when we are
6 # taking stdout from a function as it's return value. i.e. foo=$(bar)
7 # this is a workaround until a version of bash where we can put xtrace
13 if [[ $SHELLOPTS = *xtrace* ]]; then
18 # include the exit_traps library
19 . ${0%/lbuild}/exit_traps.sh
21 # our children should die when we do
22 push_exit_trap "kill -INT -$$ || true" kill_children
26 # CVSROOT is inherited from the environment
31 # XXX - some recent hacking has pretty much neutered this option.
32 # search through this file (and lbuild.old_school -- but that will
33 # be going away soon) for "-bb" and see how many places
34 # simply don't account for this option
40 TARGET_ARCH=$(uname -m)
42 TARGET_ARCHS_ALL=$TARGET_ARCH
43 [ "$TARGET_ARCH" = "i686" ] && TARGET_ARCHS_ALL="i686 i586 i386"
49 TMPDIR=${TMPDIR:-"/var/tmp"}
51 # this is a dir to try reuse old kernel RPMs in (although, it seems to be
52 # unused in any real manner
54 # this is the dir that should be used to store reuse products
56 # should cached products be used or force rebuilding?
58 # what does this do exactly? does it imply no kernel build?
61 SKIPLDISKFSRPM="v1_4_* b1_4"
62 SMPTYPES="smp bigsmp default ''"
68 # default to not adding -lustre- into the kernel RPM package names
69 KERNEL_LUSTRE_NAMING=false
86 # not in the target file any more
89 # build the lustre-tests rpm?
92 # these are disabled by default, enabled with command line switches or by
93 # the calling environment
94 BUILD_MPTLINUX=${BUILD_MPTLINUX:-false}
95 BUILD_RDAC=${BUILD_RDAC:-false}
106 # Readlink is not present on some older distributions: emulate it.
110 if [ -L "$path" ]; then
111 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
126 [ -n "$msg" ] && echo -e "\n${0##*/}: $msg" >&3
140 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
143 Specifies the CVS Root to use when pulling files from CVS. The
144 environment variable \$CVSROOT is used if this option is not
147 --external-patches=EXTERNAL_PATCHES
148 Directory similar to lustre/lustre/kernel_patches/ that lbuild should
149 look for seres and config files in before looking in the lustre
152 --extraversion=EXTRAVERSION
153 Text to use for the rpm release and kernel extraversion.
155 --timestamp=TIMESTAMP
156 Date of building lustre in format YYYYMMDDhhmmss
159 Try to reuse old kernel RPMs from DIR
162 Try to reuse old kernel builds from DIR
165 Path to distro kernel RPM collection
171 Do not build RPMs (compile only mode)
174 Build lustre client only
177 Which distro using. Autodetect by default
179 --kerneldir=KERNELDIR
180 Directory containing Linux source tarballs referenced by target
183 --kerneltree=KERNELTREE
184 Directory containing dirs with Linux source tarballs referenced by target
185 files. Dir names in format kernel version ('2.6.9', etc.)
187 --linux=LINUX --with-linux=LINUX
188 Directory of Linux kernel sources. When this option is used, only
189 Lustre modules and userspace are built.
192 Path to an existing lustre source tarball to use instead of
196 Do not try to download a kernel from downloads.lustre.org
199 Do not build a .src.rpm, a full kernel patch, or a patched kernel
203 Do ldiskfs RPM. Now true by default
209 Specifies that the files generated do not include timestamps, and
210 that this is an official release.
213 Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
216 Directory used to stage packages for release. RPMs will be placed
217 more or less in DIR/<target>-<arch>, and the tarball will be
221 A CVS branch/tag name to build from when pulling from CVS.
224 The name of the target to build. The available targets are listed
227 --target-archs=TARGET_ARCHS
228 A (space delimited) list of architectures to build. By default,
229 all of the archs supported by the TARGET will be built, in
230 addition to a .src.rpm. This option can limit those, for machines
231 that can only build certain archs or if you only want a certain
232 arch built (for testing, or a one-off kernel).
234 Also note that by using a non-"base" arch (eg, i386) only kernels
235 will be built - there will be no lustre-lite-utils package.
238 Prevents the datestamp flag (-D) from being passed to cvs for
239 checkouts. This is a workaround for a problem encountered when
240 using lbuild with tinderbox.
243 Builds a Xen domX kernel.
246 Enables the building of MPTLINUX with the same kernel Lustre is
250 Enables the building of MPTLINUX with the same kernel Lustre is
254 Set's a variable to a given value.
263 # canonicalize a relative path
267 if [ ! -d "$PATH" ]; then
271 pushd "$PATH" >/dev/null || return 1
281 if [ "$LUSTRE" ]; then
282 [ -r "$LUSTRE" ] || \
283 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
286 usage 1 "Either specify a CVS Root with -d, or a Lustre source tarball with --lustre."
288 usage 1 "A branch/tag name must be specified with --tag when not building from a tarball."
291 if [ -z "$LINUX" ]; then
292 [ "$KERNELDIR" -o "$KERNELTREE" ] || \
293 usage 1 "A kernel directory must be specified with --kerneldir or --kerneltree."
295 [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
296 usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
300 usage 1 "When building a snapshot, a tag name must be used."
303 [ "$TARGET" ] || usage 1 "A target must be specified with --target."
304 # TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
305 # [ -r "$TARGET_FILE" ] || \
306 # usage 1 "Target '$TARGET' was not found."
311 CANONICAL_TARGET="rhel5"
314 CANONICAL_TARGET="rhel-2.6"
317 CANONICAL_TARGET="sles-2.6"
320 CANONICAL_TARGET="sles10-2.6"
323 CANONICAL_TARGET="sles11"
326 CANONICAL_TARGET="oel5"
329 CANONICAL_TARGET="hp-pnnl-2.4"
337 CANONICAL_TARGET="$TARGET"
341 local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
342 [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
343 local timestamplength="${#TIMESTAMP}"
344 if [ $timestamplength -eq 12 ]; then
345 TIMESTAMP="${TIMESTAMP}00"
346 elif [ $timestamplength -ne 14 ]; then
347 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
350 RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
351 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
352 RPMBUILD=$(which rpm 2>/dev/null | head -1)
353 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
354 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
358 if [ -n "$CCACHE" ]; then
359 which "$DISTCC" &>/dev/null && export DISTCC RPM_BUILD_NCPUS
361 if which "$CCACHE" &>/dev/null; then
362 local ccache=$(which "$CCACHE")
363 local bindir="$TOPDIR/bin"
365 if [ ! -d $bindir ]; then
366 mkdir -p $bindir || fatal 1 "error trying to create $bindir"
368 rm ${bindir}/* > /dev/null 2>&1 || true
370 ln -s "$ccache" ${bindir}/ccache
371 ln -s "$ccache" ${bindir}/cc
372 ln -s "$ccache" ${bindir}/$CC
373 export PATH=$bindir:$PATH
374 export CCACHE && export CC="ccache $CC"
375 # zero the cache so we can see how effective we are being with it
379 # get some ccache stats when we are done
380 push_exit_trap '[ -n "$CCACHE" ] && ccache -s' "ccache_summary"
381 # should remove the ccache trap if lbuild is interrupted
382 trap 'echo "Received an INT TERM or HUP signal, terminating."; delete_exit_trap "ccache_summary"; exit 1' INT TERM HUP
386 [ -z "$DISTRO" ] && DISTRO=$(autodetect_distro)
392 # autodetect used Distro
393 autodetect_distro() {
398 if [ -f /etc/SuSE-release ]; then
400 version=$(grep ^VERSION /etc/SuSE-release)
401 version=${version#*= }
402 elif [ -f /etc/redhat-release ]; then
403 name=$(head -1 /etc/redhat-release)
404 version=$(echo "$distroname" |
405 sed -e 's/^[^0-9.]*//g' | sed -e 's/[ \.].*//')
407 if [ -z "$name" -o -z "$version" ]; then
408 fatal 1 "I don't know how to determine distro type/version.\nEither update autodetect_distro() or use the --distro argument"
411 echo ${name}${version}
418 echo $(echo "$*" | xargs -n 1 | sort -u)
425 local force="${3:-false}"
427 if $force || [ ! -r "$KERNELDIR/$srpm" ] ||
428 [ ! -s "$KERNELDIR/$srpm" ]; then
430 local location="http://downloads.lustre.org/public/kernels/$target/old"
431 echo "Downloading $location/$srpm..."
432 if ! wget -nv "$location/$srpm" -O "$KERNELDIR/$srpm" 2>&1 ||
433 [ ! -s "$KERNELDIR/$srpm" ]; then
434 rm -f $KERNELDIR/$srpm
435 fatal 1 "Could not download target $target's kernel SRPM $srpm from $location."
438 fatal 1 "$srpm not found in directory $KERNELDIR."
449 local file=${from##*/}
455 local semaphore="$to-downloading"
458 if [ ! -f $semaphore ]; then
462 # make sure the download has not been aborted
463 local now=$(date +%s)
464 local file_mtime=$(stat -c %Y "$to")
465 local staleness=$((now - file_mtime))
466 # let's assume an active download will write at least once a minute
467 if [ $staleness -gt 60 ]; then
475 # if the semaphore file exists, the file is either still downloading
476 # or a download was aborted and we cannot trust the target file
477 if [ -f $semaphore ]; then
481 if ! is_downloading && [ -r "$to" ] && [ -s "$to" ]; then
488 if $force || ! is_downloaded; then
489 if is_downloading; then
490 echo "Somebody else is downloading $from..."
491 while is_downloading; do
492 echo "Waiting for $to to finish downloading"
495 if is_downloaded; then
498 echo "The download we were waiting for seems to have been aborted"
504 echo "Downloading $from..."
505 # flag others so they don't try to download also
506 push_exit_trap "rm -f $to $semaphore" "download"
508 if ! wget -nv "$from" -O "$to" || [ ! -s "$to" ]; then
509 # the trap will remove the files via the fatal below
510 fatal 1 "Could not download ${to##*/} from ${from%/*}/."
513 delete_exit_trap "download"
515 fatal 1 "${to##*/} not found in directory ${to%/*}."
524 local force="${1:-false}"
526 local location="http://downloads.lustre.org/public/OFED/"
529 if [[ $OFED_VERSION = daily-* ]]; then
530 OFED_VERSION=${OFED_VERSION/daily-/}
531 Mmv=${OFED_VERSION%%-*}
532 daily=${OFED_VERSION##$Mmv-}
533 location="http://www.openfabrics.org/downloads/OFED/ofed-${Mmv}-daily/"
534 # find the filename for the version for the date specified
535 OFED_VERSION=$(curl -s "$location" | sed -nre "/${daily}-/s/.*href=\"OFED-(${Mmv//./\\.}-${daily}-[0-9]{4,4}).tgz.*$/\1/p" | tail -1)
536 if [ -z "$OFED_VERSION" ]; then
537 fatal 1 "Could not determine the filename of the OFED snapshot for ${daily}"
541 if [ -z "$OFED_VERSION" -o "$OFED_VERSION" = "inkernel" ]; then
545 local file="OFED-${OFED_VERSION}.tgz"
546 download_file "$location/$file" "$KERNELTREE" "$force"
552 EXTRA_VERSION_save="$EXTRA_VERSION"
553 for patchesdir in "$EXTERNAL_PATCHES" \
554 "$TOPDIR/lustre/lustre/kernel_patches"; do
555 TARGET_FILE="$patchesdir/targets/$TARGET.target"
556 [ -r "$TARGET_FILE" ] && break
558 [ -r "$TARGET_FILE" ] || fatal 1 "Target $TARGET was not found."
560 echo "Loading target config file $TARGET.target..."
562 # if the caller specified an OFED_VERSION it should override whatever
563 # the target file specifies
564 local env_OFED_VERSION="$OFED_VERSION"
568 if [ -n "$env_OFED_VERSION" ]; then
569 OFED_VERSION="$env_OFED_VERSION"
572 # doesn't make any sense to build OFED for xen domX's
577 # XXX - set_rpm_smp_type is an ugly undeterministic hack. it needs to
578 # go away and the target just specify the $RPMSMPTYPE
579 [ -z "$RPMSMPTYPE" ] && set_rpm_smp_type
581 # CC might have been overwriten in TARGET_FILE
582 if [[ $CC != ccache\ * ]] && which "$CCACHE" &>/dev/null; then
583 export CCACHE && export CC="ccache $CC"
586 if [ ! "$KERNELTREE" = "" ] && [ -d "$KERNELTREE" ]; then
587 KERNELDIR="$KERNELTREE/${lnxmaj}"
588 [ -d "$KERNELDIR" ] || mkdir "$KERNELDIR"
591 # verify the series is available
592 if [ "$SERIES" ]; then
593 for series in $SERIES; do
594 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
595 [ -r "$patchesdir/series/$series" ] && continue 2
597 fatal 1 "Target $TARGET's series $SERIES could not be found.\nSearched:\n\t$EXTERNAL_PATCHES/series\n\t$TOPDIR/lustre/lustre/kernel_patches/series."
601 # set the location of the .config file
607 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
608 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH${RPMSMPTYPE:+-}${RPMSMPTYPE}.config"
611 local lnxrelnew=${lnxrel//-/_}
613 # remember the EXTRA_VERSION before we diddle it here
614 # XXX - we really should not diddle with any values read in from the
615 # target file. if we want to modify a value, we should create
617 PRISTINE_EXTRA_VERSION=$EXTRA_VERSION
619 if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
620 fatal 1 "Config file for target $TARGET missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
623 if [ "$EXTRA_VERSION_save" ]; then
624 EXTRA_VERSION="$EXTRA_VERSION_save"
625 elif ! $RELEASE; then
626 # if there is no patch series, then this is not a lustre specific
627 # kernel. don't make it look like one
628 if $PATCHLESS || [ -n "$SERIES" ]; then
629 EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
630 # EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}"
631 EXTRA_VERSION="${EXTRA_VERSION}.${TIMESTAMP}"
634 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
636 ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
639 for arch in $(uniqify "$ALL_ARCHS"); do
640 if [ -z "$TARGET_ARCHS" ] ||
641 [[ \ $TARGET_ARCHS\ = *\ $arch\ * ]]; then
642 BUILD_ARCHS="$BUILD_ARCHS $arch"
645 [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
646 echo "Building for: $BUILD_ARCHS"
654 fatal 1 "tarflags(): File name argument missing."
666 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
675 local extractfile="$@"
677 echo "Untarring ${tarfile##*/}..."
678 tar $(tarflags "$tarfile") "$tarfile" $extractfile
684 if ! untar "$KERNELTREE/OFED-${OFED_VERSION}.tgz"; then
687 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
693 if ! untar "$KERNELTREE/rdac-LINUX-${RDAC_VERSION}-source.tar.gz"; then
696 [ -d rdac-LINUX ] || ln -sf rdac-LINUX-[0-9][0-9].* rdac-LINUX
702 if ! untar $KERNELTREE/SUN_MPTLINUX_RHEL5_PH16-${MPTLINUX_VERSION}.tar.gz pkg1-rhel5/srpms-1/mptlinux-${MPTLINUX_VERSION}-1.src.rpm; then
705 mv pkg1-rhel5/srpms-1/mptlinux-${MPTLINUX_VERSION}-1.src.rpm .
711 if [ -z "$LUSTRE" ]; then
714 if [ -n "$USE_DATESTAMP" ]; then
715 DATESTAMP="-D '$DATE'"
718 local DIRNAME="lustre-$TAG-$TIMESTAMP"
720 cvs -d "$CVSROOT" -qz3 co $DATESTAMP -d "$DIRNAME" lustre || \
721 fatal 1 "There was an error checking out toplevel Lustre from CVS."
722 pushd "$DIRNAME" > /dev/null
723 ./lustrecvs "$TAG" || \
724 fatal 1 "There was an error checking out Lustre/Portals/Build from CVS."
725 echo "Creating lustre tarball..."
726 sh autogen.sh || fatal 1 "There was an error running autogen.sh."
727 ./configure --disable-{modules,utils,liblustre,tests,doc} || \
728 fatal 1 "There was an error running ./configure to create makefiles."
729 make dist || fatal 1 "There was an error running 'make dist'."
730 LUSTRE=$PWD/lustre-*.tar.gz
734 untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
735 [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
741 local do_patch=${1:-true}
743 FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
744 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
745 $do_patch && pushd linux >/dev/null
746 for series in $SERIES; do
747 echo -n "Applying series $series:"
748 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
749 [ -r "$patchesdir/series/$series" ] || continue
750 SERIES_FILE="$patchesdir/series/$series"
751 for patch in $(<"$SERIES_FILE"); do
753 PATCH_FILE="$patchesdir/patches/$patch"
754 [ -r "$PATCH_FILE" ] || \
755 fatal 1 "Patch $patch does not exist in Lustre tree."
756 cat "$PATCH_FILE" >> "$FULL_PATCH" || {
758 fatal 1 "Error adding patch $patch to full patch."
761 patch -s -p1 < "$PATCH_FILE" 2>&1 || {
763 fatal 1 "Error applying patch $patch."
771 $do_patch && popd >/dev/null
772 echo "Full patch has been saved in ${FULL_PATCH##*/}."
782 pushd lustre >/dev/null
784 echo "Building Lustre RPMs for: $BUILD_ARCHS..."
786 for arch in $BUILD_ARCHS; do
787 targets="--target $arch $targets"
790 local confoptions="--with-linux=${linux}"
792 confoptions="--with-linux=${linux} --disable-server"
794 if [ "$linuxobj" != "" ]; then
795 confoptions="$confoptions --with-linux-obj=${linuxobj}"
798 ./configure $confoptions ${CONFIGURE_FLAGS} 2>&1
799 if [ "$?" != "0" ]; then
800 local saved_config="../config.log.$(date +%s)"
801 cp config.log $saved_config
802 chmod a+r $saved_config
803 echo "Saved config.log is at $saved_config"
807 echo "config.log contents:"
815 # hack. Somebody move build/lustre.spec to lustre.spec for b1_6
817 [ -f lustre.spec ] && lustre_spec=lustre.spec
818 [ -f build/lustre.spec ] && lustre_spec=build/lustre.spec
820 [ -f "$lustre_spec" ] && sed \
821 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
825 local rpmbuildopt='-bb'
828 echo NORPM mode. Only compiling.
831 # convert the $PATCHLESS boolean to an empty/not-empty boolean
832 # as silly as this seems, it makes the syntax of the rpmbuild command
833 # simpler and not need an eval to deal with the quotes in the quotes
834 local is_patchless=""
839 # ditto for the lustre-tests boolean
840 local lustre_tests=""
841 if ! $LUSTRE_TESTS; then
845 $RPMBUILD $targets $rpmbuildopt ../lustre.spec \
846 ${is_patchless:+--define "lustre_name lustre-client"} \
847 ${lustre_tests:+--define "build_lustre_tests 0"} \
848 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
849 --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \
850 --define "_tmppath $TMPDIR" \
851 --define "_topdir $TOPDIR" 2>&1 || \
852 fatal 1 "Error building rpms for $BUILD_ARCHS."
855 ( $(skeep_ldiskfs_rpm $TAG) ) && return
857 pushd lustre/ldiskfs || return 255
859 if [ "$?" != "0" ]; then
863 cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES
867 local ldiskfs_spec=lustre-ldiskfs.spec
868 [ -f "$ldiskfs_spec" ] && sed \
869 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
871 > ../lustre-ldiskfs.spec
873 if ! $RPMBUILD $targets $rpmbuildopt ../lustre-ldiskfs.spec \
874 --define "_tmppath /var/tmp" \
875 --define "_topdir $TOPDIR" 2>&1; then
881 if ! $RPMBUILD -bs ../lustre-ldiskfs.spec \
882 --define "_tmppath /var/tmp" \
883 --define "_topdir $TOPDIR" 2>&1; then
894 [ "$STAGEDIR" ] || return 0
896 for arch in $BUILD_ARCHS; do
897 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
898 echo "${0##*/}: Copying RPMs into ${rpmdir}"
900 cp -v RPMS/${arch}/*.rpm "${rpmdir}"
901 if [ -d RPMS/noarch ]; then
902 cp -v RPMS/noarch/*.rpm "${rpmdir}"
906 cp -v "$LUSTRE" "$STAGEDIR"
910 #check if we need to build separate ldiskfs RPM
911 skeep_ldiskfs_rpm() {
916 if ! $LDISKFSRPM; then
918 elif $PATCHLESS; then
921 for skiptag in $SKIPLDISKFSRPM; do
922 [[ $tag == $skiptag ]] && skip=true && break
926 pushd $TOPDIR/BUILD/lustre-[1-9]* >/dev/null
927 grep -q '^SERVER_TRUE[ \t]=[ \t]#$' autoMakefile && skip=true
934 #generate LUSTRE_EXTRA_VERSION from EXTRA_VERSION
935 gen_lustre_version() {
937 LUSTRE_EXTRA_VERSION="${lnxmaj}-${EXTRA_VERSION}${FLAVOR_DELIMITER}${RPMSMPTYPE}"
938 LUSTRE_EXTRA_VERSION=${LUSTRE_EXTRA_VERSION//-/_}
944 local infact_arch="${TARGET_ARCH}"
947 [ "$infact_arch" == "i586" ] && infact_arch="i686"
950 for smp_type in $SMP_ARCHS; do
951 [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
954 for smp_type in $BIGSMP_ARCHS; do
955 [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
958 for smp_type in $PPC64_ARCHS; do
959 [ $infact_arch == $smp_type ] && RPMSMPTYPE=ppc64 && break
962 for smp_type in $DEFAULT_ARCHS; do
963 [ $infact_arch == $smp_type ] && RPMSMPTYPE=default && break
968 # This function takes a linux source pool and digs out the linux release
970 find_linux_release() {
973 local LINUXRELEASEHEADER=$SRCDIR/include/linux/version.h
974 if [ -s $SRCDIR/include/linux/utsrelease.h ]; then
975 LINUXRELEASEHEADER=$SRCDIR/include/linux/utsrelease.h
978 sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
982 # XXX this needs to be re-written as a wrapper around find_rpm
983 # or just gotten rid of. :-)
987 local pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
988 [ -d $pathtorpms ] || return 255
990 local kernelbinaryrpm rpmfile
991 local wanted_kernel="${lnxmaj}${lnxmin}-${lnxrel}"
994 for arch in $TARGET_ARCHS_ALL; do
995 local found_rpm="" rpm
996 for rpm in ${pathtorpms}/${arch}/*.rpm; do
997 if rpm -q --provides -p "$rpm" 2>&3 | grep -q "kernel${prefix} = $wanted_kernel" 2>&3; then
1004 [ -f "$found_rpm" ] && break
1012 # unpack kernel(/source/devel) RPM
1014 # This function and it's setting of $LINUX and $LINUXOBJ is a total hack that
1015 # needs to completely refactored. It completely ingores that $BUILD_ARCHS may
1016 # contain a list of arches for which rpmbuild commands (including the one for
1018 unpack_linux_devel_rpm() {
1019 local kernelrpm="${1}"
1021 [ -f "$kernelrpm" ] || return 255
1022 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused || return 255
1024 pushd $TOPDIR/reused &>/dev/null || return 255
1026 if ! rpm2cpio < "$kernelrpm" | cpio -id > /dev/null 2>&1; then
1030 # call a distro specific hook, if available
1031 if type -p unpack_linux_devel_rpm-$DISTRO; then
1032 if ! unpack_linux_devel_rpm-$DISTRO "$kernelrpm"; then
1039 find_linux_devel_paths $TOPDIR/reused
1048 # build kernel-ib{,-devel}
1050 # ofed 1.3 had a bug in the rpm spec
1051 if [ "$OFED_VERSION" = "1.3" ]; then
1055 local OFED_CORE="--with-core-mod --with-ipoib-mod --with-sdp-mod --with-user_mad-mod --with-user_access-mod --with-addr_trans-mod --with-rds-mod --with-qlgc_vnic-mod --with-madeye-mod"
1056 local OFED_HARDWARE="--with-mthca-mod --with-mlx4-mod --with-mlx4_en-mod --with-cxgb3-mod --with-nes-mod"
1057 # some I/B drivers are architecture dependent and kernel-ib's configure
1058 # does not figure it out for us ~sigh~
1059 case "$TARGET_ARCH" in
1061 OFED_HARDWARE="$OFED_HARDWARE --with-ehca-mod"
1064 # we're no longer shipping the OFED iSCSI
1065 #OFED_ISCSI="--with-srp-mod --with-srp-target-mod"
1066 ## ISER module has no backport support as of OFED 1.5 (i.e. only builds on
1067 ##kernels >= 2.6.30)
1068 #if [[ $OFED_VERSION = 1.[0-4]* ]]; then
1069 # OFED_ISCSI="$OFED_ISCSI --with-iser-mod"
1072 # assume we are just rebuilding the SRPM
1073 local BUILD_TYPE=${BUILD_TYPE:-"--rebuild"}
1074 local SOURCE="${TOPDIR}/OFED/SRPMS/ofa_kernel-*.src.rpm"
1076 # but switch to building from the SPEC if we need to apply patches
1077 if ls ${TOPDIR}/lustre/build/patches/ofed/* >/dev/null; then
1079 rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
1080 SOURCE="${TOPDIR}/SPECS/ofa_kernel.spec"
1081 local file ed_fragment1 ed_fragment2 n=1
1082 for file in $(ls ${TOPDIR}/lustre/build/patches/ofed/*); do
1083 ed_fragment1="$ed_fragment1
1084 Patch$n: ${file%%*/}"
1085 ed_fragment2="$ed_fragment2
1087 cp $file ${TOPDIR}/SOURCES
1091 if [ $n -gt 1 ]; then
1104 local linuxrelease=$(find_linux_release "$linux")
1105 if ! $RPMBUILD $BUILD_TYPE --define 'build_kernel_ib 1' --define 'build_kernel_ib_devel 1' \
1106 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1107 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1108 --define "KVERSION ${linuxrelease}" \
1109 --define "$K_SRC ${linux}" \
1110 --define "LIB_MOD_DIR /lib/modules/${linuxrelease}/updates" \
1111 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1112 --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
1113 ${SOURCE} 2>&1; then
1114 fatal 1 "Error building kernel-ib"
1123 local signature="$4"
1124 local use_links="$5"
1131 location="$location"/"$signature"/"$module"
1132 mkdir -p "$location"
1133 # the cleanup script removes any directory that doesn't have a
1134 # .lastused, so let's try to prevent that as soon as we can
1135 # this solution still slightly racy with the cleanup script
1136 # but the race is a lot tighter now
1137 touch -t 197001010000 "$location/.lastused"
1138 ## use eval/echo here to make sure shell expansions are performed
1139 #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
1141 for article in $(eval echo $articles); do
1142 if ! cp -a${linkflag} "$article" "$location"; then
1143 error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
1144 # rename the cache location so that it's not cached
1145 # product, but is around for analysis
1146 mv "$location"{,-bad-$(date +%s)} ||
1147 error "failed to clean up a failed cache attempt" \
1148 "in \"$location\" -- manual cleanup will be" \
1154 # flag the cache as complete (i.e. in case lbuild was previously
1155 # interrupted while caching)
1156 touch "$location/.lastused"
1165 local use_links="${3:-false}"
1166 local signature="$4"
1168 if [ -n "$REUSEBUILD" ] && [ -d "$REUSEBUILD/$signature/$module" ]; then
1169 if [ ! -f "$REUSEBUILD/$signature/$module/.lastused" ]; then
1170 # the .lastused flag is populated at the end of the caching to
1171 # signal that the caching was completed. if that flag is not
1172 # there, then the cache is invalid (and should be removed in fact)
1173 mv "$REUSEBUILD/$signature/$module"{,-bad-$(date +%s)} ||
1174 fatal 1 "failed to clean up a bad cache in location $REUSEBUILD/$signature/$module\" -- manual cleanup will be necessary"
1178 # so that we know how stale this entry is
1179 touch $REUSEBUILD/$signature/$module/.lastused
1182 if ls $REUSEBUILD/$signature/$module/* >/dev/null 2>&1; then
1183 cp -al $REUSEBUILD/$signature/$module/* $dest/
1186 # copying is pretty heavy
1187 # cp -a $REUSEBUILD/$signature/$module/* $dest/
1188 # do some creative symlinking instead
1190 for dir in BUILD SRPMS SPECS; do
1191 if ls $REUSEBUILD/$signature/$module/$dir/* >/dev/null 2>&1; then
1192 ln -s $REUSEBUILD/$signature/$module/$dir/* $dest/$dir
1195 # sources have to be copied by file because we need SOURCES to
1196 # be a dir we can write into
1197 # could overrun ls's arg list here
1198 #ls $REUSEBUILD/$signature/$module/SOURCES/* |
1199 find $REUSEBUILD/$signature/$module/SOURCES/ -type f |
1200 xargs ln -t $dest/SOURCES -s
1202 # same for RPMS/* dirs
1203 # could overrun ls's arg list here
1204 #ls $REUSEBUILD/$signature/$module/RPMS/$TARGET_ARCH/* |
1206 for dir in $REUSEBUILD/$signature/$module/RPMS/*; do
1207 mkdir -p $dest/RPMS/${dir##*/}
1209 xargs ln -t $dest/RPMS/${dir##*/} -s
1222 if [[ $arch = i[3456]86 ]]; then
1231 # in a given directory, find the first rpm matching given requirements
1235 local match_type="$2"
1238 pushd "$dir" > /dev/null || \
1239 fatal 1 "Unable to chdir to directory \"$dir\" in find_rpm()"
1242 for file in $(ls *.rpm); do
1243 if [ ! -f "$file" ]; then
1246 case "$match_type" in
1248 # match is any valid ERE (i.e. given to egrep) match
1249 if rpm -q --provides -p "$file" 2>&3 | egrep -q "$match"; then
1257 fatal 1 "Unknown match type \"$match_type\" given to find_rpm()"
1266 build_kernel_with_srpm() {
1269 if [ -z "$outfd" ] || [ $outfd = 1 ]; then
1270 fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
1273 # need to generate the patch for this target
1274 do_patch_linux false >&${outfd} # sets global $FULL_PATCH (yeah, yuck)
1276 # get an md5sum of the kernel patch + config for reuse check
1277 # XXX really, there needs to be a signature and a CONFIG_FILE per arch
1281 local release_str="RELEASE=$RELEASE\n"
1284 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1285 local REUSE_SIGNATURE=$({ echo -en $release_str;
1287 cat $CONFIG_FILE $TARGET_FILE $FULL_PATCH; } |
1288 md5sum | cut -d" " -f1)
1289 # see if we can link to the reuse pool
1290 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1292 local CAN_LINK_FOR_REUSE=false
1293 touch $REUSEBUILD/$$
1294 if cp -al $REUSEBUILD/$$ $TOPDIR/ 2>/dev/null; then
1295 CAN_LINK_FOR_REUSE=true
1300 # the extra version string to use for the kernel (which might be a reused
1302 local kernel_extra_version=""
1303 if ! $USE_BUILD_CACHE || ! reuse kernel "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1304 "$REUSE_SIGNATURE"; then
1305 # nothing cached, build from scratch
1306 if [ ! -r "$KERNELDIR/$KERNEL_SRPM" ]; then
1307 echo "Downloading kernel SRPM"
1308 download_srpm "$CANONICAL_TARGET" "$KERNEL_SRPM" >&${outfd}
1311 if ! rpm -ivh $KERNELDIR/$KERNEL_SRPM \
1312 --define "_topdir $TOPDIR" >&${outfd} 2>&1; then
1313 # should we clean this up or leave it for analysis?
1315 fatal 1 "Error installing kernel SRPM."
1318 # put the Lustre kernel patch into the RPM build tree
1319 cp $FULL_PATCH $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch
1320 prepare_and_build_srpm >&${outfd} ||
1321 fatal 1 "failed to prepare_and_build_srpm"
1323 if [ -z "$REUSE_SIGNATURE" ]; then
1324 echo "No reuse signature was caculated so not storing the built kernel" >&${outfd}
1326 # store the resulting kernel RPM build tree for future use
1327 echo "Storing the built kernel for future reuse" >&${outfd}
1328 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1329 "kernel" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1330 "$CAN_LINK_FOR_REUSE"; then
1331 error "Failed to store kernel RPMS for reuse"
1338 # figure out the EXTRA_VERSION of the kernel we built or are re-using
1340 if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel ="); then
1341 fatal 1 "Failed to find a kernel RPM in $TOPDIR/RPMS/$TARGET_ARCH/"
1343 kernel_extra_version=$(rpm -q --queryformat "%{RELEASE}" -p $TOPDIR/RPMS/$TARGET_ARCH/$KERNEL_RPM)
1345 # should now have the following RPMs
1346 # $TOPDIR/RPMS/$arch/kernel-lustre-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1347 # $TOPDIR/RPMS/$arch/kernel-lustre-devel-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1348 # $TOPDIR/RPMS/$arch/kernel-lustre-headers-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1349 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-common-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1350 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1352 echo $kernel_extra_version
1361 if ! $BUILD_RDAC || [ -z "$version" -o "$version" = "inkernel" ]; then
1366 for arch in $BUILD_ARCHS; do
1367 targets="--target $arch $targets"
1370 local rpmbuildopt='-bb'
1373 echo NORPM mode. Only compiling.
1376 # if only we could just rebuild the src.rpm. but the included spec
1377 # is a real pig's breakfast. just check out the patch we need to
1378 # apply to it to make it useful.
1379 #$RPMBUILD --rebuild \
1380 # --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1381 # ${TOPDIR}/mptlinux-*.src.rpm
1382 rpm -ivh --define "_topdir ${TOPDIR}" ${TOPDIR}/mptlinux-*.src.rpm
1384 # now the big honkin' patch to the spec file
1385 pushd ${TOPDIR}/SPECS
1386 # to regen this patch use:
1387 # !!cd ~/rpm/SPECS/ && diff -u mptlinux.spec{.dist,}
1388 patch -p0 < ${TOPDIR}/lustre/build/mptlinux.spec.patch || fatal 1 "failed to patch mptlinux.spec"
1392 for arch in $BUILD_ARCHS; do
1393 targets="--target $arch $targets"
1396 local rpmbuildopt='-bb'
1399 echo NORPM mode. Only compiling.
1402 if ! $RPMBUILD $targets $rpmbuildopt \
1403 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1404 --define "_tmppath /var/tmp" \
1405 --define "_topdir ${TOPDIR}" \
1406 --define "kernel_obj $linux" \
1407 ${TOPDIR}/SPECS/mptlinux.spec 2>&1; then
1411 if ! $RPMBUILD -bs \
1412 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1413 --define "_tmppath /var/tmp" \
1414 --define "_topdir ${TOPDIR}" \
1415 --define "kernel_obj $linux" \
1416 ${TOPDIR}/SPECS/mptlinux.spec 2>&1; then
1430 if ! $BUILD_MPTLINUX || [ -z "$version" -o "$version" = "inkernel" ]; then
1434 # note that we use an _, not a . before the spec on purpose. we are not
1435 # allowed to have more than one file with a .spec trailer in a tarball
1436 # that is supposed to be usable with rpmbuild
1437 cp lustre/build/rdac_spec ${TOPDIR}/SPECS/rdac.spec || fatal 1 "Could not find rdac.spec in lustre/build"
1440 for arch in $BUILD_ARCHS; do
1441 targets="--target $arch $targets"
1444 local rpmbuildopt='-bb'
1447 echo NORPM mode. Only compiling.
1452 rhel5) distro="REDHAT"
1454 sles1*) distro="SUSE"
1456 *) echo "$DISTRO not supported by RDAC, skipping"
1460 if ! $RPMBUILD $targets $rpmbuildopt --define "dist $distro" \
1461 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1462 --define "_tmppath /var/tmp" \
1463 --define "_topdir ${TOPDIR}" \
1464 --define "kernel_obj $linux" \
1465 ${TOPDIR}/SPECS/rdac.spec 2>&1; then
1469 if ! $RPMBUILD -bs --define "dist $distro" \
1470 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1471 --define "_tmppath /var/tmp" \
1472 --define "_topdir ${TOPDIR}" \
1473 --define "kernel_obj $linux" \
1474 ${TOPDIR}/SPECS/rdac.spec 2>&1; then
1485 # REUSEBUILD, USE_BUILD_CACHE
1490 local ofed_version="$2"
1492 # if an ofed version is given, then it means use OFED proper,
1493 # not any vendor specific "inkernel" version
1494 if [ -z "$ofed_version" -o "$ofed_version" = "inkernel" ]; then
1495 # first see if there is a distro specific override for this
1496 # XXX we need to better integrate an distro specific override with
1497 # the rest of this function so that all of the reuse cache
1498 # stuff is leveraged given that 80% of this function is reuse
1499 if type -p build_ofed-${DISTRO}; then
1501 ofed_location=$(build_ofed-${DISTRO} ${STDOUT})
1502 CONFIGURE_FLAGS="--with-o2ib=${ofed_location} ${CONFIGURE_FLAGS}"
1503 return ${PIPESTATUS[0]}
1510 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1511 local REUSE_SIGNATURE=$({ echo "$ofed_version";
1512 echo "$(find_linux_release ${linux})";
1513 cat "${linux}/include/linux/autoconf.h"; } |
1514 md5sum | cut -d" " -f1)
1515 # see if we can link to the reuse pool
1516 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1518 local CAN_LINK_FOR_REUSE=false
1519 touch $REUSEBUILD/$$
1520 if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1521 CAN_LINK_FOR_REUSE=true
1526 if ! $USE_BUILD_CACHE || ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1527 "$REUSE_SIGNATURE"; then
1528 if [ -n "$REUSE_SIGNATURE" ]; then
1529 # stash away the existing built articles for a moment
1531 mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
1534 find . | cpio -pudlm ..
1538 create_rpmbuild_dirs
1541 build_kernel_ib "${linux}"
1543 if [ -z "$REUSE_SIGNATURE" ]; then
1544 echo "No reuse signature was caculated so not storing the built ofed"
1546 # store the resulting RPM build tree for future use
1547 echo "Storing the built ofed for future reuse"
1548 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1549 "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1550 "$CAN_LINK_FOR_REUSE"; then
1551 error "Failed to store OFED RPMS for reuse"
1555 # put the stuff we stashed away back
1560 pushd "$TOPDIR" >/dev/null
1561 rm -rf kernel-ib-devel
1562 mkdir kernel-ib-devel
1564 # the actual ofed RPMs don't have the -rc$n or -$date string appened that
1565 # might be present on the file
1566 local linuxrelease=$(find_linux_release "$linux")
1567 ofed_version=$(echo $ofed_version |
1568 sed -re 's/-(20[0-9]{6,6}-[0-9]{4,4}|rc[0-9]*)$//')
1569 local rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version}-${linuxrelease//-/_}.*.rpm)
1570 if ! rpm2cpio < $rpm | cpio -id; then
1571 fatal 1 "could not unpack the kernel-ib-devel rpm."
1573 CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
1580 if ! $PATCHLESS; then
1581 local kernel_extra_version
1582 if ! kernel_extra_version=$(build_kernel_with_srpm ${STDOUT}); then
1583 fatal 1 "Failed to build the kernel from it's SRPM"
1586 for arch in $BUILD_ARCHS; do
1587 local kernel_devel_rpm
1588 if ! kernel_devel_rpm=$(find_rpm "$TOPDIR/RPMS/$arch/" provides "^$(devel_kernel_name $KERNEL_LUSTRE_NAMING) ="); then
1589 fatal 1 "Failed to find a kernel development RPM in $TOPDIR/RPMS/$arch/"
1592 # install the -devel RPM in preparation for modules builds
1593 if ! lnxrel="$kernel_extra_version" unpack_linux_devel_rpm \
1594 "$TOPDIR/RPMS/$arch/$kernel_devel_rpm"; then
1595 fatal 1 "Could not find the Linux tree in $TOPDIR/RPMS/$arch/$kernel_devel_rpm"
1599 # need to find and unpack the vendor's own kernel-devel for patchless
1602 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1603 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in ${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
1605 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1606 fatal 1 "Could not find the Linux tree in $kernelrpm"
1610 # ~sigh~ have to make copies of and modify some of the rpm
1611 # infrastructure files so that find-requires can find our unpacked
1612 # kernel-devel artifacts
1613 cp $RPM_HELPERS_DIR/{symset-table,find-requires{,.ksyms}} .
1614 FIND_REQUIRES="$(pwd)/find-requires"
1615 chmod 755 {symset-table,find-requires{,.ksyms}}
1617 tmp="${tmp//\//\\/}"
1618 ed find-requires <<EOF
1622 /|.*find-requires.ksyms/s/|/| bash -x/
1623 g/ [^ ]*\/\(find-requires\.ksyms\)/s// $tmp\/\1/g
1626 ed find-requires.ksyms <<EOF
1630 g/\/.*\/\(symset-table\)/s//$tmp\/\1/g
1633 ed symset-table <<EOF
1637 g/\(\/boot\/\)/s//$tmp\/reused\1/g
1638 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1642 build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_VERSION" ||
1643 fatal 1 "error building OFED"
1645 if ! $PATCHLESS; then
1646 # only need RDAC for the server
1647 build_rdac "${LINUXOBJ:-$LINUX}" "$RDAC_VERSION" ||
1648 fatal 1 "error building RDAC"
1651 build_mptlinux "${LINUXOBJ:-$LINUX}" "$MPTLINUX_VERSION" ||
1652 fatal 1 "error building mptlinux"
1655 if build_lustre "$LINUX" "$LINUXOBJ"; then
1656 # the build worked. resolve any symlinked files (i.e. from reuse)
1657 # in RPMS/$arch to real files so that that that huge mess of
1658 # complication known as LTS can copy them yet somewhere else.
1659 # is it any wonder this whole process is so damn so? anyone ever
1660 # heard of hardlinks? it's this cool new thing that allows you save
1661 # tons of time and space by creating... well you can go read about
1662 # them if you have not heard about them yet.
1663 # can i say how much the implemenation of all of this really impedes
1666 for dir in RPMS/*; do
1669 if [ -h $file ]; then
1676 # also, for i?86, make sure all of the RPMs are in RPMS/$TARGET_ARCH
1677 # as that's where LTS expects to find them
1678 for dir in RPMS/*; do
1679 if [ $dir = RPMS/$TARGET_ARCH ]; then
1684 if [ -n "$files" ]; then
1685 cp -al $files ../$TARGET_ARCH
1695 create_rpmbuild_dirs() {
1697 [ -d RPMS ] || mkdir RPMS
1698 for arch in $BUILD_ARCHS; do
1699 if [[ $arch = i?86 ]]; then
1700 # some stupidity in the sles11 kernel spec requires an RPMS/i386
1701 # even if the target arch is i686
1702 [ -d RPMS/i386 ] || mkdir RPMS/i386
1704 [ -d RPMS/$arch ] || mkdir RPMS/$arch
1706 [ -d BUILD ] || mkdir BUILD
1707 [ -d SOURCES ] || mkdir SOURCES
1708 [ -d SPECS ] || mkdir SPECS
1709 [ -d SRPMS ] || mkdir SRPMS
1731 [[ $list\ == *\ $item\ * ]]
1735 #########################################################################
1736 # Generate a backtrace through the call stack.
1740 #########################################################################
1744 local funcname="" sourcefile="" lineno="" n
1746 echo "Call stack: (most recent first)"
1747 for (( n = $strip ; n < ${#FUNCNAME[@]} ; ++n )) ; do
1748 funcname=${FUNCNAME[$n - 1]}
1749 sourcefile=$(basename ${BASH_SOURCE[$n]})
1750 lineno=${BASH_LINENO[$n - 1]}
1754 # Display function arguments
1755 if [[ ! -z "${BASH_ARGV[@]}" ]]; then
1756 local args newarg j p=0
1757 for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do
1758 newarg=${BASH_ARGV[$j + $p - 1]}
1759 args="${args:+${args} }'${newarg}'"
1761 let p+=${BASH_ARGC[$n - 1]}
1763 echo " ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}"
1767 echo "BEGIN BACKTRACE"
1769 #echo ${BASH_LINENO[*]}
1770 #echo ${BASH_SOURCE[*]}
1771 #echo ${FUNCNAME[*]}
1772 local i=$((${#FUNCNAME[@]} - 1))
1773 while [ $i -ge 0 ]; do
1774 local lineno=${BASH_LINENO[$i]}
1778 local SOURCELINE="${BASH_SOURCE[$i + 1]}:${lineno}"
1779 # Can't figure out how to get function args from other frames...
1780 local FUNCTION="${FUNCNAME[$i]}()"
1781 echo "$SOURCELINE:$FUNCTION"
1785 echo "END BACKTRACE"
1791 seen_list=$(new_list)
1793 echo "An unexpected error has occurred at ${BASH_SOURCE[0]##*/}:$((LINENO-1)).
1794 Unfortunately the above line number in the message may or may not be correct,
1795 but details have been send to the lbuild maintainer. Attempting to continue."; (echo "Untrapped error"
1797 # have we seen this one
1798 echo "checking seen list for ${BASH_SOURCE[0]}:${BASH_LINENO[0]}"
1800 if is_list_member "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"; then
1801 echo "seen this one already"
1803 seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
1809 ) | mail -s "Untrapped error at ${BASH_SOURCE[0]##*/}:$((LINENO-15)) on $HOSTNAME" brian@sun.com >&2; set $xtrace' ERR
1812 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1814 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,ofed-version:,publish,release,set-value:,src,stage:,tag:,target:,target-archs:,with-linux:,xen,enable-mptlinux,enable-rdac -- "$@")
1816 if [ $? != 0 ]; then
1820 eval set -- "$options"
1855 if ! KERNELTREE=$(canon_path "$2"); then
1856 fatal 1 "Could not determine the canonical location of $2"
1860 --linux | --with-linux)
1861 if ! LINUX=$(canon_path "$2"); then
1862 fatal 1 "Could not determine the canonical location of $2"
1875 if ! REUSEBUILD=$(canon_path "$2"); then
1876 fatal 1 "Could not determine the canonical location of $2"
1893 if ! KERNELRPMSBASE=$(canon_path "$2"); then
1894 fatal 1 "Could not determine the canonical location of $2"
1945 --disable-datestamp)
1967 # there are actually some lustre configure flags that we need to
1968 # handle ourselves (but we still give them to configure)
1969 if [[ \ $@\ == *\ --disable-tests\ * ]]; then
1973 CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-liblustre --enable-liblustre-tests"
1977 usage 1 "Unrecognized option: $1"
1988 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
1990 unpack_ofed || fatal 1 "Error unpacking OFED tarball"
1993 if $BUILD_MPTLINUX && [ -n "$MPTLINUX_VERSION" -a "$MPTLINUX_VERSION" != "inkernel" ]; then
1994 unpack_mptlinux || fatal 1 "Error unpacking MPTLINUX distribution"
1997 # make sure the RPM build environment is set up
1998 create_rpmbuild_dirs
2000 if $BUILD_RDAC && [ -n "$RDAC_VERSION" -a "$RDAC_VERSION" != "inkernel" ]; then
2001 # we don't actually need to unpack this. just put it in the SOURCES dir
2002 #unpack_rdac || fatal 1 "Error unpacking RDAC tarball"
2003 cp "$KERNELTREE/rdac-LINUX-${RDAC_VERSION}-source.tar.gz" ${TOPDIR}/SOURCES/ ||
2004 fatal 1 "Error copying RDAC source tarball to RPM SOURCES dir"
2007 # if an unpacked kernel source tree was given on the command line
2008 # just build lustre with it (nothing distro kernel specific here)
2009 if [ -n "$LINUX" ]; then
2010 build_mptlinux "${LINUXOBJ:-$LINUX}" "$MPTLINUX_VERSION" ||
2011 fatal 1 "error building mptlinux"
2012 build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_VERSION" ||
2013 fatal 1 "error building OFED"
2014 if ! $PATCHLESS; then
2015 build_rdac "${LINUXOBJ:-$LINUX}" "$RDAC_VERSION" ||
2016 fatal 1 "error building RDAC"
2018 build_lustre "$LINUX" "$LINUXOBJ"
2020 if [ -f "${0%/*}/lbuild-$DISTRO" ]; then
2021 source ${0%/*}/lbuild-$DISTRO
2023 build_with_srpm || fatal 1 "Failed to build_with_srpm"
2025 EXTRA_VERSION_DELIMITER=${EXTRA_VERSION_DELIMITER:-"-"}
2026 source ${0%/*}/lbuild.old_school
2028 old_school_download_kernel
2032 patchless_build_sequence && build_success=true
2034 [ "$DISTRO" = "sles9" ] && build_sequence_rpm_reuse && build_success=true
2035 if ! $build_success; then
2036 build_sequence_reuse && build_success=true
2037 if ! $build_success; then
2038 build_sequence && build_success=true
2039 if $build_success; then
2040 store_for_reuse || echo "Cannot store for future reuse"
2045 ( $build_success ) || fatal 1 "Cannot build lustre"