]> git.ipfire.org Git - thirdparty/kernel/linux.git/blob - scripts/Makefile.package
s390/boot: rework decompressor reserved tracking
[thirdparty/kernel/linux.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
6 KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
7 KBUILD_PKG_ROOTCMD ?="fakeroot -u"
8 # Include only those top-level files that are needed by make, plus the GPL copy
9 TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
10 include init io_uring ipc kernel lib mm net rust \
11 samples scripts security sound tools usr virt \
12 .config Makefile \
13 Kbuild Kconfig COPYING $(wildcard localversion*)
14 MKSPEC := $(srctree)/scripts/package/mkspec
15
16 quiet_cmd_src_tar = TAR $(2).tar.gz
17 cmd_src_tar = \
18 if test "$(objtree)" != "$(srctree)"; then \
19 echo >&2; \
20 echo >&2 " ERROR:"; \
21 echo >&2 " Building source tarball is not possible outside the"; \
22 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \
23 echo >&2; \
24 false; \
25 fi ; \
26 tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
27 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
28
29 # .tmp_filelist .tmp_filelist_exclude
30 # ---------------------------------------------------------------------------
31
32 scripts/list-gitignored: FORCE
33 $(Q)$(MAKE) -f $(srctree)/Makefile scripts_package
34
35 # 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore,
36 # but it is definitely a generated file.
37 filechk_filelist = \
38 $< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=-
39
40 .tmp_filelist: scripts/list-gitignored FORCE
41 $(call filechk,filelist)
42
43 # tarball
44 # ---------------------------------------------------------------------------
45
46 quiet_cmd_tar = TAR $@
47 cmd_tar = tar -c -f $@ $(tar-compress-opt) $(tar-exclude-opt) \
48 --owner=0 --group=0 --sort=name \
49 --transform 's:^\.:$*:S' -C $(tar-rootdir) .
50
51 tar-rootdir := $(srctree)
52
53 %.tar:
54 $(call cmd,tar)
55
56 %.tar.gz: private tar-compress-opt := -I $(KGZIP)
57 %.tar.gz:
58 $(call cmd,tar)
59
60 %.tar.bz2: private tar-compress-opt := -I $(KBZIP2)
61 %.tar.bz2:
62 $(call cmd,tar)
63
64 %.tar.xz: private tar-compress-opt := -I $(XZ)
65 %.tar.xz:
66 $(call cmd,tar)
67
68 %.tar.zst: private tar-compress-opt := -I $(ZSTD)
69 %.tar.zst:
70 $(call cmd,tar)
71
72 # Linux source tarball
73 # ---------------------------------------------------------------------------
74
75 linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude
76 linux.tar.gz: .tmp_filelist
77
78 # rpm-pkg
79 # ---------------------------------------------------------------------------
80 PHONY += rpm-pkg
81 rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
82 rpm-pkg: srcrpm-pkg
83 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
84 --define='_smp_mflags %{nil}'
85
86 # srcrpm-pkg
87 # ---------------------------------------------------------------------------
88 PHONY += srcrpm-pkg
89 srcrpm-pkg: linux.tar.gz
90 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
91 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
92 --define='_smp_mflags %{nil}' --define='_sourcedir .' --define='_srcrpmdir .'
93
94 # binrpm-pkg
95 # ---------------------------------------------------------------------------
96 PHONY += binrpm-pkg
97 binrpm-pkg:
98 $(MAKE) -f $(srctree)/Makefile
99 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
100 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
101 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
102
103 quiet_cmd_debianize = GEN $@
104 cmd_debianize = $(srctree)/scripts/package/mkdebian
105
106 debian: FORCE
107 $(call cmd,debianize)
108
109 PHONY += debian-orig
110 debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
111 debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
112 debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
113 debian-orig: linux.tar.gz debian
114 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
115 ln -f $< ../$(orig-name); \
116 else \
117 cp $< ../$(orig-name); \
118 fi
119
120 PHONY += deb-pkg
121 deb-pkg: debian-orig
122 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
123 --build=source,binary -nc -us -uc
124
125 PHONY += bindeb-pkg
126 bindeb-pkg: debian
127 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
128
129 PHONY += intdeb-pkg
130 intdeb-pkg:
131 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
132
133 # snap-pkg
134 # ---------------------------------------------------------------------------
135 PHONY += snap-pkg
136 snap-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 # dir-pkg tar*-pkg - tarball targets
149 # ---------------------------------------------------------------------------
150
151 tar-pkg-tarball = linux-$(KERNELRELEASE)-$(ARCH).$(1)
152 tar-pkg-phony = $(subst .,,$(1))-pkg
153
154 tar-install: FORCE
155 $(Q)$(MAKE) -f $(srctree)/Makefile
156 +$(Q)$(srctree)/scripts/package/buildtar $@
157
158 PHONY += dir-pkg
159 dir-pkg: tar-install
160 @echo "Kernel tree successfully created in $<"
161
162 define tar-pkg-rule
163 PHONY += $(tar-pkg-phony)
164 $(tar-pkg-phony): $(tar-pkg-tarball)
165 @:
166
167 $(tar-pkg-tarball): private tar-rootdir := tar-install
168 $(tar-pkg-tarball): tar-install
169 endef
170
171 $(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call tar-pkg-rule,$(x))))
172
173 # perf-tar*-src-pkg - generate a source tarball with perf source
174 # ---------------------------------------------------------------------------
175
176 perf-tar-src-pkg-tarball = perf-$(KERNELVERSION).$(1)
177 perf-tar-src-pkg-phony = perf-$(subst .,,$(1))-src-pkg
178
179 quiet_cmd_stage_perf_src = STAGE $@
180 cmd_stage_perf_src = \
181 rm -rf $@; \
182 mkdir -p $@; \
183 tar -c -f - --exclude-from=$<_exclude -C $(srctree) --files-from=$(srctree)/tools/perf/MANIFEST | \
184 tar -x -f - -C $@
185
186 .tmp_perf: .tmp_filelist
187 $(call cmd,stage_perf_src)
188
189 filechk_perf_head = \
190 if test -z "$(git -C $(srctree) rev-parse --show-cdup 2>/dev/null)" && \
191 head=$$(git -C $(srctree) rev-parse --verify HEAD 2>/dev/null); then \
192 echo $$head; \
193 else \
194 echo "not a git tree"; \
195 fi
196
197 .tmp_perf/HEAD: .tmp_perf FORCE
198 $(call filechk,perf_head)
199
200 quiet_cmd_perf_version_file = GEN $@
201 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
202
203 # PERF-VERSION-FILE and HEAD are independent, but this avoids updating the
204 # timestamp of PERF-VERSION-FILE.
205 # The best is to fix tools/perf/util/PERF-VERSION-GEN.
206 .tmp_perf/PERF-VERSION-FILE: .tmp_perf/HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN
207 $(call cmd,perf_version_file)
208
209 define perf-tar-src-pkg-rule
210 PHONY += $(perf-tar-src-pkg-phony)
211 $(perf-tar-src-pkg-phony): $(perf-tar-src-pkg-tarball)
212 @:
213
214 $(perf-tar-src-pkg-tarball): private tar-rootdir := .tmp_perf
215 $(perf-tar-src-pkg-tarball): .tmp_filelist .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE
216 endef
217
218 $(foreach x, tar tar.gz tar.bz2 tar.xz tar.zst, $(eval $(call perf-tar-src-pkg-rule,$(x))))
219
220 # Help text displayed when executing 'make help'
221 # ---------------------------------------------------------------------------
222 PHONY += help
223 help:
224 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
225 @echo ' srcrpm-pkg - Build only the source kernel RPM package'
226 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
227 @echo ' deb-pkg - Build both source and binary deb kernel packages'
228 @echo ' bindeb-pkg - Build only the binary kernel deb package'
229 @echo ' snap-pkg - Build only the binary kernel snap package'
230 @echo ' (will connect to external hosts)'
231 @echo ' dir-pkg - Build the kernel as a plain directory structure'
232 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
233 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
234 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
235 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
236 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
237 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
238 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
239 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
240 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
241 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
242
243 PHONY += FORCE
244 FORCE:
245
246 .PHONY: $(PHONY)