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