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

Contents of /eclass/qt4-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations) (download)
Tue Mar 11 16:39:43 2008 UTC (6 years, 4 months ago) by ingmar
Branch: MAIN
Changes since 1.9: +7 -1 lines
append-flags -fno-gcse for on amd64 with gcc 3, bug 178652.

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 ingmar 1.10 # $Header: /var/cvsroot/gentoo-x86/eclass/qt4-build.eclass,v 1.9 2008/03/06 14:44:13 zlin 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     IUSE="${IUSE} debug"
15    
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     *)
22     SRCTYPE="${SRCTYPE:-opensource-src}"
23     MY_PV="${PV}"
24     ;;
25     esac
26     S=${WORKDIR}/qt-x11-${SRCTYPE}-${MY_PV}
27    
28     SRC_URI="ftp://ftp.trolltech.com/qt/source/qt-x11-${SRCTYPE}-${MY_PV}.tar.bz2"
29    
30 caleb 1.1 qt4-build_pkg_setup() {
31 ingmar 1.7 # Check USE requirements
32     qt4-build_check_use
33    
34 caleb 1.1 # Set up installation directories
35 caleb 1.5 QTBASEDIR=/usr/$(get_libdir)/qt4
36     QTPREFIXDIR=/usr
37     QTBINDIR=/usr/bin
38     QTLIBDIR=/usr/$(get_libdir)/qt4
39     QTPCDIR=/usr/$(get_libdir)/pkgconfig
40     QTDATADIR=/usr/share/qt4
41 caleb 1.6 QTDOCDIR=/usr/share/doc/qt-${PV}
42 caleb 1.5 QTHEADERDIR=/usr/include/qt4
43     QTPLUGINDIR=${QTLIBDIR}/plugins
44     QTSYSCONFDIR=/etc/qt4
45     QTTRANSDIR=${QTDATADIR}/translations
46     QTEXAMPLESDIR=${QTDATADIR}/examples
47     QTDEMOSDIR=${QTDATADIR}/demos
48 caleb 1.1
49 caleb 1.5 PLATFORM=$(qt_mkspecs_dir)
50 caleb 1.1
51     PATH="${S}/bin:${PATH}"
52     LD_LIBRARY_PATH="${S}/lib:${LD_LIBRARY_PATH}"
53     }
54    
55     qt4-build_src_unpack() {
56 ingmar 1.7 # TODO: partial unpacks, cfr split KDE ebuilds.
57 caleb 1.1 unpack ${A}
58     cd "${S}"
59    
60 ingmar 1.7 if [[ ${PN} != qt-core ]]; then
61     skip_qmake_build_patch
62     skip_project_generation_patch
63     symlink_binaries_to_buildtree
64     fi
65    
66     sed -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
67     -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
68     -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=${LDFLAGS}:" \
69     -e "s:X11R6/::" \
70     -i "${S}"/mkspecs/$(qt_mkspecs_dir)/qmake.conf || die "sed ${S}/mkspecs/$(qt_mkspecs_dir)/qmake.conf failed"
71    
72     sed -e "s:QMAKE_CFLAGS_RELEASE.*=.*:QMAKE_CFLAGS_RELEASE=${CFLAGS}:" \
73     -e "s:QMAKE_CXXFLAGS_RELEASE.*=.*:QMAKE_CXXFLAGS_RELEASE=${CXXFLAGS}:" \
74     -e "s:QMAKE_LFLAGS_RELEASE.*=.*:QMAKE_LFLAGS_RELEASE=${LDFLAGS}:" \
75     -i "${S}"/mkspecs/common/g++.conf || die "sed ${S}/mkspecs/common/g++.conf failed"
76     }
77    
78     qt4-build_src_compile() {
79 caleb 1.1 # Don't let the user go too overboard with flags. If you really want to, uncomment
80     # out the line below and give 'er a whirl.
81     strip-flags
82     replace-flags -O3 -O2
83    
84 ingmar 1.7 if [[ $(gcc-fullversion) == "3.4.6" && gcc-specs-ssp ]] ; then
85 caleb 1.1 ewarn "Appending -fno-stack-protector to CFLAGS/CXXFLAGS"
86     append-flags -fno-stack-protector
87     fi
88 ingmar 1.7
89 ingmar 1.10 # Bug 178652
90     if [[ "$(gcc-major-version)" == "3" ]] && use amd64; then
91     ewarn "Appending -fno-gcse to CFLAGS/CXXFLAGS"
92     append-flags -fno-gcse
93     fi
94    
95 ingmar 1.7 myconf="$(standard_configure_options) ${myconf}"
96    
97     echo ./configure ${myconf}
98     ./configure ${myconf} || die "./configure failed"
99    
100     build_target_directories
101 caleb 1.1 }
102    
103 caleb 1.4 qt4-build_src_install() {
104     install_directories "${QT4_TARGET_DIRECTORIES}"
105 ingmar 1.7 install_qconfigs
106 caleb 1.4 fix_library_files
107     }
108    
109 caleb 1.1 standard_configure_options() {
110     local myconf=""
111    
112 ingmar 1.7 [[ $(get_libdir) != "lib" ]] && myconf="${myconf} -L/usr/$(get_libdir)"
113 caleb 1.1
114     # Disable visibility explicitly if gcc version isn't 4
115 ingmar 1.7 if [[ "$(gcc-major-version)" -lt "4" ]]; then
116 caleb 1.1 myconf="${myconf} -no-reduce-exports"
117     fi
118    
119 ingmar 1.7 if use debug; then
120     myconf="${myconf} -debug -no-separate-debug-info"
121     else
122     myconf="${myconf} -release -no-separate-debug-info"
123     fi
124 caleb 1.1
125 ingmar 1.7 myconf="${myconf} -stl -verbose -largefile -confirm-license -no-rpath
126     -prefix ${QTPREFIXDIR} -bindir ${QTBINDIR} -libdir ${QTLIBDIR}
127     -datadir ${QTDATADIR} -docdir ${QTDOCDIR} -headerdir ${QTHEADERDIR}
128     -plugindir ${QTPLUGINDIR} -sysconfdir ${QTSYSCONFDIR}
129     -translationdir ${QTTRANSDIR} -examplesdir ${QTEXAMPLESDIR}
130     -demosdir ${QTDEMOSDIR} -silent -fast -reduce-relocations
131     -nomake examples -nomake demos"
132 caleb 1.1
133     echo "${myconf}"
134     }
135    
136 caleb 1.4 build_target_directories() {
137     build_directories "${QT4_TARGET_DIRECTORIES}"
138     }
139    
140 caleb 1.1 build_directories() {
141     local dirs="$@"
142     for x in ${dirs}; do
143     cd "${S}"/${x}
144 ingmar 1.7 "${S}"/bin/qmake "LIBS+=-L${QTLIBDIR}" "CONFIG+=nostrip" || die "qmake failed"
145     emake || die "emake failed"
146 caleb 1.1 done
147     }
148    
149     install_directories() {
150     local dirs="$@"
151     for x in ${dirs}; do
152 ingmar 1.7 pushd "${S}"/${x} >/dev/null || die "Can't pushd ${S}/${x}"
153     emake INSTALL_ROOT="${D}" install || die "emake install failed"
154     popd >/dev/null || die "Can't popd from ${S}/${x}"
155 caleb 1.1 done
156     }
157    
158 ingmar 1.7 # @ECLASS-VARIABLE: QCONFIG_ADD
159     # @DESCRIPTION:
160     # List options that need to be added to QT_CONFIG in qconfig.pri
161     QCONFIG_ADD="${QCONFIG_ADD:-}"
162    
163     # @ECLASS-VARIABLE: QCONFIG_REMOVE
164     # @DESCRIPTION:
165     # List options that need to be removed from QT_CONFIG in qconfig.pri
166     QCONFIG_REMOVE="${QCONFIG_REMOVE:-}"
167    
168     # @ECLASS-VARIABLE: QCONFIG_DEFINE
169     # @DESCRIPTION:
170     # List variables that should be defined at the top of QtCore/qconfig.h
171     QCONFIG_DEFINE="${QCONFIG_DEFINE:-}"
172    
173     install_qconfigs() {
174 zlin 1.9 local x
175     if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} ]]; then
176 ingmar 1.7 for x in QCONFIG_ADD QCONFIG_REMOVE; do
177     [[ -n ${!x} ]] && echo ${x}=${!x} >> "${T}"/${PN}-qconfig.pri
178     done
179     insinto ${QTDATADIR}/mkspecs/gentoo
180     doins "${T}"/${PN}-qconfig.pri || die "installing ${PN}-qconfig.pri failed"
181 zlin 1.9 fi
182 ingmar 1.7
183 zlin 1.9 if [[ -n ${QCONFIG_DEFINE} ]]; then
184 ingmar 1.7 for x in ${QCONFIG_DEFINE}; do
185     echo "#define ${x}" >> "${T}"/gentoo-${PN}-qconfig.h
186     done
187     insinto ${QTHEADERDIR}/Gentoo
188     doins "${T}"/gentoo-${PN}-qconfig.h || die "installing ${PN}-qconfig.h failed"
189     fi
190     }
191    
192     # Stubs for functions used by the Qt 4.4.0_technical_preview_1.
193     qconfig_add_option() { : ; }
194     qconfig_remove_option() { : ; }
195    
196     generate_qconfigs() {
197     if [[ -n ${QCONFIG_ADD} || -n ${QCONFIG_REMOVE} || -n ${QCONFIG_DEFINE} || ${CATEGORY}/${PN} == x11-libs/qt-core ]]; then
198     local x qconfig_add qconfig_remove qconfig_new
199     for x in "${ROOT}${QTDATADIR}"/mkspecs/gentoo/*-qconfig.pri; do
200     [[ -f ${x} ]] || continue
201     qconfig_add="${qconfig_add} $(sed -n 's/^QCONFIG_ADD=//p' "${x}")"
202     qconfig_remove="${qconfig_remove} $(sed -n 's/^QCONFIG_REMOVE=//p' "${x}")"
203     done
204    
205     # these error checks do not use die because dying in pkg_post{inst,rm}
206     # just makes things worse.
207     if [[ -e "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri ]]; then
208     # start with the qconfig.pri that qt-core installed
209     if ! cp "${ROOT}${QTDATADIR}"/mkspecs/gentoo/qconfig.pri \
210     "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
211     eerror "cp qconfig failed."
212     return 1
213     fi
214    
215     # generate list of QT_CONFIG entries from the existing list
216     # including qconfig_add and excluding qconfig_remove
217     for x in $(sed -n 's/^QT_CONFIG +=//p' \
218     "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri) ${qconfig_add}; do
219     hasq ${x} ${qconfig_remove} || qconfig_new="${qconfig_new} ${x}"
220     done
221    
222     # replace the existing QT_CONFIG list with qconfig_new
223     if ! sed -i -e "s/QT_CONFIG +=.*/QT_CONFIG += ${qconfig_new}/" \
224     "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri; then
225     eerror "Sed for QT_CONFIG failed"
226     return 1
227     fi
228    
229     # create Gentoo/qconfig.h
230     if [[ ! -e ${ROOT}${QTHEADERDIR}/Gentoo ]]; then
231     if ! mkdir -p "${ROOT}${QTHEADERDIR}"/Gentoo; then
232     eerror "mkdir ${QTHEADERDIR}/Gentoo failed"
233     return 1
234     fi
235     fi
236     : > "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
237     for x in "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-*-qconfig.h; do
238     [[ -f ${x} ]] || continue
239     cat "${x}" >> "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
240     done
241     else
242     rm -f "${ROOT}${QTDATADIR}"/mkspecs/qconfig.pri
243     rm -f "${ROOT}${QTHEADERDIR}"/Gentoo/gentoo-qconfig.h
244     rmdir "${ROOT}${QTDATADIR}"/mkspecs \
245     "${ROOT}${QTDATADIR}" \
246     "${ROOT}${QTHEADERDIR}"/Gentoo \
247     "${ROOT}${QTHEADERDIR}" 2>/dev/null
248     fi
249     fi
250     }
251    
252     qt4-build_pkg_postrm() {
253     generate_qconfigs
254 caleb 1.1 }
255    
256 ingmar 1.7 qt4-build_pkg_postinst() {
257     generate_qconfigs
258 caleb 1.1 }
259    
260     skip_qmake_build_patch() {
261 ingmar 1.7 # Don't need to build qmake, as it's already installed from qt-core
262     sed -i -e "s:if true:if false:g" "${S}"/configure || die "Sed failed"
263 caleb 1.1 }
264    
265     skip_project_generation_patch() {
266     # Exit the script early by throwing in an exit before all of the .pro files are scanned
267 ingmar 1.7 sed -e "s:echo \"Finding:exit 0\n\necho \"Finding:g" \
268     -i "${S}"/configure || die "Sed failed"
269 caleb 1.1 }
270    
271 ingmar 1.7 symlink_binaries_to_buildtree() {
272     for bin in qmake moc uic rcc; do
273     ln -s ${QTBINDIR}/${bin} "${S}"/bin/ || die "Symlinking ${bin} to ${S}/bin failed."
274     done
275 caleb 1.1 }
276    
277     fix_library_files() {
278 ingmar 1.7 for libfile in "${D}"/${QTLIBDIR}/{*.la,*.prl,pkgconfig/*.pc}; do
279     if [[ -e ${libfile} ]]; then
280     sed -i -e "s:${S}/lib:${QTLIBDIR}:g" ${libfile} || die "Sed on ${libfile} failed."
281     fi
282     done
283 caleb 1.1
284     # pkgconfig files refer to WORKDIR/bin as the moc and uic locations. Fix:
285 ingmar 1.7 for libfile in "${D}"/${QTLIBDIR}/pkgconfig/*.pc; do
286     if [[ -e ${libfile} ]]; then
287     sed -i -e "s:${S}/bin:${QTBINDIR}:g" ${libfile} || die "Sed failed"
288 caleb 1.1
289     # Move .pc files into the pkgconfig directory
290 ingmar 1.7
291     dodir ${QTPCDIR}
292     mv ${libfile} "${D}"/${QTPCDIR}/ \
293     || die "Moving ${libfile} to ${D}/${QTPCDIR}/ failed."
294     fi
295     done
296    
297     # Don't install an empty directory
298     rmdir "${D}"/${QTLIBDIR}/pkgconfig
299 caleb 1.1 }
300    
301     qt_use() {
302 ingmar 1.7 local flag="${1}"
303     local feature="${1}"
304 caleb 1.5 local enableval=
305 caleb 1.1
306 ingmar 1.7 [[ -n ${2} ]] && feature=${2}
307     [[ -n ${3} ]] && enableval="-${3}"
308    
309     if use ${flag}; then
310     echo "${enableval}-${feature}"
311     else
312     echo "-no-${feature}"
313     fi
314     }
315    
316     # @ECLASS-VARIABLE: QT4_BUILT_WITH_USE_CHECK
317     # @DESCRIPTION:
318     # The contents of $QT4_BUILT_WITH_USE_CHECK gets fed to built_with_use
319     # (eutils.eclass), line per line.
320     #
321     # Example:
322     # @CODE
323     # pkg_setup() {
324     # use qt3support && QT4_BUILT_WITH_USE_CHECK="${QT4_BUILT_WITH_USE_CHECK}
325     # ~x11-libs/qt-gui-${PV} qt3support"
326     # qt4-build_check_use
327     # }
328     # @CODE
329    
330     # Run built_with_use on each flag and print appropriate error messages if any
331     # flags are missing
332     _qt_built_with_use() {
333     local missing opt pkg flag flags
334 caleb 1.1
335 ingmar 1.7 if [[ ${1} = "--missing" ]]; then
336     missing="${1} ${2}" && shift 2
337     fi
338     if [[ ${1:0:1} = "-" ]]; then
339     opt=${1} && shift
340     fi
341    
342     pkg=${1} && shift
343    
344     for flag in "${@}"; do
345     flags="${flags} ${flag}"
346     if ! built_with_use ${missing} ${opt} ${pkg} ${flag}; then
347     flags="${flags}*"
348     else
349     [[ ${opt} = "-o" ]] && return 0
350     fi
351     done
352     if [[ "${flags# }" = "${@}" ]]; then
353     return 0
354     fi
355     if [[ ${opt} = "-o" ]]; then
356     eerror "This package requires '${pkg}' to be built with any of the following USE flags: '$*'."
357     else
358     eerror "This package requires '${pkg}' to be built with the following USE flags: '${flags# }'."
359     fi
360     return 1
361     }
362    
363     # @FUNCTION: qt4-build_check_use
364     # @DESCRIPTION:
365     # Check if the listed packages in $QT4_BUILT_WITH_USE_CHECK are built with the
366     # USE flags listed.
367     #
368     # If any of the required USE flags are missing, an eerror will be printed for
369     # each package with missing USE flags.
370     qt4-build_check_use() {
371     local line missing
372     while read line; do
373     [[ -z ${line} ]] && continue
374     if ! _qt_built_with_use ${line}; then
375     missing=true
376     fi
377     done <<< "${QT4_BUILT_WITH_USE_CHECK}"
378     if [[ -n ${missing} ]]; then
379     echo
380     eerror "Flags marked with an * are missing."
381     die "Missing USE flags found"
382     fi
383 caleb 1.1 }
384    
385     qt_mkspecs_dir() {
386 caleb 1.5 # Allows us to define which mkspecs dir we want to use.
387     local spec
388 caleb 1.1
389 caleb 1.5 case ${CHOST} in
390     *-freebsd*|*-dragonfly*)
391     spec="freebsd" ;;
392     *-openbsd*)
393     spec="openbsd" ;;
394     *-netbsd*)
395     spec="netbsd" ;;
396 ingmar 1.7 *-darwin*)
397 caleb 1.5 spec="darwin" ;;
398     *-linux-*|*-linux)
399     spec="linux" ;;
400     *)
401 ingmar 1.7 die "Unknown CHOST, no platform choosen."
402 caleb 1.5 esac
403    
404     CXX=$(tc-getCXX)
405     if [[ ${CXX/g++/} != ${CXX} ]]; then
406     spec="${spec}-g++"
407     elif [[ ${CXX/icpc/} != ${CXX} ]]; then
408     spec="${spec}-icc"
409     else
410     die "Unknown compiler ${CXX}."
411     fi
412 caleb 1.1
413 caleb 1.5 echo "${spec}"
414 caleb 1.1 }
415    
416 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