Gentoo Archives: gentoo-dev

From: Sergey Popov <pinkbyte@g.o>
To: gentoo-dev@l.g.o
Cc: Davide Pesavento <pesa@g.o>
Subject: [gentoo-dev] qmake-utils.eclass: new eclass with eqmake4/eqmake5 functions
Date: Mon, 11 Nov 2013 15:33:09
Message-Id: 5280F8A6.6040503@gentoo.org
1 Some work on splitting these helper functions was done earlier, and then
2 we have got request(bug #479744), so, with ACK from pesa, i would like
3 to propose this new eclass here and some times after - another proposal
4 with making qt4-r2 eclass depends on this one to prevent code duplication.
5
6 So, here it is(directly from qt overlay):
7
8
9
10 # Copyright 1999-2013 Gentoo Foundation
11 # Distributed under the terms of the GNU General Public License v2
12 # $Header: $
13
14 # @ECLASS: qmake-utils.eclass
15 # @MAINTAINER:
16 # Qt herd <qt@g.o>
17 # @AUTHOR:
18 # Davide Pesavento <pesa@g.o>
19 # @BLURB: Common functions for qmake-based packages.
20 # @DESCRIPTION:
21 # Utility eclass providing wrapper functions for Qt4 and Qt5 qmake.
22
23 if [[ ${___ECLASS_ONCE_QMAKE_UTILS} != "recur -_+^+_- spank" ]]; then
24 ___ECLASS_ONCE_QMAKE_UTILS="recur -_+^+_- spank"
25
26 inherit eutils multilib toolchain-funcs
27
28 # @FUNCTION: qmake-utils_find_pro_file
29 # @RETURN: zero or one qmake .pro file names
30 # @INTERNAL
31 # @DESCRIPTION:
32 # Outputs a project file name that can be passed to eqmake.
33 # 0 *.pro files found --> outputs null string;
34 # 1 *.pro file found --> outputs its name;
35 # 2 or more *.pro files found --> if "${PN}.pro" or
36 # "$(basename ${S}).pro" are there, outputs one of them.
37 qmake-utils_find_pro_file() {
38 local dir_name=$(basename "${S}")
39
40 # set nullglob to avoid expanding *.pro to the literal
41 # string "*.pro" when there are no matching files
42 eshopts_push -s nullglob
43 local pro_files=(*.pro)
44 eshopts_pop
45
46 case ${#pro_files[@]} in
47 0)
48 : ;;
49 1)
50 echo "${pro_files}"
51 ;;
52 *)
53 for pro_file in "${pro_files[@]}"; do
54 if [[ ${pro_file%.pro} == ${dir_name} || ${pro_file%.pro} == ${PN}
55 ]]; then
56 echo "${pro_file}"
57 break
58 fi
59 done
60 ;;
61 esac
62 }
63
64 # @VARIABLE: EQMAKE4_EXCLUDE
65 # @DEFAULT_UNSET
66 # @DESCRIPTION:
67 # List of files to be excluded from eqmake4 CONFIG processing.
68 # Paths are relative to the current working directory (usually ${S}).
69 #
70 # Example: EQMAKE4_EXCLUDE="ignore/me.pro foo/*"
71
72 # @FUNCTION: eqmake4
73 # @USAGE: [project_file] [parameters to qmake]
74 # @DESCRIPTION:
75 # Wrapper for Qt4's qmake. If project_file isn't specified, eqmake4 will
76 # look for it in the current directory (${S}, non-recursively). If more
77 # than one project file are found, then ${PN}.pro is processed, provided
78 # that it exists. Otherwise eqmake4 fails.
79 #
80 # All other arguments are appended unmodified to qmake command line.
81 #
82 # For recursive build systems, i.e. those based on the subdirs template,
83 # you should run eqmake4 on the top-level project file only, unless you
84 # have a valid reason to do otherwise. During the building, qmake will
85 # be automatically re-invoked with the right arguments on every directory
86 # specified inside the top-level project file.
87 eqmake4() {
88 debug-print-function ${FUNCNAME} "$@"
89
90 has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
91
92 ebegin "Running qmake"
93
94 local qmake_args=("$@")
95
96 # check if project file was passed as a first argument
97 # if not, then search for it
98 local regexp='.*\.pro'
99 if ! [[ ${1} =~ ${regexp} ]]; then
100 local project_file=$(qmake-utils_find_pro_file)
101 if [[ -z ${project_file} ]]; then
102 echo
103 eerror "No project files found in '${PWD}'!"
104 eerror "This shouldn't happen - please send a bug report to
105 https://bugs.gentoo.org/"
106 echo
107 die "eqmake4 failed"
108 fi
109 qmake_args+=("${project_file}")
110 fi
111
112 # make sure CONFIG variable is correctly set
113 # for both release and debug builds
114 local config_add="release"
115 local config_remove="debug"
116 if has debug ${IUSE} && use debug; then
117 config_add="debug"
118 config_remove="release"
119 fi
120
121 local awkscript='BEGIN {
122 printf "### eqmake4 was here ###\n" > file;
123 printf "CONFIG -= debug_and_release %s\n", remove >> file;
124 printf "CONFIG += %s\n\n", add >> file;
125 fixed=0;
126 }
127 /^[[:blank:]]*CONFIG[[:blank:]]*[\+\*]?=/ {
128 if (gsub("\\<((" remove ")|(debug_and_release))\\>", "") > 0) {
129 fixed=1;
130 }
131 }
132 /^[[:blank:]]*CONFIG[[:blank:]]*-=/ {
133 if (gsub("\\<" add "\\>", "") > 0) {
134 fixed=1;
135 }
136 }
137 {
138 print >> file;
139 }
140 END {
141 print fixed;
142 }'
143
144 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_push -o noglob
145
146 local file
147 while read file; do
148 local excl
149 for excl in ${EQMAKE4_EXCLUDE}; do
150 [[ ${file} == ${excl} ]] && continue 2
151 done
152 grep -q '^### eqmake4 was here ###$' "${file}" && continue
153
154 local retval=$({
155 rm -f "${file}" || echo FAIL
156 awk -v file="${file}" \
157 -v add=${config_add} \
158 -v remove=${config_remove} \
159 -- "${awkscript}" || echo FAIL
160 } < "${file}")
161
162 if [[ ${retval} == 1 ]]; then
163 einfo " - fixed CONFIG in ${file}"
164 elif [[ ${retval} != 0 ]]; then
165 eerror " - error while processing ${file}"
166 die "eqmake4 failed to process ${file}"
167 fi
168 done < <(find . -type f -name '*.pr[io]' -printf '%P\n' 2>/dev/null)
169
170 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_pop
171
172 "${EPREFIX}"/usr/bin/qmake \
173 -makefile \
174 QTDIR="${EPREFIX}"/usr/$(get_libdir) \
175 QMAKE="${EPREFIX}"/usr/bin/qmake \
176 QMAKE_AR="$(tc-getAR) cqs" \
177 QMAKE_CC="$(tc-getCC)" \
178 QMAKE_CXX="$(tc-getCXX)" \
179 QMAKE_LINK="$(tc-getCXX)" \
180 QMAKE_LINK_C="$(tc-getCC)" \
181 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
182 QMAKE_RANLIB= \
183 QMAKE_STRIP= \
184 QMAKE_CFLAGS="${CFLAGS}" \
185 QMAKE_CFLAGS_RELEASE= \
186 QMAKE_CFLAGS_DEBUG= \
187 QMAKE_CXXFLAGS="${CXXFLAGS}" \
188 QMAKE_CXXFLAGS_RELEASE= \
189 QMAKE_CXXFLAGS_DEBUG= \
190 QMAKE_LFLAGS="${LDFLAGS}" \
191 QMAKE_LFLAGS_RELEASE= \
192 QMAKE_LFLAGS_DEBUG= \
193 QMAKE_LIBDIR_QT="${EPREFIX}"/usr/$(get_libdir)/qt4 \
194 QMAKE_LIBDIR_X11="${EPREFIX}"/usr/$(get_libdir) \
195 QMAKE_LIBDIR_OPENGL="${EPREFIX}"/usr/$(get_libdir) \
196 "${qmake_args[@]}"
197
198 # was qmake successful?
199 if ! eend $? ; then
200 echo
201 eerror "Running qmake has failed! (see above for details)"
202 eerror "This shouldn't happen - please send a bug report to
203 https://bugs.gentoo.org/"
204 echo
205 die "eqmake4 failed"
206 fi
207 }
208
209 # @FUNCTION: eqmake5
210 # @USAGE: [arguments for qmake]
211 # @DESCRIPTION:
212 # Wrapper for Qt5's qmake. All arguments are passed to qmake.
213 #
214 # For recursive build systems, i.e. those based on the subdirs template,
215 # you should run eqmake5 on the top-level project file only, unless you
216 # have a valid reason to do otherwise. During the building, qmake will
217 # be automatically re-invoked with the right arguments on every directory
218 # specified inside the top-level project file.
219 eqmake5() {
220 debug-print-function ${FUNCNAME} "$@"
221
222 has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
223
224 ebegin "Running qmake"
225
226 "${EPREFIX}"/usr/$(get_libdir)/qt5/bin/qmake \
227 -makefile \
228 QMAKE_AR="$(tc-getAR) cqs" \
229 QMAKE_CC="$(tc-getCC)" \
230 QMAKE_CXX="$(tc-getCXX)" \
231 QMAKE_LINK="$(tc-getCXX)" \
232 QMAKE_LINK_C="$(tc-getCC)" \
233 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
234 QMAKE_RANLIB= \
235 QMAKE_STRIP= \
236 QMAKE_CFLAGS="${CFLAGS}" \
237 QMAKE_CFLAGS_RELEASE= \
238 QMAKE_CFLAGS_DEBUG= \
239 QMAKE_CXXFLAGS="${CXXFLAGS}" \
240 QMAKE_CXXFLAGS_RELEASE= \
241 QMAKE_CXXFLAGS_DEBUG= \
242 QMAKE_LFLAGS="${LDFLAGS}" \
243 QMAKE_LFLAGS_RELEASE= \
244 QMAKE_LFLAGS_DEBUG= \
245 "$@"
246
247 # was qmake successful?
248 if ! eend $? ; then
249 echo
250 eerror "Running qmake has failed! (see above for details)"
251 eerror "This shouldn't happen - please send a bug report to
252 https://bugs.gentoo.org/"
253 echo
254 die "eqmake5 failed"
255 fi
256 }
257
258 fi
259
260
261 --
262 Best regards, Sergey Popov
263 Gentoo developer
264 Gentoo Desktop-effects project lead
265 Gentoo Qt project lead
266 Gentoo Proxy maintainers project lead

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies