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
51 TOPDIR=$(canon "${0%%${0##*/}}/..")
62 [ "$2" ] && echo "${0##*/}: $2"
68 echo -n "Available targets:"
69 for target in $TOPDIR/kernel_patches/targets/*.target ; do
70 target_file=${target##*/}
71 echo -n " ${target_file%%.target}"
80 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
85 same as --build-kernel --build-lustre --unpack-kernel
88 configure and compile lustre. Requires that --build-kernel was
92 configure and compile a kernel. Implies --depend-kernel.
93 Requires that --unpack-kernel was already run.
96 Prepares a kernel tree for building (similar to make mrproper
97 oldconfig dep). Requires that --unpack-kernel was already run.
100 Root directory to install into (like DESTDIR with auto*).
102 --extraversion=EXTRAVERSION
103 Overrides the target kernel\'s EXTRAVERSION text.
106 Display this message.
109 same as --install-kernel --install-lustre
112 run make install in the Lustre tree.
115 install the kernel image and modules.
118 This works just like the -j option to make, and is passed to make
121 --kerneldir=KERNELDIR
122 Directory containing linux source tarballs.
125 Name of the configuration to use. The available targets are
129 Specifies an architecture to use when choosing a kernel config
130 file. Default is i386.
132 --target-config=CONFIG
133 Specifies a special option (such as smp, bigmem, or BOOT) to use
134 when choosing a kernel config file. This also modifies the kernel
135 version and modules directory.
138 Untars and patches the kernel source.
140 The order that commands (--build-lustre, --unpack-kernel) are
141 specified on the command line is ignored; ${0##*/} will always
142 execute them in the correct order (unpack, then build, then install
153 (( $BUILD_LUSTRE || $BUILD_KERNEL || $DEPEND_KERNEL || \
154 $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS || \
155 $UNPACK_KERNEL )) || \
156 fatal 1 "No commands specified."
158 if (( $UNPACK_KERNEL )) ; then
159 [ "$KERNELDIR" ] || \
160 fatal 1 "A kernel directory must be specified with --kerneldir."
161 [ -d "$KERNELDIR" ] || \
162 fatal 1 "$KERNELDIR is not a directory."
165 if (( $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS )) ; then
166 [ -z "$DESTDIR" -o -d "$DESTDIR" ] || \
167 fatal 1 "$DESTDIR is not a directory."
170 [ "$TARGET" ] || usage 1 "A target must be specified with --target."
171 TARGET_FILE="$TOPDIR/kernel_patches/targets/$TARGET.target"
172 [ -r "$TARGET_FILE" ] || \
173 fatal 1 "Target '$TARGET' was not found. Try --list-targets."
175 if [ -z "$JOBS" -o "$JOBS" -lt "1" ] ; then
182 lustre_patch=$(grep lustre_version "$SERIES_FILE" 2>/dev/null)
183 [ "$lustre_patch" ] || \
184 fatal 1 "Could not determine Lustre version from $SERIES series."
186 awk '/^\+#define LUSTRE_KERNEL_VERSION /{ print $3 }' \
187 "$TOPDIR/kernel_patches/patches/$lustre_patch" 2>/dev/null
192 EXTRA_VERSION_save="$EXTRA_VERSION"
196 [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
197 [ "$SERIES" ] || fatal 1 "Target $TARGET did not specify a patch series."
198 # [ "$CONFIG" ] || fatal 1 "Target $TARGET did not specify a kernel config."
199 [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify the kernel version."
201 if [ "$KERNELDIR" ] ; then
202 KERNEL_FILE="$KERNELDIR/$KERNEL"
203 [ -r "$KERNELDIR/$KERNEL" ] || \
204 fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
207 SERIES_FILE="$TOPDIR/kernel_patches/series/$SERIES"
208 [ -r "$SERIES_FILE" ] || \
209 fatal 1 "Target $TARGET's series $SERIES missing from $TOPDIR/kernel_patches/series."
211 TARGET_ARCH=${TARGET_ARCH:-$BASE_ARCHS}
212 CONFIG_TARGET="$TARGET-${TARGET_ARCH}${TARGET_CONFIG:+-$TARGET_CONFIG}"
213 CONFIG_FILE="$TOPDIR/kernel_patches/kernel_configs/kernel-$VERSION-$CONFIG_TARGET.config"
214 [ -r "$CONFIG_FILE" ] ||
215 fatal 1 "Target $TARGET's config file $CONFIG_FILE missing from $TOPDIR/kernel_patches/configs."
217 if [ "$EXTRA_VERSION_save" ] ; then
218 EXTRA_VERSION="$EXTRA_VERSION_save"
220 EXTRA_VERSION="${EXTRA_VERSION}_lustre.$(get_lustre_version)"
228 fatal 1 "tarflags(): File name argument missing."
237 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
244 echo "Untarring ${1##*/}..."
245 tar $(tarflags $1) $1
251 (( $UNPACK_KERNEL )) || return 0
252 pushd "$TOPDIR" >/dev/null
253 if [ -d linux ] ; then
254 [ -L linux ] && rm -rf $(readlink linux)
258 [ -d linux ] || ln -sf linux* linux
264 (( $UNPACK_KERNEL )) || return 0
265 pushd "$TOPDIR/linux" >/dev/null
266 echo -n "Applying patch"
267 for patch in $(<"$SERIES_FILE") ; do
268 PATCH_FILE="$TOPDIR/kernel_patches/patches/$patch"
269 [ -r "$PATCH_FILE" ] || \
270 fatal 1 "Patch file not found: $patch"
272 patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
280 MAKE="make -s CC=$CC"
281 if [ "$ARCH" ] ; then
282 MAKE="$MAKE ARCH=$ARCH"
284 MAKE_J="$MAKE -j $JOBS"
289 (( $DEPEND_KERNEL )) || return 0
290 # we need to override $CC at make time, since there is no
293 pushd "$TOPDIR/linux" >/dev/null
294 echo "Overriding EXTRAVERSION in kernel..."
295 perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${EXTRA_VERSION}${TARGET_CONFIG}/" Makefile
296 echo "Making depend in $PWD..."
297 $MAKE mrproper || fatal 1 "Error running make mrproper"
298 cp "$CONFIG_FILE" .config
299 if grep -q oldconfig_nonint Makefile ; then
300 OLDCONFIG='oldconfig_nonint'
302 OLDCONFIG='oldconfig'
304 $MAKE $OLDCONFIG || fatal 1 "Error running make oldconfig"
305 $MAKE_J dep || fatal 1 "Error running make dep"
306 $MAKE include/linux/version.h || fatal 1 "Error making include/linux/version.h"
311 (( $BUILD_KERNEL )) || return 0
312 # we need to override $CC at make time, since there is no
315 echo "Building kernel in $PWD..."
316 case "$TARGET_ARCH" in
317 i386 | i586 | i686 | athlon | x86_64)
318 $MAKE_J bzImage || fatal 1 "Error making bzImage."
321 $MAKE_J boot || fatal 1 "Error making boot."
324 $MAKE_J modules || fatal 1 "Error building modules."
331 (( $BUILD_LUSTRE )) || return 0
332 pushd "$TOPDIR" >/dev/null
333 [ -f Makefile ] && make -s clean
334 [ -f configure ] || sh ./autogen.sh
335 ./configure --with-linux=$PWD/linux $CONFIGURE_FLAGS || \
336 fatal 1 "Error configuring Lustre."
342 (( $BUILD_LUSTRE )) || return 0
344 pushd "$TOPDIR" >/dev/null
345 $MAKE_J || fatal 1 "Error building Lustre."
351 (( $INSTALL_KERNEL )) || return 0
352 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
353 pushd "$TOPDIR/linux" >/dev/null
354 mkdir -p "$DESTDIR/boot"
356 install -m 644 System.map "$DESTDIR/boot/System.map-${FULL_VERSION}"
357 # install -m 644 module-info ...
358 install -m 644 "$CONFIG_FILE" "$DESTDIR/boot/config-${FULL_VERSION}"
360 mkdir -p "$DESTDIR/dev/shm"
361 mkdir -p "$DESTDIR/lib/modules/${FULL_VERSION}"
363 make CC="$CC" INSTALL_MOD_PATH="$DESTDIR" KERNELRELEASE="$FULL_VERSION" \
364 -s modules_install || \
365 fatal 1 "Error installing modules."
367 case "$TARGET_ARCH" in
368 i386 | i586 | i686 | athlon)
369 cp arch/i386/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
370 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
371 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
374 cp arch/x86_64/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
375 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
376 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
379 gzip -cfv vmlinux > vmlinuz
380 mkdir -p "$DESTDIR/boot/efi/redhat"
381 install -m 755 vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
382 install -m 755 vmlinuz "$DESTDIR/boot/efi/redhat/vmlinuz-${FULL_VERSION}"
383 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/efi/redhat/vmlinux-${FULL_VERSION}"
384 ln -sf "efi/redhat/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
385 ln -sf "efi/redhat/vmlinuz-${FULL_VERSION}" "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
388 cp vmlinuz "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
389 cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}"
390 ln -sf "../lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
400 (( $INSTALL_LUSTRE )) || return 0
401 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
402 pushd "$TOPDIR" >/dev/null
403 make -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
409 echo "Saving headers for $1 $2..."
410 pushd linux >/dev/null
412 KVERREL="${VERSION}-${EXTRA_VERSION}"
413 # deal with the kernel headers that are version specific
415 saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/$2/$1"
417 install -m 644 include/linux/autoconf.h "$saveddir/autoconf.h"
418 install -m 644 include/linux/version.h "$saveddir/version.h"
419 mv include/linux/modules "$saveddir/"
420 echo $2 $1 ../../savedheaders/$2/$1/ >> $RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/list
426 (( $SAVE_HEADERS )) || return 0
428 for arch in $BIGMEM_ARCHS ; do
429 save_headers bigmem $arch
432 for arch in $BOOT_ARCHS ; do
433 save_headers BOOT $arch
436 for arch in $JENSEN_ARCHS ; do
437 save_headers jensen $arch
440 for arch in $SMP_ARCHS ; do
441 save_headers smp $arch
444 for arch in $UP_ARCHS ; do
445 save_headers up $arch
449 longopts="build,build-lustre,build-kernel,depend-kernel,destdir:,extraversion:"
450 longopts="$longopts,help,install,install-lustre,install-kernel,kerneldir:"
451 longopts="$longopts,save-headers,target:,target-arch:,target-config:,unpack-kernel"
453 options=$(getopt -o hj: -l "$longopts" -- "$@")
455 eval set -- "$options"
540 usage 1 "Unrecognized option: $1"