Make lzma-utils dep conditional upon qt-copy USE.
[gentoo-soor-overlay.git] / eclass / qt4-build.eclass
blobdeebd78785488f6c4a24a48d17775dd5b8aaaf8b
1 # Copyright 2007-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
5 # @ECLASS: qt4-build.eclass
6 # @MAINTAINER:
7 # Caleb Tennis <caleb@gentoo.org>
8 # @BLURB: Eclass for Qt4 split ebuilds.
9 # @DESCRIPTION:
10 # This eclass contains various functions that are used when building Qt4
12 KMNAME="qt-copy"
13 KMMODULE="patches"
14 ESVN_PROJECT="KDE/${KMNAME}"
15 ESVN_MIRROR="svn://anonsvn.kde.org/home/kde"
16 ESVN_REPO_URI="${ESVN_MIRROR}/trunk/${KMNAME}"
17 ESVN_REPO_URI="${ESVN_REPO_URI}/${KMMODULE}"
19 RESTRICT="mirror"
21 inherit eutils multilib toolchain-funcs flag-o-matic subversion
23 IUSE="${IUSE} debug qt-copy exceptions"
25 case "${PV}" in
26 4.4.0_rc*)
27 SRCTYPE="${SRCTYPE:-opensource-src}"
28 MY_PV="${PV/_rc/-rc}"
29 SRC_URI="ftp://ftp.trolltech.com/qt/source/qt-x11-${SRCTYPE}-${MY_PV}.tar.bz2"
32 SRCTYPE="${SRCTYPE:-opensource-src}"
33 MY_PV=${PV/_pre/-snapshot-}
34 SRC_URI="ftp://ftp.trolltech.com/qt/snapshots/qt-x11-${SRCTYPE}-${MY_PV}.tar.gz"
36 esac
38 MY_P=qt-x11-${SRCTYPE}-${MY_PV}
39 S=${WORKDIR}/${MY_P}
41 case "${PV}" in
42 4.4.0_rc*)
43 SRC_URI="${SRC_URI} mirror://gentoo/${MY_P}-headers.tar.bz2"
47 esac
49 qt4-build_pkg_setup() {
50 # Check USE requirements
51 qt4-build_check_use
53 # Set up installation directories
54 QTBASEDIR=/usr/$(get_libdir)/qt4
55 QTPREFIXDIR=/usr
56 QTBINDIR=/usr/bin
57 QTLIBDIR=/usr/$(get_libdir)/qt4
58 QTPCDIR=/usr/$(get_libdir)/pkgconfig
59 QTDATADIR=/usr/share/qt4
60 QTDOCDIR=/usr/share/doc/qt-${PV}
61 QTHEADERDIR=/usr/include/qt4
62 QTPLUGINDIR=${QTLIBDIR}/plugins
63 QTSYSCONFDIR=/etc/qt4
64 QTTRANSDIR=${QTDATADIR}/translations
65 QTEXAMPLESDIR=${QTDATADIR}/examples
66 QTDEMOSDIR=${QTDATADIR}/demos
68 PLATFORM=$(qt_mkspecs_dir)
70 PATH="${S}/bin:${PATH}"
71 LD_LIBRARY_PATH="${S}/lib:${LD_LIBRARY_PATH}"
74 qt4_unpack() {
75 local target targets
77 case "${PV}" in
78 4.4.0_rc*)
79 if use !qt-copy; then
80 for target in configure LICENSE.{GPL2,GPL3,QPL} projects.pro \
81 src/{qbase,qt_targets,qt_install}.pri bin config.tests mkspecs qmake \
82 ${QT4_EXTRACT_DIRECTORIES} ${QT4_TARGET_DIRECTORIES}; do
83 targets="${targets} ${MY_P}/${target}"
84 done
85 echo tar xjpf "${DISTDIR}/${MY_P}.tar.bz2" ${targets}
86 tar xjpf "${DISTDIR}/${MY_P}.tar.bz2" ${targets}
87 else
88 echo tar xjpf "${DISTDIR}/${MY_P}.tar.bz2"
89 tar xjpf "${DISTDIR}/${MY_P}.tar.bz2"
91 echo tar xjpf "${DISTDIR}"/${MY_P}-headers.tar.bz2
92 tar xjpf "${DISTDIR}"/${MY_P}-headers.tar.bz2
95 for target in configure LICENSE.SNAPSHOT.OPENSOURCE.{GPL2,GPL3} projects.pro \
96 src/{qbase,qt_targets,qt_install}.pri bin config.tests mkspecs qmake \
97 src/corelib/global \
98 ${QT4_EXTRACT_DIRECTORIES} ${QT4_TARGET_DIRECTORIES}; do
99 targets="${targets} ${MY_P}/${target}"
100 done
101 #echo tar xzpf "${DISTDIR}/${MY_P}.tar.gz" ${targets}
102 #tar xzpf "${DISTDIR}/${MY_P}.tar.gz" ${targets}
103 echo tar xzpf "${DISTDIR}/${MY_P}.tar.gz"
104 tar xzpf "${DISTDIR}/${MY_P}.tar.gz"
106 esac
109 qt4_qt-copy() {
110 S_="${S}"
111 S="${S}/patches"
112 subversion_src_unpack
113 for x in $(ls "${S}"); do
114 mv -vi ${x} $(echo ${x}|sed "s/[0-9]*/&_all_/;s/_all_-/_all_/")
115 done
116 S="${S_}"
117 cd "${S}"
119 EPATCH_SOURCE="${S}/patches"
120 EPATCH_EXCLUDE="0178_all_transparency-window-types.diff
121 0217_all_qurl-isempty-regression.diff
122 0218_all_qassert-macro-fix.diff
123 0172_all_prefer-xrandr-over-xinerama.diff
124 0184_all_dlopen-defaults-to-local.diff
125 0215_all_compile-with-Xcursor-linkage.diff"
126 case "${PV}" in
127 4.4.0_rc*)
130 EPATCH_EXCLUDE="${EPATCH_EXCLUDE} 0221_all__qdbus_to_dbus_fix.diff"
132 esac
133 EPATCH_SUFFIX="diff" epatch
136 qt4-build_src_unpack() {
137 qt4_unpack
138 if [[ ${PN} != qt-core ]]; then
139 cd "${S}"
140 skip_qmake_build_patch
141 skip_project_generation_patch
142 symlink_binaries_to_buildtree
145 sed -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
146 -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
147 -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=${LDFLAGS}:" \
148 -e "s:X11R6/::" \
149 -i "${S}"/mkspecs/$(qt_mkspecs_dir)/qmake.conf || die "sed ${S}/mkspecs/$(qt_mkspecs_dir)/qmake.conf failed"
151 sed -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
152 -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
153 -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=${LDFLAGS}:" \
154 -i "${S}"/mkspecs/common/g++.conf || die "sed ${S}/mkspecs/common/g++.conf failed"
156 # Apply QT Copy patches:
157 use qt-copy && qt4_qt-copy
160 qt4-build_src_compile() {
161 # Don't let the user go too overboard with flags. If you really want to, uncomment
162 # out the line below and give 'er a whirl.
163 strip-flags
164 replace-flags -O3 -O2
166 if [[ $(gcc-fullversion) == "3.4.6" && gcc-specs-ssp ]] ; then
167 ewarn "Appending -fno-stack-protector to CFLAGS/CXXFLAGS"
168 append-flags -fno-stack-protector
171 # Bug 178652
172 if [[ "$(gcc-major-version)" == "3" ]] && use amd64; then
173 ewarn "Appending -fno-gcse to CFLAGS/CXXFLAGS"
174 append-flags -fno-gcse
177 myconf="$(standard_configure_options) ${myconf}"
179 echo ./configure ${myconf}
180 ./configure ${myconf} || die "./configure failed"
182 build_target_directories
185 qt4-build_src_install() {
186 install_directories "${QT4_TARGET_DIRECTORIES}"
187 install_qconfigs
188 fix_library_files
191 standard_configure_options() {
192 local myconf=""
194 [[ $(get_libdir) != "lib" ]] && myconf="${myconf} -L/usr/$(get_libdir)"
196 # Disable visibility explicitly if gcc version isn't 4
197 if [[ "$(gcc-major-version)" -lt "4" ]]; then
198 myconf="${myconf} -no-reduce-exports"
201 if use debug; then
202 myconf="${myconf} -debug -no-separate-debug-info"
203 else
204 myconf="${myconf} -release -no-separate-debug-info"
207 # ARCH is set on Gentoo. QT now falls back to generic on an unsupported
208 # ${ARCH}. Therefore we convert it to supported values.
209 case "${ARCH}" in
210 amd64) myconf="${myconf} -arch x86_64" ;;
211 ppc|ppc64) myconf="${myconf} -arch powerpc" ;;
212 x86) myconf="${myconf} -arch i386" ;;
213 alpha|arm|ia64|mips|s390|sparc) myconf="${myconf} -arch ${ARCH}" ;;
214 hppa|sh) myconf="${myconf} -arch generic" ;;
215 *) die "${ARCH} is unsupported by this eclass. Please file a bug." ;;
216 esac
218 if [[ ${PN} != qt-xmlpatterns ]] && use !exceptions; then
219 myconf="${myconf} -no-exceptions"
222 myconf="${myconf} -stl -verbose -largefile -confirm-license -no-rpath
223 -prefix ${QTPREFIXDIR} -bindir ${QTBINDIR} -libdir ${QTLIBDIR}
224 -datadir ${QTDATADIR} -docdir ${QTDOCDIR} -headerdir ${QTHEADERDIR}
225 -plugindir ${QTPLUGINDIR} -sysconfdir ${QTSYSCONFDIR}
226 -translationdir ${QTTRANSDIR} -examplesdir ${QTEXAMPLESDIR}
227 -demosdir ${QTDEMOSDIR} -silent -fast -reduce-relocations
228 -nomake examples -nomake demos"
230 echo "${myconf}"
233 build_target_directories() {
234 build_directories "${QT4_TARGET_DIRECTORIES}"
237 build_directories() {
238 local dirs="$@"
239 for x in ${dirs}; do
240 cd "${S}"/${x}
241 "${S}"/bin/qmake "LIBS+=-L${QTLIBDIR}" "CONFIG+=nostrip" || die "qmake failed"
242 emake || die "emake failed"
243 done
246 install_directories() {
247 local dirs="$@"
248 for x in ${dirs}; do
249 pushd "${S}"/${x} >/dev/null || die "Can't pushd ${S}/${x}"
250 emake INSTALL_ROOT="${D}" install || die "emake install failed"
251 popd >/dev/null || die "Can't popd from ${S}/${x}"
252 done
255 # @ECLASS-VARIABLE: QCONFIG_ADD
256 # @DESCRIPTION:
257 # List options that need to be added to QT_CONFIG in qconfig.pri
258 QCONFIG_ADD="${QCONFIG_ADD:-}"
260 # @ECLASS-VARIABLE: QCONFIG_REMOVE
261 # @DESCRIPTION:
262 # List options that need to be removed from QT_CONFIG in qconfig.pri
263 QCONFIG_REMOVE="${QCONFIG_REMOVE:-}"
265 # @ECLASS-VARIABLE: QCONFIG_DEFINE
266 # @DESCRIPTION:
267 # List variables that should be defined at the top of QtCore/qconfig.h
268 QCONFIG_DEFINE="${QCONFIG_DEFINE:-}"
270 install_qconfigs() {
271 local x
272 if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} ]]; then
273 for x in QCONFIG_ADD QCONFIG_REMOVE; do
274 [[ -n ${!x} ]] && echo ${x}=${!x} >> "${T}"/${PN}-qconfig.pri
275 done
276 insinto ${QTDATADIR}/mkspecs/gentoo
277 doins "${T}"/${PN}-qconfig.pri || die "installing ${PN}-qconfig.pri failed"
280 if [[ -n ${QCONFIG_DEFINE} ]]; then
281 for x in ${QCONFIG_DEFINE}; do
282 echo "#define ${x}" >> "${T}"/gentoo-${PN}-qconfig.h
283 done
284 insinto ${QTHEADERDIR}/Gentoo
285 doins "${T}"/gentoo-${PN}-qconfig.h || die "installing ${PN}-qconfig.h failed"
289 # Stubs for functions used by the Qt 4.4.0_technical_preview_1.
290 qconfig_add_option() { : ; }
291 qconfig_remove_option() { : ; }
293 generate_qconfigs() {
294 if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} || -n ${QCONFIG_DEFINE} || ${CATEGORY}/${PN} == x11-libs/qt-core ]]; then
295 local x qconfig_add qconfig_remove qconfig_new
296 for x in "${ROOT}${QTDATADIR}"/mkspecs/gentoo/*-qconfig.pri; do
297 [[ -f ${x} ]] || continue
298 qconfig_add="${qconfig_add} $(sed -n 's/^QCONFIG_ADD=//p' "${x}")"
299 qconfig_remove="${qconfig_remove} $(sed -n 's/^QCONFIG_REMOVE=//p' "${x}")"
300 done
302 # these error checks do not use die because dying in pkg_post{inst,rm}
303 # just makes things worse.
304 if [[ -e "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri ]]; then
305 # start with the qconfig.pri that qt-core installed
306 if ! cp "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri \
307 "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
308 eerror "cp qconfig failed."
309 return 1
312 # generate list of QT_CONFIG entries from the existing list
313 # including qconfig_add and excluding qconfig_remove
314 for x in $(sed -n 's/^QT_CONFIG +=//p' \
315 "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri) ${qconfig_add}; do
316 hasq ${x} ${qconfig_remove} || qconfig_new="${qconfig_new} ${x}"
317 done
319 # replace the existing QT_CONFIG list with qconfig_new
320 if ! sed -i -e "s/QT_CONFIG +=.*/QT_CONFIG += ${qconfig_new}/" \
321 "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
322 eerror "Sed for QT_CONFIG failed"
323 return 1
326 # create Gentoo/qconfig.h
327 if [[ ! -e ${ROOT}${QTHEADERDIR}/Gentoo ]]; then
328 if ! mkdir -p "${ROOT}${QTHEADERDIR}"/Gentoo; then
329 eerror "mkdir ${QTHEADERDIR}/Gentoo failed"
330 return 1
333 : > "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
334 for x in "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-*-qconfig.h; do
335 [[ -f ${x} ]] || continue
336 cat "${x}" >> "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
337 done
338 else
339 rm -f "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri
340 rm -f "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
341 rmdir "${ROOT}${QTDATADIR}"/mkspecs \
342 "${ROOT}${QTDATADIR}" \
343 "${ROOT}${QTHEADERDIR}"/Gentoo \
344 "${ROOT}${QTHEADERDIR}" 2>/dev/null
349 qt4-build_pkg_postrm() {
350 generate_qconfigs
353 qt4-build_pkg_postinst() {
354 generate_qconfigs
355 if use qt-copy || use exceptions; then
356 ewarn "Do NOT report bugs to Gentoo's bugzilla when built with qt-copy or exceptions!"
360 skip_qmake_build_patch() {
361 # Don't need to build qmake, as it's already installed from qt-core
362 sed -i -e "s:if true:if false:g" "${S}"/configure || die "Sed failed"
365 skip_project_generation_patch() {
366 # Exit the script early by throwing in an exit before all of the .pro files are scanned
367 sed -e "s:echo \"Finding:exit 0\n\necho \"Finding:g" \
368 -i "${S}"/configure || die "Sed failed"
371 symlink_binaries_to_buildtree() {
372 for bin in qmake moc uic rcc; do
373 ln -s ${QTBINDIR}/${bin} "${S}"/bin/ || die "Symlinking ${bin} to ${S}/bin failed."
374 done
377 fix_library_files() {
378 for libfile in "${D}"/${QTLIBDIR}/{*.la,*.prl,pkgconfig/*.pc}; do
379 if [[ -e ${libfile} ]]; then
380 sed -i -e "s:${S}/lib:${QTLIBDIR}:g" ${libfile} || die "Sed on ${libfile} failed."
382 done
384 # pkgconfig files refer to WORKDIR/bin as the moc and uic locations. Fix:
385 for libfile in "${D}"/${QTLIBDIR}/pkgconfig/*.pc; do
386 if [[ -e ${libfile} ]]; then
387 sed -i -e "s:${S}/bin:${QTBINDIR}:g" ${libfile} || die "Sed failed"
389 # Move .pc files into the pkgconfig directory
391 dodir ${QTPCDIR}
392 mv ${libfile} "${D}"/${QTPCDIR}/ \
393 || die "Moving ${libfile} to ${D}/${QTPCDIR}/ failed."
395 done
397 # Don't install an empty directory
398 rmdir "${D}"/${QTLIBDIR}/pkgconfig
401 qt_use() {
402 local flag="${1}"
403 local feature="${1}"
404 local enableval=
406 [[ -n ${2} ]] && feature=${2}
407 [[ -n ${3} ]] && enableval="-${3}"
409 if use ${flag}; then
410 echo "${enableval}-${feature}"
411 else
412 echo "-no-${feature}"
416 # @ECLASS-VARIABLE: QT4_BUILT_WITH_USE_CHECK
417 # @DESCRIPTION:
418 # The contents of $QT4_BUILT_WITH_USE_CHECK gets fed to built_with_use
419 # (eutils.eclass), line per line.
421 # Example:
422 # @CODE
423 # pkg_setup() {
424 # use qt3support && QT4_BUILT_WITH_USE_CHECK="${QT4_BUILT_WITH_USE_CHECK}
425 # ~x11-libs/qt-gui-${PV} qt3support"
426 # qt4-build_check_use
428 # @CODE
430 # Run built_with_use on each flag and print appropriate error messages if any
431 # flags are missing
432 _qt_built_with_use() {
433 local missing opt pkg flag flags
435 if [[ ${1} = "--missing" ]]; then
436 missing="${1} ${2}" && shift 2
438 if [[ ${1:0:1} = "-" ]]; then
439 opt=${1} && shift
442 pkg=${1} && shift
444 for flag in "${@}"; do
445 flags="${flags} ${flag}"
446 if ! built_with_use ${missing} ${opt} ${pkg} ${flag}; then
447 flags="${flags}*"
448 else
449 [[ ${opt} = "-o" ]] && return 0
451 done
452 if [[ "${flags# }" = "${@}" ]]; then
453 return 0
455 if [[ ${opt} = "-o" ]]; then
456 eerror "This package requires '${pkg}' to be built with any of the following USE flags: '$*'."
457 else
458 eerror "This package requires '${pkg}' to be built with the following USE flags: '${flags# }'."
460 return 1
463 # @FUNCTION: qt4-build_check_use
464 # @DESCRIPTION:
465 # Check if the listed packages in $QT4_BUILT_WITH_USE_CHECK are built with the
466 # USE flags listed.
468 # If any of the required USE flags are missing, an eerror will be printed for
469 # each package with missing USE flags.
470 qt4-build_check_use() {
471 local line missing
472 while read line; do
473 [[ -z ${line} ]] && continue
474 if ! _qt_built_with_use ${line}; then
475 missing=true
477 done <<< "${QT4_BUILT_WITH_USE_CHECK}"
478 if [[ -n ${missing} ]]; then
479 echo
480 eerror "Flags marked with an * are missing."
481 die "Missing USE flags found"
485 qt_mkspecs_dir() {
486 # Allows us to define which mkspecs dir we want to use.
487 local spec
489 case ${CHOST} in
490 *-freebsd*|*-dragonfly*)
491 spec="freebsd" ;;
492 *-openbsd*)
493 spec="openbsd" ;;
494 *-netbsd*)
495 spec="netbsd" ;;
496 *-darwin*)
497 spec="darwin" ;;
498 *-linux-*|*-linux)
499 spec="linux" ;;
501 die "Unknown CHOST, no platform choosen."
502 esac
504 CXX=$(tc-getCXX)
505 if [[ ${CXX/g++/} != ${CXX} ]]; then
506 spec="${spec}-g++"
507 elif [[ ${CXX/icpc/} != ${CXX} ]]; then
508 spec="${spec}-icc"
509 else
510 die "Unknown compiler ${CXX}."
513 echo "${spec}"
516 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postrm pkg_postinst