Whamcloud - gitweb
Try to get some more information when update_oldconfig fails. Probably some
[fs/lustre-release.git] / build / lmake
1 #!/bin/sh
2
3 # option variables
4 DESTDIR=
5 KERNELDIR=
6 TARGET=
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/)
9 TARGET_ARCH=
10 TARGET_CONFIG=
11 JOBS=1
12 CONFIGURE_FLAGS=
13
14 # commands to run
15 BUILD_LUSTRE=0
16 BUILD_KERNEL=0
17 DEPEND_KERNEL=0
18 INSTALL_LUSTRE=0
19 INSTALL_KERNEL=0
20 SAVE_HEADERS=0
21 UNPACK_KERNEL=0
22
23 # provided by target file
24 KERNEL=
25 SERIES=
26 CONFIG=
27 VERSION=
28 EXTRA_VERSION=
29
30 BASE_ARCHS=
31 BIGMEM_ARCHS=
32 BOOT_ARCHS=
33 JENSEN_ARCHS=
34 SMP_ARCHS=
35 BIGSMP_ARCHS=
36 PSERIES64_ARCHS=
37 UP_ARCHS=
38
39 RHBUILD=0
40 SUSEBUILD=0
41
42 # flat-out globals
43 TOPDIR=
44 TARGET_FILE=
45 KERNEL_FILE=
46 SERIES_FILE=
47 CONFIG_FILE=
48 RPMBUILD=
49
50 canon()
51 {
52     pushd $1 >/dev/null
53     echo $PWD
54     popd >/dev/null
55 }
56 TOPDIR="${0%%${0##*/}}"
57 if [ "${TOPDIR}" ] ; then
58     TOPDIR=$(canon "${TOPDIR}/..")
59 else
60     TOPDIR=$(canon "..")
61 fi
62
63 lbuild_topdir()
64 {
65     retdir=$TOPDIR
66     while [ ! -d $retdir/BUILD ] ; do
67         retdir=$(canon "$retdir/..")
68         if [ "$retdir" = "/" ] ; then
69             break;
70         fi
71     done
72     echo "$retdir"
73 }
74
75 cleanup()
76 {
77     true
78 }
79
80 fatal()
81 {
82     cleanup
83     [ "$2" ] && echo
84     [ "$2" ] && echo "${0##*/}: $2"
85     exit $1
86 }
87
88 list_targets()
89 {
90     echo -n "Available targets:"
91     for target in $TOPDIR/lustre/kernel_patches/targets/*.target ; do
92         target_file=${target##*/}
93         echo -n " ${target_file%%.target}"
94     done
95     echo
96 }
97
98
99 usage()
100 {
101     cat <<EOF
102 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
103
104 Options:
105
106   --build
107     same as --build-kernel --build-lustre --unpack-kernel
108
109   --build-lustre
110     configure and compile lustre.  Requires that --build-kernel was
111     already run.
112
113   --build-kernel
114     configure and compile a kernel.  Implies --depend-kernel.
115     Requires that --unpack-kernel was already run.
116
117   --depend-kernel)
118     Prepares a kernel tree for building (similar to make mrproper
119     oldconfig dep).  Requires that --unpack-kernel was already run.
120
121   --destdir=DESTDIR
122     Root directory to install into (like DESTDIR with auto*).
123
124   --extraversion=EXTRAVERSION
125     Overrides the target kernel\'s EXTRAVERSION text.
126
127   -h, --help
128     Display this message.
129
130   --install
131     same as --install-kernel --install-lustre
132
133   --install-lustre
134     run make install in the Lustre tree.
135
136   --install-kernel
137     install the kernel image and modules.
138
139   -j jobs
140     This works just like the -j option to make, and is passed to make
141     when building.
142
143   --kerneldir=KERNELDIR
144     Directory containing linux source tarballs.
145
146   --target=TARGET
147     Name of the configuration to use.  The available targets are
148     listed below.
149
150   --target-arch=ARCH
151     Specifies an architecture to use when choosing a kernel config
152     file.  Default is i386.
153
154   --target-config=CONFIG
155     Specifies a special option (such as smp, bigsmp, bigmem, or BOOT)
156     to use when choosing a kernel config file.  This also modifies the
157     kernel version and modules directory.
158
159   --unpack-kernel
160     Untars and patches the kernel source.
161
162   The order that commands (--build-lustre, --unpack-kernel) are
163   specified on the command line is ignored; ${0##*/} will always
164   execute them in the correct order (unpack, then build, then install
165   etc.).
166
167 EOF
168     list_targets
169
170     fatal "$1" "$2"
171 }
172
173 check_options()
174 {
175     (( $BUILD_LUSTRE || $BUILD_KERNEL || $DEPEND_KERNEL || \
176             $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS || \
177             $UNPACK_KERNEL )) || \
178                 fatal 1 "No commands specified."
179
180     if (( $UNPACK_KERNEL )) ; then
181         [ "$KERNELDIR" ] || \
182             fatal 1 "A kernel directory must be specified with --kerneldir."
183         [ -d "$KERNELDIR" ] || \
184             fatal 1 "$KERNELDIR is not a directory."
185     fi
186
187     if (( $INSTALL_LUSTRE || $INSTALL_KERNEL || $SAVE_HEADERS )) ; then
188         [ -z "$DESTDIR" -o -d "$DESTDIR" ] || \
189             fatal 1 "$DESTDIR is not a directory."
190     fi
191
192     [ "$TARGET" ] || usage 1 "A target must be specified with --target."
193     TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
194     [ -r "$TARGET_FILE" ] || \
195         fatal 1 "Target '$TARGET' was not found.  Try --list-targets."
196
197     if [ -z "$JOBS" -o "$JOBS" -lt "1" ] ; then
198         JOBS=1
199     fi
200
201     RPMBUILD=$(which rpmbuild 2>/dev/null | head -1)
202     if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
203         RPMBUILD=$(which rpm 2>/dev/null | head -1)
204         if [ ! "$RPMBUILD" -o "$RPMBUILD" == "" ]; then
205             usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
206         fi
207     fi
208 }
209
210 get_lustre_version()
211 {
212     for series in $SERIES ; do
213         SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
214         lustre_patch=$(grep lustre_version "$SERIES_FILE" 2>/dev/null)
215         [ "$lustre_patch" ] && break
216     done
217     [ "$lustre_patch" ] || \
218         fatal 1 "Could not determine Lustre version from $SERIES series."
219
220     awk '/^\+#define LUSTRE_KERNEL_VERSION /{ print $3 }' \
221         "$TOPDIR/lustre/kernel_patches/patches/$lustre_patch" 2>/dev/null
222 }
223
224 load_target()
225 {
226     EXTRA_VERSION_save="$EXTRA_VERSION"
227
228     . "$TARGET_FILE"
229
230     [ "$KERNEL" ] || fatal 1 "Target $TARGET did not specify a kernel."
231 # Suse 2.6 has our patches in already
232 #    [ "$SERIES" ] || fatal 1 "Target $TARGET did not specify a patch series."
233 #    [ "$CONFIG" ] || fatal 1 "Target $TARGET did not specify a kernel config."
234     [ "$VERSION" ] || fatal 1 "Target $TARGET did not specify the kernel version."
235     
236     if [ "$KERNELDIR" ] ; then
237         KERNEL_FILE="$KERNELDIR/$KERNEL"
238         [ -r "$KERNELDIR/$KERNEL" ] || \
239             fatal 1 "Target $TARGET's kernel file $KERNEL not found in kernel directory $KERNELDIR."
240     fi
241
242     if [ "$SERIES" ] ; then
243         for series in $SERIES ; do
244             SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
245             [ -r "$SERIES_FILE" ] || \
246                 fatal 1 "Target $TARGET's series $SERIES missing from $TOPDIR/lustre/kernel_patches/series."
247         done
248     fi
249
250     TARGET_ARCH=${TARGET_ARCH:-$BASE_ARCHS}
251     CONFIG_TARGET="$TARGET-${TARGET_ARCH}${TARGET_CONFIG:+-$TARGET_CONFIG}"
252     CONFIG_FILE="$TOPDIR/lustre/kernel_patches/kernel_configs/kernel-$VERSION-$CONFIG_TARGET.config"
253     [ -r "$CONFIG_FILE" ] ||
254         fatal 1 "Target $TARGET's config file $CONFIG_FILE missing from $TOPDIR/lustre/kernel_patches/configs."
255
256     if [ "$EXTRA_VERSION_save" ] ; then
257         EXTRA_VERSION="$EXTRA_VERSION_save"
258     else
259         EXTRA_VERSION="${EXTRA_VERSION}_lustre.$(get_lustre_version)"
260     fi
261 }
262
263 tarflags()
264 {
265     case "$1" in
266         '')
267             fatal 1 "tarflags(): File name argument missing."
268             ;;
269         *.tar.gz | *.tgz)
270             echo 'zxf'
271             ;;
272         *.tar.bz2)
273             echo 'jxf'
274             ;;
275         *.tar)
276             echo 'xf'
277             ;;
278         *)
279             fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
280             ;;
281     esac
282 }
283
284 untar()
285 {
286     echo "Untarring ${1##*/}..."
287     tar $(tarflags $1) $1
288 }
289
290
291 extract_kernel()
292 {
293     (( $UNPACK_KERNEL )) || return 0
294     pushd "$TOPDIR" >/dev/null
295     if [ -d linux ] ; then
296         [ -L linux ] && rm -rf $(readlink linux)
297         rm -rf linux
298     fi
299     untar "$KERNEL_FILE"
300     [ -d linux ] || ln -sf linux* linux
301     popd >/dev/null
302 }
303
304 patch_kernel()
305 {
306     (( $UNPACK_KERNEL )) || return 0
307     [ "$SERIES" ] || return 0
308     pushd "$TOPDIR/linux" >/dev/null
309     for series in $SERIES ; do
310         echo -n "Applying series $series:"
311         SERIES_FILE="$TOPDIR/lustre/kernel_patches/series/$series"
312         for patch in $(<"$SERIES_FILE") ; do
313             PATCH_FILE="$TOPDIR/lustre/kernel_patches/patches/$patch"
314             [ -r "$PATCH_FILE" ] || \
315                 fatal 1 "Patch file not found: $patch"
316             echo -n " $patch"
317             patch -s -p1 < "$PATCH_FILE" || fatal 1 "Error applying patch $patch."
318         done
319         echo
320     done
321     popd >/dev/null
322 }
323
324 set_make()
325 {
326     MAKE="make -s"
327     if [ "$CC" ] ; then
328         MAKE_CC="CC=$CC"
329     fi
330     if [ "$ARCH" ] ; then
331         MAKE_ARCH="$MAKE ARCH=$ARCH"
332     else
333         case $TARGET_ARCH in
334             i?86)
335                 ;;
336             *)
337                 MAKE_ARCH="$MAKE ARCH=$TARGET_ARCH"
338                 ;;
339         esac
340     fi
341     MAKE_J="$MAKE -j $JOBS"
342 }
343
344 timed_run() {
345     SLEEP_TIME=$1
346     shift
347
348     set -o monitor
349
350     #bash -c "$@" &
351     ("$@") &
352     child_pid=$!
353     
354     (sleep $SLEEP_TIME
355     kill -TERM -$child_pid 2>/dev/null
356     sleep 5
357     kill -KILL -$child_pid 2>/dev/null
358     echo "$1 was killed due to timeout") &
359     dog_pid=$!
360
361     wait $child_pid
362     # status will be set to 143 if the process had to be killed due to timeout
363     status=$?
364     kill -KILL -$dog_pid
365     return $status
366 }
367
368 depend_kernel()
369 {
370     (( $DEPEND_KERNEL )) || return 0
371     # we need to override $CC at make time, since there is no
372     # configure
373     set_make
374     pushd "$TOPDIR/linux" >/dev/null
375     echo "Overriding EXTRAVERSION in kernel..."
376     perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${EXTRA_VERSION}${TARGET_CONFIG}/" Makefile
377     echo "Making depend in $PWD..."
378     $MAKE "$MAKE_CC" mrproper || fatal 1 "Error running make mrproper"
379     rm -f rpm-release
380     cp "$CONFIG_FILE" .config
381     # use the expect script to "make oldconfig" and answer the questions for
382     # new items conservatively.  QA will get notified on anything newly added
383     # for them to review and adjust accordingly.
384     local logfile=$(mktemp /tmp/XXXXXX)
385     timed_run 300 $TOPDIR/build/update_oldconfig $logfile
386     if [ ${PIPESTATUS[0]} -eq 143 ]; then
387         fatal 1 "update_oldconfig timed out"
388     elif [ ${PIPESTATUS[0]} -ne 0 ]; then
389         # dump the log
390         cat $logfile
391         rm -f $logfile
392         fatal 1 "update_oldconfig failed: $?. See log above."
393     fi
394     rm -f $logfile
395     # now notify if resulting .config is different than $CONFIG_FILE
396     local tmpfile=$(mktemp /tmp/XXXXXX)
397     diff -I '^#.*' -u "$CONFIG_FILE" .config >$tmpfile
398     if [ -s $tmpfile ]; then
399         { cat <<EOF
400 To: qa@lists.clusterfs.com
401 Subject: kernel_config change 
402
403 The result of a make oldconfig on file $CONFIG_FILE resulted in a
404 difference when compared to .config in the following way:
405
406 EOF
407         cat $tmpfile
408         echo -e "\n\nPlease consider updating $CONFIG_FILE."
409         # not sure these are entirely useful.  the above and "patch" are good
410         #echo -e "\nThe entire new .config file:\n"
411         #cat .config
412         } | sendmail -fqa@clusterfs.com -t
413     fi
414     rm -f $tmpfile
415     case "$VERSION" in
416         2.6*)
417             $MAKE "$MAKE_CC" include/asm
418             ;;
419         2.4*)
420             $MAKE "$MAKE_CC" symlinks
421             $MAKE "$MAKE_CC" dep || fatal 1 "Error running make dep"
422             ;;
423     esac
424     $MAKE "$MAKE_CC" include/linux/version.h || fatal 1 "Error making include/linux/version.h"
425 }
426
427 build_kernel()
428 {
429     (( $BUILD_KERNEL )) || return 0
430     set_make
431     echo "Building kernel in $PWD..."
432     case "$TARGET_ARCH" in
433         i386 | i586 | i686 | athlon | x86_64)
434             $MAKE_J "$MAKE_CC" bzImage || fatal 1 "Error making bzImage."
435             ;;
436     ia64 | ppc | ppc64)
437             $MAKE_J "$MAKE_CC" vmlinux || fatal 1 "Error making vmlinux."
438             ;;
439         *)
440             $MAKE_J "$MAKE_CC" boot || fatal 1 "Error making boot."
441             ;;
442     esac
443     $MAKE_J "$MAKE_CC" modules || fatal 1 "Error building modules."
444
445     popd >/dev/null
446 }
447
448 configure_lustre()
449 {
450     return 0
451     (( $BUILD_LUSTRE )) || return 0
452     pushd "$TOPDIR" >/dev/null
453     [ -f Makefile ] && make -s clean
454     [ -f configure ] || sh ./autogen.sh
455     ./configure --with-linux=$PWD/linux $CONFIGURE_FLAGS || \
456         fatal 1 "Error configuring Lustre."
457     popd >/dev/null
458 }
459
460 build_lustre()
461 {
462     (( $BUILD_LUSTRE )) || return 0
463     set_make
464     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
465     pushd "$TOPDIR" >/dev/null
466     sed \
467         -e s^@VERSION@^${LUSTRE_VERSION}^g \
468         -e s^@LINUXRELEASE@^${FULL_VERSION}^g \
469         -e s^@RELEASE@^${FULL_VERSION//-/_}^g \
470         -e s^@ac_configure_args@^"--with-linux=${PWD}/linux ${CONFIGURE_FLAGS}"^g \
471         < build/lustre.spec.in \
472         > build/lustre.spec
473     $RPMBUILD --target ${TARGET_ARCH} -bb build/lustre.spec \
474         --define "_topdir $(lbuild_topdir)" || \
475         fatal 1 "Error building Lustre rpms."
476     # $MAKE_J "$MAKE_CC" || fatal 1 "Error building Lustre."
477     popd >/dev/null
478 }
479
480 install_kernel()
481 {
482     (( $INSTALL_KERNEL )) || return 0
483     set_make
484     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
485     pushd "$TOPDIR/linux" >/dev/null
486     mkdir -p "$DESTDIR/boot"
487
488     install -m 644 System.map "$DESTDIR/boot/System.map-${FULL_VERSION}"
489     # install -m 644 module-info ...
490     install -m 644 "$CONFIG_FILE" "$DESTDIR/boot/config-${FULL_VERSION}"
491
492     mkdir -p "$DESTDIR/dev/shm"
493     mkdir -p "$DESTDIR/lib/modules/${FULL_VERSION}"
494
495     $MAKE "$MAKE_CC" INSTALL_MOD_PATH="$DESTDIR" KERNELRELEASE="$FULL_VERSION" \
496         -s modules_install || \
497         fatal 1 "Error installing modules."
498
499     case "$TARGET_ARCH" in
500         i386 | i586 | i686 | athlon)
501             cp arch/i386/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
502             cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
503             ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
504             ;;
505         x86_64)
506             cp arch/x86_64/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
507             cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
508             ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
509             ;;
510         ppc | ppc64)
511             cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
512             ln -sf "$DESTDIR/boot/vmlinux-${FULL_VERSION}" "../lib/modules/${FULL_VERSION}/vmlinux" 
513             ;;
514         ia64)
515             gzip -cfv vmlinux > vmlinuz
516             mkdir -p "$DESTDIR/boot/efi/redhat"
517             install -m 755 vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
518             install -m 755 vmlinuz "$DESTDIR/boot/efi/redhat/vmlinuz-${FULL_VERSION}"
519             ln -sf "../../../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/efi/redhat/vmlinux-${FULL_VERSION}"
520             ln -sf "efi/redhat/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
521             ln -sf "efi/redhat/vmlinuz-${FULL_VERSION}" "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
522             ;;
523         *)
524             cp vmlinuz "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
525             cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}"
526             ln -sf "../lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
527
528             ;;
529     esac
530     if [ -e init/kerntypes.o ] ; then
531         cp init/kerntypes.o "$DESTDIR/boot/Kerntypes-${FULL_VERSION}"
532     fi
533
534     popd >/dev/null
535 }
536
537 cleanup_libmodules()
538 {
539     (( $INSTALL_LUSTRE )) || return 0
540
541     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
542     KVERREL="${VERSION}-${EXTRA_VERSION}"
543     i="$DESTDIR/lib/modules/${FULL_VERSION}"
544
545     rm -f $i/build
546     rm -f $i/source
547
548     if (( $LINUX26 )) ; then
549         ln -sf ../../../usr/src/linux-${KVERREL}-obj/${TARGET_ARCH}/${TARGET_CONFIG} $i/build
550         ln -sf ../../../usr/src/linux-${KVERREL} $i/source
551     else
552         ln -sf ../../../usr/src/linux-${KVERREL} $i/build
553     fi
554 }
555
556 install_lustre()
557 {
558     (( $INSTALL_LUSTRE )) || return 0
559     return 0
560     set_make
561     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
562     pushd "$TOPDIR" >/dev/null
563     $MAKE "$MAKE_CC" -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
564     popd >/dev/null
565 }
566
567 build_kms()
568 {
569     (( $BUILD_KERNEL )) || return 0
570     (( $SUSEBUILD )) || return 0
571     set_make
572     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
573     mkdir -p "${TOPDIR}/modules-${FULL_VERSION}"
574     for dir in /usr/src/kernel-modules/* ; do
575         # we are replacing lustre-lite, so don't include it
576         if [ "${dir##*/}" != "lustre-lite" -a -e $dir/Makefile ]; then
577             build_dir="${TOPDIR}/modules-${FULL_VERSION}/${dir##*/}"
578             cp -a $dir $build_dir
579             # these modules are terrible, and don't all build
580             $MAKE_J "$MAKE_CC" -C $build_dir modules KERNEL_SOURCE="${TOPDIR}/linux"
581         fi
582     done
583 }
584
585 symver()
586 {
587     local file=$1 name=${1%.ko}
588     nm $file \
589     | sed -ne 's,^0*\([0-9a-f]\{8\}\) A __crc_\(.*\),0x\1\t\2\t'"$name"',p'
590 }
591
592 install_kms()
593 {
594     (( $INSTALL_KERNEL )) || return 0
595     (( $LINUX26 )) || return 0
596     set_make
597     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
598     for build_dir in "${TOPDIR}/modules-${FULL_VERSION}/*" ; do
599         [ -d $build_dir ] || continue
600         # these modules are terrible, and don't all build
601         $MAKE "$MAKE_CC" -C $build_dir KERNEL_SOURCE="${TOPDIR}/linux" INSTALL_MOD_PATH="$DESTDIR" 
602     done
603     (   symver vmlinux
604         moddir="${DESTDIR}/lib/modules/${FULL_VERSION}"
605         cd $moddir/kernel
606         for module in $(find * -name '*.ko'); do
607             symver $module
608         done
609         cd $moddir
610         for module in $(find * -path 'kernel/*' -prune -o \
611                            -name '*.ko' -print); do
612             symver $module
613         done
614     ) | sort -u -k2 \
615         | gzip -c9 > "${DESTDIR}/boot/symvers-${VERSION}-${EXTRA_VERSION}-${TARGET_ARCH}${TARGET_CONFIG}.gz"
616 }
617
618 save_headers()
619 {
620     (( $SAVE_HEADERS )) || return 0
621
622     echo "Saving headers for ${TARGET_CONFIG:-up} ${TARGET_ARCH}..."
623     pushd linux >/dev/null
624
625     KVERREL="${VERSION}-${EXTRA_VERSION}"
626     # deal with the kernel headers that are version specific
627     
628     saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/${TARGET_ARCH}/${TARGET_CONFIG:-up}"
629     mkdir -p "$saveddir"
630     install -m 644 include/linux/autoconf.h "$saveddir/autoconf.h"
631     install -m 644 include/linux/version.h  "$saveddir/version.h"
632     mv include/linux/modules "$saveddir/"
633     echo ${TARGET_ARCH} ${TARGET_CONFIG} ../../savedheaders/${TARGET_ARCH}/${TARGET_CONFIG:-up}/ \
634         >>  "$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/list"
635     popd >/dev/null
636 }
637
638 save_all_headers()
639 {
640     (( $SAVE_HEADERS )) || return 0
641
642     for arch in $BIGMEM_ARCHS ; do
643         save_headers bigmem $arch
644     done
645
646     for arch in $BOOT_ARCHS ; do
647         save_headers BOOT $arch
648     done
649
650     for arch in $JENSEN_ARCHS ; do
651         save_headers jensen $arch
652     done
653
654     for arch in $SMP_ARCHS ; do
655         save_headers smp $arch
656     done
657
658     for arch in $BIGSMP_ARCHS ; do
659         save_headers bigsmp $arch
660     done
661     for arch in $PSERIES64_ARCHS ; do
662         save_headers pseries64 $arch
663     done
664     for arch in $UP_ARCHS ; do
665         save_headers up $arch
666     done
667 }
668
669 longopts="build,build-lustre,build-kernel,depend-kernel,destdir:,extraversion:"
670 longopts="$longopts,help,install,install-lustre,install-kernel,kerneldir:"
671 longopts="$longopts,save-headers,target:,target-arch:,target-config:,unpack-kernel"
672
673 options=$(getopt -o hj: -l "$longopts" -- "$@")
674
675 eval set -- "$options"
676     
677 while [ "$1" ] ; do
678     case "$1" in
679         '')
680             usage 1
681             ;;
682         --build)
683             BUILD_LUSTRE=1
684             BUILD_KERNEL=1
685             DEPEND_KERNEL=1
686             UNPACK_KERNEL=1
687             shift
688             ;;
689         --build-lustre)
690             BUILD_LUSTRE=1
691             shift
692             ;;
693         --build-kernel)
694             BUILD_KERNEL=1
695             DEPEND_KERNEL=1
696             shift
697             ;;
698         --depend-kernel)
699             DEPEND_KERNEL=1
700             shift
701             ;;
702         --destdir)
703             DESTDIR=$2
704             shift 2
705             ;;
706         --extraversion)
707             EXTRA_VERSION=$2
708             shift 2
709             ;;
710         --help | -h)
711             usage 0
712             ;;
713         --install)
714             INSTALL_LUSTRE=1
715             INSTALL_KERNEL=1
716             shift
717             ;;
718         --install-lustre)
719             INSTALL_LUSTRE=1
720             shift
721             ;;
722         --install-kernel)
723             INSTALL_KERNEL=1
724             shift
725             ;;
726         -j)
727             JOBS=$2
728             shift 2
729             ;;
730         --kerneldir)
731             KERNELDIR=$2
732             shift 2
733             ;;
734         --save-headers)
735             SAVE_HEADERS=1
736             shift
737             ;;
738         --target)
739             TARGET=$2
740             shift 2
741             ;;
742         --target-arch)
743             TARGET_ARCH=$2
744             shift 2
745             ;;
746         --target-config)
747             TARGET_CONFIG=$2
748             shift 2
749             ;;
750         --unpack-kernel)
751             UNPACK_KERNEL=1
752             shift
753             ;;
754         --)
755             shift
756             CONFIGURE_FLAGS=$@
757             break
758             ;; 
759         *)
760             usage 1 "Unrecognized option: $1"
761             ;;
762     esac
763 done
764
765 check_options
766 load_target
767
768 extract_kernel
769 patch_kernel
770
771 depend_kernel
772 build_kernel
773
774 configure_lustre
775 build_lustre
776
777 build_kms
778
779 install_kernel
780 install_lustre
781
782 install_kms
783
784 cleanup_libmodules
785
786 save_headers
787
788 exit 0