]> hackdaworld.org Git - hdw-linux/hdw-linux.git/blob - scripts/Make-KPkg
lirc hotfix, createdb dir added to 00-dirtree
[hdw-linux/hdw-linux.git] / scripts / Make-KPkg
1 #!/bin/bash
2 #
3 # author: hackbard@hackdaworld.dyndns.org
4 #
5 # create a kernel binary package
6 #
7
8 config=""
9 name=""
10 builddir=""
11 homedir=$PWD
12
13 while [ "$1" ] ; do
14         case "$1" in
15                 -config)        config=$2       ; shift 2 ;;
16                 -name)          name=$2         ; shift 2 ;;
17                 -dir)           builddir=$2     ; shift 2 ;;
18                 *)
19                         echo
20                         echo "usage:"
21                         echo
22                         echo "-config <kernel config file>"
23                         echo "-name <kernel name>"
24                         echo "-dir <build dir>"
25                         echo
26                         exit 1 ;;
27         esac
28 done
29
30 . ./Config
31
32 if [ "$hdw_arch" != "ia32" ] ; then
33         echo "warning: only ia32 supported by now"
34         echo "hack me ... "
35         exit 1
36 fi
37
38 [ -z "$config" ] && config="./misc/arch/${hdw_arch}/linux.config"
39 [ -z "$name" ] && name="custom-$hdw_arch"
40 [ -z "$builddir" ] && builddir="/tmp" 
41
42 if [ ! -f $config ] ; then
43         echo "$config doesn't exist, aborting ..."
44         exit 1
45 fi
46
47 if [ ! -d $builddir ] ; then
48         echo "$builddir doesn't exist, aborting ..."
49         exit 1
50 fi
51
52 kerpkg="`grep '^#\ \[D\]' ./packages/base/linux/linux | awk '{ print $3 }'`"
53 kerver="`grep '^#\ \[V\]' ./packages/base/linux/linux | awk '{ print $3 }'`"
54
55 trg=$homedir/kernel-image-${kerver}_${name}.tar.bz2
56 if [ -f $trg ] ; then
57         echo "image $trg already exists, aborting ..."
58         exit 1
59 fi
60
61 [ ! -f ./download/base/linux/$kerpkg ] && ./scripts/Download -package linux
62
63 # backing up old kernel + modules
64 kerbackup=no
65 if [ -f /boot/vmlinuz_$kerver ] ; then
66         mv /boot/vmlinuz_$kerver /boot/vmlinuz_${kerver}__orig
67         kerbackup=yes
68 fi
69 modbackup=no
70 if [ -d /lib/modules/$kerver ] ; then
71         mv /lib/modules/$kerver /lib/modules/${kerver}__orig
72         modbackup=yes
73 fi
74
75 # build kernel & modules
76 kerarch=${hdw_arch//ia32/i386}
77 cp $config $builddir/linux.config
78 rm -rf $builddir/linux-$kerver
79 tar xfj ./download/base/linux/$kerpkg -C $builddir
80 cd $builddir/linux-$kerver
81 mv ../linux.config .config
82 cd include && ln -sf asm-${kerarch} asm && cd ..
83 yes "" | make oldconfig
84 make bzImage modules modules_install
85 cp arch/$kerarch/boot/bzImage /boot/vmlinuz_$kerver
86 cp .config /boot/kernel-config-$kerver-$name
87
88 # create the package
89 cd /
90 tar --use-compress-program=bzip2 -cf $trg lib/modules/$kerver \
91         boot/vmlinuz_$kerver /boot/kernel-config-$kerver-$name
92
93 cd $homedir
94
95 # restore kernel & modules
96 rm -f /boot/vmlinuz_$kerver
97 [ "$kerbackup" = "yes" ] && \
98         mv /boot/vmlinuz_${kerver}__orig /boot/vmlinuz_$kerver
99 rm -rf /lib/modules/$kerver
100 [ "$modbackup" = "yes" ] && \
101         mv /lib/modules/${kerver}__orig /lib/modules/$kerver
102
103 echo
104 echo "done"
105 echo