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 (( $DEPEND_KERNEL )) || return 0
281 # we need to override $CC at make time, since there is no
283 MAKE="make -s CC=$CC"
284 pushd "$TOPDIR/linux" >/dev/null
285 echo "Overriding EXTRAVERSION in kernel..."
286 perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${EXTRA_VERSION}${TARGET_CONFIG}/" Makefile
287 echo "Making depend in $PWD..."
288 $MAKE mrproper || fatal 1 "Error running make mrproper"
289 cp "$CONFIG_FILE" .config
290 $MAKE oldconfig_nonint || fatal 1 "Error running make oldconfig"
291 $MAKE -j $JOBS dep || fatal 1 "Error running make dep"
292 $MAKE include/linux/version.h || fatal 1 "Error making include/linux/version.h"
297 (( $BUILD_KERNEL )) || return 0
298 # we need to override $CC at make time, since there is no
300 MAKE="make -s CC=$CC"
301 echo "Building kernel in $PWD..."
302 case "$TARGET_ARCH" in
303 i386 | i586 | i686 | athlon | x86_64)
304 $MAKE -j $JOBS -s bzImage || fatal 1 "Error making bzImage."
307 $MAKE -j $JOBS -s boot || fatal 1 "Error making boot."
310 $MAKE -j $JOBS -s modules || fatal 1 "Error building modules."
317 (( $BUILD_LUSTRE )) || return 0
318 pushd "$TOPDIR" >/dev/null
319 [ -f Makefile ] && make -s clean
320 [ -f configure ] || sh ./autogen.sh
321 ./configure --with-linux=$PWD/linux $CONFIGURE_FLAGS || \
322 fatal 1 "Error configuring Lustre."
328 (( $BUILD_LUSTRE )) || return 0
329 pushd "$TOPDIR" >/dev/null
330 make -j $JOBS -s || fatal 1 "Error building Lustre."
336 (( $INSTALL_KERNEL )) || return 0
337 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
338 pushd "$TOPDIR/linux" >/dev/null
339 mkdir -p "$DESTDIR/boot"
341 install -m 644 System.map "$DESTDIR/boot/System.map-${FULL_VERSION}"
342 # install -m 644 module-info ...
343 install -m 644 "$CONFIG_FILE" "$DESTDIR/boot/config-${FULL_VERSION}"
345 mkdir -p "$DESTDIR/dev/shm"
347 case "$TARGET_ARCH" in
348 i386 | i586 | i686 | athlon)
349 cp arch/i386/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
350 cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
353 cp arch/x86_64/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
354 cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
357 gzip -cfv vmlinux > vmlinuz
358 mkdir -p "$DESTDIR/boot/efi/redhat"
359 install -m 755 vmlinux "$DESTDIR/boot/efi/redhat/vmlinux-${FULL_VERSION}"
360 install -m 755 vmlinuz "$DESTDIR/boot/efi/redhat/vmlinuz-${FULL_VERSION}"
361 ln -sf "efi/redhat/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
362 ln -sf "efi/redhat/vmlinuz-${FULL_VERSION}" "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
365 cp vmlinuz "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
366 cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
370 mkdir -p "$DESTDIR/lib/modules/${FULL_VERSION}"
371 make CC="$CC" INSTALL_MOD_PATH="$DESTDIR" KERNELRELEASE="$FULL_VERSION" \
372 -s modules_install || \
373 fatal 1 "Error installing modules."
380 (( $INSTALL_LUSTRE )) || return 0
381 FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
382 pushd "$TOPDIR" >/dev/null
383 make -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
389 echo "Saving headers for $1 $2..."
390 pushd linux >/dev/null
392 KVERREL="${VERSION}-${EXTRA_VERSION}"
393 # deal with the kernel headers that are version specific
395 saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/$2/$1"
397 install -m 644 include/linux/autoconf.h "$saveddir/autoconf.h"
398 install -m 644 include/linux/version.h "$saveddir/version.h"
399 mv include/linux/modules "$saveddir/"
400 echo $2 $1 ../../savedheaders/$2/$1/ >> $RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/list
406 (( $SAVE_HEADERS )) || return 0
408 for arch in $BIGMEM_ARCHS ; do
409 save_headers bigmem $arch
412 for arch in $BOOT_ARCHS ; do
413 save_headers BOOT $arch
416 for arch in $JENSEN_ARCHS ; do
417 save_headers jensen $arch
420 for arch in $SMP_ARCHS ; do
421 save_headers smp $arch
424 for arch in $UP_ARCHS ; do
425 save_headers up $arch
429 longopts="build,build-lustre,build-kernel,depend-kernel,destdir:,extraversion:"
430 longopts="$longopts,help,install,install-lustre,install-kernel,kerneldir:"
431 longopts="$longopts,save-headers,target:,target-arch:,target-config:,unpack-kernel"
433 options=$(getopt -o hj: -l "$longopts" -- "$@")
435 eval set -- "$options"
520 usage 1 "Unrecognized option: $1"