updated on Thu Jan 26 12:02:26 UTC 2012
[aur-mirror.git] / kernel26-rt-ice / PKGBUILD
blob8c8ade5a567bee7d6afee6428253027adf99d5a9
1 # Almost wholly taken from kernel26-ice by Giuseppe Calderaro
2 # Maintainer: Ng Oon-Ee <ngoonee.talk@gmail.com>
3 # Source Contributor: Giuseppe Calderaro <giuseppecalderaro@gmail.com>
5 pkgdesc="The Linux Kernel and modules with tuxonice support and rt-patchset"
6 depends=('coreutils' 'linux-firmware' 'module-init-tools' 'mkinitcpio>=0.5.20')
7 optdepends=('crda: to set the correct wireless channels of your country')
8 pkgname=kernel26-rt-ice
9 backup=(etc/mkinitcpio.d/$pkgname.preset)
10 _kernelname=${pkgname#kernel26}
11 _basekernel=2.6.33
12 _minor_patch=9
13 pkgver=${_basekernel}
14 pkgrel=18
15 install=$pkgname.install
16 makedepends=('xmlto' 'docbook-xsl')
17 arch=(i686 x86_64)
18 license=('GPL2')
19 url="https://rt.wiki.kernel.org"
21 ### User/Environment defined variables
22 _skip_minor_patch=${_skip_minor_patch:-0}
23 enable_toi=${enable_toi:-1}
24 bfs_scheduler=${bfs_scheduler:-0}
25 keep_source_code=${keep_source_code:-0}
26 gconfig=${gconfig:-0}
27 xconfig=${xconfig:-0}
28 menuconfig=${menuconfig:-0}
29 realtime_patch=${realtime_patch:-1}
30 local_patch_dir="${local_patch_dir:-}"
31 use_config="${use_config:-}"
32 use_config_gz=${use_config_gz:-0}
33 enable_reiser4=${enable_reiser4:-0}
34 ### Compile time defined variables
35 ###
37 ### Files / Versions
38 file_rt="patch-2.6.33.9-rt31.bz2"
39 file_reiser4="reiser4-for-2.6.33.patch.bz2"
40 file_toi="tuxonice-3.2-for-2.6.33.patch.bz2"
41 file_bfs="2.6.33.7-sched-bfs-318.patch"
42 ###
44 options=(!strip)
45 source=(http://kernel.org/pub/linux/kernel/v2.6/linux-${_basekernel}.tar.bz2
46         http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.33/patch-${_basekernel}.${_minor_patch}.bz2
47         http://www.kernel.org/pub/linux/kernel/projects/rt/${file_rt}
48         http://www.kernel.org/pub/linux/kernel/people/edward/reiser4/reiser4-for-2.6/${file_reiser4}
49         http://www.tuxonice.net/files/${file_toi}
50         http://ck.kolivas.org/patches/bfs/${_basekernel}/${file_bfs}
51         kernel26-member-page.patch
52         config config.x86_64
53         $pkgname.preset)
54 md5sums=('c3883760b18d50e8d78819c54d579b00'
55          'f6801744832f9cc7c7993fa2265e86c3'
56          '110380e5eeb2fbc019c7232037dc522c'
57          '49da31ea1e6c3ae65f954cd5fc8fcc4e'
58          '4d00f21b71dd195afa00c07a3b4cbfa7'
59          'c358419edc76f33a2623fa8ce80efe16'
60          '0ecef4f750421203a9e4453d1694fd9d'
61          '3194718676dd2759f71d4dd2586af89f'
62          '5c21cbbc34d677dae8c9a5171e1b9663'
63          'b54202c40593240256f40562d6f3aee2')
65 build() {
66   cd ${srcdir}/linux-$_basekernel
68   # Patching for compilation with gcc-4.6 and above (thanks beroal)
69   patch -Np1 -i ${srcdir}/kernel26-member-page.patch
71   # Applying official patch
72   if [ "$_minor_patch" != "0" ] && [ "$_skip_minor_patch" != "1" ] ; then
73     echo "Applying patch-${_basekernel}.${_minor_patch}.bz2"
74     patch -Np1 -i ${srcdir}/patch-${_basekernel}.${_minor_patch} || { echo Failed patch-${_basekernel}.${_minor_patch}.bz2 ; return 1 ; }
75   fi
77   if [ -n "${local_patch_dir}" ] && [ -d "${local_patch_dir}" ] ; then
78     echo "Applying patches from ${local_patch_dir} ..."
79     for my_patch in "${local_patch_dir}"/* ; do
80       echo -e "Applying custom patch:\t'${my_patch}'" || true
81       patch -Np1 -i "${my_patch}" || { echo -e "Failed custom patch:\t'${my_patch}'" ; return 1 ; }
82     done
83   fi
85   # Applying realtime patch
86   if [ "$realtime_patch" = "1" ]; then
87     echo "Applying real time patch"
88     # Strip './Makefile' changes
89     bzip2 -dkc ${srcdir}/${file_rt} \
90       | sed '/diff --git a\/Makefile b\/Makefile/,/*DOCUMENTATION*/d' \
91       | patch -Np1 || { echo "Failed Realtime patch '${file_rt}'"; return 1 ; }
92   fi
94   # applying reiserfs4 patch
95   if [ "$enable_reiser4" = "1" ]; then
96     echo "Applying ${file_reiser4%.gz}"
97     bzip2 -dc ${srcdir}/${file_reiser4} | patch -Np1 || { echo "Failed reiser4 patch '${file_reiser4%.gz}'"; return 1 ; }
98   fi
100   # applying tuxonice patch
101   if [ "${enable_toi}" = "1" ]; then
102     echo "Applying ${file_toi%.bz2}"
103     # fix to tuxonice patch to work with rt
104     if [ "$realtime_patch" = "1" ]; then
105       bzip2 -dck ${srcdir}/${file_toi} \
106         | sed '/diff --git a\/kernel\/fork.c b\/kernel\/fork.c/,/{/d' \
107         | sed 's/printk(KERN_INFO "PM: Creating hibernation image:\\n/printk(KERN_INFO "PM: Creating hibernation image: \\n/' \
108         | patch -Np1 || { echo "Failed TOI w/rt" ; return 1 ; }
109     else
110       bzip2 -dck ${srcdir}/${file_toi} \
111         | sed 's/printk(KERN_INFO "PM: Creating hibernation image:\\n/printk(KERN_INFO "PM: Creating hibernation image: \\n/' \
112         | patch -Np1 -F4 || { echo "Failed TOI"; return 1 ; }
113     fi
114   fi
116   if [ "${bfs_scheduler}" = "1" ] && [ "${realtime_patch}" = "0" ]; then
117     # applying BFS scheduler patch
118     echo "Applying BFS scheduler patch"
119     patch -Np1 -i ${srcdir}/${file_bfs} || { echo "Failed BFS"; return 1 ; }
120     patch -Np1 -i ${srcdir}/${file_bfs_b} || { echo "Failed BFS (file 2)"; return 1 ; }
121     #Applying quick-fix 2.6.37.1 patch for bfs/ck
122     patch -Np1 -i ${srcdir}/2.6.37.1-fix-no-more-unsigned.patch
123   fi
125   # remove extraversion
126   sed -i 's|^EXTRAVERSION = .*$|EXTRAVERSION =|g' Makefile
127   
128   # load configuration for i686 or x86_64
129   if [ "$CARCH" = "x86_64" ]; then
130     cat ../config.x86_64 >./.config
131   else
132     cat ../config >./.config
133   fi
135   # use custom config instead
136   if [ -n "${use_config}" ] ; then
137     echo "Using config: '${use_config}'"
138     cat "${use_config}" > ./.config
139     make oldconfig
140   fi
142   # use existing config.gz
143   if [ "$use_config_gz" = "1" ]; then
144     zcat /proc/config.gz > ./.config
145     make oldconfig
146   fi
147   if [ "${_kernelname}" != "" ]; then
148     sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"${_kernelname}\"|g" ./.config
149   fi
151   # hack to prevent output kernel from being marked as dirty or git
152   chmod +x ${srcdir}/linux-${_basekernel}/scripts/setlocalversion
153   sed 's/head=`git rev-parse --verify --short HEAD 2>\/dev\/null`/0/' \
154     ${srcdir}/linux-${_basekernel}/scripts/setlocalversion \
155     > ${srcdir}/linux-${_basekernel}/scripts/setlocalversion.new
156   mv ${srcdir}/linux-${_basekernel}/scripts/setlocalversion.new \
157     ${srcdir}/linux-${_basekernel}/scripts/setlocalversion
159   make prepare
160   # load configuration
161   # Configure the kernel. Replace the line below with one of your choice.
162   if [ "$gconfig" = "1" ]; then
163     make gconfig
164   else
165     if [ "$xconfig" = "1" ]; then
166       make xconfig
167     else
168       if [ "$menuconfig" = "1" ]; then
169         make menuconfig
170       fi
171     fi
172   fi
173   yes "" | make config
174   make prepare # Necessary in case config has been changed
175   # build!
176   make ${MAKEFLAGS} bzImage modules
179 package_kernel26-rt-ice() {
181   KARCH=x86
182   cd ${srcdir}/linux-$_basekernel
183   if [ "$keep_source_code" = "1" ]; then
184     echo -n "Copying source code..."
185     # Keep the source code
186     cd $startdir
187     mkdir -p $pkgdir/usr/src || return 1
188     cp -a ${srcdir}/linux-${_basekernel} $pkgdir/usr/src/linux-${_kernver} || return 1
190     #Add a link from the modules directory
191     mkdir -p $pkgdir/lib/modules/${_kernver} || return 1
192     cd $pkgdir/lib/modules/${_kernver} || return 1
193     rm -f source
194     ln -s ../../../usr/src/linux-${_kernver} source || return 1
195     echo "OK"
196   fi
197    
198   # get kernel version
199   _kernver="$(make kernelrelease)"
200   mkdir -p ${pkgdir}/{lib/modules,lib/firmware,boot}
201   make INSTALL_MOD_PATH=${pkgdir} modules_install
202   cp System.map ${pkgdir}/boot/System.map26${_kernelname}
203   cp arch/$KARCH/boot/bzImage ${pkgdir}/boot/vmlinuz26${_kernelname}
204   #  # add vmlinux
205   install -m644 -D vmlinux ${pkgdir}/usr/src/linux-${_kernver}/vmlinux
207   # install fallback mkinitcpio.conf file and preset file for kernel
208   install -m644 -D ${srcdir}/${pkgname}.preset ${pkgdir}/etc/mkinitcpio.d/${pkgname}.preset
209   # set correct depmod command for install
210   sed \
211     -e  "s/KERNEL_NAME=.*/KERNEL_NAME=${_kernelname}/g" \
212     -e  "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_kernver}/g" \
213     -i $startdir/${pkgname}.install
214   sed \
215     -e "s|source .*|source /etc/mkinitcpio.d/kernel26${_kernelname}.kver|g" \
216     -e "s|default_image=.*|default_image=\"/boot/${pkgname}.img\"|g" \
217     -e "s|fallback_image=.*|fallback_image=\"/boot/${pkgname}-fallback.img\"|g" \
218     -i ${pkgdir}/etc/mkinitcpio.d/${pkgname}.preset
220   echo -e "# DO NOT EDIT THIS FILE\nALL_kver='${_kernver}'" > ${pkgdir}/etc/mkinitcpio.d/${pkgname}.kver
221   # remove build and source links
222   rm -f ${pkgdir}/lib/modules/${_kernver}/{source,build}
223   # remove the firmware
224   rm -rf ${pkgdir}/lib/firmware
225   # gzip -9 all modules to safe 100MB of space
226   find "$pkgdir" -name '*.ko' -exec gzip -9 {} \;
228   mkdir -p ${pkgdir}/lib/modules/${_kernver}
229   cd ${pkgdir}/lib/modules/${_kernver}
230   ln -sf ../../../usr/src/linux-${_kernver} build
231   cd ${srcdir}/linux-$_basekernel
232   install -D -m644 Makefile \
233     ${pkgdir}/usr/src/linux-${_kernver}/Makefile
234   install -D -m644 kernel/Makefile \
235     ${pkgdir}/usr/src/linux-${_kernver}/kernel/Makefile
236   install -D -m644 .config \
237     ${pkgdir}/usr/src/linux-${_kernver}/.config
238   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/include
240   for i in acpi asm-generic config generated linux math-emu media net pcmcia scsi sound trace video xen; do
241     cp -a include/$i ${pkgdir}/usr/src/linux-${_kernver}/include/
242   done
244   # copy arch includes for external modules
245   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/arch/x86
246   cp -a arch/x86/include ${pkgdir}/usr/src/linux-${_kernver}/arch/x86/
248   # copy files necessary for later builds, like nvidia and vmware
249   cp Module.symvers ${pkgdir}/usr/src/linux-${_kernver}
250   cp -a scripts ${pkgdir}/usr/src/linux-${_kernver}
251   # fix permissions on scripts dir
252   chmod og-w -R ${pkgdir}/usr/src/linux-${_kernver}/scripts
253   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/.tmp_versions
255   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/kernel
257   cp arch/$KARCH/Makefile ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/
258   if [ "$CARCH" = "i686" ]; then
259     cp arch/$KARCH/Makefile_32.cpu ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/
260   fi
261   cp arch/$KARCH/kernel/asm-offsets.s ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/kernel/
263   # add headers for lirc package
264   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video
265   cp drivers/media/video/*.h  ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video/
266   for i in bt8xx cpia2 cx25840 cx88 em28xx et61x251 pwc saa7134 sn9c102; do
267    mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video/$i
268    cp -a drivers/media/video/$i/*.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video/$i
269   done
270   # add docbook makefile
271   install -D -m644 Documentation/DocBook/Makefile \
272     ${pkgdir}/usr/src/linux-${_kernver}/Documentation/DocBook/Makefile
273   # add dm headers
274   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/md
275   cp drivers/md/*.h  ${pkgdir}/usr/src/linux-${_kernver}/drivers/md
276   # add inotify.h
277   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/include/linux
278   cp include/linux/inotify.h ${pkgdir}/usr/src/linux-${_kernver}/include/linux/
279   # add wireless headers
280   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/net/mac80211/
281   cp net/mac80211/*.h ${pkgdir}/usr/src/linux-${_kernver}/net/mac80211/
282   # add dvb headers for external modules
283   # in reference to:
284   # http://bugs.archlinux.org/task/9912
285   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/dvb-core
286   cp drivers/media/dvb/dvb-core/*.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/dvb-core/
287   # add dvb headers for http://mcentral.de/hg/~mrec/em28xx-new
288   # in reference to:
289   # http://bugs.archlinux.org/task/13146
290   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends/
291   cp drivers/media/dvb/frontends/lgdt330x.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends/
292   cp drivers/media/video/msp3400-driver.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends/
293   # add dvb headers  
294   # in reference to:
295   # http://bugs.archlinux.org/task/20402
296   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/dvb-usb
297   cp drivers/media/dvb/dvb-usb/*.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/dvb-usb/
298   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends
299   cp drivers/media/dvb/frontends/*.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends/
300   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/common/tuners
301   cp drivers/media/common/tuners/*.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/common/tuners/
302   # add xfs and shmem for aufs building
303   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/fs/xfs
304   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/mm
305   cp fs/xfs/xfs_sb.h ${pkgdir}/usr/src/linux-${_kernver}/fs/xfs/xfs_sb.h
306   # add headers vor virtualbox
307   # in reference to:
308   # http://bugs.archlinux.org/task/14568
309   cp -a include/drm $pkgdir/usr/src/linux-${_kernver}/include/
310   # add headers for broadcom wl
311   # in reference to:
312   # http://bugs.archlinux.org/task/14568
313   cp -a include/trace $pkgdir/usr/src/linux-${_kernver}/include/
314   # add headers for crypto modules
315   # in reference to:
316   # http://bugs.archlinux.org/task/22081
317   cp -a include/crypto $pkgdir/usr/src/linux-${_kernver}/include/
318   # copy in Kconfig files
319   for i in `find . -name "Kconfig*"`; do 
320     mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/`echo $i | sed 's|/Kconfig.*||'`
321     cp $i ${pkgdir}/usr/src/linux-${_kernver}/$i
322   done
324   chown -R root.root ${pkgdir}/usr/src/linux-${_kernver}
325   find ${pkgdir}/usr/src/linux-${_kernver} -type d -exec chmod 755 {} \;
326   # strip scripts directory
327   find ${pkgdir}/usr/src/linux-${_kernver}/scripts  -type f -perm -u+w 2>/dev/null | while read binary ; do
328   case "$(file -bi "$binary")" in
329     *application/x-sharedlib*) # Libraries (.so)
330     /usr/bin/strip $STRIP_SHARED "$binary";;
331     *application/x-archive*) # Libraries (.a)
332     /usr/bin/strip $STRIP_STATIC "$binary";;
333     *application/x-executable*) # Binaries
334     /usr/bin/strip $STRIP_BINARIES "$binary";;
335     esac 
336   done 
337   # remove unneeded architectures
338   if [ "$keep_source_code" = "0" ]; then
339     rm -rf ${pkgdir}/usr/src/linux-${_kernver}/arch/{alpha,arm,arm26,avr32,blackfin,cris,frv,h8300,ia64,m32r,m68k,m68knommu,mips,microblaze,mn10300,parisc,powerpc,ppc,s390,sh,sh64,sparc,sparc64,um,v850,xtensa}
340   fi