aboutsummaryrefslogtreecommitdiff
blob: 866008ab6375889900e0cace331d5bbc0d6386a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?xml version="1.0" encoding="UTF-8"?>
<guide self="ebuild-writing/functions/src_prepare/eapply/">
<chapter>
<title>Patching with epatch and eapply</title>

<body>
<p>
The canonical way of applying patches in ebuilds is to
use <c>epatch</c> (from <c>epatch.eclass</c>, which you must make sure
to inherit!) inside <c>src_prepare</c>. This function automatically
handles <c>-p</c> levels, <c>gunzip</c> and so on as necessary.
</p>

<p>
Starting with EAPI=7, this function is banned and <c>eapply</c> must be used.
</p>

<p>
Beginning with EAPI=6, a new function <c>eapply</c> was added to apply patches
without the need for an eclass.
This function differs from epatch in several ways:
</p>

<ul>
<li><c>eapply</c> will not unpack patches for you.</li>
<li>
The default patch level is -p1.
Other patch levels must be specified manually or the command will fail.
</li>
<li>
When specifying a directory, at least one file with a name ending in .patch or .diff
must exist or the command fails.  Other files are ignored.
</li>
</ul>

<p>
Note that distributing modified tarballs rather than a vanilla tarball
and patches is <e>highly</e> discouraged.
</p>
</body>

<section>
<title>Basic <c>eapply</c></title>
<body>
<p>
The default src_prepare function will look for a global PATCHES array to apply
a list of patches for you.
</p>
<codesample lang="ebuild">
PATCHES=(
	"${FILESDIR}/${P}-destdir.patch"
	"${FILESDIR}/${P}-parallel_build.patch"
)
</codesample>
</body>
</section>

<section>
<title>Advanced <c>eapply</c></title>
<body>
<p>
This example shows how different patch levels can be applied:
</p>

<codesample lang="ebuild">
src_prepare() {
	eapply -p2 "${WORKDIR}/${P}-suse-update.patch"
	eapply -p0 "${FILESDIR}/${PV}-no-TIOCGDEV.patch"
	eapply "${FILESDIR}/${PV}-gcc-6.patch"
	eapply_user
}
</codesample>
</body>
</section>

<section>
<title>Basic <c>epatch</c></title>
<body>

<p>
In its simplest form, <c>epatch</c> takes a single filename and
applies that patch. It will automatically <c>die</c> if the apply
fails. The following is taken from <c>app-misc/detox</c>:
</p>

<codesample lang="ebuild">
src_prepare() {
	epatch "${FILESDIR}/${P}-destdir.patch"
	epatch "${FILESDIR}/${P}-parallel_build.patch"
}
</codesample>

<p>
For larger patches, using
<uri link="::general-concepts/mirrors/#Suitable Download Hosts">
your devspace</uri> rather than
<uri link="::ebuild-writing/variables/#Predefined Read-Only Variables">
${FILESDIR}</uri> is more appropriate. In these situations, it is
usually best to compress the patch in question with <c>xz</c> or
<c>bzip2</c> (as opposed to <c>${FILESDIR}</c> patches, which must not
be compressed). For example, from <c>app-admin/showconsole</c>:
</p>

<codesample lang="ebuild">
src_prepare() {
	epatch "${WORKDIR}/${P}-suse-update.patch.bz2"
	epatch "${FILESDIR}/${PV}-no-TIOCGDEV.patch"
}
</codesample>

<p>
Remember to add the patch to <c>SRC_URI</c>.
</p>
</body>
</section>

<section>
<title>Multiple Patches with <c>epatch</c></title>
<body>

<p>
epatch can also apply multiple patches (which can be selectively based
upon arch) from a single directory. This can be useful if upstream
have releases that need more patches.
</p>

<p>
A simple example:
</p>

<codesample lang="ebuild">
src_prepare() {
	EPATCH_SOURCE="${WORKDIR}/patches" EPATCH_SUFFIX="patch" \
		EPATCH_FORCE="yes" epatch
}
</codesample>

<p>
Here, one of the <c>SRC_URI</c> components is a tarball containing
many patches with file extension <c>.patch</c>.
</p>

<p>
Variables which may be defined include:
</p>

<table>
  <tr>
    <th>Variable</th>
    <th>Purpose</th>
  </tr>
  <tr>
    <ti><c>EPATCH_SOURCE</c></ti>
    <ti>Specifies the directory in which epatch looks for patches.</ti>
  </tr>
  <tr>
    <ti><c>EPATCH_SUFFIX</c></ti>
    <ti>File extension for patches.</ti>
  </tr>
  <tr>
    <ti><c>EPATCH_OPTS</c></ti>
    <ti>Default options to <c>patch</c>.</ti>
  </tr>
  <tr>
    <ti><c>EPATCH_EXCLUDE</c></ti>
    <ti>List of patches to exclude.</ti>
  </tr>
  <tr>
    <ti><c>EPATCH_FORCE</c></ti>
    <ti>
    Force epatch to apply patches even if they do not follow the
    canonical naming form (set to <c>yes</c>).
    </ti>
  </tr>
</table>

<p>
Bulk patches should be named in the form
<c>??_${ARCH}_foo.${EPATCH_SUFFIX}</c>. If they are
not, <c>EPATCH_FORCE="yes"</c> must be set. To apply a patch on <c>all</c>
archs, use all for the <c>${ARCH}</c> part.
</p>

</body>
</section>
</chapter>
</guide>