1 # Copyright 2007-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/qt4-build.eclass,v 1.9 2008/03/06 14:44:13 zlin Exp $
5 # @ECLASS: qt4-build.eclass
7 # Caleb Tennis <caleb@gentoo.org>
8 # @BLURB: Eclass for Qt4 split ebuilds.
10 # This eclass contains various functions that are used when building Qt4
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}"
21 inherit eutils multilib toolchain-funcs flag-o-matic subversion
23 IUSE
="${IUSE} debug qt-copy exceptions"
27 SRCTYPE
="${SRCTYPE:-opensource-src}"
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"
38 MY_P
=qt-x11-
${SRCTYPE}-${MY_PV}
43 SRC_URI
="${SRC_URI} mirror://gentoo/${MY_P}-headers.tar.bz2"
49 qt4-build_pkg_setup
() {
50 # Check USE requirements
53 # Set up installation directories
54 QTBASEDIR
=/usr
/$
(get_libdir
)/qt4
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
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}"
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}"
85 echo tar xjpf
"${DISTDIR}/${MY_P}.tar.bz2" ${targets}
86 tar xjpf "${DISTDIR}/${MY_P}.tar.bz2" ${targets}
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 \
98 ${QT4_EXTRACT_DIRECTORIES} ${QT4_TARGET_DIRECTORIES}; do
99 targets
="${targets} ${MY_P}/${target}"
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"
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_/")
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"
130 EPATCH_EXCLUDE
="${EPATCH_EXCLUDE} 0221_all__qdbus_to_dbus_fix.diff"
133 EPATCH_SUFFIX
="diff" epatch
136 qt4-build_src_unpack
() {
138 if [[ ${PN} != qt-core
]]; then
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}:" \
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.
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
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}"
191 standard_configure_options
() {
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"
202 myconf
="${myconf} -debug -no-separate-debug-info"
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.
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." ;;
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"
233 build_target_directories
() {
234 build_directories
"${QT4_TARGET_DIRECTORIES}"
237 build_directories
() {
241 "${S}"/bin
/qmake
"LIBS+=-L${QTLIBDIR}" "CONFIG+=nostrip" || die
"qmake failed"
242 emake || die
"emake failed"
246 install_directories
() {
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}"
255 # @ECLASS-VARIABLE: QCONFIG_ADD
257 # List options that need to be added to QT_CONFIG in qconfig.pri
258 QCONFIG_ADD
="${QCONFIG_ADD:-}"
260 # @ECLASS-VARIABLE: QCONFIG_REMOVE
262 # List options that need to be removed from QT_CONFIG in qconfig.pri
263 QCONFIG_REMOVE
="${QCONFIG_REMOVE:-}"
265 # @ECLASS-VARIABLE: QCONFIG_DEFINE
267 # List variables that should be defined at the top of QtCore/qconfig.h
268 QCONFIG_DEFINE
="${QCONFIG_DEFINE:-}"
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
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
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}")"
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.
"
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}"
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
"
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
"
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
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() {
353 qt4-build_pkg_postinst() {
357 skip_qmake_build_patch() {
358 # Don't need to build qmake, as it's already installed from qt-core
359 sed -i -e "s
:if true
:if false
:g
" "${S}"/configure || die "Sed failed
"
362 skip_project_generation_patch() {
363 # Exit the script early by throwing in an exit before all of the .pro files are scanned
364 sed -e "s
:echo \"Finding
:exit 0\n\necho
\"Finding
:g
" \
365 -i "${S}"/configure || die "Sed failed
"
368 symlink_binaries_to_buildtree() {
369 for bin in qmake moc uic rcc; do
370 ln -s ${QTBINDIR}/${bin} "${S}"/bin/ || die "Symlinking ${bin} to ${S}/bin failed."
374 fix_library_files
() {
375 for libfile
in "${D}"/${QTLIBDIR}/{*.la,*.prl,pkgconfig/*.pc}; do
376 if [[ -e ${libfile} ]]; then
377 sed -i -e "s
:${S}/lib:${QTLIBDIR}:g" ${libfile} || die "Sed on ${libfile} failed.
"
381 # pkgconfig files refer to WORKDIR/bin as the moc and uic locations. Fix:
382 for libfile in "${D}"/${QTLIBDIR}/pkgconfig/*.pc; do
383 if [[ -e ${libfile} ]]; then
384 sed -i -e "s
:${S}/bin:${QTBINDIR}:g" ${libfile} || die
"Sed failed"
386 # Move .pc files into the pkgconfig directory
389 mv ${libfile} "${D}"/${QTPCDIR}/ \
390 || die
"Moving ${libfile} to ${D}/${QTPCDIR}/ failed."
394 # Don't install an empty directory
395 rmdir "${D}"/${QTLIBDIR}/pkgconfig
403 [[ -n ${2} ]] && feature
=${2}
404 [[ -n ${3} ]] && enableval
="-${3}"
407 echo "${enableval}-${feature}"
409 echo "-no-${feature}"
413 # @ECLASS-VARIABLE: QT4_BUILT_WITH_USE_CHECK
415 # The contents of $QT4_BUILT_WITH_USE_CHECK gets fed to built_with_use
416 # (eutils.eclass), line per line.
421 # use qt3support && QT4_BUILT_WITH_USE_CHECK="${QT4_BUILT_WITH_USE_CHECK}
422 # ~x11-libs/qt-gui-${PV} qt3support"
423 # qt4-build_check_use
427 # Run built_with_use on each flag and print appropriate error messages if any
429 _qt_built_with_use
() {
430 local missing opt pkg flag flags
432 if [[ ${1} = "--missing" ]]; then
433 missing
="${1} ${2}" && shift 2
435 if [[ ${1:0:1} = "-" ]]; then
441 for flag
in "${@}"; do
442 flags
="${flags} ${flag}"
443 if ! built_with_use
${missing} ${opt} ${pkg} ${flag}; then
446 [[ ${opt} = "-o" ]] && return 0
449 if [[ "${flags# }" = "${@}" ]]; then
452 if [[ ${opt} = "-o" ]]; then
453 eerror
"This package requires '${pkg}' to be built with any of the following USE flags: '$*'."
455 eerror
"This package requires '${pkg}' to be built with the following USE flags: '${flags# }'."
460 # @FUNCTION: qt4-build_check_use
462 # Check if the listed packages in $QT4_BUILT_WITH_USE_CHECK are built with the
465 # If any of the required USE flags are missing, an eerror will be printed for
466 # each package with missing USE flags.
467 qt4-build_check_use
() {
470 [[ -z ${line} ]] && continue
471 if ! _qt_built_with_use
${line}; then
474 done <<< "${QT4_BUILT_WITH_USE_CHECK}"
475 if [[ -n ${missing} ]]; then
477 eerror
"Flags marked with an * are missing."
478 die
"Missing USE flags found"
483 # Allows us to define which mkspecs dir we want to use.
487 *-freebsd*|
*-dragonfly*)
498 die
"Unknown CHOST, no platform choosen."
502 if [[ ${CXX/g++/} != ${CXX} ]]; then
504 elif [[ ${CXX/icpc/} != ${CXX} ]]; then
507 die
"Unknown compiler ${CXX}."
513 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postrm pkg_postinst