net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / qt4-build.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @DEAD
6
7 # @ECLASS: qt4-build.eclass
8 # @MAINTAINER:
9 # Qt herd <qt@gentoo.org>
10 # @BLURB: Eclass for Qt4 split ebuilds.
11 # @DESCRIPTION:
12 # This eclass contains various functions that are used when building Qt4.
13
14 case ${EAPI} in
15         4|5)    : ;;
16         *)      die "qt4-build.eclass: unsupported EAPI=${EAPI:-0}" ;;
17 esac
18
19 inherit eutils flag-o-matic multilib toolchain-funcs
20
21 HOMEPAGE="https://www.qt.io/"
22 LICENSE="|| ( LGPL-2.1 GPL-3 )"
23 SLOT="4"
24
25 case ${PV} in
26         4.?.9999)
27                 QT4_BUILD_TYPE="live"
28                 EGIT_REPO_URI=(
29                         "git://code.qt.io/qt/qt.git"
30                         "https://code.qt.io/git/qt/qt.git"
31                         "https://github.com/qtproject/qt.git"
32                 )
33                 EGIT_BRANCH=${PV%.9999}
34                 inherit git-r3
35                 ;;
36         *)
37                 QT4_BUILD_TYPE="release"
38                 MY_P=qt-everywhere-opensource-src-${PV/_/-}
39                 SRC_URI="http://download.qt.io/archive/qt/${PV%.*}/${PV}/${MY_P}.tar.gz"
40                 S=${WORKDIR}/${MY_P}
41                 ;;
42 esac
43
44 IUSE="aqua debug pch"
45 [[ ${PN} != qtxmlpatterns ]] && IUSE+=" +exceptions"
46
47 DEPEND="virtual/pkgconfig"
48 if [[ ${QT4_BUILD_TYPE} == live ]]; then
49         DEPEND+=" dev-lang/perl"
50 fi
51
52 # @FUNCTION: qt4-build_pkg_setup
53 # @DESCRIPTION:
54 # Sets up PATH and LD_LIBRARY_PATH.
55 qt4-build_pkg_setup() {
56         # Warn users of possible breakage when downgrading to a previous release.
57         # Downgrading revisions within the same release is safe.
58         if has_version ">${CATEGORY}/${P}-r9999:4"; then
59                 ewarn
60                 ewarn "Downgrading Qt is completely unsupported and can break your system!"
61                 ewarn
62         fi
63
64         PATH="${S}/bin${PATH:+:}${PATH}"
65         if [[ ${CHOST} != *-darwin* ]]; then
66                 LD_LIBRARY_PATH="${S}/lib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"
67         else
68                 DYLD_LIBRARY_PATH="${S}/lib${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}"
69                 # On MacOS we *need* at least src/gui/kernel/qapplication_mac.mm for
70                 # platform detection. Note: needs to come before any directories to
71                 # avoid extract failure.
72                 [[ ${CHOST} == *-apple-darwin* ]] && \
73                         QT4_EXTRACT_DIRECTORIES="src/gui/kernel/qapplication_mac.mm
74                                 ${QT4_EXTRACT_DIRECTORIES}"
75         fi
76 }
77
78 # @ECLASS-VARIABLE: PATCHES
79 # @DEFAULT_UNSET
80 # @DESCRIPTION:
81 # Array variable containing all the patches to be applied. This variable
82 # is expected to be defined in the global scope of ebuilds. Make sure to
83 # specify the full path. This variable is used in src_prepare phase.
84 #
85 # Example:
86 # @CODE
87 #       PATCHES=(
88 #               "${FILESDIR}/mypatch.patch"
89 #               "${FILESDIR}/patches_folder/"
90 #       )
91 # @CODE
92
93 # @ECLASS-VARIABLE: QT4_EXTRACT_DIRECTORIES
94 # @DEFAULT_UNSET
95 # @DESCRIPTION:
96 # Space-separated list of directories that will be extracted
97 # from Qt tarball.
98
99 # @ECLASS-VARIABLE: QT4_TARGET_DIRECTORIES
100 # @DEFAULT_UNSET
101 # @DESCRIPTION:
102 # Space-separated list of directories that will be configured,
103 # compiled, and installed. All paths must be relative to ${S}.
104
105 # @FUNCTION: qt4-build_src_unpack
106 # @DESCRIPTION:
107 # Unpacks the sources.
108 qt4-build_src_unpack() {
109         setqtenv
110
111         if [[ $(gcc-major-version) -lt 4 ]] || [[ $(gcc-major-version) -eq 4 && $(gcc-minor-version) -lt 4 ]]; then
112                 ewarn
113                 ewarn "Using a GCC version lower than 4.4 is not supported."
114                 ewarn
115         fi
116
117         if [[ ${PN} == qtwebkit ]]; then
118                 eshopts_push -s extglob
119                 if is-flagq '-g?(gdb)?([1-9])'; then
120                         ewarn
121                         ewarn "You have enabled debug info (probably have -g or -ggdb in your CFLAGS/CXXFLAGS)."
122                         ewarn "You may experience really long compilation times and/or increased memory usage."
123                         ewarn "If compilation fails, please try removing -g/-ggdb before reporting a bug."
124                         ewarn "For more info check out https://bugs.gentoo.org/307861"
125                         ewarn
126                 fi
127                 eshopts_pop
128         fi
129
130         case ${QT4_BUILD_TYPE} in
131                 live)
132                         git-r3_src_unpack
133                         ;;
134                 release)
135                         local tarball="${MY_P}.tar.gz" target= targets=
136                         for target in configure LICENSE.GPL3 LICENSE.LGPL projects.pro \
137                                 src/{qbase,qt_targets,qt_install}.pri bin config.tests \
138                                 mkspecs qmake ${QT4_EXTRACT_DIRECTORIES}
139                         do
140                                 targets+="${MY_P}/${target} "
141                         done
142
143                         ebegin "Unpacking parts of ${tarball}:" ${targets//${MY_P}\/}
144                         tar -xzf "${DISTDIR}/${tarball}" ${targets}
145                         eend $? || die "failed to unpack"
146                         ;;
147         esac
148 }
149
150 # @FUNCTION: qt4-build_src_prepare
151 # @DESCRIPTION:
152 # Prepare the sources before the configure phase. Strip CFLAGS if necessary, and fix
153 # the build system in order to respect CFLAGS/CXXFLAGS/LDFLAGS specified in make.conf.
154 qt4-build_src_prepare() {
155         setqtenv
156
157         if [[ ${QT4_BUILD_TYPE} == live ]]; then
158                 QTDIR="." ./bin/syncqt || die "syncqt failed"
159         fi
160
161         # avoid X11 dependency in non-gui packages
162         local nolibx11_pkgs="qtbearer qtcore qtdbus qtscript qtsql qttest qtxmlpatterns"
163         has ${PN} ${nolibx11_pkgs} && qt_nolibx11
164
165         if use aqua; then
166                 # provide a proper macx-g++-64
167                 use x64-macos && ln -s macx-g++ mkspecs/$(qt_mkspecs_dir)
168
169                 sed -e '/^CONFIG/s:app_bundle::' \
170                         -e '/^CONFIG/s:plugin_no_soname:plugin_with_soname absolute_library_soname:' \
171                         -i mkspecs/$(qt_mkspecs_dir)/qmake.conf || die
172         fi
173
174         if [[ ${CATEGORY}/${PN} != dev-qt/qtcore ]]; then
175                 skip_qmake_build
176                 skip_project_generation
177                 symlink_binaries_to_buildtree
178         else
179                 # Bug 373061
180                 # qmake bus errors with -O2 or -O3 but -O1 works
181                 if [[ ${CHOST} == *86*-apple-darwin* ]]; then
182                         replace-flags -O[23] -O1
183                 fi
184
185                 # Bug 503500
186                 # undefined reference with -Os and --as-needed
187                 if use x86; then
188                         replace-flags -Os -O2
189                 fi
190         fi
191
192         # Bug 261632
193         if use ppc64; then
194                 append-flags -mminimal-toc
195         fi
196
197         # Bug 417105
198         # graphite on gcc 4.7 causes miscompilations
199         if [[ $(gcc-version) == "4.7" ]]; then
200                 filter-flags -fgraphite-identity
201         fi
202
203         if use_if_iuse c++0x; then
204                 append-cxxflags -std=c++0x
205         fi
206
207         # Respect CC, CXX, {C,CXX,LD}FLAGS in .qmake.cache
208         sed -e "/^SYSTEM_VARIABLES=/i \
209                 CC='$(tc-getCC)'\n\
210                 CXX='$(tc-getCXX)'\n\
211                 CFLAGS='${CFLAGS}'\n\
212                 CXXFLAGS='${CXXFLAGS}'\n\
213                 LDFLAGS='${LDFLAGS}'\n\
214                 QMakeVar set QMAKE_CFLAGS_RELEASE\n\
215                 QMakeVar set QMAKE_CFLAGS_DEBUG\n\
216                 QMakeVar set QMAKE_CXXFLAGS_RELEASE\n\
217                 QMakeVar set QMAKE_CXXFLAGS_DEBUG\n\
218                 QMakeVar set QMAKE_LFLAGS_RELEASE\n\
219                 QMakeVar set QMAKE_LFLAGS_DEBUG\n"\
220                 -i configure \
221                 || die "sed SYSTEM_VARIABLES failed"
222
223         # Respect CC, CXX, LINK and *FLAGS in config.tests
224         find config.tests/unix -name '*.test' -type f -print0 | xargs -0 \
225                 sed -i -e "/bin\/qmake/ s: \"\$SRCDIR/: \
226                         'QMAKE_CC=$(tc-getCC)'    'QMAKE_CXX=$(tc-getCXX)'      'QMAKE_LINK=$(tc-getCXX)' \
227                         'QMAKE_CFLAGS+=${CFLAGS}' 'QMAKE_CXXFLAGS+=${CXXFLAGS}' 'QMAKE_LFLAGS+=${LDFLAGS}'&:" \
228                 || die "sed config.tests failed"
229
230         # Bug 172219
231         sed -e 's:/X11R6/:/:' -i mkspecs/$(qt_mkspecs_dir)/qmake.conf || die
232
233         if [[ ${CHOST} == *-darwin* ]]; then
234                 # Set FLAGS *and* remove -arch, since our gcc-apple is multilib
235                 # crippled (by design) :/
236                 local mac_gpp_conf=
237                 if [[ -f mkspecs/common/mac-g++.conf ]]; then
238                         # qt < 4.8 has mac-g++.conf
239                         mac_gpp_conf="mkspecs/common/mac-g++.conf"
240                 elif [[ -f mkspecs/common/g++-macx.conf ]]; then
241                         # qt >= 4.8 has g++-macx.conf
242                         mac_gpp_conf="mkspecs/common/g++-macx.conf"
243                 else
244                         die "no known conf file for mac found"
245                 fi
246                 sed \
247                         -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
248                         -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
249                         -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=-headerpad_max_install_names ${LDFLAGS}:" \
250                         -e "s:-arch\s\w*::g" \
251                         -i ${mac_gpp_conf} \
252                         || die "sed ${mac_gpp_conf} failed"
253
254                 # Fix configure's -arch settings that appear in qmake/Makefile and also
255                 # fix arch handling (automagically duplicates our -arch arg and breaks
256                 # pch). Additionally disable Xarch support.
257                 local mac_gcc_confs="${mac_gpp_conf}"
258                 if [[ -f mkspecs/common/gcc-base-macx.conf ]]; then
259                         mac_gcc_confs+=" mkspecs/common/gcc-base-macx.conf"
260                 fi
261                 sed \
262                         -e "s:-arch i386::" \
263                         -e "s:-arch ppc::" \
264                         -e "s:-arch x86_64::" \
265                         -e "s:-arch ppc64::" \
266                         -e "s:-arch \$i::" \
267                         -e "/if \[ ! -z \"\$NATIVE_64_ARCH\" \]; then/,/fi/ d" \
268                         -e "s:CFG_MAC_XARCH=yes:CFG_MAC_XARCH=no:g" \
269                         -e "s:-Xarch_x86_64::g" \
270                         -e "s:-Xarch_ppc64::g" \
271                         -i configure ${mac_gcc_confs} \
272                         || die "sed -arch/-Xarch failed"
273
274                 # On Snow Leopard don't fall back to 10.5 deployment target.
275                 if [[ ${CHOST} == *-apple-darwin10 ]]; then
276                         sed -e "s:QMakeVar set QMAKE_MACOSX_DEPLOYMENT_TARGET.*:QMakeVar set QMAKE_MACOSX_DEPLOYMENT_TARGET 10.6:g" \
277                                 -e "s:-mmacosx-version-min=10.[0-9]:-mmacosx-version-min=10.6:g" \
278                                 -i configure ${mac_gpp_conf} \
279                                 || die "sed deployment target failed"
280                 fi
281         fi
282
283         # this one is needed for all systems with a separate -liconv, apart from
284         # Darwin, for which the sources already cater for -liconv
285         if use !elibc_glibc && [[ ${CHOST} != *-darwin* ]]; then
286                 sed -e 's|mac:\(LIBS += -liconv\)|\1|g' \
287                         -i config.tests/unix/iconv/iconv.pro \
288                         || die "sed iconv.pro failed"
289         fi
290
291         # we need some patches for Solaris
292         sed -i -e '/^QMAKE_LFLAGS_THREAD/a\QMAKE_LFLAGS_DYNAMIC_LIST = -Wl,--dynamic-list,' \
293                 mkspecs/$(qt_mkspecs_dir)/qmake.conf || die
294         # use GCC over SunStudio
295         sed -i -e '/PLATFORM=solaris-cc/s/cc/g++/' configure || die
296         # do not flirt with non-Prefix stuff, we're quite possessive
297         sed -i -e '/^QMAKE_\(LIB\|INC\)DIR\(_X11\|_OPENGL\|\)\t/s/=.*$/=/' \
298                 mkspecs/$(qt_mkspecs_dir)/qmake.conf || die
299
300         # apply patches
301         [[ -n ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
302         epatch_user
303 }
304
305 # @FUNCTION: qt4-build_src_configure
306 # @DESCRIPTION:
307 # Default configure phase
308 qt4-build_src_configure() {
309         setqtenv
310
311         local conf="
312                 -prefix ${QTPREFIXDIR}
313                 -bindir ${QTBINDIR}
314                 -libdir ${QTLIBDIR}
315                 -docdir ${QTDOCDIR}
316                 -headerdir ${QTHEADERDIR}
317                 -plugindir ${QTPLUGINDIR}
318                 -importdir ${QTIMPORTDIR}
319                 -datadir ${QTDATADIR}
320                 -translationdir ${QTTRANSDIR}
321                 -sysconfdir ${QTSYSCONFDIR}
322                 -examplesdir ${QTEXAMPLESDIR}
323                 -demosdir ${QTDEMOSDIR}
324                 -opensource -confirm-license
325                 -shared -fast -largefile -stl -verbose
326                 -nomake examples -nomake demos"
327
328         # ARCH is set on Gentoo. Qt now falls back to generic on an unsupported
329         # $(tc-arch). Therefore we convert it to supported values.
330         case "$(tc-arch)" in
331                 amd64|x64-*)              conf+=" -arch x86_64" ;;
332                 ppc-macos)                conf+=" -arch ppc" ;;
333                 ppc|ppc64|ppc-*)          conf+=" -arch powerpc" ;;
334                 sparc|sparc-*|sparc64-*)  conf+=" -arch sparc" ;;
335                 x86-macos)                conf+=" -arch x86" ;;
336                 x86|x86-*)                conf+=" -arch i386" ;;
337                 alpha|arm|ia64|mips|s390) conf+=" -arch $(tc-arch)" ;;
338                 arm64|hppa|sh)            conf+=" -arch generic" ;;
339                 *) die "$(tc-arch) is unsupported by this eclass. Please file a bug." ;;
340         esac
341
342         conf+=" -platform $(qt_mkspecs_dir)"
343
344         [[ $(get_libdir) != lib ]] && conf+=" -L${EPREFIX}/usr/$(get_libdir)"
345
346         # debug/release
347         if use debug; then
348                 conf+=" -debug"
349         else
350                 conf+=" -release"
351         fi
352         conf+=" -no-separate-debug-info"
353
354         # exceptions USE flag
355         conf+=" $(in_iuse exceptions && qt_use exceptions || echo -exceptions)"
356
357         # disable rpath (bug 380415), except on prefix (bug 417169)
358         use prefix || conf+=" -no-rpath"
359
360         # precompiled headers don't work on hardened, where the flag is masked
361         conf+=" $(qt_use pch)"
362
363         # -reduce-relocations
364         # This flag seems to introduce major breakage to applications,
365         # mostly to be seen as a core dump with the message "QPixmap: Must
366         # construct a QApplication before a QPaintDevice" on Solaris.
367         #   -- Daniel Vergien
368         [[ ${CHOST} != *-solaris* ]] && conf+=" -reduce-relocations"
369
370         # this one is needed for all systems with a separate -liconv, apart from
371         # Darwin, for which the sources already cater for -liconv
372         if use !elibc_glibc && [[ ${CHOST} != *-darwin* ]]; then
373                 conf+=" -liconv"
374         fi
375
376         if use_if_iuse glib; then
377                 local glibflags="$(pkg-config --cflags --libs glib-2.0 gthread-2.0)"
378                 # avoid the -pthread argument
379                 conf+=" ${glibflags//-pthread}"
380                 unset glibflags
381         fi
382
383         if use aqua; then
384                 # On (snow) leopard use the new (frameworked) cocoa code.
385                 if [[ ${CHOST##*-darwin} -ge 9 ]]; then
386                         conf+=" -cocoa -framework"
387                         # We need the source's headers, not the installed ones.
388                         conf+=" -I${S}/include"
389                         # Add hint for the framework location.
390                         conf+=" -F${QTLIBDIR}"
391
392                         # We are crazy and build cocoa + qt3support :-)
393                         if use qt3support; then
394                                 sed -e "/case \"\$PLATFORM,\$CFG_MAC_COCOA\" in/,/;;/ s|CFG_QT3SUPPORT=\"no\"|CFG_QT3SUPPORT=\"yes\"|" \
395                                         -i configure || die
396                         fi
397                 else
398                         conf+=" -no-framework"
399                 fi
400         else
401                 # freetype2 include dir is non-standard, thus pass it to configure
402                 conf+=" $(pkg-config --cflags-only-I freetype2)"
403         fi
404
405         conf+=" ${myconf}"
406         myconf=
407
408         echo ./configure ${conf}
409         ./configure ${conf} || die "./configure failed"
410
411         prepare_directories ${QT4_TARGET_DIRECTORIES}
412 }
413
414 # @FUNCTION: qt4-build_src_compile
415 # @DESCRIPTION:
416 # Actual compile phase
417 qt4-build_src_compile() {
418         setqtenv
419
420         build_directories ${QT4_TARGET_DIRECTORIES}
421 }
422
423 # @FUNCTION: qt4-build_src_test
424 # @DESCRIPTION:
425 # Runs tests only in target directories.
426 qt4-build_src_test() {
427         # QtMultimedia does not have any test suite (bug #332299)
428         [[ ${CATEGORY}/${PN} == dev-qt/qtmultimedia ]] && return
429
430         for dir in ${QT4_TARGET_DIRECTORIES}; do
431                 emake -j1 check -C ${dir}
432         done
433 }
434
435 # @FUNCTION: fix_includes
436 # @DESCRIPTION:
437 # For MacOS X we need to add some symlinks when frameworks are
438 # being used, to avoid complications with some more or less stupid packages.
439 fix_includes() {
440         if use aqua && [[ ${CHOST##*-darwin} -ge 9 ]]; then
441                 local frw dest f h rdir
442                 # Some packages tend to include <Qt/...>
443                 dodir "${QTHEADERDIR#${EPREFIX}}"/Qt
444
445                 # Fake normal headers when frameworks are installed... eases life later
446                 # on, make sure we use relative links though, as some ebuilds assume
447                 # these dirs exist in src_install to add additional files
448                 f=${QTHEADERDIR}
449                 h=${QTLIBDIR}
450                 while [[ -n ${f} && ${f%%/*} == ${h%%/*} ]] ; do
451                         f=${f#*/}
452                         h=${h#*/}
453                 done
454                 rdir=${h}
455                 f="../"
456                 while [[ ${h} == */* ]] ; do
457                         f="${f}../"
458                         h=${h#*/}
459                 done
460                 rdir="${f}${rdir}"
461
462                 for frw in "${D}${QTLIBDIR}"/*.framework; do
463                         [[ -e "${frw}"/Headers ]] || continue
464                         f=$(basename ${frw})
465                         dest="${QTHEADERDIR#${EPREFIX}}"/${f%.framework}
466                         dosym "${rdir}"/${f}/Headers "${dest}"
467
468                         # Link normal headers as well.
469                         for hdr in "${D}/${QTLIBDIR}/${f}"/Headers/*; do
470                                 h=$(basename ${hdr})
471                                 dosym "../${rdir}"/${f}/Headers/${h} \
472                                         "${QTHEADERDIR#${EPREFIX}}"/Qt/${h}
473                         done
474                 done
475         fi
476 }
477
478 # @FUNCTION: qt4-build_src_install
479 # @DESCRIPTION:
480 # Perform the actual installation including some library fixes.
481 qt4-build_src_install() {
482         setqtenv
483
484         install_directories ${QT4_TARGET_DIRECTORIES}
485         install_qconfigs
486         fix_library_files
487         fix_includes
488
489         # remove .la files since we are building only shared libraries
490         prune_libtool_files
491 }
492
493 # @FUNCTION: setqtenv
494 # @INTERNAL
495 setqtenv() {
496         # Set up installation directories
497         QTPREFIXDIR=${EPREFIX}/usr
498         QTBINDIR=${QTPREFIXDIR}/bin
499         QTLIBDIR=${QTPREFIXDIR}/$(get_libdir)/qt4
500         QTPCDIR=${QTPREFIXDIR}/$(get_libdir)/pkgconfig
501         QTDOCDIR=${QTPREFIXDIR}/share/doc/qt-${PV}
502         QTHEADERDIR=${QTPREFIXDIR}/include/qt4
503         QTPLUGINDIR=${QTLIBDIR}/plugins
504         QTIMPORTDIR=${QTLIBDIR}/imports
505         QTDATADIR=${QTPREFIXDIR}/share/qt4
506         QTTRANSDIR=${QTDATADIR}/translations
507         QTSYSCONFDIR=${EPREFIX}/etc/qt4
508         QTEXAMPLESDIR=${QTDATADIR}/examples
509         QTDEMOSDIR=${QTDATADIR}/demos
510         QMAKE_LIBDIR_QT=${QTLIBDIR}
511
512         PLATFORM=$(qt_mkspecs_dir)
513         unset QMAKESPEC
514
515         export XDG_CONFIG_HOME="${T}"
516 }
517
518 # @FUNCTION: prepare_directories
519 # @USAGE: < directories >
520 # @INTERNAL
521 # @DESCRIPTION:
522 # Generates Makefiles for the given list of directories.
523 prepare_directories() {
524         for x in "$@"; do
525                 pushd "${S}"/${x} >/dev/null || die
526                 einfo "Running qmake in: ${x}"
527                 "${S}"/bin/qmake \
528                         "LIBS+=-L${QTLIBDIR}" \
529                         "CONFIG+=nostrip" \
530                         || die "qmake failed"
531                 popd >/dev/null || die
532         done
533 }
534
535 # @FUNCTION: build_directories
536 # @USAGE: < directories >
537 # @INTERNAL
538 # @DESCRIPTION:
539 # Compiles the code in the given list of directories.
540 build_directories() {
541         for x in "$@"; do
542                 pushd "${S}"/${x} >/dev/null || die
543                 emake \
544                         AR="$(tc-getAR) cqs" \
545                         CC="$(tc-getCC)" \
546                         CXX="$(tc-getCXX)" \
547                         LINK="$(tc-getCXX)" \
548                         RANLIB=":" \
549                         STRIP=":"
550                 popd >/dev/null || die
551         done
552 }
553
554 # @FUNCTION: install_directories
555 # @USAGE: < directories >
556 # @INTERNAL
557 # @DESCRIPTION:
558 # Runs emake install in the given directories, which are separated by spaces.
559 install_directories() {
560         for x in "$@"; do
561                 pushd "${S}"/${x} >/dev/null || die
562                 emake INSTALL_ROOT="${D}" install
563                 popd >/dev/null || die
564         done
565 }
566
567 # @ECLASS-VARIABLE: QCONFIG_ADD
568 # @DESCRIPTION:
569 # List options that need to be added to QT_CONFIG in qconfig.pri
570 : ${QCONFIG_ADD:=}
571
572 # @ECLASS-VARIABLE: QCONFIG_REMOVE
573 # @DESCRIPTION:
574 # List options that need to be removed from QT_CONFIG in qconfig.pri
575 : ${QCONFIG_REMOVE:=}
576
577 # @ECLASS-VARIABLE: QCONFIG_DEFINE
578 # @DESCRIPTION:
579 # List variables that should be defined at the top of QtCore/qconfig.h
580 : ${QCONFIG_DEFINE:=}
581
582 # @FUNCTION: install_qconfigs
583 # @INTERNAL
584 # @DESCRIPTION:
585 # Install gentoo-specific mkspecs configurations.
586 install_qconfigs() {
587         local x
588         if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} ]]; then
589                 for x in QCONFIG_ADD QCONFIG_REMOVE; do
590                         [[ -n ${!x} ]] && echo ${x}=${!x} >> "${T}"/${PN}-qconfig.pri
591                 done
592                 insinto ${QTDATADIR#${EPREFIX}}/mkspecs/gentoo
593                 doins "${T}"/${PN}-qconfig.pri
594         fi
595
596         if [[ -n ${QCONFIG_DEFINE} ]]; then
597                 for x in ${QCONFIG_DEFINE}; do
598                         echo "#define ${x}" >> "${T}"/gentoo-${PN}-qconfig.h
599                 done
600                 insinto ${QTHEADERDIR#${EPREFIX}}/Gentoo
601                 doins "${T}"/gentoo-${PN}-qconfig.h
602         fi
603 }
604
605 # @FUNCTION: generate_qconfigs
606 # @INTERNAL
607 # @DESCRIPTION:
608 # Generates gentoo-specific qconfig.{h,pri}.
609 generate_qconfigs() {
610         if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} || -n ${QCONFIG_DEFINE} || ${CATEGORY}/${PN} == dev-qt/qtcore ]]; then
611                 local x qconfig_add qconfig_remove qconfig_new
612                 for x in "${ROOT}${QTDATADIR}"/mkspecs/gentoo/*-qconfig.pri; do
613                         [[ -f ${x} ]] || continue
614                         qconfig_add+=" $(sed -n 's/^QCONFIG_ADD=//p' "${x}")"
615                         qconfig_remove+=" $(sed -n 's/^QCONFIG_REMOVE=//p' "${x}")"
616                 done
617
618                 # these error checks do not use die because dying in pkg_post{inst,rm}
619                 # just makes things worse.
620                 if [[ -e "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri ]]; then
621                         # start with the qconfig.pri that qtcore installed
622                         if ! cp "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri \
623                                 "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
624                                 eerror "cp qconfig failed."
625                                 return 1
626                         fi
627
628                         # generate list of QT_CONFIG entries from the existing list
629                         # including qconfig_add and excluding qconfig_remove
630                         for x in $(sed -n 's/^QT_CONFIG +=//p' \
631                                 "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri) ${qconfig_add}; do
632                                         has ${x} ${qconfig_remove} || qconfig_new+=" ${x}"
633                         done
634
635                         # replace the existing QT_CONFIG list with qconfig_new
636                         if ! sed -i -e "s/QT_CONFIG +=.*/QT_CONFIG += ${qconfig_new}/" \
637                                 "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
638                                 eerror "Sed for QT_CONFIG failed"
639                                 return 1
640                         fi
641
642                         # create Gentoo/qconfig.h
643                         if [[ ! -e ${ROOT}${QTHEADERDIR}/Gentoo ]]; then
644                                 if ! mkdir -p "${ROOT}${QTHEADERDIR}"/Gentoo; then
645                                         eerror "mkdir ${QTHEADERDIR}/Gentoo failed"
646                                         return 1
647                                 fi
648                         fi
649                         : > "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
650                         for x in "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-*-qconfig.h; do
651                                 [[ -f ${x} ]] || continue
652                                 cat "${x}" >> "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
653                         done
654                 else
655                         rm -f "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri
656                         rm -f "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
657                         rmdir "${ROOT}${QTDATADIR}"/mkspecs \
658                                 "${ROOT}${QTDATADIR}" \
659                                 "${ROOT}${QTHEADERDIR}"/Gentoo \
660                                 "${ROOT}${QTHEADERDIR}" 2>/dev/null
661                 fi
662         fi
663 }
664
665 # @FUNCTION: qt4-build_pkg_postrm
666 # @DESCRIPTION:
667 # Regenerate configuration when the package is completely removed.
668 qt4-build_pkg_postrm() {
669         generate_qconfigs
670 }
671
672 # @FUNCTION: qt4-build_pkg_postinst
673 # @DESCRIPTION:
674 # Regenerate configuration, plus throw a message about possible
675 # breakages and proposed solutions.
676 qt4-build_pkg_postinst() {
677         generate_qconfigs
678 }
679
680 # @FUNCTION: skip_qmake_build
681 # @INTERNAL
682 # @DESCRIPTION:
683 # Patches configure to skip qmake compilation, as it's already installed by qtcore.
684 skip_qmake_build() {
685         sed -i -e "s:if true:if false:g" "${S}"/configure || die
686 }
687
688 # @FUNCTION: skip_project_generation
689 # @INTERNAL
690 # @DESCRIPTION:
691 # Exit the script early by throwing in an exit before all of the .pro files are scanned.
692 skip_project_generation() {
693         sed -i -e "s:echo \"Finding:exit 0\n\necho \"Finding:g" "${S}"/configure || die
694 }
695
696 # @FUNCTION: symlink_binaries_to_buildtree
697 # @INTERNAL
698 # @DESCRIPTION:
699 # Symlinks generated binaries to buildtree, so they can be used during compilation time.
700 symlink_binaries_to_buildtree() {
701         for bin in qmake moc uic rcc; do
702                 ln -s "${QTBINDIR}"/${bin} "${S}"/bin/ || die "symlinking ${bin} to ${S}/bin failed"
703         done
704 }
705
706 # @FUNCTION: fix_library_files
707 # @INTERNAL
708 # @DESCRIPTION:
709 # Fixes the paths in *.la, *.prl, *.pc, as they are wrong due to sandbox and
710 # moves the *.pc files into the pkgconfig directory.
711 fix_library_files() {
712         local libfile
713         for libfile in "${D}"/${QTLIBDIR}/{*.la,*.prl,pkgconfig/*.pc}; do
714                 if [[ -e ${libfile} ]]; then
715                         sed -i -e "s:${S}/lib:${QTLIBDIR}:g" ${libfile} || die "sed on ${libfile} failed"
716                 fi
717         done
718
719         # pkgconfig files refer to WORKDIR/bin as the moc and uic locations
720         for libfile in "${D}"/${QTLIBDIR}/pkgconfig/*.pc; do
721                 if [[ -e ${libfile} ]]; then
722                         sed -i -e "s:${S}/bin:${QTBINDIR}:g" ${libfile} || die "sed on ${libfile} failed"
723
724                 # Move .pc files into the pkgconfig directory
725                 dodir ${QTPCDIR#${EPREFIX}}
726                 mv ${libfile} "${D}"/${QTPCDIR}/ || die "moving ${libfile} to ${D}/${QTPCDIR}/ failed"
727                 fi
728         done
729
730         # Don't install an empty directory
731         rmdir "${D}"/${QTLIBDIR}/pkgconfig
732 }
733
734 # @FUNCTION: qt_use
735 # @USAGE: < flag > [ feature ] [ enableval ]
736 # @DESCRIPTION:
737 # This will echo "-${enableval}-${feature}" if <flag> is enabled, or
738 # "-no-${feature}" if it's disabled. If [feature] is not specified, <flag>
739 # will be used for that. If [enableval] is not specified, it omits the
740 # "-${enableval}" part.
741 qt_use() {
742         use "$1" && echo "${3:+-$3}-${2:-$1}" || echo "-no-${2:-$1}"
743 }
744
745 # @FUNCTION: qt_mkspecs_dir
746 # @RETURN: the specs-directory w/o path
747 # @DESCRIPTION:
748 # Allows us to define which mkspecs dir we want to use.
749 qt_mkspecs_dir() {
750         local spec=
751
752         case "${CHOST}" in
753                 *-freebsd*|*-dragonfly*)
754                         spec=freebsd ;;
755                 *-openbsd*)
756                         spec=openbsd ;;
757                 *-netbsd*)
758                         spec=netbsd ;;
759                 *-darwin*)
760                         if use aqua; then
761                                 # mac with carbon/cocoa
762                                 spec=macx
763                         else
764                                 # darwin/mac with x11
765                                 spec=darwin
766                         fi
767                         ;;
768                 *-solaris*)
769                         spec=solaris ;;
770                 *-linux-*|*-linux)
771                         spec=linux ;;
772                 *)
773                         die "${FUNCNAME}(): Unknown CHOST '${CHOST}'" ;;
774         esac
775
776         case "$(tc-getCXX)" in
777                 *g++*)
778                         spec+=-g++ ;;
779                 *icpc*)
780                         spec+=-icc ;;
781                 *)
782                         die "${FUNCNAME}(): Unknown compiler '$(tc-getCXX)'" ;;
783         esac
784
785         # Add -64 for 64bit profiles
786         if use x64-freebsd ||
787                 use amd64-linux ||
788                 use x64-macos ||
789                 use x64-solaris ||
790                 use sparc64-solaris
791         then
792                 spec+=-64
793         fi
794
795         echo "${spec}"
796 }
797
798 # @FUNCTION: qt_nolibx11
799 # @INTERNAL
800 # @DESCRIPTION:
801 # Skip X11 tests for packages that don't need X libraries installed.
802 qt_nolibx11() {
803         sed -i -e '/^if.*PLATFORM_X11.*CFG_GUI/,/^fi$/d' "${S}"/configure || die
804 }
805
806 EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_install src_test pkg_postrm pkg_postinst