1 # SPDX-License-Identifier: GPL-2.0-only
2 # Makefile for the different targets used to generate full packages of a kernel
4 include $(srctree)/scripts/Kbuild.include
5 include $(srctree)/scripts/Makefile.lib
7 KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
8 KBUILD_PKG_ROOTCMD ?="fakeroot -u"
9 # Include only those top-level files that are needed by make, plus the GPL copy
10 TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
11 include init io_uring ipc kernel lib mm net rust \
12 samples scripts security sound tools usr virt \
14 Kbuild Kconfig COPYING $(wildcard localversion*)
15 MKSPEC := $(srctree)/scripts/package/mkspec
17 quiet_cmd_src_tar = TAR $(2).tar.gz
19 if test "$(objtree)" != "$(srctree)"; then \
22 echo >&2 " Building source tarball is not possible outside the"; \
23 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \
27 tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
28 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
31 # ---------------------------------------------------------------------------
33 filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
35 .tmp_HEAD: check-git FORCE
40 @if ! $(srctree)/scripts/check-git; then \
41 echo >&2 "error: creating source package requires git repository"; \
45 git-config-tar.gz = -c tar.tar.gz.command="$(KGZIP)"
46 git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
47 git-config-tar.xz = -c tar.tar.xz.command="$(XZ)"
48 git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
50 quiet_cmd_archive = ARCHIVE $@
51 cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
52 --output=$$(realpath $@) $(archive-args)
54 # Linux source tarball
55 # ---------------------------------------------------------------------------
57 linux-tarballs := $(addprefix linux, .tar.gz)
59 targets += $(linux-tarballs)
60 $(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<)
61 $(linux-tarballs): .tmp_HEAD FORCE
62 $(call if_changed,archive)
65 # ---------------------------------------------------------------------------
67 rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
69 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
70 --define='_smp_mflags %{nil}'
73 # ---------------------------------------------------------------------------
75 srcrpm-pkg: linux.tar.gz
76 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
77 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
78 --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
81 # ---------------------------------------------------------------------------
84 $(MAKE) -f $(srctree)/Makefile
85 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
86 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
87 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
89 quiet_cmd_debianize = GEN $@
90 cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
96 debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
97 debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
98 debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
99 debian-orig: mkdebian-opts = --need-source
100 debian-orig: linux.tar.gz debian
101 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
102 ln -f $< ../$(orig-name); \
104 cp $< ../$(orig-name); \
109 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
110 --build=source,binary -nc -us -uc
114 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
118 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
121 # ---------------------------------------------------------------------------
124 rm -rf $(objtree)/snap
125 mkdir $(objtree)/snap
127 $(call cmd,src_tar,$(KERNELPATH))
128 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
129 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
130 $(srctree)/scripts/package/snapcraft.template > \
131 $(objtree)/snap/snapcraft.yaml
132 cd $(objtree)/snap && \
133 snapcraft --target-arch=$(UTS_MACHINE)
135 # dir-pkg tar*-pkg - tarball targets
136 # ---------------------------------------------------------------------------
139 $(Q)$(MAKE) -f $(srctree)/Makefile
140 +$(Q)$(srctree)/scripts/package/buildtar $@
142 compress-tar.gz = -I "$(KGZIP)"
143 compress-tar.bz2 = -I "$(KBZIP2)"
144 compress-tar.xz = -I "$(XZ)"
145 compress-tar.zst = -I "$(ZSTD)"
147 quiet_cmd_tar = TAR $@
148 cmd_tar = cd $<; tar cf ../$@ $(compress-tar$(suffix $@)) --owner=root --group=root --sort=name *
150 dir-tarballs := $(addprefix linux-$(KERNELRELEASE)-$(ARCH), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
152 $(dir-tarballs): tar-install
157 @echo "Kernel tree successfully created in $<"
160 tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
163 tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
166 # perf-tar*-src-pkg - generate a source tarball with perf source
167 # ---------------------------------------------------------------------------
172 .tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
175 quiet_cmd_perf_version_file = GEN $@
176 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
178 # PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
179 # timestamp of PERF-VERSION-FILE.
180 # The best is to fix tools/perf/util/PERF-VERSION-GEN.
181 .tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
182 $(call cmd,perf_version_file)
184 perf-archive-args = --add-file=$$(realpath $(word 2, $^)) \
185 --add-file=$$(realpath $(word 3, $^)) \
186 $$(cat $(word 2, $^))^{tree} $$(cat $<)
189 perf-tarballs := $(addprefix perf-$(KERNELVERSION), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
191 targets += $(perf-tarballs)
192 $(perf-tarballs): archive-args = --prefix=perf-$(KERNELVERSION)/ $(perf-archive-args)
193 $(perf-tarballs): tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
194 $(call if_changed,archive)
196 PHONY += perf-tar-src-pkg
197 perf-tar-src-pkg: perf-$(KERNELVERSION).tar
200 perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
203 # Help text displayed when executing 'make help'
204 # ---------------------------------------------------------------------------
207 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
208 @echo ' srcrpm-pkg - Build only the source kernel RPM package'
209 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
210 @echo ' deb-pkg - Build both source and binary deb kernel packages'
211 @echo ' bindeb-pkg - Build only the binary kernel deb package'
212 @echo ' snap-pkg - Build only the binary kernel snap package'
213 @echo ' (will connect to external hosts)'
214 @echo ' dir-pkg - Build the kernel as a plain directory structure'
215 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
216 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
217 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
218 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
219 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
220 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
221 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
222 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
223 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
224 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
229 # Read all saved command lines and dependencies for the $(targets) we
230 # may be building above, using $(if_changed{,_dep}). As an
231 # optimization, we don't need to read them if the target does not
232 # exist, we will rebuild anyway in that case.
234 existing-targets := $(wildcard $(sort $(targets)))
236 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)