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 |
The pull request which includes this eclass as well as a few ebuilds |
5 |
using it (with more to come) can be found at |
6 |
https://github.com/gentoo/gentoo/pull/9330 |
7 |
|
8 |
Thanks, |
9 |
~Craig |
10 |
|
11 |
--- |
12 |
eclass/libretro-core.eclass | 168 ++++++++++++++++++++++++++++++++++++ |
13 |
1 file changed, 168 insertions(+) |
14 |
create mode 100644 eclass/libretro-core.eclass |
15 |
|
16 |
diff --git a/eclass/libretro-core.eclass b/eclass/libretro-core.eclass |
17 |
new file mode 100644 |
18 |
index 000000000000..c82420ac98cc |
19 |
--- /dev/null |
20 |
+++ b/eclass/libretro-core.eclass |
21 |
@@ -0,0 +1,168 @@ |
22 |
+# Copyright 1999-2018 Gentoo Foundation |
23 |
+# Distributed under the terms of the GNU General Public License v2 |
24 |
+ |
25 |
+# @ECLASS: libretro-core.eclass |
26 |
+# @MAINTAINER: |
27 |
+# candrews@g.o |
28 |
+# @AUTHOR: |
29 |
+# Cecil Curry <leycec@×××××.com> |
30 |
+# Craig Andrews <candrews@g.o> |
31 |
+# @BLURB: An eclass to streamline the construction of Libretro core |
32 |
ebuilds |
33 |
+# @DESCRIPTION: |
34 |
+# The libretro eclass is designed to streamline the construction of |
35 |
+# ebuilds for low-level Libretro core ebuilds. |
36 |
+ |
37 |
+if [[ -z ${_LIBRETRO_CORE_ECLASS} ]]; then |
38 |
+_LIBRETRO_CORE_ECLASS=1 |
39 |
+ |
40 |
+IUSE="debug" |
41 |
+RDEPEND=" games-emulation/libretro-info" |
42 |
+ |
43 |
+# @ECLASS-VARIABLE: LIBRETRO_CORE_NAME |
44 |
+# @REQUIRED |
45 |
+# @DESCRIPTION: |
46 |
+# Name of this Libretro core. The libretro-core_src_install() phase |
47 |
function |
48 |
+# will install the shared library |
49 |
"${S}/${LIBRETRO_CORE_NAME}_libretro.so" as a |
50 |
+# Libretro core. Defaults to the name of the current package excluding |
51 |
the |
52 |
+# "libretro-" prefix (e.g., "mgba" for the package "libretro-mgba"). |
53 |
+: ${LIBRETRO_CORE_NAME:=${PN#libretro-}} |
54 |
+ |
55 |
+# @ECLASS-VARIABLE: LIBRETRO_COMMIT_SHA |
56 |
+# @DESCRIPTION: |
57 |
+# Commit SHA used for SRC_URI will die if not set in <9999 ebuilds. |
58 |
+# Needs to be set before inherit. |
59 |
+ |
60 |
+# @ECLASS-VARIABLE: LIBRETRO_REPO_NAME |
61 |
+# @REQUIRED |
62 |
+# @DESCRIPTION: |
63 |
+# Contains the real repo name of the core formatted as |
64 |
"repouser/reponame". |
65 |
+# Needs to be set before inherit. Otherwise defaults to |
66 |
"libretro/${PN}" |
67 |
+: ${LIBRETRO_REPO_NAME:="libretro/libretro-${LIBRETRO_CORE_NAME}"} |
68 |
+ |
69 |
+: ${HOMEPAGE:="https://github.com/${LIBRETRO_REPO_NAME}"} |
70 |
+ |
71 |
+if [[ ${PV} == *9999 ]]; then |
72 |
+ : ${EGIT_REPO_URI:="https://github.com/${LIBRETRO_REPO_NAME}.git"} |
73 |
+ inherit git-r3 |
74 |
+else |
75 |
+ [[ -z "${LIBRETRO_COMMIT_SHA}" ]] && die "LIBRETRO_COMMIT_SHA must be |
76 |
set before inherit." |
77 |
+ S="${WORKDIR}/${LIBRETRO_REPO_NAME##*/}-${LIBRETRO_COMMIT_SHA}" |
78 |
+ : |
79 |
${SRC_URI:="https://github.com/${LIBRETRO_REPO_NAME}/archive/${LIBRETRO_COMMIT_SHA}.tar.gz |
80 |
-> ${P}.tar.gz"} |
81 |
+fi |
82 |
+inherit flag-o-matic |
83 |
+ |
84 |
+# @ECLASS-VARIABLE: LIBRETRO_CORE_LIB_FILE |
85 |
+# @REQUIRED |
86 |
+# @DESCRIPTION: |
87 |
+# Absolute path of this Libretro core's shared library. |
88 |
+: ${LIBRETRO_CORE_LIB_FILE:="${S}/${LIBRETRO_CORE_NAME}_libretro.so"} |
89 |
+ |
90 |
+case "${EAPI:-0}" in |
91 |
+ 6) |
92 |
+ EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install |
93 |
+ ;; |
94 |
+ *) |
95 |
+ die "EAPI=${EAPI} is not supported" ;; |
96 |
+esac |
97 |
+ |
98 |
+# @FUNCTION: libretro-core_src_unpack |
99 |
+# @DESCRIPTION: |
100 |
+# The libretro-core src_unpack function which is exported. |
101 |
+# |
102 |
+# This function retrieves the remote Libretro core info files. |
103 |
+libretro-core_src_unpack() { |
104 |
+ # If this is a live ebuild, retrieve this core's remote repository. |
105 |
+ if [[ ${PV} == *9999 ]]; then |
106 |
+ git-r3_src_unpack |
107 |
+ # Add used commit SHA for version information, the above could also |
108 |
work. |
109 |
+ LIBRETRO_COMMIT_SHA=$(git -C |
110 |
"${EGIT3_STORE_DIR}/${LIBRETRO_REPO_NAME//\//_}.git" rev-parse HEAD) |
111 |
+ # Else, unpack this core's local tarball. |
112 |
+ else |
113 |
+ default_src_unpack |
114 |
+ fi |
115 |
+} |
116 |
+ |
117 |
+# @FUNCTION: libretro-core_src_prepare |
118 |
+# @DESCRIPTION: |
119 |
+# The libretro-core src_prepare function which is exported. |
120 |
+# |
121 |
+# This function prepares the source by making custom modifications. |
122 |
+libretro-core_src_prepare() { |
123 |
+ local flags_modified=0 |
124 |
+ ebegin "Attempting to hack Makefiles to use custom-cflags" |
125 |
+ for makefile in "${S}"/?akefile* "${S}"/target-libretro/?akefile*; do |
126 |
+ # * Convert CRLF to LF |
127 |
+ # * Expand *FLAGS to prevent potential self-references |
128 |
+ # * Where LDFLAGS directly define the link version |
129 |
+ # script append LDFLAGS and LIBS |
130 |
+ # * Where SHARED is used to provide shared linking |
131 |
+ # flags ensure final link command includes LDFLAGS |
132 |
+ # and LIBS |
133 |
+ # * Always use $(CFLAGS) when calling $(CC) |
134 |
+ sed \ |
135 |
+ -e 's/\r$//g' \ |
136 |
+ -e "/flags.*=/s/-O[[:digit:]]/${CFLAGS}/g" \ |
137 |
+ -e "/CFLAGS.*=/s/-O[[:digit:]]/${CFLAGS}/g" \ |
138 |
+ -e "/.*,--version-script=.*/s/$/ ${LDFLAGS} ${LIBS}/g" \ |
139 |
+ -e "/\$(CC)/s/\(\$(SHARED)\)/\1 ${LDFLAGS} ${LIBS}/" \ |
140 |
+ -e 's/\(\$(CC)\)/\1 \$(CFLAGS)/g' \ |
141 |
+ -i "${makefile}" \ |
142 |
+ &> /dev/null && flags_modified=1 |
143 |
+ done |
144 |
+ [[ ${flags_modified} == 1 ]] && true || false |
145 |
+ eend $? |
146 |
+ export OPTFLAGS="${CFLAGS}" |
147 |
+ |
148 |
+ # Populate COMMIT for GIT_VERSION |
149 |
+ if [[ -z "${CUSTOM_LIBRETRO_COMMIT_SHA}" ]]; then |
150 |
+ CUSTOM_LIBRETRO_COMMIT_SHA="\" ${LIBRETRO_COMMIT_SHA:0:7}\"" |
151 |
+ fi |
152 |
+ |
153 |
+ for makefile in "${S}"/?akefile* "${S}"/target-libretro/?akefile*; do |
154 |
+ # Add short-rev to Makefile |
155 |
+ sed \ |
156 |
+ -e |
157 |
"s/GIT_VERSION\s.=.*$/GIT_VERSION=${CUSTOM_LIBRETRO_COMMIT_SHA}/g" \ |
158 |
+ -i "${makefile}" \ |
159 |
+ &> /dev/null |
160 |
+ done |
161 |
+ default_src_prepare |
162 |
+} |
163 |
+ |
164 |
+# @FUNCTION: libretro-core_src_compile |
165 |
+# @DESCRIPTION: |
166 |
+# The libretro-core src_compile function which is exported. |
167 |
+# |
168 |
+# This function compiles the shared library for this Libretro core. |
169 |
+libretro-core_src_compile() { |
170 |
+ emake CC=$(tc-getCC) CXX=$(tc-getCXX) \ |
171 |
+ $(usex debug "DEBUG=1" "") "${myemakeargs[@]}" \ |
172 |
+ $([[ -f makefile.libretro ]] && echo '-f makefile.libretro') \ |
173 |
+ $([[ -f Makefile.libretro ]] && echo '-f Makefile.libretro') |
174 |
+} |
175 |
+ |
176 |
+# @FUNCTION: libretro-core_src_install |
177 |
+# @DESCRIPTION: |
178 |
+# The libretro-core src_install function which is exported. |
179 |
+# |
180 |
+# This function installs the shared library for this Libretro core. |
181 |
+libretro-core_src_install() { |
182 |
+ # Absolute path of the directory containing Libretro shared libraries. |
183 |
+ LIBRETRO_LIB_DIR="/usr/$(get_libdir)/libretro" |
184 |
+ # If this core's shared library exists, install that. |
185 |
+ if [[ -f "${LIBRETRO_CORE_LIB_FILE}" ]]; then |
186 |
+ insinto "${LIBRETRO_LIB_DIR}" |
187 |
+ doins "${LIBRETRO_CORE_LIB_FILE}" |
188 |
+ else |
189 |
+ # Basename of this library. |
190 |
+ local lib_basename="${LIBRETRO_CORE_LIB_FILE##*/}" |
191 |
+ |
192 |
+ # Absolute path to which this library was installed. |
193 |
+ local lib_file_target="${ED}${LIBRETRO_LIB_DIR}/${lib_basename}" |
194 |
+ |
195 |
+ # If this library was *NOT* installed, fail. |
196 |
+ [[ -f "${lib_file_target}" ]] || |
197 |
+ die "Libretro core shared library \"${lib_file_target}\" not |
198 |
installed." |
199 |
+ fi |
200 |
+} |
201 |
+ |
202 |
+fi |
203 |
-- |
204 |
2.18.0 |