Merge tag 'nfs-for-6.4-1' of git://git.linux-nfs.org/projects/anna/linux-nfs
[linux-block.git] / scripts / Makefile.package
CommitLineData
ec8f24b7 1# SPDX-License-Identifier: GPL-2.0-only
1da177e4 2# Makefile for the different targets used to generate full packages of a kernel
000ec95f
MY
3
4include $(srctree)/scripts/Kbuild.include
05e96e96 5include $(srctree)/scripts/Makefile.lib
1da177e4 6
e1287eb8 7KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
b41d920a 8KBUILD_PKG_ROOTCMD ?="fakeroot -u"
6615d6c3 9# Include only those top-level files that are needed by make, plus the GPL copy
a3c4d4ab 10TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
df1f1ea9
PL
11 include init io_uring ipc kernel lib mm net rust \
12 samples scripts security sound tools usr virt \
f6e09b07 13 .config Makefile \
6615d6c3 14 Kbuild Kconfig COPYING $(wildcard localversion*)
1da177e4 15MKSPEC := $(srctree)/scripts/package/mkspec
1da177e4 16
26803821
RV
17quiet_cmd_src_tar = TAR $(2).tar.gz
18 cmd_src_tar = \
19if test "$(objtree)" != "$(srctree)"; then \
262dad68
MY
20 echo >&2; \
21 echo >&2 " ERROR:"; \
22 echo >&2 " Building source tarball is not possible outside the"; \
6fc91752 23 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \
262dad68 24 echo >&2; \
26803821
RV
25 false; \
26fi ; \
e4a42c82 27tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
f6e09b07 28 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
26803821 29
05e96e96
MY
30# Git
31# ---------------------------------------------------------------------------
7bf4582d 32
05e96e96 33filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
e0ca1674 34
05e96e96
MY
35.tmp_HEAD: check-git FORCE
36 $(call filechk,HEAD)
e0ca1674 37
05e96e96
MY
38PHONY += check-git
39check-git:
40 @if ! $(srctree)/scripts/check-git; then \
41 echo >&2 "error: creating source package requires git repository"; \
42 false; \
43 fi
e0ca1674 44
f8d94c4e
MY
45git-config-tar.gz = -c tar.tar.gz.command="$(KGZIP)"
46git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
47git-config-tar.xz = -c tar.tar.xz.command="$(XZ)"
48git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
49
f6d82835 50quiet_cmd_archive = ARCHIVE $@
f8d94c4e 51 cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
9cedc5e8 52 --output=$$(realpath $@) $(archive-args)
f6d82835 53
7bf4582d
MY
54# Linux source tarball
55# ---------------------------------------------------------------------------
56
f8d94c4e
MY
57linux-tarballs := $(addprefix linux, .tar.gz)
58
59targets += $(linux-tarballs)
9cedc5e8 60$(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<)
f8d94c4e 61$(linux-tarballs): .tmp_HEAD FORCE
f6d82835 62 $(call if_changed,archive)
7bf4582d 63
1da177e4 64# rpm-pkg
0131705d 65# ---------------------------------------------------------------------------
6a4f6a26 66PHONY += rpm-pkg
1ec9bb70
MY
67rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
68rpm-pkg: srcrpm-pkg
69 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
8a16a070 70 --define='_smp_mflags %{nil}'
1da177e4 71
8818039f
IV
72# srcrpm-pkg
73# ---------------------------------------------------------------------------
74PHONY += srcrpm-pkg
6fc91752 75srcrpm-pkg: linux.tar.gz
8818039f 76 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
6fc91752 77 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
81f59a26 78 --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
8818039f 79
1da177e4 80# binrpm-pkg
0131705d 81# ---------------------------------------------------------------------------
6a4f6a26
MY
82PHONY += binrpm-pkg
83binrpm-pkg:
175209cc 84 $(MAKE) -f $(srctree)/Makefile
65013203 85 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
606625be 86 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
6105e4f6 87 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
af60e207 88
6eabebb1 89quiet_cmd_debianize = GEN $@
aa7d233f 90 cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
6eabebb1
MY
91
92debian: FORCE
93 $(call cmd,debianize)
94
95PHONY += debian-orig
96debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
97debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
98debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
aa7d233f 99debian-orig: mkdebian-opts = --need-source
6eabebb1 100debian-orig: linux.tar.gz debian
b44aa8c9
MY
101 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
102 ln -f $< ../$(orig-name); \
103 else \
104 cp $< ../$(orig-name); \
105 fi
6eabebb1 106
6a4f6a26 107PHONY += deb-pkg
6eabebb1 108deb-pkg: debian-orig
7bf4582d 109 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
e7853995 110 --build=source,binary -nc -us -uc
3716001b 111
6a4f6a26 112PHONY += bindeb-pkg
6eabebb1 113bindeb-pkg: debian
117948ac 114 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
b41d920a 115
6a4f6a26
MY
116PHONY += intdeb-pkg
117intdeb-pkg:
b41d920a 118 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
1da177e4 119
5704d455
PP
120# snap-pkg
121# ---------------------------------------------------------------------------
6a4f6a26
MY
122PHONY += snap-pkg
123snap-pkg:
5704d455
PP
124 rm -rf $(objtree)/snap
125 mkdir $(objtree)/snap
126 $(MAKE) clean
127 $(call cmd,src_tar,$(KERNELPATH))
128 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
129 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
130 $(srctree)/scripts/package/snapcraft.template > \
131 $(objtree)/snap/snapcraft.yaml
132 cd $(objtree)/snap && \
133 snapcraft --target-arch=$(UTS_MACHINE)
134
1fc90958 135# dir-pkg tar*-pkg - tarball targets
6d983fea 136# ---------------------------------------------------------------------------
1fc90958 137
1fc90958
MY
138tar-install: FORCE
139 $(Q)$(MAKE) -f $(srctree)/Makefile
140 +$(Q)$(srctree)/scripts/package/buildtar $@
141
3c65a270
MY
142compress-tar.gz = -I "$(KGZIP)"
143compress-tar.bz2 = -I "$(KBZIP2)"
144compress-tar.xz = -I "$(XZ)"
145compress-tar.zst = -I "$(ZSTD)"
146
05e96e96 147quiet_cmd_tar = TAR $@
3c65a270
MY
148 cmd_tar = cd $<; tar cf ../$@ $(compress-tar$(suffix $@)) --owner=root --group=root --sort=name *
149
150dir-tarballs := $(addprefix linux-$(KERNELRELEASE)-$(ARCH), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
05e96e96 151
3c65a270 152$(dir-tarballs): tar-install
05e96e96
MY
153 $(call cmd,tar)
154
1fc90958
MY
155PHONY += dir-pkg
156dir-pkg: tar-install
157 @echo "Kernel tree successfully created in $<"
158
05e96e96
MY
159PHONY += tar-pkg
160tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
1fc90958
MY
161 @:
162
05e96e96
MY
163tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
164 @:
6d983fea 165
e0ca1674 166# perf-tar*-src-pkg - generate a source tarball with perf source
8e5564e6
ACM
167# ---------------------------------------------------------------------------
168
05e96e96
MY
169.tmp_perf:
170 $(Q)mkdir .tmp_perf
e0ca1674 171
05e96e96
MY
172.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
173 $(call cmd,copy)
e0ca1674
MY
174
175quiet_cmd_perf_version_file = GEN $@
176 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
177
05e96e96 178# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
e0ca1674
MY
179# timestamp of PERF-VERSION-FILE.
180# The best is to fix tools/perf/util/PERF-VERSION-GEN.
05e96e96 181.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
e0ca1674
MY
182 $(call cmd,perf_version_file)
183
f6d82835 184perf-archive-args = --add-file=$$(realpath $(word 2, $^)) \
05e96e96
MY
185 --add-file=$$(realpath $(word 3, $^)) \
186 $$(cat $(word 2, $^))^{tree} $$(cat $<)
e0ca1674 187
f8d94c4e
MY
188
189perf-tarballs := $(addprefix perf-$(KERNELVERSION), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
190
191targets += $(perf-tarballs)
9cedc5e8 192$(perf-tarballs): archive-args = --prefix=perf-$(KERNELVERSION)/ $(perf-archive-args)
f8d94c4e 193$(perf-tarballs): tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
f6d82835 194 $(call if_changed,archive)
05e96e96
MY
195
196PHONY += perf-tar-src-pkg
197perf-tar-src-pkg: perf-$(KERNELVERSION).tar
198 @:
e0ca1674 199
05e96e96
MY
200perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
201 @:
8e5564e6 202
1da177e4
LT
203# Help text displayed when executing 'make help'
204# ---------------------------------------------------------------------------
6a4f6a26
MY
205PHONY += help
206help:
8e5564e6 207 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
9c9b55a5 208 @echo ' srcrpm-pkg - Build only the source kernel RPM package'
3716001b
RV
209 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
210 @echo ' deb-pkg - Build both source and binary deb kernel packages'
211 @echo ' bindeb-pkg - Build only the binary kernel deb package'
a64c0440
GU
212 @echo ' snap-pkg - Build only the binary kernel snap package'
213 @echo ' (will connect to external hosts)'
af7db99a 214 @echo ' dir-pkg - Build the kernel as a plain directory structure'
8e5564e6
ACM
215 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
216 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
217 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
9a17f400 218 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
88f5e1e6 219 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
e0ca1674
MY
220 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
221 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
222 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
223 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
224 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
000ec95f 225
7bf4582d
MY
226PHONY += FORCE
227FORCE:
228
05e96e96
MY
229# Read all saved command lines and dependencies for the $(targets) we
230# may be building above, using $(if_changed{,_dep}). As an
231# optimization, we don't need to read them if the target does not
232# exist, we will rebuild anyway in that case.
233
234existing-targets := $(wildcard $(sort $(targets)))
235
236-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
237
000ec95f 238.PHONY: $(PHONY)