1 |
commit: e0c6d31a51938736e8c447e22f000eff67fb61ec |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jan 4 16:20:48 2020 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jan 9 16:10:16 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e0c6d31a |
7 |
|
8 |
kernel-build.eclass: Build logic for dist-kernels |
9 |
|
10 |
Introduce a new eclass that contains common logic for building |
11 |
distribution kernels from source. |
12 |
|
13 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
14 |
|
15 |
eclass/kernel-build.eclass | 175 +++++++++++++++++++++++++++++++++++++++++++++ |
16 |
1 file changed, 175 insertions(+) |
17 |
|
18 |
diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass |
19 |
new file mode 100644 |
20 |
index 00000000000..028f0da8148 |
21 |
--- /dev/null |
22 |
+++ b/eclass/kernel-build.eclass |
23 |
@@ -0,0 +1,175 @@ |
24 |
+# Copyright 2020 Gentoo Authors |
25 |
+# Distributed under the terms of the GNU General Public License v2 |
26 |
+ |
27 |
+# @ECLASS: kernel-build.eclass |
28 |
+# @MAINTAINER: |
29 |
+# Distribution Kernel Project <dist-kernel@g.o> |
30 |
+# @AUTHOR: |
31 |
+# Michał Górny <mgorny@g.o> |
32 |
+# @SUPPORTED_EAPIS: 7 |
33 |
+# @BLURB: Build mechanics for Distribution Kernels |
34 |
+# @DESCRIPTION: |
35 |
+# This eclass provides the logic to build a Distribution Kernel from |
36 |
+# source and install it. Post-install and test logic is inherited |
37 |
+# from kernel-install.eclass. |
38 |
+# |
39 |
+# The ebuild must take care of unpacking the kernel sources, copying |
40 |
+# an appropriate .config into them (e.g. in src_prepare()) and setting |
41 |
+# correct S. The eclass takes care of respecting savedconfig, building |
42 |
+# the kernel and installing it along with its modules and subset |
43 |
+# of sources needed to build external modules. |
44 |
+ |
45 |
+if [[ ! ${_KERNEL_BUILD_ECLASS} ]]; then |
46 |
+ |
47 |
+case "${EAPI:-0}" in |
48 |
+ 0|1|2|3|4|5|6) |
49 |
+ die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" |
50 |
+ ;; |
51 |
+ 7) |
52 |
+ ;; |
53 |
+ *) |
54 |
+ die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" |
55 |
+ ;; |
56 |
+esac |
57 |
+ |
58 |
+inherit savedconfig toolchain-funcs kernel-install |
59 |
+ |
60 |
+BDEPEND=" |
61 |
+ sys-devel/bc |
62 |
+ virtual/libelf" |
63 |
+ |
64 |
+# @FUNCTION: kernel-build_src_configure |
65 |
+# @DESCRIPTION: |
66 |
+# Prepare the toolchain for building the kernel, get the default .config |
67 |
+# or restore savedconfig, and get build tree configured for modprep. |
68 |
+kernel-build_src_configure() { |
69 |
+ debug-print-function ${FUNCNAME} "${@}" |
70 |
+ |
71 |
+ # force ld.bfd if we can find it easily |
72 |
+ local LD="$(tc-getLD)" |
73 |
+ if type -P "${LD}.bfd" &>/dev/null; then |
74 |
+ LD+=.bfd |
75 |
+ fi |
76 |
+ |
77 |
+ tc-export_build_env |
78 |
+ MAKEARGS=( |
79 |
+ V=1 |
80 |
+ |
81 |
+ HOSTCC="$(tc-getBUILD_CC)" |
82 |
+ HOSTCXX="$(tc-getBUILD_CXX)" |
83 |
+ HOSTCFLAGS="${BUILD_CFLAGS}" |
84 |
+ HOSTLDFLAGS="${BUILD_LDFLAGS}" |
85 |
+ |
86 |
+ CROSS_COMPILE=${CHOST}- |
87 |
+ AS="$(tc-getAS)" |
88 |
+ CC="$(tc-getCC)" |
89 |
+ LD="${LD}" |
90 |
+ AR="$(tc-getAR)" |
91 |
+ NM="$(tc-getNM)" |
92 |
+ STRIP=":" |
93 |
+ OBJCOPY="$(tc-getOBJCOPY)" |
94 |
+ OBJDUMP="$(tc-getOBJDUMP)" |
95 |
+ |
96 |
+ # we need to pass it to override colliding Gentoo envvar |
97 |
+ ARCH=$(tc-arch-kernel) |
98 |
+ ) |
99 |
+ |
100 |
+ [[ -f .config ]] || die "Ebuild error: please copy default config into .config" |
101 |
+ restore_config .config |
102 |
+ |
103 |
+ mkdir -p "${WORKDIR}"/modprep || die |
104 |
+ mv .config "${WORKDIR}"/modprep/ || die |
105 |
+ emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" olddefconfig |
106 |
+ emake O="${WORKDIR}"/modprep "${MAKEARGS[@]}" modules_prepare |
107 |
+ cp -pR "${WORKDIR}"/modprep "${WORKDIR}"/build || die |
108 |
+} |
109 |
+ |
110 |
+# @FUNCTION: kernel-build_src_compile |
111 |
+# @DESCRIPTION: |
112 |
+# Compile the kernel sources. |
113 |
+kernel-build_src_compile() { |
114 |
+ debug-print-function ${FUNCNAME} "${@}" |
115 |
+ |
116 |
+ emake O="${WORKDIR}"/build "${MAKEARGS[@]}" all |
117 |
+} |
118 |
+ |
119 |
+# @FUNCTION: kernel-build_src_test |
120 |
+# @DESCRIPTION: |
121 |
+# Test the built kernel via qemu. This just wraps the logic |
122 |
+# from kernel-install.eclass with the correct paths. |
123 |
+kernel-build_src_test() { |
124 |
+ debug-print-function ${FUNCNAME} "${@}" |
125 |
+ |
126 |
+ emake O="${WORKDIR}"/build "${MAKEARGS[@]}" \ |
127 |
+ INSTALL_MOD_PATH="${T}" modules_install |
128 |
+ |
129 |
+ kernel-install_test "${PV}" \ |
130 |
+ "${WORKDIR}/build/$(kernel-install_get_image_path)" \ |
131 |
+ "${T}/lib/modules/${PV}" |
132 |
+} |
133 |
+ |
134 |
+# @FUNCTION: kernel-build_src_install |
135 |
+# @DESCRIPTION: |
136 |
+# Install the built kernel along with subset of sources |
137 |
+# into /usr/src/linux-${PV}. Install the modules. Save the config. |
138 |
+kernel-build_src_install() { |
139 |
+ debug-print-function ${FUNCNAME} "${@}" |
140 |
+ |
141 |
+ # do not use 'make install' as it behaves differently based |
142 |
+ # on what kind of installkernel is installed |
143 |
+ emake O="${WORKDIR}"/build "${MAKEARGS[@]}" \ |
144 |
+ INSTALL_MOD_PATH="${ED}" modules_install |
145 |
+ |
146 |
+ # note: we're using mv rather than doins to save space and time |
147 |
+ # install main and arch-specific headers first, and scripts |
148 |
+ local kern_arch=$(tc-arch-kernel) |
149 |
+ dodir "/usr/src/linux-${PV}/arch/${kern_arch}" |
150 |
+ mv include scripts "${ED}/usr/src/linux-${PV}/" || die |
151 |
+ mv "arch/${kern_arch}/include" \ |
152 |
+ "${ED}/usr/src/linux-${PV}/arch/${kern_arch}/" || die |
153 |
+ |
154 |
+ # remove everything but Makefile* and Kconfig* |
155 |
+ find -type f '!' '(' -name 'Makefile*' -o -name 'Kconfig*' ')' \ |
156 |
+ -delete || die |
157 |
+ find -type l -delete || die |
158 |
+ cp -p -R * "${ED}/usr/src/linux-${PV}/" || die |
159 |
+ |
160 |
+ cd "${WORKDIR}" || die |
161 |
+ # strip out-of-source build stuffs from modprep |
162 |
+ # and then copy built files as well |
163 |
+ find modprep -type f '(' \ |
164 |
+ -name Makefile -o \ |
165 |
+ -name '*.[ao]' -o \ |
166 |
+ '(' -name '.*' -a -not -name '.config' ')' \ |
167 |
+ ')' -delete || die |
168 |
+ rm modprep/source || die |
169 |
+ cp -p -R modprep/. "${ED}/usr/src/linux-${PV}"/ || die |
170 |
+ |
171 |
+ # install the kernel and files needed for module builds |
172 |
+ insinto "/usr/src/linux-${PV}" |
173 |
+ doins build/{System.map,Module.symvers} |
174 |
+ local image_path=$(kernel-install_get_image_path) |
175 |
+ cp -p "build/${image_path}" "${ED}/usr/src/linux-${PV}/${image_path}" || die |
176 |
+ |
177 |
+ # strip empty directories |
178 |
+ find "${D}" -type d -empty -exec rmdir {} + || die |
179 |
+ |
180 |
+ # fix source tree and build dir symlinks |
181 |
+ dosym ../../../usr/src/linux-${PV} /lib/modules/${PV}/build |
182 |
+ dosym ../../../usr/src/linux-${PV} /lib/modules/${PV}/source |
183 |
+ |
184 |
+ save_config build/.config |
185 |
+} |
186 |
+ |
187 |
+# @FUNCTION: kernel-build_pkg_postinst |
188 |
+# @DESCRIPTION: |
189 |
+# Combine postinst from kernel-install and savedconfig eclasses. |
190 |
+kernel-build_pkg_postinst() { |
191 |
+ kernel-install_pkg_postinst |
192 |
+ savedconfig_pkg_postinst |
193 |
+} |
194 |
+ |
195 |
+_KERNEL_BUILD_ECLASS=1 |
196 |
+fi |
197 |
+ |
198 |
+EXPORT_FUNCTIONS src_configure src_compile src_test src_install pkg_postinst |