Keep unnecessary programs from installing into kerncache
[catalyst.git] / targets / support / kmerge.sh
1 #!/bin/bash
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 source /tmp/chroot-functions.sh
6
7 check_genkernel_version
8
9 PKGDIR=/usr/portage/packages/gk_binaries/${clst_kname}/ebuilds
10
11 setup_gk_args() {
12         # default genkernel args
13         GK_ARGS="${clst_gk_mainargs} \
14                          ${clst_kernel_gk_kernargs} \
15                          --cachedir=/usr/portage/packages/gk_binaries/${clst_kname}-genkernel_cache-${clst_version_stamp} \
16                          --no-mountboot \
17                          --no-install \
18                          --kerneldir=/usr/src/linux \
19                          --kernel-config=/var/tmp/${clst_kname}.config \
20                          --modulespackage=/usr/portage/packages/gk_binaries/${clst_kname}-modules-${clst_version_stamp}.tar.bz2 \
21                          --minkernpackage=/usr/portage/packages/gk_binaries/${clst_kname}-kernel-initrd-${clst_version_stamp}.tar.bz2 \
22                          --kerncache=/usr/portage/packages/gk_binaries/${clst_kname}-kerncache-${clst_version_stamp}.tar.bz2 all"
23         # extra genkernel options that we have to test for
24         if [ "${clst_splash_type}" == "bootsplash" -a -n "${clst_splash_theme}" ]
25         then
26                 GK_ARGS="${GK_ARGS} --bootsplash=${clst_splash_theme}"
27         fi
28         
29         if [ "${clst_splash_type}" == "gensplash" -a -n "${clst_splash_theme}" ]
30         then
31                 GK_ARGS="${GK_ARGS} --gensplash=${clst_splash_theme}"
32         fi
33
34         if [ -d "${clst_initramfs_overlay}" ]
35         then
36                 GK_ARGS="${GK_ARGS} --initramfs-overlay=/tmp/initramfs_overlay/${clst_initramfs_overlay}"
37         fi
38         if [ -n "${clst_CCACHE}" ]
39         then
40                 GK_ARGS="${GK_ARGS} --kernel-cc=/usr/lib/ccache/bin/gcc --utils-cc=/usr/lib/ccache/bin/gcc"
41         fi
42         
43         if [ "${clst_devmanager}" == "devfs" ]
44         then
45                 GK_ARGS="${GK_ARGS} --no-udev"
46         fi
47
48         if [ -n "${clst_linuxrc}" ]
49         then
50                 GK_ARGS="${GK_ARGS} --linuxrc=/tmp/linuxrc"
51         fi
52 }
53
54 genkernel_compile(){
55         
56         eval "clst_initramfs_overlay=\$clst_boot_kernel_${clst_kname}_initramfs_overlay"
57         eval "clst_kernel_merge=\$clst_boot_kernel_${clst_kname}_packages"
58         
59         setup_gk_args
60         #echo "The GK_ARGS are"
61         #echo ${GK_ARGS}        
62         export clst_kernel_merge
63         export clst_initramfs_overlay
64         # build with genkernel using the set options
65         # callback is put here to avoid escaping issues
66         if [ -n "${clst_KERNCACHE}" ]
67         then
68                 if [ "$clst_kernel_merge" != "" ]
69                 then
70                         genkernel --callback="PKGDIR=${PKGDIR} emerge -kb ${clst_kernel_merge}" \
71                                         ${GK_ARGS} || exit 1
72                 else
73                         genkernel ${GK_ARGS} || exit 1
74                 fi
75         else
76                 if [ "$clst_kernel_merge" != "" ]
77                 then
78                         genkernel --callback="emerge ${clst_kernel_merge}" \
79                                 ${GK_ARGS} || exit 1
80                         if [ "${clst_livecd_type}" = "gentoo-release-livecd" ]
81                         then
82                                 mkdir -p /usr/livecd
83                                 echo "${clst_kernel_merge}" > /usr/livecd/kernelpkgs.txt
84                         fi
85                 else
86                         genkernel ${GK_ARGS} || exit 1
87                 fi
88         fi
89         md5sum /var/tmp/${clst_kname}.config|awk '{print $1}' > /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG
90 }
91
92 build_kernel() {
93         genkernel_compile
94 }
95
96
97
98 # Script to build each kernel, kernel-related packages
99 /usr/sbin/env-update
100 source /etc/profile
101
102 setup_myfeatures
103 setup_myemergeopts
104
105 [ -n "${clst_ENVSCRIPT}" ] && source /tmp/envscript
106 export CONFIG_PROTECT="-*"
107
108 #set the timezone for the kernel build
109 rm /etc/localtime
110 ln -s /usr/share/zoneinfo/UTC /etc/localtime
111
112 eval "clst_kernel_use=\$clst_boot_kernel_${clst_kname}_use"
113 export USE=$clst_kernel_use
114
115 eval "clst_kernel_gk_kernargs=\$clst_boot_kernel_${clst_kname}_gk_kernargs"
116 eval "clst_ksource=\$clst_boot_kernel_${clst_kname}_sources"
117
118
119
120 # Don't use pkgcache here, as the kernel source may get emerge with different USE variables
121 # (and thus different patches enabled/disabled.) Also, there's no real benefit in using the
122 # pkgcache for kernel source ebuilds.
123
124 USE_MATCH=0 
125 if [ -e /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE ]
126 then
127
128         STR1=$(for i in `cat /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE`; do echo $i; done|sort)
129         STR2=$(for i in ${clst_kernel_use}; do echo $i; done|sort)
130         if [ "${STR1}" = "${STR2}" ]
131         then 
132                 #echo "USE Flags match"
133                 USE_MATCH=1 
134         else
135             if [ -n "${clst_KERNCACHE}" ]
136             then
137                 [ -d /usr/portage/packages/gk_binaries/${clst_kname}/ebuilds ] && \
138                         rm -r /usr/portage/packages/gk_binaries/${clst_kname}/ebuilds
139                 [ -e /usr/portage/packages/gk_binaries/${clst_kname}/usr/src/linux/.config ] && \
140                         rm /usr/portage/packages/gk_binaries/${clst_kname}/usr/src/linux/.config
141             fi
142         fi
143 fi
144
145 EXTRAVERSION_MATCH=0
146 if [ -e /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION ]
147 then
148         STR1=`cat /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION`
149         STR2=${clst_kextraversion}
150         if [ "${STR1}" = "${STR2}" ]
151         then 
152                 if [ -n "${clst_KERNCACHE}" ]
153                 then
154                         #echo "EXTRAVERSION match"
155                         EXTRAVERSION_MATCH=1
156                 fi
157         fi
158 fi
159
160 CONFIG_MATCH=0
161 if [ -e /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG ]
162 then
163         STR1=`cat /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.CONFIG`
164         STR2=`md5sum /var/tmp/${clst_kname}.config|awk '{print $1}'`
165         if [ "${STR1}" = "${STR2}" ]
166         then 
167                 if [ -n "${clst_KERNCACHE}" ]
168                 then
169                         #echo "CONFIG match"
170                         CONFIG_MATCH=1
171                 fi
172
173         fi
174 fi
175
176 if [ "${USE_MATCH}" = "0" -o "${EXTRAVERSION_MATCH}" = "0" -o "${CONFIG_MATCH}" = "0" ]
177 then
178         echo "Cleaning up ${clst_kname} kernel install ..."
179         echo "This may take some time ..."
180         if [ -d /usr/portage/packages/gk_binaries/${clst_kname}/ ] 
181         then
182                 rm -r /usr/portage/packages/gk_binaries/${clst_kname}/ || exit 1
183         fi
184 fi
185
186 mkdir -p /usr/portage/packages/gk_binaries/${clst_kname}
187         
188 if [ -n "${clst_KERNCACHE}" ]
189 then
190         ROOT=/usr/portage/packages/gk_binaries/${clst_kname} PKGDIR=${PKGDIR} USE="${USE} symlink build" emerge --nodeps -ukb  "${clst_ksource}" || exit 1
191         KERNELVERSION=`/usr/lib/portage/bin/portageq best_visible / "${clst_ksource}"`
192         if [ ! -e /etc/portage/profile/package.provided ]
193         then
194                 mkdir -p /etc/portage/profile
195                 echo "${KERNELVERSION}" > /etc/portage/profile/package.provided
196         else
197                 if ( ! grep -q "^${KERNELVERSION}"  /etc/portage/profile/package.provided ) 
198                 then
199                         echo "${KERNELVERSION}" >> /etc/portage/profile/package.provided
200                 fi
201         fi
202         [ -d /usr/src/linux ] && rm /usr/src/linux
203         ln -s /usr/portage/packages/gk_binaries/${clst_kname}/usr/src/linux /usr/src/linux
204 else
205         USE="${USE} symlink build" emerge "${clst_ksource}" || exit 1
206 fi
207
208 #if catalyst has set to a empty string, extraversion wasn't specified so we skip this part
209 if [ "${EXTRAVERSION_MATCH}" != "1" ]
210 then
211     if [ "${clst_kextraversion}" != "" ]
212     then
213         echo "Setting extraversion to ${clst_kextraversion}"
214         sed -i -e "s:EXTRAVERSION \(=.*\):EXTRAVERSION \1-${clst_kextraversion}:" /usr/src/linux/Makefile
215         echo ${clst_kextraversion} > /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION
216     else 
217         touch /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.EXTRAVERSION
218     fi
219 fi
220         
221
222 build_kernel
223 # grep out the kernel version so that we can do our modules magic
224 VER=`grep ^VERSION\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
225 PAT=`grep ^PATCHLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
226 SUB=`grep ^SUBLEVEL\ \= /usr/src/linux/Makefile | awk '{ print $3 };'`
227 EXV=`grep ^EXTRAVERSION\ \= /usr/src/linux/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g"`
228 clst_fudgeuname=${VER}.${PAT}.${SUB}${EXV}
229
230 /sbin/modules-update --assume-kernel=${clst_fudgeuname}
231
232 unset USE
233 echo ${clst_kernel_use} > /usr/portage/packages/gk_binaries/${clst_kname}/${clst_kname}-${clst_version_stamp}.USE