ecm.eclass: Set correct KFMIN default for kde-frameworks/*
[gentoo.git] / eclass / vala.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: vala.eclass
5 # @MAINTAINER:
6 # gnome@gentoo.org
7 # @AUTHOR:
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.
11 # @DESCRIPTION:
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.
16 #
17 # This eclass provides one phase function: src_prepare.
18
19 inherit eutils multilib
20
21 case "${EAPI:-0}" in
22         0)      die "EAPI=0 is not supported" ;;
23         1)      ;;
24         *)      EXPORT_FUNCTIONS src_prepare ;;
25 esac
26
27 # @ECLASS-VARIABLE: VALA_MIN_API_VERSION
28 # @DESCRIPTION:
29 # Minimum vala API version (e.g. 0.36).
30 VALA_MIN_API_VERSION=${VALA_MIN_API_VERSION:-0.36}
31
32 # @ECLASS-VARIABLE: VALA_MAX_API_VERSION
33 # @DESCRIPTION:
34 # Maximum vala API version (e.g. 0.36).
35 VALA_MAX_API_VERSION=${VALA_MAX_API_VERSION:-0.46}
36
37 # @ECLASS-VARIABLE: VALA_USE_DEPEND
38 # @DEFAULT_UNSET
39 # @DESCRIPTION:
40 # USE dependencies that vala must be built with (e.g. vapigen).
41
42 # @FUNCTION: vala_api_versions
43 # @DESCRIPTION:
44 # Outputs a list of vala API versions from VALA_MAX_API_VERSION down to
45 # VALA_MIN_API_VERSION.
46 vala_api_versions() {
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"
49
50         local minimal_supported_minor_version minor_version
51
52         # Dependency atoms are not generated for Vala versions older than 0.${minimal_supported_minor_version}.
53         minimal_supported_minor_version="36"
54
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}"
59                 fi
60         done
61 }
62
63 # Outputs VALA_USE_DEPEND as a a USE-dependency string
64 _vala_use_depend() {
65         local u="" vala_use
66
67         if [[ -n ${VALA_USE_DEPEND} ]]; then
68                 for vala_use in ${VALA_USE_DEPEND}; do
69                         case ${vala_use} in
70                                 vapigen) u="${u},${vala_use}(+)" ;;
71                                 valadoc) u="${u},${vala_use}(-)" ;;
72                         esac
73                 done
74                 u="[${u#,}]"
75         fi
76
77         echo -n "${u}"
78 }
79
80 # @FUNCTION: vala_depend
81 # @DESCRIPTION:
82 # Outputs a ||-dependency string on vala from VALA_MAX_API_VERSION down to
83 # VALA_MIN_API_VERSION
84 vala_depend() {
85         local u v
86         u=$(_vala_use_depend)
87
88         echo -n "|| ("
89         for v in $(vala_api_versions); do
90                 echo -n " dev-lang/vala:${v}${u}"
91         done
92         echo " )"
93 }
94
95 # @FUNCTION: vala_best_api_version
96 # @DESCRIPTION:
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() {
100         local u v
101         u=$(_vala_use_depend)
102
103         for v in $(vala_api_versions); do
104                 has_version "dev-lang/vala:${v}${u}" && echo "${v}" && return
105         done
106 }
107
108 # @FUNCTION: vala_src_prepare
109 # @USAGE: [--ignore-use] [--vala-api-version api_version]
110 # @DESCRIPTION:
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.
118 vala_src_prepare() {
119         local p d valafoo version ignore_use
120
121         while [[ $1 ]]; do
122                 case $1 in
123                         "--ignore-use" )
124                                 ignore_use=1 ;;
125                         "--vala-api-version" )
126                                 shift
127                                 version=$1
128                                 [[ ${version} ]] || die "'--vala-api-version' option requires API version parameter."
129                 esac
130                 shift
131         done
132
133         if [[ -z ${ignore_use} ]]; then
134                 in_iuse vala && ! use vala && return 0
135         fi
136
137         if [[ ${version} ]]; then
138                 has_version "dev-lang/vala:${version}" || die "No installed vala:${version}"
139         else
140                 version=$(vala_best_api_version)
141                 [[ ${version} ]] || die "No installed vala in $(vala_depend)"
142         fi
143
144         export VALAC=$(type -P valac-${version})
145
146         valafoo=$(type -P vala-gen-introspect-${version})
147         [[ ${valafoo} ]] && export VALA_GEN_INTROSPECT="${valafoo}"
148
149         valafoo=$(type -P vapigen-${version})
150         [[ ${valafoo} ]] && export VAPIGEN="${valafoo}"
151
152         valafoo=$(type -P valadoc-${version})
153         [[ ${valafoo} ]] && has valadoc ${VALA_USE_DEPEND} && export VALADOC="${valafoo}"
154
155         valafoo="${EPREFIX}/usr/share/vala/Makefile.vapigen"
156         [[ -e ${valafoo} ]] && export VAPIGEN_MAKEFILE="${valafoo}"
157
158         export VAPIGEN_VAPIDIR="${EPREFIX}/usr/share/vala/vapi"
159
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"
165                                 break
166                         fi
167                 done
168         done
169         : ${PKG_CONFIG_PATH:="${EPREFIX}/usr/$(get_libdir)/pkgconfig:${EPREFIX}/usr/share/pkgconfig"}
170         export PKG_CONFIG_PATH="${T}/pkgconfig:${PKG_CONFIG_PATH}"
171 }