From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id C8FB3138334 for ; Thu, 26 Jul 2018 20:14:42 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 51848E08F1; Thu, 26 Jul 2018 20:14:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C24B7E08C4 for ; Thu, 26 Jul 2018 20:14:37 +0000 (UTC) Received: from pomiot (d202-252.icpnet.pl [109.173.202.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id CA5AA335CCB; Thu, 26 Jul 2018 20:14:35 +0000 (UTC) Message-ID: <1532636066.8727.12.camel@gentoo.org> Subject: Re: [gentoo-dev] [PATCH] libretro-core.eclass: An eclass to streamline the construction of Libretro core ebuilds From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Date: Thu, 26 Jul 2018 22:14:26 +0200 In-Reply-To: References: Organization: Gentoo Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-JDdhG1VmQXhksYtGOur/" X-Mailer: Evolution 3.24.6 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org Mime-Version: 1.0 X-Archives-Salt: b8e64d59-abd7-4edb-8dc9-6c0f54935c4a X-Archives-Hash: 0bdc848b97ede9bd294be8b2fc8f6ae0 --=-JDdhG1VmQXhksYtGOur/ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable W dniu czw, 26.07.2018 o godzinie 15=E2=88=B612=E2=80=89-0400, u=C5=BCytkow= nik Craig Andrews napisa=C5=82: > I'm proposing the addition of a new eclass, libretro-core.eclass, which= =20 > I'll use when adding a number of libretro ebuilds. >=20 > The pull request which includes this eclass as well as a few ebuilds=20 > using it (with more to come) can be found at=20 > https://github.com/gentoo/gentoo/pull/9330 >=20 > Thanks, > ~Craig >=20 > --- > eclass/libretro-core.eclass | 168 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 168 insertions(+) > create mode 100644 eclass/libretro-core.eclass >=20 > diff --git a/eclass/libretro-core.eclass b/eclass/libretro-core.eclass > new file mode 100644 > index 000000000000..c82420ac98cc > --- /dev/null > +++ b/eclass/libretro-core.eclass > @@ -0,0 +1,168 @@ > +# Copyright 1999-2018 Gentoo Foundation > +# Distributed under the terms of the GNU General Public License v2 > + > +# @ECLASS: libretro-core.eclass > +# @MAINTAINER: > +# candrews@gentoo.org > +# @AUTHOR: > +# Cecil Curry > +# Craig Andrews > +# @BLURB: An eclass to streamline the construction of Libretro core=20 > ebuilds > +# @DESCRIPTION: > +# The libretro eclass is designed to streamline the construction of > +# ebuilds for low-level Libretro core ebuilds. That's not a very helpful description. Description should clearly let a layman know when he should use the eclass, and when it should not be used. Also some generic tips, maybe an example would be helpful. > + > +if [[ -z ${_LIBRETRO_CORE_ECLASS} ]]; then > +_LIBRETRO_CORE_ECLASS=3D1 > + > +IUSE=3D"debug" > +RDEPEND=3D" games-emulation/libretro-info" > + > +# @ECLASS-VARIABLE: LIBRETRO_CORE_NAME > +# @REQUIRED > +# @DESCRIPTION: > +# Name of this Libretro core. The libretro-core_src_install() phase=20 > function > +# will install the shared library=20 > "${S}/${LIBRETRO_CORE_NAME}_libretro.so" as a > +# Libretro core. Defaults to the name of the current package excluding= =20 > the > +# "libretro-" prefix (e.g., "mgba" for the package "libretro-mgba"). > +: ${LIBRETRO_CORE_NAME:=3D${PN#libretro-}} > + > +# @ECLASS-VARIABLE: LIBRETRO_COMMIT_SHA > +# @DESCRIPTION: > +# Commit SHA used for SRC_URI will die if not set in <9999 ebuilds. > +# Needs to be set before inherit. > + > +# @ECLASS-VARIABLE: LIBRETRO_REPO_NAME > +# @REQUIRED > +# @DESCRIPTION: > +# Contains the real repo name of the core formatted as=20 > "repouser/reponame". > +# Needs to be set before inherit. Otherwise defaults to=20 > "libretro/${PN}" > +: ${LIBRETRO_REPO_NAME:=3D"libretro/libretro-${LIBRETRO_CORE_NAME}"} > + > +: ${HOMEPAGE:=3D"https://github.com/${LIBRETRO_REPO_NAME}"} > + > +if [[ ${PV} =3D=3D *9999 ]]; then > + : ${EGIT_REPO_URI:=3D"https://github.com/${LIBRETRO_REPO_NAME}.git"} > + inherit git-r3 > +else > + [[ -z "${LIBRETRO_COMMIT_SHA}" ]] && die "LIBRETRO_COMMIT_SHA must be= =20 > set before inherit." > + S=3D"${WORKDIR}/${LIBRETRO_REPO_NAME##*/}-${LIBRETRO_COMMIT_SHA}" > + :=20 > ${SRC_URI:=3D"https://github.com/${LIBRETRO_REPO_NAME}/archive/${LIBRETRO= _COMMIT_SHA}.tar.gz=20 > -> ${P}.tar.gz"} > +fi > +inherit flag-o-matic > + > +# @ECLASS-VARIABLE: LIBRETRO_CORE_LIB_FILE > +# @REQUIRED > +# @DESCRIPTION: > +# Absolute path of this Libretro core's shared library. > +: ${LIBRETRO_CORE_LIB_FILE:=3D"${S}/${LIBRETRO_CORE_NAME}_libretro.so"} > + > +case "${EAPI:-0}" in > + 6) Why no EAPI 7? > + EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install > + ;; > + *) > + die "EAPI=3D${EAPI} is not supported" ;; > +esac > + > +# @FUNCTION: libretro-core_src_unpack > +# @DESCRIPTION: > +# The libretro-core src_unpack function which is exported. > +# > +# This function retrieves the remote Libretro core info files. > +libretro-core_src_unpack() { > + # If this is a live ebuild, retrieve this core's remote repository. > + if [[ ${PV} =3D=3D *9999 ]]; then > + git-r3_src_unpack > + # Add used commit SHA for version information, the above could also= =20 > work. > + LIBRETRO_COMMIT_SHA=3D$(git -C=20 > "${EGIT3_STORE_DIR}/${LIBRETRO_REPO_NAME//\//_}.git" rev-parse HEAD) It's internal implementation detail. U can't touch this. > + # Else, unpack this core's local tarball. > + else > + default_src_unpack > + fi > +} > + > +# @FUNCTION: libretro-core_src_prepare > +# @DESCRIPTION: > +# The libretro-core src_prepare function which is exported. > +# > +# This function prepares the source by making custom modifications. > +libretro-core_src_prepare() { > + local flags_modified=3D0 > + ebegin "Attempting to hack Makefiles to use custom-cflags" > + for makefile in "${S}"/?akefile* "${S}"/target-libretro/?akefile*; do Missing local for 'makefile'. Do you expect names other than 'makefile*' and 'Makefile*'? Because this '?' looks like a ticking bomb. > + # * Convert CRLF to LF > + # * Expand *FLAGS to prevent potential self-references > + # * Where LDFLAGS directly define the link version > + # script append LDFLAGS and LIBS > + # * Where SHARED is used to provide shared linking > + # flags ensure final link command includes LDFLAGS > + # and LIBS > + # * Always use $(CFLAGS) when calling $(CC) > + sed \ > + -e 's/\r$//g' \ > + -e "/flags.*=3D/s/-O[[:digit:]]/${CFLAGS}/g" \ > + -e "/CFLAGS.*=3D/s/-O[[:digit:]]/${CFLAGS}/g" \ > + -e "/.*,--version-script=3D.*/s/$/ ${LDFLAGS} ${LIBS}/g" \ > + -e "/\$(CC)/s/\(\$(SHARED)\)/\1 ${LDFLAGS} ${LIBS}/" \ Don't inline ${CFLAGS} etc. in sed expressions. This will fail hard when they contain a slash (which is entirely possible e.g. due to -L with a path). > + -e 's/\(\$(CC)\)/\1 \$(CFLAGS)/g' \ > + -i "${makefile}" \ > + &> /dev/null && flags_modified=3D1 Don't ignore the output and don't ignore the errors. Make it || die. > + done > + [[ ${flags_modified} =3D=3D 1 ]] && true || false '&& true || false' is completely redundant here. Not that there's any reason to keep this thing. > + eend $? > + export OPTFLAGS=3D"${CFLAGS}" > + > + # Populate COMMIT for GIT_VERSION > + if [[ -z "${CUSTOM_LIBRETRO_COMMIT_SHA}" ]]; then When can it be empty? FWICS you're requiring it for release, and setting it for -9999. > + CUSTOM_LIBRETRO_COMMIT_SHA=3D"\" ${LIBRETRO_COMMIT_SHA:0:7}\"" > + fi > + > + for makefile in "${S}"/?akefile* "${S}"/target-libretro/?akefile*; do Why not combine the two loops and use a single 'sed' call? > + # Add short-rev to Makefile > + sed \ > + -e=20 > "s/GIT_VERSION\s.=3D.*$/GIT_VERSION=3D${CUSTOM_LIBRETRO_COMMIT_SHA}/g" \ > + -i "${makefile}" \ > + &> /dev/null Same as above sed. > + done > + default_src_prepare > +} > + > +# @FUNCTION: libretro-core_src_compile > +# @DESCRIPTION: > +# The libretro-core src_compile function which is exported. > +# > +# This function compiles the shared library for this Libretro core. > +libretro-core_src_compile() { > + emake CC=3D$(tc-getCC) CXX=3D$(tc-getCXX) \ > + $(usex debug "DEBUG=3D1" "") "${myemakeargs[@]}" \ What does DEBUG=3D1 do? myemakeargs is not documented. > + $([[ -f makefile.libretro ]] && echo '-f makefile.libretro') \ > + $([[ -f Makefile.libretro ]] && echo '-f Makefile.libretro') > +} > + > +# @FUNCTION: libretro-core_src_install > +# @DESCRIPTION: > +# The libretro-core src_install function which is exported. > +# > +# This function installs the shared library for this Libretro core. > +libretro-core_src_install() { > + # Absolute path of the directory containing Libretro shared libraries. > + LIBRETRO_LIB_DIR=3D"/usr/$(get_libdir)/libretro" Why are you setting a global variable? > + # If this core's shared library exists, install that. > + if [[ -f "${LIBRETRO_CORE_LIB_FILE}" ]]; then > + insinto "${LIBRETRO_LIB_DIR}" > + doins "${LIBRETRO_CORE_LIB_FILE}" Shared libraries should have +x, so doexe here. > + else > + # Basename of this library. > + local lib_basename=3D"${LIBRETRO_CORE_LIB_FILE##*/}" > + > + # Absolute path to which this library was installed. > + local lib_file_target=3D"${ED}${LIBRETRO_LIB_DIR}/${lib_basename}" > + > + # If this library was *NOT* installed, fail. > + [[ -f "${lib_file_target}" ]] || > + die "Libretro core shared library \"${lib_file_target}\" not=20 > installed." What use case does this whole block cover? > + fi > +} > + > +fi --=20 Best regards, Micha=C5=82 G=C3=B3rny --=-JDdhG1VmQXhksYtGOur/ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQKTBAABCgB9FiEEbbsHzE8NrQbqCv5BsHoa6u+0Rk4FAltaK6JfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDZE QkIwN0NDNEYwREFEMDZFQTBBRkU0MUIwN0ExQUVBRUZCNDQ2NEUACgkQsHoa6u+0 Rk6qahAA0gObqigQn0LonvgzSHJa9GidrCWZTmaQtIGGR0JY4HnOl6jHXQ77hJbh rxz6L5cQamlx/iklG6law+JkTyHvSyytTWrBw+tkNTLzo+ST8h79sAvk+sHxIdX0 kTWHKTeNpOLzZoLi6KcCJBeJNtXxtYhdGDiKvMY2tnqkIwEwAGAzey2tL52ZEjt4 vb10N8gy8YsBZ3FnwhbZxqY8jOxXR+eVqexXO8pAlAzE1A6+1RQtICqZcua/Q4mm CXtMLUMZ7yKEW9b5ARU/TQ53I37jLSmBa33RWzacO8JMpdYcBYF2UTTYF8Zlirn4 QMdo9Ci2siFpXI2hikOEZgpF/FIMJjFgvsnFvnbRUpunCrGcNf4/iy0YPkuCbGXB jZxP/gPXYN+2djPBusAKQFovrgiRwD2aLv12vPB7gMwKYcB480BUydwWgh5irL+q PUjIjS8Bt5KQhwjwMwhEXrff3ECuN50c9y0CUW1wMpAvAWDLQb/ZVdkeKW5EDBwf WNqBr2zaAJ/rszjBmeslhktSVnAXJnVb1sNlsFMx+9rKvjxuBuexbMuw+6nMcUB8 6WwR2c27O9Mh8H5mEdGF76cvMFgcQiO0aN7UcUCJb1BT6D4OlLnfJh5pDhUN6HGE eaAQlfSJLpbcxKJ4gP/H0sq9WJ8p11hfHs73ffPbKvC4tTDGM4c= =2UM1 -----END PGP SIGNATURE----- --=-JDdhG1VmQXhksYtGOur/--