blob: 92dbc889bd7c0008abc10feb4528e1b8363f8d93 [file] [log] [blame]
Thomas Gleixnerec8f24b2019-05-19 13:07:45 +01001# SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002# Makefile for the different targets used to generate full packages of a kernel
Masahiro Yamada000ec952019-08-21 16:02:04 +09003
4include $(srctree)/scripts/Kbuild.include
Masahiro Yamada05e96e92023-03-16 00:50:18 +09005include $(srctree)/scripts/Makefile.lib
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Arun Sharmae1287eb2011-05-04 13:48:11 -07007KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
Michal Marek6615d6c32013-04-12 14:12:50 +02008# Include only those top-level files that are needed by make, plus the GPL copy
Masahiro Yamadaa3c4d4a2022-09-25 03:19:09 +09009TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
Paran Leedf1f1ea2022-11-24 07:00:44 +090010 include init io_uring ipc kernel lib mm net rust \
11 samples scripts security sound tools usr virt \
Masahiro Yamadaf6e09b02023-01-22 23:14:21 +090012 .config Makefile \
Michal Marek6615d6c32013-04-12 14:12:50 +020013 Kbuild Kconfig COPYING $(wildcard localversion*)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014MKSPEC := $(srctree)/scripts/package/mkspec
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Riku Voipio26803822015-09-02 12:57:08 +030016quiet_cmd_src_tar = TAR $(2).tar.gz
17 cmd_src_tar = \
18if test "$(objtree)" != "$(srctree)"; then \
Masahiro Yamada262dad62017-12-06 19:32:57 +090019 echo >&2; \
20 echo >&2 " ERROR:"; \
21 echo >&2 " Building source tarball is not possible outside the"; \
Masahiro Yamada6fc91752023-02-15 10:20:26 +090022 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \
Masahiro Yamada262dad62017-12-06 19:32:57 +090023 echo >&2; \
Riku Voipio26803822015-09-02 12:57:08 +030024 false; \
25fi ; \
Denis Efremove4a42c82020-06-08 12:59:44 +030026tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
Masahiro Yamadaf6e09b02023-01-22 23:14:21 +090027 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
Riku Voipio26803822015-09-02 12:57:08 +030028
Masahiro Yamada05e96e92023-03-16 00:50:18 +090029# Git
Masahiro Yamada7bf45822023-02-15 10:20:24 +090030# ---------------------------------------------------------------------------
31
Masahiro Yamada05e96e92023-03-16 00:50:18 +090032filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
Masahiro Yamada7bf45822023-02-15 10:20:24 +090033
Masahiro Yamada05e96e92023-03-16 00:50:18 +090034.tmp_HEAD: check-git FORCE
35 $(call filechk,HEAD)
Masahiro Yamada7bf45822023-02-15 10:20:24 +090036
Masahiro Yamada05e96e92023-03-16 00:50:18 +090037PHONY += 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
Masahiro Yamadae0ca1672023-02-15 10:20:30 +090043
Masahiro Yamada1d29b4c2023-04-17 23:25:48 +090044git-config-tar.gz = -c tar.tar.gz.command="$(KGZIP)"
45git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
46git-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)"
47git-config-tar.xz = -c tar.tar.xz.command="$(XZ)"
48git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
Masahiro Yamadaf8d94c42023-04-07 19:16:28 +090049
Masahiro Yamadaf6d82832023-04-07 19:16:27 +090050quiet_cmd_archive = ARCHIVE $@
Masahiro Yamadaf8d94c42023-04-07 19:16:28 +090051 cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
Masahiro Yamada9cedc5e2023-04-20 02:04:24 +090052 --output=$$(realpath $@) $(archive-args)
Masahiro Yamadaf6d82832023-04-07 19:16:27 +090053
Masahiro Yamada1d29b4c2023-04-17 23:25:48 +090054suffix-gzip := .gz
55suffix-bzip2 := .bz2
56suffix-lzma := .lzma
57suffix-xz := .xz
58
Masahiro Yamada7bf45822023-02-15 10:20:24 +090059# Linux source tarball
60# ---------------------------------------------------------------------------
61
Masahiro Yamada1d29b4c2023-04-17 23:25:48 +090062linux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz)
Masahiro Yamadaf8d94c42023-04-07 19:16:28 +090063
64targets += $(linux-tarballs)
Masahiro Yamada9cedc5e2023-04-20 02:04:24 +090065$(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<)
Masahiro Yamadaf8d94c42023-04-07 19:16:28 +090066$(linux-tarballs): .tmp_HEAD FORCE
Masahiro Yamadaf6d82832023-04-07 19:16:27 +090067 $(call if_changed,archive)
Masahiro Yamada7bf45822023-02-15 10:20:24 +090068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069# rpm-pkg
Sam Ravnborg01317052006-03-08 18:39:05 +010070# ---------------------------------------------------------------------------
Masahiro Yamada6a4f6a22019-08-21 16:02:03 +090071PHONY += rpm-pkg
Masahiro Yamada1ec9bb72023-02-15 10:20:25 +090072rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
73rpm-pkg: srcrpm-pkg
74 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
Masahiro Yamada8a16a072017-09-30 10:10:11 +090075 --define='_smp_mflags %{nil}'
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Ivan Vecera88180392022-11-21 09:48:45 -050077# srcrpm-pkg
78# ---------------------------------------------------------------------------
79PHONY += srcrpm-pkg
Masahiro Yamada6fc91752023-02-15 10:20:26 +090080srcrpm-pkg: linux.tar.gz
Ivan Vecera88180392022-11-21 09:48:45 -050081 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
Masahiro Yamada6fc91752023-02-15 10:20:26 +090082 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
Masahiro Yamada81f59a22023-03-16 00:50:17 +090083 --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
Ivan Vecera88180392022-11-21 09:48:45 -050084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085# binrpm-pkg
Sam Ravnborg01317052006-03-08 18:39:05 +010086# ---------------------------------------------------------------------------
Masahiro Yamada6a4f6a22019-08-21 16:02:03 +090087PHONY += binrpm-pkg
88binrpm-pkg:
Masahiro Yamada175209c2019-02-14 12:05:14 +090089 $(MAKE) -f $(srctree)/Makefile
Michal Marek65013202013-04-13 21:21:15 +020090 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
Masahiro Yamada606625b2017-09-30 10:10:09 +090091 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
Masahiro Yamada6105e4f2022-07-14 14:02:41 +090092 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
Masahiro Yamadaaf60e202017-09-30 10:10:10 +090093
Masahiro Yamada31f735c2023-04-17 23:25:47 +090094# deb-pkg srcdeb-pkg bindeb-pkg
95# ---------------------------------------------------------------------------
96
Masahiro Yamada1d29b4c2023-04-17 23:25:48 +090097KDEB_SOURCE_COMPRESS ?= gzip
98
99supported-deb-source-compress := gzip bzip2 lzma xz
100
101PHONY += linux.tar.unsupported-deb-src-compress
102linux.tar.unsupported-deb-src-compress:
103 @echo "error: KDEB_SOURCE_COMPRESS=$(KDEB_SOURCE_COMPRESS) is not supported. The supported values are: $(supported-deb-source-compress)" >&2
104 @false
105
106debian-orig-suffix := \
107 $(strip $(if $(filter $(supported-deb-source-compress), $(KDEB_SOURCE_COMPRESS)), \
108 $(suffix-$(KDEB_SOURCE_COMPRESS)),.unsupported-deb-src-compress))
109
Masahiro Yamada6eabebb2023-02-15 10:20:27 +0900110quiet_cmd_debianize = GEN $@
Masahiro Yamadaaa7d2332023-04-10 21:09:07 +0900111 cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
Masahiro Yamada6eabebb2023-02-15 10:20:27 +0900112
113debian: FORCE
114 $(call cmd,debianize)
115
116PHONY += debian-orig
117debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
118debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
Masahiro Yamada1d29b4c2023-04-17 23:25:48 +0900119debian-orig: private orig-name = $(source)_$(version).orig.tar$(debian-orig-suffix)
Masahiro Yamadaaa7d2332023-04-10 21:09:07 +0900120debian-orig: mkdebian-opts = --need-source
Masahiro Yamada1d29b4c2023-04-17 23:25:48 +0900121debian-orig: linux.tar$(debian-orig-suffix) debian
Masahiro Yamadab44aa8c2023-02-15 10:20:28 +0900122 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
123 ln -f $< ../$(orig-name); \
124 else \
125 cp $< ../$(orig-name); \
126 fi
Masahiro Yamada6eabebb2023-02-15 10:20:27 +0900127
Masahiro Yamada31f735c2023-04-17 23:25:47 +0900128KBUILD_PKG_ROOTCMD ?= 'fakeroot -u'
Riku Voipio37160012015-09-02 12:57:24 +0300129
Masahiro Yamada31f735c2023-04-17 23:25:47 +0900130PHONY += deb-pkg srcdeb-pkg bindeb-pkg
131
132deb-pkg: private build-type := source,binary
133srcdeb-pkg: private build-type := source
134bindeb-pkg: private build-type := binary
135
136deb-pkg srcdeb-pkg: debian-orig
Masahiro Yamada6eabebb2023-02-15 10:20:27 +0900137bindeb-pkg: debian
Masahiro Yamada31f735c2023-04-17 23:25:47 +0900138deb-pkg srcdeb-pkg bindeb-pkg:
139 +$(strip dpkg-buildpackage \
140 --build=$(build-type) --no-pre-clean --unsigned-changes \
141 $(if $(findstring source, $(build-type)), \
Masahiro Yamada1d29b4c2023-04-17 23:25:48 +0900142 --unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
Masahiro Yamada31f735c2023-04-17 23:25:47 +0900143 $(if $(findstring binary, $(build-type)), \
144 -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch), \
145 --no-check-builddeps) \
146 $(DPKG_FLAGS))
Riku Voipiob41d9202018-04-05 14:22:29 +0300147
Masahiro Yamada6a4f6a22019-08-21 16:02:03 +0900148PHONY += intdeb-pkg
149intdeb-pkg:
Riku Voipiob41d9202018-04-05 14:22:29 +0300150 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Paolo Pisati5704d452017-11-27 12:07:34 +0100152# snap-pkg
153# ---------------------------------------------------------------------------
Masahiro Yamada6a4f6a22019-08-21 16:02:03 +0900154PHONY += snap-pkg
155snap-pkg:
Paolo Pisati5704d452017-11-27 12:07:34 +0100156 rm -rf $(objtree)/snap
157 mkdir $(objtree)/snap
158 $(MAKE) clean
159 $(call cmd,src_tar,$(KERNELPATH))
160 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
161 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
162 $(srctree)/scripts/package/snapcraft.template > \
163 $(objtree)/snap/snapcraft.yaml
164 cd $(objtree)/snap && \
165 snapcraft --target-arch=$(UTS_MACHINE)
166
Masahiro Yamada1fc90952023-02-15 10:20:31 +0900167# dir-pkg tar*-pkg - tarball targets
Jan-Benedict Glaw6d983fe2005-05-24 11:27:37 +0200168# ---------------------------------------------------------------------------
Masahiro Yamada1fc90952023-02-15 10:20:31 +0900169
Masahiro Yamada1fc90952023-02-15 10:20:31 +0900170tar-install: FORCE
171 $(Q)$(MAKE) -f $(srctree)/Makefile
172 +$(Q)$(srctree)/scripts/package/buildtar $@
173
Masahiro Yamada3c65a272023-04-07 19:16:29 +0900174compress-tar.gz = -I "$(KGZIP)"
175compress-tar.bz2 = -I "$(KBZIP2)"
176compress-tar.xz = -I "$(XZ)"
177compress-tar.zst = -I "$(ZSTD)"
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900178
Masahiro Yamada3c65a272023-04-07 19:16:29 +0900179quiet_cmd_tar = TAR $@
180 cmd_tar = cd $<; tar cf ../$@ $(compress-tar$(suffix $@)) --owner=root --group=root --sort=name *
181
182dir-tarballs := $(addprefix linux-$(KERNELRELEASE)-$(ARCH), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
183
184$(dir-tarballs): tar-install
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900185 $(call cmd,tar)
186
Masahiro Yamada1fc90952023-02-15 10:20:31 +0900187PHONY += dir-pkg
188dir-pkg: tar-install
189 @echo "Kernel tree successfully created in $<"
190
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900191PHONY += tar-pkg
192tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
Masahiro Yamada1fc90952023-02-15 10:20:31 +0900193 @:
194
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900195tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
196 @:
Jan-Benedict Glaw6d983fe2005-05-24 11:27:37 +0200197
Masahiro Yamadae0ca1672023-02-15 10:20:30 +0900198# perf-tar*-src-pkg - generate a source tarball with perf source
Arnaldo Carvalho de Melo8e5564e2010-05-31 11:13:21 -0300199# ---------------------------------------------------------------------------
200
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900201.tmp_perf:
202 $(Q)mkdir .tmp_perf
Arnaldo Carvalho de Melo8e5564e2010-05-31 11:13:21 -0300203
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900204.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
205 $(call cmd,copy)
Masahiro Yamadae0ca1672023-02-15 10:20:30 +0900206
207quiet_cmd_perf_version_file = GEN $@
208 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
209
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900210# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
Masahiro Yamadae0ca1672023-02-15 10:20:30 +0900211# timestamp of PERF-VERSION-FILE.
212# The best is to fix tools/perf/util/PERF-VERSION-GEN.
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900213.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
Masahiro Yamadae0ca1672023-02-15 10:20:30 +0900214 $(call cmd,perf_version_file)
215
Masahiro Yamadaf6d82832023-04-07 19:16:27 +0900216perf-archive-args = --add-file=$$(realpath $(word 2, $^)) \
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900217 --add-file=$$(realpath $(word 3, $^)) \
218 $$(cat $(word 2, $^))^{tree} $$(cat $<)
219
Masahiro Yamadaf8d94c42023-04-07 19:16:28 +0900220
221perf-tarballs := $(addprefix perf-$(KERNELVERSION), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
222
223targets += $(perf-tarballs)
Masahiro Yamada9cedc5e2023-04-20 02:04:24 +0900224$(perf-tarballs): archive-args = --prefix=perf-$(KERNELVERSION)/ $(perf-archive-args)
Masahiro Yamadaf8d94c42023-04-07 19:16:28 +0900225$(perf-tarballs): tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
Masahiro Yamadaf6d82832023-04-07 19:16:27 +0900226 $(call if_changed,archive)
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900227
228PHONY += perf-tar-src-pkg
229perf-tar-src-pkg: perf-$(KERNELVERSION).tar
Masahiro Yamadae0ca1672023-02-15 10:20:30 +0900230 @:
231
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900232perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
233 @:
Arnaldo Carvalho de Melo8e5564e2010-05-31 11:13:21 -0300234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235# Help text displayed when executing 'make help'
236# ---------------------------------------------------------------------------
Masahiro Yamada6a4f6a22019-08-21 16:02:03 +0900237PHONY += help
238help:
Arnaldo Carvalho de Melo8e5564e2010-05-31 11:13:21 -0300239 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
Jun ASAKA9c9b55a2022-12-27 17:21:57 +0800240 @echo ' srcrpm-pkg - Build only the source kernel RPM package'
Riku Voipio37160012015-09-02 12:57:24 +0300241 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
242 @echo ' deb-pkg - Build both source and binary deb kernel packages'
Masahiro Yamada31f735c2023-04-17 23:25:47 +0900243 @echo ' srcdeb-pkg - Build only the source kernel deb package'
Riku Voipio37160012015-09-02 12:57:24 +0300244 @echo ' bindeb-pkg - Build only the binary kernel deb package'
Geert Uytterhoevena64c0442019-10-25 13:52:32 +0200245 @echo ' snap-pkg - Build only the binary kernel snap package'
246 @echo ' (will connect to external hosts)'
Matteo Croceaf7db992019-11-04 14:11:44 +0100247 @echo ' dir-pkg - Build the kernel as a plain directory structure'
Arnaldo Carvalho de Melo8e5564e2010-05-31 11:13:21 -0300248 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
249 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
250 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
Zdenek Kaspar9a17f402011-01-30 12:18:51 +0100251 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
Paweł Jasiak88f5e1e2021-10-08 13:37:59 +0200252 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
Masahiro Yamadae0ca1672023-02-15 10:20:30 +0900253 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
254 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
255 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
256 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
257 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
Masahiro Yamada000ec952019-08-21 16:02:04 +0900258
Masahiro Yamada7bf45822023-02-15 10:20:24 +0900259PHONY += FORCE
260FORCE:
261
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900262# Read all saved command lines and dependencies for the $(targets) we
263# may be building above, using $(if_changed{,_dep}). As an
264# optimization, we don't need to read them if the target does not
265# exist, we will rebuild anyway in that case.
266
267existing-targets := $(wildcard $(sort $(targets)))
268
269-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
270
Masahiro Yamada000ec952019-08-21 16:02:04 +0900271.PHONY: $(PHONY)