aboutsummaryrefslogtreecommitdiff
blob: 1322a5ee4d44cc7a9d21d8c8104e74ed4d182ddc (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
<?xml version="1.0"?>
<guide self="ebuild-writing/functions/src_prepare/epatch/">
<chapter>
<title>Patching with epatch</title>

<body>
<p>
The canonical way of applying patches in ebuilds is to
use <c>epatch</c> (from <c>eutils.eclass</c>, which you must make sure
to import!) inside <c>src_prepare</c>. This function automatically
handles <c>-p</c> levels, <c>gunzip</c> and so on as necessary. Also note that olds ebuild may still use src_unpack to apply patches. This is because those ebuilds are based in EAPI="1". You are advised to use EAPI="2" and apply your patches in src_prepare function instead.
</p>

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

<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_unpack() {
    unpack ${A}
    cd "${S}"
    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 <c>files/</c> is more appropriate. In these situations, it is
usually best to <c>bzip2</c> the patch in question (as opposed to
<c>files/</c> patches, which must not be compressed). For example,
from <c>app-admin/showconsole</c>:
</p>

<codesample lang="ebuild">
src_unpack() {
    unpack ${A}
    cd "${S}"
    epatch "${WORKDIR}/${P}-suse-update.patch.bz2"
    epatch "${FILESDIR}/${PV}-no-TIOCGDEV.patch"
}
</codesample>
<p>As stated before, if you are using EAPI >=2, you should apply the patches in the <uri link="::ebuild-writing/functions/src_prepare">src_prepare</uri> function</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>

<subsection>
<title>CVS Keyword Lines and Patches</title>
<body>
<p>
If your patch includes any changes to CVS <c>$Id: $</c>
(or <c>$Header: $</c>, or <c>$Date: $</c>) lines, it cannot be
distributed under <c>files/</c>, since CVS will clobber the patch when
you commit. In these situations, either remove this hunk of the patch
manually, or mirror the file.
</p>
</body>
</subsection>

</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_unpack() {
    unpack ${A}
    cd "${S}"
    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>