/[gentoo-x86]/eclass/qt4-build.eclass
Gentoo

Contents of /eclass/qt4-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Wed Jan 21 08:55:28 2009 UTC (5 years, 7 months ago) by gengor
Branch: MAIN
Changes since 1.17: +10 -4 lines
Append -fno-stack-protector-all to creation of internal qmake, bug 253127

1 ingmar 1.7 # Copyright 2007-2008 Gentoo Foundation
2 caleb 1.1 # Distributed under the terms of the GNU General Public License v2
3 gengor 1.18 # $Header: /var/cvsroot/gentoo-x86/eclass/qt4-build.eclass,v 1.17 2009/01/12 23:47:16 yngwin Exp $
4 caleb 1.1
5     # @ECLASS: qt4-build.eclass
6     # @MAINTAINER:
7     # Caleb Tennis <caleb@gentoo.org>
8 ingmar 1.8 # @BLURB: Eclass for Qt4 split ebuilds.
9 caleb 1.1 # @DESCRIPTION:
10     # This eclass contains various functions that are used when building Qt4
11    
12     inherit eutils multilib toolchain-funcs flag-o-matic
13    
14 ingmar 1.12 IUSE="${IUSE} debug pch"
15 caleb 1.1
16 ingmar 1.7 case "${PV}" in
17     4.4.0_beta*)
18     SRCTYPE="${SRCTYPE:-opensource-src}"
19     MY_PV="${PV/_beta/-beta}"
20     ;;
21 ingmar 1.11 4.4.0_rc*)
22     SRCTYPE="${SRCTYPE:-opensource-src}"
23     MY_PV="${PV/_rc/-rc}"
24     ;;
25 ingmar 1.7 *)
26     SRCTYPE="${SRCTYPE:-opensource-src}"
27     MY_PV="${PV}"
28     ;;
29     esac
30 ingmar 1.11 MY_P=qt-x11-${SRCTYPE}-${MY_PV}
31     S=${WORKDIR}/${MY_P}
32 ingmar 1.7
33 ingmar 1.11 SRC_URI="ftp://ftp.trolltech.com/qt/source/${MY_P}.tar.bz2"
34    
35     case "${PV}" in
36 yngwin 1.16 4.4.2|4.4.1|4.4.0|4.4.0_rc*)
37 ingmar 1.11 SRC_URI="${SRC_URI} mirror://gentoo/${MY_P}-headers.tar.bz2"
38     ;;
39     *)
40     ;;
41     esac
42 ingmar 1.7
43 caleb 1.1 qt4-build_pkg_setup() {
44 ingmar 1.7 # Check USE requirements
45     qt4-build_check_use
46    
47 caleb 1.1 # Set up installation directories
48 caleb 1.5 QTBASEDIR=/usr/$(get_libdir)/qt4
49     QTPREFIXDIR=/usr
50     QTBINDIR=/usr/bin
51     QTLIBDIR=/usr/$(get_libdir)/qt4
52     QTPCDIR=/usr/$(get_libdir)/pkgconfig
53     QTDATADIR=/usr/share/qt4
54 caleb 1.6 QTDOCDIR=/usr/share/doc/qt-${PV}
55 caleb 1.5 QTHEADERDIR=/usr/include/qt4
56     QTPLUGINDIR=${QTLIBDIR}/plugins
57     QTSYSCONFDIR=/etc/qt4
58     QTTRANSDIR=${QTDATADIR}/translations
59     QTEXAMPLESDIR=${QTDATADIR}/examples
60     QTDEMOSDIR=${QTDATADIR}/demos
61 caleb 1.1
62 caleb 1.5 PLATFORM=$(qt_mkspecs_dir)
63 caleb 1.1
64     PATH="${S}/bin:${PATH}"
65     LD_LIBRARY_PATH="${S}/lib:${LD_LIBRARY_PATH}"
66     }
67    
68 ingmar 1.11 qt4_unpack() {
69     local target targets
70 yngwin 1.15 for target in configure LICENSE.{GPL2,GPL3} projects.pro \
71 ingmar 1.11 src/{qbase,qt_targets,qt_install}.pri bin config.tests mkspecs qmake \
72 ingmar 1.13 ${QT4_EXTRACT_DIRECTORIES}; do
73 ingmar 1.11 targets="${targets} ${MY_P}/${target}"
74     done
75    
76     echo tar xjpf "${DISTDIR}"/${MY_P}.tar.bz2 ${targets}
77     tar xjpf "${DISTDIR}"/${MY_P}.tar.bz2 ${targets}
78    
79     case "${PV}" in
80 yngwin 1.16 4.4.2|4.4.1|4.4.0|4.4.0_rc*)
81 ingmar 1.11 echo tar xjpf "${DISTDIR}"/${MY_P}-headers.tar.bz2
82     tar xjpf "${DISTDIR}"/${MY_P}-headers.tar.bz2
83     ;;
84     esac
85     }
86    
87 caleb 1.1 qt4-build_src_unpack() {
88 ingmar 1.11 qt4_unpack
89 ingmar 1.7 if [[ ${PN} != qt-core ]]; then
90 ingmar 1.11 cd "${S}"
91 ingmar 1.7 skip_qmake_build_patch
92     skip_project_generation_patch
93     symlink_binaries_to_buildtree
94     fi
95    
96 gengor 1.18 # Bug 253127
97     if [[ $(gcc-major-version) -lt "4" ]] ; then
98     sed -e "/^QMAKE_CFLAGS\t/ s:$: -fno-stack-protector-all:" \
99     -i "${S}"/mkspecs/common/g++.conf || die "sed ${S}/mkspecs/common/g++.conf failed"
100     fi
101    
102 ingmar 1.7 sed -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
103     -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
104     -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=${LDFLAGS}:" \
105     -e "s:X11R6/::" \
106     -i "${S}"/mkspecs/$(qt_mkspecs_dir)/qmake.conf || die "sed ${S}/mkspecs/$(qt_mkspecs_dir)/qmake.conf failed"
107    
108     sed -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
109     -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
110     -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=${LDFLAGS}:" \
111     -i "${S}"/mkspecs/common/g++.conf || die "sed ${S}/mkspecs/common/g++.conf failed"
112     }
113    
114     qt4-build_src_compile() {
115 caleb 1.1 # Don't let the user go too overboard with flags. If you really want to, uncomment
116     # out the line below and give 'er a whirl.
117     strip-flags
118     replace-flags -O3 -O2
119    
120 gengor 1.18 if [[ $(gcc-major-version) -lt "4" ]] ; then
121     ewarn "Appending -fno-stack-protector to CXXFLAGS"
122     append-cxxflags -fno-stack-protector
123 caleb 1.1 fi
124 ingmar 1.7
125 ingmar 1.10 # Bug 178652
126     if [[ "$(gcc-major-version)" == "3" ]] && use amd64; then
127     ewarn "Appending -fno-gcse to CFLAGS/CXXFLAGS"
128     append-flags -fno-gcse
129     fi
130    
131 ingmar 1.7 myconf="$(standard_configure_options) ${myconf}"
132    
133     echo ./configure ${myconf}
134     ./configure ${myconf} || die "./configure failed"
135    
136     build_target_directories
137 caleb 1.1 }
138    
139 caleb 1.4 qt4-build_src_install() {
140     install_directories "${QT4_TARGET_DIRECTORIES}"
141 ingmar 1.7 install_qconfigs
142 caleb 1.4 fix_library_files
143     }
144    
145 caleb 1.1 standard_configure_options() {
146     local myconf=""
147    
148 ingmar 1.7 [[ $(get_libdir) != "lib" ]] && myconf="${myconf} -L/usr/$(get_libdir)"
149 caleb 1.1
150     # Disable visibility explicitly if gcc version isn't 4
151 ingmar 1.7 if [[ "$(gcc-major-version)" -lt "4" ]]; then
152 caleb 1.1 myconf="${myconf} -no-reduce-exports"
153     fi
154    
155 ingmar 1.12 # precompiled headers doesn't work on hardened, where the flag is masked.
156     if use pch; then
157     myconf="${myconf} -pch"
158     else
159     myconf="${myconf} -no-pch"
160     fi
161    
162 ingmar 1.7 if use debug; then
163     myconf="${myconf} -debug -no-separate-debug-info"
164     else
165     myconf="${myconf} -release -no-separate-debug-info"
166     fi
167 caleb 1.1
168 ingmar 1.11 # ARCH is set on Gentoo. QT now falls back to generic on an unsupported
169     # ${ARCH}. Therefore we convert it to supported values.
170     case "${ARCH}" in
171     amd64) myconf="${myconf} -arch x86_64" ;;
172     ppc|ppc64) myconf="${myconf} -arch powerpc" ;;
173 ingmar 1.14 x86|x86-*) myconf="${myconf} -arch i386" ;;
174 ingmar 1.11 alpha|arm|ia64|mips|s390|sparc) myconf="${myconf} -arch ${ARCH}" ;;
175     hppa|sh) myconf="${myconf} -arch generic" ;;
176     *) die "${ARCH} is unsupported by this eclass. Please file a bug." ;;
177     esac
178    
179 ingmar 1.7 myconf="${myconf} -stl -verbose -largefile -confirm-license -no-rpath
180     -prefix ${QTPREFIXDIR} -bindir ${QTBINDIR} -libdir ${QTLIBDIR}
181     -datadir ${QTDATADIR} -docdir ${QTDOCDIR} -headerdir ${QTHEADERDIR}
182     -plugindir ${QTPLUGINDIR} -sysconfdir ${QTSYSCONFDIR}
183     -translationdir ${QTTRANSDIR} -examplesdir ${QTEXAMPLESDIR}
184     -demosdir ${QTDEMOSDIR} -silent -fast -reduce-relocations
185     -nomake examples -nomake demos"
186 caleb 1.1
187     echo "${myconf}"
188     }
189    
190 caleb 1.4 build_target_directories() {
191     build_directories "${QT4_TARGET_DIRECTORIES}"
192     }
193    
194 caleb 1.1 build_directories() {
195     local dirs="$@"
196     for x in ${dirs}; do
197     cd "${S}"/${x}
198 ingmar 1.7 "${S}"/bin/qmake "LIBS+=-L${QTLIBDIR}" "CONFIG+=nostrip" || die "qmake failed"
199     emake || die "emake failed"
200 caleb 1.1 done
201     }
202    
203     install_directories() {
204     local dirs="$@"
205     for x in ${dirs}; do
206 ingmar 1.7 pushd "${S}"/${x} >/dev/null || die "Can't pushd ${S}/${x}"
207     emake INSTALL_ROOT="${D}" install || die "emake install failed"
208     popd >/dev/null || die "Can't popd from ${S}/${x}"
209 caleb 1.1 done
210     }
211    
212 ingmar 1.7 # @ECLASS-VARIABLE: QCONFIG_ADD
213     # @DESCRIPTION:
214     # List options that need to be added to QT_CONFIG in qconfig.pri
215     QCONFIG_ADD="${QCONFIG_ADD:-}"
216    
217     # @ECLASS-VARIABLE: QCONFIG_REMOVE
218     # @DESCRIPTION:
219     # List options that need to be removed from QT_CONFIG in qconfig.pri
220     QCONFIG_REMOVE="${QCONFIG_REMOVE:-}"
221    
222     # @ECLASS-VARIABLE: QCONFIG_DEFINE
223     # @DESCRIPTION:
224     # List variables that should be defined at the top of QtCore/qconfig.h
225     QCONFIG_DEFINE="${QCONFIG_DEFINE:-}"
226    
227     install_qconfigs() {
228 zlin 1.9 local x
229     if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} ]]; then
230 ingmar 1.7 for x in QCONFIG_ADD QCONFIG_REMOVE; do
231     [[ -n ${!x} ]] && echo ${x}=${!x} >> "${T}"/${PN}-qconfig.pri
232     done
233     insinto ${QTDATADIR}/mkspecs/gentoo
234     doins "${T}"/${PN}-qconfig.pri || die "installing ${PN}-qconfig.pri failed"
235 zlin 1.9 fi
236 ingmar 1.7
237 zlin 1.9 if [[ -n ${QCONFIG_DEFINE} ]]; then
238 ingmar 1.7 for x in ${QCONFIG_DEFINE}; do
239     echo "#define ${x}" >> "${T}"/gentoo-${PN}-qconfig.h
240     done
241     insinto ${QTHEADERDIR}/Gentoo
242     doins "${T}"/gentoo-${PN}-qconfig.h || die "installing ${PN}-qconfig.h failed"
243     fi
244     }
245    
246     # Stubs for functions used by the Qt 4.4.0_technical_preview_1.
247     qconfig_add_option() { : ; }
248     qconfig_remove_option() { : ; }
249    
250     generate_qconfigs() {
251     if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} || -n ${QCONFIG_DEFINE} || ${CATEGORY}/${PN} == x11-libs/qt-core ]]; then
252     local x qconfig_add qconfig_remove qconfig_new
253     for x in "${ROOT}${QTDATADIR}"/mkspecs/gentoo/*-qconfig.pri; do
254     [[ -f ${x} ]] || continue
255     qconfig_add="${qconfig_add} $(sed -n 's/^QCONFIG_ADD=//p' "${x}")"
256     qconfig_remove="${qconfig_remove} $(sed -n 's/^QCONFIG_REMOVE=//p' "${x}")"
257     done
258    
259     # these error checks do not use die because dying in pkg_post{inst,rm}
260     # just makes things worse.
261     if [[ -e "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri ]]; then
262     # start with the qconfig.pri that qt-core installed
263     if ! cp "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri \
264     "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
265     eerror "cp qconfig failed."
266     return 1
267     fi
268    
269     # generate list of QT_CONFIG entries from the existing list
270     # including qconfig_add and excluding qconfig_remove
271     for x in $(sed -n 's/^QT_CONFIG +=//p' \
272     "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri) ${qconfig_add}; do
273     hasq ${x} ${qconfig_remove} || qconfig_new="${qconfig_new} ${x}"
274     done
275    
276     # replace the existing QT_CONFIG list with qconfig_new
277     if ! sed -i -e "s/QT_CONFIG +=.*/QT_CONFIG += ${qconfig_new}/" \
278     "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
279     eerror "Sed for QT_CONFIG failed"
280     return 1
281     fi
282    
283     # create Gentoo/qconfig.h
284     if [[ ! -e ${ROOT}${QTHEADERDIR}/Gentoo ]]; then
285     if ! mkdir -p "${ROOT}${QTHEADERDIR}"/Gentoo; then
286     eerror "mkdir ${QTHEADERDIR}/Gentoo failed"
287     return 1
288     fi
289     fi
290     : > "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
291     for x in "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-*-qconfig.h; do
292     [[ -f ${x} ]] || continue
293     cat "${x}" >> "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
294     done
295     else
296     rm -f "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri
297     rm -f "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
298     rmdir "${ROOT}${QTDATADIR}"/mkspecs \
299     "${ROOT}${QTDATADIR}" \
300     "${ROOT}${QTHEADERDIR}"/Gentoo \
301     "${ROOT}${QTHEADERDIR}" 2>/dev/null
302     fi
303     fi
304     }
305    
306     qt4-build_pkg_postrm() {
307     generate_qconfigs
308 caleb 1.1 }
309    
310 ingmar 1.7 qt4-build_pkg_postinst() {
311     generate_qconfigs
312 yngwin 1.17 echo
313     ewarn "After a rebuild or upgrade of Qt, it can happen that Qt plugins (such as Qt"
314     ewarn "and KDE styles and widgets) can no longer be loaded. In this situation you"
315     ewarn "should recompile the packages providing these plugins. Also, make sure you"
316     ewarn "compile the Qt packages, and the packages that depend on it, with the same"
317     ewarn "GCC version and the same USE flag settings (especially the debug flag)."
318     ewarn
319     ewarn "Packages that typically need to be recompiled are kdelibs from KDE4, any"
320     ewarn "additional KDE4/Qt4 styles, qscintilla and PyQt4. Before filing a bug report,"
321     ewarn "make sure all your Qt4 packages are up-to-date and built with the same"
322     ewarn "configuration."
323     ewarn
324     ewarn "For more information, see http://doc.trolltech.com/4.4/plugins-howto.html"
325     echo
326 caleb 1.1 }
327    
328     skip_qmake_build_patch() {
329 ingmar 1.7 # Don't need to build qmake, as it's already installed from qt-core
330     sed -i -e "s:if true:if false:g" "${S}"/configure || die "Sed failed"
331 caleb 1.1 }
332    
333     skip_project_generation_patch() {
334     # Exit the script early by throwing in an exit before all of the .pro files are scanned
335 ingmar 1.7 sed -e "s:echo \"Finding:exit 0\n\necho \"Finding:g" \
336     -i "${S}"/configure || die "Sed failed"
337 caleb 1.1 }
338    
339 ingmar 1.7 symlink_binaries_to_buildtree() {
340     for bin in qmake moc uic rcc; do
341     ln -s ${QTBINDIR}/${bin} "${S}"/bin/ || die "Symlinking ${bin} to ${S}/bin failed."
342     done
343 caleb 1.1 }
344    
345     fix_library_files() {
346 ingmar 1.7 for libfile in "${D}"/${QTLIBDIR}/{*.la,*.prl,pkgconfig/*.pc}; do
347     if [[ -e ${libfile} ]]; then
348     sed -i -e "s:${S}/lib:${QTLIBDIR}:g" ${libfile} || die "Sed on ${libfile} failed."
349     fi
350     done
351 caleb 1.1
352     # pkgconfig files refer to WORKDIR/bin as the moc and uic locations. Fix:
353 ingmar 1.7 for libfile in "${D}"/${QTLIBDIR}/pkgconfig/*.pc; do
354     if [[ -e ${libfile} ]]; then
355     sed -i -e "s:${S}/bin:${QTBINDIR}:g" ${libfile} || die "Sed failed"
356 caleb 1.1
357     # Move .pc files into the pkgconfig directory
358 ingmar 1.7
359     dodir ${QTPCDIR}
360     mv ${libfile} "${D}"/${QTPCDIR}/ \
361     || die "Moving ${libfile} to ${D}/${QTPCDIR}/ failed."
362     fi
363     done
364    
365     # Don't install an empty directory
366     rmdir "${D}"/${QTLIBDIR}/pkgconfig
367 caleb 1.1 }
368    
369     qt_use() {
370 ingmar 1.7 local flag="${1}"
371     local feature="${1}"
372 caleb 1.5 local enableval=
373 caleb 1.1
374 ingmar 1.7 [[ -n ${2} ]] && feature=${2}
375     [[ -n ${3} ]] && enableval="-${3}"
376    
377     if use ${flag}; then
378     echo "${enableval}-${feature}"
379     else
380     echo "-no-${feature}"
381     fi
382     }
383    
384     # @ECLASS-VARIABLE: QT4_BUILT_WITH_USE_CHECK
385     # @DESCRIPTION:
386     # The contents of $QT4_BUILT_WITH_USE_CHECK gets fed to built_with_use
387     # (eutils.eclass), line per line.
388     #
389     # Example:
390     # @CODE
391     # pkg_setup() {
392     # use qt3support && QT4_BUILT_WITH_USE_CHECK="${QT4_BUILT_WITH_USE_CHECK}
393     # ~x11-libs/qt-gui-${PV} qt3support"
394     # qt4-build_check_use
395     # }
396     # @CODE
397    
398     # Run built_with_use on each flag and print appropriate error messages if any
399     # flags are missing
400     _qt_built_with_use() {
401     local missing opt pkg flag flags
402 caleb 1.1
403 ingmar 1.7 if [[ ${1} = "--missing" ]]; then
404     missing="${1} ${2}" && shift 2
405     fi
406     if [[ ${1:0:1} = "-" ]]; then
407     opt=${1} && shift
408     fi
409    
410     pkg=${1} && shift
411    
412     for flag in "${@}"; do
413     flags="${flags} ${flag}"
414     if ! built_with_use ${missing} ${opt} ${pkg} ${flag}; then
415     flags="${flags}*"
416     else
417     [[ ${opt} = "-o" ]] && return 0
418     fi
419     done
420     if [[ "${flags# }" = "${@}" ]]; then
421     return 0
422     fi
423     if [[ ${opt} = "-o" ]]; then
424     eerror "This package requires '${pkg}' to be built with any of the following USE flags: '$*'."
425     else
426     eerror "This package requires '${pkg}' to be built with the following USE flags: '${flags# }'."
427     fi
428     return 1
429     }
430    
431     # @FUNCTION: qt4-build_check_use
432     # @DESCRIPTION:
433     # Check if the listed packages in $QT4_BUILT_WITH_USE_CHECK are built with the
434     # USE flags listed.
435     #
436     # If any of the required USE flags are missing, an eerror will be printed for
437     # each package with missing USE flags.
438     qt4-build_check_use() {
439     local line missing
440     while read line; do
441     [[ -z ${line} ]] && continue
442     if ! _qt_built_with_use ${line}; then
443     missing=true
444     fi
445     done <<< "${QT4_BUILT_WITH_USE_CHECK}"
446     if [[ -n ${missing} ]]; then
447     echo
448     eerror "Flags marked with an * are missing."
449     die "Missing USE flags found"
450     fi
451 caleb 1.1 }
452    
453     qt_mkspecs_dir() {
454 caleb 1.5 # Allows us to define which mkspecs dir we want to use.
455     local spec
456 caleb 1.1
457 caleb 1.5 case ${CHOST} in
458     *-freebsd*|*-dragonfly*)
459     spec="freebsd" ;;
460     *-openbsd*)
461     spec="openbsd" ;;
462     *-netbsd*)
463     spec="netbsd" ;;
464 ingmar 1.7 *-darwin*)
465 caleb 1.5 spec="darwin" ;;
466     *-linux-*|*-linux)
467     spec="linux" ;;
468     *)
469 ingmar 1.7 die "Unknown CHOST, no platform choosen."
470 caleb 1.5 esac
471    
472     CXX=$(tc-getCXX)
473     if [[ ${CXX/g++/} != ${CXX} ]]; then
474     spec="${spec}-g++"
475     elif [[ ${CXX/icpc/} != ${CXX} ]]; then
476     spec="${spec}-icc"
477     else
478     die "Unknown compiler ${CXX}."
479     fi
480 caleb 1.1
481 caleb 1.5 echo "${spec}"
482 caleb 1.1 }
483    
484 ingmar 1.7 EXPORT_FUNCTIONS pkg_setup src_unpack src_compile src_install pkg_postrm pkg_postinst

  ViewVC Help
Powered by ViewVC 1.1.20