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