Merge branch 'for-6.4/core' into for-linus
[linux-block.git] / scripts / Makefile.package
1 # SPDX-License-Identifier: GPL-2.0-only
2 # Makefile for the different targets used to generate full packages of a kernel
3
4 include $(srctree)/scripts/Kbuild.include
5 include $(srctree)/scripts/Makefile.lib
6
7 KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
8 KBUILD_PKG_ROOTCMD ?="fakeroot -u"
9 # Include only those top-level files that are needed by make, plus the GPL copy
10 TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
11                include init io_uring ipc kernel lib mm net rust \
12                samples scripts security sound tools usr virt \
13                .config Makefile \
14                Kbuild Kconfig COPYING $(wildcard localversion*)
15 MKSPEC     := $(srctree)/scripts/package/mkspec
16
17 quiet_cmd_src_tar = TAR     $(2).tar.gz
18       cmd_src_tar = \
19 if test "$(objtree)" != "$(srctree)"; then \
20         echo >&2; \
21         echo >&2 "  ERROR:"; \
22         echo >&2 "  Building source tarball is not possible outside the"; \
23         echo >&2 "  kernel source tree. Don't set KBUILD_OUTPUT"; \
24         echo >&2; \
25         false; \
26 fi ; \
27 tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
28         --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
29
30 # tarball compression
31 # ---------------------------------------------------------------------------
32
33 %.tar.gz: %.tar
34         $(call cmd,gzip)
35
36 %.tar.bz2: %.tar
37         $(call cmd,bzip2)
38
39 %.tar.xz: %.tar
40         $(call cmd,xzmisc)
41
42 %.tar.zst: %.tar
43         $(call cmd,zstd)
44
45 # Git
46 # ---------------------------------------------------------------------------
47
48 filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
49
50 .tmp_HEAD: check-git FORCE
51         $(call filechk,HEAD)
52
53 PHONY += check-git
54 check-git:
55         @if ! $(srctree)/scripts/check-git; then \
56                 echo >&2 "error: creating source package requires git repository"; \
57                 false; \
58         fi
59
60 # Linux source tarball
61 # ---------------------------------------------------------------------------
62
63 quiet_cmd_archive_linux = ARCHIVE $@
64       cmd_archive_linux = \
65         git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ $$(cat $<)
66
67 targets += linux.tar
68 linux.tar: .tmp_HEAD FORCE
69         $(call if_changed,archive_linux)
70
71 # rpm-pkg
72 # ---------------------------------------------------------------------------
73 PHONY += rpm-pkg
74 rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
75 rpm-pkg: srcrpm-pkg
76         +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
77         --define='_smp_mflags %{nil}'
78
79 # srcrpm-pkg
80 # ---------------------------------------------------------------------------
81 PHONY += srcrpm-pkg
82 srcrpm-pkg: linux.tar.gz
83         $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
84         +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
85         --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
86
87 # binrpm-pkg
88 # ---------------------------------------------------------------------------
89 PHONY += binrpm-pkg
90 binrpm-pkg:
91         $(MAKE) -f $(srctree)/Makefile
92         $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
93         +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
94                 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
95
96 quiet_cmd_debianize = GEN     $@
97       cmd_debianize = $(srctree)/scripts/package/mkdebian
98
99 debian: FORCE
100         $(call cmd,debianize)
101
102 PHONY += debian-orig
103 debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
104 debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
105 debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
106 debian-orig: linux.tar.gz debian
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
112
113 PHONY += deb-pkg
114 deb-pkg: debian-orig
115         +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
116                 --build=source,binary -nc -us -uc
117
118 PHONY += bindeb-pkg
119 bindeb-pkg: debian
120         +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
121
122 PHONY += intdeb-pkg
123 intdeb-pkg:
124         +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
125
126 # snap-pkg
127 # ---------------------------------------------------------------------------
128 PHONY += snap-pkg
129 snap-pkg:
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
141 # dir-pkg tar*-pkg - tarball targets
142 # ---------------------------------------------------------------------------
143
144 tar-install: FORCE
145         $(Q)$(MAKE) -f $(srctree)/Makefile
146         +$(Q)$(srctree)/scripts/package/buildtar $@
147
148 quiet_cmd_tar = TAR     $@
149       cmd_tar = cd $<; tar cf ../$@ --owner=root --group=root --sort=name *
150
151 linux-$(KERNELRELEASE)-$(ARCH).tar: tar-install
152         $(call cmd,tar)
153
154 PHONY += dir-pkg
155 dir-pkg: tar-install
156         @echo "Kernel tree successfully created in $<"
157
158 PHONY += tar-pkg
159 tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
160         @:
161
162 tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
163         @:
164
165 # perf-tar*-src-pkg - generate a source tarball with perf source
166 # ---------------------------------------------------------------------------
167
168 .tmp_perf:
169         $(Q)mkdir .tmp_perf
170
171 .tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
172         $(call cmd,copy)
173
174 quiet_cmd_perf_version_file = GEN     $@
175       cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
176
177 # PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
178 # timestamp of PERF-VERSION-FILE.
179 # The best is to fix tools/perf/util/PERF-VERSION-GEN.
180 .tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
181         $(call cmd,perf_version_file)
182
183 quiet_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 $<)
189
190 targets += perf-$(KERNELVERSION).tar
191 perf-$(KERNELVERSION).tar: tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
192         $(call if_changed,archive_perf)
193
194 PHONY += perf-tar-src-pkg
195 perf-tar-src-pkg: perf-$(KERNELVERSION).tar
196         @:
197
198 perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
199         @:
200
201 # Help text displayed when executing 'make help'
202 # ---------------------------------------------------------------------------
203 PHONY += help
204 help:
205         @echo '  rpm-pkg             - Build both source and binary RPM kernel packages'
206         @echo '  srcrpm-pkg          - Build only the source kernel RPM package'
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'
210         @echo '  snap-pkg            - Build only the binary kernel snap package'
211         @echo '                        (will connect to external hosts)'
212         @echo '  dir-pkg             - Build the kernel as a plain directory structure'
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'
216         @echo '  tarxz-pkg           - Build the kernel as a xz compressed tarball'
217         @echo '  tarzst-pkg          - Build the kernel as a zstd compressed tarball'
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'
223
224 PHONY += FORCE
225 FORCE:
226
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
232 existing-targets := $(wildcard $(sort $(targets)))
233
234 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
235
236 .PHONY: $(PHONY)