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