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
6 KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
7 KBUILD_PKG_ROOTCMD ?="fakeroot -u"
8 # Include only those top-level files that are needed by make, plus the GPL copy
9 TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
10 include init io_uring ipc kernel lib mm net rust \
11 samples scripts security sound tools usr virt \
13 Kbuild Kconfig COPYING $(wildcard localversion*)
14 MKSPEC := $(srctree)/scripts/package/mkspec
16 quiet_cmd_src_tar = TAR $(2).tar.gz
18 if test "$(objtree)" != "$(srctree)"; then \
21 echo >&2 " Building source tarball is not possible outside the"; \
22 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \
26 tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
27 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
29 # .tmp_filelist .tmp_filelist_exclude
30 # ---------------------------------------------------------------------------
32 scripts/list-gitignored: FORCE
33 $(Q)$(MAKE) -f $(srctree)/Makefile scripts_package
35 # 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore,
36 # but it is definitely a generated file.
38 $< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=-
40 .tmp_filelist: scripts/list-gitignored FORCE
41 $(call filechk,filelist)
44 # ---------------------------------------------------------------------------
46 quiet_cmd_tar = TAR $@
47 cmd_tar = tar -c -f $@ $(tar-compress-opt) $(tar-exclude-opt) \
48 --owner=0 --group=0 --sort=name \
49 --transform 's:^\.:$*:S' -C $(tar-rootdir) .
51 tar-rootdir := $(srctree)
56 %.tar.gz: private tar-compress-opt := -I $(KGZIP)
60 %.tar.bz2: private tar-compress-opt := -I $(KBZIP2)
64 %.tar.xz: private tar-compress-opt := -I $(XZ)
68 %.tar.zst: private tar-compress-opt := -I $(ZSTD)
72 # Linux source tarball
73 # ---------------------------------------------------------------------------
75 linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude
76 linux.tar.gz: .tmp_filelist
79 # ---------------------------------------------------------------------------
81 rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
83 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
84 --define='_smp_mflags %{nil}'
87 # ---------------------------------------------------------------------------
89 srcrpm-pkg: linux.tar.gz
90 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
91 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
92 --define='_smp_mflags %{nil}' --define='_sourcedir .' --define='_srcrpmdir .'
95 # ---------------------------------------------------------------------------
98 $(MAKE) -f $(srctree)/Makefile
99 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
100 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
101 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
103 quiet_cmd_debianize = GEN $@
104 cmd_debianize = $(srctree)/scripts/package/mkdebian
107 $(call cmd,debianize)
110 debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
111 debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
112 debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
113 debian-orig: linux.tar.gz debian
114 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
115 ln -f $< ../$(orig-name); \
117 cp $< ../$(orig-name); \
122 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
123 --build=source,binary -nc -us -uc
127 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
131 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
134 # ---------------------------------------------------------------------------
137 rm -rf $(objtree)/snap
138 mkdir $(objtree)/snap
140 $(call cmd,src_tar,$(KERNELPATH))
141 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
142 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
143 $(srctree)/scripts/package/snapcraft.template > \
144 $(objtree)/snap/snapcraft.yaml
145 cd $(objtree)/snap && \
146 snapcraft --target-arch=$(UTS_MACHINE)
148 # dir-pkg tar*-pkg - tarball targets
149 # ---------------------------------------------------------------------------
151 tar-pkg-tarball = linux-$(KERNELRELEASE)-$(ARCH).$(1)
152 tar-pkg-phony = $(subst .,,$(1))-pkg
155 $(Q)$(MAKE) -f $(srctree)/Makefile
156 +$(Q)$(srctree)/scripts/package/buildtar $@
160 @echo "Kernel tree successfully created in $<"
163 PHONY += $(tar-pkg-phony)
164 $(tar-pkg-phony): $(tar-pkg-tarball)
167 $(tar-pkg-tarball): private tar-rootdir := tar-install
168 $(tar-pkg-tarball): tar-install
171 $(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call tar-pkg-rule,$(x))))
173 # perf-tar*-src-pkg - generate a source tarball with perf source
174 # ---------------------------------------------------------------------------
176 perf-tar-src-pkg-tarball = perf-$(KERNELVERSION).$(1)
177 perf-tar-src-pkg-phony = perf-$(subst .,,$(1))-src-pkg
179 quiet_cmd_stage_perf_src = STAGE $@
180 cmd_stage_perf_src = \
183 tar -c -f - --exclude-from=$<_exclude -C $(srctree) --files-from=$(srctree)/tools/perf/MANIFEST | \
186 .tmp_perf: .tmp_filelist
187 $(call cmd,stage_perf_src)
189 filechk_perf_head = \
190 if test -z "$(git -C $(srctree) rev-parse --show-cdup 2>/dev/null)" && \
191 head=$$(git -C $(srctree) rev-parse --verify HEAD 2>/dev/null); then \
194 echo "not a git tree"; \
197 .tmp_perf/HEAD: .tmp_perf FORCE
198 $(call filechk,perf_head)
200 quiet_cmd_perf_version_file = GEN $@
201 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
203 # PERF-VERSION-FILE and HEAD are independent, but this avoids updating the
204 # timestamp of PERF-VERSION-FILE.
205 # The best is to fix tools/perf/util/PERF-VERSION-GEN.
206 .tmp_perf/PERF-VERSION-FILE: .tmp_perf/HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN
207 $(call cmd,perf_version_file)
209 define perf-tar-src-pkg-rule
210 PHONY += $(perf-tar-src-pkg-phony)
211 $(perf-tar-src-pkg-phony): $(perf-tar-src-pkg-tarball)
214 $(perf-tar-src-pkg-tarball): private tar-rootdir := .tmp_perf
215 $(perf-tar-src-pkg-tarball): .tmp_filelist .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE
218 $(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call perf-tar-src-pkg-rule,$(x))))
220 # Help text displayed when executing 'make help'
221 # ---------------------------------------------------------------------------
224 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
225 @echo ' srcrpm-pkg - Build only the source kernel RPM package'
226 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
227 @echo ' deb-pkg - Build both source and binary deb kernel packages'
228 @echo ' bindeb-pkg - Build only the binary kernel deb package'
229 @echo ' snap-pkg - Build only the binary kernel snap package'
230 @echo ' (will connect to external hosts)'
231 @echo ' dir-pkg - Build the kernel as a plain directory structure'
232 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
233 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
234 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
235 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
236 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
237 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
238 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
239 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
240 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
241 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'