x11-misc/alock: Take ownership of package
[gentoo.git] / eclass / qt5-build.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: qt5-build.eclass
6 # @MAINTAINER:
7 # qt@gentoo.org
8 # @AUTHOR:
9 # Davide Pesavento <pesa@gentoo.org>
10 # @BLURB: Eclass for Qt5 split ebuilds.
11 # @DESCRIPTION:
12 # This eclass contains various functions that are used when building Qt5.
13 # Requires EAPI 5.
14
15 case ${EAPI} in
16         5)      : ;;
17         *)      die "qt5-build.eclass: unsupported EAPI=${EAPI:-0}" ;;
18 esac
19
20 inherit eutils flag-o-matic multilib toolchain-funcs virtualx
21
22 QT5_MINOR_VERSION=${PV#*.}
23 QT5_MINOR_VERSION=${QT5_MINOR_VERSION%%.*}
24
25 HOMEPAGE="https://www.qt.io/"
26 LICENSE="|| ( LGPL-2.1 LGPL-3 ) FDL-1.3"
27 SLOT="5"
28
29 # @ECLASS-VARIABLE: QT5_MODULE
30 # @DESCRIPTION:
31 # The upstream name of the module this package belongs to. Used for
32 # SRC_URI and EGIT_REPO_URI. Must be defined before inheriting the eclass.
33 : ${QT5_MODULE:=${PN}}
34
35 case ${PV} in
36         5.9999)
37                 # git dev branch
38                 QT5_BUILD_TYPE="live"
39                 EGIT_BRANCH="dev"
40                 ;;
41         5.?.9999)
42                 # git stable branch
43                 QT5_BUILD_TYPE="live"
44                 EGIT_BRANCH=${PV%.9999}
45                 ;;
46         *_alpha*|*_beta*|*_rc*)
47                 # development release
48                 QT5_BUILD_TYPE="release"
49                 MY_P=${QT5_MODULE}-opensource-src-${PV/_/-}
50                 SRC_URI="http://download.qt.io/development_releases/qt/${PV%.*}/${PV/_/-}/submodules/${MY_P}.tar.xz"
51                 S=${WORKDIR}/${MY_P}
52                 ;;
53         *)
54                 # official stable release
55                 QT5_BUILD_TYPE="release"
56                 MY_P=${QT5_MODULE}-opensource-src-${PV}
57                 SRC_URI="http://download.qt.io/official_releases/qt/${PV%.*}/${PV}/submodules/${MY_P}.tar.xz"
58                 S=${WORKDIR}/${MY_P}
59                 ;;
60 esac
61
62 EGIT_REPO_URI=(
63         "git://code.qt.io/qt/${QT5_MODULE}.git"
64         "https://code.qt.io/git/qt/${QT5_MODULE}.git"
65         "https://github.com/qtproject/${QT5_MODULE}.git"
66 )
67 [[ ${QT5_BUILD_TYPE} == live ]] && inherit git-r3
68
69 IUSE="debug test"
70
71 [[ ${PN} == qtwebkit ]] && RESTRICT+=" mirror" # bug 524584
72 [[ ${QT5_BUILD_TYPE} == release ]] && RESTRICT+=" test" # bug 457182
73
74 DEPEND="
75         dev-lang/perl
76         virtual/pkgconfig
77 "
78 if [[ ${PN} != qttest ]]; then
79         if [[ ${QT5_MODULE} == qtbase ]]; then
80                 DEPEND+=" test? ( ~dev-qt/qttest-${PV} )"
81         else
82                 DEPEND+=" test? ( >=dev-qt/qttest-${PV}:5 )"
83         fi
84 fi
85 RDEPEND="
86         dev-qt/qtchooser
87 "
88
89 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install src_test pkg_postinst pkg_postrm
90
91
92 # @ECLASS-VARIABLE: PATCHES
93 # @DEFAULT_UNSET
94 # @DESCRIPTION:
95 # Array variable containing all the patches to be applied. This variable
96 # is expected to be defined in the global scope of ebuilds. Make sure to
97 # specify the full path. This variable is used in src_prepare phase.
98 #
99 # Example:
100 # @CODE
101 #       PATCHES=(
102 #               "${FILESDIR}/mypatch.patch"
103 #               "${FILESDIR}/mypatch2.patch"
104 #       )
105 # @CODE
106
107 # @ECLASS-VARIABLE: QT5_TARGET_SUBDIRS
108 # @DEFAULT_UNSET
109 # @DESCRIPTION:
110 # Array variable containing the source directories that should be built.
111 # All paths must be relative to ${S}.
112
113 # @ECLASS-VARIABLE: QT5_BUILD_DIR
114 # @DESCRIPTION:
115 # Build directory for out-of-source builds.
116 case ${QT5_BUILD_TYPE} in
117         live)    : ${QT5_BUILD_DIR:=${S}_build} ;;
118         release) : ${QT5_BUILD_DIR:=${S}} ;; # workaround for bug 497312
119 esac
120
121 # @ECLASS-VARIABLE: QT5_GENTOO_CONFIG
122 # @DEFAULT_UNSET
123 # @DESCRIPTION:
124 # Array of <useflag:feature:macro> triplets that are evaluated in src_install
125 # to generate the per-package list of enabled QT_CONFIG features and macro
126 # definitions, which are then merged together with all other Qt5 packages
127 # installed on the system to obtain the global qconfig.{h,pri} files.
128
129 # @ECLASS-VARIABLE: VIRTUALX_REQUIRED
130 # @DESCRIPTION:
131 # For proper description see virtualx.eclass man page.
132 # Here we redefine default value to be manual, if your package needs virtualx
133 # for tests you should proceed with setting VIRTUALX_REQUIRED=test.
134 : ${VIRTUALX_REQUIRED:=manual}
135
136
137 ######  Phase functions  ######
138
139 # @FUNCTION: qt5-build_src_unpack
140 # @DESCRIPTION:
141 # Unpacks the sources.
142 qt5-build_src_unpack() {
143         if [[ $(gcc-major-version) -lt 4 ]] || [[ $(gcc-major-version) -eq 4 && $(gcc-minor-version) -lt 5 ]]; then
144                 ewarn
145                 ewarn "Using a GCC version lower than 4.5 is not supported."
146                 ewarn
147         fi
148
149         if [[ ${PN} == qtwebkit ]]; then
150                 eshopts_push -s extglob
151                 if is-flagq '-g?(gdb)?([1-9])'; then
152                         ewarn
153                         ewarn "You have enabled debug info (probably have -g or -ggdb in your CFLAGS/CXXFLAGS)."
154                         ewarn "You may experience really long compilation times and/or increased memory usage."
155                         ewarn "If compilation fails, please try removing -g/-ggdb before reporting a bug."
156                         ewarn "For more info check out https://bugs.gentoo.org/307861"
157                         ewarn
158                 fi
159                 eshopts_pop
160         fi
161
162         case ${QT5_BUILD_TYPE} in
163                 live)    git-r3_src_unpack ;;
164                 release) default ;;
165         esac
166 }
167
168 # @FUNCTION: qt5-build_src_prepare
169 # @DESCRIPTION:
170 # Prepares the environment and patches the sources if necessary.
171 qt5-build_src_prepare() {
172         qt5_prepare_env
173
174         if [[ ${QT5_MODULE} == qtbase ]]; then
175                 qt5_symlink_tools_to_build_dir
176
177                 # Avoid unnecessary qmake recompilations
178                 sed -i -re "s|^if true;.*(\[ '\!').*(\"\\\$outpath/bin/qmake\".*)|if \1 -e \2 then|" \
179                         configure || die "sed failed (skip qmake bootstrap)"
180
181                 # Respect CC, CXX, *FLAGS, MAKEOPTS and EXTRA_EMAKE when bootstrapping qmake
182                 sed -i -e "/outpath\/qmake\".*\"\$MAKE\")/ s:): \
183                         ${MAKEOPTS} ${EXTRA_EMAKE} 'CC=$(tc-getCC)' 'CXX=$(tc-getCXX)' \
184                         'QMAKE_CFLAGS=${CFLAGS}' 'QMAKE_CXXFLAGS=${CXXFLAGS}' 'QMAKE_LFLAGS=${LDFLAGS}'&:" \
185                         -e '/"$CFG_RELEASE_QMAKE"/,/^\s\+fi$/ d' \
186                         configure || die "sed failed (respect env for qmake build)"
187                 sed -i -e '/^CPPFLAGS\s*=/ s/-g //' \
188                         qmake/Makefile.unix || die "sed failed (CPPFLAGS for qmake build)"
189
190                 # Respect CXX in {bsymbolic_functions,fvisibility,precomp}.test
191                 sed -i -e "/^QMAKE_CONF_COMPILER=/ s:=.*:=\"$(tc-getCXX)\":" \
192                         configure || die "sed failed (QMAKE_CONF_COMPILER)"
193
194                 # Respect toolchain and flags in config.tests
195                 find config.tests/unix -name '*.test' -type f \
196                         -execdir sed -i -e '/bin\/qmake/ s/-nocache //' '{}' + \
197                         || die "sed failed (config.tests)"
198
199                 # Don't add -O3 to CXXFLAGS (bug 549140)
200                 sed -i -e '/CONFIG\s*+=/ s/optimize_full//' \
201                         src/{corelib/corelib,gui/gui}.pro || die "sed failed (optimize_full)"
202         fi
203
204         # apply patches
205         [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
206         epatch_user
207 }
208
209 # @FUNCTION: qt5-build_src_configure
210 # @DESCRIPTION:
211 # Runs qmake in the target directories. For packages
212 # in qtbase, ./configure is also run before qmake.
213 qt5-build_src_configure() {
214         if [[ ${QT5_MODULE} == qtbase ]]; then
215                 qt5_base_configure
216         fi
217
218         qt5_foreach_target_subdir qt5_qmake
219 }
220
221 # @FUNCTION: qt5-build_src_compile
222 # @DESCRIPTION:
223 # Runs emake in the target directories.
224 qt5-build_src_compile() {
225         qt5_foreach_target_subdir emake
226 }
227
228 # @FUNCTION: qt5-build_src_test
229 # @DESCRIPTION:
230 # Runs tests in the target directories.
231 qt5-build_src_test() {
232         # disable broken cmake tests (bug 474004)
233         local myqmakeargs=("${myqmakeargs[@]}" -after SUBDIRS-=cmake SUBDIRS-=installed_cmake)
234
235         qt5_foreach_target_subdir qt5_qmake
236         qt5_foreach_target_subdir emake
237
238         # create a custom testrunner script that correctly sets
239         # {,DY}LD_LIBRARY_PATH before executing the given test
240         local testrunner=${QT5_BUILD_DIR}/gentoo-testrunner
241         cat <<-EOF > "${testrunner}"
242         #!/bin/sh
243         export LD_LIBRARY_PATH="${QT5_BUILD_DIR}/lib:${QT5_LIBDIR}"
244         export DYLD_LIBRARY_PATH="${QT5_BUILD_DIR}/lib:${QT5_LIBDIR}"
245         "\$@"
246         EOF
247         chmod +x "${testrunner}"
248
249         _qt5_test_runner() {
250                 qt5_foreach_target_subdir emake TESTRUNNER="'${testrunner}'" check
251         }
252
253         if [[ ${VIRTUALX_REQUIRED} == test ]]; then
254                 VIRTUALX_COMMAND="_qt5_test_runner" virtualmake
255         else
256                 _qt5_test_runner
257         fi
258 }
259
260 # @FUNCTION: qt5-build_src_install
261 # @DESCRIPTION:
262 # Runs emake install in the target directories.
263 qt5-build_src_install() {
264         qt5_foreach_target_subdir emake INSTALL_ROOT="${D}" install
265
266         if [[ ${PN} == qtcore ]]; then
267                 pushd "${QT5_BUILD_DIR}" >/dev/null || die
268
269                 set -- emake INSTALL_ROOT="${D}" install_{global_docs,mkspecs,qmake,syncqt}
270                 einfo "Running $*"
271                 "$@"
272
273                 popd >/dev/null || die
274
275                 docompress -x "${QT5_DOCDIR#${EPREFIX}}"/global
276
277                 # install an empty Gentoo/gentoo-qconfig.h in ${D}
278                 # so that it's placed under package manager control
279                 > "${T}"/gentoo-qconfig.h
280                 (
281                         insinto "${QT5_HEADERDIR#${EPREFIX}}"/Gentoo
282                         doins "${T}"/gentoo-qconfig.h
283                 )
284
285                 # include gentoo-qconfig.h at the beginning of QtCore/qconfig.h
286                 sed -i -e '1i #include <Gentoo/gentoo-qconfig.h>\n' \
287                         "${D}${QT5_HEADERDIR}"/QtCore/qconfig.h \
288                         || die "sed failed (qconfig.h)"
289
290                 # install qtchooser configuration file
291                 cat > "${T}/qt5-${CHOST}.conf" <<-_EOF_
292                         ${QT5_BINDIR}
293                         ${QT5_LIBDIR}
294                 _EOF_
295
296                 (
297                         insinto /etc/xdg/qtchooser
298                         doins "${T}/qt5-${CHOST}.conf"
299                 )
300
301                 # convenience symlinks
302                 dosym qt5-"${CHOST}".conf /etc/xdg/qtchooser/5.conf
303                 dosym qt5-"${CHOST}".conf /etc/xdg/qtchooser/qt5.conf
304         fi
305
306         qt5_install_module_qconfigs
307         prune_libtool_files
308 }
309
310 # @FUNCTION: qt5-build_pkg_postinst
311 # @DESCRIPTION:
312 # Regenerate configuration after installation or upgrade/downgrade.
313 qt5-build_pkg_postinst() {
314         qt5_regenerate_global_qconfigs
315 }
316
317 # @FUNCTION: qt5-build_pkg_postrm
318 # @DESCRIPTION:
319 # Regenerate configuration when a module is completely removed.
320 qt5-build_pkg_postrm() {
321         if [[ -z ${REPLACED_BY_VERSION} && ${PN} != qtcore ]]; then
322                 qt5_regenerate_global_qconfigs
323         fi
324 }
325
326
327 ######  Public helpers  ######
328
329 # @FUNCTION: qt_use
330 # @USAGE: <flag> [feature] [enableval]
331 # @DESCRIPTION:
332 # <flag> is the name of a flag in IUSE.
333 #
334 # Outputs "-${enableval}-${feature}" if <flag> is enabled, "-no-${feature}"
335 # otherwise. If [feature] is not specified, <flag> is used in its place.
336 # If [enableval] is not specified, the "-${enableval}" prefix is omitted.
337 qt_use() {
338         [[ $# -ge 1 ]] || die "${FUNCNAME}() requires at least one argument"
339
340         usex "$1" "${3:+-$3}-${2:-$1}" "-no-${2:-$1}"
341 }
342
343 # @FUNCTION: qt_use_compile_test
344 # @USAGE: <flag> [config]
345 # @DESCRIPTION:
346 # <flag> is the name of a flag in IUSE.
347 # [config] is the argument of qtCompileTest, defaults to <flag>.
348 #
349 # This function is useful to disable optional dependencies that are checked
350 # at qmake-time using the qtCompileTest() function. If <flag> is disabled,
351 # the compile test is skipped and the dependency is assumed to be unavailable,
352 # i.e. the corresponding feature will be disabled. Note that all invocations
353 # of this function must happen before calling qt5-build_src_configure.
354 qt_use_compile_test() {
355         [[ $# -ge 1 ]] || die "${FUNCNAME}() requires at least one argument"
356
357         if ! use "$1"; then
358                 mkdir -p "${QT5_BUILD_DIR}" || die
359                 echo "CONFIG += done_config_${2:-$1}" >> "${QT5_BUILD_DIR}"/.qmake.cache || die
360         fi
361 }
362
363 # @FUNCTION: qt_use_disable_mod
364 # @USAGE: <flag> <module> <files...>
365 # @DESCRIPTION:
366 # <flag> is the name of a flag in IUSE.
367 # <module> is the (lowercase) name of a Qt5 module.
368 # <files...> is a list of one or more qmake project files.
369 #
370 # This function patches <files> to treat <module> as not installed
371 # when <flag> is disabled, otherwise it does nothing.
372 # This can be useful to avoid an automagic dependency when the module
373 # is present on the system but the corresponding USE flag is disabled.
374 qt_use_disable_mod() {
375         [[ $# -ge 3 ]] || die "${FUNCNAME}() requires at least three arguments"
376
377         local flag=$1
378         local module=$2
379         shift 2
380
381         if ! use "${flag}"; then
382                 echo "$@" | xargs sed -i -e "s/qtHaveModule(${module})/false/g" || die
383         fi
384 }
385
386
387 ######  Internal functions  ######
388
389 # @FUNCTION: qt5_prepare_env
390 # @INTERNAL
391 # @DESCRIPTION:
392 # Prepares the environment for building Qt.
393 qt5_prepare_env() {
394         # setup installation directories
395         # note: keep paths in sync with qmake-utils.eclass
396         QT5_PREFIX=${EPREFIX}/usr
397         QT5_HEADERDIR=${QT5_PREFIX}/include/qt5
398         QT5_LIBDIR=${QT5_PREFIX}/$(get_libdir)
399         QT5_ARCHDATADIR=${QT5_PREFIX}/$(get_libdir)/qt5
400         QT5_BINDIR=${QT5_ARCHDATADIR}/bin
401         QT5_PLUGINDIR=${QT5_ARCHDATADIR}/plugins
402         QT5_LIBEXECDIR=${QT5_ARCHDATADIR}/libexec
403         QT5_IMPORTDIR=${QT5_ARCHDATADIR}/imports
404         QT5_QMLDIR=${QT5_ARCHDATADIR}/qml
405         QT5_DATADIR=${QT5_PREFIX}/share/qt5
406         QT5_DOCDIR=${QT5_PREFIX}/share/doc/qt-${PV}
407         QT5_TRANSLATIONDIR=${QT5_DATADIR}/translations
408         QT5_EXAMPLESDIR=${QT5_DATADIR}/examples
409         QT5_TESTSDIR=${QT5_DATADIR}/tests
410         QT5_SYSCONFDIR=${EPREFIX}/etc/xdg
411
412         if [[ ${QT5_MODULE} == qtbase ]]; then
413                 # see mkspecs/features/qt_config.prf
414                 export QMAKEMODULES="${QT5_BUILD_DIR}/mkspecs/modules:${S}/mkspecs/modules:${QT5_ARCHDATADIR}/mkspecs/modules"
415         fi
416 }
417
418 # @FUNCTION: qt5_foreach_target_subdir
419 # @INTERNAL
420 # @DESCRIPTION:
421 # Executes the arguments inside each directory listed in QT5_TARGET_SUBDIRS.
422 qt5_foreach_target_subdir() {
423         [[ -z ${QT5_TARGET_SUBDIRS[@]} ]] && QT5_TARGET_SUBDIRS=("")
424
425         local ret=0 subdir=
426         for subdir in "${QT5_TARGET_SUBDIRS[@]}"; do
427                 if [[ ${EBUILD_PHASE} == test ]]; then
428                         subdir=tests/auto${subdir#src}
429                         [[ -d ${S}/${subdir} ]] || continue
430                 fi
431
432                 mkdir -p "${QT5_BUILD_DIR}/${subdir}" || die
433                 pushd "${QT5_BUILD_DIR}/${subdir}" >/dev/null || die
434
435                 einfo "Running $* ${subdir:+in ${subdir}}"
436                 "$@"
437                 ((ret+=$?))
438
439                 popd >/dev/null || die
440         done
441
442         return ${ret}
443 }
444
445 # @FUNCTION: qt5_symlink_tools_to_build_dir
446 # @INTERNAL
447 # @DESCRIPTION:
448 # Symlinks qmake and a few other tools to QT5_BUILD_DIR,
449 # so that they can be used when building other modules.
450 qt5_symlink_tools_to_build_dir() {
451         local tool= tools=()
452         if [[ ${PN} != qtcore ]]; then
453                 tools+=(qmake moc rcc qlalr)
454                 [[ ${PN} != qdoc ]] && tools+=(qdoc)
455                 [[ ${PN} != qtdbus ]] && tools+=(qdbuscpp2xml qdbusxml2cpp)
456                 [[ ${PN} != qtwidgets ]] && tools+=(uic)
457         fi
458
459         mkdir -p "${QT5_BUILD_DIR}"/bin || die
460         pushd "${QT5_BUILD_DIR}"/bin >/dev/null || die
461
462         for tool in "${tools[@]}"; do
463                 [[ -e ${QT5_BINDIR}/${tool} ]] || continue
464                 ln -s "${QT5_BINDIR}/${tool}" . || die "failed to symlink ${tool}"
465         done
466
467         popd >/dev/null || die
468 }
469
470 # @FUNCTION: qt5_base_configure
471 # @INTERNAL
472 # @DESCRIPTION:
473 # Runs ./configure for modules belonging to qtbase.
474 qt5_base_configure() {
475         # setup toolchain variables used by configure
476         tc-export AR CC CXX OBJDUMP RANLIB STRIP
477         export LD="$(tc-getCXX)"
478
479         # configure arguments
480         local conf=(
481                 # installation paths
482                 -prefix "${QT5_PREFIX}"
483                 -bindir "${QT5_BINDIR}"
484                 -headerdir "${QT5_HEADERDIR}"
485                 -libdir "${QT5_LIBDIR}"
486                 -archdatadir "${QT5_ARCHDATADIR}"
487                 -plugindir "${QT5_PLUGINDIR}"
488                 -libexecdir "${QT5_LIBEXECDIR}"
489                 -importdir "${QT5_IMPORTDIR}"
490                 -qmldir "${QT5_QMLDIR}"
491                 -datadir "${QT5_DATADIR}"
492                 -docdir "${QT5_DOCDIR}"
493                 -translationdir "${QT5_TRANSLATIONDIR}"
494                 -sysconfdir "${QT5_SYSCONFDIR}"
495                 -examplesdir "${QT5_EXAMPLESDIR}"
496                 -testsdir "${QT5_TESTSDIR}"
497
498                 # configure in release mode by default,
499                 # override via the CONFIG qmake variable
500                 -release
501                 -no-separate-debug-info
502
503                 # licensing stuff
504                 -opensource -confirm-license
505
506                 # let configure automatically figure out if C++11 is supported
507                 #-c++11
508
509                 # build shared libraries
510                 -shared
511
512                 # always enable large file support
513                 -largefile
514
515                 # disabling accessibility is not recommended by upstream, as
516                 # it will break QStyle and may break other internal parts of Qt
517                 -accessibility
518
519                 # disable all SQL drivers by default, override in qtsql
520                 -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci -no-sql-odbc
521                 -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 -no-sql-tds
522
523                 # obsolete flag, does nothing
524                 #-qml-debug
525
526                 # instruction set support
527                 $(is-flagq -mno-sse2    && echo -no-sse2)
528                 $(is-flagq -mno-sse3    && echo -no-sse3)
529                 $(is-flagq -mno-ssse3   && echo -no-ssse3)
530                 $(is-flagq -mno-sse4.1  && echo -no-sse4.1)
531                 $(is-flagq -mno-sse4.2  && echo -no-sse4.2)
532                 $(is-flagq -mno-avx     && echo -no-avx)
533                 $(is-flagq -mno-avx2    && echo -no-avx2)
534                 $(is-flagq -mno-dsp     && echo -no-mips_dsp)
535                 $(is-flagq -mno-dspr2   && echo -no-mips_dspr2)
536
537                 # use pkg-config to detect include and library paths
538                 -pkg-config
539
540                 # prefer system libraries (only common deps here)
541                 -system-zlib
542                 -system-pcre
543
544                 # disable everything to prevent automagic deps (part 1)
545                 -no-mtdev
546                 -no-journald
547                 $([[ ${QT5_MINOR_VERSION} -ge 6 ]] && echo -no-syslog)
548                 -no-libpng -no-libjpeg
549                 -no-freetype -no-harfbuzz
550                 -no-openssl
551                 $([[ ${QT5_MINOR_VERSION} -ge 5 ]] && echo -no-libproxy)
552                 $([[ ${QT5_MINOR_VERSION} -ge 5 ]] && echo -no-xkbcommon-{x11,evdev})
553                 -no-xinput2 -no-xcb-xlib
554
555                 # don't specify -no-gif because there is no way to override it later
556                 #-no-gif
557
558                 # always enable glib event loop support
559                 -glib
560
561                 # disable everything to prevent automagic deps (part 2)
562                 -no-pulseaudio -no-alsa
563                 $([[ ${QT5_MINOR_VERSION} -ge 7 ]] && echo -no-gtk || echo -no-gtkstyle)
564
565                 # exclude examples and tests from default build
566                 -nomake examples
567                 -nomake tests
568                 -no-compile-examples
569
570                 # disable rpath on non-prefix (bugs 380415 and 417169)
571                 $(usex prefix '' -no-rpath)
572
573                 # print verbose information about each configure test
574                 -verbose
575
576                 # doesn't actually matter since we override CXXFLAGS
577                 #-no-optimized-qmake
578
579                 # obsolete flag, does nothing
580                 #-nis
581
582                 # always enable iconv support
583                 -iconv
584
585                 # disable everything to prevent automagic deps (part 3)
586                 -no-cups -no-evdev
587                 $([[ ${QT5_MINOR_VERSION} -ge 5 ]] && echo -no-tslib)
588                 -no-icu -no-fontconfig
589                 -no-dbus
590
591                 # don't strip
592                 -no-strip
593
594                 # precompiled headers are not that useful for us
595                 # and cause problems on hardened, so turn them off
596                 -no-pch
597
598                 # reduced relocations cause major breakage on at least arm and ppc, so
599                 # don't specify anything and let the configure figure out if they are
600                 # supported; see also https://bugreports.qt.io/browse/QTBUG-36129
601                 #-reduce-relocations
602
603                 # let configure automatically detect if GNU gold is available
604                 #-use-gold-linker
605
606                 # disable all platform plugins by default, override in qtgui
607                 -no-xcb -no-eglfs -no-kms -no-directfb -no-linuxfb
608                 $([[ ${QT5_MINOR_VERSION} -ge 6 ]] && echo -no-mirclient)
609
610                 # disable undocumented X11-related flags, override in qtgui
611                 # (not shown in ./configure -help output)
612                 -no-xkb -no-xrender
613
614                 # disable obsolete/unused X11-related flags
615                 # (not shown in ./configure -help output)
616                 -no-mitshm -no-xcursor -no-xfixes -no-xinerama -no-xinput
617                 -no-xrandr -no-xshape -no-xsync -no-xvideo
618
619                 # always enable session management support: it doesn't need extra deps
620                 # at configure time and turning it off is dangerous, see bug 518262
621                 -sm
622
623                 # typedef qreal to double (warning: changing this flag breaks the ABI)
624                 -qreal double
625
626                 # disable OpenGL and EGL support by default, override in qtgui,
627                 # qtopengl, qtprintsupport and qtwidgets
628                 -no-opengl -no-egl
629
630                 # disable libinput-based generic plugin by default, override in qtgui
631                 $([[ ${QT5_MINOR_VERSION} -ge 5 ]] && echo -no-libinput)
632
633                 # disable gstreamer by default, override in qtmultimedia
634                 $([[ ${QT5_MINOR_VERSION} -ge 5 ]] && echo -no-gstreamer)
635
636                 # use upstream default
637                 #-no-system-proxies
638
639                 # do not build with -Werror
640                 -no-warnings-are-errors
641
642                 # module-specific options
643                 "${myconf[@]}"
644         )
645
646         pushd "${QT5_BUILD_DIR}" >/dev/null || die
647
648         einfo "Configuring with: ${conf[@]}"
649         "${S}"/configure "${conf[@]}" || die "configure failed"
650
651         popd >/dev/null || die
652 }
653
654 # @FUNCTION: qt5_qmake
655 # @INTERNAL
656 # @DESCRIPTION:
657 # Helper function that runs qmake in the current target subdir.
658 # Intended to be called by qt5_foreach_target_subdir().
659 qt5_qmake() {
660         local projectdir=${PWD/#${QT5_BUILD_DIR}/${S}}
661         local qmakepath=
662         if [[ ${QT5_MODULE} == qtbase ]]; then
663                 qmakepath=${QT5_BUILD_DIR}/bin
664         else
665                 qmakepath=${QT5_BINDIR}
666         fi
667
668         "${qmakepath}"/qmake \
669                 "${projectdir}" \
670                 CONFIG+=$(usex debug debug release) \
671                 CONFIG-=$(usex debug release debug) \
672                 QMAKE_AR="$(tc-getAR) cqs" \
673                 QMAKE_CC="$(tc-getCC)" \
674                 QMAKE_LINK_C="$(tc-getCC)" \
675                 QMAKE_LINK_C_SHLIB="$(tc-getCC)" \
676                 QMAKE_CXX="$(tc-getCXX)" \
677                 QMAKE_LINK="$(tc-getCXX)" \
678                 QMAKE_LINK_SHLIB="$(tc-getCXX)" \
679                 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
680                 QMAKE_RANLIB= \
681                 QMAKE_STRIP="$(tc-getSTRIP)" \
682                 QMAKE_CFLAGS="${CFLAGS}" \
683                 QMAKE_CFLAGS_RELEASE= \
684                 QMAKE_CFLAGS_DEBUG= \
685                 QMAKE_CXXFLAGS="${CXXFLAGS}" \
686                 QMAKE_CXXFLAGS_RELEASE= \
687                 QMAKE_CXXFLAGS_DEBUG= \
688                 QMAKE_LFLAGS="${LDFLAGS}" \
689                 QMAKE_LFLAGS_RELEASE= \
690                 QMAKE_LFLAGS_DEBUG= \
691                 "${myqmakeargs[@]}" \
692                 || die "qmake failed (${projectdir#${S}/})"
693 }
694
695 # @FUNCTION: qt5_install_module_qconfigs
696 # @INTERNAL
697 # @DESCRIPTION:
698 # Creates and installs gentoo-specific ${PN}-qconfig.{h,pri} files.
699 qt5_install_module_qconfigs() {
700         local x qconfig_add= qconfig_remove=
701
702         > "${T}"/${PN}-qconfig.h
703         > "${T}"/${PN}-qconfig.pri
704
705         # generate qconfig_{add,remove} and ${PN}-qconfig.h
706         for x in "${QT5_GENTOO_CONFIG[@]}"; do
707                 local flag=${x%%:*}
708                 x=${x#${flag}:}
709                 local feature=${x%%:*}
710                 x=${x#${feature}:}
711                 local macro=${x}
712                 macro=$(tr 'a-z-' 'A-Z_' <<< "${macro}")
713
714                 if [[ -z ${flag} ]] || { [[ ${flag} != '!' ]] && use ${flag}; }; then
715                         [[ -n ${feature} ]] && qconfig_add+=" ${feature}"
716                         [[ -n ${macro} ]] && echo "#define QT_${macro}" >> "${T}"/${PN}-qconfig.h
717                 else
718                         [[ -n ${feature} ]] && qconfig_remove+=" ${feature}"
719                         [[ -n ${macro} ]] && echo "#define QT_NO_${macro}" >> "${T}"/${PN}-qconfig.h
720                 fi
721         done
722
723         # install ${PN}-qconfig.h
724         [[ -s ${T}/${PN}-qconfig.h ]] && (
725                 insinto "${QT5_HEADERDIR#${EPREFIX}}"/Gentoo
726                 doins "${T}"/${PN}-qconfig.h
727         )
728
729         # generate and install ${PN}-qconfig.pri
730         [[ -n ${qconfig_add} ]] && echo "QCONFIG_ADD=${qconfig_add}" >> "${T}"/${PN}-qconfig.pri
731         [[ -n ${qconfig_remove} ]] && echo "QCONFIG_REMOVE=${qconfig_remove}" >> "${T}"/${PN}-qconfig.pri
732         [[ -s ${T}/${PN}-qconfig.pri ]] && (
733                 insinto "${QT5_ARCHDATADIR#${EPREFIX}}"/mkspecs/gentoo
734                 doins "${T}"/${PN}-qconfig.pri
735         )
736 }
737
738 # @FUNCTION: qt5_regenerate_global_qconfigs
739 # @INTERNAL
740 # @DESCRIPTION:
741 # Generates Gentoo-specific qconfig.{h,pri} according to the build configuration.
742 # Don't call die here because dying in pkg_post{inst,rm} only makes things worse.
743 qt5_regenerate_global_qconfigs() {
744         einfo "Regenerating gentoo-qconfig.h"
745
746         find "${ROOT%/}${QT5_HEADERDIR}"/Gentoo \
747                 -name '*-qconfig.h' -a \! -name 'gentoo-qconfig.h' -type f \
748                 -execdir cat '{}' + | sort -u > "${T}"/gentoo-qconfig.h
749
750         [[ -s ${T}/gentoo-qconfig.h ]] || ewarn "Generated gentoo-qconfig.h is empty"
751         mv -f "${T}"/gentoo-qconfig.h "${ROOT%/}${QT5_HEADERDIR}"/Gentoo/gentoo-qconfig.h \
752                 || eerror "Failed to install new gentoo-qconfig.h"
753
754         einfo "Updating QT_CONFIG in qconfig.pri"
755
756         local qconfig_pri=${ROOT%/}${QT5_ARCHDATADIR}/mkspecs/qconfig.pri
757         if [[ -f ${qconfig_pri} ]]; then
758                 local x qconfig_add= qconfig_remove=
759                 local qt_config=$(sed -n 's/^QT_CONFIG\s*+=\s*//p' "${qconfig_pri}")
760                 local new_qt_config=
761
762                 # generate list of QT_CONFIG entries from the existing list,
763                 # appending QCONFIG_ADD and excluding QCONFIG_REMOVE
764                 eshopts_push -s nullglob
765                 for x in "${ROOT%/}${QT5_ARCHDATADIR}"/mkspecs/gentoo/*-qconfig.pri; do
766                         qconfig_add+=" $(sed -n 's/^QCONFIG_ADD=\s*//p' "${x}")"
767                         qconfig_remove+=" $(sed -n 's/^QCONFIG_REMOVE=\s*//p' "${x}")"
768                 done
769                 eshopts_pop
770                 for x in ${qt_config} ${qconfig_add}; do
771                         if ! has "${x}" ${new_qt_config} ${qconfig_remove}; then
772                                 new_qt_config+=" ${x}"
773                         fi
774                 done
775
776                 # now replace the existing QT_CONFIG with the generated list
777                 sed -i -e "s/^QT_CONFIG\s*+=.*/QT_CONFIG +=${new_qt_config}/" \
778                         "${qconfig_pri}" || eerror "Failed to sed QT_CONFIG in ${qconfig_pri}"
779         else
780                 ewarn "${qconfig_pri} does not exist or is not a regular file"
781         fi
782 }