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 KDEB_SOURCENAME ?= linux-upstream
8 KBUILD_PKG_ROOTCMD ?="fakeroot -u"
10 # Include only those top-level files that are needed by make, plus the GPL copy
11 TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
12 include init io_uring ipc kernel lib mm net rust \
13 samples scripts security sound tools usr virt \
15 Kbuild Kconfig COPYING $(wildcard localversion*)
16 MKSPEC := $(srctree)/scripts/package/mkspec
18 quiet_cmd_src_tar = TAR $(2).tar.gz
20 if test "$(objtree)" != "$(srctree)"; then \
23 echo >&2 " Building source tarball is not possible outside the"; \
24 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \
28 tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
29 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
31 # .tmp_filelist .tmp_filelist_exclude
32 # ---------------------------------------------------------------------------
34 scripts/list-gitignored: FORCE
35 $(Q)$(MAKE) -f $(srctree)/Makefile scripts_package
37 # 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore,
38 # but it is definitely a generated file.
40 $< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=-
42 .tmp_filelist: scripts/list-gitignored FORCE
43 $(call filechk,filelist)
46 # ---------------------------------------------------------------------------
48 quiet_cmd_tar = TAR $@
49 cmd_tar = tar -c -f $@ $(tar-compress-opt) $(tar-exclude-opt) \
50 --owner=0 --group=0 --sort=name \
51 --transform 's:^\.:$*:S' -C $(tar-rootdir) .
53 tar-rootdir := $(srctree)
55 %.tar.gz: private tar-compress-opt := -I $(KGZIP)
59 # Linux source tarball
60 # ---------------------------------------------------------------------------
62 linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude
63 linux.tar.gz: .tmp_filelist
66 # ---------------------------------------------------------------------------
68 rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
70 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
71 --define='_smp_mflags %{nil}'
74 # ---------------------------------------------------------------------------
76 srcrpm-pkg: linux.tar.gz
77 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
78 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
79 --define='_smp_mflags %{nil}' --define='_sourcedir .' --define='_srcrpmdir .'
82 # ---------------------------------------------------------------------------
85 $(MAKE) -f $(srctree)/Makefile
86 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
87 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
88 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
92 $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
93 origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\
94 cp linux.tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz
95 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
96 --build=source,binary --source-option=-sP -nc -us -uc
100 $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
101 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
105 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
108 # ---------------------------------------------------------------------------
111 rm -rf $(objtree)/snap
112 mkdir $(objtree)/snap
114 $(call cmd,src_tar,$(KERNELPATH))
115 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
116 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
117 $(srctree)/scripts/package/snapcraft.template > \
118 $(objtree)/snap/snapcraft.yaml
119 cd $(objtree)/snap && \
120 snapcraft --target-arch=$(UTS_MACHINE)
123 # ---------------------------------------------------------------------------
124 tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg tarzst-pkg
127 $(MAKE) -f $(srctree)/Makefile
128 +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
130 # perf-pkg - generate a source tarball with perf source
131 # ---------------------------------------------------------------------------
133 perf-tar=perf-$(KERNELVERSION)
135 quiet_cmd_perf_tar = TAR
137 git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \
138 HEAD^{tree} $$(cd $(srctree); \
139 echo $$(cat tools/perf/MANIFEST)) \
140 -o $(perf-tar).tar; \
141 mkdir -p $(perf-tar); \
142 git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \
143 (cd $(srctree)/tools/perf; \
144 util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \
145 tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
147 $(if $(findstring tar-src,$@),, \
148 $(if $(findstring bz2,$@),$(KBZIP2), \
149 $(if $(findstring gz,$@),$(KGZIP), \
150 $(if $(findstring xz,$@),$(XZ), \
151 $(if $(findstring zst,$@),$(ZSTD), \
152 $(error unknown target $@))))) \
153 -f -9 $(perf-tar).tar)
155 perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \
156 perf-tarxz-src-pkg perf-tarzst-src-pkg
157 PHONY += $(perf-tar-pkgs)
161 # Help text displayed when executing 'make help'
162 # ---------------------------------------------------------------------------
165 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
166 @echo ' srcrpm-pkg - Build only the source kernel RPM package'
167 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
168 @echo ' deb-pkg - Build both source and binary deb kernel packages'
169 @echo ' bindeb-pkg - Build only the binary kernel deb package'
170 @echo ' snap-pkg - Build only the binary kernel snap package'
171 @echo ' (will connect to external hosts)'
172 @echo ' dir-pkg - Build the kernel as a plain directory structure'
173 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
174 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
175 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
176 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
177 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
178 @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
179 @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
180 @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
181 @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball'
182 @echo ' perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball'