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

Contents of /eclass/qt4-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Wed Mar 5 23:06:26 2008 UTC (6 years, 5 months ago) by ingmar
Branch: MAIN
Changes since 1.6: +270 -49 lines
qt4-build.eclass: Rework eclass for Qt-4.4.0_beta1, thanks to David Leverton & Bo Andresen.

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

  ViewVC Help
Powered by ViewVC 1.1.20