xref: /linux-6.15/scripts/Makefile.package (revision 7bf4582d)
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
6# RPM target
7# ---------------------------------------------------------------------------
8# The rpm target generates two rpm files:
9# /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm
10# /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1.<arch>.rpm
11# The src.rpm files includes all source for the kernel being built
12# The <arch>.rpm includes kernel configuration, modules etc.
13#
14# Process to create the rpm files
15# a) clean the kernel
16# b) Generate .spec file
17# c) Build a tar ball, using symlink to make kernel version
18#    first entry in the path
19# d) and pack the result to a tar.gz file
20# e) generate the rpm files, based on kernel.spec
21# - Use /. to avoid tar packing just the symlink
22
23# Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT,
24# but the binrpm-pkg target can; for some reason O= gets ignored.
25
26# Remove hyphens since they have special meaning in RPM filenames
27KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
28KDEB_SOURCENAME ?= linux-upstream
29KBUILD_PKG_ROOTCMD ?="fakeroot -u"
30export KDEB_SOURCENAME
31# Include only those top-level files that are needed by make, plus the GPL copy
32TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
33               include init io_uring ipc kernel lib mm net rust \
34               samples scripts security sound tools usr virt \
35               .config Makefile \
36               Kbuild Kconfig COPYING $(wildcard localversion*)
37MKSPEC     := $(srctree)/scripts/package/mkspec
38
39quiet_cmd_src_tar = TAR     $(2).tar.gz
40      cmd_src_tar = \
41if test "$(objtree)" != "$(srctree)"; then \
42	echo >&2; \
43	echo >&2 "  ERROR:"; \
44	echo >&2 "  Building source tarball is not possible outside the"; \
45	echo >&2 "  kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \
46	echo >&2 "  binrpm-pkg target instead."; \
47	echo >&2; \
48	false; \
49fi ; \
50tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
51	--transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
52
53# .tmp_filelist .tmp_filelist_exclude
54# ---------------------------------------------------------------------------
55
56scripts/list-gitignored: FORCE
57	$(Q)$(MAKE) -f $(srctree)/Makefile scripts_package
58
59# 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore,
60# but it is definitely a generated file.
61filechk_filelist = \
62	$< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=-
63
64.tmp_filelist: scripts/list-gitignored FORCE
65	$(call filechk,filelist)
66
67# tarball
68# ---------------------------------------------------------------------------
69
70quiet_cmd_tar = TAR     $@
71      cmd_tar = tar -c -f $@ $(tar-compress-opt) $(tar-exclude-opt) \
72                --owner=0 --group=0 --sort=name \
73                --transform 's:^\.:$*:S' -C $(tar-rootdir) .
74
75tar-rootdir := $(srctree)
76
77%.tar.gz: private tar-compress-opt := -I $(KGZIP)
78%.tar.gz:
79	$(call cmd,tar)
80
81# Linux source tarball
82# ---------------------------------------------------------------------------
83
84linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude
85linux.tar.gz: .tmp_filelist
86
87# rpm-pkg
88# ---------------------------------------------------------------------------
89PHONY += rpm-pkg
90rpm-pkg:
91	$(MAKE) clean
92	$(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
93	$(call cmd,src_tar,$(KERNELPATH),kernel.spec)
94	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ta $(KERNELPATH).tar.gz \
95	--define='_smp_mflags %{nil}'
96
97# srcrpm-pkg
98# ---------------------------------------------------------------------------
99PHONY += srcrpm-pkg
100srcrpm-pkg:
101	$(MAKE) clean
102	$(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
103	$(call cmd,src_tar,$(KERNELPATH),kernel.spec)
104	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ts $(KERNELPATH).tar.gz \
105	--define='_smp_mflags %{nil}' --define='_srcrpmdir $(srctree)'
106
107# binrpm-pkg
108# ---------------------------------------------------------------------------
109PHONY += binrpm-pkg
110binrpm-pkg:
111	$(MAKE) -f $(srctree)/Makefile
112	$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
113	+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
114		$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
115
116PHONY += deb-pkg
117deb-pkg: linux.tar.gz
118	$(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
119	origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\
120		cp linux.tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz
121	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
122		--build=source,binary --source-option=-sP -nc -us -uc
123
124PHONY += bindeb-pkg
125bindeb-pkg:
126	$(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
127	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
128
129PHONY += intdeb-pkg
130intdeb-pkg:
131	+$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
132
133# snap-pkg
134# ---------------------------------------------------------------------------
135PHONY += snap-pkg
136snap-pkg:
137	rm -rf $(objtree)/snap
138	mkdir $(objtree)/snap
139	$(MAKE) clean
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)
147
148# tarball targets
149# ---------------------------------------------------------------------------
150tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg tarzst-pkg
151PHONY += $(tar-pkgs)
152$(tar-pkgs):
153	$(MAKE) -f $(srctree)/Makefile
154	+$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
155
156# perf-pkg - generate a source tarball with perf source
157# ---------------------------------------------------------------------------
158
159perf-tar=perf-$(KERNELVERSION)
160
161quiet_cmd_perf_tar = TAR
162      cmd_perf_tar = \
163git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/         \
164	HEAD^{tree} $$(cd $(srctree);                               \
165		       echo $$(cat tools/perf/MANIFEST)) \
166	-o $(perf-tar).tar;                                         \
167mkdir -p $(perf-tar);                                               \
168git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD;    \
169(cd $(srctree)/tools/perf;                                          \
170util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/);              \
171tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
172rm -r $(perf-tar);                                                  \
173$(if $(findstring tar-src,$@),,                                     \
174$(if $(findstring bz2,$@),$(KBZIP2),                                 \
175$(if $(findstring gz,$@),$(KGZIP),                                  \
176$(if $(findstring xz,$@),$(XZ),                                     \
177$(if $(findstring zst,$@),$(ZSTD),                                  \
178$(error unknown target $@)))))                                      \
179	-f -9 $(perf-tar).tar)
180
181perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \
182		 perf-tarxz-src-pkg perf-tarzst-src-pkg
183PHONY += $(perf-tar-pkgs)
184$(perf-tar-pkgs):
185	$(call cmd,perf_tar)
186
187# Help text displayed when executing 'make help'
188# ---------------------------------------------------------------------------
189PHONY += help
190help:
191	@echo '  rpm-pkg             - Build both source and binary RPM kernel packages'
192	@echo '  srcrpm-pkg          - Build only the source kernel RPM package'
193	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
194	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
195	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
196	@echo '  snap-pkg            - Build only the binary kernel snap package'
197	@echo '                        (will connect to external hosts)'
198	@echo '  dir-pkg             - Build the kernel as a plain directory structure'
199	@echo '  tar-pkg             - Build the kernel as an uncompressed tarball'
200	@echo '  targz-pkg           - Build the kernel as a gzip compressed tarball'
201	@echo '  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball'
202	@echo '  tarxz-pkg           - Build the kernel as a xz compressed tarball'
203	@echo '  tarzst-pkg          - Build the kernel as a zstd compressed tarball'
204	@echo '  perf-tar-src-pkg    - Build $(perf-tar).tar source tarball'
205	@echo '  perf-targz-src-pkg  - Build $(perf-tar).tar.gz source tarball'
206	@echo '  perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
207	@echo '  perf-tarxz-src-pkg  - Build $(perf-tar).tar.xz source tarball'
208	@echo '  perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball'
209
210PHONY += FORCE
211FORCE:
212
213.PHONY: $(PHONY)
214