1 |
W dniu czw, 26.07.2018 o godzinie 15∶12 -0400, użytkownik Craig Andrews |
2 |
napisał: |
3 |
> I'm proposing the addition of a new eclass, libretro-core.eclass, which |
4 |
> I'll use when adding a number of libretro ebuilds. |
5 |
> |
6 |
> The pull request which includes this eclass as well as a few ebuilds |
7 |
> using it (with more to come) can be found at |
8 |
> https://github.com/gentoo/gentoo/pull/9330 |
9 |
> |
10 |
> Thanks, |
11 |
> ~Craig |
12 |
> |
13 |
> --- |
14 |
> eclass/libretro-core.eclass | 168 ++++++++++++++++++++++++++++++++++++ |
15 |
> 1 file changed, 168 insertions(+) |
16 |
> create mode 100644 eclass/libretro-core.eclass |
17 |
> |
18 |
> diff --git a/eclass/libretro-core.eclass b/eclass/libretro-core.eclass |
19 |
> new file mode 100644 |
20 |
> index 000000000000..c82420ac98cc |
21 |
> --- /dev/null |
22 |
> +++ b/eclass/libretro-core.eclass |
23 |
> @@ -0,0 +1,168 @@ |
24 |
> +# Copyright 1999-2018 Gentoo Foundation |
25 |
> +# Distributed under the terms of the GNU General Public License v2 |
26 |
> + |
27 |
> +# @ECLASS: libretro-core.eclass |
28 |
> +# @MAINTAINER: |
29 |
> +# candrews@g.o |
30 |
> +# @AUTHOR: |
31 |
> +# Cecil Curry <leycec@×××××.com> |
32 |
> +# Craig Andrews <candrews@g.o> |
33 |
> +# @BLURB: An eclass to streamline the construction of Libretro core |
34 |
> ebuilds |
35 |
> +# @DESCRIPTION: |
36 |
> +# The libretro eclass is designed to streamline the construction of |
37 |
> +# ebuilds for low-level Libretro core ebuilds. |
38 |
|
39 |
That's not a very helpful description. Description should clearly let |
40 |
a layman know when he should use the eclass, and when it should not be |
41 |
used. Also some generic tips, maybe an example would be helpful. |
42 |
|
43 |
> + |
44 |
> +if [[ -z ${_LIBRETRO_CORE_ECLASS} ]]; then |
45 |
> +_LIBRETRO_CORE_ECLASS=1 |
46 |
> + |
47 |
> +IUSE="debug" |
48 |
> +RDEPEND=" games-emulation/libretro-info" |
49 |
> + |
50 |
> +# @ECLASS-VARIABLE: LIBRETRO_CORE_NAME |
51 |
> +# @REQUIRED |
52 |
> +# @DESCRIPTION: |
53 |
> +# Name of this Libretro core. The libretro-core_src_install() phase |
54 |
> function |
55 |
> +# will install the shared library |
56 |
> "${S}/${LIBRETRO_CORE_NAME}_libretro.so" as a |
57 |
> +# Libretro core. Defaults to the name of the current package excluding |
58 |
> the |
59 |
> +# "libretro-" prefix (e.g., "mgba" for the package "libretro-mgba"). |
60 |
> +: ${LIBRETRO_CORE_NAME:=${PN#libretro-}} |
61 |
> + |
62 |
> +# @ECLASS-VARIABLE: LIBRETRO_COMMIT_SHA |
63 |
> +# @DESCRIPTION: |
64 |
> +# Commit SHA used for SRC_URI will die if not set in <9999 ebuilds. |
65 |
> +# Needs to be set before inherit. |
66 |
> + |
67 |
> +# @ECLASS-VARIABLE: LIBRETRO_REPO_NAME |
68 |
> +# @REQUIRED |
69 |
> +# @DESCRIPTION: |
70 |
> +# Contains the real repo name of the core formatted as |
71 |
> "repouser/reponame". |
72 |
> +# Needs to be set before inherit. Otherwise defaults to |
73 |
> "libretro/${PN}" |
74 |
> +: ${LIBRETRO_REPO_NAME:="libretro/libretro-${LIBRETRO_CORE_NAME}"} |
75 |
> + |
76 |
> +: ${HOMEPAGE:="https://github.com/${LIBRETRO_REPO_NAME}"} |
77 |
> + |
78 |
> +if [[ ${PV} == *9999 ]]; then |
79 |
> + : ${EGIT_REPO_URI:="https://github.com/${LIBRETRO_REPO_NAME}.git"} |
80 |
> + inherit git-r3 |
81 |
> +else |
82 |
> + [[ -z "${LIBRETRO_COMMIT_SHA}" ]] && die "LIBRETRO_COMMIT_SHA must be |
83 |
> set before inherit." |
84 |
> + S="${WORKDIR}/${LIBRETRO_REPO_NAME##*/}-${LIBRETRO_COMMIT_SHA}" |
85 |
> + : |
86 |
> ${SRC_URI:="https://github.com/${LIBRETRO_REPO_NAME}/archive/${LIBRETRO_COMMIT_SHA}.tar.gz |
87 |
> -> ${P}.tar.gz"} |
88 |
> +fi |
89 |
> +inherit flag-o-matic |
90 |
> + |
91 |
> +# @ECLASS-VARIABLE: LIBRETRO_CORE_LIB_FILE |
92 |
> +# @REQUIRED |
93 |
> +# @DESCRIPTION: |
94 |
> +# Absolute path of this Libretro core's shared library. |
95 |
> +: ${LIBRETRO_CORE_LIB_FILE:="${S}/${LIBRETRO_CORE_NAME}_libretro.so"} |
96 |
> + |
97 |
> +case "${EAPI:-0}" in |
98 |
> + 6) |
99 |
|
100 |
Why no EAPI 7? |
101 |
|
102 |
> + EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install |
103 |
> + ;; |
104 |
> + *) |
105 |
> + die "EAPI=${EAPI} is not supported" ;; |
106 |
> +esac |
107 |
> + |
108 |
> +# @FUNCTION: libretro-core_src_unpack |
109 |
> +# @DESCRIPTION: |
110 |
> +# The libretro-core src_unpack function which is exported. |
111 |
> +# |
112 |
> +# This function retrieves the remote Libretro core info files. |
113 |
> +libretro-core_src_unpack() { |
114 |
> + # If this is a live ebuild, retrieve this core's remote repository. |
115 |
> + if [[ ${PV} == *9999 ]]; then |
116 |
> + git-r3_src_unpack |
117 |
> + # Add used commit SHA for version information, the above could also |
118 |
> work. |
119 |
> + LIBRETRO_COMMIT_SHA=$(git -C |
120 |
> "${EGIT3_STORE_DIR}/${LIBRETRO_REPO_NAME//\//_}.git" rev-parse HEAD) |
121 |
|
122 |
It's internal implementation detail. U can't touch this. |
123 |
|
124 |
> + # Else, unpack this core's local tarball. |
125 |
> + else |
126 |
> + default_src_unpack |
127 |
> + fi |
128 |
> +} |
129 |
> + |
130 |
> +# @FUNCTION: libretro-core_src_prepare |
131 |
> +# @DESCRIPTION: |
132 |
> +# The libretro-core src_prepare function which is exported. |
133 |
> +# |
134 |
> +# This function prepares the source by making custom modifications. |
135 |
> +libretro-core_src_prepare() { |
136 |
> + local flags_modified=0 |
137 |
> + ebegin "Attempting to hack Makefiles to use custom-cflags" |
138 |
> + for makefile in "${S}"/?akefile* "${S}"/target-libretro/?akefile*; do |
139 |
|
140 |
Missing local for 'makefile'. |
141 |
|
142 |
Do you expect names other than 'makefile*' and 'Makefile*'? Because |
143 |
this '?' looks like a ticking bomb. |
144 |
|
145 |
> + # * Convert CRLF to LF |
146 |
> + # * Expand *FLAGS to prevent potential self-references |
147 |
> + # * Where LDFLAGS directly define the link version |
148 |
> + # script append LDFLAGS and LIBS |
149 |
> + # * Where SHARED is used to provide shared linking |
150 |
> + # flags ensure final link command includes LDFLAGS |
151 |
> + # and LIBS |
152 |
> + # * Always use $(CFLAGS) when calling $(CC) |
153 |
> + sed \ |
154 |
> + -e 's/\r$//g' \ |
155 |
> + -e "/flags.*=/s/-O[[:digit:]]/${CFLAGS}/g" \ |
156 |
> + -e "/CFLAGS.*=/s/-O[[:digit:]]/${CFLAGS}/g" \ |
157 |
> + -e "/.*,--version-script=.*/s/$/ ${LDFLAGS} ${LIBS}/g" \ |
158 |
> + -e "/\$(CC)/s/\(\$(SHARED)\)/\1 ${LDFLAGS} ${LIBS}/" \ |
159 |
|
160 |
Don't inline ${CFLAGS} etc. in sed expressions. This will fail hard |
161 |
when they contain a slash (which is entirely possible e.g. due to -L |
162 |
with a path). |
163 |
|
164 |
> + -e 's/\(\$(CC)\)/\1 \$(CFLAGS)/g' \ |
165 |
> + -i "${makefile}" \ |
166 |
> + &> /dev/null && flags_modified=1 |
167 |
|
168 |
Don't ignore the output and don't ignore the errors. Make it || die. |
169 |
|
170 |
> + done |
171 |
> + [[ ${flags_modified} == 1 ]] && true || false |
172 |
|
173 |
'&& true || false' is completely redundant here. Not that there's any |
174 |
reason to keep this thing. |
175 |
|
176 |
> + eend $? |
177 |
> + export OPTFLAGS="${CFLAGS}" |
178 |
> + |
179 |
> + # Populate COMMIT for GIT_VERSION |
180 |
> + if [[ -z "${CUSTOM_LIBRETRO_COMMIT_SHA}" ]]; then |
181 |
|
182 |
When can it be empty? FWICS you're requiring it for release, |
183 |
and setting it for -9999. |
184 |
|
185 |
> + CUSTOM_LIBRETRO_COMMIT_SHA="\" ${LIBRETRO_COMMIT_SHA:0:7}\"" |
186 |
> + fi |
187 |
> + |
188 |
> + for makefile in "${S}"/?akefile* "${S}"/target-libretro/?akefile*; do |
189 |
|
190 |
Why not combine the two loops and use a single 'sed' call? |
191 |
|
192 |
> + # Add short-rev to Makefile |
193 |
> + sed \ |
194 |
> + -e |
195 |
> "s/GIT_VERSION\s.=.*$/GIT_VERSION=${CUSTOM_LIBRETRO_COMMIT_SHA}/g" \ |
196 |
> + -i "${makefile}" \ |
197 |
> + &> /dev/null |
198 |
|
199 |
Same as above sed. |
200 |
|
201 |
> + done |
202 |
> + default_src_prepare |
203 |
> +} |
204 |
> + |
205 |
> +# @FUNCTION: libretro-core_src_compile |
206 |
> +# @DESCRIPTION: |
207 |
> +# The libretro-core src_compile function which is exported. |
208 |
> +# |
209 |
> +# This function compiles the shared library for this Libretro core. |
210 |
> +libretro-core_src_compile() { |
211 |
> + emake CC=$(tc-getCC) CXX=$(tc-getCXX) \ |
212 |
> + $(usex debug "DEBUG=1" "") "${myemakeargs[@]}" \ |
213 |
|
214 |
What does DEBUG=1 do? |
215 |
|
216 |
myemakeargs is not documented. |
217 |
|
218 |
> + $([[ -f makefile.libretro ]] && echo '-f makefile.libretro') \ |
219 |
> + $([[ -f Makefile.libretro ]] && echo '-f Makefile.libretro') |
220 |
> +} |
221 |
> + |
222 |
> +# @FUNCTION: libretro-core_src_install |
223 |
> +# @DESCRIPTION: |
224 |
> +# The libretro-core src_install function which is exported. |
225 |
> +# |
226 |
> +# This function installs the shared library for this Libretro core. |
227 |
> +libretro-core_src_install() { |
228 |
> + # Absolute path of the directory containing Libretro shared libraries. |
229 |
> + LIBRETRO_LIB_DIR="/usr/$(get_libdir)/libretro" |
230 |
|
231 |
Why are you setting a global variable? |
232 |
|
233 |
> + # If this core's shared library exists, install that. |
234 |
> + if [[ -f "${LIBRETRO_CORE_LIB_FILE}" ]]; then |
235 |
> + insinto "${LIBRETRO_LIB_DIR}" |
236 |
> + doins "${LIBRETRO_CORE_LIB_FILE}" |
237 |
|
238 |
Shared libraries should have +x, so doexe here. |
239 |
|
240 |
> + else |
241 |
> + # Basename of this library. |
242 |
> + local lib_basename="${LIBRETRO_CORE_LIB_FILE##*/}" |
243 |
> + |
244 |
> + # Absolute path to which this library was installed. |
245 |
> + local lib_file_target="${ED}${LIBRETRO_LIB_DIR}/${lib_basename}" |
246 |
> + |
247 |
> + # If this library was *NOT* installed, fail. |
248 |
> + [[ -f "${lib_file_target}" ]] || |
249 |
> + die "Libretro core shared library \"${lib_file_target}\" not |
250 |
> installed." |
251 |
|
252 |
What use case does this whole block cover? |
253 |
|
254 |
> + fi |
255 |
> +} |
256 |
> + |
257 |
> +fi |
258 |
|
259 |
-- |
260 |
Best regards, |
261 |
Michał Górny |