net-wireless/hostapd: use #!/sbin/openrc-run instead of #!/sbin/runscript
[gentoo.git] / eclass / qt4-build-multilib.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: qt4-build-multilib.eclass
6 # @MAINTAINER:
7 # qt@gentoo.org
8 # @AUTHOR:
9 # Davide Pesavento <pesa@gentoo.org>
10 # @BLURB: Eclass for Qt4 split ebuilds with multilib support.
11 # @DESCRIPTION:
12 # This eclass contains various functions that are used when building Qt4.
13 # Requires EAPI 5.
14
15 case ${EAPI} in
16         5)      : ;;
17         *)      die "qt4-build-multilib.eclass: unsupported EAPI=${EAPI:-0}" ;;
18 esac
19
20 inherit eutils flag-o-matic multilib multilib-minimal toolchain-funcs
21
22 HOMEPAGE="https://www.qt.io/"
23 LICENSE="|| ( LGPL-2.1 LGPL-3 GPL-3 ) FDL-1.3"
24 SLOT="4"
25
26 case ${PV} in
27         4.?.9999)
28                 # git stable branch
29                 QT4_BUILD_TYPE="live"
30                 EGIT_BRANCH=${PV%.9999}
31                 ;;
32         *)
33                 # official stable release
34                 QT4_BUILD_TYPE="release"
35                 MY_P=qt-everywhere-opensource-src-${PV/_/-}
36                 SRC_URI="http://download.qt.io/official_releases/qt/${PV%.*}/${PV}/${MY_P}.tar.gz"
37                 S=${WORKDIR}/${MY_P}
38                 ;;
39 esac
40
41 EGIT_REPO_URI=(
42         "git://code.qt.io/qt/qt.git"
43         "https://code.qt.io/git/qt/qt.git"
44         "https://github.com/qtproject/qt.git"
45 )
46 [[ ${QT4_BUILD_TYPE} == live ]] && inherit git-r3
47
48 if [[ ${PN} != qttranslations ]]; then
49         IUSE="aqua debug pch"
50         [[ ${PN} != qtxmlpatterns ]] && IUSE+=" +exceptions"
51 fi
52
53 DEPEND="
54         dev-lang/perl
55         virtual/pkgconfig[${MULTILIB_USEDEP}]
56 "
57 RDEPEND="
58         dev-qt/qtchooser
59         abi_x86_32? ( !app-emulation/emul-linux-x86-qtlibs[-abi_x86_32(-)] )
60 "
61
62
63 # src_{configure,compile,test,install} are inherited from multilib-minimal
64 EXPORT_FUNCTIONS src_unpack src_prepare pkg_postinst pkg_postrm
65
66 multilib_src_configure()        { qt4_multilib_src_configure; }
67 multilib_src_compile()          { qt4_multilib_src_compile; }
68 multilib_src_test()             { qt4_multilib_src_test; }
69 multilib_src_install()          { qt4_multilib_src_install; }
70 multilib_src_install_all()      { qt4_multilib_src_install_all; }
71
72
73 # @ECLASS-VARIABLE: PATCHES
74 # @DEFAULT_UNSET
75 # @DESCRIPTION:
76 # Array variable containing all the patches to be applied. This variable
77 # is expected to be defined in the global scope of ebuilds. Make sure to
78 # specify the full path. This variable is used in src_prepare phase.
79 #
80 # Example:
81 # @CODE
82 #       PATCHES=(
83 #               "${FILESDIR}/mypatch.patch"
84 #               "${FILESDIR}/mypatch2.patch"
85 #       )
86 # @CODE
87
88 # @ECLASS-VARIABLE: QT4_TARGET_DIRECTORIES
89 # @DEFAULT_UNSET
90 # @DESCRIPTION:
91 # Space-separated list of directories that will be configured,
92 # compiled, and installed. All paths must be relative to ${S}.
93
94 # @ECLASS-VARIABLE: QCONFIG_ADD
95 # @DEFAULT_UNSET
96 # @DESCRIPTION:
97 # List of options that must be added to QT_CONFIG in qconfig.pri
98
99 # @ECLASS-VARIABLE: QCONFIG_REMOVE
100 # @DEFAULT_UNSET
101 # @DESCRIPTION:
102 # List of options that must be removed from QT_CONFIG in qconfig.pri
103
104 # @ECLASS-VARIABLE: QCONFIG_DEFINE
105 # @DEFAULT_UNSET
106 # @DESCRIPTION:
107 # List of macros that must be defined in QtCore/qconfig.h
108
109
110 ######  Phase functions  ######
111
112 # @FUNCTION: qt4-build-multilib_src_unpack
113 # @DESCRIPTION:
114 # Unpacks the sources.
115 qt4-build-multilib_src_unpack() {
116         if [[ $(gcc-major-version) -lt 4 ]] || [[ $(gcc-major-version) -eq 4 && $(gcc-minor-version) -lt 4 ]]; then
117                 ewarn
118                 ewarn "Using a GCC version lower than 4.4 is not supported."
119                 ewarn
120         fi
121
122         if [[ ${PN} == qtwebkit ]]; then
123                 eshopts_push -s extglob
124                 if is-flagq '-g?(gdb)?([1-9])'; then
125                         ewarn
126                         ewarn "You have enabled debug info (probably have -g or -ggdb in your CFLAGS/CXXFLAGS)."
127                         ewarn "You may experience really long compilation times and/or increased memory usage."
128                         ewarn "If compilation fails, please try removing -g/-ggdb before reporting a bug."
129                         ewarn "For more info check out https://bugs.gentoo.org/307861"
130                         ewarn
131                 fi
132                 eshopts_pop
133         fi
134
135         case ${QT4_BUILD_TYPE} in
136                 live)    git-r3_src_unpack ;;
137                 release) default ;;
138         esac
139 }
140
141 # @FUNCTION: qt4-build-multilib_src_prepare
142 # @DESCRIPTION:
143 # Prepare the sources before the configure phase. Strip CFLAGS if necessary, and fix
144 # the build system in order to respect CFLAGS/CXXFLAGS/LDFLAGS specified in make.conf.
145 qt4-build-multilib_src_prepare() {
146         if [[ ${PN} != qtcore ]]; then
147                 # avoid unnecessary qmake recompilations
148                 sed -i -e 's/^if true;/if false;/' configure \
149                         || die "sed failed (skip qmake bootstrap)"
150         fi
151
152         # skip X11 tests in non-gui packages to avoid spurious dependencies
153         if has ${PN} qtbearer qtcore qtdbus qtscript qtsql qttest qttranslations qtxmlpatterns; then
154                 sed -i -e '/^if.*PLATFORM_X11.*CFG_GUI/,/^fi$/d' configure \
155                         || die "sed failed (skip X11 tests)"
156         fi
157
158         if [[ ${PN} == qtcore ]]; then
159                 # Bug 373061
160                 # qmake bus errors with -O2 or -O3 but -O1 works
161                 if [[ ${CHOST} == *86*-apple-darwin* ]]; then
162                         replace-flags -O[23] -O1
163                 fi
164
165                 # Bug 503500
166                 # undefined reference with -Os and --as-needed
167                 if use x86 || use_if_iuse abi_x86_32; then
168                         replace-flags -Os -O2
169                 fi
170         fi
171
172         if [[ ${PN} == qtdeclarative ]]; then
173                 # Bug 551560
174                 # gcc-4.8 ICE with -Os, fixed in 4.9
175                 if use x86 && [[ $(gcc-version) == 4.8 ]]; then
176                         replace-flags -Os -O2
177                 fi
178         fi
179
180         if [[ ${PN} == qtwebkit ]]; then
181                 # Bug 550780
182                 # various ICEs with graphite-related flags, gcc-5 works
183                 if [[ $(gcc-major-version) -lt 5 ]]; then
184                         filter-flags -fgraphite-identity -floop-strip-mine
185                 fi
186         fi
187
188         # Bug 261632
189         if use ppc64; then
190                 append-flags -mminimal-toc
191         fi
192
193         # Teach configure about gcc-6 and later
194         sed -i -e 's:5\*|:[5-9]*|:' \
195                 configure || die "sed gcc version failed"
196
197         # Read also AR from the environment
198         sed -i -e 's/^SYSTEM_VARIABLES="/&AR /' \
199                 configure || die "sed SYSTEM_VARIABLES failed"
200
201         # Reset QMAKE_*FLAGS_{RELEASE,DEBUG} variables,
202         # or they will override the user's flags (via .qmake.cache)
203         sed -i -e '/^SYSTEM_VARIABLES=/ i \
204                 QMakeVar set QMAKE_CFLAGS_RELEASE\
205                 QMakeVar set QMAKE_CFLAGS_DEBUG\
206                 QMakeVar set QMAKE_CXXFLAGS_RELEASE\
207                 QMakeVar set QMAKE_CXXFLAGS_DEBUG\
208                 QMakeVar set QMAKE_LFLAGS_RELEASE\
209                 QMakeVar set QMAKE_LFLAGS_DEBUG\n' \
210                 configure || die "sed QMAKE_*FLAGS_{RELEASE,DEBUG} failed"
211
212         # Drop -nocache from qmake invocation in all configure tests, to ensure that the
213         # correct toolchain and build flags are picked up from config.tests/.qmake.cache
214         find config.tests/unix -name '*.test' -type f -execdir \
215                 sed -i -e '/bin\/qmake/s/-nocache//' '{}' + || die "sed -nocache failed"
216
217         # compile.test needs additional patching so that it doesn't create another cache file
218         # inside the test subdir, which would incorrectly override config.tests/.qmake.cache
219         sed -i -e '/echo.*QT_BUILD_TREE.*\.qmake\.cache/d' \
220                 -e '/bin\/qmake/s/ "$SRCDIR/ "QT_BUILD_TREE=$OUTDIR"&/' \
221                 config.tests/unix/compile.test || die "sed compile.test failed"
222
223         # Delete references to the obsolete /usr/X11R6 directory
224         # On prefix, this also prevents looking at non-prefix stuff
225         sed -i -re '/^QMAKE_(LIB|INC)DIR(_X11|_OPENGL|)\s+/ s/=.*/=/' \
226                 mkspecs/common/linux.conf \
227                 mkspecs/$(qt4_get_mkspec)/qmake.conf \
228                 || die "sed QMAKE_(LIB|INC)DIR failed"
229
230         if use_if_iuse aqua; then
231                 sed -i \
232                         -e '/^CONFIG/s:app_bundle::' \
233                         -e '/^CONFIG/s:plugin_no_soname:plugin_with_soname absolute_library_soname:' \
234                         mkspecs/$(qt4_get_mkspec)/qmake.conf \
235                         || die "sed failed (aqua)"
236
237                 # we are crazy and build cocoa + qt3support
238                 if { ! in_iuse qt3support || use qt3support; } && [[ ${CHOST##*-darwin} -ge 9 ]]; then
239                         sed -i -e "/case \"\$PLATFORM,\$CFG_MAC_COCOA\" in/,/;;/ s|CFG_QT3SUPPORT=\"no\"|CFG_QT3SUPPORT=\"yes\"|" \
240                                 configure || die "sed failed (cocoa + qt3support)"
241                 fi
242         fi
243
244         if [[ ${CHOST} == *-darwin* ]]; then
245                 # Set FLAGS and remove -arch, since our gcc-apple is multilib crippled (by design)
246                 sed -i \
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                         mkspecs/common/g++-macx.conf \
252                         || die "sed g++-macx.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                 sed -i \
258                         -e "s:-arch i386::" \
259                         -e "s:-arch ppc::" \
260                         -e "s:-arch x86_64::" \
261                         -e "s:-arch ppc64::" \
262                         -e "s:-arch \$i::" \
263                         -e "/if \[ ! -z \"\$NATIVE_64_ARCH\" \]; then/,/fi/ d" \
264                         -e "s:CFG_MAC_XARCH=yes:CFG_MAC_XARCH=no:g" \
265                         -e "s:-Xarch_x86_64::g" \
266                         -e "s:-Xarch_ppc64::g" \
267                         configure mkspecs/common/gcc-base-macx.conf mkspecs/common/g++-macx.conf \
268                         || die "sed -arch/-Xarch failed"
269
270                 # On Snow Leopard don't fall back to 10.5 deployment target.
271                 if [[ ${CHOST} == *-apple-darwin10 ]]; then
272                         sed -i \
273                                 -e "s:QMakeVar set QMAKE_MACOSX_DEPLOYMENT_TARGET.*:QMakeVar set QMAKE_MACOSX_DEPLOYMENT_TARGET 10.6:g" \
274                                 -e "s:-mmacosx-version-min=10.[0-9]:-mmacosx-version-min=10.6:g" \
275                                 configure mkspecs/common/g++-macx.conf \
276                                 || die "sed deployment target failed"
277                 fi
278         fi
279
280         if [[ ${CHOST} == *-solaris* ]]; then
281                 sed -i -e '/^QMAKE_LFLAGS_THREAD/a QMAKE_LFLAGS_DYNAMIC_LIST = -Wl,--dynamic-list,' \
282                         mkspecs/$(qt4_get_mkspec)/qmake.conf || die
283         fi
284
285         # apply patches
286         [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
287         epatch_user
288 }
289
290 qt4_multilib_src_configure() {
291         qt4_prepare_env
292
293         qt4_symlink_tools_to_build_dir
294
295         # toolchain setup ('local -x' because of bug 532510)
296         local -x \
297                 AR="$(tc-getAR) cqs" \
298                 CC=$(tc-getCC) \
299                 CXX=$(tc-getCXX) \
300                 LD=$(tc-getCXX) \
301                 MAKEFLAGS=${MAKEOPTS} \
302                 OBJCOPY=$(tc-getOBJCOPY) \
303                 OBJDUMP=$(tc-getOBJDUMP) \
304                 STRIP=$(tc-getSTRIP)
305
306         # convert tc-arch to the values supported by Qt
307         local arch=$(tc-arch)
308         case ${arch} in
309                 amd64|x64-*)    arch=x86_64 ;;
310                 arm64|hppa)     arch=generic ;;
311                 ppc*-macos)     arch=ppc ;;
312                 ppc*)           arch=powerpc ;;
313                 sparc*)         arch=sparc ;;
314                 x86-macos)      arch=x86 ;;
315                 x86*)           arch=i386 ;;
316         esac
317
318         # configure arguments
319         local conf=(
320                 # installation paths
321                 -prefix "${QT4_PREFIX}"
322                 -bindir "${QT4_BINDIR}"
323                 -libdir "${QT4_LIBDIR}"
324                 -docdir "${QT4_DOCDIR}"
325                 -headerdir "${QT4_HEADERDIR}"
326                 -plugindir "${QT4_PLUGINDIR}"
327                 -importdir "${QT4_IMPORTDIR}"
328                 -datadir "${QT4_DATADIR}"
329                 -translationdir "${QT4_TRANSLATIONDIR}"
330                 -sysconfdir "${QT4_SYSCONFDIR}"
331                 -examplesdir "${QT4_EXAMPLESDIR}"
332                 -demosdir "${QT4_DEMOSDIR}"
333
334                 # debug/release
335                 $(use_if_iuse debug && echo -debug || echo -release)
336                 -no-separate-debug-info
337
338                 # licensing stuff
339                 -opensource -confirm-license
340
341                 # build shared libraries
342                 -shared
343
344                 # skip recursive processing of .pro files at the end of configure
345                 # (we run qmake by ourselves), thus saving quite a bit of time
346                 -dont-process
347
348                 # always enable large file support
349                 -largefile
350
351                 # exceptions USE flag
352                 $(in_iuse exceptions && qt_use exceptions || echo -exceptions)
353
354                 # build STL support
355                 -stl
356
357                 # architecture/platform (mkspec)
358                 -arch ${arch}
359                 -platform $(qt4_get_mkspec)
360
361                 # instruction set support
362                 $(is-flagq -mno-mmx     && echo -no-mmx)
363                 $(is-flagq -mno-3dnow   && echo -no-3dnow)
364                 $(is-flagq -mno-sse     && echo -no-sse)
365                 $(is-flagq -mno-sse2    && echo -no-sse2)
366                 $(is-flagq -mno-sse3    && echo -no-sse3)
367                 $(is-flagq -mno-ssse3   && echo -no-ssse3)
368                 $(is-flagq -mno-sse4.1  && echo -no-sse4.1)
369                 $(is-flagq -mno-sse4.2  && echo -no-sse4.2)
370                 $(is-flagq -mno-avx     && echo -no-avx)
371                 $(is-flagq -mfpu=*      && ! is-flagq -mfpu=*neon* && echo -no-neon)
372
373                 # bug 367045
374                 $([[ ${CHOST} == *86*-apple-darwin* ]] && echo -no-ssse3)
375
376                 # prefer system libraries
377                 -system-zlib
378
379                 # exclude examples and demos from default build
380                 -nomake examples
381                 -nomake demos
382
383                 # disable rpath on non-prefix (bugs 380415 and 417169)
384                 $(usex prefix '' -no-rpath)
385
386                 # print verbose information about each configure test
387                 -verbose
388
389                 # precompiled headers don't work on hardened, where the flag is masked
390                 $(in_iuse pch && qt_use pch || echo -no-pch)
391
392                 # enable linker optimizations to reduce relocations, except on Solaris
393                 # where this flag seems to introduce major breakage to applications,
394                 # mostly to be seen as a core dump with the message:
395                 # "QPixmap: Must construct a QApplication before a QPaintDevice"
396                 $([[ ${CHOST} != *-solaris* ]] && echo -reduce-relocations)
397         )
398
399         if use_if_iuse aqua; then
400                 if [[ ${CHOST##*-darwin} -ge 9 ]]; then
401                         conf+=(
402                                 # on (snow) leopard use the new (frameworked) cocoa code
403                                 -cocoa -framework
404                                 # add hint for the framework location
405                                 -F"${QT4_LIBDIR}"
406                         )
407                 else
408                         conf+=(-no-framework)
409                 fi
410         fi
411
412         conf+=(
413                 # module-specific options
414                 "${myconf[@]}"
415         )
416
417         einfo "Configuring with: ${conf[@]}"
418         "${S}"/configure "${conf[@]}" || die "configure failed"
419
420         # configure is stupid and assigns QMAKE_LFLAGS twice,
421         # thus the previous -rpath-link flag gets overwritten
422         # and some packages (e.g. qthelp) fail to link
423         sed -i -e '/^QMAKE_LFLAGS =/ s:$: $$QMAKE_LFLAGS:' \
424                 .qmake.cache || die "sed .qmake.cache failed"
425
426         qt4_qmake
427         qt4_foreach_target_subdir qt4_qmake
428 }
429
430 qt4_multilib_src_compile() {
431         qt4_prepare_env
432
433         qt4_foreach_target_subdir emake
434 }
435
436 qt4_multilib_src_test() {
437         qt4_prepare_env
438
439         qt4_foreach_target_subdir emake -j1 check
440 }
441
442 qt4_multilib_src_install() {
443         qt4_prepare_env
444
445         qt4_foreach_target_subdir emake INSTALL_ROOT="${D}" install
446
447         if [[ ${PN} == qtcore ]]; then
448                 set -- emake INSTALL_ROOT="${D}" install_{mkspecs,qmake}
449                 einfo "Running $*"
450                 "$@"
451
452                 # install env.d file
453                 cat > "${T}/44qt4-${CHOST}" <<-_EOF_
454                         LDPATH="${QT4_LIBDIR}"
455                 _EOF_
456                 doenvd "${T}/44qt4-${CHOST}"
457
458                 # install qtchooser configuration file
459                 cat > "${T}/qt4-${CHOST}.conf" <<-_EOF_
460                         ${QT4_BINDIR}
461                         ${QT4_LIBDIR}
462                 _EOF_
463
464                 (
465                         insinto /etc/xdg/qtchooser
466                         doins "${T}/qt4-${CHOST}.conf"
467                 )
468
469                 if multilib_is_native_abi; then
470                         # convenience symlinks
471                         dosym qt4-"${CHOST}".conf /etc/xdg/qtchooser/4.conf
472                         dosym qt4-"${CHOST}".conf /etc/xdg/qtchooser/qt4.conf
473                         # TODO bug 522646: write an eselect module to manage default.conf
474                         dosym qt4.conf /etc/xdg/qtchooser/default.conf
475                 fi
476         fi
477
478         # move pkgconfig directory to the correct location
479         if [[ -d ${D}${QT4_LIBDIR}/pkgconfig ]]; then
480                 mv "${D}${QT4_LIBDIR}"/pkgconfig "${ED}usr/$(get_libdir)" || die
481         fi
482
483         qt4_install_module_qconfigs
484         qt4_symlink_framework_headers
485 }
486
487 qt4_multilib_src_install_all() {
488         if [[ ${PN} == qtcore ]]; then
489                 # include gentoo-qconfig.h at the beginning of Qt{,Core}/qconfig.h
490                 if use aqua && [[ ${CHOST#*-darwin} -ge 9 ]]; then
491                         sed -i -e '1i #include <QtCore/Gentoo/gentoo-qconfig.h>\n' \
492                                 "${D}${QT4_LIBDIR}"/QtCore.framework/Headers/qconfig.h \
493                                 || die "sed failed (qconfig.h)"
494                         dosym "${QT4_HEADERDIR#${EPREFIX}}"/Gentoo \
495                                 "${QT4_LIBDIR#${EPREFIX}}"/QtCore.framework/Headers/Gentoo
496                 else
497                         sed -i -e '1i #include <Gentoo/gentoo-qconfig.h>\n' \
498                                 "${D}${QT4_HEADERDIR}"/Qt{,Core}/qconfig.h \
499                                 || die "sed failed (qconfig.h)"
500                 fi
501
502                 dodir "${QT4_DATADIR#${EPREFIX}}"/mkspecs/gentoo
503                 mv "${D}${QT4_DATADIR}"/mkspecs/{qconfig.pri,gentoo/} || die
504         fi
505
506         # install private headers of a few modules
507         if has ${PN} qtcore qtdeclarative qtgui qtscript; then
508                 local moduledir=${PN#qt}
509                 local modulename=Qt$(tr 'a-z' 'A-Z' <<< ${moduledir:0:1})${moduledir:1}
510                 [[ ${moduledir} == core ]] && moduledir=corelib
511
512                 einfo "Installing private headers into ${QT4_HEADERDIR}/${modulename}/private"
513                 insinto "${QT4_HEADERDIR#${EPREFIX}}"/${modulename}/private
514                 find "${S}"/src/${moduledir} -type f -name '*_p.h' -exec doins '{}' + || die
515         fi
516
517         prune_libtool_files
518 }
519
520 # @FUNCTION: qt4-build-multilib_pkg_postinst
521 # @DESCRIPTION:
522 # Regenerate configuration after installation or upgrade/downgrade.
523 qt4-build-multilib_pkg_postinst() {
524         qt4_regenerate_global_qconfigs
525 }
526
527 # @FUNCTION: qt4-build-multilib_pkg_postrm
528 # @DESCRIPTION:
529 # Regenerate configuration when a module is completely removed.
530 qt4-build-multilib_pkg_postrm() {
531         qt4_regenerate_global_qconfigs
532 }
533
534
535 ######  Public helpers  ######
536
537 # @FUNCTION: qt_use
538 # @USAGE: <flag> [feature] [enableval]
539 # @DESCRIPTION:
540 # <flag> is the name of a flag in IUSE.
541 #
542 # Outputs "-${enableval}-${feature}" if <flag> is enabled, "-no-${feature}"
543 # otherwise. If [feature] is not specified, <flag> is used in its place.
544 # If [enableval] is not specified, the "-${enableval}" prefix is omitted.
545 qt_use() {
546         [[ $# -ge 1 ]] || die "${FUNCNAME}() requires at least one argument"
547
548         usex "$1" "${3:+-$3}-${2:-$1}" "-no-${2:-$1}"
549 }
550
551 # @FUNCTION: qt_native_use
552 # @USAGE: <flag> [feature] [enableval]
553 # @DESCRIPTION:
554 # <flag> is the name of a flag in IUSE.
555 #
556 # Outputs "-${enableval}-${feature}" if <flag> is enabled and we are currently
557 # building for the native ABI, "-no-${feature}" otherwise. If [feature] is not
558 # specified, <flag> is used in its place. If [enableval] is not specified,
559 # the "-${enableval}" prefix is omitted.
560 qt_native_use() {
561         [[ $# -ge 1 ]] || die "${FUNCNAME}() requires at least one argument"
562
563         multilib_is_native_abi && qt_use "$@" || echo "-no-${2:-$1}"
564 }
565
566
567 ######  Internal functions  ######
568
569 # @FUNCTION: qt4_prepare_env
570 # @INTERNAL
571 # @DESCRIPTION:
572 # Prepares the environment for building Qt.
573 qt4_prepare_env() {
574         # setup installation directories
575         # note: keep paths in sync with qmake-utils.eclass
576         QT4_PREFIX=${EPREFIX}/usr
577         QT4_HEADERDIR=${QT4_PREFIX}/include/qt4
578         QT4_LIBDIR=${QT4_PREFIX}/$(get_libdir)/qt4
579         QT4_BINDIR=${QT4_LIBDIR}/bin
580         QT4_PLUGINDIR=${QT4_LIBDIR}/plugins
581         QT4_IMPORTDIR=${QT4_LIBDIR}/imports
582         QT4_DATADIR=${QT4_PREFIX}/share/qt4
583         QT4_DOCDIR=${QT4_PREFIX}/share/doc/qt-${PV}
584         QT4_TRANSLATIONDIR=${QT4_DATADIR}/translations
585         QT4_EXAMPLESDIR=${QT4_DATADIR}/examples
586         QT4_DEMOSDIR=${QT4_DATADIR}/demos
587         QT4_SYSCONFDIR=${EPREFIX}/etc/qt4
588         QMAKE_LIBDIR_QT=${QT4_LIBDIR}
589
590         export XDG_CONFIG_HOME="${T}"
591 }
592
593 # @FUNCTION: qt4_foreach_target_subdir
594 # @INTERNAL
595 # @DESCRIPTION:
596 # Executes the given command inside each directory listed in QT4_TARGET_DIRECTORIES.
597 qt4_foreach_target_subdir() {
598         local ret=0 subdir=
599         for subdir in ${QT4_TARGET_DIRECTORIES}; do
600                 mkdir -p "${subdir}" || die
601                 pushd "${subdir}" >/dev/null || die
602
603                 einfo "Running $* ${subdir:+in ${subdir}}"
604                 "$@"
605                 ((ret+=$?))
606
607                 popd >/dev/null || die
608         done
609
610         return ${ret}
611 }
612
613 # @FUNCTION: qt4_symlink_tools_to_build_dir
614 # @INTERNAL
615 # @DESCRIPTION:
616 # Symlinks qtcore tools to BUILD_DIR,
617 # so that they can be used when building other modules.
618 qt4_symlink_tools_to_build_dir() {
619         local tool= tools=()
620         if [[ ${PN} != qtcore ]]; then
621                 tools+=(qmake moc rcc uic)
622         fi
623
624         mkdir -p "${BUILD_DIR}"/bin || die
625         pushd "${BUILD_DIR}"/bin >/dev/null || die
626
627         for tool in "${tools[@]}"; do
628                 [[ -e ${QT4_BINDIR}/${tool} ]] || continue
629                 ln -s "${QT4_BINDIR}/${tool}" . || die "failed to symlink ${tool}"
630         done
631
632         popd >/dev/null || die
633 }
634
635 # @FUNCTION: qt4_qmake
636 # @INTERNAL
637 # @DESCRIPTION:
638 # Helper function that runs qmake in the current target subdir.
639 # Intended to be called by qt4_foreach_target_subdir().
640 qt4_qmake() {
641         local projectdir=${PWD/#${BUILD_DIR}/${S}}
642
643         "${BUILD_DIR}"/bin/qmake \
644                 "${projectdir}" \
645                 CONFIG+=nostrip \
646                 LIBS+=-L"${QT4_LIBDIR}" \
647                 "${myqmakeargs[@]}" \
648                 || die "qmake failed (${projectdir#${S}/})"
649 }
650
651 # @FUNCTION: qt4_install_module_qconfigs
652 # @INTERNAL
653 # @DESCRIPTION:
654 # Creates and installs gentoo-specific ${PN}-qconfig.{h,pri} files.
655 qt4_install_module_qconfigs() {
656         local x
657         if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} ]]; then
658                 for x in QCONFIG_ADD QCONFIG_REMOVE; do
659                         [[ -n ${!x} ]] && echo ${x}=${!x} >> "${BUILD_DIR}"/${PN}-qconfig.pri
660                 done
661                 insinto ${QT4_DATADIR#${EPREFIX}}/mkspecs/gentoo
662                 doins "${BUILD_DIR}"/${PN}-qconfig.pri
663         fi
664
665         if [[ -n ${QCONFIG_DEFINE} ]]; then
666                 for x in ${QCONFIG_DEFINE}; do
667                         echo "#define ${x}" >> "${BUILD_DIR}"/gentoo-${PN}-qconfig.h
668                 done
669                 insinto ${QT4_HEADERDIR#${EPREFIX}}/Gentoo
670                 doins "${BUILD_DIR}"/gentoo-${PN}-qconfig.h
671         fi
672 }
673
674 # @FUNCTION: qt4_regenerate_global_qconfigs
675 # @INTERNAL
676 # @DESCRIPTION:
677 # Generates Gentoo-specific qconfig.{h,pri} according to the build configuration.
678 # Don't call die here because dying in pkg_post{inst,rm} only makes things worse.
679 qt4_regenerate_global_qconfigs() {
680         if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} || -n ${QCONFIG_DEFINE} || ${PN} == qtcore ]]; then
681                 local x qconfig_add qconfig_remove qconfig_new
682                 for x in "${ROOT}${QT4_DATADIR}"/mkspecs/gentoo/*-qconfig.pri; do
683                         [[ -f ${x} ]] || continue
684                         qconfig_add+=" $(sed -n 's/^QCONFIG_ADD=//p' "${x}")"
685                         qconfig_remove+=" $(sed -n 's/^QCONFIG_REMOVE=//p' "${x}")"
686                 done
687
688                 if [[ -e "${ROOT}${QT4_DATADIR}"/mkspecs/gentoo/qconfig.pri ]]; then
689                         # start with the qconfig.pri that qtcore installed
690                         if ! cp "${ROOT}${QT4_DATADIR}"/mkspecs/gentoo/qconfig.pri \
691                                 "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri; then
692                                 eerror "cp qconfig failed."
693                                 return 1
694                         fi
695
696                         # generate list of QT_CONFIG entries from the existing list
697                         # including qconfig_add and excluding qconfig_remove
698                         for x in $(sed -n 's/^QT_CONFIG +=//p' \
699                                 "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri) ${qconfig_add}; do
700                                         has ${x} ${qconfig_remove} || qconfig_new+=" ${x}"
701                         done
702
703                         # replace the existing QT_CONFIG list with qconfig_new
704                         if ! sed -i -e "s/QT_CONFIG +=.*/QT_CONFIG += ${qconfig_new}/" \
705                                 "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri; then
706                                 eerror "Sed for QT_CONFIG failed"
707                                 return 1
708                         fi
709
710                         # create Gentoo/qconfig.h
711                         if [[ ! -e ${ROOT}${QT4_HEADERDIR}/Gentoo ]]; then
712                                 if ! mkdir -p "${ROOT}${QT4_HEADERDIR}"/Gentoo; then
713                                         eerror "mkdir ${QT4_HEADERDIR}/Gentoo failed"
714                                         return 1
715                                 fi
716                         fi
717                         : > "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-qconfig.h
718                         for x in "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-*-qconfig.h; do
719                                 [[ -f ${x} ]] || continue
720                                 cat "${x}" >> "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-qconfig.h
721                         done
722                 else
723                         rm -f "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri
724                         rm -f "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-qconfig.h
725                         rmdir "${ROOT}${QT4_DATADIR}"/mkspecs \
726                                 "${ROOT}${QT4_DATADIR}" \
727                                 "${ROOT}${QT4_HEADERDIR}"/Gentoo \
728                                 "${ROOT}${QT4_HEADERDIR}" 2>/dev/null
729                 fi
730         fi
731 }
732
733 # @FUNCTION: qt4_symlink_framework_headers
734 # @DESCRIPTION:
735 # On OS X we need to add some symlinks when frameworks are being
736 # used, to avoid complications with some more or less stupid packages.
737 qt4_symlink_framework_headers() {
738         if use_if_iuse aqua && [[ ${CHOST##*-darwin} -ge 9 ]]; then
739                 local frw dest f h rdir
740                 # Some packages tend to include <Qt/...>
741                 dodir "${QT4_HEADERDIR#${EPREFIX}}"/Qt
742
743                 # Fake normal headers when frameworks are installed... eases life later
744                 # on, make sure we use relative links though, as some ebuilds assume
745                 # these dirs exist in src_install to add additional files
746                 f=${QT4_HEADERDIR}
747                 h=${QT4_LIBDIR}
748                 while [[ -n ${f} && ${f%%/*} == ${h%%/*} ]] ; do
749                         f=${f#*/}
750                         h=${h#*/}
751                 done
752                 rdir=${h}
753                 f="../"
754                 while [[ ${h} == */* ]] ; do
755                         f="${f}../"
756                         h=${h#*/}
757                 done
758                 rdir="${f}${rdir}"
759
760                 for frw in "${D}${QT4_LIBDIR}"/*.framework; do
761                         [[ -e "${frw}"/Headers ]] || continue
762                         f=$(basename ${frw})
763                         dest="${QT4_HEADERDIR#${EPREFIX}}"/${f%.framework}
764                         dosym "${rdir}"/${f}/Headers "${dest}"
765
766                         # Link normal headers as well.
767                         for hdr in "${D}${QT4_LIBDIR}/${f}"/Headers/*; do
768                                 h=$(basename ${hdr})
769                                 dosym "../${rdir}"/${f}/Headers/${h} \
770                                         "${QT4_HEADERDIR#${EPREFIX}}"/Qt/${h}
771                         done
772                 done
773         fi
774 }
775
776 # @FUNCTION: qt4_get_mkspec
777 # @INTERNAL
778 # @DESCRIPTION:
779 # Returns the right mkspec for the current CHOST/CXX combination.
780 qt4_get_mkspec() {
781         local spec=
782
783         case ${CHOST} in
784                 *-linux*)
785                         spec=linux ;;
786                 *-darwin*)
787                         use_if_iuse aqua &&
788                                 spec=macx ||   # mac with carbon/cocoa
789                                 spec=darwin ;; # darwin/mac with X11
790                 *-freebsd*|*-dragonfly*)
791                         spec=freebsd ;;
792                 *-netbsd*)
793                         spec=netbsd ;;
794                 *-openbsd*)
795                         spec=openbsd ;;
796                 *-aix*)
797                         spec=aix ;;
798                 hppa*-hpux*)
799                         spec=hpux ;;
800                 ia64*-hpux*)
801                         spec=hpuxi ;;
802                 *-solaris*)
803                         spec=solaris ;;
804                 *)
805                         die "qt4-build-multilib.eclass: unsupported CHOST '${CHOST}'" ;;
806         esac
807
808         case $(tc-getCXX) in
809                 *g++*)
810                         spec+=-g++ ;;
811                 *clang*)
812                         if [[ -d ${S}/mkspecs/unsupported/${spec}-clang ]]; then
813                                 spec=unsupported/${spec}-clang
814                         else
815                                 ewarn "${spec}-clang mkspec does not exist, falling back to ${spec}-g++"
816                                 spec+=-g++
817                         fi ;;
818                 *icpc*)
819                         if [[ -d ${S}/mkspecs/${spec}-icc ]]; then
820                                 spec+=-icc
821                         else
822                                 ewarn "${spec}-icc mkspec does not exist, falling back to ${spec}-g++"
823                                 spec+=-g++
824                         fi ;;
825                 *)
826                         die "qt4-build-multilib.eclass: unsupported compiler '$(tc-getCXX)'" ;;
827         esac
828
829         # Add -64 for 64-bit prefix profiles
830         if use amd64-linux || use ia64-linux || use ppc64-linux ||
831                 use x64-macos ||
832                 use sparc64-freebsd || use x64-freebsd || use x64-openbsd ||
833                 use ia64-hpux ||
834                 use sparc64-solaris || use x64-solaris
835         then
836                 [[ -d ${S}/mkspecs/${spec}-64 ]] && spec+=-64
837         fi
838
839         echo ${spec}
840 }