1 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
6 SUSEBUILD=${SUSEBUILD:-0}
8 SUSEBUILD=${SUSEBUILD:-0}
14 if [ "$TARGET" = "rhel-2.6" -o "$TARGET" = "rhel-2.4" ]; then
16 if [ "$TARGET" = "rhel-2.6" ]; then
18 OLDCONFIG=nonint_oldconfig
19 elif [ "$TARGET" = "rhel-2.4" ]; then
24 RPMTOPDIR=$(mktemp -d $KERNELDIR/rpm_XXXXXX)
25 mkdir $RPMTOPDIR/BUILD/
26 rpm -ivh $KERNELDIR/$SRPM --define "_topdir $RPMTOPDIR" || \
27 { rm -rf $RPMTOPDIR; fatal 1 "Error installing kernel SRPM."; }
28 $RPMBUILD -bp --nodeps --target i686 $RPMTOPDIR/SPECS/$SPEC --define "_topdir $RPMTOPDIR"
29 pushd $RPMTOPDIR/BUILD/kernel-${lnxmaj}/linux-${lnxmaj} && {
31 cp configs/kernel-${lnxmaj}-i686-smp.config .config
32 if ! make $OLDCONFIG > /dev/null; then
33 fatal 1 "error trying to make $OLDCONFIG while building a tarball from SRPM."
35 make include/linux/version.h
38 tar cjf $KERNEL_FILE linux-${lnxmaj}
45 download_and_build_tarball() {
49 local srpm=kernel-${lnxmaj}-${lnxrel}.src.rpm
51 echo "Downloading http://downloads.lustre.org/public/kernels/$target/old/$srpm..."
52 if ! wget -nv "http://downloads.lustre.org/public/kernels/$target/old/$srpm" \
53 -O "$KERNELDIR/$srpm" ; then
54 fatal 1 "Could not download target $kernel_file's kernel SRPM $srpm from downloads.lustre.org."
56 [ -s "$KERNELDIR/$srpm" ] || {
57 rm -rf $KERNELDIR/$srpm
58 fatal 1 "Could not download target $kernel_file's kernel SRPM $srpm from downloads.lustre.org."
61 build_tarball $target $srpm
66 untar "$KERNEL_FILE" || fatal 1 "Error unpacking Linux tarball"
67 [ -d linux ] || ln -sf linux* linux
73 [ "$SERIES" ] || return 0
77 echo "Replacing .config files..."
78 [ -d linux/configs ] || mkdir linux/configs || \
79 fatal 1 "Error creating configs directory."
82 for patchesdir in "$EXTERNAL_PATCHES" "lustre/lustre/kernel_patches" ; do
83 [ "$patchesdir" ] && \
84 cp -v $patchesdir/kernel_configs/kernel-${VERSION}-${TARGET}*.config linux/configs/ >/dev/null && copysuccess=1
86 [ "$copysuccess" = "1" ] || \
87 fatal 1 "Error copying in kernel configs."
91 TARBALL="$(readlink linux)-$EXTRA_VERSION.tar.gz"
92 echo "Creating patched linux tarball $TARBALL..."
93 tar zcf "$TARBALL" "$(readlink linux)" \
94 --exclude "CVS" --exclude ".cvsignore" || \
95 --exclude "*.orig" --exclude "*~" --exclude "*.rej" || \
96 fatal 1 "Error creating patched Linux tarball."
100 [ -d linux ] || return 0
101 echo "Cleaning linux..."
102 [ -L linux ] && rm -rf $(readlink linux)
106 prep_kernel_build() {
107 local lmakeopts="\"\""
112 ENABLE_INIT_SCRIPTS=""
114 -e "s^@BASE_ARCHS@^$BASE_ARCHS^g" \
115 -e "s^@BIGMEM_ARCHS@^$BIGMEM_ARCHS^g" \
116 -e "s^@BIGSMP_ARCHS@^$BIGSMP_ARCHS^g" \
117 -e "s^@BOOT_ARCHS@^$BOOT_ARCHS^g" \
118 -e "s^@CONFIGURE_FLAGS@^$CONFIGURE_FLAGS^g" \
119 -e "s^@ENABLE_INIT_SCRIPTS@^$ENABLE_INIT_SCRIPTS^g" \
120 -e "s^@JENSEN_ARCHS@^$BOOT_ARCHS^g" \
121 -e "s^@KERNEL_EXTRA_VERSION@^$EXTRA_VERSION^g" \
122 -e "s^@KERNEL_EXTRA_VERSION_DELIMITER@^$EXTRA_VERSION_DELIMITER^g" \
123 -e "s^@KERNEL_TARGET_DELIMITER@^$TARGET_DELIMITER^g" \
124 -e "s^@KERNEL_RELEASE@^${EXTRA_VERSION//-/_}^g" \
125 -e "s^@KERNEL_SOURCE@^$KERNEL^g" \
126 -e "s^@KERNEL_VERSION@^$VERSION^g" \
127 -e "s^@LINUX26@^$LINUX26^g" \
128 -e "s^@LUSTRE_SOURCE@^${LUSTRE##*/}^g" \
129 -e "s^@LUSTRE_TARGET@^$TARGET^g" \
130 -e "s^@PSERIES64_ARCHS@^$PSERIES64_ARCHS^g" \
131 -e "s^@RHBUILD@^$RHBUILD^g" \
132 -e "s^@SMP_ARCHS@^$SMP_ARCHS^g" \
133 -e "s^@SUSEBUILD@^$SUSEBUILD^g" \
134 -e "s^@UP_ARCHS@^$UP_ARCHS^g" \
135 -e "s^@LMAKEOPTS@^$lmakeopts^g" \
136 < $TOPDIR/lustre/build/lustre-kernel-2.4.spec.in \
137 > lustre-kernel-2.4.spec
138 [ -d SRPMS ] || mkdir SRPMS
139 [ -d RPMS ] || mkdir RPMS
140 [ -d BUILD ] || mkdir BUILD
141 [ -d SOURCES ] || mkdir SOURCES
142 for script in linux-{rhconfig.h,merge-config.awk,merge-modules.awk} \
143 suse-{functions.sh,post.sh,postun.sh,trigger-script.sh.in} \
144 sles8-{pre,post,postun,update_{INITRD_MODULES,rcfile_setting}}.sh ; do
145 cp $TOPDIR/lustre/build/$script SOURCES
147 cp "$LUSTRE" "$KERNEL_FILE" SOURCES
148 if [ "$EXTERNAL_PATCHES" -a -d "$EXTERNAL_PATCHES" ] ; then
149 tar zcf SOURCES/external-patches.tar.gz -C "$EXTERNAL_PATCHES" series targets patches kernel_configs
151 touch SOURCES/external-patches.tar.gz
156 [ -d lustre ] || return 0
157 echo "Cleaning Lustre..."
158 [ -L lustre ] && rm -rf $(readlink lustre)
163 echo "Building kernel + Lustre RPMs for: $BUILD_ARCHS..."
165 for arch in $BUILD_ARCHS ; do
166 targets="--target $arch $targets"
169 local rpmbuildopt='-bb'
172 # echo NORPM mode. Only compiling.
173 # echo "XXX: need to fix lmake - add options to do rpmbuild -bc instead of -bb"
176 $RPMBUILD $targets $rpmbuildopt lustre-kernel-2.4.spec \
177 --define "_tmppath $TMPDIR" \
178 --define "_topdir $TOPDIR" || \
179 fatal 1 "Error building rpms for $BUILD_ARCHS."
182 $RPMBUILD -bs lustre-kernel-2.4.spec \
183 --define "_tmppath $TMPDIR" \
184 --define "_topdir $TOPDIR" || \
185 fatal 1 "Error building .src.rpm."
188 ( $(skeep_ldiskfs_rpm $TAG) ) && return
190 pushd $TOPDIR/BUILD/lustre*/ldiskfs || return 255
192 if [ "$?" != "0" ] ; then
196 cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES
200 local ldiskfs_spec=lustre-ldiskfs.spec
201 [ -f "$ldiskfs_spec" ] && sed \
202 -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \
204 > ../lustre-ldiskfs.spec
206 $RPMBUILD $targets $rpmbuildopt ../lustre-ldiskfs.spec \
207 --define "_tmppath /var/tmp" \
208 --define "_topdir $TOPDIR"
209 if [ "$?" != "0" ] ; then
215 $RPMBUILD -bs ../lustre-ldiskfs.spec \
216 --define "_tmppath /var/tmp" \
217 --define "_topdir $TOPDIR"
218 if [ "$?" != "0" ] ; then
226 #get date of last changed target/config/series/patches
227 get_last_source_date() {
228 local filelist="${TOPDIR}/lustre/lustre/kernel_patches/series/${SERIES} \
230 local TOPDIRnew=$(echo ${TOPDIR} | sed -e s/\\//\\\\\\//g)
231 filelist="$filelist $( \
232 cat ${TOPDIR}/lustre/lustre/kernel_patches/series/${SERIES} | \
233 sed -e s/^/${TOPDIRnew}\\/lustre\\/lustre\\/kernel_patches\\/patches\\// 2>&1)"
234 local sourcelastdate=$( find ${filelist} -name CVS -prune -o \
235 -type f -printf "%T@\n" 2>&1 | sort | tail -1 )
236 is_integer $sourcelastdate && echo $sourcelastdate
239 #check if variable is integer
242 [ "$invariable" = "" ] && return 255
243 local invariableint=$( echo $invariable | sed -e s/[^0-9]//g )
244 [ "$invariable" = "$invariableint" ] || return 255
247 #store RPMs and/or BUILD dir for future reuse
250 if [ ! "$REUSEBUILD" = "" ] && [ -d "/$REUSEBUILD/" ] ; then
251 [ -d "${REUSEBUILD}/${TIMESTAMP}" ] || mkdir "${REUSEBUILD}/${TIMESTAMP}"
252 [ -d "${REUSEBUILD}/${TIMESTAMP}" ] || return 255
257 local lnxrelnew=${lnxrel//-/_}
258 local EXTRA_VERSIONnew=${EXTRA_VERSION//-/_}
259 local KERNELRPMnew=$(basename "$KERNELRPM")
260 if [ ! "$rpmonly" = "rpmonly" ]; then
262 if [ ! "$KERNELCOMPILEDIR" = "" ]; then
263 builddir="$KERNELCOMPILEDIR"
265 builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/linux-${lnxmaj}"
266 [ "$KERNELCOMPILEDIR" = "" ] || builddir="$KERNELCOMPILEDIR"
267 [ -d "$builddir" ] || builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/linux-${lnxmaj}.${lnxrel}"
268 [ -d "$builddir" ] || builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/linux-${lnxmaj}-${lnxrel}"
269 if [ ! -d "$builddir" ]; then
270 pushd "BUILD/lustre-kernel-${lnxmaj}/lustre/" || return 255
271 local basebuilddir=$(ls -d linux-${lnxmaj}* | head -1)
272 [ "$basebuilddir" = "" ] || builddir="BUILD/lustre-kernel-${lnxmaj}/lustre/${basebuilddir}"
276 [ -d "$builddir" ] || return 255
277 local dstdir="${REUSEBUILD}/${TIMESTAMP}/linux-${KERNCONFSMPTYPE}-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}"
278 ( $PATCHLESS ) && dstdir="${REUSEBUILD}/${TIMESTAMP}/linux-$KERNELRPMnew" && \
279 dstdir="${dstdir%.rpm}"
280 [ -d "$dstdir" ] && rm -rf "$dstdir"
281 mv "${builddir}" "$dstdir" || return 255
282 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
283 # move the OFED kernel-ib-devel tree as well
284 mv "${builddir%/*}/kernel-ib-devel/usr/src/ofa_kernel" "${dstdir%/*}" || return 255
288 local kernelrpmname="kernel-lustre-${KERNCONFSMPTYPE}-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}.rpm"
289 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] || kernelrpmname="kernel-${KERNCONFSMPTYPE}-${lnxmaj}-${EXTRA_VERSNnew}.${TARGET_ARCH}.rpm"
290 ( $PATCHLESS ) && [ -f "$KERNELRPM" ] && kernelrpmname="$KERNELRPMnew"
291 if [ "$rpmonly" = "rpmonly" ] && [ -f "${REUSEBUILD}/${TIMESTAMP}/${kernelrpmname}" ]; then
292 echo "RPM already exist in store directory tree"
294 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] && cp -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" "${REUSEBUILD}/${TIMESTAMP}/"
296 #store kernel source rpm
297 kernelrpmname="kernel-lustre-source-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}.rpm"
298 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] || kernelrpmname="kernel-source-${lnxmaj}-${EXTRA_VERSIONnew}.${TARGET_ARCH}.rpm"
299 ( $PATCHLESS ) && [ -f "$KERNELSOURCERPM" ] && kernelrpmname=$(basename "$KERNELSOURCERPM")
300 if [ "$rpmonly" = "rpmonly" ] && [ -f "${REUSEBUILD}/${TIMESTAMP}/${kernelrpmname}" ]; then
301 echo "RPM already exist in store directory tree"
303 [ -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" ] && cp -f "RPMS/${TARGET_ARCH}/${kernelrpmname}" "${REUSEBUILD}/${TIMESTAMP}/"
305 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
306 # store kernel-ib RPMs
308 local ofed_version=$(echo $OFED_VERSION |
309 sed -re 's/-(20[0-9]{6,6}-[0-9]{4,4}|rc[0-9]*)$//')
310 for rpmname in "kernel-ib" "kernel-ib-devel"; do
311 rpmname="${rpmname}-${ofed_version}"
313 rpmname="${rpmname}-${LINUXRELEASE//-/_}"
315 rpmname="${rpmname}-${lnxmaj}${EXTRA_VERSION_DELIMITER//-/_}${EXTRA_VERSIONnew}${TARGET_DELIMITER//-/_}${KERNCONFSMPTYPE}"
317 rpmname="${rpmname}.${TARGET_ARCH}.rpm"
318 if [ "$rpmonly" = "rpmonly" ] && [ -f "${REUSEBUILD}/${TIMESTAMP}/${rpmname}" ]; then
319 echo "RPM already exist in store directory tree"
321 [ -f "RPMS/${TARGET_ARCH}/${rpmname}" ] && cp -f "RPMS/${TARGET_ARCH}/${rpmname}" "${REUSEBUILD}/${TIMESTAMP}/"
327 #look for kernel source RPM
328 find_linux_source_rpm() {
333 [ ! "$TARGET_ARCH" = "" ] && arch=$TARGET_ARCH && findarch=false
336 pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${arch}"
337 [ -d $pathtorpms ] || return 255
340 rpmfile="kernel-${lnxmaj}-${lnxrel}.src.rpm"
343 rpmfile="kernel-source-${lnxmaj}.${lnxrel}.${arch}.rpm"
346 rpmfile="kernel-source-${lnxmaj}-${lnxrel}.${arch}.rpm"
349 [ -f "${pathtorpms}/${rpmfile}" ] || return 255
350 KERNELSOURCERPM="${pathtorpms}/${rpmfile}"
352 for arch in $TARGET_ARCHS_ALL; do
353 pathtorpms="${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}/${arch}"
354 [ -d $pathtorpms ] || continue
357 rpmfile="kernel-${lnxmaj}-${lnxrel}.src.rpm"
360 rpmfile="kernel-source-${lnxmaj}.${lnxrel}.${arch}.rpm"
363 rpmfile="kernel-source-${lnxmaj}-${lnxrel}.${arch}.rpm"
366 [ -f "${pathtorpms}/${rpmfile}" ] || continue
367 KERNELSOURCERPM="${pathtorpms}/${rpmfile}"
372 [ -f "${KERNELSOURCERPM}" ] || return 255
375 #unpack and make symlinks for reusing kernel RPM
378 local pathtokernelibrpm=$2
379 [ "$pathtorpm" = "" ] && return 255
380 [ -f "$pathtorpm" ] || return 255
381 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused
382 pushd $TOPDIR/reused || return 255
384 rpm2cpio < $pathtorpm | cpio -idc
385 [ ${PIPESTATUS[0]} -eq 0 ] || return 255
387 if [ -n "$pathtokernelibrpm" ] && [ -f "$pathtokernelibrpm" ]; then
388 rpm2cpio < $pathtokernelibrpm | cpio -idc
389 [ ${PIPESTATUS[0]} -eq 0 -o ${PIPESTATUS[1]} -eq 0 ] || return 255
390 CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
394 if pushd usr/src/linux-*-obj/${TARGET_ARCH}; then
395 local smptypes="$SMPTYPES"
396 [ "$RPMSMPTYPE" = "" ] || smptypes=$RPMSMPTYPE
397 ( ! $PATCHLESS ) && [ ! "$KERNCONFSMPTYPE" = "" ] && smptypes="$KERNCONFSMPTYPE"
399 for cursmptype in $smptypes; do
400 [ "$cursmptype" = "''" ] && continue
401 [ -d $cursmptype ] && smptype=$cursmptype
402 [ -d $smptype ] && break
406 if [ "${smptype}" = "" ]; then
408 return 255 # cannot detect smp type
410 if pushd usr/src/linux-*-obj/${TARGET_ARCH}/$smptype/include2; then
411 local base=$(readlink asm)
412 if [ ! -d "/${base}/" ]; then
414 base=$(basename "$base")
415 if pushd ../../../../linux-*/include; then
418 [ -d "$lsrc/${base}" ] && ln -s $lsrc/${base} asm
422 read a b < <(echo $(pwd)/usr/src/linux-*)
423 if [[ $a == $(pwd)/* && $b = $(pwd)/* ]]; then
424 cp -f $a/include/linux/config.h $b/${TARGET_ARCH}/$smptype/include/linux/
425 cp $b/${TARGET_ARCH}/$smptype/.config $a/
426 [ -f "$b/${TARGET_ARCH}/$smptype/.config" ] && KERNELRPMCONFIG="$b/${TARGET_ARCH}/$smptype/.config"
427 cp $b/${TARGET_ARCH}/$smptype/.kernelrelease $a/
428 [ -f "$b/${TARGET_ARCH}/$smptype/.kernelrelease" ] && KERNELRPMRELEASE="$b/${TARGET_ARCH}/$smptype/.kernelrelease"
430 LINUXOBJ=$b/${TARGET_ARCH}/$smptype
431 # local fname=$(basename $kernel_rpm)
432 # KERNELRPMSDIR=${kernel_rpm%$fname}
436 [ "$LINUX" = "" ] && return 255
437 [ -d "$LINUX" ] || return 255
440 #build linux kernel rpm
442 pushd $LINUX || return 255
443 make binrpm-pkg || ( popd ; return 255 )
445 [ -f ".version" ] && addlnxrel="-$(cat .version)"
448 for arch in $TARGET_ARCHS_ALL; do
449 [ -f "/usr/src/rpm/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" ] && \
450 KERNELRPM="/usr/src/rpm/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" && \
452 [ -f "/usr/src/packages/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" ] && \
453 KERNELRPM="/usr/src/packages/RPMS/$arch/kernel-$lnxmaj.${lnxrel}${addlnxrel}.$arch.rpm" && \
456 [ "$KERNELRPM" = "" ] || return
463 local nocopykernel=$2
464 pushd $LINUX || fatal 1 "Kernel source not found"
465 [ "$nofullmake" = "nofullmake" ] || make mrproper
466 [ "$nofullmake" = "nofullmake" ] || rm -f rpm-release
467 # [ "$nocopykernel" = "copyrpmkernel" ] || rm -f localversion-*
468 [ "$nocopykernel" = "copykernel" ] && [ -f "$CONFIG_FILE" ] && cp $CONFIG_FILE .config
469 if [ "$nocopykernel" = "copyrpmkernel" ]; then
470 [ -f "$KERNELRPMCONFIG" ] && cp $KERNELRPMCONFIG .config
471 if [ -f "$KERNELRPMRELEASE" ]; then
472 cp $KERNELRPMRELEASE .
474 sed -e "s/^EXTRAVERSION\s\+=\s\+.*$/EXTRAVERSION = -${lnxrel}/" < Makefile > Makefile.new
475 [ -f "Makefile.new" ] && mv Makefile.new Makefile
478 [ -f ".config" ] || ( popd ; echo "Cannot find .config file"; return 255 )
479 make oldconfig || ( popd ; return 255 )
480 make include/linux/version.h
481 if [ ! "$nofullmake" = "nofullmake" ]; then
482 make || ( popd ; return 255 )
488 #build patchless lustre
489 patchless_build_sequence() {
490 if [ -f $LINUX/Makefile ]; then
491 # Get the correct kernel release - I'm unsure how this can ever
492 # work otherwise, unless you're using the exact same kernel version
493 # Lustre is shipped with.
495 local LINUXRELEASE=$(find_linux_release ${LINUXOBJ:-$LINUX})
496 if [ -z "$LINUXRELEASE" ]; then
497 echo "Failed to find linux release in ${LINUXOBJ:-$LINUX}"
501 lnxmaj=$(echo $LINUXRELEASE | cut -f1 -d-)
502 EXTRA_VERSION=$(echo $LINUXRELEASE | cut -f2 -d-)_lustre.$LUSTRE_VERSION
504 build_lustre && buildsuccess=true
506 #try to build from kernel-devel RPM (RHEL)
510 local buildsuccess=false
511 local storeforreuse=false
512 if [ "$KERNELRPMSBASE" = "" ] || [ ! -d "$KERNELRPMSBASE" ]; then
515 [ -d $TOPDIR/reused ] && rm -rf $TOPDIR/reused
517 local delimiter=${EXTRA_VERSION_DELIMITER:-"-"}
519 # default to source type -source and special case below
527 local kernel_devel_rpm
529 if ! kernel_devel_rpm=$(find_linux_rpm "$type" "$delimiter"); then
530 fatal 1 "Could not find the kernel$type RPM in ${KERNELRPMSBASE}/${lnxmaj}/${DISTRO}"
533 # find_linux_rpm() used to set these globals, but now it's a function
534 # run in a subshell so it's unable to set globals in our namespace
535 TARGET_ARCH=$(rpm -q --queryformat "%{ARCH}" -p "$kernel_devel_rpm")
536 BUILD_ARCHS="$TARGET_ARCH"
538 unpack_linux_devel_rpm "$kernel_devel_rpm" "$delimiter" && rpmfound=true
540 [ -d SRPMS ] || mkdir SRPMS
541 [ -d RPMS ] || mkdir RPMS
542 [ -d BUILD ] || mkdir BUILD
543 [ -d SOURCES ] || mkdir SOURCES
545 # first build kernel-ib
546 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
547 $rpmfound && build_kernel_ib
549 ( $rpmfound ) && build_lustre && buildsuccess=true && find_linux_source_rpm
552 if $buildsuccess; then
553 [ -d "RPMS/${TARGET_ARCH}" ] && [ -f "$KERNELRPM" ] && \
554 cp "$KERNELRPM" RPMS/${TARGET_ARCH}/
555 [ -d "RPMS/${TARGET_ARCH}" ] && [ -f "$KERNELSOURCERPM" ] && \
556 cp "$KERNELSOURCERPM" RPMS/${TARGET_ARCH}/
557 KERNELCOMPILEDIR="$LINUX"
558 if $storeforreuse; then
559 store_for_reuse || echo "Cannot store for future reuse"
563 elif ! $rpmfound; then
564 echo "COULD NOT FIND VENDOR -devel or -source RPM for $DISTRO/$TARGET_ARCH: $lnxmaj-$lnxrel in $KERNELRPMSBASE"
567 echo "Patchless build failed."
572 #check timestamp value. should bi 14-digits string
575 local timestampnodig=$(echo $invalue | sed -e s/[0-9]*//g)
576 [ "$timestampnodig" = "" ] || return 255
577 local timestamplength="${#invalue}"
578 [ $timestamplength -eq 14 ] || return 255
581 # get list of suitable directories with potential reused staff
582 get_reuse_dir_list() {
584 local reusedkernelmasknew=$2
585 local buildtimestamp=
587 local sourcelastdate=$(get_last_source_date)
588 for buildtimestamp in $(ls "$REUSEBUILD/" 2>&1); do
589 [ -d "$REUSEBUILD/$buildtimestamp" ] || continue
590 check_timestamp "$buildtimestamp" || continue
591 local buildtimestampstr=$(echo $buildtimestamp | \
592 sed -e "s^\(....\)\(..\)\(..\)\(..\)\(..\)\(..\)^\1-\2-\3 \4:\5:\6 GMT^g")
593 local buildtimestampepoch=$(date --date="$buildtimestampstr" +%s )
594 #check for suitable date
595 if ! $PATCHLESS; then
596 [ $buildtimestampepoch -ge $sourcelastdate ] || continue
598 #check for suitable version
599 if [ "$rpmonly" = "rpmonly" ]; then
600 local reusedkernelprefix="kernel-lustre-"
601 ( $PATCHLESS ) && reusedkernelprefix=
602 local rpmmask="${reusedkernelprefix}${REUSEDKERNELMASK}"
603 [ "$reusedkernelmasknew" = "" ] || rpmmask="$reusedkernelmasknew"
604 [ -f $REUSEBUILD/$buildtimestamp/${rpmmask}.rpm ] && \
605 dirsforreuse="$dirsforreuse $REUSEBUILD/$buildtimestamp"
607 local rpmmask="$REUSEDKERNELMASK"
608 [ "$reusedkernelmasknew" = "" ] || rpmmask="$reusedkernelmasknew"
609 pushd $REUSEBUILD/$buildtimestamp/linux-${rpmmask} > /dev/null 2>&1 || continue
611 dirsforreuse="$dirsforreuse $curdir"
618 #try to reuse old RPM
619 build_sequence_rpm_reuse() {
621 [ "$REUSERPM" = "" ] && [ "$REUSEBUILD" = "" ] && return 255
623 if ! [ "$REUSEBUILD" = "" ] && [ -d "$REUSEBUILD" ]; then #try to reuse RPM
624 local REUSEDKERNELMASKnew=$(echo $REUSEDKERNELMASK | sed -e "s/^[^0-9]*//")
625 REUSEDKERNELMASKnew="kernel-lustre-source-${REUSEDKERNELMASKnew}"
626 local dirsforreuse="$(get_reuse_dir_list rpmonly $REUSEDKERNELMASKnew)"
627 local buildsuccess=false
629 for curdir in $(echo $dirsforreuse); do
630 [ -d "$curdir" ] || continue
631 local reusedkernelprefix="kernel-lustre-"
632 local reusedkernelrpm=
633 [ -f ${curdir}/${reusedkernelprefix}${REUSEDKERNELMASK}.rpm ] && \
634 reusedkernelrpm=$(ls ${curdir}/${reusedkernelprefix}${REUSEDKERNELMASK}.rpm | head -1 )
635 [ -f "$reusedkernelrpm" ] || continue
637 local reusedkernelsourcerpm=
638 [ -f ${curdir}/${REUSEDKERNELMASKnew}.rpm ] && \
639 reusedkernelsourcerpm=$(ls ${curdir}/${REUSEDKERNELMASKnew}.rpm | head -1 )
640 [ -f "$reusedkernelsourcerpm" ] || continue
642 # don't need to check for kernel-ib RPM reuse here because sles9 is not supported
643 # by OFED >= 1.3.0 and this function appears to only be used for sles9
645 [ -d $TOPDIR/reused ] && rm -rf $TOPDIR/reused
646 reuse_kernel_rpm "$reusedkernelsourcerpm" "" && build_linux nofullmake copyrpmkernel && build_lustre && buildsuccess=true
647 ( $buildsuccess ) || continue
648 if ( ! $NORPM ) && ( ! $PATCHLESS ) ; then
649 [ -f "$reusedkernelrpm" ] && \
650 cp -f "$reusedkernelrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
652 [ -f "$reusedkernelsourcerpm" ] && \
653 cp -f "$reusedkernelsourcerpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1 && \
654 touch RPMS/${TARGET_ARCH}/kernel_was_reused
662 #try to reuse old BUILD dir
663 build_sequence_reuse() {
665 [ "$REUSERPM" = "" ] && [ "$REUSEBUILD" = "" ] && return 255
667 if [ ! "$REUSEBUILD" = "" ] && [ -d "$REUSEBUILD" ]; then #try to reuse old kernel build directory
668 local dirsforreuse="$(get_reuse_dir_list)"
669 local buildsuccess=false
671 local REUSEDKERNELMASKnew=$(echo $REUSEDKERNELMASK | sed -e "s/^[^0-9]*//")
672 for curdir in $(echo $dirsforreuse); do
673 local reusedkernelrpm=
674 local reusedkernelsourcerpm=
675 local reusedkernelibrpm=
676 [ -d "$curdir" ] || continue
677 [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" -a
678 ! -d "${curdir%/*}/ofa_kernel" ] && continue
679 local reusedkernelprefix="kernel-lustre-"
680 ( $PATCHLESS ) && reusedkernelprefix=
681 [ -f ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASK}.rpm ] && \
682 reusedkernelrpm=$(ls ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASK}.rpm | head -1 )
683 reusedkernelprefix="kernel-lustre-source-"
684 [ -f ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASKnew}.rpm ] && \
685 reusedkernelsourcerpm=$(ls ${curdir}/../${reusedkernelprefix}${REUSEDKERNELMASKnew}.rpm | head -1 )
686 if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then
688 reusedkernelprefix="kernel-ib-"
689 [ -f ${curdir}/../${reusedkernelprefix}${OFED_VERSION}-${LUSTRE_EXTRA_VERSION}.${TARGET_ARCH}.rpm ] && \
690 reusedkernelibrpm=$(ls ${curdir}/../${reusedkernelprefix}${OFED_VERSION}-${LUSTRE_EXTRA_VERSION}.${TARGET_ARCH}.rpm | head -1 )
691 reusedkernelibdevelrpm=$(ls ${curdir}/../${reusedkernelprefix}devel-${OFED_VERSION}-${LUSTRE_EXTRA_VERSION}.${TARGET_ARCH}.rpm | head -1 )
693 if ! ( $NORPM ) && ! [ -f "$reusedkernelrpm" ]; then #kernel rpm not found. Build all
696 if ! ( $NORPM ) && ! [ -f "$reusedkernelsourcerpm" ]; then #kernel source rpm not found. Build all
699 if [ -n "$OFED_VERSION" ]; then
700 if [ "$OFED_VERSION" != "inkernel" ]; then
701 if ! ( $NORPM ) && [ ! -f "$reusedkernelibrpm" -o ! -f "$reusedkernelibdevelrpm"]; then #kernel-ib{,-devel} rpm not found. Build all
704 CONFIGURE_FLAGS="--with-o2ib=${curdir%/*}/ofa_kernel ${CONFIGURE_FLAGS}"
706 CONFIGURE_FLAGS="--with-o2ib=yes ${CONFIGURE_FLAGS}"
710 build_lustre || continue
713 if ( ! $NORPM ) && ( ! $PATCHLESS ) ; then
714 [ -f "$reusedkernelrpm" ] && \
715 cp -f "$reusedkernelrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1 && \
716 touch RPMS/${TARGET_ARCH}/kernel_was_reused
717 [ -f "$reusedkernelsourcerpm" ] && \
718 cp -f "$reusedkernelsourcerpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
719 [ -f "$reusedkernelibrpm" ] && \
720 cp -f "$reusedkernelibrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
721 cp -f "$reusedkernelibdevelrpm" RPMS/${TARGET_ARCH}/ > /dev/null 2>&1
736 prep_kernel_build || return 255
737 clean_lustre || return 255
739 build_kernel || return 255
742 old_school_download_kernel() {
744 if [ "$KERNELDIR" ] ; then
745 KERNEL_FILE="$KERNELDIR/$KERNEL"
746 if [ ! -r "$KERNEL_FILE" ] ; then
747 # see if we have an SRPM we can build a tarball for
748 KERNEL_SRPM=kernel-${lnxmaj}-${lnxrel}.src.rpm
749 if [ -r "$KERNELDIR/$KERNEL_SRPM" ] ; then
750 build_tarball $CANONICAL_TARGET $KERNEL_SRPM
753 echo "Downloading http://downloads.lustre.org/public/kernels/$DISTRO/old/$KERNEL..."
754 if ! wget -nv "http://downloads.lustre.org/public/kernels/$DISTRO/old/$KERNEL" -O "$KERNELDIR/$KERNEL" ; then
755 # see if we can do it with an SRPM from the download site
756 download_and_build_tarball $CANONICAL_TARGET $KERNEL_FILE
758 [ -s "$KERNELDIR/$KERNEL" ] || {
759 rm -rf "$KERNELDIR/$KERNEL"
760 fatal 1 "Target $TARGET's kernel $KERNEL not found in directory $KERNELDIR."
764 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."