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

Contents of /eclass/qt4-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Thu Mar 6 14:44:13 2008 UTC (6 years, 5 months ago) by zlin
Branch: MAIN
Changes since 1.8: +5 -3 lines
Only install qconfig.pri if one of QCONFIG_{ADD,REMOVE} is non-empty (bug #212491).

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

  ViewVC Help
Powered by ViewVC 1.1.20