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/)
23 # provided by target file
54 TOPDIR=$(canon "${0%%${0##*/}}/..")
65 [ "$2" ] && echo "${0##*/}: $2"
71 echo -n "Available targets:"
72 for target in $TOPDIR/lustre/kernel_patches/targets/*.target ; do
73 target_file=${target##*/}
74 echo -n " ${target_file%%.target}"
83 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
88 same as --build-kernel --build-lustre --unpack-kernel
91 configure and compile lustre. Requires that --build-kernel was
95 configure and compile a kernel. Implies --depend-kernel.
96 Requires that --unpack-kernel was already run.
99 Prepares a kernel tree for building (similar to make mrproper
100 oldconfig dep). Requires that --unpack-kernel was already run.
103 Root directory to install into (like DESTDIR with auto*).
105 --extraversion=EXTRAVERSION
106 Overrides the target kernel\'s EXTRAVERSION text.
109 Display this message.
112 same as --install-kernel --install-lustre
115 run make install in the Lustre tree.
118 install the kernel image and modules.
121 This works just like the -j option to make, and is passed to make
124 --kerneldir=KERNELDIR
125 Directory containing linux source tarballs.
128 Name of the configuration to use. The available targets are
132 Specifies an architecture to use when choosing a kernel config
133 file. Default is i386.
135 --target-config=CONFIG
136 Specifies a special option (such as smp, bigsmp, bigmem, or BOOT)
137 to use when choosing a kernel config file. This also modifies the
138 kernel version and modules directory.
141 Untars and patches the kernel source.
143 The order that commands (--build-lustre, --unpack-kernel) are
144 specified on the command line is ignored; ${0##*/} will always
145 execute them in the correct order (unpack, then build, then install
156 (( $BUILD_LUSTRE || $BUILD_KERNEL || $DEPEND_KERNEL || \
157 $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS || \
158 $UNPACK_KERNEL )) || \
159 fatal 1 "No commands specified."
161 if (( $UNPACK_KERNEL )) ; then
162 [ "$KERNELDIR" ] || \
163 fatal 1 "A kernel directory must be specified with --kerneldir."
164 [ -d "$KERNELDIR" ] || \
165 fatal 1 "$KERNELDIR is not a directory."
168 if (( $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS )) ; then
169 [ -z "$DESTDIR" -o -d "$DESTDIR" ] || \
170 fatal 1 "$DESTDIR is not a directory."
173 [ "$TARGET" ] || usage 1 "A target must be specified with --target."
174 TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
175 [ -r "$TARGET_FILE" ] || \
176 fatal 1 "Target '$TARGET' was not found. Try --list-targets."
178 if [ -z "$JOBS" -o "$JOBS" -lt "1" ] ; then
185 for series in $SERIES ; do
186 SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
187 lustre_patch=$(grep lustre_version "$SERIES_FILE" 2>/dev/null)
188 [ "$lustre_patch" ] && break
190 [ "$lustre_patch" ] || \
191 fatal 1 "Could not determine Lustre version from $SERIES series."
193 awk '/^\+#define LUSTRE_KERNEL_VERSION /{ print $3 }' \
194 "$TOPDIR/lustre/kernel_patches/patches/$lustre_patch" 2>/dev/null
199 EXTRA_VERSION_save="$EXTRA_VERSION"
203 [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
204 # Suse 2.6 has our patches in already
205 # [ "$SERIES" ] || fatal 1 "Target $TARGET did not specify a patch series."
206 # [ "$CONFIG" ] || fatal 1 "Target $TARGET did not specify a kernel config."
207 [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify the kernel version."
209 if [ "$KERNELDIR" ] ; then
210 KERNEL_FILE="$KERNELDIR/$KERNEL"
211 [ -r "$KERNELDIR/$KERNEL" ] || \
212 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
215 if [ "$SERIES" ] ; then
216 for series in $SERIES ; do
217 SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
218 [ -r "$SERIES_FILE" ] || \
219 fatal 1 "Target $TARGET's series $SERIES missing from $TOPDIR/lustre/kernel_patches/series."
223 TARGET_ARCH=${TARGET_ARCH:-$BASE_ARCHS}
224 CONFIG_TARGET="$TARGET-${TARGET_ARCH}${TARGET_CONFIG:+-$TARGET_CONFIG}"
225 CONFIG_FILE="$TOPDIR/lustre/kernel_patches/kernel_configs/kernel-$VERSION-$CONFIG_TARGET.config"
226 [ -r "$CONFIG_FILE" ] ||
227 fatal 1 "Target $TARGET's config file $CONFIG_FILE missing from $TOPDIR/lustre/kernel_patches/configs."
229 if [ "$EXTRA_VERSION_save" ] ; then
230 EXTRA_VERSION="$EXTRA_VERSION_save"
232 EXTRA_VERSION="${EXTRA_VERSION}_lustre.$(get_lustre_version)"
240 fatal 1 "tarflags(): File name argument missing."
249 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
256 echo "Untarring ${1##*/}..."
257 tar $(tarflags $1) $1
263 (( $UNPACK_KERNEL )) || return 0
264 pushd "$TOPDIR" >/dev/null
265 if [ -d linux ] ; then
266 [ -L linux ] && rm -rf $(readlink linux)
270 [ -d linux ] || ln -sf linux* linux
276 (( $UNPACK_KERNEL )) || return 0
277 [ "$SERIES" ] || return 0
278 pushd "$TOPDIR/linux" >/dev/null
279 for series in $SERIES ; do
280 echo -n "Applying series $series:"
281 SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
282 for patch in $(<"$SERIES_FILE") ; do
283 PATCH_FILE="$TOPDIR/lustre/kernel_patches/patches/$patch"
284 [ -r "$PATCH_FILE" ] || \
285 fatal 1 "Patch file not found: $patch"
287 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
300 if [ "$ARCH" ] ; then
301 MAKE_ARCH="$MAKE ARCH=$ARCH"
307 MAKE_ARCH="$MAKE ARCH=$TARGET_ARCH"
311 MAKE_J="$MAKE -j $JOBS"
316 (( $DEPEND_KERNEL )) || return 0
317 # we need to override $CC at make time, since there is no
320 pushd "$TOPDIR/linux" >/dev/null
321 echo "Overriding EXTRAVERSION in kernel..."
322 perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${EXTRA_VERSION}${TARGET_CONFIG}/" Makefile
323 echo "Making depend in $PWD..."
324 $MAKE mrproper || fatal 1 "Error running make mrproper"
325 cp "$CONFIG_FILE" .config
326 for oc in oldconfig_nonint silentoldconfig oldconfig ; do
327 if grep -q "$oc" Makefile ; then
328 $MAKE $oc || fatal 1 "Error running make oldconfig"
338 $MAKE dep || fatal 1 "Error running make dep"
341 $MAKE include/linux/version.h || fatal 1 "Error making include/linux/version.h"
346 (( $BUILD_KERNEL )) || return 0
348 echo "Building kernel in $PWD..."
349 case "$TARGET_ARCH" in
350 i386 | i586 | i686 | athlon | x86_64)
351 $MAKE_J bzImage || fatal 1 "Error making bzImage."
354 $MAKE_J vmlinux || fatal 1 "Error making vmlinux."
357 $MAKE_J boot || fatal 1 "Error making boot."
360 $MAKE_J modules || fatal 1 "Error building modules."
367 (( $BUILD_LUSTRE )) || return 0
368 pushd "$TOPDIR" >/dev/null
369 [ -f Makefile ] && make -s clean
370 [ -f configure ] || sh ./autogen.sh
371 ./configure --with-linux=$PWD/linux $CONFIGURE_FLAGS || \
372 fatal 1 "Error configuring Lustre."
378 (( $BUILD_LUSTRE )) || return 0
380 pushd "$TOPDIR" >/dev/null
381 $MAKE_J || fatal 1 "Error building Lustre."
387 (( $INSTALL_KERNEL )) || return 0
389 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
390 pushd "$TOPDIR/linux" >/dev/null
391 mkdir -p "$DESTDIR/boot"
393 install -m 644 System.map "$DESTDIR/boot/System.map-${FULL_VERSION}"
394 # install -m 644 module-info ...
395 install -m 644 "$CONFIG_FILE" "$DESTDIR/boot/config-${FULL_VERSION}"
397 mkdir -p "$DESTDIR/dev/shm"
398 mkdir -p "$DESTDIR/lib/modules/${FULL_VERSION}"
400 $MAKE INSTALL_MOD_PATH="$DESTDIR" KERNELRELEASE="$FULL_VERSION" \
401 -s modules_install || \
402 fatal 1 "Error installing modules."
404 case "$TARGET_ARCH" in
405 i386 | i586 | i686 | athlon)
406 cp arch/i386/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
407 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
408 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
411 cp arch/x86_64/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
412 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
413 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
416 cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
417 ln -sf "$DESTDIR/boot/vmlinux-${FULL_VERSION}" "../lib/modules/${FULL_VERSION}/vmlinux"
420 gzip -cfv vmlinux > vmlinuz
421 mkdir -p "$DESTDIR/boot/efi/redhat"
422 install -m 755 vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
423 install -m 755 vmlinuz "$DESTDIR/boot/efi/redhat/vmlinuz-${FULL_VERSION}"
424 ln -sf "../../../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/efi/redhat/vmlinux-${FULL_VERSION}"
425 ln -sf "efi/redhat/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
426 ln -sf "efi/redhat/vmlinuz-${FULL_VERSION}" "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
429 cp vmlinuz "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
430 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}"
431 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
435 if [ -e init/kerntypes.o ] ; then
436 cp init/kerntypes.o "$DESTDIR/boot/Kerntypes-${FULL_VERSION}"
444 (( $INSTALL_LUSTRE )) || return 0
446 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
447 pushd "$TOPDIR" >/dev/null
448 $MAKE -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
454 (( $BUILD_KERNEL )) || return 0
455 (( $SUSEBUILD )) || return 0
457 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
458 mkdir -p "${TOPDIR}/modules-${FULL_VERSION}"
459 for dir in /usr/src/kernel-modules/* ; do
460 # we are replacing lustre-lite, so don't include it
461 if [ ${dir##*/} != "lustre-lite" -a -e $dir/Makefile ]; then
462 build_dir="${TOPDIR}/modules-${FULL_VERSION}/${dir##*/}"
463 cp -a $dir $build_dir
464 # these modules are terrible, and don't all build
465 $MAKE_J -C $build_dir modules KERNEL_SOURCE="${TOPDIR}/linux"
472 local file=$1 name=${1%.ko}
474 | sed -ne 's,^0*\([0-9a-f]\{8\}\) A __crc_\(.*\),0x\1\t\2\t'"$name"',p'
479 (( $INSTALL_KERNEL )) || return 0
480 (( $SUSEBUILD )) || return 0
482 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
483 for build_dir in "${TOPDIR}/modules-${FULL_VERSION}/*" ; do
484 [ -d $build_dir ] || continue
485 # these modules are terrible, and don't all build
486 $MAKE -C $build_dir KERNEL_SOURCE="${TOPDIR}/linux" INSTALL_MOD_PATH="$DESTDIR"
489 moddir="${DESTDIR}/lib/modules/${FULL_VERSION}"
491 for module in $(find * -name '*.ko'); do
495 for module in $(find * -path 'kernel/*' -prune -o \
496 -name '*.ko' -print); do
500 | gzip -c9 > "${DESTDIR}/boot/symvers-${VERSION}-${EXTRA_VERSION}-${TARGET_ARCH}${TARGET_CONFIG}.gz"
505 echo "Saving headers for $1 $2..."
506 pushd linux >/dev/null
508 KVERREL="${VERSION}-${EXTRA_VERSION}"
509 # deal with the kernel headers that are version specific
511 saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/$2/$1"
513 install -m 644 include/linux/autoconf.h "$saveddir/autoconf.h"
514 install -m 644 include/linux/version.h "$saveddir/version.h"
515 mv include/linux/modules "$saveddir/"
516 echo $2 $1 ../../savedheaders/$2/$1/ >> $RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/list
522 (( $SAVE_HEADERS )) || return 0
524 for arch in $BIGMEM_ARCHS ; do
525 save_headers bigmem $arch
528 for arch in $BOOT_ARCHS ; do
529 save_headers BOOT $arch
532 for arch in $JENSEN_ARCHS ; do
533 save_headers jensen $arch
536 for arch in $SMP_ARCHS ; do
537 save_headers smp $arch
540 for arch in $BIGSMP_ARCHS ; do
541 save_headers bigsmp $arch
543 for arch in $UP_ARCHS ; do
544 save_headers up $arch
548 longopts="build,build-lustre,build-kernel,depend-kernel,destdir:,extraversion:"
549 longopts="$longopts,help,install,install-lustre,install-kernel,kerneldir:"
550 longopts="$longopts,save-headers,target:,target-arch:,target-config:,unpack-kernel"
552 options=$(getopt -o hj: -l "$longopts" -- "$@")
554 eval set -- "$options"
639 usage 1 "Unrecognized option: $1"