1 |
On 09.08.2018 16:58, Craig Andrews wrote: |
2 |
> I'm proposing the addition of a new eclass, libretro-core.eclass, |
3 |
> which I'll use when adding a number of libretro ebuilds. |
4 |
> |
5 |
> This version incorporates all the changes and suggestions posed so far. |
6 |
> |
7 |
> The pull request which includes this eclass as well as a few ebuilds |
8 |
> using it (with more to come) can be found at |
9 |
> https://github.com/gentoo/gentoo/pull/9330 |
10 |
> |
11 |
> Thanks, |
12 |
> ~Craig |
13 |
> |
14 |
> --- |
15 |
> eclass/libretro-core.eclass | 197 ++++++++++++++++++++++++++++++++++++ |
16 |
> 1 file changed, 197 insertions(+) |
17 |
> create mode 100644 eclass/libretro-core.eclass |
18 |
> |
19 |
> diff --git a/eclass/libretro-core.eclass b/eclass/libretro-core.eclass |
20 |
> new file mode 100644 |
21 |
> index 000000000000..510f905111ce |
22 |
> --- /dev/null |
23 |
> +++ b/eclass/libretro-core.eclass |
24 |
> @@ -0,0 +1,197 @@ |
25 |
> +# Copyright 1999-2018 Gentoo Foundation |
26 |
> +# Distributed under the terms of the GNU General Public License v2 |
27 |
> + |
28 |
> +# @ECLASS: libretro-core.eclass |
29 |
> +# @MAINTAINER: |
30 |
> +# candrews@g.o |
31 |
> +# @AUTHOR: |
32 |
> +# Cecil Curry <leycec@×××××.com> |
33 |
> +# Craig Andrews <candrews@g.o> |
34 |
> +# @BLURB: Simplify libretro core ebuilds |
35 |
> +# @DESCRIPTION: |
36 |
> +# The libretro eclass is designed to streamline the construction of |
37 |
> +# ebuilds for Libretro core ebuilds. |
38 |
> +# |
39 |
> +# Libretro cores can be found under https://github.com/libretro/ |
40 |
> +# |
41 |
> +# They all use the same basic make based build system, are located |
42 |
> +# in the same github account, and do not release named or numbered |
43 |
> +# versions (so ebuild versions for git commits are keys). |
44 |
> +# This eclass covers those commonalities reducing much duplication |
45 |
> +# between the ebuilds. |
46 |
> +# @EXAMPLE: |
47 |
> +# @CODE |
48 |
> +# EAPI=7 |
49 |
> +# |
50 |
> +# LIBRETRO_CORE_NAME="2048" |
51 |
> +# LIBRETRO_COMMIT_SHA="45655d3662e4cbcd8afb28e2ee3f5494a75888de" |
52 |
> +# KEYWORDS="~amd64 ~x86" |
53 |
> +# inherit libretro-core |
54 |
> +# |
55 |
> +# DESCRIPTION="Port of 2048 puzzle game to the libretro API" |
56 |
> +# LICENSE="Unlicense" |
57 |
> +# SLOT="0" |
58 |
> +# @CODE |
59 |
> + |
60 |
> +if [[ -z ${_LIBRETRO_CORE_ECLASS} ]]; then |
61 |
> +_LIBRETRO_CORE_ECLASS=1 |
62 |
> + |
63 |
> +IUSE="debug" |
64 |
> + |
65 |
> +# @ECLASS-VARIABLE: LIBRETRO_CORE_NAME |
66 |
> +# @REQUIRED |
67 |
> +# @DESCRIPTION: |
68 |
> +# Name of this Libretro core. The libretro-core_src_install() phase |
69 |
> function |
70 |
> +# will install the shared library |
71 |
> "${S}/${LIBRETRO_CORE_NAME}_libretro.so" as a |
72 |
> +# Libretro core. Defaults to the name of the current package excluding |
73 |
> the |
74 |
> +# "libretro-" prefix (e.g., "mgba" for the package "libretro-mgba"). |
75 |
> +: ${LIBRETRO_CORE_NAME:=${PN#libretro-}} |
76 |
> + |
77 |
> +# @ECLASS-VARIABLE: LIBRETRO_COMMIT_SHA |
78 |
> +# @DESCRIPTION: |
79 |
> +# Commit SHA used for SRC_URI will die if not set in <9999 ebuilds. |
80 |
> +# Needs to be set before inherit. |
81 |
> + |
82 |
> +# @ECLASS-VARIABLE: LIBRETRO_REPO_NAME |
83 |
> +# @REQUIRED |
84 |
> +# @DESCRIPTION: |
85 |
> +# Contains the real repo name of the core formatted as |
86 |
> "repouser/reponame". |
87 |
> +# Needs to be set before inherit. Otherwise defaults to |
88 |
> "libretro/${PN}" |
89 |
> +: ${LIBRETRO_REPO_NAME:="libretro/libretro-${LIBRETRO_CORE_NAME}"} |
90 |
> + |
91 |
> +: ${HOMEPAGE:="https://github.com/${LIBRETRO_REPO_NAME}"} |
92 |
> + |
93 |
> +if [[ ${PV} == *9999 ]]; then |
94 |
> + : ${EGIT_REPO_URI:="https://github.com/${LIBRETRO_REPO_NAME}.git"} |
95 |
> + inherit git-r3 |
96 |
> +else |
97 |
> + [[ -z "${LIBRETRO_COMMIT_SHA}" ]] && die "LIBRETRO_COMMIT_SHA must |
98 |
> be set before inherit." |
99 |
> + S="${WORKDIR}/${LIBRETRO_REPO_NAME##*/}-${LIBRETRO_COMMIT_SHA}" |
100 |
> + : |
101 |
> ${SRC_URI:="https://github.com/${LIBRETRO_REPO_NAME}/archive/${LIBRETRO_COMMIT_SHA}.tar.gz |
102 |
> -> ${P}.tar.gz"} |
103 |
> +fi |
104 |
> +inherit flag-o-matic |
105 |
> + |
106 |
> +# @ECLASS-VARIABLE: LIBRETRO_CORE_LIB_FILE |
107 |
> +# @REQUIRED |
108 |
> +# @DESCRIPTION: |
109 |
> +# Absolute path of this Libretro core's shared library. |
110 |
> +: ${LIBRETRO_CORE_LIB_FILE:="${S}/${LIBRETRO_CORE_NAME}_libretro.so"} |
111 |
> + |
112 |
> +case "${EAPI:-0}" in |
113 |
> + 6|7) |
114 |
> + EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install |
115 |
> + ;; |
116 |
> + *) |
117 |
> + die "EAPI=${EAPI} is not supported" ;; |
118 |
> +esac |
119 |
> + |
120 |
> +# @FUNCTION: libretro-core_src_unpack |
121 |
> +# @DESCRIPTION: |
122 |
> +# The libretro-core src_unpack function which is exported. |
123 |
> +# |
124 |
> +# This function retrieves the remote Libretro core info files. |
125 |
> +libretro-core_src_unpack() { |
126 |
> + # If this is a live ebuild, retrieve this core's remote repository. |
127 |
> + if [[ ${PV} == *9999 ]]; then |
128 |
> + git-r3_src_unpack |
129 |
> + # Add used commit SHA for version information, the above could also |
130 |
> work. |
131 |
> + LIBRETRO_COMMIT_SHA=$(git -C "${WORKDIR}/${P}" rev-parse HEAD) |
132 |
> + # Else, unpack this core's local tarball. |
133 |
> + else |
134 |
> + default_src_unpack |
135 |
> + fi |
136 |
> +} |
137 |
> + |
138 |
> +# @FUNCTION: libretro-core_src_prepare |
139 |
> +# @DESCRIPTION: |
140 |
> +# The libretro-core src_prepare function which is exported. |
141 |
> +# |
142 |
> +# This function prepares the source by making custom modifications. |
143 |
> +libretro-core_src_prepare() { |
144 |
> + ebegin "Attempting to hack Makefiles to use custom cflags" |
145 |
> + # Populate COMMIT for GIT_VERSION |
146 |
> + CUSTOM_LIBRETRO_COMMIT_SHA="\" ${LIBRETRO_COMMIT_SHA:0:7}\"" |
147 |
> + local makefile |
148 |
> + local flags_modified=0 |
149 |
> + local shopt_saved=$(shopt -p nullglob) |
150 |
> + shopt -s nullglob |
151 |
> + for makefile in "${S}"/[Mm]akefile* |
152 |
> "${S}"/target-libretro/[Mm]akefile*; do |
153 |
> + # * Convert CRLF to LF |
154 |
> + # * Expand *FLAGS to prevent potential self-references |
155 |
> + # * Where LDFLAGS directly define the link version |
156 |
> + # script append LDFLAGS and LIBS |
157 |
> + # * Where SHARED is used to provide shared linking |
158 |
> + # flags ensure final link command includes LDFLAGS |
159 |
> + # and LIBS |
160 |
> + # * Always use $(CFLAGS) when calling $(CC) |
161 |
> + # * Add short-rev to Makefile |
162 |
> + [[ -e "${makefile}" ]] && sed \ |
163 |
> + -e 's/\r$//g' \ |
164 |
> + -e "/flags.*=/s:-O[[:digit:]]:${CFLAGS}:g" \ |
165 |
> + -e "/CFLAGS.*=/s:-O[[:digit:]]:${CFLAGS}:g" \ |
166 |
> + -e "/.*,--version-script=.*/s:$: ${LDFLAGS} ${LIBS}:g" \ |
167 |
> + -e "/\$(CC)/s:\(\$(SHARED)\):\1 ${LDFLAGS} ${LIBS}:" \ |
168 |
> + -e 's:\(\$(CC)\):\1 \$(CFLAGS):g' \ |
169 |
> + -e |
170 |
> "s/GIT_VERSION\s.=.*$/GIT_VERSION=${CUSTOM_LIBRETRO_COMMIT_SHA}/g" \ |
171 |
> + -i "${makefile}" || die "Failed to use custom cflags in |
172 |
> ${makefile}" |
173 |
> + done |
174 |
> + ${shopt_saved} |
175 |
> + eend |
176 |
> + export OPTFLAGS="${CFLAGS}" |
177 |
> + default_src_prepare |
178 |
> +} |
179 |
> + |
180 |
> +# @VARIABLE: myemakeargs |
181 |
> +# @DEFAULT_UNSET |
182 |
> +# @DESCRIPTION: |
183 |
> +# Optional emake arguments as a bash array. Should be defined before |
184 |
> calling |
185 |
> +# src_compile. |
186 |
> +# @CODE |
187 |
> +# src_compile() { |
188 |
> +# local myemakeargs=( |
189 |
> +# $(usex neon "HAVE_NEON=1" "") |
190 |
> +# ) |
191 |
> +# libretro-core_src_configure |
192 |
> +# } |
193 |
> +# @CODE |
194 |
> + |
195 |
> +# @FUNCTION: libretro-core_src_compile |
196 |
> +# @DESCRIPTION: |
197 |
> +# The libretro-core src_compile function which is exported. |
198 |
> +# |
199 |
> +# This function compiles the shared library for this Libretro core. |
200 |
> +libretro-core_src_compile() { |
201 |
> + # most (if not all) libretro makefiles use DEBUG=1 |
202 |
> + # to enable additional debug features. |
203 |
> + emake CC=$(tc-getCC) CXX=$(tc-getCXX) \ |
204 |
> + $(usex debug "DEBUG=1" "") "${myemakeargs[@]}" \ |
205 |
> + $([[ -f makefile.libretro ]] && echo '-f makefile.libretro') \ |
206 |
> + $([[ -f Makefile.libretro ]] && echo '-f Makefile.libretro') |
207 |
> +} |
208 |
> + |
209 |
> +# @FUNCTION: libretro-core_src_install |
210 |
> +# @DESCRIPTION: |
211 |
> +# The libretro-core src_install function which is exported. |
212 |
> +# |
213 |
> +# This function installs the shared library for this Libretro core. |
214 |
> +libretro-core_src_install() { |
215 |
> + # Absolute path of the directory containing Libretro shared |
216 |
> libraries. |
217 |
> + local LIBRETRO_LIB_DIR="/usr/$(get_libdir)/libretro" |
218 |
> + # If this core's shared library exists, install that. |
219 |
> + if [[ -f "${LIBRETRO_CORE_LIB_FILE}" ]]; then |
220 |
> + insinto "${LIBRETRO_LIB_DIR}" |
221 |
> + doexe "${LIBRETRO_CORE_LIB_FILE}" |
222 |
> + else |
223 |
> + # Basename of this library. |
224 |
> + local lib_basename="${LIBRETRO_CORE_LIB_FILE##*/}" |
225 |
> + |
226 |
> + # Absolute path to which this library was installed. |
227 |
> + local lib_file_target="${ED}${LIBRETRO_LIB_DIR}/${lib_basename}" |
228 |
> + |
229 |
> + # If this library was *NOT* installed, fail. |
230 |
> + [[ -f "${lib_file_target}" ]] || |
231 |
> + die "Libretro core shared library \"${lib_file_target}\" not |
232 |
> installed." |
233 |
> + fi |
234 |
> +} |
235 |
> + |
236 |
> +fi # end _LIBRETRO_CORE_ECLASS guard |
237 |
|
238 |
|
239 |
Merged with a few tweaks: commit |
240 |
532441d38e4bc6fe2445385ab177f7ed6b1ec2c1 |
241 |
|
242 |
Thank you to everyone who reviewed this work and provided feedback! |
243 |
|
244 |
~Craig |