rpm  5.4.10
buildroot
Go to the documentation of this file.
1 /*! \page buildroot Using a build root
2 
3 The build root is very similar to Root: (which is now legacy).
4 By using Buildroot: in your spec file you are indicating
5 that your package can be built (installed into and packaged from)
6 a user-definable directory. This helps package building by normal
7 users.
8 
9 \subsection buildroot_specfile The Spec File
10 
11 Simply use
12 \verbatim
13  Buildroot: <dir>
14 \endverbatim
15 
16 in your spec file. The actual buildroot used by RPM during the
17 build will be available to you (and your %prep, %build, and %install
18 sections) as the environment variable RPM_BUILD_ROOT. You must
19 make sure that the files for the package are installed into the
20 proper buildroot. As with Root:, the files listed in the %files
21 section should *not* contain the buildroot. For example, the
22 following hypothetical spec file:
23 
24 \verbatim
25  Name: foo
26  ...
27  Root: /tmp
28 
29  %prep
30  ...
31 
32  %build
33  ...
34 
35  %install
36  install -m755 fooprog /tmp/usr/bin/fooprog
37 
38  %files
39  /usr/bin/fooprog
40 \endverbatim
41 
42 would be changed to:
43 
44 \verbatim
45  Name: foo
46  ...
47  BuildRoot: /tmp
48 
49  %prep
50  ...
51 
52  %build
53  ...
54 
55  %install
56  install -m755 fooprog $RPM_BUILD_ROOT/usr/bin/fooprog
57 
58  %files
59  /usr/bin/fooprog
60 \endverbatim
61 
62 \subsection buildroot_building Building With a Build Root
63 
64 RPM will use the buildroot listed in the spec file as the default
65 buildroot. There are two ways to override this. First, you can
66 have "buildroot: <dir>" in your rpmrc. Second, you can override
67 the default, and any entry in an rpmrc by using "--buildroot <dir>"
68 on the RPM command line.
69 
70 \subsection buildroot_caveats Caveats using Build Roots
71 
72 Care should be taken when using buildroots that the install directory
73 is owned by the correct package. For example the file
74 
75 \verbatim
76  /usr/lib/perl5/site_perl/MD5.pm
77 \endverbatim
78 
79 is installed by the package perl-MD5. If we were to use a buildroot
80 and specified
81 
82 \verbatim
83  %files
84  /usr/lib/perl5/site_perl
85 \endverbatim
86 
87 we would end up with the directory /usr/lib/perl5/site_perl being
88 owned by the library package. This directory is in fact used by ALL
89 perl libraries and should be owned by the package for perl not any of
90 its libraries. It is important that the %files command specifies all
91 the known directories explicitly. So this would be preferable:
92 
93 \verbatim
94  /usr/lib/perl5/site_perl/*
95 \endverbatim
96 
97 Since we only want the files and directories that the package perl-MD5
98 installed into /usr/lib/perl5/site_perl/ to be owned by the package.
99 The directory /usr/lib/perl5/site_perl/ is created when perl is
100 installed.
101 
102 If we were to use the bad %files line shown above, then when the MD5
103 package is removed, RPM will try to remove each of the perl-MD5 files and
104 then try to remove the dir itself. If there's still files in the
105 site_perl directory (e.g. from other packages) then the Unix rmdir(2)
106 will fail and you will get a non-zero return code from RPM. If the
107 rmdir succeeds then you will no longer have a site_perl directory on
108 your machine even though this directory was created when Perl was
109 installed.
110 
111 The other common problem is that two packages could install two files
112 with the the same name into the same directory. This would lead to
113 other collision problems when removing the file. Care should be taken
114 by the packager to ensure that all packages install unique files.
115 Explicit use of %files can help make the packager aware of potential
116 problems before they happen. When you try to install a package which
117 contains file names already used by other packages on the system then
118 RPM will warn you of the problem and give a fatal error. This error can
119 be overridden with --force and the installed file will be replaced by the
120 new file and when the new package is removed the file will be removed as well.
121 
122 */