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 66D5A138239 for ; Thu, 9 Aug 2018 20:59:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0A43FE09CE; Thu, 9 Aug 2018 20:59:22 +0000 (UTC) Received: from smtpauth.rollernet.us (smtpauth.rollernet.us [IPv6:2607:fe70:0:3::d]) (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 A08E1E09BB for ; Thu, 9 Aug 2018 20:59:21 +0000 (UTC) Received: from smtpauth.rollernet.us (localhost [127.0.0.1]) by smtpauth.rollernet.us (Postfix) with ESMTP id 6BEE42805075 for ; Thu, 9 Aug 2018 13:59:19 -0700 (PDT) Received: from irrational.integralblue.com (pool-173-76-206-89.bstnma.fios.verizon.net [173.76.206.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by smtpauth.rollernet.us (Postfix) with ESMTPSA for ; Thu, 9 Aug 2018 13:59:19 -0700 (PDT) Received: from localhost (irrational [127.0.0.1]) by localhost (Postfix) with ESMTP id DB2CA3DC9913 for ; Thu, 9 Aug 2018 16:59:11 -0400 (EDT) X-Virus-Scanned: amavisd-new at integralblue.com Received: from irrational.integralblue.com ([127.0.0.1]) by localhost (integralblue.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id dzOJXLzPImh6 for ; Thu, 9 Aug 2018 16:58:56 -0400 (EDT) Received: from www.integralblue.com (irrational [IPv6:::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by irrational.integralblue.com (Postfix) with ESMTPSA id C59D63DC98FD for ; Thu, 9 Aug 2018 16:58:56 -0400 (EDT) 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 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 09 Aug 2018 16:58:56 -0400 From: Craig Andrews To: gentoo-dev@lists.gentoo.org Subject: [gentoo-dev] [PATCH v2] libretro-core.eclass: An eclass to streamline the construction of Libretro core ebuilds Message-ID: X-Sender: candrews@gentoo.org User-Agent: Roundcube Webmail/1.3.7 X-Rollernet-Abuse: Processed by Roller Network Mail Services. Contact abuse@rollernet.us to report violations. Abuse policy: http://www.rollernet.us/policy X-Rollernet-Submit: Submit ID 654e.5b6cab27.60cbb.0 X-Archives-Salt: 0f5cb235-46f2-49e9-a48d-cd23fed46a1a X-Archives-Hash: 8e15d06fd330e0ab97d335baf8e3c47e I'm proposing the addition of a new eclass, libretro-core.eclass, which I'll use when adding a number of libretro ebuilds. This version incorporates all the changes and suggestions posed so far. The pull request which includes this eclass as well as a few ebuilds using it (with more to come) can be found at https://github.com/gentoo/gentoo/pull/9330 Thanks, ~Craig --- eclass/libretro-core.eclass | 197 ++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 eclass/libretro-core.eclass diff --git a/eclass/libretro-core.eclass b/eclass/libretro-core.eclass new file mode 100644 index 000000000000..510f905111ce --- /dev/null +++ b/eclass/libretro-core.eclass @@ -0,0 +1,197 @@ +# 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: Simplify libretro core ebuilds +# @DESCRIPTION: +# The libretro eclass is designed to streamline the construction of +# ebuilds for Libretro core ebuilds. +# +# Libretro cores can be found under https://github.com/libretro/ +# +# They all use the same basic make based build system, are located +# in the same github account, and do not release named or numbered +# versions (so ebuild versions for git commits are keys). +# This eclass covers those commonalities reducing much duplication +# between the ebuilds. +# @EXAMPLE: +# @CODE +# EAPI=7 +# +# LIBRETRO_CORE_NAME="2048" +# LIBRETRO_COMMIT_SHA="45655d3662e4cbcd8afb28e2ee3f5494a75888de" +# KEYWORDS="~amd64 ~x86" +# inherit libretro-core +# +# DESCRIPTION="Port of 2048 puzzle game to the libretro API" +# LICENSE="Unlicense" +# SLOT="0" +# @CODE + +if [[ -z ${_LIBRETRO_CORE_ECLASS} ]]; then +_LIBRETRO_CORE_ECLASS=1 + +IUSE="debug" + +# @ECLASS-VARIABLE: LIBRETRO_CORE_NAME +# @REQUIRED +# @DESCRIPTION: +# Name of this Libretro core. The libretro-core_src_install() phase function +# will install the shared library "${S}/${LIBRETRO_CORE_NAME}_libretro.so" as a +# Libretro core. Defaults to the name of the current package excluding the +# "libretro-" prefix (e.g., "mgba" for the package "libretro-mgba"). +: ${LIBRETRO_CORE_NAME:=${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 "repouser/reponame". +# Needs to be set before inherit. Otherwise defaults to "libretro/${PN}" +: ${LIBRETRO_REPO_NAME:="libretro/libretro-${LIBRETRO_CORE_NAME}"} + +: ${HOMEPAGE:="https://github.com/${LIBRETRO_REPO_NAME}"} + +if [[ ${PV} == *9999 ]]; then + : ${EGIT_REPO_URI:="https://github.com/${LIBRETRO_REPO_NAME}.git"} + inherit git-r3 +else + [[ -z "${LIBRETRO_COMMIT_SHA}" ]] && die "LIBRETRO_COMMIT_SHA must be set before inherit." + S="${WORKDIR}/${LIBRETRO_REPO_NAME##*/}-${LIBRETRO_COMMIT_SHA}" + : ${SRC_URI:="https://github.com/${LIBRETRO_REPO_NAME}/archive/${LIBRETRO_COMMIT_SHA}.tar.gz -> ${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:="${S}/${LIBRETRO_CORE_NAME}_libretro.so"} + +case "${EAPI:-0}" in + 6|7) + EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install + ;; + *) + die "EAPI=${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} == *9999 ]]; then + git-r3_src_unpack + # Add used commit SHA for version information, the above could also work. + LIBRETRO_COMMIT_SHA=$(git -C "${WORKDIR}/${P}" rev-parse HEAD) + # 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() { + ebegin "Attempting to hack Makefiles to use custom cflags" + # Populate COMMIT for GIT_VERSION + CUSTOM_LIBRETRO_COMMIT_SHA="\" ${LIBRETRO_COMMIT_SHA:0:7}\"" + local makefile + local flags_modified=0 + local shopt_saved=$(shopt -p nullglob) + shopt -s nullglob + for makefile in "${S}"/[Mm]akefile* "${S}"/target-libretro/[Mm]akefile*; do + # * 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) + # * Add short-rev to Makefile + [[ -e "${makefile}" ]] && sed \ + -e 's/\r$//g' \ + -e "/flags.*=/s:-O[[:digit:]]:${CFLAGS}:g" \ + -e "/CFLAGS.*=/s:-O[[:digit:]]:${CFLAGS}:g" \ + -e "/.*,--version-script=.*/s:$: ${LDFLAGS} ${LIBS}:g" \ + -e "/\$(CC)/s:\(\$(SHARED)\):\1 ${LDFLAGS} ${LIBS}:" \ + -e 's:\(\$(CC)\):\1 \$(CFLAGS):g' \ + -e "s/GIT_VERSION\s.=.*$/GIT_VERSION=${CUSTOM_LIBRETRO_COMMIT_SHA}/g" \ + -i "${makefile}" || die "Failed to use custom cflags in ${makefile}" + done + ${shopt_saved} + eend + export OPTFLAGS="${CFLAGS}" + default_src_prepare +} + +# @VARIABLE: myemakeargs +# @DEFAULT_UNSET +# @DESCRIPTION: +# Optional emake arguments as a bash array. Should be defined before calling +# src_compile. +# @CODE +# src_compile() { +# local myemakeargs=( +# $(usex neon "HAVE_NEON=1" "") +# ) +# libretro-core_src_configure +# } +# @CODE + +# @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() { + # most (if not all) libretro makefiles use DEBUG=1 + # to enable additional debug features. + emake CC=$(tc-getCC) CXX=$(tc-getCXX) \ + $(usex debug "DEBUG=1" "") "${myemakeargs[@]}" \ + $([[ -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. + local LIBRETRO_LIB_DIR="/usr/$(get_libdir)/libretro" + # If this core's shared library exists, install that. + if [[ -f "${LIBRETRO_CORE_LIB_FILE}" ]]; then + insinto "${LIBRETRO_LIB_DIR}" + doexe "${LIBRETRO_CORE_LIB_FILE}" + else + # Basename of this library. + local lib_basename="${LIBRETRO_CORE_LIB_FILE##*/}" + + # Absolute path to which this library was installed. + local lib_file_target="${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 installed." + fi +} + +fi # end _LIBRETRO_CORE_ECLASS guard -- 2.18.0