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