nvidia-driver.eclass: Use next gen version of readme.gentoo eclass
[gentoo.git] / eclass / wxwidgets.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: wxwidgets.eclass
6 # @MAINTAINER:
7 # wxwidgets@gentoo.org
8 # @BLURB: Manages build configuration for wxGTK-using packages.
9 # @DESCRIPTION:
10 #  This eclass gives ebuilds the ability to build against a specific wxGTK
11 #  SLOT and profile without interfering with the system configuration.  Any
12 #  ebuild with a x11-libs/wxGTK dependency must use this eclass.
13 #
14 #  There are two ways to do it:
15 #
16 #    - set WX_GTK_VER before inheriting the eclass
17 #    - set WX_GTK_VER and call need-wxwidgets from a phase function
18 #
19 #  (where WX_GTK_VER is the SLOT you want)
20 #
21 #  If your package has optional support for wxGTK (ie. by a USE flag) then
22 #  you should use need-wxwidgets.  This is important because some packages
23 #  will force-enable wxGTK if they find WX_CONFIG set in the environment.
24 #
25 # @CODE
26 #      inherit wxwidgets
27 #
28 #      IUSE="X wxwidgets"
29 #      DEPEND="wxwidgets? ( x11-libs/wxGTK:2.8[X?] )"
30 #
31 #      src_configure() {
32 #          if use wxwidgets; then
33 #              WX_GTK_VER="2.8"
34 #              if use X; then
35 #                  need-wxwidgets unicode
36 #              else
37 #                  need-wxwidgets base-unicode
38 #              fi
39 #          fi
40 #          econf --with-wx-config="${WX_CONFIG}"
41 #      }
42 # @CODE
43 #
44 # That's about as complicated as it gets.  99% of ebuilds can get away with:
45 #
46 # @CODE
47 #      inherit wxwidgets
48 #      DEPEND="wxwidgets? ( x11-libs/wxGTK:2.8[X] )
49 #      ...
50 #      WX_GTK_VER=2.8 need-wxwidgets unicode
51 # @CODE
52 #
53 # Note: unless you know your package works with wxbase (which is very
54 # doubtful), always depend on wxGTK[X].
55 #
56 # Debugging: In wxGTK 3.0 and later debugging support is enabled in the
57 # library by default and needs to be controlled at the package level.
58 # Use the -DNDEBUG preprocessor flag to disable debugging features.
59 # (Using need-wxwidgets will do this for you, see below.)
60
61 if [[ -z ${_WXWIDGETS_ECLASS} ]]; then
62
63 case ${EAPI} in
64         0|1|2|3|4|5)
65                 inherit eutils flag-o-matic multilib
66                 ;;
67         *)
68                 die "EAPI=${EAPI:-0} is not supported"
69                 ;;
70 esac
71
72 # We do this in global scope so ebuilds can get sane defaults just by
73 # inheriting.
74 if [[ -z ${WX_CONFIG} ]]; then
75         if [[ -n ${WX_GTK_VER} ]]; then
76                 for _wxtoolkit in mac gtk2 base; do
77                         # newer versions don't have a seperate debug profile
78                         for _wxdebug in xxx release- debug-; do
79                                 _wxconf="${_wxtoolkit}-unicode-${_wxdebug/xxx/}${WX_GTK_VER}"
80
81                                 [[ -f ${EPREFIX}/usr/$(get_libdir)/wx/config/${_wxconf} ]] || continue
82
83                                 WX_CONFIG="${EPREFIX}/usr/$(get_libdir)/wx/config/${_wxconf}"
84                                 WX_ECLASS_CONFIG="${WX_CONFIG}"
85                                 break
86                         done
87                         [[ -n ${WX_CONFIG} ]] && break
88                 done
89                 [[ -n ${WX_CONFIG} ]] && export WX_CONFIG WX_ECLASS_CONFIG
90         fi
91 fi
92 unset _wxtoolkit
93 unset _wxdebug
94 unset _wxconf
95
96 # @FUNCTION:    need-wxwidgets
97 # @USAGE:       <profile>
98 # @DESCRIPTION:
99 #
100 #  Available profiles are:
101 #
102 #    unicode       (USE="X")
103 #    base-unicode  (USE="-X")
104 #
105 #  This lets you choose which config file from /usr/lib/wx/config is used when
106 #  building the package. It also exports ${WX_CONFIG} with the full path to
107 #  that config.
108 #
109 #  If your ebuild does not have a debug USE flag, or it has one and it is
110 #  disabled, -DNDEBUG will be automatically added to CPPFLAGS. This can be
111 #  overridden by setting WX_DISABLE_DEBUG if you want to handle it yourself.
112
113 need-wxwidgets() {
114         local wxtoolkit wxdebug wxconf
115
116         if [[ -z ${WX_GTK_VER} ]]; then
117                 eerror "WX_GTK_VER must be set before calling $FUNCNAME."
118                 echo
119                 die
120         fi
121
122         if [[ ${WX_GTK_VER} != 2.8 && ${WX_GTK_VER} != 2.9 && ${WX_GTK_VER} != 3.0 ]]; then
123                 eerror "Invalid WX_GTK_VER: ${WX_GTK_VER} - must be set to a valid wxGTK SLOT."
124                 echo
125                 die
126         fi
127
128         case $1 in
129                 unicode|base-unicode) ;;
130                 *)      eerror "Invalid $FUNCNAME profile: $1"
131                         echo
132                         die
133                         ;;
134         esac
135
136         # wxbase is provided by both gtk2 and base installations
137         if has_version "x11-libs/wxGTK:${WX_GTK_VER}[aqua]"; then
138                 wxtoolkit="mac"
139         elif has_version "x11-libs/wxGTK:${WX_GTK_VER}[X]"; then
140                 wxtoolkit="gtk2"
141         else
142                 wxtoolkit="base"
143         fi
144
145         # 2.8 has a separate debug element
146         if [[ ${WX_GTK_VER} == 2.8 ]]; then
147                 if has_version "x11-libs/wxGTK:${WX_GTK_VER}[debug]"; then
148                         wxdebug="debug-"
149                 else
150                         wxdebug="release-"
151                 fi
152         else
153                 if [[ -z ${WX_DISABLE_DEBUG} ]]; then
154                         use_if_iuse debug || append-cppflags -DNDEBUG
155                 fi
156         fi
157
158         wxconf="${wxtoolkit}-unicode-${wxdebug}${WX_GTK_VER}"
159
160         if [[ ! -f ${EPREFIX}/usr/$(get_libdir)/wx/config/${wxconf} ]]; then
161                 echo
162                 eerror "Failed to find configuration ${wxconf}"
163                 echo
164                 die
165         fi
166
167         export WX_CONFIG="${EPREFIX}/usr/$(get_libdir)/wx/config/${wxconf}"
168         export WX_ECLASS_CONFIG="${WX_CONFIG}"
169
170         echo
171         einfo "Requested wxWidgets:        ${1} ${WX_GTK_VER}"
172         einfo "Using wxWidgets:            ${wxconf}"
173         echo
174 }
175
176 _WXWIDGETS_ECLASS=1
177 fi