kbuild: pkg: clean up package files/dirs from the top Makefile
[linux-block.git] / scripts / package / Makefile
CommitLineData
ec8f24b7 1# SPDX-License-Identifier: GPL-2.0-only
1da177e4
LT
2# Makefile for the different targets used to generate full packages of a kernel
3# It uses the generic clean infrastructure of kbuild
4
1da177e4
LT
5# RPM target
6# ---------------------------------------------------------------------------
7# The rpm target generates two rpm files:
8# /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm
9# /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1.<arch>.rpm
10# The src.rpm files includes all source for the kernel being built
11# The <arch>.rpm includes kernel configuration, modules etc.
12#
13# Process to create the rpm files
14# a) clean the kernel
15# b) Generate .spec file
16# c) Build a tar ball, using symlink to make kernel version
17# first entry in the path
18# d) and pack the result to a tar.gz file
19# e) generate the rpm files, based on kernel.spec
20# - Use /. to avoid tar packing just the symlink
21
db9038c8
FP
22# Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT,
23# but the binrpm-pkg target can; for some reason O= gets ignored.
24
1da177e4 25# Remove hyphens since they have special meaning in RPM filenames
e1287eb8 26KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
3716001b 27KDEB_SOURCENAME ?= linux-$(KERNELRELEASE)
b41d920a 28KBUILD_PKG_ROOTCMD ?="fakeroot -u"
3716001b 29export KDEB_SOURCENAME
6615d6c3 30# Include only those top-level files that are needed by make, plus the GPL copy
26803821 31TAR_CONTENT := $(KBUILD_ALLDIRS) .config .scmversion Makefile \
6615d6c3 32 Kbuild Kconfig COPYING $(wildcard localversion*)
1da177e4 33MKSPEC := $(srctree)/scripts/package/mkspec
1da177e4 34
26803821
RV
35quiet_cmd_src_tar = TAR $(2).tar.gz
36 cmd_src_tar = \
37if test "$(objtree)" != "$(srctree)"; then \
262dad68
MY
38 echo >&2; \
39 echo >&2 " ERROR:"; \
40 echo >&2 " Building source tarball is not possible outside the"; \
41 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \
42 echo >&2 " binrpm-pkg or bindeb-pkg target instead."; \
43 echo >&2; \
26803821
RV
44 false; \
45fi ; \
46$(srctree)/scripts/setlocalversion --save-scmversion; \
26803821 47tar -cz $(RCS_TAR_IGNORE) -f $(2).tar.gz \
2dbc644a
MY
48 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3); \
49rm -f $(objtree)/.scmversion
26803821 50
1da177e4 51# rpm-pkg
0131705d 52# ---------------------------------------------------------------------------
ebaad7d3 53rpm-pkg: FORCE
1da177e4 54 $(MAKE) clean
65013203 55 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
26803821 56 $(call cmd,src_tar,$(KERNELPATH),kernel.spec)
8a16a070
MY
57 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \
58 --define='_smp_mflags %{nil}'
1da177e4
LT
59
60# binrpm-pkg
0131705d 61# ---------------------------------------------------------------------------
65013203 62binrpm-pkg: FORCE
175209cc 63 $(MAKE) -f $(srctree)/Makefile
65013203 64 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
606625be 65 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
f66ba560 66 $(UTS_MACHINE) -bb $(objtree)/binkernel.spec
af60e207 67
0131705d 68deb-pkg: FORCE
3716001b 69 $(MAKE) clean
b41d920a 70 $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
3716001b 71 $(call cmd,src_tar,$(KDEB_SOURCENAME))
b41d920a
RV
72 origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\
73 mv $(KDEB_SOURCENAME).tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz
117948ac 74 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -i.git -us -uc
3716001b
RV
75
76bindeb-pkg: FORCE
b41d920a 77 $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
117948ac 78 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
b41d920a
RV
79
80intdeb-pkg: FORCE
81 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
1da177e4 82
5704d455
PP
83# snap-pkg
84# ---------------------------------------------------------------------------
85snap-pkg: FORCE
86 rm -rf $(objtree)/snap
87 mkdir $(objtree)/snap
88 $(MAKE) clean
89 $(call cmd,src_tar,$(KERNELPATH))
90 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
91 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
92 $(srctree)/scripts/package/snapcraft.template > \
93 $(objtree)/snap/snapcraft.yaml
94 cd $(objtree)/snap && \
95 snapcraft --target-arch=$(UTS_MACHINE)
96
6d983fea
JBG
97# tarball targets
98# ---------------------------------------------------------------------------
0131705d 99tar%pkg: FORCE
175209cc 100 $(MAKE) -f $(srctree)/Makefile
a6e04877 101 +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
6d983fea 102
8e5564e6
ACM
103# perf-pkg - generate a source tarball with perf source
104# ---------------------------------------------------------------------------
105
106perf-tar=perf-$(KERNELVERSION)
107
108quiet_cmd_perf_tar = TAR
109 cmd_perf_tar = \
3bdccc88 110git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \
111 HEAD^{tree} $$(cd $(srctree); \
4b63f603 112 echo $$(cat tools/perf/MANIFEST)) \
3bdccc88 113 -o $(perf-tar).tar; \
8e5564e6 114mkdir -p $(perf-tar); \
3bdccc88 115git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \
a614d01b 116(cd $(srctree)/tools/perf; \
4b63f603 117util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \
a614d01b 118tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
8e5564e6
ACM
119rm -r $(perf-tar); \
120$(if $(findstring tar-src,$@),, \
121$(if $(findstring bz2,$@),bzip2, \
122$(if $(findstring gz,$@),gzip, \
9a17f400
ZK
123$(if $(findstring xz,$@),xz, \
124$(error unknown target $@)))) \
8e5564e6
ACM
125 -f -9 $(perf-tar).tar)
126
127perf-%pkg: FORCE
128 $(call cmd,perf_tar)
129
1da177e4
LT
130# Help text displayed when executing 'make help'
131# ---------------------------------------------------------------------------
0131705d 132help: FORCE
8e5564e6 133 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
3716001b
RV
134 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
135 @echo ' deb-pkg - Build both source and binary deb kernel packages'
136 @echo ' bindeb-pkg - Build only the binary kernel deb package'
5704d455 137 @echo ' snap-pkg - Build only the binary kernel snap package (will connect to external hosts)'
8e5564e6
ACM
138 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
139 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
140 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
9a17f400 141 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
8e5564e6
ACM
142 @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
143 @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
144 @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
9a17f400 145 @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball'