1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
9 # Alexandre Rostovtsev <tetromino@gentoo.org>
10 # @BLURB: Sets up the environment for using a specific version of vala.
12 # This eclass sets up commonly used environment variables for using a specific
13 # version of dev-lang/vala to configure and build a package. It is needed for
14 # packages whose build systems assume the existence of certain unversioned vala
15 # executables, pkgconfig files, etc., which Gentoo does not provide.
17 # This eclass provides one phase function: src_prepare.
19 inherit eutils multilib
22 0) die "EAPI=0 is not supported" ;;
24 *) EXPORT_FUNCTIONS src_prepare ;;
27 # @ECLASS-VARIABLE: VALA_MIN_API_VERSION
29 # Minimum vala API version (e.g. 0.22).
30 VALA_MIN_API_VERSION=${VALA_MIN_API_VERSION:-0.22}
32 # @ECLASS-VARIABLE: VALA_MAX_API_VERSION
34 # Maximum vala API version (e.g. 0.30).
35 VALA_MAX_API_VERSION=${VALA_MAX_API_VERSION:-0.30}
37 # @ECLASS-VARIABLE: VALA_USE_DEPEND
40 # USE dependencies that vala must be built with (e.g. vapigen).
42 # @FUNCTION: vala_api_versions
44 # Outputs a list of vala API versions from VALA_MAX_API_VERSION down to
45 # VALA_MIN_API_VERSION.
47 [[ ${VALA_MIN_API_VERSION} =~ ^0\.[[:digit:]]+$ ]] || die "Invalid syntax of VALA_MIN_API_VERSION"
48 [[ ${VALA_MAX_API_VERSION} =~ ^0\.[[:digit:]]+$ ]] || die "Invalid syntax of VALA_MAX_API_VERSION"
50 local minimal_supported_minor_version minor_version
52 # Dependency atoms are not generated for Vala versions older than 0.${minimal_supported_minor_version}.
53 minimal_supported_minor_version="22"
55 for ((minor_version = ${VALA_MAX_API_VERSION#*.}; minor_version >= ${VALA_MIN_API_VERSION#*.}; minor_version = minor_version - 2)); do
56 if ((minor_version >= minimal_supported_minor_version)); then
57 echo "0.${minor_version}"
62 # @FUNCTION: vala_depend
64 # Outputs a ||-dependency string on vala from VALA_MAX_API_VERSION down to
65 # VALA_MIN_API_VERSION
67 local u v versions=$(vala_api_versions)
68 [[ ${VALA_USE_DEPEND} ]] && u="[${VALA_USE_DEPEND}(+)]"
71 for v in ${versions}; do
72 echo -n " dev-lang/vala:${v}${u}"
77 # @FUNCTION: vala_best_api_version
79 # Returns the highest installed vala API version satisfying
80 # VALA_MAX_API_VERSION, VALA_MIN_API_VERSION, and VALA_USE_DEPEND.
81 vala_best_api_version() {
83 [[ ${VALA_USE_DEPEND} ]] && u="[${VALA_USE_DEPEND}(+)]"
84 for v in $(vala_api_versions); do
85 has_version "dev-lang/vala:${v}${u}" && echo "${v}" && return
89 # @FUNCTION: vala_src_prepare
90 # @USAGE: [--ignore-use] [--vala-api-version api_version]
92 # Sets up the environment variables and pkgconfig files for the
93 # specified API version, or, if no version is specified, for the
94 # highest installed vala API version satisfying
95 # VALA_MAX_API_VERSION, VALA_MIN_API_VERSION, and VALA_USE_DEPEND.
96 # Is a no-op if called without --ignore-use when USE=-vala.
97 # Dies if the USE check is passed (or ignored) and a suitable vala
98 # version is not available.
100 local p d valafoo version ignore_use
106 "--vala-api-version" )
109 [[ ${version} ]] || die "'--vala-api-version' option requires API version parameter."
114 if [[ -z ${ignore_use} ]]; then
115 in_iuse vala && ! use vala && return 0
118 if [[ ${version} ]]; then
119 has_version "dev-lang/vala:${version}" || die "No installed vala:${version}"
121 version=$(vala_best_api_version)
122 [[ ${version} ]] || die "No installed vala in $(vala_depend)"
125 export VALAC=$(type -P valac-${version})
127 valafoo=$(type -P vala-gen-introspect-${version})
128 [[ ${valafoo} ]] && export VALA_GEN_INTROSPECT="${valafoo}"
130 valafoo=$(type -P vapigen-${version})
131 [[ ${valafoo} ]] && export VAPIGEN="${valafoo}"
133 valafoo="${EPREFIX}/usr/share/vala/Makefile.vapigen"
134 [[ -e ${valafoo} ]] && export VAPIGEN_MAKEFILE="${valafoo}"
136 export VAPIGEN_VAPIDIR="${EPREFIX}/usr/share/vala/vapi"
138 mkdir -p "${T}/pkgconfig" || die "mkdir failed"
139 for p in libvala vapigen; do
140 for d in "${EPREFIX}/usr/$(get_libdir)/pkgconfig" "${EPREFIX}/usr/share/pkgconfig"; do
141 if [[ -e ${d}/${p}-${version}.pc ]]; then
142 ln -s "${d}/${p}-${version}.pc" "${T}/pkgconfig/${p}.pc" || die "ln failed"
147 : ${PKG_CONFIG_PATH:="${EPREFIX}/usr/$(get_libdir)/pkgconfig:${EPREFIX}/usr/share/pkgconfig"}
148 export PKG_CONFIG_PATH="${T}/pkgconfig:${PKG_CONFIG_PATH}"