kde5.eclass: Cleanup obsolete blocker
[gentoo.git] / eclass / gnustep-base.eclass
1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: gnustep-base.eclass
5 # @MAINTAINER:
6 # GNUstep Herd <gnustep@gentoo.org>
7 # @BLURB: Internal handling of GNUstep pacakges
8 # @DESCRIPTION:
9 # Inner gnustep eclass, should only be inherited directly by gnustep-base
10 # packages
11
12 inherit eutils flag-o-matic
13
14 # IUSE variables across all GNUstep packages
15 # "debug": enable code for debugging
16 # "doc": build and install documentation, if available
17 IUSE="debug doc"
18
19 # packages needed to build any base gnustep package
20 GNUSTEP_CORE_DEPEND="doc? ( virtual/texi2dvi dev-tex/latex2html app-text/texi2html )"
21
22 # New layout is used when ${EPREFIX}/usr/share/GNUstep/Makefiles exists
23 # Where to install GNUstep (with old layout)
24 GNUSTEP_PREFIX="${EPREFIX}/usr/GNUstep"
25
26 # GNUstep environment array
27 typeset -a GS_ENV
28
29 # Ebuild function overrides
30 gnustep-base_pkg_setup() {
31         if test_version_info 3.3 ; then
32                 strip-unsupported-flags
33         elif test_version_info 3.4 ; then
34                 # strict-aliasing is known to break obj-c stuff in gcc-3.4*
35                 filter-flags -fstrict-aliasing
36         fi
37
38         # known to break ObjC (bug 86089)
39         filter-flags -fomit-frame-pointer
40 }
41
42 gnustep-base_src_unpack() {
43         unpack ${A}
44         cd "${S}"
45
46         gnustep-base_src_prepare
47 }
48
49 gnustep-base_src_prepare() {
50         if [[ -f ./GNUmakefile ]] ; then
51                 # Kill stupid includes that are simply overdone or useless on normal
52                 # Gentoo, but (may) cause major headaches on Prefixed Gentoo.  If this
53                 # only removes a part of a path it's good that it bails out, as we want
54                 # to know when they use some direct include.
55                 ebegin "Cleaning paths from GNUmakefile"
56                 sed -i \
57                         -e 's|-I/usr/X11R6/include/\?||g' \
58                         -e 's|-I/usr/include/\?||g' \
59                         -e 's|-L/usr/X11R6/lib/\?||g' \
60                         -e 's|-L/usr/lib/\?||g' \
61                         GNUmakefile
62                 eend $?
63         fi
64
65         has ${EAPI:-0} 6 && default
66 }
67
68 gnustep-base_src_configure() {
69         egnustep_env
70         if [[ -x ./configure ]] ; then
71                 econf || die "configure failed"
72         fi
73 }
74
75 gnustep-base_src_compile() {
76         egnustep_env
77         case ${EAPI:-0} in
78                 0|1) gnustep-base_src_configure ;;
79         esac
80
81         egnustep_make
82 }
83
84 gnustep-base_src_install() {
85         egnustep_env
86         egnustep_install
87         if use doc ; then
88                 egnustep_env
89                 egnustep_doc
90         fi
91         egnustep_install_config
92 }
93
94 gnustep-base_pkg_postinst() {
95         [[ $(type -t gnustep_config_script) != "function" ]] && return 0
96
97         local SCRIPT_PATH
98         if [[ -d ${EPREFIX}/usr/share/GNUstep/Makefiles ]]; then
99                 SCRIPT_PATH="/usr/bin"
100         else
101                 SCRIPT_PATH=${GNUSTEP_SYSTEM_TOOLS}/Gentoo
102         fi
103         elog "To use this package, as *user* you should run:"
104         elog "  ${SCRIPT_PATH}/config-${PN}.sh"
105 }
106
107 # Clean/reset an ebuild to the installed GNUstep environment
108 egnustep_env() {
109         # Get additional variables
110         GNUSTEP_SH_EXPORT_ALL_VARIABLES="true"
111
112         # Makefiles path
113         local GS_MAKEFILES
114         if [[ -d ${EPREFIX}/usr/share/GNUstep/Makefiles ]]; then
115                 GS_MAKEFILES=${EPREFIX}/usr/share/GNUstep/Makefiles
116         else
117                 GS_MAKEFILES=${GNUSTEP_PREFIX}/System/Library/Makefiles
118         fi
119         if [[ -f ${GS_MAKEFILES}/GNUstep.sh ]] ; then
120                 # Reset GNUstep variables
121                 source "${GS_MAKEFILES}"/GNUstep-reset.sh
122                 source "${GS_MAKEFILES}"/GNUstep.sh
123
124                 # Create compilation GNUstep.conf if it does not exist yet
125                 if [[ ! -f ${WORKDIR}/GNUstep.conf ]]; then
126                         cp "${EPREFIX}"/etc/GNUstep/GNUstep.conf "${WORKDIR}" \
127                                 || die "GNUstep.conf copy failed"
128                         sed -e "s#\(GNUSTEP_USER_.*DIR.*=\)#\1${WORKDIR}/#" \
129                                 -i "${WORKDIR}"/GNUstep.conf || die "GNUstep.conf sed failed"
130                 fi
131
132
133                 if [[ ! -d ${EPREFIX}/usr/share/GNUstep/Makefiles ]]; then
134                         # Set rpath in ldflags when available
135                         case ${CHOST} in
136                                 *-linux-gnu|*-solaris*)
137                                         is-ldflagq -Wl,-rpath="${GNUSTEP_SYSTEM_LIBRARIES}" \
138                                                 || append-ldflags \
139                                                         -Wl,-rpath="${GNUSTEP_SYSTEM_LIBRARIES}"
140                                 ;;
141                         esac
142                 fi
143
144                 # Set up env vars for make operations
145                 GS_ENV=( AUXILIARY_LDFLAGS="${LDFLAGS}" \
146                         ADDITIONAL_NATIVE_LIB_DIRS="${GNUSTEP_SYSTEM_LIBRARIES}" \
147                         DESTDIR="${D}" \
148                         HOME="${T}" \
149                         GNUSTEP_CONFIG_FILE="${WORKDIR}"/GNUstep.conf \
150                         GNUSTEP_INSTALLATION_DOMAIN=SYSTEM \
151                         TAR_OPTIONS="${TAR_OPTIONS} --no-same-owner" \
152                         messages=yes )
153
154                 use doc \
155                         && GS_ENV=( "${GS_ENV[@]}" VARTEXFONTS="${T}"/fonts )
156
157                 use debug \
158                         && GS_ENV=( "${GS_ENV[@]}" "debug=yes" ) \
159                         || GS_ENV=( "${GS_ENV[@]}" "debug=no" )
160
161                 if has_version "gnustep-base/gnustep-make[libobjc2]";
162                 then
163                         # Set clang for packages that do not respect gnustep-make
164                         # settings (gnustep-base's configure for example)
165                         export CC=clang CXX=clang CPP="clang -E" LD="clang"
166                 fi
167
168                 return 0
169         fi
170         die "gnustep-make not installed!"
171 }
172
173 # Make utilizing GNUstep Makefiles
174 egnustep_make() {
175         if [[ -f ./Makefile || -f ./makefile || -f ./GNUmakefile ]] ; then
176                 emake ${*} "${GS_ENV[@]}" all || die "package make failed"
177                 return 0
178         fi
179         die "no Makefile found"
180 }
181
182 # Make-install utilizing GNUstep Makefiles
183 egnustep_install() {
184         if [[ ! -d ${EPREFIX}/usr/share/GNUstep/Makefiles ]]; then
185                 # avoid problems due to our "weird" prefix, make sure it exists
186                 mkdir -p "${D}"${GNUSTEP_SYSTEM_TOOLS}
187         fi
188         if [[ -f ./[mM]akefile || -f ./GNUmakefile ]] ; then
189                 emake ${*} "${GS_ENV[@]}" install || die "package install failed"
190                 return 0
191         fi
192         die "no Makefile found"
193 }
194
195 # Make and install docs using GNUstep Makefiles
196 egnustep_doc() {
197         if [[ -d "${S}"/Documentation ]] ; then
198                 # Check documentation presence
199                 pushd "${S}"/Documentation || die
200                 if [[ -f ./[mM]akefile || -f ./GNUmakefile ]] ; then
201                         emake "${GS_ENV[@]}" all || die "doc make failed"
202                         emake "${GS_ENV[@]}" install || die "doc install failed"
203                 fi
204                 popd || die
205         fi
206 }
207
208 egnustep_install_config() {
209         [[ $(type -t gnustep_config_script) != "function" ]] && return 0
210
211         local cfile=config-${PN}.sh
212
213         cat << 'EOF' > "${T}"/${cfile}
214 #!/usr/bin/env bash
215 gnustep_append_default() {
216         if [[ -z $1 || -z $2 || -z $3 ]]; then
217                 echo "warning: invalid script invocation"
218                 return
219         fi
220         dom=$1
221         key=$2
222         val=$3
223         cur=$(defaults read ${dom} ${key}) 2> /dev/null
224         if [[ -z $cur ]] ; then
225                 echo " * setting ${dom} ${key}"
226                 defaults write ${dom} ${key} "( ${val} )"
227         elif [[ ${cur} != *${val}* ]] ; then
228                 echo " * adding ${val} to ${dom} ${key}"
229                 echo "${cur%)\'}, \"${val}\" )'" | defaults write
230         else
231                 echo " * ${val} already present in ${dom} ${key}"
232         fi
233 }
234
235 gnustep_set_default() {
236         if [[ -z $1 || -z $2 || -z $3 ]]; then
237                 echo "warning: invalid script invocation"
238                 return
239         fi
240         dom=$1
241         key=$2
242         val=$3
243         echo " * setting ${dom} ${key}"
244         defaults write ${dom} ${key} ${val}
245 }
246
247 EOF
248
249         echo "echo \"Applying ${P} default configuration ...\"" >> "${T}"/${cfile}
250
251         gnustep_config_script | \
252         while read line ; do
253                 echo "${line}" >> "${T}"/${cfile}
254         done
255         echo 'echo "done"' >> "${T}"/${cfile}
256
257         if [[ -d ${EPREFIX}/usr/share/GNUstep/Makefiles ]]; then
258                 exeinto /usr/bin
259         else
260                 exeinto ${GNUSTEP_SYSTEM_TOOLS#${EPREFIX}}/Gentoo
261         fi
262         doexe "${T}"/${cfile}
263 }
264
265 case ${EAPI:-0} in
266         0|1) EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postinst ;;
267         *) EXPORT_FUNCTIONS pkg_setup src_prepare src_configure src_compile src_install pkg_postinst ;;
268 esac