xref: /linux-6.15/scripts/Makefile.package (revision 6fc91752)
1# SPDX-License-Identifier: GPL-2.0-only
2# Makefile for the different targets used to generate full packages of a kernel
3
4include $(srctree)/scripts/Kbuild.include
5
6KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
7KDEB_SOURCENAME ?= linux-upstream
8KBUILD_PKG_ROOTCMD ?="fakeroot -u"
9export KDEB_SOURCENAME
10# Include only those top-level files that are needed by make, plus the GPL copy
11TAR_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 \
14               .config Makefile \
15               Kbuild Kconfig COPYING $(wildcard localversion*)
16MKSPEC     := $(srctree)/scripts/package/mkspec
17
18quiet_cmd_src_tar = TAR     $(2).tar.gz
19      cmd_src_tar = \
20if test "$(objtree)" != "$(srctree)"; then \
21	echo >&2; \
22	echo >&2 "  ERROR:"; \
23	echo >&2 "  Building source tarball is not possible outside the"; \
24	echo >&2 "  kernel source tree. Don't set KBUILD_OUTPUT"; \
25	echo >&2; \
26	false; \
27fi ; \
28tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
29	--transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
30
31# .tmp_filelist .tmp_filelist_exclude
32# ---------------------------------------------------------------------------
33
34scripts/list-gitignored: FORCE
35	$(Q)$(MAKE) -f $(srctree)/Makefile scripts_package
36
37# 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore,
38# but it is definitely a generated file.
39filechk_filelist = \
40	$< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=-
41
42.tmp_filelist: scripts/list-gitignored FORCE
43	$(call filechk,filelist)
44
45# tarball
46# ---------------------------------------------------------------------------
47
48quiet_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) .
52
53tar-rootdir := $(srctree)
54
55%.tar.gz: private tar-compress-opt := -I $(KGZIP)
56%.tar.gz:
57	$(call cmd,tar)
58
59# Linux source tarball
60# ---------------------------------------------------------------------------
61
62linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude
63linux.tar.gz: .tmp_filelist
64
65# rpm-pkg
66# ---------------------------------------------------------------------------
67PHONY += rpm-pkg
68rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
69rpm-pkg: srcrpm-pkg
70	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
71	--define='_smp_mflags %{nil}'
72
73# srcrpm-pkg
74# ---------------------------------------------------------------------------
75PHONY += srcrpm-pkg
76srcrpm-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 .'
80
81# binrpm-pkg
82# ---------------------------------------------------------------------------
83PHONY += binrpm-pkg
84binrpm-pkg:
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
89
90PHONY += deb-pkg
91deb-pkg: linux.tar.gz
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
97
98PHONY += bindeb-pkg
99bindeb-pkg:
100	$(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
101	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
102
103PHONY += intdeb-pkg
104intdeb-pkg:
105	+$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
106
107# snap-pkg
108# ---------------------------------------------------------------------------
109PHONY += snap-pkg
110snap-pkg:
111	rm -rf $(objtree)/snap
112	mkdir $(objtree)/snap
113	$(MAKE) clean
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)
121
122# tarball targets
123# ---------------------------------------------------------------------------
124tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg tarzst-pkg
125PHONY += $(tar-pkgs)
126$(tar-pkgs):
127	$(MAKE) -f $(srctree)/Makefile
128	+$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
129
130# perf-pkg - generate a source tarball with perf source
131# ---------------------------------------------------------------------------
132
133perf-tar=perf-$(KERNELVERSION)
134
135quiet_cmd_perf_tar = TAR
136      cmd_perf_tar = \
137git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/         \
138	HEAD^{tree} $$(cd $(srctree);                               \
139		       echo $$(cat tools/perf/MANIFEST)) \
140	-o $(perf-tar).tar;                                         \
141mkdir -p $(perf-tar);                                               \
142git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD;    \
143(cd $(srctree)/tools/perf;                                          \
144util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/);              \
145tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
146rm -r $(perf-tar);                                                  \
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)
154
155perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \
156		 perf-tarxz-src-pkg perf-tarzst-src-pkg
157PHONY += $(perf-tar-pkgs)
158$(perf-tar-pkgs):
159	$(call cmd,perf_tar)
160
161# Help text displayed when executing 'make help'
162# ---------------------------------------------------------------------------
163PHONY += help
164help:
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'
183
184PHONY += FORCE
185FORCE:
186
187.PHONY: $(PHONY)
188