blob: 348af5b20618eae037a46063a5068f2d9bfb9fd0 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001# Makefile for the different targets used to generate full packages of a kernel
2# It uses the generic clean infrastructure of kbuild
3
4# RPM target
5# ---------------------------------------------------------------------------
6# The rpm target generates two rpm files:
7# /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm
8# /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1.<arch>.rpm
9# The src.rpm files includes all source for the kernel being built
10# The <arch>.rpm includes kernel configuration, modules etc.
11#
12# Process to create the rpm files
13# a) clean the kernel
14# b) Generate .spec file
15# c) Build a tar ball, using symlink to make kernel version
16# first entry in the path
17# d) and pack the result to a tar.gz file
18# e) generate the rpm files, based on kernel.spec
19# - Use /. to avoid tar packing just the symlink
20
21# Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT,
22# but the binrpm-pkg target can; for some reason O= gets ignored.
23
24# Remove hyphens since they have special meaning in RPM filenames
25KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
26KDEB_SOURCENAME ?= linux-$(KERNELRELEASE)
27export KDEB_SOURCENAME
28# Include only those top-level files that are needed by make, plus the GPL copy
29TAR_CONTENT := $(KBUILD_ALLDIRS) .config .scmversion Makefile \
30 Kbuild Kconfig COPYING $(wildcard localversion*)
31MKSPEC := $(srctree)/scripts/package/mkspec
32
33quiet_cmd_src_tar = TAR $(2).tar.gz
34 cmd_src_tar = \
35if test "$(objtree)" != "$(srctree)"; then \
36 echo "Building source tarball is not possible outside the"; \
37 echo "kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \
38 echo "binrpm-pkg or bindeb-pkg target instead."; \
39 false; \
40fi ; \
41$(srctree)/scripts/setlocalversion --save-scmversion; \
42tar -cz $(RCS_TAR_IGNORE) -f $(2).tar.gz \
43 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3); \
44rm -f $(objtree)/.scmversion
45
46# rpm-pkg
47# ---------------------------------------------------------------------------
48rpm-pkg rpm: FORCE
49 $(MAKE) clean
50 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
51 $(call cmd,src_tar,$(KERNELPATH),kernel.spec)
52 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz
53
54# binrpm-pkg
55# ---------------------------------------------------------------------------
56binrpm-pkg: FORCE
57 $(MAKE) KBUILD_SRC=
58 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
59 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
60 $(UTS_MACHINE) -bb $(objtree)/binkernel.spec
61
62clean-files += $(objtree)/*.spec
63
64# Deb target
65# ---------------------------------------------------------------------------
66quiet_cmd_builddeb = BUILDDEB
67 cmd_builddeb = set -e; \
68 test `id -u` = 0 || \
69 test -n "$(KBUILD_PKG_ROOTCMD)" || { \
70 which fakeroot >/dev/null 2>&1 && \
71 KBUILD_PKG_ROOTCMD="fakeroot -u"; \
72 } || { \
73 echo; \
74 echo "builddeb must be run as root (or using fakeroot)."; \
75 echo "KBUILD_PKG_ROOTCMD is unset and fakeroot not found."; \
76 echo "Try setting KBUILD_PKG_ROOTCMD to a command to acquire"; \
77 echo "root privileges (e.g., 'fakeroot -u' or 'sudo')."; \
78 false; \
79 } && \
80 \
81 $$KBUILD_PKG_ROOTCMD $(CONFIG_SHELL) \
82 $(srctree)/scripts/package/builddeb $@
83
84deb-pkg: FORCE
85 $(MAKE) clean
86 $(call cmd,src_tar,$(KDEB_SOURCENAME))
87 $(MAKE) KBUILD_SRC=
88 +$(call cmd,builddeb)
89
90bindeb-pkg: FORCE
91 $(MAKE) KBUILD_SRC=
92 +$(call cmd,builddeb)
93
94clean-dirs += $(objtree)/debian/
95
96
97# tarball targets
98# ---------------------------------------------------------------------------
99tar%pkg: FORCE
100 $(MAKE) KBUILD_SRC=
101 $(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
102
103clean-dirs += $(objtree)/tar-install/
104
105
106# perf-pkg - generate a source tarball with perf source
107# ---------------------------------------------------------------------------
108
109perf-tar=perf-$(KERNELVERSION)
110
111quiet_cmd_perf_tar = TAR
112 cmd_perf_tar = \
113git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \
114 HEAD^{tree} $$(cd $(srctree); \
115 echo $$(cat tools/perf/MANIFEST)) \
116 -o $(perf-tar).tar; \
117mkdir -p $(perf-tar); \
118git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \
119(cd $(srctree)/tools/perf; \
120util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \
121tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
122rm -r $(perf-tar); \
123$(if $(findstring tar-src,$@),, \
124$(if $(findstring bz2,$@),bzip2, \
125$(if $(findstring gz,$@),gzip, \
126$(if $(findstring xz,$@),xz, \
127$(error unknown target $@)))) \
128 -f -9 $(perf-tar).tar)
129
130perf-%pkg: FORCE
131 $(call cmd,perf_tar)
132
133# Help text displayed when executing 'make help'
134# ---------------------------------------------------------------------------
135help: FORCE
136 @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
137 @echo ' binrpm-pkg - Build only the binary kernel RPM package'
138 @echo ' deb-pkg - Build both source and binary deb kernel packages'
139 @echo ' bindeb-pkg - Build only the binary kernel deb package'
140 @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
141 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
142 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
143 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
144 @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
145 @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
146 @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
147 @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball'