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