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 lustre_patch=$(grep lustre_version "$SERIES_FILE" 2>/dev/null)
186 [ "$lustre_patch" ] || \
187 fatal 1 "Could not determine Lustre version from $SERIES series."
189 awk '/^\+#define LUSTRE_KERNEL_VERSION /{ print $3 }' \
190 "$TOPDIR/lustre/kernel_patches/patches/$lustre_patch" 2>/dev/null
195 EXTRA_VERSION_save="$EXTRA_VERSION"
199 [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
200 # Suse 2.6 has our patches in already
201 # [ "$SERIES" ] || fatal 1 "Target $TARGET did not specify a patch series."
202 # [ "$CONFIG" ] || fatal 1 "Target $TARGET did not specify a kernel config."
203 [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify the kernel version."
205 if [ "$KERNELDIR" ] ; then
206 KERNEL_FILE="$KERNELDIR/$KERNEL"
207 [ -r "$KERNELDIR/$KERNEL" ] || \
208 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
211 if [ "$SERIES" ]; then
212 SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$SERIES"
213 [ -r "$SERIES_FILE" ] || \
214 fatal 1 "Target $TARGET's series $SERIES missing from $TOPDIR/lustre/kernel_patches/series."
217 TARGET_ARCH=${TARGET_ARCH:-$BASE_ARCHS}
218 CONFIG_TARGET="$TARGET-${TARGET_ARCH}${TARGET_CONFIG:+-$TARGET_CONFIG}"
219 CONFIG_FILE="$TOPDIR/lustre/kernel_patches/kernel_configs/kernel-$VERSION-$CONFIG_TARGET.config"
220 [ -r "$CONFIG_FILE" ] ||
221 fatal 1 "Target $TARGET's config file $CONFIG_FILE missing from $TOPDIR/lustre/kernel_patches/configs."
223 if [ "$EXTRA_VERSION_save" ] ; then
224 EXTRA_VERSION="$EXTRA_VERSION_save"
226 EXTRA_VERSION="${EXTRA_VERSION}_lustre.$(get_lustre_version)"
234 fatal 1 "tarflags(): File name argument missing."
243 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
250 echo "Untarring ${1##*/}..."
251 tar $(tarflags $1) $1
257 (( $UNPACK_KERNEL )) || return 0
258 pushd "$TOPDIR" >/dev/null
259 if [ -d linux ] ; then
260 [ -L linux ] && rm -rf $(readlink linux)
264 [ -d linux ] || ln -sf linux* linux
270 (( $UNPACK_KERNEL )) || return 0
271 [ "$SERIES" ] || return 0
272 pushd "$TOPDIR/linux" >/dev/null
273 echo -n "Applying patch"
274 for patch in $(<"$SERIES_FILE") ; do
275 PATCH_FILE="$TOPDIR/lustre/kernel_patches/patches/$patch"
276 [ -r "$PATCH_FILE" ] || \
277 fatal 1 "Patch file not found: $patch"
279 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
291 if [ "$ARCH" ] ; then
292 MAKE_ARCH="$MAKE ARCH=$ARCH"
298 MAKE_ARCH="$MAKE ARCH=$TARGET_ARCH"
302 MAKE_J="$MAKE -j $JOBS"
307 (( $DEPEND_KERNEL )) || return 0
308 # we need to override $CC at make time, since there is no
311 pushd "$TOPDIR/linux" >/dev/null
312 echo "Overriding EXTRAVERSION in kernel..."
313 perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${EXTRA_VERSION}${TARGET_CONFIG}/" Makefile
314 echo "Making depend in $PWD..."
315 $MAKE mrproper || fatal 1 "Error running make mrproper"
316 cp "$CONFIG_FILE" .config
317 for oc in oldconfig_nonint silentoldconfig oldconfig ; do
318 if grep -q "$oc" Makefile ; then
323 $MAKE $OLDCONFIG || fatal 1 "Error running make oldconfig"
326 SYMLINKS="include/asm"
333 $MAKE_J dep || fatal 1 "Error running make dep"
334 $MAKE include/linux/version.h || fatal 1 "Error making include/linux/version.h"
339 (( $BUILD_KERNEL )) || return 0
341 echo "Building kernel in $PWD..."
342 case "$TARGET_ARCH" in
343 i386 | i586 | i686 | athlon | x86_64)
344 $MAKE_J bzImage || fatal 1 "Error making bzImage."
347 $MAKE_J vmlinux || fatal 1 "Error making vmlinux."
350 $MAKE_J boot || fatal 1 "Error making boot."
353 $MAKE_J modules || fatal 1 "Error building modules."
360 (( $BUILD_LUSTRE )) || return 0
361 pushd "$TOPDIR" >/dev/null
362 [ -f Makefile ] && make -s clean
363 [ -f configure ] || sh ./autogen.sh
364 ./configure --with-linux=$PWD/linux $CONFIGURE_FLAGS || \
365 fatal 1 "Error configuring Lustre."
371 (( $BUILD_LUSTRE )) || return 0
373 pushd "$TOPDIR" >/dev/null
374 $MAKE_J || fatal 1 "Error building Lustre."
380 (( $INSTALL_KERNEL )) || return 0
382 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
383 pushd "$TOPDIR/linux" >/dev/null
384 mkdir -p "$DESTDIR/boot"
386 install -m 644 System.map "$DESTDIR/boot/System.map-${FULL_VERSION}"
387 # install -m 644 module-info ...
388 install -m 644 "$CONFIG_FILE" "$DESTDIR/boot/config-${FULL_VERSION}"
390 mkdir -p "$DESTDIR/dev/shm"
391 mkdir -p "$DESTDIR/lib/modules/${FULL_VERSION}"
393 $MAKE INSTALL_MOD_PATH="$DESTDIR" KERNELRELEASE="$FULL_VERSION" \
394 -s modules_install || \
395 fatal 1 "Error installing modules."
397 case "$TARGET_ARCH" in
398 i386 | i586 | i686 | athlon)
399 cp arch/i386/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
400 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
401 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
404 cp arch/x86_64/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
405 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
406 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
409 cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
410 ln -sf "$DESTDIR/boot/vmlinux-${FULL_VERSION}" "../lib/modules/${FULL_VERSION}/vmlinux"
413 gzip -cfv vmlinux > vmlinuz
414 mkdir -p "$DESTDIR/boot/efi/redhat"
415 install -m 755 vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
416 install -m 755 vmlinuz "$DESTDIR/boot/efi/redhat/vmlinuz-${FULL_VERSION}"
417 ln -sf "../../../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/efi/redhat/vmlinux-${FULL_VERSION}"
418 ln -sf "efi/redhat/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
419 ln -sf "efi/redhat/vmlinuz-${FULL_VERSION}" "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
422 cp vmlinuz "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
423 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}"
424 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
428 if [ -e init/kerntypes.o ] ; then
429 cp init/kerntypes.o "$DESTDIR/boot/Kerntypes-${FULL_VERSION}"
437 (( $INSTALL_LUSTRE )) || return 0
439 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
440 pushd "$TOPDIR" >/dev/null
441 $MAKE -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
447 (( $BUILD_KERNEL )) || return 0
448 (( $SUSEBUILD )) || return 0
450 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
451 mkdir -p "${TOPDIR}/modules-${FULL_VERSION}"
452 for dir in /usr/src/kernel-modules/* ; do
453 # we are replacing lustre-lite, so don't include it
454 if [ ${dir##*/} != "lustre-lite" -a -e $dir/Makefile ]; then
455 build_dir="${TOPDIR}/modules-${FULL_VERSION}/${dir##*/}"
456 cp -a $dir $build_dir
457 # these modules are terrible, and don't all build
458 $MAKE_J -C $build_dir modules KERNEL_SOURCE="${TOPDIR}/linux"
465 local file=$1 name=${1%.ko}
467 | sed -ne 's,^0*\([0-9a-f]\{8\}\) A __crc_\(.*\),0x\1\t\2\t'"$name"',p'
472 (( $INSTALL_KERNEL )) || return 0
473 (( $SUSEBUILD )) || return 0
475 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
476 for build_dir in "${TOPDIR}/modules-${FULL_VERSION}/*" ; do
477 [ -d $build_dir ] || continue
478 # these modules are terrible, and don't all build
479 $MAKE -C $build_dir KERNEL_SOURCE="${TOPDIR}/linux" INSTALL_MOD_PATH="$DESTDIR"
482 moddir="${DESTDIR}/lib/modules/${FULL_VERSION}"
484 for module in $(find * -name '*.ko'); do
488 for module in $(find * -path 'kernel/*' -prune -o \
489 -name '*.ko' -print); do
493 | gzip -c9 > "${DESTDIR}/boot/symvers-${VERSION}-${EXTRA_VERSION}-${TARGET_ARCH}${TARGET_CONFIG}.gz"
498 echo "Saving headers for $1 $2..."
499 pushd linux >/dev/null
501 KVERREL="${VERSION}-${EXTRA_VERSION}"
502 # deal with the kernel headers that are version specific
504 saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/$2/$1"
506 install -m 644 include/linux/autoconf.h "$saveddir/autoconf.h"
507 install -m 644 include/linux/version.h "$saveddir/version.h"
508 mv include/linux/modules "$saveddir/"
509 echo $2 $1 ../../savedheaders/$2/$1/ >> $RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/list
515 (( $SAVE_HEADERS )) || return 0
517 for arch in $BIGMEM_ARCHS ; do
518 save_headers bigmem $arch
521 for arch in $BOOT_ARCHS ; do
522 save_headers BOOT $arch
525 for arch in $JENSEN_ARCHS ; do
526 save_headers jensen $arch
529 for arch in $SMP_ARCHS ; do
530 save_headers smp $arch
533 for arch in $BIGSMP_ARCHS ; do
534 save_headers bigsmp $arch
536 for arch in $UP_ARCHS ; do
537 save_headers up $arch
541 longopts="build,build-lustre,build-kernel,depend-kernel,destdir:,extraversion:"
542 longopts="$longopts,help,install,install-lustre,install-kernel,kerneldir:"
543 longopts="$longopts,save-headers,target:,target-arch:,target-config:,unpack-kernel"
545 options=$(getopt -o hj: -l "$longopts" -- "$@")
547 eval set -- "$options"
632 usage 1 "Unrecognized option: $1"