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