qt4-build-multilib.eclass 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: qt4-build-multilib.eclass
  4. # @MAINTAINER:
  5. # qt@gentoo.org
  6. # @AUTHOR:
  7. # Davide Pesavento <pesa@gentoo.org>
  8. # @BLURB: Eclass for Qt4 split ebuilds with multilib support.
  9. # @DESCRIPTION:
  10. # This eclass contains various functions that are used when building Qt4.
  11. # Requires EAPI 5.
  12. case ${EAPI} in
  13. 5) : ;;
  14. *) die "qt4-build-multilib.eclass: unsupported EAPI=${EAPI:-0}" ;;
  15. esac
  16. inherit eutils flag-o-matic multilib multilib-minimal toolchain-funcs
  17. HOMEPAGE="https://www.qt.io/"
  18. LICENSE="|| ( LGPL-2.1 LGPL-3 GPL-3 ) FDL-1.3"
  19. SLOT="4"
  20. case ${PV} in
  21. 4.?.9999)
  22. # git stable branch
  23. QT4_BUILD_TYPE="live"
  24. EGIT_BRANCH=${PV%.9999}
  25. ;;
  26. *)
  27. # official stable release
  28. QT4_BUILD_TYPE="release"
  29. MY_P=qt-everywhere-opensource-src-${PV/_/-}
  30. SRC_URI="http://download.qt.io/official_releases/qt/${PV%.*}/${PV}/${MY_P}.tar.gz"
  31. S=${WORKDIR}/${MY_P}
  32. ;;
  33. esac
  34. EGIT_REPO_URI=(
  35. "git://code.qt.io/qt/qt.git"
  36. "https://code.qt.io/git/qt/qt.git"
  37. "https://github.com/qtproject/qt.git"
  38. )
  39. [[ ${QT4_BUILD_TYPE} == live ]] && inherit git-r3
  40. if [[ ${PN} != qttranslations ]]; then
  41. IUSE="aqua debug pch"
  42. [[ ${PN} != qtxmlpatterns ]] && IUSE+=" +exceptions"
  43. fi
  44. DEPEND="
  45. dev-lang/perl
  46. virtual/pkgconfig[${MULTILIB_USEDEP}]
  47. "
  48. RDEPEND="
  49. dev-qt/qtchooser
  50. abi_x86_32? ( !app-emulation/emul-linux-x86-qtlibs[-abi_x86_32(-)] )
  51. "
  52. # src_{configure,compile,test,install} are inherited from multilib-minimal
  53. EXPORT_FUNCTIONS src_unpack src_prepare pkg_postinst pkg_postrm
  54. multilib_src_configure() { qt4_multilib_src_configure; }
  55. multilib_src_compile() { qt4_multilib_src_compile; }
  56. multilib_src_test() { qt4_multilib_src_test; }
  57. multilib_src_install() { qt4_multilib_src_install; }
  58. multilib_src_install_all() { qt4_multilib_src_install_all; }
  59. # @ECLASS-VARIABLE: PATCHES
  60. # @DEFAULT_UNSET
  61. # @DESCRIPTION:
  62. # Array variable containing all the patches to be applied. This variable
  63. # is expected to be defined in the global scope of ebuilds. Make sure to
  64. # specify the full path. This variable is used in src_prepare phase.
  65. #
  66. # Example:
  67. # @CODE
  68. # PATCHES=(
  69. # "${FILESDIR}/mypatch.patch"
  70. # "${FILESDIR}/mypatch2.patch"
  71. # )
  72. # @CODE
  73. # @ECLASS-VARIABLE: QT4_TARGET_DIRECTORIES
  74. # @DEFAULT_UNSET
  75. # @DESCRIPTION:
  76. # Space-separated list of directories that will be configured,
  77. # compiled, and installed. All paths must be relative to ${S}.
  78. # @ECLASS-VARIABLE: QCONFIG_ADD
  79. # @DEFAULT_UNSET
  80. # @DESCRIPTION:
  81. # List of options that must be added to QT_CONFIG in qconfig.pri
  82. # @ECLASS-VARIABLE: QCONFIG_REMOVE
  83. # @DEFAULT_UNSET
  84. # @DESCRIPTION:
  85. # List of options that must be removed from QT_CONFIG in qconfig.pri
  86. # @ECLASS-VARIABLE: QCONFIG_DEFINE
  87. # @DEFAULT_UNSET
  88. # @DESCRIPTION:
  89. # List of macros that must be defined in QtCore/qconfig.h
  90. ###### Phase functions ######
  91. # @FUNCTION: qt4-build-multilib_src_unpack
  92. # @DESCRIPTION:
  93. # Unpacks the sources.
  94. qt4-build-multilib_src_unpack() {
  95. if tc-is-gcc; then
  96. if [[ $(gcc-major-version) -lt 4 ]] || \
  97. [[ $(gcc-major-version) -eq 4 && $(gcc-minor-version) -lt 4 ]]; then
  98. ewarn
  99. ewarn "Using a GCC version lower than 4.4 is not supported"
  100. ewarn
  101. fi
  102. fi
  103. if [[ ${PN} == qtwebkit ]]; then
  104. eshopts_push -s extglob
  105. if is-flagq '-g?(gdb)?([1-9])'; then
  106. ewarn
  107. ewarn "You have enabled debug info (probably have -g or -ggdb in your CFLAGS/CXXFLAGS)."
  108. ewarn "You may experience really long compilation times and/or increased memory usage."
  109. ewarn "If compilation fails, please try removing -g/-ggdb before reporting a bug."
  110. ewarn "For more info check out https://bugs.gentoo.org/307861"
  111. ewarn
  112. fi
  113. eshopts_pop
  114. fi
  115. case ${QT4_BUILD_TYPE} in
  116. live) git-r3_src_unpack ;;
  117. release) default ;;
  118. esac
  119. }
  120. # @FUNCTION: qt4-build-multilib_src_prepare
  121. # @DESCRIPTION:
  122. # Prepare the sources before the configure phase. Strip CFLAGS if necessary, and fix
  123. # the build system in order to respect CFLAGS/CXXFLAGS/LDFLAGS specified in make.conf.
  124. qt4-build-multilib_src_prepare() {
  125. if [[ ${PN} != qtcore ]]; then
  126. # avoid unnecessary qmake recompilations
  127. sed -i -e 's/^if true;/if false;/' configure \
  128. || die "sed failed (skip qmake bootstrap)"
  129. fi
  130. # skip X11 tests in non-gui packages to avoid spurious dependencies
  131. if has ${PN} qtbearer qtcore qtdbus qtscript qtsql qttest qttranslations qtxmlpatterns; then
  132. sed -i -e '/^if.*PLATFORM_X11.*CFG_GUI/,/^fi$/d' configure \
  133. || die "sed failed (skip X11 tests)"
  134. fi
  135. # Qt4 is not safe to build with C++14 (the new gcc-6 default).
  136. # Upstream has addressed this for Qt5, but while we continue to
  137. # support Qt4, we need to ensure everything is built in C++98 mode.
  138. # See bugs 582522, 582618, 583662, 583744.
  139. append-cxxflags -std=gnu++98
  140. if [[ ${PN} == qtcore ]]; then
  141. # Bug 373061
  142. # qmake bus errors with -O2 or -O3 but -O1 works
  143. if [[ ${CHOST} == *86*-apple-darwin* ]]; then
  144. replace-flags -O[23] -O1
  145. fi
  146. # Bug 503500
  147. # undefined reference with -Os and --as-needed
  148. if use x86 || use_if_iuse abi_x86_32; then
  149. replace-flags -Os -O2
  150. fi
  151. fi
  152. if [[ ${PN} == qtdeclarative ]]; then
  153. # Bug 551560
  154. # gcc-4.8 ICE with -Os, fixed in 4.9
  155. if use x86 && tc-is-gcc && [[ $(gcc-version) == 4.8 ]]; then
  156. replace-flags -Os -O2
  157. fi
  158. fi
  159. if [[ ${PN} == qtwebkit ]]; then
  160. # Bug 550780
  161. # various ICEs with graphite-related flags, gcc-5 works
  162. if [[ $(gcc-major-version) -lt 5 ]]; then
  163. filter-flags -fgraphite-identity -floop-strip-mine
  164. fi
  165. fi
  166. # Bug 261632
  167. if use ppc64; then
  168. append-flags -mminimal-toc
  169. fi
  170. # Teach configure about gcc-6 and later
  171. sed -i -e 's:5\*|:[5-9]*|:' \
  172. configure || die "sed gcc version failed"
  173. # Read also AR from the environment
  174. sed -i -e 's/^SYSTEM_VARIABLES="/&AR /' \
  175. configure || die "sed SYSTEM_VARIABLES failed"
  176. # Reset QMAKE_*FLAGS_{RELEASE,DEBUG} variables,
  177. # or they will override the user's flags (via .qmake.cache)
  178. sed -i -e '/^SYSTEM_VARIABLES=/ i \
  179. QMakeVar set QMAKE_CFLAGS_RELEASE\
  180. QMakeVar set QMAKE_CFLAGS_DEBUG\
  181. QMakeVar set QMAKE_CXXFLAGS_RELEASE\
  182. QMakeVar set QMAKE_CXXFLAGS_DEBUG\
  183. QMakeVar set QMAKE_LFLAGS_RELEASE\
  184. QMakeVar set QMAKE_LFLAGS_DEBUG\n' \
  185. configure || die "sed QMAKE_*FLAGS_{RELEASE,DEBUG} failed"
  186. # Drop -nocache from qmake invocation in all configure tests, to ensure that the
  187. # correct toolchain and build flags are picked up from config.tests/.qmake.cache
  188. find config.tests/unix -name '*.test' -type f -execdir \
  189. sed -i -e '/bin\/qmake/s/-nocache//' '{}' + || die "sed -nocache failed"
  190. # compile.test needs additional patching so that it doesn't create another cache file
  191. # inside the test subdir, which would incorrectly override config.tests/.qmake.cache
  192. sed -i -e '/echo.*QT_BUILD_TREE.*\.qmake\.cache/d' \
  193. -e '/bin\/qmake/s/ "$SRCDIR/ "QT_BUILD_TREE=$OUTDIR"&/' \
  194. config.tests/unix/compile.test || die "sed compile.test failed"
  195. # Delete references to the obsolete /usr/X11R6 directory
  196. # On prefix, this also prevents looking at non-prefix stuff
  197. sed -i -re '/^QMAKE_(LIB|INC)DIR(_X11|_OPENGL|)\s+/ s/=.*/=/' \
  198. mkspecs/common/linux.conf \
  199. mkspecs/$(qt4_get_mkspec)/qmake.conf \
  200. || die "sed QMAKE_(LIB|INC)DIR failed"
  201. if use_if_iuse aqua; then
  202. sed -i \
  203. -e '/^CONFIG/s:app_bundle::' \
  204. -e '/^CONFIG/s:plugin_no_soname:plugin_with_soname absolute_library_soname:' \
  205. mkspecs/$(qt4_get_mkspec)/qmake.conf \
  206. || die "sed failed (aqua)"
  207. # we are crazy and build cocoa + qt3support
  208. if { ! in_iuse qt3support || use qt3support; } && [[ ${CHOST##*-darwin} -ge 9 ]]; then
  209. sed -i -e "/case \"\$PLATFORM,\$CFG_MAC_COCOA\" in/,/;;/ s|CFG_QT3SUPPORT=\"no\"|CFG_QT3SUPPORT=\"yes\"|" \
  210. configure || die "sed failed (cocoa + qt3support)"
  211. fi
  212. fi
  213. if [[ ${CHOST} == *-darwin* ]]; then
  214. # Set FLAGS and remove -arch, since our gcc-apple is multilib crippled (by design)
  215. sed -i \
  216. -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
  217. -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
  218. -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=-headerpad_max_install_names ${LDFLAGS}:" \
  219. -e "s:-arch\s\w*::g" \
  220. mkspecs/common/g++-macx.conf \
  221. || die "sed g++-macx.conf failed"
  222. # Fix configure's -arch settings that appear in qmake/Makefile and also
  223. # fix arch handling (automagically duplicates our -arch arg and breaks
  224. # pch). Additionally disable Xarch support.
  225. sed -i \
  226. -e "s:-arch i386::" \
  227. -e "s:-arch ppc::" \
  228. -e "s:-arch x86_64::" \
  229. -e "s:-arch ppc64::" \
  230. -e "s:-arch \$i::" \
  231. -e "/if \[ ! -z \"\$NATIVE_64_ARCH\" \]; then/,/fi/ d" \
  232. -e "s:CFG_MAC_XARCH=yes:CFG_MAC_XARCH=no:g" \
  233. -e "s:-Xarch_x86_64::g" \
  234. -e "s:-Xarch_ppc64::g" \
  235. configure mkspecs/common/gcc-base-macx.conf mkspecs/common/g++-macx.conf \
  236. || die "sed -arch/-Xarch failed"
  237. # On Snow Leopard don't fall back to 10.5 deployment target.
  238. if [[ ${CHOST} == *-apple-darwin10 ]]; then
  239. sed -i \
  240. -e "s:QMakeVar set QMAKE_MACOSX_DEPLOYMENT_TARGET.*:QMakeVar set QMAKE_MACOSX_DEPLOYMENT_TARGET 10.6:g" \
  241. -e "s:-mmacosx-version-min=10.[0-9]:-mmacosx-version-min=10.6:g" \
  242. configure mkspecs/common/g++-macx.conf \
  243. || die "sed deployment target failed"
  244. fi
  245. fi
  246. if [[ ${CHOST} == *-solaris* ]]; then
  247. sed -i -e '/^QMAKE_LFLAGS_THREAD/a QMAKE_LFLAGS_DYNAMIC_LIST = -Wl,--dynamic-list,' \
  248. mkspecs/$(qt4_get_mkspec)/qmake.conf || die
  249. fi
  250. # apply patches
  251. [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
  252. epatch_user
  253. }
  254. qt4_multilib_src_configure() {
  255. qt4_prepare_env
  256. qt4_symlink_tools_to_build_dir
  257. # toolchain setup ('local -x' because of bug 532510)
  258. local -x \
  259. AR="$(tc-getAR) cqs" \
  260. CC=$(tc-getCC) \
  261. CXX=$(tc-getCXX) \
  262. LD=$(tc-getCXX) \
  263. MAKEFLAGS=${MAKEOPTS} \
  264. OBJCOPY=$(tc-getOBJCOPY) \
  265. OBJDUMP=$(tc-getOBJDUMP) \
  266. STRIP=$(tc-getSTRIP)
  267. # convert tc-arch to the values supported by Qt
  268. local arch=$(tc-arch)
  269. case ${arch} in
  270. amd64|x64-*) arch=x86_64 ;;
  271. arm64|hppa) arch=generic ;;
  272. ppc*-macos) arch=ppc ;;
  273. ppc*) arch=powerpc ;;
  274. sparc*) arch=sparc ;;
  275. x86-macos) arch=x86 ;;
  276. x86*) arch=i386 ;;
  277. esac
  278. # configure arguments
  279. local conf=(
  280. # installation paths
  281. -prefix "${QT4_PREFIX}"
  282. -bindir "${QT4_BINDIR}"
  283. -libdir "${QT4_LIBDIR}"
  284. -docdir "${QT4_DOCDIR}"
  285. -headerdir "${QT4_HEADERDIR}"
  286. -plugindir "${QT4_PLUGINDIR}"
  287. -importdir "${QT4_IMPORTDIR}"
  288. -datadir "${QT4_DATADIR}"
  289. -translationdir "${QT4_TRANSLATIONDIR}"
  290. -sysconfdir "${QT4_SYSCONFDIR}"
  291. -examplesdir "${QT4_EXAMPLESDIR}"
  292. -demosdir "${QT4_DEMOSDIR}"
  293. # debug/release
  294. $(use_if_iuse debug && echo -debug || echo -release)
  295. -no-separate-debug-info
  296. # licensing stuff
  297. -opensource -confirm-license
  298. # build shared libraries
  299. -shared
  300. # skip recursive processing of .pro files at the end of configure
  301. # (we run qmake by ourselves), thus saving quite a bit of time
  302. -dont-process
  303. # always enable large file support
  304. -largefile
  305. # exceptions USE flag
  306. $(in_iuse exceptions && qt_use exceptions || echo -exceptions)
  307. # build STL support
  308. -stl
  309. # architecture/platform (mkspec)
  310. -arch ${arch}
  311. -platform $(qt4_get_mkspec)
  312. # instruction set support
  313. $(is-flagq -mno-mmx && echo -no-mmx)
  314. $(is-flagq -mno-3dnow && echo -no-3dnow)
  315. $(is-flagq -mno-sse && echo -no-sse)
  316. $(is-flagq -mno-sse2 && echo -no-sse2)
  317. $(is-flagq -mno-sse3 && echo -no-sse3)
  318. $(is-flagq -mno-ssse3 && echo -no-ssse3)
  319. $(is-flagq -mno-sse4.1 && echo -no-sse4.1)
  320. $(is-flagq -mno-sse4.2 && echo -no-sse4.2)
  321. $(is-flagq -mno-avx && echo -no-avx)
  322. $(is-flagq -mfpu=* && ! is-flagq -mfpu=*neon* && echo -no-neon)
  323. # bug 367045
  324. $([[ ${CHOST} == *86*-apple-darwin* ]] && echo -no-ssse3)
  325. # prefer system libraries
  326. -system-zlib
  327. # exclude examples and demos from default build
  328. -nomake examples
  329. -nomake demos
  330. # disable rpath on non-prefix (bugs 380415 and 417169)
  331. $(usex prefix '' -no-rpath)
  332. # print verbose information about each configure test
  333. -verbose
  334. # precompiled headers don't work on hardened, where the flag is masked
  335. $(in_iuse pch && qt_use pch || echo -no-pch)
  336. # enable linker optimizations to reduce relocations, except on Solaris
  337. # where this flag seems to introduce major breakage to applications,
  338. # mostly to be seen as a core dump with the message:
  339. # "QPixmap: Must construct a QApplication before a QPaintDevice"
  340. $([[ ${CHOST} != *-solaris* ]] && echo -reduce-relocations)
  341. )
  342. if use_if_iuse aqua; then
  343. if [[ ${CHOST##*-darwin} -ge 9 ]]; then
  344. conf+=(
  345. # on (snow) leopard use the new (frameworked) cocoa code
  346. -cocoa -framework
  347. # add hint for the framework location
  348. -F"${QT4_LIBDIR}"
  349. )
  350. else
  351. conf+=(-no-framework)
  352. fi
  353. fi
  354. conf+=(
  355. # module-specific options
  356. "${myconf[@]}"
  357. )
  358. einfo "Configuring with: ${conf[@]}"
  359. "${S}"/configure "${conf[@]}" || die "configure failed"
  360. # configure is stupid and assigns QMAKE_LFLAGS twice,
  361. # thus the previous -rpath-link flag gets overwritten
  362. # and some packages (e.g. qthelp) fail to link
  363. sed -i -e '/^QMAKE_LFLAGS =/ s:$: $$QMAKE_LFLAGS:' \
  364. .qmake.cache || die "sed .qmake.cache failed"
  365. qt4_qmake
  366. qt4_foreach_target_subdir qt4_qmake
  367. }
  368. qt4_multilib_src_compile() {
  369. qt4_prepare_env
  370. qt4_foreach_target_subdir emake
  371. }
  372. qt4_multilib_src_test() {
  373. qt4_prepare_env
  374. qt4_foreach_target_subdir emake -j1 check
  375. }
  376. qt4_multilib_src_install() {
  377. qt4_prepare_env
  378. qt4_foreach_target_subdir emake INSTALL_ROOT="${D}" install
  379. if [[ ${PN} == qtcore ]]; then
  380. set -- emake INSTALL_ROOT="${D}" install_{mkspecs,qmake}
  381. einfo "Running $*"
  382. "$@"
  383. # install env.d file
  384. cat > "${T}/44qt4-${CHOST}" <<-_EOF_
  385. LDPATH="${QT4_LIBDIR}"
  386. _EOF_
  387. doenvd "${T}/44qt4-${CHOST}"
  388. # install qtchooser configuration file
  389. cat > "${T}/qt4-${CHOST}.conf" <<-_EOF_
  390. ${QT4_BINDIR}
  391. ${QT4_LIBDIR}
  392. _EOF_
  393. (
  394. insinto /etc/xdg/qtchooser
  395. doins "${T}/qt4-${CHOST}.conf"
  396. )
  397. if multilib_is_native_abi; then
  398. # convenience symlinks
  399. dosym qt4-"${CHOST}".conf /etc/xdg/qtchooser/4.conf
  400. dosym qt4-"${CHOST}".conf /etc/xdg/qtchooser/qt4.conf
  401. # TODO bug 522646: write an eselect module to manage default.conf
  402. dosym qt4.conf /etc/xdg/qtchooser/default.conf
  403. fi
  404. fi
  405. # move pkgconfig directory to the correct location
  406. if [[ -d ${D}${QT4_LIBDIR}/pkgconfig ]]; then
  407. mv "${D}${QT4_LIBDIR}"/pkgconfig "${ED}usr/$(get_libdir)" || die
  408. fi
  409. qt4_install_module_qconfigs
  410. qt4_symlink_framework_headers
  411. }
  412. qt4_multilib_src_install_all() {
  413. if [[ ${PN} == qtcore ]]; then
  414. # include gentoo-qconfig.h at the beginning of Qt{,Core}/qconfig.h
  415. if use aqua && [[ ${CHOST#*-darwin} -ge 9 ]]; then
  416. sed -i -e '1i #include <QtCore/Gentoo/gentoo-qconfig.h>\n' \
  417. "${D}${QT4_LIBDIR}"/QtCore.framework/Headers/qconfig.h \
  418. || die "sed failed (qconfig.h)"
  419. dosym "${QT4_HEADERDIR#${EPREFIX}}"/Gentoo \
  420. "${QT4_LIBDIR#${EPREFIX}}"/QtCore.framework/Headers/Gentoo
  421. else
  422. sed -i -e '1i #include <Gentoo/gentoo-qconfig.h>\n' \
  423. "${D}${QT4_HEADERDIR}"/Qt{,Core}/qconfig.h \
  424. || die "sed failed (qconfig.h)"
  425. fi
  426. dodir "${QT4_DATADIR#${EPREFIX}}"/mkspecs/gentoo
  427. mv "${D}${QT4_DATADIR}"/mkspecs/{qconfig.pri,gentoo/} || die
  428. fi
  429. # install private headers of a few modules
  430. if has ${PN} qtcore qtdeclarative qtgui qtscript; then
  431. local moduledir=${PN#qt}
  432. local modulename=Qt$(tr 'a-z' 'A-Z' <<< ${moduledir:0:1})${moduledir:1}
  433. [[ ${moduledir} == core ]] && moduledir=corelib
  434. einfo "Installing private headers into ${QT4_HEADERDIR}/${modulename}/private"
  435. insinto "${QT4_HEADERDIR#${EPREFIX}}"/${modulename}/private
  436. find "${S}"/src/${moduledir} -type f -name '*_p.h' -exec doins '{}' + || die
  437. fi
  438. prune_libtool_files
  439. }
  440. # @FUNCTION: qt4-build-multilib_pkg_postinst
  441. # @DESCRIPTION:
  442. # Regenerate configuration after installation or upgrade/downgrade.
  443. qt4-build-multilib_pkg_postinst() {
  444. qt4_regenerate_global_qconfigs
  445. }
  446. # @FUNCTION: qt4-build-multilib_pkg_postrm
  447. # @DESCRIPTION:
  448. # Regenerate configuration when a module is completely removed.
  449. qt4-build-multilib_pkg_postrm() {
  450. qt4_regenerate_global_qconfigs
  451. }
  452. ###### Public helpers ######
  453. # @FUNCTION: qt_use
  454. # @USAGE: <flag> [feature] [enableval]
  455. # @DESCRIPTION:
  456. # <flag> is the name of a flag in IUSE.
  457. #
  458. # Outputs "-${enableval}-${feature}" if <flag> is enabled, "-no-${feature}"
  459. # otherwise. If [feature] is not specified, <flag> is used in its place.
  460. # If [enableval] is not specified, the "-${enableval}" prefix is omitted.
  461. qt_use() {
  462. [[ $# -ge 1 ]] || die "${FUNCNAME}() requires at least one argument"
  463. usex "$1" "${3:+-$3}-${2:-$1}" "-no-${2:-$1}"
  464. }
  465. # @FUNCTION: qt_native_use
  466. # @USAGE: <flag> [feature] [enableval]
  467. # @DESCRIPTION:
  468. # <flag> is the name of a flag in IUSE.
  469. #
  470. # Outputs "-${enableval}-${feature}" if <flag> is enabled and we are currently
  471. # building for the native ABI, "-no-${feature}" otherwise. If [feature] is not
  472. # specified, <flag> is used in its place. If [enableval] is not specified,
  473. # the "-${enableval}" prefix is omitted.
  474. qt_native_use() {
  475. [[ $# -ge 1 ]] || die "${FUNCNAME}() requires at least one argument"
  476. multilib_is_native_abi && qt_use "$@" || echo "-no-${2:-$1}"
  477. }
  478. ###### Internal functions ######
  479. # @FUNCTION: qt4_prepare_env
  480. # @INTERNAL
  481. # @DESCRIPTION:
  482. # Prepares the environment for building Qt.
  483. qt4_prepare_env() {
  484. # setup installation directories
  485. # note: keep paths in sync with qmake-utils.eclass
  486. QT4_PREFIX=${EPREFIX}/usr
  487. QT4_HEADERDIR=${QT4_PREFIX}/include/qt4
  488. QT4_LIBDIR=${QT4_PREFIX}/$(get_libdir)/qt4
  489. QT4_BINDIR=${QT4_LIBDIR}/bin
  490. QT4_PLUGINDIR=${QT4_LIBDIR}/plugins
  491. QT4_IMPORTDIR=${QT4_LIBDIR}/imports
  492. QT4_DATADIR=${QT4_PREFIX}/share/qt4
  493. QT4_DOCDIR=${QT4_PREFIX}/share/doc/qt-${PV}
  494. QT4_TRANSLATIONDIR=${QT4_DATADIR}/translations
  495. QT4_EXAMPLESDIR=${QT4_DATADIR}/examples
  496. QT4_DEMOSDIR=${QT4_DATADIR}/demos
  497. QT4_SYSCONFDIR=${EPREFIX}/etc/qt4
  498. # are these still needed?
  499. QMAKE_LIBDIR_QT=${QT4_LIBDIR}
  500. export XDG_CONFIG_HOME="${T}"
  501. # can confuse qmake if set (bug 583352)
  502. unset QMAKESPEC
  503. }
  504. # @FUNCTION: qt4_foreach_target_subdir
  505. # @INTERNAL
  506. # @DESCRIPTION:
  507. # Executes the given command inside each directory listed in QT4_TARGET_DIRECTORIES.
  508. qt4_foreach_target_subdir() {
  509. local ret=0 subdir=
  510. for subdir in ${QT4_TARGET_DIRECTORIES}; do
  511. mkdir -p "${subdir}" || die
  512. pushd "${subdir}" >/dev/null || die
  513. einfo "Running $* ${subdir:+in ${subdir}}"
  514. "$@"
  515. ((ret+=$?))
  516. popd >/dev/null || die
  517. done
  518. return ${ret}
  519. }
  520. # @FUNCTION: qt4_symlink_tools_to_build_dir
  521. # @INTERNAL
  522. # @DESCRIPTION:
  523. # Symlinks qtcore tools to BUILD_DIR,
  524. # so that they can be used when building other modules.
  525. qt4_symlink_tools_to_build_dir() {
  526. local tool= tools=()
  527. if [[ ${PN} != qtcore ]]; then
  528. tools+=(qmake moc rcc uic)
  529. fi
  530. mkdir -p "${BUILD_DIR}"/bin || die
  531. pushd "${BUILD_DIR}"/bin >/dev/null || die
  532. for tool in "${tools[@]}"; do
  533. [[ -e ${QT4_BINDIR}/${tool} ]] || continue
  534. ln -s "${QT4_BINDIR}/${tool}" . || die "failed to symlink ${tool}"
  535. done
  536. popd >/dev/null || die
  537. }
  538. # @FUNCTION: qt4_qmake
  539. # @INTERNAL
  540. # @DESCRIPTION:
  541. # Helper function that runs qmake in the current target subdir.
  542. # Intended to be called by qt4_foreach_target_subdir().
  543. qt4_qmake() {
  544. local projectdir=${PWD/#${BUILD_DIR}/${S}}
  545. "${BUILD_DIR}"/bin/qmake \
  546. "${projectdir}" \
  547. CONFIG+=nostrip \
  548. LIBS+=-L"${QT4_LIBDIR}" \
  549. "${myqmakeargs[@]}" \
  550. || die "qmake failed (${projectdir#${S}/})"
  551. }
  552. # @FUNCTION: qt4_install_module_qconfigs
  553. # @INTERNAL
  554. # @DESCRIPTION:
  555. # Creates and installs gentoo-specific ${PN}-qconfig.{h,pri} files.
  556. qt4_install_module_qconfigs() {
  557. local x
  558. if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} ]]; then
  559. for x in QCONFIG_ADD QCONFIG_REMOVE; do
  560. [[ -n ${!x} ]] && echo ${x}=${!x} >> "${BUILD_DIR}"/${PN}-qconfig.pri
  561. done
  562. insinto ${QT4_DATADIR#${EPREFIX}}/mkspecs/gentoo
  563. doins "${BUILD_DIR}"/${PN}-qconfig.pri
  564. fi
  565. if [[ -n ${QCONFIG_DEFINE} ]]; then
  566. for x in ${QCONFIG_DEFINE}; do
  567. echo "#define ${x}" >> "${BUILD_DIR}"/gentoo-${PN}-qconfig.h
  568. done
  569. insinto ${QT4_HEADERDIR#${EPREFIX}}/Gentoo
  570. doins "${BUILD_DIR}"/gentoo-${PN}-qconfig.h
  571. fi
  572. }
  573. # @FUNCTION: qt4_regenerate_global_qconfigs
  574. # @INTERNAL
  575. # @DESCRIPTION:
  576. # Generates Gentoo-specific qconfig.{h,pri} according to the build configuration.
  577. # Don't call die here because dying in pkg_post{inst,rm} only makes things worse.
  578. qt4_regenerate_global_qconfigs() {
  579. if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} || -n ${QCONFIG_DEFINE} || ${PN} == qtcore ]]; then
  580. local x qconfig_add qconfig_remove qconfig_new
  581. for x in "${ROOT}${QT4_DATADIR}"/mkspecs/gentoo/*-qconfig.pri; do
  582. [[ -f ${x} ]] || continue
  583. qconfig_add+=" $(sed -n 's/^QCONFIG_ADD=//p' "${x}")"
  584. qconfig_remove+=" $(sed -n 's/^QCONFIG_REMOVE=//p' "${x}")"
  585. done
  586. if [[ -e "${ROOT}${QT4_DATADIR}"/mkspecs/gentoo/qconfig.pri ]]; then
  587. # start with the qconfig.pri that qtcore installed
  588. if ! cp "${ROOT}${QT4_DATADIR}"/mkspecs/gentoo/qconfig.pri \
  589. "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri; then
  590. eerror "cp qconfig failed."
  591. return 1
  592. fi
  593. # generate list of QT_CONFIG entries from the existing list
  594. # including qconfig_add and excluding qconfig_remove
  595. for x in $(sed -n 's/^QT_CONFIG +=//p' \
  596. "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri) ${qconfig_add}; do
  597. has ${x} ${qconfig_remove} || qconfig_new+=" ${x}"
  598. done
  599. # replace the existing QT_CONFIG list with qconfig_new
  600. if ! sed -i -e "s/QT_CONFIG +=.*/QT_CONFIG += ${qconfig_new}/" \
  601. "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri; then
  602. eerror "Sed for QT_CONFIG failed"
  603. return 1
  604. fi
  605. # create Gentoo/qconfig.h
  606. if [[ ! -e ${ROOT}${QT4_HEADERDIR}/Gentoo ]]; then
  607. if ! mkdir -p "${ROOT}${QT4_HEADERDIR}"/Gentoo; then
  608. eerror "mkdir ${QT4_HEADERDIR}/Gentoo failed"
  609. return 1
  610. fi
  611. fi
  612. : > "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-qconfig.h
  613. for x in "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-*-qconfig.h; do
  614. [[ -f ${x} ]] || continue
  615. cat "${x}" >> "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-qconfig.h
  616. done
  617. else
  618. rm -f "${ROOT}${QT4_DATADIR}"/mkspecs/qconfig.pri
  619. rm -f "${ROOT}${QT4_HEADERDIR}"/Gentoo/gentoo-qconfig.h
  620. rmdir "${ROOT}${QT4_DATADIR}"/mkspecs \
  621. "${ROOT}${QT4_DATADIR}" \
  622. "${ROOT}${QT4_HEADERDIR}"/Gentoo \
  623. "${ROOT}${QT4_HEADERDIR}" 2>/dev/null
  624. fi
  625. fi
  626. }
  627. # @FUNCTION: qt4_symlink_framework_headers
  628. # @DESCRIPTION:
  629. # On OS X we need to add some symlinks when frameworks are being
  630. # used, to avoid complications with some more or less stupid packages.
  631. qt4_symlink_framework_headers() {
  632. if use_if_iuse aqua && [[ ${CHOST##*-darwin} -ge 9 ]]; then
  633. local frw dest f h rdir
  634. # Some packages tend to include <Qt/...>
  635. dodir "${QT4_HEADERDIR#${EPREFIX}}"/Qt
  636. # Fake normal headers when frameworks are installed... eases life later
  637. # on, make sure we use relative links though, as some ebuilds assume
  638. # these dirs exist in src_install to add additional files
  639. f=${QT4_HEADERDIR}
  640. h=${QT4_LIBDIR}
  641. while [[ -n ${f} && ${f%%/*} == ${h%%/*} ]] ; do
  642. f=${f#*/}
  643. h=${h#*/}
  644. done
  645. rdir=${h}
  646. f="../"
  647. while [[ ${h} == */* ]] ; do
  648. f="${f}../"
  649. h=${h#*/}
  650. done
  651. rdir="${f}${rdir}"
  652. for frw in "${D}${QT4_LIBDIR}"/*.framework; do
  653. [[ -e "${frw}"/Headers ]] || continue
  654. f=$(basename ${frw})
  655. dest="${QT4_HEADERDIR#${EPREFIX}}"/${f%.framework}
  656. dosym "${rdir}"/${f}/Headers "${dest}"
  657. # Link normal headers as well.
  658. for hdr in "${D}${QT4_LIBDIR}/${f}"/Headers/*; do
  659. h=$(basename ${hdr})
  660. dosym "../${rdir}"/${f}/Headers/${h} \
  661. "${QT4_HEADERDIR#${EPREFIX}}"/Qt/${h}
  662. done
  663. done
  664. fi
  665. }
  666. # @FUNCTION: qt4_get_mkspec
  667. # @INTERNAL
  668. # @DESCRIPTION:
  669. # Returns the right mkspec for the current CHOST/CXX combination.
  670. qt4_get_mkspec() {
  671. local spec=
  672. case ${CHOST} in
  673. *-linux*)
  674. spec=linux ;;
  675. *-darwin*)
  676. use_if_iuse aqua &&
  677. spec=macx || # mac with carbon/cocoa
  678. spec=darwin ;; # darwin/mac with X11
  679. *-freebsd*|*-dragonfly*)
  680. spec=freebsd ;;
  681. *-netbsd*)
  682. spec=netbsd ;;
  683. *-openbsd*)
  684. spec=openbsd ;;
  685. *-aix*)
  686. spec=aix ;;
  687. hppa*-hpux*)
  688. spec=hpux ;;
  689. ia64*-hpux*)
  690. spec=hpuxi ;;
  691. *-solaris*)
  692. spec=solaris ;;
  693. *)
  694. die "qt4-build-multilib.eclass: unsupported CHOST '${CHOST}'" ;;
  695. esac
  696. case $(tc-getCXX) in
  697. *g++*)
  698. spec+=-g++ ;;
  699. *clang*)
  700. if [[ -d ${S}/mkspecs/unsupported/${spec}-clang ]]; then
  701. spec=unsupported/${spec}-clang
  702. else
  703. ewarn "${spec}-clang mkspec does not exist, falling back to ${spec}-g++"
  704. spec+=-g++
  705. fi ;;
  706. *icpc*)
  707. if [[ -d ${S}/mkspecs/${spec}-icc ]]; then
  708. spec+=-icc
  709. else
  710. ewarn "${spec}-icc mkspec does not exist, falling back to ${spec}-g++"
  711. spec+=-g++
  712. fi ;;
  713. *)
  714. die "qt4-build-multilib.eclass: unsupported compiler '$(tc-getCXX)'" ;;
  715. esac
  716. # Add -64 for 64-bit prefix profiles
  717. if use amd64-linux || use ppc64-linux ||
  718. use x64-macos ||
  719. use sparc64-solaris || use x64-solaris
  720. then
  721. [[ -d ${S}/mkspecs/${spec}-64 ]] && spec+=-64
  722. fi
  723. echo ${spec}
  724. }