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