xref: /linux/scripts/Makefile.package (revision a33ab3f94f510b5bc6b74b2d1e9bc585391c2861)
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
705e96e96SMasahiro Yamada# Git
87bf4582dSMasahiro Yamada# ---------------------------------------------------------------------------
97bf4582dSMasahiro Yamada
1005e96e96SMasahiro Yamadafilechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
117bf4582dSMasahiro Yamada
1205e96e96SMasahiro Yamada.tmp_HEAD: check-git FORCE
1305e96e96SMasahiro Yamada	$(call filechk,HEAD)
147bf4582dSMasahiro Yamada
1505e96e96SMasahiro YamadaPHONY += check-git
1605e96e96SMasahiro Yamadacheck-git:
1705e96e96SMasahiro Yamada	@if ! $(srctree)/scripts/check-git; then \
1805e96e96SMasahiro Yamada		echo >&2 "error: creating source package requires git repository"; \
1905e96e96SMasahiro Yamada		false; \
2005e96e96SMasahiro Yamada	fi
21e0ca1674SMasahiro Yamada
22f8d94c4eSMasahiro Yamadagit-config-tar.gz   = -c tar.tar.gz.command="$(KGZIP)"
23f8d94c4eSMasahiro Yamadagit-config-tar.bz2  = -c tar.tar.bz2.command="$(KBZIP2)"
241d29b4c2SMasahiro Yamadagit-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)"
25f8d94c4eSMasahiro Yamadagit-config-tar.xz   = -c tar.tar.xz.command="$(XZ)"
26f8d94c4eSMasahiro Yamadagit-config-tar.zst  = -c tar.tar.zst.command="$(ZSTD)"
27f8d94c4eSMasahiro Yamada
28f6d82835SMasahiro Yamadaquiet_cmd_archive = ARCHIVE $@
29f8d94c4eSMasahiro Yamada      cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
309cedc5e8SMasahiro Yamada                    --output=$$(realpath $@) $(archive-args)
31f6d82835SMasahiro Yamada
321d29b4c2SMasahiro Yamadasuffix-gzip  := .gz
331d29b4c2SMasahiro Yamadasuffix-bzip2 := .bz2
341d29b4c2SMasahiro Yamadasuffix-lzma  := .lzma
351d29b4c2SMasahiro Yamadasuffix-xz    := .xz
361d29b4c2SMasahiro Yamada
377bf4582dSMasahiro Yamada# Linux source tarball
387bf4582dSMasahiro Yamada# ---------------------------------------------------------------------------
397bf4582dSMasahiro Yamada
401d29b4c2SMasahiro Yamadalinux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz)
41f8d94c4eSMasahiro Yamada
42f8d94c4eSMasahiro Yamadatargets += $(linux-tarballs)
439cedc5e8SMasahiro Yamada$(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<)
44f8d94c4eSMasahiro Yamada$(linux-tarballs): .tmp_HEAD FORCE
45f6d82835SMasahiro Yamada	$(call if_changed,archive)
467bf4582dSMasahiro Yamada
4737477496SMasahiro Yamada# rpm-pkg srcrpm-pkg binrpm-pkg
48000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
49000ec95fSMasahiro Yamada
5037477496SMasahiro Yamadaquiet_cmd_mkspec = GEN     $@
51ffa46bbcSMasahiro Yamada      cmd_mkspec = $(srctree)/scripts/package/mkspec $@
528818039fSIvan Vecera
53ffa46bbcSMasahiro Yamadarpmbuild/SPECS/kernel.spec: FORCE
5437477496SMasahiro Yamada	$(call cmd,mkspec)
5537477496SMasahiro Yamada
5637477496SMasahiro YamadaPHONY += rpm-sources
5737477496SMasahiro Yamadarpm-sources: linux.tar.gz
5837477496SMasahiro Yamada	$(Q)mkdir -p rpmbuild/SOURCES
5937477496SMasahiro Yamada	$(Q)ln -f linux.tar.gz rpmbuild/SOURCES/linux.tar.gz
6037477496SMasahiro Yamada	$(Q)cp $(KCONFIG_CONFIG) rpmbuild/SOURCES/config
6137477496SMasahiro Yamada	$(Q)$(srctree)/scripts/package/gen-diff-patch rpmbuild/SOURCES/diff.patch
6237477496SMasahiro Yamada
6337477496SMasahiro YamadaPHONY += rpm-pkg srcrpm-pkg binrpm-pkg
6437477496SMasahiro Yamada
65*cb08a026SMasahiro Yamadaifneq ($(CC),$(HOSTCC))
66*cb08a026SMasahiro Yamadarpm-no-devel = --without=devel
67*cb08a026SMasahiro Yamadaendif
68*cb08a026SMasahiro Yamada
6937477496SMasahiro Yamadarpm-pkg:    private build-type := a
7037477496SMasahiro Yamadasrcrpm-pkg: private build-type := s
7137477496SMasahiro Yamadabinrpm-pkg: private build-type := b
7237477496SMasahiro Yamada
7337477496SMasahiro Yamadarpm-pkg srcrpm-pkg: rpm-sources
74ffa46bbcSMasahiro Yamadarpm-pkg srcrpm-pkg binrpm-pkg: rpmbuild/SPECS/kernel.spec
75ffa46bbcSMasahiro Yamada	+$(strip rpmbuild -b$(build-type) rpmbuild/SPECS/kernel.spec \
7637477496SMasahiro Yamada	--define='_topdir $(abspath rpmbuild)' \
7737477496SMasahiro Yamada	$(if $(filter a b, $(build-type)), \
78783c55aeSMasahiro Yamada		--target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}' \
79*cb08a026SMasahiro Yamada		$$(rpm -q rpm >/dev/null 2>&1 || echo --nodeps) \
80*cb08a026SMasahiro Yamada		$(rpm-no-devel)) \
8137477496SMasahiro Yamada	$(RPMOPTS))
82000ec95fSMasahiro Yamada
8331f735c6SMasahiro Yamada# deb-pkg srcdeb-pkg bindeb-pkg
8431f735c6SMasahiro Yamada# ---------------------------------------------------------------------------
8531f735c6SMasahiro Yamada
861d29b4c2SMasahiro YamadaKDEB_SOURCE_COMPRESS ?= gzip
871d29b4c2SMasahiro Yamada
881d29b4c2SMasahiro Yamadasupported-deb-source-compress := gzip bzip2 lzma xz
891d29b4c2SMasahiro Yamada
901d29b4c2SMasahiro YamadaPHONY += linux.tar.unsupported-deb-src-compress
911d29b4c2SMasahiro Yamadalinux.tar.unsupported-deb-src-compress:
921d29b4c2SMasahiro Yamada	@echo "error: KDEB_SOURCE_COMPRESS=$(KDEB_SOURCE_COMPRESS) is not supported. The supported values are: $(supported-deb-source-compress)" >&2
931d29b4c2SMasahiro Yamada	@false
941d29b4c2SMasahiro Yamada
951d29b4c2SMasahiro Yamadadebian-orig-suffix := \
961d29b4c2SMasahiro Yamada    $(strip $(if $(filter $(supported-deb-source-compress), $(KDEB_SOURCE_COMPRESS)), \
971d29b4c2SMasahiro Yamada    $(suffix-$(KDEB_SOURCE_COMPRESS)),.unsupported-deb-src-compress))
981d29b4c2SMasahiro Yamada
996eabebb1SMasahiro Yamadaquiet_cmd_debianize = GEN     $@
100aa7d233fSMasahiro Yamada      cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
1016eabebb1SMasahiro Yamada
1026eabebb1SMasahiro Yamadadebian: FORCE
1036eabebb1SMasahiro Yamada	$(call cmd,debianize)
1046eabebb1SMasahiro Yamada
1056eabebb1SMasahiro YamadaPHONY += debian-orig
1066eabebb1SMasahiro Yamadadebian-orig: private source = $(shell dpkg-parsechangelog -S Source)
1076eabebb1SMasahiro Yamadadebian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
1081d29b4c2SMasahiro Yamadadebian-orig: private orig-name = $(source)_$(version).orig.tar$(debian-orig-suffix)
109aa7d233fSMasahiro Yamadadebian-orig: mkdebian-opts = --need-source
1101d29b4c2SMasahiro Yamadadebian-orig: linux.tar$(debian-orig-suffix) debian
111c6156653SThayne Harbaugh	$(Q)if [ "$$(df  --output=target .. 2>/dev/null)" = "$$(df --output=target $< 2>/dev/null)" ]; then \
112b44aa8c9SMasahiro Yamada		ln -f $< ../$(orig-name); \
113b44aa8c9SMasahiro Yamada	else \
114b44aa8c9SMasahiro Yamada		cp $< ../$(orig-name); \
115b44aa8c9SMasahiro Yamada	fi
1166eabebb1SMasahiro Yamada
11731f735c6SMasahiro YamadaPHONY += deb-pkg srcdeb-pkg bindeb-pkg
11831f735c6SMasahiro Yamada
11931f735c6SMasahiro Yamadadeb-pkg:    private build-type := source,binary
12031f735c6SMasahiro Yamadasrcdeb-pkg: private build-type := source
12131f735c6SMasahiro Yamadabindeb-pkg: private build-type := binary
12231f735c6SMasahiro Yamada
12331f735c6SMasahiro Yamadadeb-pkg srcdeb-pkg: debian-orig
1246eabebb1SMasahiro Yamadabindeb-pkg: debian
12531f735c6SMasahiro Yamadadeb-pkg srcdeb-pkg bindeb-pkg:
12631f735c6SMasahiro Yamada	+$(strip dpkg-buildpackage \
12731f735c6SMasahiro Yamada	--build=$(build-type) --no-pre-clean --unsigned-changes \
12831f735c6SMasahiro Yamada	$(if $(findstring source, $(build-type)), \
1291d29b4c2SMasahiro Yamada		--unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
13031f735c6SMasahiro Yamada	$(if $(findstring binary, $(build-type)), \
13153243e09SMasahiro Yamada		-R'$(MAKE) -f debian/rules' -j1 -a$$(cat debian/arch), \
13231f735c6SMasahiro Yamada		--no-check-builddeps) \
13331f735c6SMasahiro Yamada	$(DPKG_FLAGS))
134000ec95fSMasahiro Yamada
135000ec95fSMasahiro Yamada# snap-pkg
136000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
137000ec95fSMasahiro YamadaPHONY += snap-pkg
138000ec95fSMasahiro Yamadasnap-pkg:
139000ec95fSMasahiro Yamada	rm -rf $(objtree)/snap
140000ec95fSMasahiro Yamada	mkdir $(objtree)/snap
141000ec95fSMasahiro Yamada	$(MAKE) clean
142000ec95fSMasahiro Yamada	sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
143e2bad142SMasahiro Yamada		s@SRCTREE@$(realpath $(srctree))@" \
144000ec95fSMasahiro Yamada		$(srctree)/scripts/package/snapcraft.template > \
145000ec95fSMasahiro Yamada		$(objtree)/snap/snapcraft.yaml
146000ec95fSMasahiro Yamada	cd $(objtree)/snap && \
147000ec95fSMasahiro Yamada	snapcraft --target-arch=$(UTS_MACHINE)
148000ec95fSMasahiro Yamada
149c8578539SThomas Weißschuh# pacman-pkg
150c8578539SThomas Weißschuh# ---------------------------------------------------------------------------
151c8578539SThomas Weißschuh
152c8578539SThomas WeißschuhPHONY += pacman-pkg
153c8578539SThomas Weißschuhpacman-pkg:
154c8578539SThomas Weißschuh	@ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD
1555b000f3cSMasahiro Yamada	+BUILDDIR="$(realpath $(objtree))/pacman" \
156c8578539SThomas Weißschuh		CARCH="$(UTS_MACHINE)" \
157c8578539SThomas Weißschuh		KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
158c8578539SThomas Weißschuh		KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
159c8578539SThomas Weißschuh		makepkg $(MAKEPKGOPTS)
160c8578539SThomas Weißschuh
1611fc90958SMasahiro Yamada# dir-pkg tar*-pkg - tarball targets
162000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
1631fc90958SMasahiro Yamada
1641fc90958SMasahiro Yamadatar-install: FORCE
1651fc90958SMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/Makefile
1661fc90958SMasahiro Yamada	+$(Q)$(srctree)/scripts/package/buildtar $@
1671fc90958SMasahiro Yamada
1683c65a270SMasahiro Yamadacompress-tar.gz  = -I "$(KGZIP)"
1693c65a270SMasahiro Yamadacompress-tar.bz2 = -I "$(KBZIP2)"
1703c65a270SMasahiro Yamadacompress-tar.xz  = -I "$(XZ)"
1713c65a270SMasahiro Yamadacompress-tar.zst = -I "$(ZSTD)"
17205e96e96SMasahiro Yamada
1733c65a270SMasahiro Yamadaquiet_cmd_tar = TAR     $@
1743c65a270SMasahiro Yamada      cmd_tar = cd $<; tar cf ../$@ $(compress-tar$(suffix $@)) --owner=root --group=root --sort=name *
1753c65a270SMasahiro Yamada
1763c65a270SMasahiro Yamadadir-tarballs := $(addprefix linux-$(KERNELRELEASE)-$(ARCH), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
1773c65a270SMasahiro Yamada
1783c65a270SMasahiro Yamada$(dir-tarballs): tar-install
17905e96e96SMasahiro Yamada	$(call cmd,tar)
18005e96e96SMasahiro Yamada
1811fc90958SMasahiro YamadaPHONY += dir-pkg
1821fc90958SMasahiro Yamadadir-pkg: tar-install
1831fc90958SMasahiro Yamada	@echo "Kernel tree successfully created in $<"
1841fc90958SMasahiro Yamada
18505e96e96SMasahiro YamadaPHONY += tar-pkg
18605e96e96SMasahiro Yamadatar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
1871fc90958SMasahiro Yamada	@:
1881fc90958SMasahiro Yamada
18905e96e96SMasahiro Yamadatar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
19005e96e96SMasahiro Yamada	@:
191000ec95fSMasahiro Yamada
192e0ca1674SMasahiro Yamada# perf-tar*-src-pkg - generate a source tarball with perf source
193000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
194000ec95fSMasahiro Yamada
19505e96e96SMasahiro Yamada.tmp_perf:
19605e96e96SMasahiro Yamada	$(Q)mkdir .tmp_perf
197000ec95fSMasahiro Yamada
19805e96e96SMasahiro Yamada.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
19905e96e96SMasahiro Yamada	$(call cmd,copy)
200e0ca1674SMasahiro Yamada
201e0ca1674SMasahiro Yamadaquiet_cmd_perf_version_file = GEN     $@
202e0ca1674SMasahiro Yamada      cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
203e0ca1674SMasahiro Yamada
20405e96e96SMasahiro Yamada# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
205e0ca1674SMasahiro Yamada# timestamp of PERF-VERSION-FILE.
206e0ca1674SMasahiro Yamada# The best is to fix tools/perf/util/PERF-VERSION-GEN.
20705e96e96SMasahiro Yamada.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
208e0ca1674SMasahiro Yamada	$(call cmd,perf_version_file)
209e0ca1674SMasahiro Yamada
210f6d82835SMasahiro Yamadaperf-archive-args = --add-file=$$(realpath $(word 2, $^)) \
21105e96e96SMasahiro Yamada	--add-file=$$(realpath $(word 3, $^)) \
21205e96e96SMasahiro Yamada	$$(cat $(word 2, $^))^{tree} $$(cat $<)
21305e96e96SMasahiro Yamada
214f8d94c4eSMasahiro Yamada
215f8d94c4eSMasahiro Yamadaperf-tarballs := $(addprefix perf-$(KERNELVERSION), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
216f8d94c4eSMasahiro Yamada
217f8d94c4eSMasahiro Yamadatargets += $(perf-tarballs)
2189cedc5e8SMasahiro Yamada$(perf-tarballs): archive-args = --prefix=perf-$(KERNELVERSION)/ $(perf-archive-args)
219f8d94c4eSMasahiro Yamada$(perf-tarballs): tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
220f6d82835SMasahiro Yamada	$(call if_changed,archive)
22105e96e96SMasahiro Yamada
22205e96e96SMasahiro YamadaPHONY += perf-tar-src-pkg
22305e96e96SMasahiro Yamadaperf-tar-src-pkg: perf-$(KERNELVERSION).tar
224e0ca1674SMasahiro Yamada	@:
225e0ca1674SMasahiro Yamada
22605e96e96SMasahiro Yamadaperf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
22705e96e96SMasahiro Yamada	@:
228000ec95fSMasahiro Yamada
229000ec95fSMasahiro Yamada# Help text displayed when executing 'make help'
230000ec95fSMasahiro Yamada# ---------------------------------------------------------------------------
231000ec95fSMasahiro YamadaPHONY += help
232000ec95fSMasahiro Yamadahelp:
233000ec95fSMasahiro Yamada	@echo '  rpm-pkg             - Build both source and binary RPM kernel packages'
2349c9b55a5SJun ASAKA	@echo '  srcrpm-pkg          - Build only the source kernel RPM package'
235000ec95fSMasahiro Yamada	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
236000ec95fSMasahiro Yamada	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
23731f735c6SMasahiro Yamada	@echo '  srcdeb-pkg          - Build only the source kernel deb package'
238000ec95fSMasahiro Yamada	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
239a64c0440SGeert Uytterhoeven	@echo '  snap-pkg            - Build only the binary kernel snap package'
240a64c0440SGeert Uytterhoeven	@echo '                        (will connect to external hosts)'
241c8578539SThomas Weißschuh	@echo '  pacman-pkg          - Build only the binary kernel pacman package'
242af7db99aSMatteo Croce	@echo '  dir-pkg             - Build the kernel as a plain directory structure'
243000ec95fSMasahiro Yamada	@echo '  tar-pkg             - Build the kernel as an uncompressed tarball'
244000ec95fSMasahiro Yamada	@echo '  targz-pkg           - Build the kernel as a gzip compressed tarball'
245000ec95fSMasahiro Yamada	@echo '  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball'
246000ec95fSMasahiro Yamada	@echo '  tarxz-pkg           - Build the kernel as a xz compressed tarball'
24788f5e1e6SPaweł Jasiak	@echo '  tarzst-pkg          - Build the kernel as a zstd compressed tarball'
248e0ca1674SMasahiro Yamada	@echo '  perf-tar-src-pkg    - Build the perf source tarball with no compression'
249e0ca1674SMasahiro Yamada	@echo '  perf-targz-src-pkg  - Build the perf source tarball with gzip compression'
250e0ca1674SMasahiro Yamada	@echo '  perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
251e0ca1674SMasahiro Yamada	@echo '  perf-tarxz-src-pkg  - Build the perf source tarball with xz compression'
252e0ca1674SMasahiro Yamada	@echo '  perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
253000ec95fSMasahiro Yamada
2547bf4582dSMasahiro YamadaPHONY += FORCE
2557bf4582dSMasahiro YamadaFORCE:
2567bf4582dSMasahiro Yamada
25705e96e96SMasahiro Yamada# Read all saved command lines and dependencies for the $(targets) we
25805e96e96SMasahiro Yamada# may be building above, using $(if_changed{,_dep}). As an
25905e96e96SMasahiro Yamada# optimization, we don't need to read them if the target does not
26005e96e96SMasahiro Yamada# exist, we will rebuild anyway in that case.
26105e96e96SMasahiro Yamada
26205e96e96SMasahiro Yamadaexisting-targets := $(wildcard $(sort $(targets)))
26305e96e96SMasahiro Yamada
26405e96e96SMasahiro Yamada-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
26505e96e96SMasahiro Yamada
266000ec95fSMasahiro Yamada.PHONY: $(PHONY)
267