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