net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / wxwidgets.eclass
1 # Copyright 1999-2015 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 inherit eutils flag-o-matic multilib
62
63 # We do this in global scope so ebuilds can get sane defaults just by
64 # inheriting.
65 if [[ -z ${WX_CONFIG} ]]; then
66         if [[ -n ${WX_GTK_VER} ]]; then
67                 for wxtoolkit in mac gtk2 base; do
68                         # newer versions don't have a seperate debug profile
69                         for wxdebug in xxx release- debug-; do
70                                 wxconf="${wxtoolkit}-unicode-${wxdebug/xxx/}${WX_GTK_VER}"
71
72                                 [[ -f ${EPREFIX}/usr/$(get_libdir)/wx/config/${wxconf} ]] || continue
73
74                                 WX_CONFIG="${EPREFIX}/usr/$(get_libdir)/wx/config/${wxconf}"
75                                 WX_ECLASS_CONFIG="${WX_CONFIG}"
76                                 break
77                         done
78                         [[ -n ${WX_CONFIG} ]] && break
79                 done
80                 [[ -n ${WX_CONFIG} ]] && export WX_CONFIG WX_ECLASS_CONFIG
81         fi
82 fi
83
84 # @FUNCTION:    need-wxwidgets
85 # @USAGE:       <profile>
86 # @DESCRIPTION:
87 #
88 #  Available profiles are:
89 #
90 #    unicode       (USE="X")
91 #    base-unicode  (USE="-X")
92 #
93 #  This lets you choose which config file from /usr/lib/wx/config is used when
94 #  building the package. It also exports ${WX_CONFIG} with the full path to
95 #  that config.
96 #
97 #  If your ebuild does not have a debug USE flag, or it has one and it is
98 #  disabled, -DNDEBUG will be automatically added to CPPFLAGS. This can be
99 #  overridden by setting WX_DISABLE_DEBUG if you want to handle it yourself.
100
101 need-wxwidgets() {
102         local wxtoolkit wxdebug wxconf
103
104         if [[ -z ${WX_GTK_VER} ]]; then
105                 eerror "WX_GTK_VER must be set before calling $FUNCNAME."
106                 echo
107                 die
108         fi
109         
110         if [[ ${WX_GTK_VER} != 2.8 && ${WX_GTK_VER} != 2.9 && ${WX_GTK_VER} != 3.0 ]]; then
111                 eerror "Invalid WX_GTK_VER: ${WX_GTK_VER} - must be set to a valid wxGTK SLOT."
112                 echo
113                 die
114         fi
115
116         case $1 in
117                 unicode|base-unicode) ;;
118                 *)      eerror "Invalid $FUNCNAME profile: $1"
119                         echo
120                         die
121                         ;;
122         esac
123
124         # wxbase is provided by both gtk2 and base installations
125         if has_version "x11-libs/wxGTK:${WX_GTK_VER}[aqua]"; then
126                 wxtoolkit="mac"
127         elif has_version "x11-libs/wxGTK:${WX_GTK_VER}[X]"; then
128                 wxtoolkit="gtk2"
129         else
130                 wxtoolkit="base"
131         fi
132
133         # 2.8 has a separate debug element
134         if [[ ${WX_GTK_VER} == 2.8 ]]; then
135                 if has_version "x11-libs/wxGTK:${WX_GTK_VER}[debug]"; then
136                         wxdebug="debug-"
137                 else
138                         wxdebug="release-"
139                 fi
140         else
141                 if [[ -z ${WX_DISABLE_DEBUG} ]]; then
142                         use_if_iuse debug || append-cppflags -DNDEBUG
143                 fi
144         fi
145
146         wxconf="${wxtoolkit}-unicode-${wxdebug}${WX_GTK_VER}"
147
148         if [[ ! -f ${EPREFIX}/usr/$(get_libdir)/wx/config/${wxconf} ]]; then
149                 echo
150                 eerror "Failed to find configuration ${wxconf}"
151                 echo
152                 die
153         fi
154
155         export WX_CONFIG="${EPREFIX}/usr/$(get_libdir)/wx/config/${wxconf}"
156         export WX_ECLASS_CONFIG="${WX_CONFIG}"
157
158         echo
159         einfo "Requested wxWidgets:        ${1} ${WX_GTK_VER}"
160         einfo "Using wxWidgets:            ${wxconf}"
161         echo
162 }