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 # @SUPPORTED_EAPIS: 1 2 3 4 5 6 7
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.36).
30 VALA_MIN_API_VERSION=${VALA_MIN_API_VERSION:-0.36}
32 # @ECLASS-VARIABLE: VALA_MAX_API_VERSION
34 # Maximum vala API version (e.g. 0.36).
35 VALA_MAX_API_VERSION=${VALA_MAX_API_VERSION:-0.46}
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="36"
55 for ((minor_version = ${VALA_MAX_API_VERSION#*.}; minor_version >= ${VALA_MIN_API_VERSION#*.}; minor_version = minor_version - 2)); do
56 # 0.38 was never in main tree; remove the special case once minimal_supported_minor_version >= 40
57 if ((minor_version >= minimal_supported_minor_version)) && ((minor_version != 38)); then
58 echo "0.${minor_version}"
63 # Outputs VALA_USE_DEPEND as a a USE-dependency string
67 if [[ -n ${VALA_USE_DEPEND} ]]; then
68 for vala_use in ${VALA_USE_DEPEND}; do
70 vapigen) u="${u},${vala_use}(+)" ;;
71 valadoc) u="${u},${vala_use}(-)" ;;
80 # @FUNCTION: vala_depend
82 # Outputs a ||-dependency string on vala from VALA_MAX_API_VERSION down to
83 # VALA_MIN_API_VERSION
89 for v in $(vala_api_versions); do
90 echo -n " dev-lang/vala:${v}${u}"
95 # @FUNCTION: vala_best_api_version
97 # Returns the highest installed vala API version satisfying
98 # VALA_MAX_API_VERSION, VALA_MIN_API_VERSION, and VALA_USE_DEPEND.
99 vala_best_api_version() {
101 u=$(_vala_use_depend)
103 for v in $(vala_api_versions); do
104 has_version "dev-lang/vala:${v}${u}" && echo "${v}" && return
108 # @FUNCTION: vala_src_prepare
109 # @USAGE: [--ignore-use] [--vala-api-version api_version]
111 # Sets up the environment variables and pkgconfig files for the
112 # specified API version, or, if no version is specified, for the
113 # highest installed vala API version satisfying
114 # VALA_MAX_API_VERSION, VALA_MIN_API_VERSION, and VALA_USE_DEPEND.
115 # Is a no-op if called without --ignore-use when USE=-vala.
116 # Dies if the USE check is passed (or ignored) and a suitable vala
117 # version is not available.
119 local p d valafoo version ignore_use
125 "--vala-api-version" )
128 [[ ${version} ]] || die "'--vala-api-version' option requires API version parameter."
133 if [[ -z ${ignore_use} ]]; then
134 in_iuse vala && ! use vala && return 0
137 if [[ ${version} ]]; then
138 has_version "dev-lang/vala:${version}" || die "No installed vala:${version}"
140 version=$(vala_best_api_version)
141 [[ ${version} ]] || die "No installed vala in $(vala_depend)"
144 export VALAC=$(type -P valac-${version})
146 valafoo=$(type -P vala-gen-introspect-${version})
147 [[ ${valafoo} ]] && export VALA_GEN_INTROSPECT="${valafoo}"
149 valafoo=$(type -P vapigen-${version})
150 [[ ${valafoo} ]] && export VAPIGEN="${valafoo}"
152 valafoo=$(type -P valadoc-${version})
153 [[ ${valafoo} ]] && has valadoc ${VALA_USE_DEPEND} && export VALADOC="${valafoo}"
155 valafoo="${EPREFIX}/usr/share/vala/Makefile.vapigen"
156 [[ -e ${valafoo} ]] && export VAPIGEN_MAKEFILE="${valafoo}"
158 export VAPIGEN_VAPIDIR="${EPREFIX}/usr/share/vala/vapi"
160 mkdir -p "${T}/pkgconfig" || die "mkdir failed"
161 for p in libvala vapigen; do
162 for d in "${EPREFIX}/usr/$(get_libdir)/pkgconfig" "${EPREFIX}/usr/share/pkgconfig"; do
163 if [[ -e ${d}/${p}-${version}.pc ]]; then
164 ln -s "${d}/${p}-${version}.pc" "${T}/pkgconfig/${p}.pc" || die "ln failed"
169 : ${PKG_CONFIG_PATH:="${EPREFIX}/usr/$(get_libdir)/pkgconfig:${EPREFIX}/usr/share/pkgconfig"}
170 export PKG_CONFIG_PATH="${T}/pkgconfig:${PKG_CONFIG_PATH}"