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