xref: /linux-6.15/scripts/Makefile.package (revision 1ec9bb70)
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: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
91rpm-pkg: srcrpm-pkg
92	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
93	--define='_smp_mflags %{nil}'
94
95# srcrpm-pkg
96# ---------------------------------------------------------------------------
97PHONY += srcrpm-pkg
98srcrpm-pkg:
99	$(MAKE) clean
100	$(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
101	$(call cmd,src_tar,$(KERNELPATH),kernel.spec)
102	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -ts $(KERNELPATH).tar.gz \
103	--define='_smp_mflags %{nil}' --define='_srcrpmdir $(srctree)'
104
105# binrpm-pkg
106# ---------------------------------------------------------------------------
107PHONY += binrpm-pkg
108binrpm-pkg:
109	$(MAKE) -f $(srctree)/Makefile
110	$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
111	+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
112		$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
113
114PHONY += deb-pkg
115deb-pkg: linux.tar.gz
116	$(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
117	origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\
118		cp linux.tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz
119	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
120		--build=source,binary --source-option=-sP -nc -us -uc
121
122PHONY += bindeb-pkg
123bindeb-pkg:
124	$(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
125	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
126
127PHONY += intdeb-pkg
128intdeb-pkg:
129	+$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
130
131# snap-pkg
132# ---------------------------------------------------------------------------
133PHONY += snap-pkg
134snap-pkg:
135	rm -rf $(objtree)/snap
136	mkdir $(objtree)/snap
137	$(MAKE) clean
138	$(call cmd,src_tar,$(KERNELPATH))
139	sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
140		s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
141		$(srctree)/scripts/package/snapcraft.template > \
142		$(objtree)/snap/snapcraft.yaml
143	cd $(objtree)/snap && \
144	snapcraft --target-arch=$(UTS_MACHINE)
145
146# tarball targets
147# ---------------------------------------------------------------------------
148tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg tarzst-pkg
149PHONY += $(tar-pkgs)
150$(tar-pkgs):
151	$(MAKE) -f $(srctree)/Makefile
152	+$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
153
154# perf-pkg - generate a source tarball with perf source
155# ---------------------------------------------------------------------------
156
157perf-tar=perf-$(KERNELVERSION)
158
159quiet_cmd_perf_tar = TAR
160      cmd_perf_tar = \
161git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/         \
162	HEAD^{tree} $$(cd $(srctree);                               \
163		       echo $$(cat tools/perf/MANIFEST)) \
164	-o $(perf-tar).tar;                                         \
165mkdir -p $(perf-tar);                                               \
166git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD;    \
167(cd $(srctree)/tools/perf;                                          \
168util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/);              \
169tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
170rm -r $(perf-tar);                                                  \
171$(if $(findstring tar-src,$@),,                                     \
172$(if $(findstring bz2,$@),$(KBZIP2),                                 \
173$(if $(findstring gz,$@),$(KGZIP),                                  \
174$(if $(findstring xz,$@),$(XZ),                                     \
175$(if $(findstring zst,$@),$(ZSTD),                                  \
176$(error unknown target $@)))))                                      \
177	-f -9 $(perf-tar).tar)
178
179perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \
180		 perf-tarxz-src-pkg perf-tarzst-src-pkg
181PHONY += $(perf-tar-pkgs)
182$(perf-tar-pkgs):
183	$(call cmd,perf_tar)
184
185# Help text displayed when executing 'make help'
186# ---------------------------------------------------------------------------
187PHONY += help
188help:
189	@echo '  rpm-pkg             - Build both source and binary RPM kernel packages'
190	@echo '  srcrpm-pkg          - Build only the source kernel RPM package'
191	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
192	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
193	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
194	@echo '  snap-pkg            - Build only the binary kernel snap package'
195	@echo '                        (will connect to external hosts)'
196	@echo '  dir-pkg             - Build the kernel as a plain directory structure'
197	@echo '  tar-pkg             - Build the kernel as an uncompressed tarball'
198	@echo '  targz-pkg           - Build the kernel as a gzip compressed tarball'
199	@echo '  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball'
200	@echo '  tarxz-pkg           - Build the kernel as a xz compressed tarball'
201	@echo '  tarzst-pkg          - Build the kernel as a zstd compressed tarball'
202	@echo '  perf-tar-src-pkg    - Build $(perf-tar).tar source tarball'
203	@echo '  perf-targz-src-pkg  - Build $(perf-tar).tar.gz source tarball'
204	@echo '  perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
205	@echo '  perf-tarxz-src-pkg  - Build $(perf-tar).tar.xz source tarball'
206	@echo '  perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball'
207
208PHONY += FORCE
209FORCE:
210
211.PHONY: $(PHONY)
212