7 # Not sure what to put here
8 # TARGET_ARCH=$(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
13 TMPDIR=${TMPDIR:-"/var/tmp"}
24 # provided by target file
57 TOPDIR="${0%%${0##*/}}"
58 if [ "${TOPDIR}" ] ; then
59 TOPDIR=$(canon "${TOPDIR}/..")
67 while [ ! -d $retdir/BUILD ] ; do
68 retdir=$(canon "$retdir/..")
69 if [ "$retdir" = "/" ] ; then
85 [ "$2" ] && echo "${0##*/}: $2"
91 echo -n "Available targets:"
92 for target in $TOPDIR/lustre/kernel_patches/targets/*.target ; do
93 target_file=${target##*/}
94 echo -n " ${target_file%%.target}"
103 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
108 same as --build-kernel --build-lustre --unpack-kernel
111 configure and compile lustre. Requires that --build-kernel was
115 configure and compile a kernel. Implies --depend-kernel.
116 Requires that --unpack-kernel was already run.
119 Prepares a kernel tree for building (similar to make mrproper
120 oldconfig dep). Requires that --unpack-kernel was already run.
123 Root directory to install into (like DESTDIR with auto*).
125 --extraversion=EXTRAVERSION
126 Overrides the target kernel\'s EXTRAVERSION text.
129 Display this message.
132 same as --install-kernel --install-lustre
135 run make install in the Lustre tree.
138 install the kernel image and modules.
141 This works just like the -j option to make, and is passed to make
144 --kerneldir=KERNELDIR
145 Directory containing linux source tarballs.
148 Name of the configuration to use. The available targets are
152 Specifies an architecture to use when choosing a kernel config
153 file. Default is i386.
155 --target-config=CONFIG
156 Specifies a special option (such as smp, bigsmp, bigmem, or BOOT)
157 to use when choosing a kernel config file. This also modifies the
158 kernel version and modules directory.
161 Untars and patches the kernel source.
163 The order that commands (--build-lustre, --unpack-kernel) are
164 specified on the command line is ignored; ${0##*/} will always
165 execute them in the correct order (unpack, then build, then install
176 (( $BUILD_LUSTRE || $BUILD_KERNEL || $DEPEND_KERNEL || \
177 $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS || \
178 $UNPACK_KERNEL )) || \
179 fatal 1 "No commands specified."
181 if (( $UNPACK_KERNEL )) ; then
182 [ "$KERNELDIR" ] || \
183 fatal 1 "A kernel directory must be specified with --kerneldir."
184 [ -d "$KERNELDIR" ] || \
185 fatal 1 "$KERNELDIR is not a directory."
188 if (( $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS )) ; then
189 [ -z "$DESTDIR" -o -d "$DESTDIR" ] || \
190 fatal 1 "$DESTDIR is not a directory."
193 [ "$TARGET" ] || usage 1 "A target must be specified with --target."
194 TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
195 [ -r "$TARGET_FILE" ] || \
196 fatal 1 "Target '$TARGET' was not found. Try --list-targets."
198 if [ -z "$JOBS" -o "$JOBS" -lt "1" ] ; then
202 RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
203 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
204 RPMBUILD=$(which rpm 2>/dev/null | head -1)
205 if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
206 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
213 for series in $SERIES ; do
214 SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
215 lustre_patch=$(grep lustre_version "$SERIES_FILE" 2>/dev/null)
216 [ "$lustre_patch" ] && break
218 [ "$lustre_patch" ] || \
219 fatal 1 "Could not determine Lustre version from $SERIES series."
221 awk '/^\+#define LUSTRE_KERNEL_VERSION /{ print $3 }' \
222 "$TOPDIR/lustre/kernel_patches/patches/$lustre_patch" 2>/dev/null
227 EXTRA_VERSION_save="$EXTRA_VERSION"
231 [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
232 # Suse 2.6 has our patches in already
233 # [ "$SERIES" ] || fatal 1 "Target $TARGET did not specify a patch series."
234 # [ "$CONFIG" ] || fatal 1 "Target $TARGET did not specify a kernel config."
235 [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify the kernel version."
237 if [ "$KERNELDIR" ] ; then
238 KERNEL_FILE="$KERNELDIR/$KERNEL"
239 [ -r "$KERNELDIR/$KERNEL" ] || \
240 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
243 if [ "$SERIES" ] ; then
244 for series in $SERIES ; do
245 SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
246 [ -r "$SERIES_FILE" ] || \
247 fatal 1 "Target $TARGET's series $SERIES missing from $TOPDIR/lustre/kernel_patches/series."
251 TARGET_ARCH=${TARGET_ARCH:-$BASE_ARCHS}
252 CONFIG_TARGET="$TARGET-${TARGET_ARCH}${TARGET_CONFIG:+-$TARGET_CONFIG}"
253 CONFIG_FILE="$TOPDIR/lustre/kernel_patches/kernel_configs/kernel-$VERSION-$CONFIG_TARGET.config"
254 [ -r "$CONFIG_FILE" ] ||
255 fatal 1 "Target $TARGET's config file $CONFIG_FILE missing from $TOPDIR/lustre/kernel_patches/configs."
257 if [ "$EXTRA_VERSION_save" ] ; then
258 EXTRA_VERSION="$EXTRA_VERSION_save"
260 EXTRA_VERSION="${EXTRA_VERSION}_lustre.$(get_lustre_version)"
264 # do these after load_target(), which maybe export CC
265 setup_ccache_distcc()
267 # distcc can't handle ".incbin"
268 if [ "$TARGET" == "2.6-suse" -o "$TARGET" == "2.6-rhel4" ]; then
269 if [ "$TARGET_ARCH" == "x86_64" ]; then
275 if [ "$CCACHE" ]; then
277 [ "$DISTCC" ] && export CCACHE_PREFIX="$DISTCC"
279 [ "$DISTCC" ] && CC="$DISTCC $CC"
287 fatal 1 "tarflags(): File name argument missing."
299 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
306 echo "Untarring ${1##*/}..."
307 tar $(tarflags $1) $1
313 (( $UNPACK_KERNEL )) || return 0
314 pushd "$TOPDIR" >/dev/null
315 if [ -d linux ] ; then
316 [ -L linux ] && rm -rf $(readlink linux)
320 [ -d linux ] || ln -sf linux* linux
326 (( $UNPACK_KERNEL )) || return 0
327 [ "$SERIES" ] || return 0
328 pushd "$TOPDIR/linux" >/dev/null
329 for series in $SERIES ; do
330 echo -n "Applying series $series:"
331 SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
332 for patch in $(<"$SERIES_FILE") ; do
333 PATCH_FILE="$TOPDIR/lustre/kernel_patches/patches/$patch"
334 [ -r "$PATCH_FILE" ] || \
335 fatal 1 "Patch file not found: $patch"
337 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
350 if [ "$ARCH" ] ; then
351 MAKE_ARCH="$MAKE ARCH=$ARCH"
357 MAKE_ARCH="$MAKE ARCH=$TARGET_ARCH"
361 MAKE_J="$MAKE -j $JOBS"
375 kill -TERM -$child_pid 2>/dev/null
377 kill -KILL -$child_pid 2>/dev/null
378 echo "$1 was killed due to timeout") &
382 # status will be set to 143 if the process had to be killed due to timeout
383 status=${PIPESTATUS[0]}
390 (( $DEPEND_KERNEL )) || return 0
391 # we need to override $CC at make time, since there is no
394 pushd "$TOPDIR/linux" >/dev/null
395 echo "Overriding EXTRAVERSION in kernel..."
396 local extra_version="${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
397 if [ -n "${TARGET_CONFIG}" ]; then
398 extra_version="${extra_version}${TARGET_DELIMITER}${TARGET_CONFIG}"
400 perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = ${extra_version}/" Makefile
401 echo "Making depend in $PWD..."
402 $MAKE "$MAKE_CC" mrproper || fatal 1 "Error running make mrproper"
404 # remove localversion-* files to avoid kernel release string
405 # srewing up by the top-level Makefile
407 cp "$CONFIG_FILE" .config
408 local UPDATE_OLDCONFIG=
409 for oc in oldconfig_nonint silentoldconfig oldconfig ; do
410 if grep -q "$oc" Makefile ; then
411 timed_run 300 $MAKE "$MAKE_CC" $oc || UPDATE_OLDCONFIG=1
416 if [ "$UPDATE_OLDCONFIG" ] ; then
417 # use the expect script to "make oldconfig" and answer the questions for
418 # new items conservatively. QA will get notified on anything newly added
419 # for them to review and adjust accordingly.
420 local logfile=$(mktemp /tmp/XXXXXX)
421 #timed_run 300 $TOPDIR/build/update_oldconfig $logfile
422 #local RC=${PIPESTATUS[0]}
423 #local RC=$(strace -f -o update_oldconfig.strace bash -c "$TOPDIR/build/update_oldconfig $logfile; echo \$?")
424 $TOPDIR/build/update_oldconfig $logfile
425 local RC=${PIPESTATUS[0]}
426 #$TOPDIR/build/update_oldconfig $logfile
427 #local RC=${PIPESTATUS[0]}
428 if [ $RC -eq 143 ]; then
429 fatal 1 "update_oldconfig timed out"
430 elif [ $RC -ne 0 ]; then
434 if [ -f update_oldconfig.strace ]; then
435 cat update_oldconfig.strace
436 rm -f update_oldconfig.strace
438 fatal 1 "update_oldconfig failed: $RC. See log above."
442 # now notify if resulting .config is different than $CONFIG_FILE
443 local tmpfile=$(mktemp /tmp/XXXXXX)
444 diff -I '^#.*' -u "$CONFIG_FILE" .config >$tmpfile
445 if [ -s $tmpfile ]; then
447 To: lustre-qa-team@sun.com
448 Subject: kernel_config change
450 The result of a make oldconfig on file $CONFIG_FILE resulted in a
451 difference when compared to .config in the following way:
455 echo -e "\n\nPlease consider updating $CONFIG_FILE for version: $extra_version."
456 # not sure these are entirely useful. the above and "patch" are good
457 #echo -e "\nThe entire new .config file:\n"
459 # sadly, the build roots can't e-mail out, so we can only display this
460 # to stderr for an interested party to inspect
461 #} | sendmail -flustre-qa-team@sun.com -t
468 $MAKE "$MAKE_CC" include/asm
471 $MAKE "$MAKE_CC" symlinks
472 $MAKE "$MAKE_CC" dep || fatal 1 "Error running make dep"
475 $MAKE "$MAKE_CC" include/linux/version.h || fatal 1 "Error making include/linux/version.h"
480 (( $BUILD_KERNEL )) || return 0
482 echo "Building kernel in $PWD..."
483 case "$TARGET_ARCH" in
484 i386 | i586 | i686 | athlon | x86_64)
485 $MAKE_J "$MAKE_CC" bzImage || fatal 1 "Error making bzImage."
488 $MAKE_J "$MAKE_CC" vmlinux || fatal 1 "Error making vmlinux."
491 $MAKE_J "$MAKE_CC" boot || fatal 1 "Error making boot."
494 $MAKE_J "$MAKE_CC" modules || fatal 1 "Error building modules."
501 (( $BUILD_KERNEL )) || return 0
502 # build kernel-ib{,-devel}
503 # some I/B drivers are architecture dependent and kernel-ib's configure
504 # does not figure it out for us ~sigh~
505 local configure_options=""
506 case "$TARGET_ARCH" in
508 configure_options="--with-ipath_inf-mod"
511 configure_options="--with-ipath_inf-mod --with-ehca-mod"
514 $RPMBUILD --rebuild --define 'build_kernel_ib 1' --define 'build_kernel_ib_devel 1' \
515 --define "_topdir $(lbuild_topdir)" --target ${TARGET_ARCH} \
516 --define "KVERSION ${FULL_VERSION}" \
517 --define "KSRC $PWD/linux" \
518 --define "LIB_MOD_DIR /lib/modules/${FULL_VERSION}" \
519 --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" $(lbuild_topdir)/OFED/SRPMS/ofa_kernel-${OFED_VERSION}-ofed${OFED_VERSION}.src.rpm
521 if [ ${PIPESTATUS[0]} != 0 ]; then
522 fatal 1 "Error building kernel-ib"
525 pushd "$TOPDIR" >/dev/null
526 rm -rf kernel-ib-devel
527 mkdir kernel-ib-devel
529 local rpm=$(ls $(lbuild_topdir)/RPMS/*/kernel-ib-devel-${OFED_VERSION}-${FULL_VERSION//-/_}.*.rpm)
530 rpm2cpio -itv < $rpm | cpio -id
531 CONFIGURE_FLAGS="--with-o2ib=$(pwd)/usr/src/ofa_kernel ${CONFIGURE_FLAGS}"
539 (( $BUILD_LUSTRE )) || return 0
540 pushd "$TOPDIR" >/dev/null
541 [ -f Makefile ] && make -s clean
542 [ -f configure ] || sh ./autogen.sh
543 ./configure --with-linux=$PWD/linux $CONFIGURE_FLAGS || \
544 fatal 1 "Error configuring Lustre."
550 (( $BUILD_LUSTRE )) || return 0
552 pushd "$TOPDIR" >/dev/null
554 -e s^@VERSION@^${LUSTRE_VERSION}^g \
555 -e s^@LINUXRELEASE@^${FULL_VERSION}^g \
556 -e s^@RELEASE@^${FULL_VERSION//-/_}^g \
557 -e s^@ac_configure_args@^"--with-linux=${PWD}/linux ${CONFIGURE_FLAGS}"^g \
560 $RPMBUILD --target ${TARGET_ARCH} -bb lustre.spec \
561 --define "_tmppath $TMPDIR" \
562 --define "_topdir $(lbuild_topdir)" || \
563 fatal 1 "Error building Lustre rpms."
564 # $MAKE_J "$MAKE_CC" || fatal 1 "Error building Lustre."
570 (( $INSTALL_KERNEL )) || return 0
572 pushd "$TOPDIR/linux" >/dev/null
573 mkdir -p "$DESTDIR/boot"
575 install -m 644 System.map "$DESTDIR/boot/System.map-${FULL_VERSION}"
576 # install -m 644 module-info ...
577 install -m 644 "$CONFIG_FILE" "$DESTDIR/boot/config-${FULL_VERSION}"
579 mkdir -p "$DESTDIR/dev/shm"
580 mkdir -p "$DESTDIR/lib/modules/${FULL_VERSION}"
582 $MAKE "$MAKE_CC" INSTALL_MOD_PATH="$DESTDIR" KERNELRELEASE="$FULL_VERSION" \
583 -s modules_install || \
584 fatal 1 "Error installing modules."
586 case "$TARGET_ARCH" in
587 i386 | i586 | i686 | athlon)
588 cp arch/i386/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
589 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
590 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
593 cp arch/x86_64/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
594 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
595 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
598 cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
599 ln -sf "$DESTDIR/boot/vmlinux-${FULL_VERSION}" "../lib/modules/${FULL_VERSION}/vmlinux"
602 gzip -cfv vmlinux > vmlinuz
603 mkdir -p "$DESTDIR/boot/efi/redhat"
604 install -m 755 vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
605 install -m 755 vmlinuz "$DESTDIR/boot/efi/redhat/vmlinuz-${FULL_VERSION}"
606 ln -sf "../../../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/efi/redhat/vmlinux-${FULL_VERSION}"
607 ln -sf "efi/redhat/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
608 ln -sf "efi/redhat/vmlinuz-${FULL_VERSION}" "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
611 cp vmlinuz "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
612 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}"
613 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
617 if [ -e init/kerntypes.o ] ; then
618 cp init/kerntypes.o "$DESTDIR/boot/Kerntypes-${FULL_VERSION}"
626 (( $INSTALL_LUSTRE )) || return 0
628 KVERREL="${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
629 i="$DESTDIR/lib/modules/${FULL_VERSION}"
634 if (( $LINUX26 )) ; then
635 ln -sf ../../../usr/src/linux-${KVERREL}-obj/${TARGET_ARCH}/${TARGET_CONFIG} $i/build
636 ln -sf ../../../usr/src/linux-${KVERREL} $i/source
638 ln -sf ../../../usr/src/linux-${KVERREL} $i/build
644 (( $INSTALL_LUSTRE )) || return 0
647 pushd "$TOPDIR" >/dev/null
648 $MAKE "$MAKE_CC" -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
654 (( $BUILD_KERNEL )) || return 0
655 (( $SUSEBUILD )) || return 0
657 mkdir -p "${TOPDIR}/modules-${FULL_VERSION}"
658 for dir in /usr/src/kernel-modules/* ; do
659 # we are replacing lustre-lite, so don't include it
660 if [ "${dir##*/}" != "lustre-lite" -a -e $dir/Makefile ]; then
661 build_dir="${TOPDIR}/modules-${FULL_VERSION}/${dir##*/}"
662 cp -a $dir $build_dir
663 # these modules are terrible, and don't all build
664 $MAKE_J "$MAKE_CC" -C $build_dir modules KERNEL_SOURCE="${TOPDIR}/linux"
671 local file=$1 name=${1%.ko}
673 | sed -ne 's,^0*\([0-9a-f]\{8\}\) A __crc_\(.*\),0x\1\t\2\t'"$name"',p'
678 (( $INSTALL_KERNEL )) || return 0
679 (( $LINUX26 )) || return 0
681 for build_dir in "${TOPDIR}/modules-${FULL_VERSION}/*" ; do
682 [ -d $build_dir ] || continue
683 # these modules are terrible, and don't all build
684 $MAKE "$MAKE_CC" -C $build_dir KERNEL_SOURCE="${TOPDIR}/linux" INSTALL_MOD_PATH="$DESTDIR"
686 local symvers_file="${DESTDIR}/boot/symvers-${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}-${TARGET_ARCH}"
687 if [ -n "$TARGET_CONFIG" ]; then
688 symvers_file="${symvers_file}${TARGET_DELIMITER}${TARGET_CONFIG}"
690 symvers_file="$symvers_file.gz"
692 moddir="${DESTDIR}/lib/modules/${FULL_VERSION}"
694 for module in $(find * -name '*.ko'); do
698 for module in $(find * -path 'kernel/*' -prune -o \
699 -name '*.ko' -print); do
702 ) | sort -u -k2 | gzip -c9 > $symvers_file
707 (( $SAVE_HEADERS )) || return 0
709 echo "Saving headers for ${TARGET_CONFIG:-up} ${TARGET_ARCH}..."
710 pushd linux >/dev/null
712 KVERREL="${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
713 # deal with the kernel headers that are version specific
715 saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/${TARGET_ARCH}/${TARGET_CONFIG:-up}"
717 install -m 644 include/linux/autoconf.h "$saveddir/autoconf.h"
718 install -m 644 include/linux/version.h "$saveddir/version.h"
719 mv include/linux/modules "$saveddir/"
720 echo ${TARGET_ARCH} ${TARGET_CONFIG} ../../savedheaders/${TARGET_ARCH}/${TARGET_CONFIG:-up}/ \
721 >> "$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/list"
727 (( $SAVE_HEADERS )) || return 0
729 for arch in $BIGMEM_ARCHS ; do
730 save_headers bigmem $arch
733 for arch in $BOOT_ARCHS ; do
734 save_headers BOOT $arch
737 for arch in $JENSEN_ARCHS ; do
738 save_headers jensen $arch
741 for arch in $SMP_ARCHS ; do
742 save_headers smp $arch
745 for arch in $BIGSMP_ARCHS ; do
746 save_headers bigsmp $arch
748 for arch in $PSERIES64_ARCHS ; do
749 save_headers pseries64 $arch
751 for arch in $UP_ARCHS ; do
752 save_headers up $arch
756 longopts="build,build-lustre,build-kernel,depend-kernel,destdir:,extraversion:"
757 longopts="$longopts,help,install,install-lustre,install-kernel,kerneldir:"
758 longopts="$longopts,save-headers,target:,target-arch:,target-config:,unpack-kernel"
760 options=$(getopt -o hj: -l "$longopts" -- "$@")
762 eval set -- "$options"
847 usage 1 "Unrecognized option: $1"
854 EXTRA_VERSION_DELIMITER=${EXTRA_VERSION_DELIMITER:-"-"}
855 FULL_VERSION="${VERSION}${EXTRA_VERSION_DELIMITER}${EXTRA_VERSION}"
856 if [ -n "$TARGET_CONFIG" ]; then
857 FULL_VERSION="${FULL_VERSION}${TARGET_DELIMITER}${TARGET_CONFIG}"
867 if [ -n "$OFED_VERSION" ]; then