xref: /linux/scripts/Makefile.package (revision 3c65a2704cdd2a0cd0766352e587bae4a6268155)
1000ec95fSMasahiro Yamada# SPDX-License-Identifier: GPL-2.0-only
2000ec95fSMasahiro Yamada# Makefile for the different targets used to generate full packages of a kernel
3000ec95fSMasahiro Yamada
4000ec95fSMasahiro Yamadainclude $(srctree)/scripts/Kbuild.include
505e96e96SMasahiro Yamadainclude $(srctree)/scripts/Makefile.lib
6000ec95fSMasahiro Yamada
7000ec95fSMasahiro YamadaKERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
8000ec95fSMasahiro YamadaKBUILD_PKG_ROOTCMD ?="fakeroot -u"
9000ec95fSMasahiro Yamada# Include only those top-level files that are needed by make, plus the GPL copy
10a3c4d4abSMasahiro YamadaTAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \
11df1f1ea9SParan Lee               include init io_uring ipc kernel lib mm net rust \
12df1f1ea9SParan Lee               samples scripts security sound tools usr virt \
13f6e09b07SMasahiro Yamada               .config Makefile \
14000ec95fSMasahiro Yamada               Kbuild Kconfig COPYING $(wildcard localversion*)
15000ec95fSMasahiro YamadaMKSPEC     := $(srctree)/scripts/package/mkspec
16000ec95fSMasahiro Yamada
17000ec95fSMasahiro Yamadaquiet_cmd_src_tar = TAR     $(2).tar.gz
18000ec95fSMasahiro Yamada      cmd_src_tar = \
19000ec95fSMasahiro Yamadaif test "$(objtree)" != "$(srctree)"; then \
20000ec95fSMasahiro Yamada	echo >&2; \
21000ec95fSMasahiro Yamada	echo >&2 "  ERROR:"; \
22000ec95fSMasahiro Yamada	echo >&2 "  Building source tarball is not possible outside the"; \
236fc91752SMasahiro Yamada	echo >&2 "  kernel source tree. Don't set KBUILD_OUTPUT"; \
24000ec95fSMasahiro Yamada	echo >&2; \
25000ec95fSMasahiro Yamada	false; \
26000ec95fSMasahiro Yamadafi ; \
27e4a42c82SDenis Efremovtar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
28f6e09b07SMasahiro Yamada	--transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3)
29000ec95fSMasahiro Yamada
3005e96e96SMasahiro Yamada# Git
317bf4582dSMasahiro Yamada# ---------------------------------------------------------------------------
327bf4582dSMasahiro Yamada
3305e96e96SMasahiro Yamadafilechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
347bf4582dSMasahiro Yamada
3505e96e96SMasahiro Yamada.tmp_HEAD: check-git FORCE
3605e96e96SMasahiro Yamada	$(call filechk,HEAD)
377bf4582dSMasahiro Yamada
3805e96e96SMasahiro YamadaPHONY += check-git
3905e96e96SMasahiro Yamadacheck-git:
4005e96e96SMasahiro Yamada	@if ! $(srctree)/scripts/check-git; then \
4105e96e96SMasahiro Yamada		echo >&2 "error: creating source package requires git repository"; \
4205e96e96SMasahiro Yamada		false; \
4305e96e96SMasahiro Yamada	fi
44e0ca1674SMasahiro Yamada
45f8d94c4eSMasahiro Yamadagit-config-tar.gz  = -c tar.tar.gz.command="$(KGZIP)"
46f8d94c4eSMasahiro Yamadagit-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
47f8d94c4eSMasahiro Yamadagit-config-tar.xz  = -c tar.tar.xz.command="$(XZ)"
48f8d94c4eSMasahiro Yamadagit-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
49f8d94c4eSMasahiro Yamada
50f6d82835SMasahiro Yamadaquiet_cmd_archive = ARCHIVE $@
51f8d94c4eSMasahiro Yamada      cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
52f6d82835SMasahiro Yamada                    --output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args)
53f6d82835SMasahiro Yamada
547bf4582dSMasahiro Yamada# Linux source tarball
557bf4582dSMasahiro Yamada# ---------------------------------------------------------------------------
567bf4582dSMasahiro Yamada
57f8d94c4eSMasahiro Yamadalinux-tarballs := $(addprefix linux, .tar.gz)
58f8d94c4eSMasahiro Yamada
59f8d94c4eSMasahiro Yamadatargets += $(linux-tarballs)
60f8d94c4eSMasahiro Yamada$(linux-tarballs): archive-args = $$(cat $<)
61f8d94c4eSMasahiro Yamada$(linux-tarballs): .tmp_HEAD FORCE
62f6d82835SMasahiro Yamada	$(call if_changed,archive)
637bf4582dSMasahiro Yamada
64000ec95fSMasahiro Yamada# rpm-pkg
65000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
66000ec95fSMasahiro YamadaPHONY += rpm-pkg
671ec9bb70SMasahiro Yamadarpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
681ec9bb70SMasahiro Yamadarpm-pkg: srcrpm-pkg
691ec9bb70SMasahiro Yamada	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
70000ec95fSMasahiro Yamada	--define='_smp_mflags %{nil}'
71000ec95fSMasahiro Yamada
728818039fSIvan Vecera# srcrpm-pkg
738818039fSIvan Vecera# ---------------------------------------------------------------------------
748818039fSIvan VeceraPHONY += srcrpm-pkg
756fc91752SMasahiro Yamadasrcrpm-pkg: linux.tar.gz
768818039fSIvan Vecera	$(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
776fc91752SMasahiro Yamada	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \
7881f59a26SMasahiro Yamada	--define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .'
798818039fSIvan Vecera
80000ec95fSMasahiro Yamada# binrpm-pkg
81000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
82000ec95fSMasahiro YamadaPHONY += binrpm-pkg
83000ec95fSMasahiro Yamadabinrpm-pkg:
84000ec95fSMasahiro Yamada	$(MAKE) -f $(srctree)/Makefile
85000ec95fSMasahiro Yamada	$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
86000ec95fSMasahiro Yamada	+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
876105e4f6SMasahiro Yamada		$(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec
88000ec95fSMasahiro Yamada
896eabebb1SMasahiro Yamadaquiet_cmd_debianize = GEN     $@
90aa7d233fSMasahiro Yamada      cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
916eabebb1SMasahiro Yamada
926eabebb1SMasahiro Yamadadebian: FORCE
936eabebb1SMasahiro Yamada	$(call cmd,debianize)
946eabebb1SMasahiro Yamada
956eabebb1SMasahiro YamadaPHONY += debian-orig
966eabebb1SMasahiro Yamadadebian-orig: private source = $(shell dpkg-parsechangelog -S Source)
976eabebb1SMasahiro Yamadadebian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
986eabebb1SMasahiro Yamadadebian-orig: private orig-name = $(source)_$(version).orig.tar.gz
99aa7d233fSMasahiro Yamadadebian-orig: mkdebian-opts = --need-source
1006eabebb1SMasahiro Yamadadebian-orig: linux.tar.gz debian
101b44aa8c9SMasahiro Yamada	$(Q)if [ "$(df  --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
102b44aa8c9SMasahiro Yamada		ln -f $< ../$(orig-name); \
103b44aa8c9SMasahiro Yamada	else \
104b44aa8c9SMasahiro Yamada		cp $< ../$(orig-name); \
105b44aa8c9SMasahiro Yamada	fi
1066eabebb1SMasahiro Yamada
107000ec95fSMasahiro YamadaPHONY += deb-pkg
1086eabebb1SMasahiro Yamadadeb-pkg: debian-orig
1097bf4582dSMasahiro Yamada	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
110e7853995SMasahiro Yamada		--build=source,binary -nc -us -uc
111000ec95fSMasahiro Yamada
112000ec95fSMasahiro YamadaPHONY += bindeb-pkg
1136eabebb1SMasahiro Yamadabindeb-pkg: debian
114000ec95fSMasahiro Yamada	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
115000ec95fSMasahiro Yamada
116000ec95fSMasahiro YamadaPHONY += intdeb-pkg
117000ec95fSMasahiro Yamadaintdeb-pkg:
118000ec95fSMasahiro Yamada	+$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
119000ec95fSMasahiro Yamada
120000ec95fSMasahiro Yamada# snap-pkg
121000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
122000ec95fSMasahiro YamadaPHONY += snap-pkg
123000ec95fSMasahiro Yamadasnap-pkg:
124000ec95fSMasahiro Yamada	rm -rf $(objtree)/snap
125000ec95fSMasahiro Yamada	mkdir $(objtree)/snap
126000ec95fSMasahiro Yamada	$(MAKE) clean
127000ec95fSMasahiro Yamada	$(call cmd,src_tar,$(KERNELPATH))
128000ec95fSMasahiro Yamada	sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
129000ec95fSMasahiro Yamada		s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
130000ec95fSMasahiro Yamada		$(srctree)/scripts/package/snapcraft.template > \
131000ec95fSMasahiro Yamada		$(objtree)/snap/snapcraft.yaml
132000ec95fSMasahiro Yamada	cd $(objtree)/snap && \
133000ec95fSMasahiro Yamada	snapcraft --target-arch=$(UTS_MACHINE)
134000ec95fSMasahiro Yamada
1351fc90958SMasahiro Yamada# dir-pkg tar*-pkg - tarball targets
136000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
1371fc90958SMasahiro Yamada
1381fc90958SMasahiro Yamadatar-install: FORCE
1391fc90958SMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/Makefile
1401fc90958SMasahiro Yamada	+$(Q)$(srctree)/scripts/package/buildtar $@
1411fc90958SMasahiro Yamada
142*3c65a270SMasahiro Yamadacompress-tar.gz  = -I "$(KGZIP)"
143*3c65a270SMasahiro Yamadacompress-tar.bz2 = -I "$(KBZIP2)"
144*3c65a270SMasahiro Yamadacompress-tar.xz  = -I "$(XZ)"
145*3c65a270SMasahiro Yamadacompress-tar.zst = -I "$(ZSTD)"
14605e96e96SMasahiro Yamada
147*3c65a270SMasahiro Yamadaquiet_cmd_tar = TAR     $@
148*3c65a270SMasahiro Yamada      cmd_tar = cd $<; tar cf ../$@ $(compress-tar$(suffix $@)) --owner=root --group=root --sort=name *
149*3c65a270SMasahiro Yamada
150*3c65a270SMasahiro Yamadadir-tarballs := $(addprefix linux-$(KERNELRELEASE)-$(ARCH), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
151*3c65a270SMasahiro Yamada
152*3c65a270SMasahiro Yamada$(dir-tarballs): tar-install
15305e96e96SMasahiro Yamada	$(call cmd,tar)
15405e96e96SMasahiro Yamada
1551fc90958SMasahiro YamadaPHONY += dir-pkg
1561fc90958SMasahiro Yamadadir-pkg: tar-install
1571fc90958SMasahiro Yamada	@echo "Kernel tree successfully created in $<"
1581fc90958SMasahiro Yamada
15905e96e96SMasahiro YamadaPHONY += tar-pkg
16005e96e96SMasahiro Yamadatar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
1611fc90958SMasahiro Yamada	@:
1621fc90958SMasahiro Yamada
16305e96e96SMasahiro Yamadatar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
16405e96e96SMasahiro Yamada	@:
165000ec95fSMasahiro Yamada
166e0ca1674SMasahiro Yamada# perf-tar*-src-pkg - generate a source tarball with perf source
167000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
168000ec95fSMasahiro Yamada
16905e96e96SMasahiro Yamada.tmp_perf:
17005e96e96SMasahiro Yamada	$(Q)mkdir .tmp_perf
171000ec95fSMasahiro Yamada
17205e96e96SMasahiro Yamada.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
17305e96e96SMasahiro Yamada	$(call cmd,copy)
174e0ca1674SMasahiro Yamada
175e0ca1674SMasahiro Yamadaquiet_cmd_perf_version_file = GEN     $@
176e0ca1674SMasahiro Yamada      cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
177e0ca1674SMasahiro Yamada
17805e96e96SMasahiro Yamada# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
179e0ca1674SMasahiro Yamada# timestamp of PERF-VERSION-FILE.
180e0ca1674SMasahiro Yamada# The best is to fix tools/perf/util/PERF-VERSION-GEN.
18105e96e96SMasahiro Yamada.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
182e0ca1674SMasahiro Yamada	$(call cmd,perf_version_file)
183e0ca1674SMasahiro Yamada
184f6d82835SMasahiro Yamadaperf-archive-args = --add-file=$$(realpath $(word 2, $^)) \
18505e96e96SMasahiro Yamada	--add-file=$$(realpath $(word 3, $^)) \
18605e96e96SMasahiro Yamada	$$(cat $(word 2, $^))^{tree} $$(cat $<)
18705e96e96SMasahiro Yamada
188f8d94c4eSMasahiro Yamada
189f8d94c4eSMasahiro Yamadaperf-tarballs := $(addprefix perf-$(KERNELVERSION), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
190f8d94c4eSMasahiro Yamada
191f8d94c4eSMasahiro Yamadatargets += $(perf-tarballs)
192f8d94c4eSMasahiro Yamada$(perf-tarballs): archive-args = $(perf-archive-args)
193f8d94c4eSMasahiro Yamada$(perf-tarballs): tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
194f6d82835SMasahiro Yamada	$(call if_changed,archive)
19505e96e96SMasahiro Yamada
19605e96e96SMasahiro YamadaPHONY += perf-tar-src-pkg
19705e96e96SMasahiro Yamadaperf-tar-src-pkg: perf-$(KERNELVERSION).tar
198e0ca1674SMasahiro Yamada	@:
199e0ca1674SMasahiro Yamada
20005e96e96SMasahiro Yamadaperf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
20105e96e96SMasahiro Yamada	@:
202000ec95fSMasahiro Yamada
203000ec95fSMasahiro Yamada# Help text displayed when executing 'make help'
204000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
205000ec95fSMasahiro YamadaPHONY += help
206000ec95fSMasahiro Yamadahelp:
207000ec95fSMasahiro Yamada	@echo '  rpm-pkg             - Build both source and binary RPM kernel packages'
2089c9b55a5SJun ASAKA	@echo '  srcrpm-pkg          - Build only the source kernel RPM package'
209000ec95fSMasahiro Yamada	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
210000ec95fSMasahiro Yamada	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
211000ec95fSMasahiro Yamada	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
212a64c0440SGeert Uytterhoeven	@echo '  snap-pkg            - Build only the binary kernel snap package'
213a64c0440SGeert Uytterhoeven	@echo '                        (will connect to external hosts)'
214af7db99aSMatteo Croce	@echo '  dir-pkg             - Build the kernel as a plain directory structure'
215000ec95fSMasahiro Yamada	@echo '  tar-pkg             - Build the kernel as an uncompressed tarball'
216000ec95fSMasahiro Yamada	@echo '  targz-pkg           - Build the kernel as a gzip compressed tarball'
217000ec95fSMasahiro Yamada	@echo '  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball'
218000ec95fSMasahiro Yamada	@echo '  tarxz-pkg           - Build the kernel as a xz compressed tarball'
21988f5e1e6SPaweł Jasiak	@echo '  tarzst-pkg          - Build the kernel as a zstd compressed tarball'
220e0ca1674SMasahiro Yamada	@echo '  perf-tar-src-pkg    - Build the perf source tarball with no compression'
221e0ca1674SMasahiro Yamada	@echo '  perf-targz-src-pkg  - Build the perf source tarball with gzip compression'
222e0ca1674SMasahiro Yamada	@echo '  perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
223e0ca1674SMasahiro Yamada	@echo '  perf-tarxz-src-pkg  - Build the perf source tarball with xz compression'
224e0ca1674SMasahiro Yamada	@echo '  perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
225000ec95fSMasahiro Yamada
2267bf4582dSMasahiro YamadaPHONY += FORCE
2277bf4582dSMasahiro YamadaFORCE:
2287bf4582dSMasahiro Yamada
22905e96e96SMasahiro Yamada# Read all saved command lines and dependencies for the $(targets) we
23005e96e96SMasahiro Yamada# may be building above, using $(if_changed{,_dep}). As an
23105e96e96SMasahiro Yamada# optimization, we don't need to read them if the target does not
23205e96e96SMasahiro Yamada# exist, we will rebuild anyway in that case.
23305e96e96SMasahiro Yamada
23405e96e96SMasahiro Yamadaexisting-targets := $(wildcard $(sort $(targets)))
23505e96e96SMasahiro Yamada
23605e96e96SMasahiro Yamada-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
23705e96e96SMasahiro Yamada
238000ec95fSMasahiro Yamada.PHONY: $(PHONY)
239