Gentoo Archives: gentoo-commits

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/kde-sunset:master commit in: eclass/
Date: Sat, 30 Jun 2018 08:45:23
Message-Id: 1530348302.a5d29b4cb629ce203481511a7c134dc8f46629dd.asturm@gentoo
1 commit: a5d29b4cb629ce203481511a7c134dc8f46629dd
2 Author: Andreas Sturmlechner <andreas.sturmlechner <AT> gmail <DOT> com>
3 AuthorDate: Sat Jun 30 08:29:24 2018 +0000
4 Commit: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
5 CommitDate: Sat Jun 30 08:45:02 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/kde-sunset.git/commit/?id=a5d29b4c
7
8 qmake-utils.eclass: Import from Gentoo ebuild repository
9
10 eclass/qmake-utils.eclass | 327 ++++++++++++++++++++++++++++++++++++++++++++++
11 1 file changed, 327 insertions(+)
12
13 diff --git a/eclass/qmake-utils.eclass b/eclass/qmake-utils.eclass
14 new file mode 100644
15 index 0000000..0ebd732
16 --- /dev/null
17 +++ b/eclass/qmake-utils.eclass
18 @@ -0,0 +1,327 @@
19 +# Copyright 1999-2015 Gentoo Foundation
20 +# Distributed under the terms of the GNU General Public License v2
21 +
22 +# @ECLASS: qmake-utils.eclass
23 +# @AUTHOR:
24 +# Davide Pesavento <pesa@g.o>
25 +# @BLURB: Common functions for qmake-based packages.
26 +# @DESCRIPTION:
27 +# Utility eclass providing wrapper functions for Qt4 and Qt5 qmake.
28 +#
29 +# This eclass does not set any metadata variables nor export any phase
30 +# functions. It can be inherited safely.
31 +
32 +if [[ -z ${_QMAKE_UTILS_ECLASS} ]]; then
33 +_QMAKE_UTILS_ECLASS=1
34 +
35 +[[ ${EAPI:-0} == [012345] ]] && inherit eutils multilib
36 +inherit estack toolchain-funcs
37 +
38 +# @FUNCTION: qt4_get_bindir
39 +# @DESCRIPTION:
40 +# Echoes the directory where Qt4 binaries are installed.
41 +# EPREFIX is already prepended to the returned path.
42 +qt4_get_bindir() {
43 + [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
44 + has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
45 +
46 + local qtbindir=${EPREFIX}$(qt4_get_libdir)/bin
47 + if [[ -d ${qtbindir} ]]; then
48 + echo ${qtbindir}
49 + else
50 + echo ${EPREFIX}/usr/bin
51 + fi
52 +}
53 +
54 +# @FUNCTION: qt4_get_headerdir
55 +# @DESCRIPTION:
56 +# Echoes the directory where Qt4 headers are installed.
57 +qt4_get_headerdir() {
58 + [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
59 + echo /usr/include/qt4
60 +}
61 +
62 +# @FUNCTION: qt4_get_libdir
63 +# @DESCRIPTION:
64 +# Echoes the directory where Qt4 libraries are installed.
65 +qt4_get_libdir() {
66 + [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
67 + echo /usr/$(get_libdir)/qt4
68 +}
69 +
70 +# @FUNCTION: qt4_get_mkspecsdir
71 +# @DESCRIPTION:
72 +# Echoes the directory where Qt4 mkspecs are installed.
73 +qt4_get_mkspecsdir() {
74 + [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
75 + echo /usr/share/qt4/mkspecs
76 +}
77 +
78 +# @FUNCTION: qt4_get_plugindir
79 +# @DESCRIPTION:
80 +# Echoes the directory where Qt4 plugins are installed.
81 +qt4_get_plugindir() {
82 + [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
83 + echo $(qt4_get_libdir)/plugins
84 +}
85 +
86 +# @FUNCTION: qt5_get_bindir
87 +# @DESCRIPTION:
88 +# Echoes the directory where Qt5 binaries are installed.
89 +# EPREFIX is already prepended to the returned path.
90 +qt5_get_bindir() {
91 + has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
92 +
93 + echo ${EPREFIX}$(qt5_get_libdir)/qt5/bin
94 +}
95 +
96 +# @FUNCTION: qt5_get_headerdir
97 +# @DESCRIPTION:
98 +# Echoes the directory where Qt5 headers are installed.
99 +qt5_get_headerdir() {
100 + echo /usr/include/qt5
101 +}
102 +
103 +# @FUNCTION: qt5_get_libdir
104 +# @DESCRIPTION:
105 +# Echoes the directory where Qt5 libraries are installed.
106 +qt5_get_libdir() {
107 + echo /usr/$(get_libdir)
108 +}
109 +
110 +# @FUNCTION: qt5_get_mkspecsdir
111 +# @DESCRIPTION:
112 +# Echoes the directory where Qt5 mkspecs are installed.
113 +qt5_get_mkspecsdir() {
114 + echo $(qt5_get_libdir)/qt5/mkspecs
115 +}
116 +
117 +# @FUNCTION: qt5_get_plugindir
118 +# @DESCRIPTION:
119 +# Echoes the directory where Qt5 plugins are installed.
120 +qt5_get_plugindir() {
121 + echo $(qt5_get_libdir)/qt5/plugins
122 +}
123 +
124 +# @FUNCTION: qmake-utils_find_pro_file
125 +# @RETURN: zero or one qmake .pro file names
126 +# @INTERNAL
127 +# @DESCRIPTION:
128 +# Outputs a project file name that can be passed to eqmake.
129 +# 0 *.pro files found --> outputs null string;
130 +# 1 *.pro file found --> outputs its name;
131 +# 2 or more *.pro files found --> if "${PN}.pro" or
132 +# "$(basename ${S}).pro" are there, outputs one of them.
133 +qmake-utils_find_pro_file() {
134 + local dir_name=$(basename "${S}")
135 +
136 + # set nullglob to avoid expanding *.pro to the literal
137 + # string "*.pro" when there are no matching files
138 + eshopts_push -s nullglob
139 + local pro_files=(*.pro)
140 + eshopts_pop
141 +
142 + case ${#pro_files[@]} in
143 + 0)
144 + : ;;
145 + 1)
146 + echo "${pro_files}"
147 + ;;
148 + *)
149 + for pro_file in "${pro_files[@]}"; do
150 + if [[ ${pro_file%.pro} == ${dir_name} || ${pro_file%.pro} == ${PN} ]]; then
151 + echo "${pro_file}"
152 + break
153 + fi
154 + done
155 + ;;
156 + esac
157 +}
158 +
159 +# @VARIABLE: EQMAKE4_EXCLUDE
160 +# @DEFAULT_UNSET
161 +# @DESCRIPTION:
162 +# List of files to be excluded from eqmake4 CONFIG processing.
163 +# Paths are relative to the current working directory (usually ${S}).
164 +#
165 +# Example: EQMAKE4_EXCLUDE="ignore/me.pro foo/*"
166 +
167 +# @FUNCTION: eqmake4
168 +# @USAGE: [project_file] [parameters to qmake]
169 +# @DESCRIPTION:
170 +# Wrapper for Qt4's qmake. If project_file is not specified, eqmake4 looks
171 +# for one in the current directory (non-recursively). If multiple project
172 +# files are found, then ${PN}.pro is used, if it exists, otherwise eqmake4
173 +# will not be able to continue.
174 +#
175 +# All other arguments are appended unmodified to qmake command line.
176 +#
177 +# For recursive build systems, i.e. those based on the subdirs template,
178 +# you should run eqmake4 on the top-level project file only, unless you
179 +# have a valid reason to do otherwise. During the building, qmake will
180 +# be automatically re-invoked with the right arguments on every directory
181 +# specified inside the top-level project file.
182 +eqmake4() {
183 + debug-print-function ${FUNCNAME} "$@"
184 +
185 + [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
186 + has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
187 +
188 + ebegin "Running qmake"
189 +
190 + local qmake_args=("$@")
191 +
192 + # Check if the project file name was passed as first argument. If not, look for candidates.
193 + local regexp='.*\.pro'
194 + if ! [[ ${1} =~ ${regexp} ]]; then
195 + local project_file=$(qmake-utils_find_pro_file)
196 + if [[ -z ${project_file} ]]; then
197 + echo
198 + eerror "No project files found in '${PWD}'"
199 + eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
200 + echo
201 + die "eqmake4 failed"
202 + fi
203 + qmake_args+=("${project_file}")
204 + fi
205 +
206 + # Make sure the CONFIG variable is correctly set for both release and debug builds.
207 + local config_add=release
208 + local config_remove=debug
209 + if in_iuse debug && use debug; then
210 + config_add=debug
211 + config_remove=release
212 + fi
213 +
214 + local awkscript='BEGIN {
215 + printf "### eqmake4 was here ###\n" > file;
216 + printf "CONFIG -= debug_and_release %s\n", remove >> file;
217 + printf "CONFIG += %s\n\n", add >> file;
218 + fixed=0;
219 + }
220 + /^[[:blank:]]*CONFIG[[:blank:]]*[\+\*]?=/ {
221 + if (gsub("\\<((" remove ")|(debug_and_release))\\>", "") > 0) {
222 + fixed=1;
223 + }
224 + }
225 + /^[[:blank:]]*CONFIG[[:blank:]]*-=/ {
226 + if (gsub("\\<" add "\\>", "") > 0) {
227 + fixed=1;
228 + }
229 + }
230 + {
231 + print >> file;
232 + }
233 + END {
234 + print fixed;
235 + }'
236 +
237 + [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_push -o noglob
238 +
239 + local file
240 + while read file; do
241 + local excl
242 + for excl in ${EQMAKE4_EXCLUDE}; do
243 + [[ ${file} == ${excl} ]] && continue 2
244 + done
245 + grep -q '^### eqmake4 was here ###$' "${file}" && continue
246 +
247 + local retval=$({
248 + rm -f "${file}" || echo FAIL
249 + awk -v file="${file}" \
250 + -v add=${config_add} \
251 + -v remove=${config_remove} \
252 + -- "${awkscript}" || echo FAIL
253 + } < "${file}")
254 +
255 + if [[ ${retval} == 1 ]]; then
256 + einfo " - fixed CONFIG in ${file}"
257 + elif [[ ${retval} != 0 ]]; then
258 + eerror " - error while processing ${file}"
259 + die "eqmake4 failed to process ${file}"
260 + fi
261 + done < <(find . -type f -name '*.pr[io]' -printf '%P\n' 2>/dev/null)
262 +
263 + [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_pop
264 +
265 + "$(qt4_get_bindir)"/qmake \
266 + -makefile \
267 + QMAKE_AR="$(tc-getAR) cqs" \
268 + QMAKE_CC="$(tc-getCC)" \
269 + QMAKE_CXX="$(tc-getCXX)" \
270 + QMAKE_LINK="$(tc-getCXX)" \
271 + QMAKE_LINK_C="$(tc-getCC)" \
272 + QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
273 + QMAKE_RANLIB= \
274 + QMAKE_STRIP= \
275 + QMAKE_CFLAGS="${CFLAGS}" \
276 + QMAKE_CFLAGS_RELEASE= \
277 + QMAKE_CFLAGS_DEBUG= \
278 + QMAKE_CXXFLAGS="${CXXFLAGS}" \
279 + QMAKE_CXXFLAGS_RELEASE= \
280 + QMAKE_CXXFLAGS_DEBUG= \
281 + QMAKE_LFLAGS="${LDFLAGS}" \
282 + QMAKE_LFLAGS_RELEASE= \
283 + QMAKE_LFLAGS_DEBUG= \
284 + QMAKE_LIBDIR_QT="${EPREFIX}$(qt4_get_libdir)" \
285 + QMAKE_LIBDIR_X11="${EPREFIX}/usr/$(get_libdir)" \
286 + QMAKE_LIBDIR_OPENGL="${EPREFIX}/usr/$(get_libdir)" \
287 + "${qmake_args[@]}"
288 +
289 + if ! eend $? ; then
290 + echo
291 + eerror "Running qmake has failed! (see above for details)"
292 + eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
293 + echo
294 + die "eqmake4 failed"
295 + fi
296 +}
297 +
298 +# @FUNCTION: eqmake5
299 +# @USAGE: [arguments for qmake]
300 +# @DESCRIPTION:
301 +# Wrapper for Qt5's qmake. All arguments are passed to qmake.
302 +#
303 +# For recursive build systems, i.e. those based on the subdirs template,
304 +# you should run eqmake5 on the top-level project file only, unless you
305 +# have a valid reason to do otherwise. During the building, qmake will
306 +# be automatically re-invoked with the right arguments on every directory
307 +# specified inside the top-level project file.
308 +eqmake5() {
309 + debug-print-function ${FUNCNAME} "$@"
310 +
311 + ebegin "Running qmake"
312 +
313 + "$(qt5_get_bindir)"/qmake \
314 + -makefile \
315 + QMAKE_AR="$(tc-getAR) cqs" \
316 + QMAKE_CC="$(tc-getCC)" \
317 + QMAKE_LINK_C="$(tc-getCC)" \
318 + QMAKE_LINK_C_SHLIB="$(tc-getCC)" \
319 + QMAKE_CXX="$(tc-getCXX)" \
320 + QMAKE_LINK="$(tc-getCXX)" \
321 + QMAKE_LINK_SHLIB="$(tc-getCXX)" \
322 + QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
323 + QMAKE_RANLIB= \
324 + QMAKE_STRIP= \
325 + QMAKE_CFLAGS="${CFLAGS}" \
326 + QMAKE_CFLAGS_RELEASE= \
327 + QMAKE_CFLAGS_DEBUG= \
328 + QMAKE_CXXFLAGS="${CXXFLAGS}" \
329 + QMAKE_CXXFLAGS_RELEASE= \
330 + QMAKE_CXXFLAGS_DEBUG= \
331 + QMAKE_LFLAGS="${LDFLAGS}" \
332 + QMAKE_LFLAGS_RELEASE= \
333 + QMAKE_LFLAGS_DEBUG= \
334 + "$@"
335 +
336 + if ! eend $? ; then
337 + echo
338 + eerror "Running qmake has failed! (see above for details)"
339 + eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
340 + echo
341 + die "eqmake5 failed"
342 + fi
343 +}
344 +
345 +fi