qt5-build.eclass 24 KB

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