Update to v3.10.2
[platform/upstream/kernel-adaptation-pc.git] / packaging / kernel-adaptation-pc.spec
1 Summary: The Linux kernel (the core of the Linux operating system)
2
3 %define tar_version 3.10.2
4 %define make_target bzImage
5 %define KVERREL %{version}-%{release}
6 %define hdrarch %_target_cpu
7 %define all_x86 i386 i586 i686 %{ix86} x86_64
8 %define _default_patch_fuzz 0
9
10 %ifarch %{all_x86}
11 %define image_install_path boot
12 %define hdrarch i386
13 %define kernel_image arch/x86/boot/bzImage
14 %endif
15
16 %ifarch x86_64
17 %define image_install_path boot
18 %define hdrarch x86_64
19 %define kernel_image arch/x86/boot/bzImage
20 %endif
21
22
23 ExclusiveArch: %{all_x86} x86_64
24
25 #
26 # Packages that need to be installed before the kernel is, because the %post
27 # scripts use them.
28 #
29 %define kernel_prereq  /usr/sbin/killall5
30
31 #
32 # This macro does requires, provides, conflicts, obsoletes for a kernel package.
33 #       %%kernel_reqprovconf <subpackage>
34 # It uses any kernel_<subpackage>_conflicts and kernel_<subpackage>_obsoletes
35 # macros defined above.
36 #
37 %define kernel_reqprovconf \
38 Provides: kernel = %{version}-%{release}\
39 Provides: kernel-uname-r = %{KVERREL}%{?1:-%{1}}\
40 #Requires(pre): %{kernel_prereq}\
41 %{?1:%{expand:%%{?kernel_%{1}_conflicts:Conflicts: %%{kernel_%{1}_conflicts}}}}\
42 %{?1:%{expand:%%{?kernel_%{1}_provides:Provides: %%{kernel_%{1}_provides}}}}\
43 # We can't let RPM do the dependencies automatic because it'll then pick up\
44 # a correct but undesirable perl dependency from the module headers which\
45 # isn't required for the kernel proper to function\
46 AutoReq: no\
47 AutoProv: yes\
48 %{nil}
49
50 Name: kernel-adaptation-pc
51
52 Group: System/Kernel
53 License: GPL-2.0
54 URL: http://www.kernel.org/
55 Version: 3.10.2
56 Release: 1
57
58 %kernel_reqprovconf
59
60 #
61 # List the packages used during the kernel build
62 #
63 BuildRequires: kmod-compat
64 BuildRequires: bc
65 BuildRequires: bash >= 2.03
66 BuildRequires: findutils
67 BuildRequires: make >= 3.78
68 BuildRequires: libelf-devel
69 BuildRequires: binutils-devel 
70 Requires(post): /usr/sbin/depmod
71 Requires(post): /usr/bin/dracut
72 Requires(post): /usr/bin/kmod
73
74 Source0: ftp://ftp.kernel.org/pub/linux/kernel/v3.0/linux-%{tar_version}.tar.bz2
75 Source10: COPYING.modules
76
77 Source100: config
78 Source101: config.x86_64
79 Source1001: kernel-adaptation-pc.manifest 
80 BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root
81
82
83 #
84 # This macro creates a kernel-<subpackage>-devel package.
85 #       %%kernel_devel_package <subpackage> <pretty-name>
86 #
87 %define kernel_devel_package() \
88 %package -n kernel-%{?1:%{1}-}devel\
89 Summary: Development package for building kernel modules to match the %{?2:%{2} }kernel\
90 Group: System/Kernel\
91 Provides: kernel%{?1:-%{1}}-devel = %{version}-%{release}\
92 Provides: kernel-devel = %{version}-%{release}%{?1:-%{1}}\
93 Provides: kernel-devel = %{version}-%{release}%{?1:-%{1}}\
94 Provides: kernel-devel-uname-r = %{KVERREL}%{?1:-%{1}}\
95 Requires: kernel%{?1:-%{1}} = %{version}-%{release}\
96 Requires: hardlink \
97 AutoReqProv: no\
98 Requires(pre): /usr/bin/find\
99 %description -n kernel%{?1:-%{1}}-devel\
100 This package provides kernel headers and makefiles sufficient to build modules\
101 against the %{?2:%{2} }kernel package.\
102 %{nil}
103
104 #
105 # This macro creates a kernel-<subpackage> and its -devel too.
106 #       %%define variant_summary The Linux kernel compiled for <configuration>
107 #       %%kernel_variant_package [-n <pretty-name>] <subpackage>
108 #
109 %define kernel_variant_package(n:) \
110 %package -n kernel-%1\
111 Summary: %{variant_summary}\
112 Group: System/Kernel\
113 %kernel_reqprovconf\
114 %{nil}
115
116
117 %define variant_summary Kernel for PC compatible systems
118 %kernel_devel_package adaptation-pc
119 %description -n kernel-adaptation-pc
120 This package contains the kernel optimized for PC compatible systems platforms
121
122
123 %prep
124 %setup -q -n linux-%{tar_version} 
125
126 chmod +x scripts/checkpatch.pl
127 cp %{SOURCE10} Documentation/
128 mkdir configs
129
130 #
131 # We want to run the config checks of all configurations for all architectures always.
132 # That way, developers immediately found out if they forget to enable not-their-native
133 # architecture. It's cheap to run anyway.
134 #
135
136 %ifarch x86_64
137   cp %{SOURCE101} .config
138   Arch="x86_64"
139 %else
140   cp %{SOURCE100} .config
141   Arch="x86"
142 %endif
143
144   make ARCH=$Arch listnewconfig &> /tmp/configs
145   export conf=`cat /tmp/configs | grep CONFIG | wc -l`
146   echo CONF is $conf
147   if [ $conf -gt 0 ]; then
148           make ARCH=$Arch listnewconfig  
149           #exit 1
150   fi
151   make ARCH=$Arch oldconfig > /dev/null
152   echo "# $Arch" > configs/%{name}.config
153   cat .config >> configs/%{name}.config
154
155 #
156 # get rid of unwanted files resulting from patch fuzz
157 # (not that we can have any)
158 #
159 find . \( -name "*.orig" -o -name "*~" \) -exec rm -f {} \; >/dev/null
160
161 cd ..
162
163 %build
164 cp %{SOURCE1001} .
165
166
167 cp_vmlinux()
168 {
169   eu-strip --remove-comment -o "$2" "$1"
170 }
171
172 BuildKernel() {
173     MakeTarget=$1
174     KernelImage=$2
175     TargetArch=$3
176     Flavour=$4
177     InstallName=${5:-vmlinuz}
178
179     # Pick the right config file for the kernel we're building
180     Config=kernel${Flavour:+-${Flavour}}.config
181     DevelDir=/usr/src/kernels/%{KVERREL}${Flavour:+-${Flavour}}
182
183     # When the bootable image is just the ELF kernel, strip it.
184     # We already copy the unstripped file into the debuginfo package.
185     if [ "$KernelImage" = vmlinux ]; then
186       CopyKernel=cp_vmlinux
187     else
188       CopyKernel=cp
189     fi
190
191     KernelVer=%{version}-%{release}${Flavour:+-${Flavour}}
192     ExtraVer=%{?rctag}-%{release}${Flavour:+-${Flavour}}
193     Arch="x86"
194 %ifarch x86_64
195    Arch="x86_64"
196 %endif
197
198
199     if [ "$Arch" = "$TargetArch" ]; then
200         echo BUILDING A KERNEL FOR ${Flavour} %{_target_cpu}... ${KernelVer}
201         echo USING ARCH=$Arch
202
203         # make sure EXTRAVERSION says what we want it to say
204         perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = ${ExtraVer}/" Makefile
205
206         # and now to start the build process
207
208         make -s mrproper
209         cp configs/$Config .config
210
211         make -s ARCH=$Arch oldconfig > /dev/null
212         make -s CONFIG_DEBUG_SECTION_MISMATCH=y ARCH=$Arch %{?_smp_mflags} $MakeTarget %{?sparse_mflags}
213         make -s CONFIG_DEBUG_SECTION_MISMATCH=y ARCH=$Arch %{?_smp_mflags} modules %{?sparse_mflags} || exit 1
214
215         # Start installing the results
216         mkdir -p %{buildroot}/%{image_install_path}
217         install -m 644 .config %{buildroot}/boot/config-$KernelVer
218         install -m 644 System.map %{buildroot}/boot/System.map-$KernelVer
219         touch %{buildroot}/boot/initramfs-$KernelVer.img
220         if [ -f arch/$Arch/boot/zImage.stub ]; then
221           cp arch/$Arch/boot/zImage.stub %{buildroot}/%{image_install_path}/zImage.stub-$KernelVer || :
222         fi
223         $CopyKernel $KernelImage \
224                         %{buildroot}/%{image_install_path}/$InstallName-$KernelVer
225         chmod 755 %{buildroot}/%{image_install_path}/$InstallName-$KernelVer
226         ln -sf $InstallName-$KernelVer \
227             %{buildroot}/%{image_install_path}/vmlinuz
228
229         mkdir -p %{buildroot}/usr/lib/modules/$KernelVer
230         make -s ARCH=$Arch INSTALL_MOD_PATH=%{buildroot}/usr modules_install KERNELRELEASE=$KernelVer
231         # And save the headers/makefiles etc for building modules against
232         #
233         # This all looks scary, but the end result is supposed to be:
234         # * all arch relevant include/ files
235         # * all Makefile/Kconfig files
236         # * all script/ files
237
238         rm -f %{buildroot}/usr/lib/modules/$KernelVer/build
239         rm -f %{buildroot}/usr/lib/modules/$KernelVer/source
240         mkdir -p %{buildroot}/usr/lib/modules/$KernelVer/build
241         (cd %{buildroot}/usr/lib/modules/$KernelVer ; ln -s build source)
242         # dirs for additional modules per module-init-tools, kbuild/modules.txt
243         # first copy everything
244         cp --parents `find  -type f -name "Makefile*" -o -name "Kconfig*"` %{buildroot}/usr/lib/modules/$KernelVer/build
245         cp Module.symvers %{buildroot}/usr/lib/modules/$KernelVer/build
246         cp System.map %{buildroot}/usr/lib/modules/$KernelVer/build
247         if [ -s Module.markers ]; then
248           cp Module.markers %{buildroot}/usr/lib/modules/$KernelVer/build
249         fi
250         # then drop all but the needed Makefiles/Kconfig files
251         rm -rf %{buildroot}/usr/lib/modules/$KernelVer/build/Documentation
252         rm -rf %{buildroot}/usr/lib/modules/$KernelVer/build/scripts
253         rm -rf %{buildroot}/usr/lib/modules/$KernelVer/build/include
254         cp .config %{buildroot}/usr/lib/modules/$KernelVer/build
255         cp -a scripts %{buildroot}/usr/lib/modules/$KernelVer/build
256         if [ -d arch/%{_arch}/scripts ]; then
257           cp -a arch/%{_arch}/scripts %{buildroot}/usr/lib/modules/$KernelVer/build/arch/%{_arch} || :
258         fi
259         if [ -f arch/%{_arch}/*lds ]; then
260           cp -a arch/%{_arch}/*lds %{buildroot}/usr/lib/modules/$KernelVer/build/arch/%{_arch}/ || :
261         fi
262         rm -f %{buildroot}/usr/lib/modules/$KernelVer/build/scripts/*.o
263         rm -f %{buildroot}/usr/lib/modules/$KernelVer/build/scripts/*/*.o
264         cp -a --parents arch/x86/include %{buildroot}/usr/lib/modules/$KernelVer/build
265         mkdir -p %{buildroot}/usr/lib/modules/$KernelVer/build/include
266         cd include
267         cp -a acpi asm-generic config crypto drm generated keys linux math-emu media net pcmcia rdma rxrpc scsi sound video trace %{buildroot}/usr/lib/modules/$KernelVer/build/include
268
269         # Make sure the Makefile and version.h have a matching timestamp so that
270         # external modules can be built
271         touch -r %{buildroot}/usr/lib/modules/$KernelVer/build/Makefile %{buildroot}/usr/lib/modules/$KernelVer/build/include/linux/version.h
272         touch -r %{buildroot}/usr/lib/modules/$KernelVer/build/.config %{buildroot}/usr/lib/modules/$KernelVer/build/include/linux/autoconf.h
273         # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
274         cp %{buildroot}/usr/lib/modules/$KernelVer/build/.config %{buildroot}/usr/lib/modules/$KernelVer/build/include/config/auto.conf
275         cd ..
276
277         #
278         # save the vmlinux file for kernel debugging into the kernel-*-devel rpm
279         #
280
281         cp vmlinux %{buildroot}/usr/lib/modules/$KernelVer
282
283         find %{buildroot}/usr/lib/modules/$KernelVer -name "*.ko" -type f >modnames
284
285         # mark modules executable so that strip-to-file can strip them
286         xargs --no-run-if-empty chmod u+x < modnames
287
288         # Generate a list of modules for block and networking.
289
290         fgrep /drivers/ modnames | xargs --no-run-if-empty nm -upA |
291         sed -n 's,^.*/\([^/]*\.ko\):  *U \(.*\)$,\1 \2,p' > drivers.undef
292
293         collect_modules_list()
294         {
295           sed -r -n -e "s/^([^ ]+) \\.?($2)\$/\\1/p" drivers.undef |
296           LC_ALL=C sort -u > %{buildroot}/usr/lib/modules/$KernelVer/modules.$1
297         }
298
299         collect_modules_list networking \
300                                  'register_netdev|ieee80211_register_hw|usbnet_probe'
301         collect_modules_list block \
302                                  'ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans'
303
304         # remove files that will be auto generated by depmod at rpm -i time
305         for i in alias ccwmap dep ieee1394map inputmap isapnpmap ofmap pcimap seriomap symbols usbmap
306         do
307           rm -f %{buildroot}/usr/lib/modules/$KernelVer/modules.$i
308         done
309
310         # Move the devel headers out of the root file system
311         mkdir -p %{buildroot}/usr/src/kernels
312         mv %{buildroot}/usr/lib/modules/$KernelVer/build %{buildroot}/$DevelDir
313         ln -sf $DevelDir %{buildroot}/usr/lib/modules/$KernelVer/build
314     fi
315 }
316
317 ###
318 # DO it...
319 ###
320
321 # prepare directories
322 rm -rf %{buildroot}
323 mkdir -p %{buildroot}/boot
324
325
326 %ifarch x86_64
327 BuildKernel %make_target %kernel_image x86_64 adaptation-pc
328 %else
329 BuildKernel %make_target %kernel_image x86 adaptation-pc
330 %endif
331
332 ###
333 ### install
334 ###
335
336 %define install  %{?_enable_debug_packages:%{?buildsubdir:%{debug_package}}}\
337 %%install
338
339
340 %install
341
342 rm -rf %{buildroot}/usr/lib/firmware
343
344
345 ###
346 ### clean
347 ###
348
349 %clean
350 rm -rf %{buildroot}
351
352 ###
353 ### scripts
354 ###
355
356 #
357 # This macro defines a %%post script for a kernel*-devel package.
358 #       %%kernel_devel_post <subpackage>
359 #
360 %define kernel_devel_post() \
361 %{expand:%%post -n kernel-%{?1:%{1}-}devel}\
362 if [ -x /usr/sbin/hardlink ]\
363 then\
364     (cd /usr/src/kernels/%{KVERREL}%{?1:-%{1}} &&\
365      /usr/bin/find . -type f | while read f; do\
366        hardlink -c /usr/src/kernels/*/$f $f\
367      done)\
368 fi\
369 %{nil}
370
371 # This macro defines a %%posttrans script for a kernel package.
372 #       %%kernel_variant_posttrans [-v <subpackage>] [-s <s> -r <r>] <mkinitrd-args>
373 # More text can follow to go at the end of this variant's %%post.
374 #
375 %define kernel_variant_posttrans(s:r:v:) \
376 %{expand:%%posttrans -n kernel-%{?-v*}}\
377 %{nil}
378
379 #
380 # This macro defines a %%post script for a kernel package and its devel package.
381 #       %%kernel_variant_post [-v <subpackage>] [-s <s> -r <r>] <mkinitrd-args>
382 # More text can follow to go at the end of this variant's %%post.
383 #
384 %define kernel_variant_post(s:r:v:) \
385 %{expand:%%kernel_devel_post %{?-v*}}\
386 %{expand:%%kernel_variant_posttrans %{?-v*}}\
387 %{expand:%%post -n kernel-%{?-v*}}\
388 /sbin/depmod -a %{KVERREL}-%{?-v*}\
389 /usr/bin/dracut /boot/initramfs-%{KVERREL}-%{?-v*}.img %{KVERREL}-%{?-v*}\
390 %{nil}
391
392 #
393 # This macro defines a %%preun script for a kernel package.
394 #       %%kernel_variant_preun <subpackage>
395 #
396 %define kernel_variant_preun() \
397 %{expand:%%preun -n kernel-%{?1}}\
398 %{nil}
399
400
401 %ifarch %all_x86
402
403 %kernel_variant_preun adaptation-pc
404 %kernel_variant_post -v adaptation-pc
405
406 %endif
407
408
409 ###
410 ### file lists
411 ###
412
413
414
415 #
416 # This macro defines the %%files sections for a kernel package
417 # and its devel packages.
418 #       %%kernel_variant_files [-k vmlinux] [-a <extra-files-glob>] [-e <extra-nonbinary>] <condition> <subpackage>
419 #
420 %define kernel_variant_files(a:e:k:) \
421 %ifarch %{1}\
422 %{expand:%%files -n kernel%{?2:-%{2}}}\
423 %defattr(-,root,root)\
424 /%{image_install_path}/%{?-k:%{-k*}}%{!?-k:vmlinuz}-%{KVERREL}%{?2:-%{2}}\
425 /boot/vmlinuz\
426 /boot/System.map-%{KVERREL}%{?2:-%{2}}\
427 #/boot/symvers-%{KVERREL}%{?2:-%{2}}.gz\
428 /boot/config-%{KVERREL}%{?2:-%{2}}\
429 %{?-a:%{-a*}}\
430 %dir /usr/lib/modules/%{KVERREL}%{?2:-%{2}}\
431 /usr/lib/modules/%{KVERREL}%{?2:-%{2}}/kernel\
432 /usr/lib/modules/%{KVERREL}%{?2:-%{2}}/build\
433 /usr/lib/modules/%{KVERREL}%{?2:-%{2}}/source\
434 /usr/lib/modules/%{KVERREL}%{?2:-%{2}}/modules.*\
435 %ghost /boot/initramfs-%{KVERREL}%{?2:-%{2}}.img\
436 %{?-e:%{-e*}}\
437 %{expand:%%files -n kernel-%{?2:%{2}-}devel}\
438 %defattr(-,root,root)\
439 %verify(not mtime) /usr/src/kernels/%{KVERREL}%{?2:-%{2}}\
440 /usr/lib/modules/%{KVERREL}%{?2:-%{2}}/vmlinux \
441 %endif\
442 %{nil}
443
444
445 %kernel_variant_files %all_x86 adaptation-pc