Commit | Line | Data |
---|---|---|
ec8f24b7 | 1 | # SPDX-License-Identifier: GPL-2.0-only |
1da177e4 | 2 | # Makefile for the different targets used to generate full packages of a kernel |
000ec95f MY |
3 | |
4 | include $(srctree)/scripts/Kbuild.include | |
05e96e96 | 5 | include $(srctree)/scripts/Makefile.lib |
1da177e4 | 6 | |
e1287eb8 | 7 | KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) |
6615d6c3 | 8 | # Include only those top-level files that are needed by make, plus the GPL copy |
a3c4d4ab | 9 | TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \ |
df1f1ea9 PL |
10 | include init io_uring ipc kernel lib mm net rust \ |
11 | samples scripts security sound tools usr virt \ | |
f6e09b07 | 12 | .config Makefile \ |
6615d6c3 | 13 | Kbuild Kconfig COPYING $(wildcard localversion*) |
1da177e4 | 14 | MKSPEC := $(srctree)/scripts/package/mkspec |
1da177e4 | 15 | |
26803821 RV |
16 | quiet_cmd_src_tar = TAR $(2).tar.gz |
17 | cmd_src_tar = \ | |
18 | if test "$(objtree)" != "$(srctree)"; then \ | |
262dad68 MY |
19 | echo >&2; \ |
20 | echo >&2 " ERROR:"; \ | |
21 | echo >&2 " Building source tarball is not possible outside the"; \ | |
6fc91752 | 22 | echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \ |
262dad68 | 23 | echo >&2; \ |
26803821 RV |
24 | false; \ |
25 | fi ; \ | |
e4a42c82 | 26 | tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \ |
f6e09b07 | 27 | --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3) |
26803821 | 28 | |
05e96e96 MY |
29 | # Git |
30 | # --------------------------------------------------------------------------- | |
7bf4582d | 31 | |
05e96e96 | 32 | filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null |
e0ca1674 | 33 | |
05e96e96 MY |
34 | .tmp_HEAD: check-git FORCE |
35 | $(call filechk,HEAD) | |
e0ca1674 | 36 | |
05e96e96 MY |
37 | PHONY += check-git |
38 | check-git: | |
39 | @if ! $(srctree)/scripts/check-git; then \ | |
40 | echo >&2 "error: creating source package requires git repository"; \ | |
41 | false; \ | |
42 | fi | |
e0ca1674 | 43 | |
1d29b4c2 MY |
44 | git-config-tar.gz = -c tar.tar.gz.command="$(KGZIP)" |
45 | git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)" | |
46 | git-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)" | |
47 | git-config-tar.xz = -c tar.tar.xz.command="$(XZ)" | |
48 | git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)" | |
f8d94c4e | 49 | |
f6d82835 | 50 | quiet_cmd_archive = ARCHIVE $@ |
f8d94c4e | 51 | cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \ |
9cedc5e8 | 52 | --output=$$(realpath $@) $(archive-args) |
f6d82835 | 53 | |
1d29b4c2 MY |
54 | suffix-gzip := .gz |
55 | suffix-bzip2 := .bz2 | |
56 | suffix-lzma := .lzma | |
57 | suffix-xz := .xz | |
58 | ||
7bf4582d MY |
59 | # Linux source tarball |
60 | # --------------------------------------------------------------------------- | |
61 | ||
1d29b4c2 | 62 | linux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz) |
f8d94c4e MY |
63 | |
64 | targets += $(linux-tarballs) | |
9cedc5e8 | 65 | $(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<) |
f8d94c4e | 66 | $(linux-tarballs): .tmp_HEAD FORCE |
f6d82835 | 67 | $(call if_changed,archive) |
7bf4582d | 68 | |
1da177e4 | 69 | # rpm-pkg |
0131705d | 70 | # --------------------------------------------------------------------------- |
6a4f6a26 | 71 | PHONY += rpm-pkg |
1ec9bb70 MY |
72 | rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) |
73 | rpm-pkg: srcrpm-pkg | |
74 | +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ | |
19286825 | 75 | --define='_smp_mflags %{nil}' --define='make $(MAKE)' |
1da177e4 | 76 | |
8818039f IV |
77 | # srcrpm-pkg |
78 | # --------------------------------------------------------------------------- | |
79 | PHONY += srcrpm-pkg | |
6fc91752 | 80 | srcrpm-pkg: linux.tar.gz |
8818039f | 81 | $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec |
6fc91752 | 82 | +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ |
81f59a26 | 83 | --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .' |
8818039f | 84 | |
1da177e4 | 85 | # binrpm-pkg |
0131705d | 86 | # --------------------------------------------------------------------------- |
6a4f6a26 MY |
87 | PHONY += binrpm-pkg |
88 | binrpm-pkg: | |
65013203 | 89 | $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec |
606625be | 90 | +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ |
19286825 | 91 | $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec \ |
1789fc91 | 92 | --build-in-place --noprep --define='_smp_mflags %{nil}' \ |
19286825 | 93 | --define='make $(MAKE)' |
af60e207 | 94 | |
31f735c6 MY |
95 | # deb-pkg srcdeb-pkg bindeb-pkg |
96 | # --------------------------------------------------------------------------- | |
97 | ||
1d29b4c2 MY |
98 | KDEB_SOURCE_COMPRESS ?= gzip |
99 | ||
100 | supported-deb-source-compress := gzip bzip2 lzma xz | |
101 | ||
102 | PHONY += linux.tar.unsupported-deb-src-compress | |
103 | linux.tar.unsupported-deb-src-compress: | |
104 | @echo "error: KDEB_SOURCE_COMPRESS=$(KDEB_SOURCE_COMPRESS) is not supported. The supported values are: $(supported-deb-source-compress)" >&2 | |
105 | @false | |
106 | ||
107 | debian-orig-suffix := \ | |
108 | $(strip $(if $(filter $(supported-deb-source-compress), $(KDEB_SOURCE_COMPRESS)), \ | |
109 | $(suffix-$(KDEB_SOURCE_COMPRESS)),.unsupported-deb-src-compress)) | |
110 | ||
6eabebb1 | 111 | quiet_cmd_debianize = GEN $@ |
aa7d233f | 112 | cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts) |
6eabebb1 MY |
113 | |
114 | debian: FORCE | |
115 | $(call cmd,debianize) | |
116 | ||
117 | PHONY += debian-orig | |
118 | debian-orig: private source = $(shell dpkg-parsechangelog -S Source) | |
119 | debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//') | |
1d29b4c2 | 120 | debian-orig: private orig-name = $(source)_$(version).orig.tar$(debian-orig-suffix) |
aa7d233f | 121 | debian-orig: mkdebian-opts = --need-source |
1d29b4c2 | 122 | debian-orig: linux.tar$(debian-orig-suffix) debian |
b44aa8c9 MY |
123 | $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \ |
124 | ln -f $< ../$(orig-name); \ | |
125 | else \ | |
126 | cp $< ../$(orig-name); \ | |
127 | fi | |
6eabebb1 | 128 | |
31f735c6 MY |
129 | KBUILD_PKG_ROOTCMD ?= 'fakeroot -u' |
130 | ||
131 | PHONY += deb-pkg srcdeb-pkg bindeb-pkg | |
132 | ||
133 | deb-pkg: private build-type := source,binary | |
134 | srcdeb-pkg: private build-type := source | |
135 | bindeb-pkg: private build-type := binary | |
3716001b | 136 | |
31f735c6 | 137 | deb-pkg srcdeb-pkg: debian-orig |
6eabebb1 | 138 | bindeb-pkg: debian |
31f735c6 MY |
139 | deb-pkg srcdeb-pkg bindeb-pkg: |
140 | +$(strip dpkg-buildpackage \ | |
141 | --build=$(build-type) --no-pre-clean --unsigned-changes \ | |
142 | $(if $(findstring source, $(build-type)), \ | |
1d29b4c2 | 143 | --unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \ |
31f735c6 MY |
144 | $(if $(findstring binary, $(build-type)), \ |
145 | -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \ | |
146 | --no-check-builddeps) \ | |
147 | $(DPKG_FLAGS)) | |
b41d920a | 148 | |
5704d455 PP |
149 | # snap-pkg |
150 | # --------------------------------------------------------------------------- | |
6a4f6a26 MY |
151 | PHONY += snap-pkg |
152 | snap-pkg: | |
5704d455 PP |
153 | rm -rf $(objtree)/snap |
154 | mkdir $(objtree)/snap | |
155 | $(MAKE) clean | |
156 | $(call cmd,src_tar,$(KERNELPATH)) | |
157 | sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ | |
158 | s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \ | |
159 | $(srctree)/scripts/package/snapcraft.template > \ | |
160 | $(objtree)/snap/snapcraft.yaml | |
161 | cd $(objtree)/snap && \ | |
162 | snapcraft --target-arch=$(UTS_MACHINE) | |
163 | ||
1fc90958 | 164 | # dir-pkg tar*-pkg - tarball targets |
6d983fea | 165 | # --------------------------------------------------------------------------- |
1fc90958 | 166 | |
1fc90958 MY |
167 | tar-install: FORCE |
168 | $(Q)$(MAKE) -f $(srctree)/Makefile | |
169 | +$(Q)$(srctree)/scripts/package/buildtar $@ | |
170 | ||
3c65a270 MY |
171 | compress-tar.gz = -I "$(KGZIP)" |
172 | compress-tar.bz2 = -I "$(KBZIP2)" | |
173 | compress-tar.xz = -I "$(XZ)" | |
174 | compress-tar.zst = -I "$(ZSTD)" | |
175 | ||
05e96e96 | 176 | quiet_cmd_tar = TAR $@ |
3c65a270 MY |
177 | cmd_tar = cd $<; tar cf ../$@ $(compress-tar$(suffix $@)) --owner=root --group=root --sort=name * |
178 | ||
179 | dir-tarballs := $(addprefix linux-$(KERNELRELEASE)-$(ARCH), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst) | |
05e96e96 | 180 | |
3c65a270 | 181 | $(dir-tarballs): tar-install |
05e96e96 MY |
182 | $(call cmd,tar) |
183 | ||
1fc90958 MY |
184 | PHONY += dir-pkg |
185 | dir-pkg: tar-install | |
186 | @echo "Kernel tree successfully created in $<" | |
187 | ||
05e96e96 MY |
188 | PHONY += tar-pkg |
189 | tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar | |
1fc90958 MY |
190 | @: |
191 | ||
05e96e96 MY |
192 | tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE |
193 | @: | |
6d983fea | 194 | |
e0ca1674 | 195 | # perf-tar*-src-pkg - generate a source tarball with perf source |
8e5564e6 ACM |
196 | # --------------------------------------------------------------------------- |
197 | ||
05e96e96 MY |
198 | .tmp_perf: |
199 | $(Q)mkdir .tmp_perf | |
e0ca1674 | 200 | |
05e96e96 MY |
201 | .tmp_perf/HEAD: .tmp_HEAD | .tmp_perf |
202 | $(call cmd,copy) | |
e0ca1674 MY |
203 | |
204 | quiet_cmd_perf_version_file = GEN $@ | |
205 | cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@)) | |
206 | ||
05e96e96 | 207 | # PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the |
e0ca1674 MY |
208 | # timestamp of PERF-VERSION-FILE. |
209 | # The best is to fix tools/perf/util/PERF-VERSION-GEN. | |
05e96e96 | 210 | .tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf |
e0ca1674 MY |
211 | $(call cmd,perf_version_file) |
212 | ||
f6d82835 | 213 | perf-archive-args = --add-file=$$(realpath $(word 2, $^)) \ |
05e96e96 MY |
214 | --add-file=$$(realpath $(word 3, $^)) \ |
215 | $$(cat $(word 2, $^))^{tree} $$(cat $<) | |
e0ca1674 | 216 | |
f8d94c4e MY |
217 | |
218 | perf-tarballs := $(addprefix perf-$(KERNELVERSION), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst) | |
219 | ||
220 | targets += $(perf-tarballs) | |
9cedc5e8 | 221 | $(perf-tarballs): archive-args = --prefix=perf-$(KERNELVERSION)/ $(perf-archive-args) |
f8d94c4e | 222 | $(perf-tarballs): tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE |
f6d82835 | 223 | $(call if_changed,archive) |
05e96e96 MY |
224 | |
225 | PHONY += perf-tar-src-pkg | |
226 | perf-tar-src-pkg: perf-$(KERNELVERSION).tar | |
227 | @: | |
e0ca1674 | 228 | |
05e96e96 MY |
229 | perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE |
230 | @: | |
8e5564e6 | 231 | |
1da177e4 LT |
232 | # Help text displayed when executing 'make help' |
233 | # --------------------------------------------------------------------------- | |
6a4f6a26 MY |
234 | PHONY += help |
235 | help: | |
8e5564e6 | 236 | @echo ' rpm-pkg - Build both source and binary RPM kernel packages' |
9c9b55a5 | 237 | @echo ' srcrpm-pkg - Build only the source kernel RPM package' |
3716001b RV |
238 | @echo ' binrpm-pkg - Build only the binary kernel RPM package' |
239 | @echo ' deb-pkg - Build both source and binary deb kernel packages' | |
31f735c6 | 240 | @echo ' srcdeb-pkg - Build only the source kernel deb package' |
3716001b | 241 | @echo ' bindeb-pkg - Build only the binary kernel deb package' |
a64c0440 GU |
242 | @echo ' snap-pkg - Build only the binary kernel snap package' |
243 | @echo ' (will connect to external hosts)' | |
af7db99a | 244 | @echo ' dir-pkg - Build the kernel as a plain directory structure' |
8e5564e6 ACM |
245 | @echo ' tar-pkg - Build the kernel as an uncompressed tarball' |
246 | @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' | |
247 | @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' | |
9a17f400 | 248 | @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' |
88f5e1e6 | 249 | @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' |
e0ca1674 MY |
250 | @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression' |
251 | @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression' | |
252 | @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression' | |
253 | @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression' | |
254 | @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression' | |
000ec95f | 255 | |
7bf4582d MY |
256 | PHONY += FORCE |
257 | FORCE: | |
258 | ||
05e96e96 MY |
259 | # Read all saved command lines and dependencies for the $(targets) we |
260 | # may be building above, using $(if_changed{,_dep}). As an | |
261 | # optimization, we don't need to read them if the target does not | |
262 | # exist, we will rebuild anyway in that case. | |
263 | ||
264 | existing-targets := $(wildcard $(sort $(targets))) | |
265 | ||
266 | -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) | |
267 | ||
000ec95f | 268 | .PHONY: $(PHONY) |