1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
8 # Alexandre Rostovtsev <tetromino@gentoo.org>
9 # @BLURB: Sets up the environment for using a specific version of vala.
11 # This eclass sets up commonly used environment variables for using a specific
12 # version of dev-lang/vala to configure and build a package. It is needed for
13 # packages whose build systems assume the existence of certain unversioned vala
14 # executables, pkgconfig files, etc., which Gentoo does not provide.
16 # This eclass provides one phase function: src_prepare.
18 inherit eutils multilib
21 0) die "EAPI=0 is not supported" ;;
23 *) EXPORT_FUNCTIONS src_prepare ;;
26 # @ECLASS-VARIABLE: VALA_MIN_API_VERSION
28 # Minimum vala API version (e.g. 0.32).
29 VALA_MIN_API_VERSION=${VALA_MIN_API_VERSION:-0.32}
31 # @ECLASS-VARIABLE: VALA_MAX_API_VERSION
33 # Maximum vala API version (e.g. 0.32).
34 VALA_MAX_API_VERSION=${VALA_MAX_API_VERSION:-0.36}
36 # @ECLASS-VARIABLE: VALA_USE_DEPEND
39 # USE dependencies that vala must be built with (e.g. vapigen).
41 # @FUNCTION: vala_api_versions
43 # Outputs a list of vala API versions from VALA_MAX_API_VERSION down to
44 # VALA_MIN_API_VERSION.
46 [[ ${VALA_MIN_API_VERSION} =~ ^0\.[[:digit:]]+$ ]] || die "Invalid syntax of VALA_MIN_API_VERSION"
47 [[ ${VALA_MAX_API_VERSION} =~ ^0\.[[:digit:]]+$ ]] || die "Invalid syntax of VALA_MAX_API_VERSION"
49 local minimal_supported_minor_version minor_version
51 # Dependency atoms are not generated for Vala versions older than 0.${minimal_supported_minor_version}.
52 minimal_supported_minor_version="32"
54 for ((minor_version = ${VALA_MAX_API_VERSION#*.}; minor_version >= ${VALA_MIN_API_VERSION#*.}; minor_version = minor_version - 2)); do
55 if ((minor_version >= minimal_supported_minor_version)); then
56 echo "0.${minor_version}"
61 # @FUNCTION: vala_depend
63 # Outputs a ||-dependency string on vala from VALA_MAX_API_VERSION down to
64 # VALA_MIN_API_VERSION
66 local u v versions=$(vala_api_versions)
67 [[ ${VALA_USE_DEPEND} ]] && u="[${VALA_USE_DEPEND}(+)]"
70 for v in ${versions}; do
71 echo -n " dev-lang/vala:${v}${u}"
76 # @FUNCTION: vala_best_api_version
78 # Returns the highest installed vala API version satisfying
79 # VALA_MAX_API_VERSION, VALA_MIN_API_VERSION, and VALA_USE_DEPEND.
80 vala_best_api_version() {
82 [[ ${VALA_USE_DEPEND} ]] && u="[${VALA_USE_DEPEND}(+)]"
83 for v in $(vala_api_versions); do
84 has_version "dev-lang/vala:${v}${u}" && echo "${v}" && return
88 # @FUNCTION: vala_src_prepare
89 # @USAGE: [--ignore-use] [--vala-api-version api_version]
91 # Sets up the environment variables and pkgconfig files for the
92 # specified API version, or, if no version is specified, for the
93 # highest installed vala API version satisfying
94 # VALA_MAX_API_VERSION, VALA_MIN_API_VERSION, and VALA_USE_DEPEND.
95 # Is a no-op if called without --ignore-use when USE=-vala.
96 # Dies if the USE check is passed (or ignored) and a suitable vala
97 # version is not available.
99 local p d valafoo version ignore_use
105 "--vala-api-version" )
108 [[ ${version} ]] || die "'--vala-api-version' option requires API version parameter."
113 if [[ -z ${ignore_use} ]]; then
114 in_iuse vala && ! use vala && return 0
117 if [[ ${version} ]]; then
118 has_version "dev-lang/vala:${version}" || die "No installed vala:${version}"
120 version=$(vala_best_api_version)
121 [[ ${version} ]] || die "No installed vala in $(vala_depend)"
124 export VALAC=$(type -P valac-${version})
126 valafoo=$(type -P vala-gen-introspect-${version})
127 [[ ${valafoo} ]] && export VALA_GEN_INTROSPECT="${valafoo}"
129 valafoo=$(type -P vapigen-${version})
130 [[ ${valafoo} ]] && export VAPIGEN="${valafoo}"
132 valafoo="${EPREFIX}/usr/share/vala/Makefile.vapigen"
133 [[ -e ${valafoo} ]] && export VAPIGEN_MAKEFILE="${valafoo}"
135 export VAPIGEN_VAPIDIR="${EPREFIX}/usr/share/vala/vapi"
137 mkdir -p "${T}/pkgconfig" || die "mkdir failed"
138 for p in libvala vapigen; do
139 for d in "${EPREFIX}/usr/$(get_libdir)/pkgconfig" "${EPREFIX}/usr/share/pkgconfig"; do
140 if [[ -e ${d}/${p}-${version}.pc ]]; then
141 ln -s "${d}/${p}-${version}.pc" "${T}/pkgconfig/${p}.pc" || die "ln failed"
146 : ${PKG_CONFIG_PATH:="${EPREFIX}/usr/$(get_libdir)/pkgconfig:${EPREFIX}/usr/share/pkgconfig"}
147 export PKG_CONFIG_PATH="${T}/pkgconfig:${PKG_CONFIG_PATH}"