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