Documentation/llvm: Add a note about prebuilt kernel.org toolchains
[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 30# tarball compression
7bf4582d
MY
31# ---------------------------------------------------------------------------
32
05e96e96
MY
33%.tar.gz: %.tar
34 $(call cmd,gzip)
7bf4582d 35
05e96e96
MY
36%.tar.bz2: %.tar
37 $(call cmd,bzip2)
7bf4582d 38
05e96e96
MY
39%.tar.xz: %.tar
40 $(call cmd,xzmisc)
7bf4582d 41
05e96e96
MY
42%.tar.zst: %.tar
43 $(call cmd,zstd)
7bf4582d 44
05e96e96
MY
45# Git
46# ---------------------------------------------------------------------------
7bf4582d 47
05e96e96 48filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
e0ca1674 49
05e96e96
MY
50.tmp_HEAD: check-git FORCE
51 $(call filechk,HEAD)
e0ca1674 52
05e96e96
MY
53PHONY += check-git
54check-git:
55 @if ! $(srctree)/scripts/check-git; then \
56 echo >&2 "error: creating source package requires git repository"; \
57 false; \
58 fi
e0ca1674 59
7bf4582d
MY
60# Linux source tarball
61# ---------------------------------------------------------------------------
62
05e96e96
MY
63quiet_cmd_archive_linux = ARCHIVE $@
64 cmd_archive_linux = \
65 git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ $$(cat $<)
66
67targets += linux.tar
68linux.tar: .tmp_HEAD FORCE
69 $(call if_changed,archive_linux)
7bf4582d 70
1da177e4 71# rpm-pkg
0131705d 72# ---------------------------------------------------------------------------
6a4f6a26 73PHONY += rpm-pkg
1ec9bb70
MY
74rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
75rpm-pkg: srcrpm-pkg
76 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
8a16a070 77 --define='_smp_mflags %{nil}'
1da177e4 78
8818039f
IV
79# srcrpm-pkg
80# ---------------------------------------------------------------------------
81PHONY += srcrpm-pkg
6fc91752 82srcrpm-pkg: linux.tar.gz
8818039f 83 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
6fc91752 84 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
81f59a26 85 --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
8818039f 86
1da177e4 87# binrpm-pkg
0131705d 88# ---------------------------------------------------------------------------
6a4f6a26
MY
89PHONY += binrpm-pkg
90binrpm-pkg:
175209cc 91 $(MAKE) -f $(srctree)/Makefile
65013203 92 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
606625be 93 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
6105e4f6 94 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
af60e207 95
6eabebb1
MY
96quiet_cmd_debianize = GEN $@
97 cmd_debianize = $(srctree)/scripts/package/mkdebian
98
99debian: FORCE
100 $(call cmd,debianize)
101
102PHONY += debian-orig
103debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
104debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
105debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
106debian-orig: linux.tar.gz debian
b44aa8c9
MY
107 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
108 ln -f $< ../$(orig-name); \
109 else \
110 cp $< ../$(orig-name); \
111 fi
6eabebb1 112
6a4f6a26 113PHONY += deb-pkg
6eabebb1 114deb-pkg: debian-orig
7bf4582d 115 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
e7853995 116 --build=source,binary -nc -us -uc
3716001b 117
6a4f6a26 118PHONY += bindeb-pkg
6eabebb1 119bindeb-pkg: debian
117948ac 120 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
b41d920a 121
6a4f6a26
MY
122PHONY += intdeb-pkg
123intdeb-pkg:
b41d920a 124 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
1da177e4 125
5704d455
PP
126# snap-pkg
127# ---------------------------------------------------------------------------
6a4f6a26
MY
128PHONY += snap-pkg
129snap-pkg:
5704d455
PP
130 rm -rf $(objtree)/snap
131 mkdir $(objtree)/snap
132 $(MAKE) clean
133 $(call cmd,src_tar,$(KERNELPATH))
134 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
135 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
136 $(srctree)/scripts/package/snapcraft.template > \
137 $(objtree)/snap/snapcraft.yaml
138 cd $(objtree)/snap && \
139 snapcraft --target-arch=$(UTS_MACHINE)
140
1fc90958 141# dir-pkg tar*-pkg - tarball targets
6d983fea 142# ---------------------------------------------------------------------------
1fc90958 143
1fc90958
MY
144tar-install: FORCE
145 $(Q)$(MAKE) -f $(srctree)/Makefile
146 +$(Q)$(srctree)/scripts/package/buildtar $@
147
05e96e96
MY
148quiet_cmd_tar = TAR $@
149 cmd_tar = cd $<; tar cf ../$@ --owner=root --group=root --sort=name *
150
151linux-$(KERNELRELEASE)-$(ARCH).tar: tar-install
152 $(call cmd,tar)
153
1fc90958
MY
154PHONY += dir-pkg
155dir-pkg: tar-install
156 @echo "Kernel tree successfully created in $<"
157
05e96e96
MY
158PHONY += tar-pkg
159tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
1fc90958
MY
160 @:
161
05e96e96
MY
162tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
163 @:
6d983fea 164
e0ca1674 165# perf-tar*-src-pkg - generate a source tarball with perf source
8e5564e6
ACM
166# ---------------------------------------------------------------------------
167
05e96e96
MY
168.tmp_perf:
169 $(Q)mkdir .tmp_perf
e0ca1674 170
05e96e96
MY
171.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
172 $(call cmd,copy)
e0ca1674
MY
173
174quiet_cmd_perf_version_file = GEN $@
175 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
176
05e96e96 177# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
e0ca1674
MY
178# timestamp of PERF-VERSION-FILE.
179# The best is to fix tools/perf/util/PERF-VERSION-GEN.
05e96e96 180.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
e0ca1674
MY
181 $(call cmd,perf_version_file)
182
05e96e96
MY
183quiet_cmd_archive_perf = ARCHIVE $@
184 cmd_archive_perf = \
185 git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ \
186 --add-file=$$(realpath $(word 2, $^)) \
187 --add-file=$$(realpath $(word 3, $^)) \
188 $$(cat $(word 2, $^))^{tree} $$(cat $<)
e0ca1674 189
05e96e96
MY
190targets += perf-$(KERNELVERSION).tar
191perf-$(KERNELVERSION).tar: tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
192 $(call if_changed,archive_perf)
193
194PHONY += perf-tar-src-pkg
195perf-tar-src-pkg: perf-$(KERNELVERSION).tar
196 @:
e0ca1674 197
05e96e96
MY
198perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
199 @:
8e5564e6 200
1da177e4
LT
201# Help text displayed when executing 'make help'
202# ---------------------------------------------------------------------------
6a4f6a26
MY
203PHONY += help
204help:
8e5564e6 205 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
9c9b55a5 206 @echo ' srcrpm-pkg - Build only the source kernel RPM package'
3716001b
RV
207 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
208 @echo ' deb-pkg - Build both source and binary deb kernel packages'
209 @echo ' bindeb-pkg - Build only the binary kernel deb package'
a64c0440
GU
210 @echo ' snap-pkg - Build only the binary kernel snap package'
211 @echo ' (will connect to external hosts)'
af7db99a 212 @echo ' dir-pkg - Build the kernel as a plain directory structure'
8e5564e6
ACM
213 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
214 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
215 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
9a17f400 216 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
88f5e1e6 217 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
e0ca1674
MY
218 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
219 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
220 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
221 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
222 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
000ec95f 223
7bf4582d
MY
224PHONY += FORCE
225FORCE:
226
05e96e96
MY
227# Read all saved command lines and dependencies for the $(targets) we
228# may be building above, using $(if_changed{,_dep}). As an
229# optimization, we don't need to read them if the target does not
230# exist, we will rebuild anyway in that case.
231
232existing-targets := $(wildcard $(sort $(targets)))
233
234-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
235
000ec95f 236.PHONY: $(PHONY)