packaging: add spec file, gbs.conf
[platform/kernel/linux-stable.git] / packaging / linux-stable.spec
1 #
2 # Spec written for Tizen Mobile, some bits and pieces originate
3 # from MeeGo/Moblin/Fedora
4 #
5
6 %define upstream_version 3.14.20
7
8 %if !%{defined platform}
9 %define platform default
10 %endif
11
12 %define variant %{profile}-%{_arch}-%{platform}
13 %define kernel_version %{version}-%{release}
14 %define kernel_full_version %{version}-%{release}-%{variant}
15 %define arch_32bits i386 i586 i686 %{ix86}
16
17 # Default arch config for tizen per arch (unless overiden after)
18 %define kernel_image bzImage
19
20 %define dtbs_supported 0
21 %define modules_supported 1
22 %define trace_supported 1
23 %define uboot_supported 0
24 %define vdso_supported 1
25
26
27 # Overide per configuration
28
29 %ifarch %{arch_32bits}
30 %define kernel_arch i386
31 %define kernel_arch_subdir arch/x86
32 %define defconfig i386_defconfig
33 %endif
34
35 %ifarch x86_64
36 %define kernel_arch x86_64
37 %define kernel_arch_subdir arch/x86
38 %define defconfig x86_64_defconfig
39 %endif
40
41 %ifarch %arm
42 %define kernel_arch arm
43 %define kernel_arch_subdir arch/%{kernel_arch}
44 %define defconfig vexpress_defconfig
45 %define kernel_image zImage
46 %define vdso_supported 0
47 %define modules_supported 0
48 %endif
49
50
51 Name: linux-stable
52 Summary: Tizen kernel
53 Group: System/Kernel
54 License: GPL-2.0
55 URL: http://www.kernel.org/
56 Version: %{upstream_version}
57
58 # The below is used when we are on an -rc version
59 #%#define rc_num 6
60 #%#define release_ver 0
61 #%#define rc_str %{?rc_num:0.rc%{rc_num}}%{!?rc_num:1}
62 #%if ! 0%{?opensuse_bs}
63 #Release: 0
64 #%else
65 #Release: 0
66 #%endif
67 Release: 0
68
69 BuildRequires: module-init-tools
70 BuildRequires: findutils
71 BuildRequires: libelf-devel
72 BuildRequires: binutils-devel
73 BuildRequires: which
74 BuildRequires: bc
75 # net-tools provides the 'hostname' utility which kernel build wants
76 BuildRequires: net-tools
77 # The below is required for building perf
78 BuildRequires: flex
79 BuildRequires: bison
80 BuildRequires: libdw-devel
81 BuildRequires: python-devel
82 %if %{uboot_supported}
83 BuildRequires: u-boot-tools
84 %endif
85
86 ExclusiveArch: %{arch_32bits} x86_64 armv7l
87
88 Source0: %{name}-%{version}.tar.bz2
89
90 %description
91 This package contains the Linux kernel for Tizen.
92
93
94 %package -n kernel-%{variant}
95 Summary: Tizen kernel
96 Group: System/Kernel
97 Provides: kernel-profile-%{profile} = %{version}-%{release}
98 Provides: kernel-uname-r = %{kernel_full_version}
99 Requires(post): /usr/bin/ln
100 Requires(post): /usr/bin/sort
101 Requires(post): rpm
102
103 # We use 'setup-scripts-bootloader-conf' in post and postun, so ideally we need to
104 # have the below here, but this causes gbs/obs build failures like this:
105 #    "have choice for virtual-setup-scripts-bootloader needed by kernel-x86-scripts: setup-extlinux setup-gummiboot"
106 # The reason is that it will try to install the kernel to the build root, and
107 # fail with the above error. To fix it one would need to add 'setup-extlinux'
108 # or 'setup-gummiboot' to 'review.tizen.org/gerrit/scm/meta/build-config'. But
109 # it is probably not worth the trouble, so I commented out the below two lines.
110 # -- Artem
111 #Requires(post): virtual-setup-scripts-bootloader
112 #Requires(postun): virtual-setup-scripts-bootloader
113
114 #Requires(post): setup-gummiboot
115 #Requires(postun): setup-gummiboot
116
117 Requires(post): /usr/sbin/depmod
118 Requires(post): /usr/bin/dracut
119 Requires(post): /usr/bin/kmod
120
121 Requires(postun): /usr/bin/ln
122 Requires(postun): /usr/bin/sed
123 Requires(postun): rpm
124
125 # We can't let RPM do the dependencies automatic because it'll then pick up
126 # a correct but undesirable perl dependency from the module headers which
127 # isn't required for the kernel proper to function
128 AutoReq: no
129 AutoProv: yes
130
131 %description -n kernel-%{variant}
132 This package contains the Linux kernel for Tizen (%{profile} profile, architecure %{_arch})
133
134 %package -n kernel-%{variant}-devel
135 Summary: Development package for building kernel modules
136 Group: Development/System
137 Provides: kernel-devel = %{kernel_full_version}
138 Provides: kernel-devel-uname-r = %{kernel_full_version}
139 Requires(post): /usr/bin/find
140 Requires: kernel-%{variant} = %{version}-%{release}
141 AutoReqProv: no
142
143 %description -n kernel-%{variant}-devel
144 This package provides kernel headers and makefiles sufficient to build modules
145 against the %{variant} kernel package.
146
147
148 %package -n perf
149 Summary: The 'perf' performance counter tool
150 Group: System/Kernel
151 Provides: perf = %{kernel_full_version}
152 Requires: kernel-%{variant} = %{version}-%{release}
153
154 %description -n perf
155 This package provides the "perf" tool that can be used to monitor performance
156 counter events as well as various kernel internal events.
157
158
159
160 ###
161 ### PREP
162 ###
163 %prep
164 # Unpack the kernel tarball
165 %setup -q -n %{name}-%{version}
166
167
168
169 ###
170 ### BUILD
171 ###
172 %build
173 # Make sure EXTRAVERSION says what we want it to say
174 sed -i "s/^EXTRAVERSION.*/EXTRAVERSION = -%{release}-%{variant}/" Makefile
175
176 # Build perf
177 make -s -C tools/lib/traceevent ARCH=%{kernel_arch} %{?_smp_mflags}
178 make -s -C tools/perf WERROR=0 ARCH=%{kernel_arch}
179
180 %if %{defined loadaddr}
181 export LOADADDR=%{loadaddr}
182 %endif
183
184 # Build kernel and modules
185 make -s ARCH=%{kernel_arch} %{defconfig}
186 make %{?_smp_mflags} %{kernel_image} ARCH=%{kernel_arch}
187
188 %if %modules_supported
189 make -s ARCH=%{kernel_arch} %{?_smp_mflags} modules
190 %endif
191
192 %if %dtbs_supported
193 make -s ARCH=%{kernel_arch} %{?_smp_mflags} dtbs
194 %endif
195
196
197
198 ###
199 ### INSTALL
200 ###
201 %install
202 install -d %{buildroot}/boot
203
204 install -m 644 .config %{buildroot}/boot/config-%{kernel_full_version}
205 install -m 644 System.map %{buildroot}/boot/System.map-%{kernel_full_version}
206 install -m 755 %{kernel_arch_subdir}/boot/%{kernel_image} %{buildroot}/boot/vmlinuz-%{kernel_full_version}
207 # Dummy initrd, will not be included in the actual package but needed for files
208 touch %{buildroot}/boot/initrd-%{kernel_full_version}.img
209
210 %if %modules_supported
211 make -s ARCH=%{kernel_arch} INSTALL_MOD_PATH=%{buildroot} modules_install KERNELRELEASE=%{kernel_full_version}
212 %endif
213
214 %if %vdso_supported
215 make -s ARCH=%{kernel_arch} INSTALL_MOD_PATH=%{buildroot} vdso_install KERNELRELEASE=%{kernel_full_version}
216 %endif
217
218 %if %dtbs_supported
219 install -d "%{buildroot}/boot/"
220 find "arch/%{kernel_arch}/" -iname "*.dtb" -exec install "{}" "%{buildroot}/boot/" \;
221 %endif
222
223 rm -rf %{buildroot}/lib/firmware
224
225 # And save the headers/makefiles etc for building modules against
226 #
227 # This all looks scary, but the end result is supposed to be:
228 # * all arch relevant include/ files
229 # * all Makefile/Kconfig files
230 # * all script/ files
231
232 # Remove existing build/source links and create pristine dirs
233 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/build
234 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/source
235 install -d %{buildroot}/lib/modules/%{kernel_full_version}/build
236 ln -fs build %{buildroot}/lib/modules/%{kernel_full_version}/source
237
238
239 # First, copy all dirs containing Makefile of Kconfig files
240 cp --parents `find  -type f -name "Makefile*" -o -name "Kconfig*"` %{buildroot}/lib/modules/%{kernel_full_version}/build
241 install Module.symvers %{buildroot}/lib/modules/%{kernel_full_version}/build/
242 install System.map %{buildroot}/lib/modules/%{kernel_full_version}/build/
243
244 # Then, drop all but the needed Makefiles/Kconfig files
245 rm -rf %{buildroot}/lib/modules/%{kernel_full_version}/build/Documentation
246 rm -rf %{buildroot}/lib/modules/%{kernel_full_version}/build/scripts
247 rm -rf %{buildroot}/lib/modules/%{kernel_full_version}/build/include
248
249 # Copy config and scripts
250 install .config %{buildroot}/lib/modules/%{kernel_full_version}/build/
251 cp -a scripts %{buildroot}/lib/modules/%{kernel_full_version}/build
252 if [ -d %{kernel_arch_subdir}/scripts ]; then
253     cp -a %{kernel_arch_subdir}/scripts %{buildroot}/lib/modules/%{kernel_full_version}/build/%{kernel_arch_subdir}/ || :
254 fi
255 if [ -f %{kernel_arch_subdir}/*lds ]; then
256     cp -a %{kernel_arch_subdir}/*lds %{buildroot}/lib/modules/%{kernel_full_version}/build/%{kernel_arch_subdir}/ || :
257 fi
258 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/build/scripts/*.o
259 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/build/scripts/*/*.o
260 cp -a --parents %{kernel_arch_subdir}/include %{buildroot}/lib/modules/%{kernel_full_version}/build
261
262 # Copy include files
263 mkdir -p %{buildroot}/lib/modules/%{kernel_full_version}/build/include
264 find include/ -mindepth 1 -maxdepth 1 -type d | xargs -I{} cp -a {} %{buildroot}/lib/modules/%{kernel_full_version}/build/include
265
266 # Save the vmlinux file for kernel debugging into the devel package
267 cp vmlinux %{buildroot}/lib/modules/%{kernel_full_version}
268
269 # Mark modules executable so that strip-to-file can strip them
270 find %{buildroot}/lib/modules/%{kernel_full_version} -name "*.ko" -type f | xargs --no-run-if-empty chmod 755
271
272 # Move the devel headers out of the root file system
273 install -d %{buildroot}/usr/src/kernels
274 mv %{buildroot}/lib/modules/%{kernel_full_version}/build %{buildroot}/usr/src/kernels/%{kernel_full_version}
275
276 ln -sf /usr/src/kernels/%{kernel_full_version} %{buildroot}/lib/modules/%{kernel_full_version}/build
277
278 # Install perf
279 install -d %{buildroot}
280 make -s -C tools/perf DESTDIR=%{buildroot} install
281 install -d  %{buildroot}%{_bindir}
282 install -d  %{buildroot}%{_libexecdir}
283 mv %{buildroot}/bin/* %{buildroot}%{_bindir}
284 mv %{buildroot}/libexec/* %{buildroot}%{_libexecdir}
285 rm %{buildroot}/etc/bash_completion.d/perf
286
287 # Dont package debug files
288 rm -rf %{buildroot}/usr/lib/debug/.build-id
289 rm -rf %{buildroot}/usr/lib/debug/lib/traceevent/plugins/*.debug
290
291
292
293 ###
294 ### SCRIPTS
295 ###
296
297 %post -n kernel-%{variant}
298 if [ -f "/boot/loader/loader.conf" ]; then
299         # EFI boot with gummiboot
300         INSTALLERFW_MOUNT_PREFIX="/" /usr/sbin/setup-scripts-gummiboot-conf
301     # "/etc/installerfw-environment" does not exist in MIC environment, when it
302     # builds the image. MIC will add boot-loader entries later using the
303     # 'setup-scripts-boot' script.
304     if [ -f "/etc/installerfw-environment" ] && \
305         [ -x "/usr/sbin/setup-scripts-bootloader-conf" ]; then
306             /usr/sbin/setup-scripts-bootloader-conf add -f vmlinuz-%{kernel_full_version}
307             /usr/sbin/setup-scripts-bootloader-conf default -f vmlinuz-%{kernel_full_version}
308     fi
309 else
310         # Legacy boot
311         last_installed_ver="$(rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant} | sort -r | sed -e 's/[^:]*: \(.*\)/\1/g' | sed -n -e "1p")"
312         ln -sf vmlinuz-$last_installed_ver-%{variant} /boot/vmlinuz
313
314         if [ -z "$last_installed_ver" ]; then
315                 # Something went wrong, print some diagnostics
316                 printf "%s\n" "Error: cannot find kernel version" 1>&2
317                 printf "%s\n" "The command was: rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant} | sort -r | sed -e 's/[^:]*: \(.*\)/\1/g' | sed -n -e \"1p\"" 1>&2
318                 printf "%s\n" "Output of the \"rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant}\" is:" 1>&2
319                 result="$(rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant})"
320                 printf "%s\n" "$result" 1>&2
321         fi
322 fi
323
324 %{_bindir}/dracut /boot/initrd-%{kernel_full_version}.img %{kernel_full_version}
325
326 %post -n kernel-%{variant}-devel
327 if [ -x /usr/sbin/hardlink ]; then
328         cd /usr/src/kernels/%{kernel_full_version}
329         /usr/bin/find . -type f | while read f; do
330                 hardlink -c /usr/src/kernels/*/$f $f
331         done
332 fi
333
334 %postun -n kernel-%{variant}
335 if [ -f "/boot/loader/loader.conf" ]; then
336         # EFI boot with gummiboot
337         INSTALLERFW_MOUNT_PREFIX="/" /usr/sbin/setup-scripts-gummiboot-conf
338     if [ -f "/etc/installerfw-environment" ] && \
339         [ -x "/usr/sbin/setup-scripts-bootloader-conf" ]; then
340             /usr/sbin/setup-scripts-bootloader-conf remove -f vmlinuz-%{kernel_full_version}
341     fi
342
343 else
344         last_installed_ver="$(rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant} | sort -r | sed -e 's/[^:]*: \(.*\)/\1/g' | sed -n -e "1p")"
345         if [ -n "$last_installed_ver" ]; then
346                 ln -sf vmlinuz-$last_installed_ver-%{variant} /boot/vmlinuz
347         else
348                 rm -rf /boot/vmlinuz
349         fi
350 fi
351
352
353
354 ###
355 ### FILES
356 ###
357 %files -n kernel-%{variant}
358 %license COPYING
359 /boot/vmlinuz-%{kernel_full_version}
360 /boot/System.map-%{kernel_full_version}
361 /boot/config-%{kernel_full_version}
362 %if %modules_supported
363 %dir /lib/modules/%{kernel_full_version}
364 /lib/modules/%{kernel_full_version}/kernel
365 /lib/modules/%{kernel_full_version}/modules.*
366 %endif
367 /lib/modules/%{kernel_full_version}/build
368 /lib/modules/%{kernel_full_version}/source
369
370 %if %vdso_supported
371 /lib/modules/%{kernel_full_version}/vdso
372 %endif
373 %if %dtbs_supported
374 /boot/*.dtb
375 %endif
376 %ghost /boot/initrd-%{kernel_full_version}.img
377
378
379 %files -n kernel-%{variant}-devel
380 %license COPYING
381 %verify(not mtime) /usr/src/kernels/%{kernel_full_version}
382 /lib/modules/%{kernel_full_version}/vmlinux
383
384
385 %files -n perf
386 %license COPYING
387 %{_bindir}/perf
388 %{_libexecdir}/perf-core
389 %if %trace_supported
390 %{_bindir}/trace
391 /%{_lib}/traceevent/plugins/*.so
392 %endif