Whamcloud - gitweb
Trickery to get the exit status of strace's subject.
[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=${PIPESTATUS[0]}
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     #local RC=${PIPESTATUS[0]}
387     local RC=$(strace -f -o update_oldconfig.strace bash -c "$TOPDIR/build/update_oldconfig $logfile; echo \$?")
388     if [ $RC -eq 143 ]; then
389         fatal 1 "update_oldconfig timed out"
390     elif [ $RC -ne 0 ]; then
391         # dump the log
392         cat $logfile
393         rm -f $logfile
394         cat update_oldconfig.strace
395         rm -f update_oldconfig.strace
396         fatal 1 "update_oldconfig failed: $RC. See log above."
397     fi
398     rm -f $logfile
399     # now notify if resulting .config is different than $CONFIG_FILE
400     local tmpfile=$(mktemp /tmp/XXXXXX)
401     diff -I '^#.*' -u "$CONFIG_FILE" .config >$tmpfile
402     if [ -s $tmpfile ]; then
403         { cat <<EOF
404 To: qa@lists.clusterfs.com
405 Subject: kernel_config change 
406
407 The result of a make oldconfig on file $CONFIG_FILE resulted in a
408 difference when compared to .config in the following way:
409
410 EOF
411         cat $tmpfile
412         echo -e "\n\nPlease consider updating $CONFIG_FILE."
413         # not sure these are entirely useful.  the above and "patch" are good
414         #echo -e "\nThe entire new .config file:\n"
415         #cat .config
416         } | sendmail -fqa@clusterfs.com -t
417     fi
418     rm -f $tmpfile
419     case "$VERSION" in
420         2.6*)
421             $MAKE "$MAKE_CC" include/asm
422             ;;
423         2.4*)
424             $MAKE "$MAKE_CC" symlinks
425             $MAKE "$MAKE_CC" dep || fatal 1 "Error running make dep"
426             ;;
427     esac
428     $MAKE "$MAKE_CC" include/linux/version.h || fatal 1 "Error making include/linux/version.h"
429 }
430
431 build_kernel()
432 {
433     (( $BUILD_KERNEL )) || return 0
434     set_make
435     echo "Building kernel in $PWD..."
436     case "$TARGET_ARCH" in
437         i386 | i586 | i686 | athlon | x86_64)
438             $MAKE_J "$MAKE_CC" bzImage || fatal 1 "Error making bzImage."
439             ;;
440     ia64 | ppc | ppc64)
441             $MAKE_J "$MAKE_CC" vmlinux || fatal 1 "Error making vmlinux."
442             ;;
443         *)
444             $MAKE_J "$MAKE_CC" boot || fatal 1 "Error making boot."
445             ;;
446     esac
447     $MAKE_J "$MAKE_CC" modules || fatal 1 "Error building modules."
448
449     popd >/dev/null
450 }
451
452 configure_lustre()
453 {
454     return 0
455     (( $BUILD_LUSTRE )) || return 0
456     pushd "$TOPDIR" >/dev/null
457     [ -f Makefile ] && make -s clean
458     [ -f configure ] || sh ./autogen.sh
459     ./configure --with-linux=$PWD/linux $CONFIGURE_FLAGS || \
460         fatal 1 "Error configuring Lustre."
461     popd >/dev/null
462 }
463
464 build_lustre()
465 {
466     (( $BUILD_LUSTRE )) || return 0
467     set_make
468     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
469     pushd "$TOPDIR" >/dev/null
470     sed \
471         -e s^@VERSION@^${LUSTRE_VERSION}^g \
472         -e s^@LINUXRELEASE@^${FULL_VERSION}^g \
473         -e s^@RELEASE@^${FULL_VERSION//-/_}^g \
474         -e s^@ac_configure_args@^"--with-linux=${PWD}/linux ${CONFIGURE_FLAGS}"^g \
475         < build/lustre.spec.in \
476         > build/lustre.spec
477     $RPMBUILD --target ${TARGET_ARCH} -bb build/lustre.spec \
478         --define "_topdir $(lbuild_topdir)" || \
479         fatal 1 "Error building Lustre rpms."
480     # $MAKE_J "$MAKE_CC" || fatal 1 "Error building Lustre."
481     popd >/dev/null
482 }
483
484 install_kernel()
485 {
486     (( $INSTALL_KERNEL )) || return 0
487     set_make
488     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
489     pushd "$TOPDIR/linux" >/dev/null
490     mkdir -p "$DESTDIR/boot"
491
492     install -m 644 System.map "$DESTDIR/boot/System.map-${FULL_VERSION}"
493     # install -m 644 module-info ...
494     install -m 644 "$CONFIG_FILE" "$DESTDIR/boot/config-${FULL_VERSION}"
495
496     mkdir -p "$DESTDIR/dev/shm"
497     mkdir -p "$DESTDIR/lib/modules/${FULL_VERSION}"
498
499     $MAKE "$MAKE_CC" INSTALL_MOD_PATH="$DESTDIR" KERNELRELEASE="$FULL_VERSION" \
500         -s modules_install || \
501         fatal 1 "Error installing modules."
502
503     case "$TARGET_ARCH" in
504         i386 | i586 | i686 | athlon)
505             cp arch/i386/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
506             cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
507             ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
508             ;;
509         x86_64)
510             cp arch/x86_64/boot/bzImage "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
511             cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
512             ln -sf "../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
513             ;;
514         ppc | ppc64)
515             cp vmlinux "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
516             ln -sf "$DESTDIR/boot/vmlinux-${FULL_VERSION}" "../lib/modules/${FULL_VERSION}/vmlinux" 
517             ;;
518         ia64)
519             gzip -cfv vmlinux > vmlinuz
520             mkdir -p "$DESTDIR/boot/efi/redhat"
521             install -m 755 vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/"
522             install -m 755 vmlinuz "$DESTDIR/boot/efi/redhat/vmlinuz-${FULL_VERSION}"
523             ln -sf "../../../lib/modules/${FULL_VERSION}/vmlinux" "$DESTDIR/boot/efi/redhat/vmlinux-${FULL_VERSION}"
524             ln -sf "efi/redhat/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
525             ln -sf "efi/redhat/vmlinuz-${FULL_VERSION}" "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
526             ;;
527         *)
528             cp vmlinuz "$DESTDIR/boot/vmlinuz-${FULL_VERSION}"
529             cp vmlinux "$DESTDIR/lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}"
530             ln -sf "../lib/modules/${FULL_VERSION}/vmlinux-${FULL_VERSION}" "$DESTDIR/boot/vmlinux-${FULL_VERSION}"
531
532             ;;
533     esac
534     if [ -e init/kerntypes.o ] ; then
535         cp init/kerntypes.o "$DESTDIR/boot/Kerntypes-${FULL_VERSION}"
536     fi
537
538     popd >/dev/null
539 }
540
541 cleanup_libmodules()
542 {
543     (( $INSTALL_LUSTRE )) || return 0
544
545     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
546     KVERREL="${VERSION}-${EXTRA_VERSION}"
547     i="$DESTDIR/lib/modules/${FULL_VERSION}"
548
549     rm -f $i/build
550     rm -f $i/source
551
552     if (( $LINUX26 )) ; then
553         ln -sf ../../../usr/src/linux-${KVERREL}-obj/${TARGET_ARCH}/${TARGET_CONFIG} $i/build
554         ln -sf ../../../usr/src/linux-${KVERREL} $i/source
555     else
556         ln -sf ../../../usr/src/linux-${KVERREL} $i/build
557     fi
558 }
559
560 install_lustre()
561 {
562     (( $INSTALL_LUSTRE )) || return 0
563     return 0
564     set_make
565     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
566     pushd "$TOPDIR" >/dev/null
567     $MAKE "$MAKE_CC" -s install "DESTDIR=$DESTDIR" KERNELRELEASE="$FULL_VERSION" || fatal 1 "Error installing Lustre."
568     popd >/dev/null
569 }
570
571 build_kms()
572 {
573     (( $BUILD_KERNEL )) || return 0
574     (( $SUSEBUILD )) || return 0
575     set_make
576     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
577     mkdir -p "${TOPDIR}/modules-${FULL_VERSION}"
578     for dir in /usr/src/kernel-modules/* ; do
579         # we are replacing lustre-lite, so don't include it
580         if [ "${dir##*/}" != "lustre-lite" -a -e $dir/Makefile ]; then
581             build_dir="${TOPDIR}/modules-${FULL_VERSION}/${dir##*/}"
582             cp -a $dir $build_dir
583             # these modules are terrible, and don't all build
584             $MAKE_J "$MAKE_CC" -C $build_dir modules KERNEL_SOURCE="${TOPDIR}/linux"
585         fi
586     done
587 }
588
589 symver()
590 {
591     local file=$1 name=${1%.ko}
592     nm $file \
593     | sed -ne 's,^0*\([0-9a-f]\{8\}\) A __crc_\(.*\),0x\1\t\2\t'"$name"',p'
594 }
595
596 install_kms()
597 {
598     (( $INSTALL_KERNEL )) || return 0
599     (( $LINUX26 )) || return 0
600     set_make
601     FULL_VERSION="${VERSION}-${EXTRA_VERSION}${TARGET_CONFIG}"
602     for build_dir in "${TOPDIR}/modules-${FULL_VERSION}/*" ; do
603         [ -d $build_dir ] || continue
604         # these modules are terrible, and don't all build
605         $MAKE "$MAKE_CC" -C $build_dir KERNEL_SOURCE="${TOPDIR}/linux" INSTALL_MOD_PATH="$DESTDIR" 
606     done
607     (   symver vmlinux
608         moddir="${DESTDIR}/lib/modules/${FULL_VERSION}"
609         cd $moddir/kernel
610         for module in $(find * -name '*.ko'); do
611             symver $module
612         done
613         cd $moddir
614         for module in $(find * -path 'kernel/*' -prune -o \
615                            -name '*.ko' -print); do
616             symver $module
617         done
618     ) | sort -u -k2 \
619         | gzip -c9 > "${DESTDIR}/boot/symvers-${VERSION}-${EXTRA_VERSION}-${TARGET_ARCH}${TARGET_CONFIG}.gz"
620 }
621
622 save_headers()
623 {
624     (( $SAVE_HEADERS )) || return 0
625
626     echo "Saving headers for ${TARGET_CONFIG:-up} ${TARGET_ARCH}..."
627     pushd linux >/dev/null
628
629     KVERREL="${VERSION}-${EXTRA_VERSION}"
630     # deal with the kernel headers that are version specific
631     
632     saveddir="$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/${TARGET_ARCH}/${TARGET_CONFIG:-up}"
633     mkdir -p "$saveddir"
634     install -m 644 include/linux/autoconf.h "$saveddir/autoconf.h"
635     install -m 644 include/linux/version.h  "$saveddir/version.h"
636     mv include/linux/modules "$saveddir/"
637     echo ${TARGET_ARCH} ${TARGET_CONFIG} ../../savedheaders/${TARGET_ARCH}/${TARGET_CONFIG:-up}/ \
638         >>  "$RPM_BUILD_ROOT/usr/src/linux-${KVERREL}/savedheaders/list"
639     popd >/dev/null
640 }
641
642 save_all_headers()
643 {
644     (( $SAVE_HEADERS )) || return 0
645
646     for arch in $BIGMEM_ARCHS ; do
647         save_headers bigmem $arch
648     done
649
650     for arch in $BOOT_ARCHS ; do
651         save_headers BOOT $arch
652     done
653
654     for arch in $JENSEN_ARCHS ; do
655         save_headers jensen $arch
656     done
657
658     for arch in $SMP_ARCHS ; do
659         save_headers smp $arch
660     done
661
662     for arch in $BIGSMP_ARCHS ; do
663         save_headers bigsmp $arch
664     done
665     for arch in $PSERIES64_ARCHS ; do
666         save_headers pseries64 $arch
667     done
668     for arch in $UP_ARCHS ; do
669         save_headers up $arch
670     done
671 }
672
673 longopts="build,build-lustre,build-kernel,depend-kernel,destdir:,extraversion:"
674 longopts="$longopts,help,install,install-lustre,install-kernel,kerneldir:"
675 longopts="$longopts,save-headers,target:,target-arch:,target-config:,unpack-kernel"
676
677 options=$(getopt -o hj: -l "$longopts" -- "$@")
678
679 eval set -- "$options"
680     
681 while [ "$1" ] ; do
682     case "$1" in
683         '')
684             usage 1
685             ;;
686         --build)
687             BUILD_LUSTRE=1
688             BUILD_KERNEL=1
689             DEPEND_KERNEL=1
690             UNPACK_KERNEL=1
691             shift
692             ;;
693         --build-lustre)
694             BUILD_LUSTRE=1
695             shift
696             ;;
697         --build-kernel)
698             BUILD_KERNEL=1
699             DEPEND_KERNEL=1
700             shift
701             ;;
702         --depend-kernel)
703             DEPEND_KERNEL=1
704             shift
705             ;;
706         --destdir)
707             DESTDIR=$2
708             shift 2
709             ;;
710         --extraversion)
711             EXTRA_VERSION=$2
712             shift 2
713             ;;
714         --help | -h)
715             usage 0
716             ;;
717         --install)
718             INSTALL_LUSTRE=1
719             INSTALL_KERNEL=1
720             shift
721             ;;
722         --install-lustre)
723             INSTALL_LUSTRE=1
724             shift
725             ;;
726         --install-kernel)
727             INSTALL_KERNEL=1
728             shift
729             ;;
730         -j)
731             JOBS=$2
732             shift 2
733             ;;
734         --kerneldir)
735             KERNELDIR=$2
736             shift 2
737             ;;
738         --save-headers)
739             SAVE_HEADERS=1
740             shift
741             ;;
742         --target)
743             TARGET=$2
744             shift 2
745             ;;
746         --target-arch)
747             TARGET_ARCH=$2
748             shift 2
749             ;;
750         --target-config)
751             TARGET_CONFIG=$2
752             shift 2
753             ;;
754         --unpack-kernel)
755             UNPACK_KERNEL=1
756             shift
757             ;;
758         --)
759             shift
760             CONFIGURE_FLAGS=$@
761             break
762             ;; 
763         *)
764             usage 1 "Unrecognized option: $1"
765             ;;
766     esac
767 done
768
769 check_options
770 load_target
771
772 extract_kernel
773 patch_kernel
774
775 depend_kernel
776 build_kernel
777
778 configure_lustre
779 build_lustre
780
781 build_kms
782
783 install_kernel
784 install_lustre
785
786 install_kms
787
788 cleanup_libmodules
789
790 save_headers
791
792 exit 0