1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: qmake-utils.eclass
8 # Davide Pesavento <pesa@gentoo.org>
9 # @BLURB: Common functions for qmake-based packages.
11 # Utility eclass providing wrapper functions for Qt4 and Qt5 qmake.
13 # This eclass does not set any metadata variables nor export any phase
14 # functions. It can be inherited safely.
16 if [[ -z ${_QMAKE_UTILS_ECLASS} ]]; then
19 [[ ${EAPI:-0} == [012345] ]] && inherit eutils multilib
20 inherit estack toolchain-funcs
22 # @FUNCTION: qt4_get_bindir
24 # Echoes the directory where Qt4 binaries are installed.
25 # EPREFIX is already prepended to the returned path.
27 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
28 has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
30 local qtbindir=${EPREFIX}$(qt4_get_libdir)/bin
31 if [[ -d ${qtbindir} ]]; then
34 echo ${EPREFIX}/usr/bin
38 # @FUNCTION: qt4_get_headerdir
40 # Echoes the directory where Qt4 headers are installed.
42 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
46 # @FUNCTION: qt4_get_libdir
48 # Echoes the directory where Qt4 libraries are installed.
50 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
51 echo /usr/$(get_libdir)/qt4
54 # @FUNCTION: qt4_get_mkspecsdir
56 # Echoes the directory where Qt4 mkspecs are installed.
57 qt4_get_mkspecsdir() {
58 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
59 echo /usr/share/qt4/mkspecs
62 # @FUNCTION: qt4_get_plugindir
64 # Echoes the directory where Qt4 plugins are installed.
66 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
67 echo $(qt4_get_libdir)/plugins
70 # @FUNCTION: qt5_get_bindir
72 # Echoes the directory where Qt5 binaries are installed.
73 # EPREFIX is already prepended to the returned path.
75 has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
77 echo ${EPREFIX}$(qt5_get_libdir)/qt5/bin
80 # @FUNCTION: qt5_get_headerdir
82 # Echoes the directory where Qt5 headers are installed.
87 # @FUNCTION: qt5_get_libdir
89 # Echoes the directory where Qt5 libraries are installed.
91 echo /usr/$(get_libdir)
94 # @FUNCTION: qt5_get_mkspecsdir
96 # Echoes the directory where Qt5 mkspecs are installed.
97 qt5_get_mkspecsdir() {
98 echo $(qt5_get_libdir)/qt5/mkspecs
101 # @FUNCTION: qt5_get_plugindir
103 # Echoes the directory where Qt5 plugins are installed.
104 qt5_get_plugindir() {
105 echo $(qt5_get_libdir)/qt5/plugins
108 # @FUNCTION: qmake-utils_find_pro_file
109 # @RETURN: zero or one qmake .pro file names
112 # Outputs a project file name that can be passed to eqmake.
113 # 0 *.pro files found --> outputs null string;
114 # 1 *.pro file found --> outputs its name;
115 # 2 or more *.pro files found --> if "${PN}.pro" or
116 # "$(basename ${S}).pro" are there, outputs one of them.
117 qmake-utils_find_pro_file() {
118 local dir_name=$(basename "${S}")
120 # set nullglob to avoid expanding *.pro to the literal
121 # string "*.pro" when there are no matching files
122 eshopts_push -s nullglob
123 local pro_files=(*.pro)
126 case ${#pro_files[@]} in
133 for pro_file in "${pro_files[@]}"; do
134 if [[ ${pro_file%.pro} == ${dir_name} || ${pro_file%.pro} == ${PN} ]]; then
143 # @VARIABLE: EQMAKE4_EXCLUDE
146 # List of files to be excluded from eqmake4 CONFIG processing.
147 # Paths are relative to the current working directory (usually ${S}).
149 # Example: EQMAKE4_EXCLUDE="ignore/me.pro foo/*"
152 # @USAGE: [project_file] [parameters to qmake]
154 # Wrapper for Qt4's qmake. If project_file is not specified, eqmake4 looks
155 # for one in the current directory (non-recursively). If multiple project
156 # files are found, then ${PN}.pro is used, if it exists, otherwise eqmake4
157 # will not be able to continue.
159 # All other arguments are appended unmodified to qmake command line.
161 # For recursive build systems, i.e. those based on the subdirs template,
162 # you should run eqmake4 on the top-level project file only, unless you
163 # have a valid reason to do otherwise. During the building, qmake will
164 # be automatically re-invoked with the right arguments on every directory
165 # specified inside the top-level project file.
167 debug-print-function ${FUNCNAME} "$@"
169 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
170 has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
172 ebegin "Running qmake"
174 local qmake_args=("$@")
176 # Check if the project file name was passed as first argument. If not, look for candidates.
177 local regexp='.*\.pro'
178 if ! [[ ${1} =~ ${regexp} ]]; then
179 local project_file=$(qmake-utils_find_pro_file)
180 if [[ -z ${project_file} ]]; then
182 eerror "No project files found in '${PWD}'"
183 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
187 qmake_args+=("${project_file}")
190 # Make sure the CONFIG variable is correctly set for both release and debug builds.
191 local config_add=release
192 local config_remove=debug
193 if in_iuse debug && use debug; then
195 config_remove=release
198 local awkscript='BEGIN {
199 printf "### eqmake4 was here ###\n" > file;
200 printf "CONFIG -= debug_and_release %s\n", remove >> file;
201 printf "CONFIG += %s\n\n", add >> file;
204 /^[[:blank:]]*CONFIG[[:blank:]]*[\+\*]?=/ {
205 if (gsub("\\<((" remove ")|(debug_and_release))\\>", "") > 0) {
209 /^[[:blank:]]*CONFIG[[:blank:]]*-=/ {
210 if (gsub("\\<" add "\\>", "") > 0) {
221 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_push -o noglob
226 for excl in ${EQMAKE4_EXCLUDE}; do
227 [[ ${file} == ${excl} ]] && continue 2
229 grep -q '^### eqmake4 was here ###$' "${file}" && continue
232 rm -f "${file}" || echo FAIL
233 awk -v file="${file}" \
234 -v add=${config_add} \
235 -v remove=${config_remove} \
236 -- "${awkscript}" || echo FAIL
239 if [[ ${retval} == 1 ]]; then
240 einfo " - fixed CONFIG in ${file}"
241 elif [[ ${retval} != 0 ]]; then
242 eerror " - error while processing ${file}"
243 die "eqmake4 failed to process ${file}"
245 done < <(find . -type f -name '*.pr[io]' -printf '%P\n' 2>/dev/null)
247 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_pop
249 "$(qt4_get_bindir)"/qmake \
251 QMAKE_AR="$(tc-getAR) cqs" \
252 QMAKE_CC="$(tc-getCC)" \
253 QMAKE_CXX="$(tc-getCXX)" \
254 QMAKE_LINK="$(tc-getCXX)" \
255 QMAKE_LINK_C="$(tc-getCC)" \
256 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
259 QMAKE_CFLAGS="${CFLAGS}" \
260 QMAKE_CFLAGS_RELEASE= \
261 QMAKE_CFLAGS_DEBUG= \
262 QMAKE_CXXFLAGS="${CXXFLAGS}" \
263 QMAKE_CXXFLAGS_RELEASE= \
264 QMAKE_CXXFLAGS_DEBUG= \
265 QMAKE_LFLAGS="${LDFLAGS}" \
266 QMAKE_LFLAGS_RELEASE= \
267 QMAKE_LFLAGS_DEBUG= \
268 QMAKE_LIBDIR_QT="${EPREFIX}$(qt4_get_libdir)" \
269 QMAKE_LIBDIR_X11="${EPREFIX}/usr/$(get_libdir)" \
270 QMAKE_LIBDIR_OPENGL="${EPREFIX}/usr/$(get_libdir)" \
275 eerror "Running qmake has failed! (see above for details)"
276 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
283 # @USAGE: [arguments for qmake]
285 # Wrapper for Qt5's qmake. All arguments are passed to qmake.
287 # For recursive build systems, i.e. those based on the subdirs template,
288 # you should run eqmake5 on the top-level project file only, unless you
289 # have a valid reason to do otherwise. During the building, qmake will
290 # be automatically re-invoked with the right arguments on every directory
291 # specified inside the top-level project file.
293 debug-print-function ${FUNCNAME} "$@"
295 ebegin "Running qmake"
297 "$(qt5_get_bindir)"/qmake \
299 QMAKE_AR="$(tc-getAR) cqs" \
300 QMAKE_CC="$(tc-getCC)" \
301 QMAKE_LINK_C="$(tc-getCC)" \
302 QMAKE_LINK_C_SHLIB="$(tc-getCC)" \
303 QMAKE_CXX="$(tc-getCXX)" \
304 QMAKE_LINK="$(tc-getCXX)" \
305 QMAKE_LINK_SHLIB="$(tc-getCXX)" \
306 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
309 QMAKE_CFLAGS="${CFLAGS}" \
310 QMAKE_CFLAGS_RELEASE= \
311 QMAKE_CFLAGS_DEBUG= \
312 QMAKE_CXXFLAGS="${CXXFLAGS}" \
313 QMAKE_CXXFLAGS_RELEASE= \
314 QMAKE_CXXFLAGS_DEBUG= \
315 QMAKE_LFLAGS="${LDFLAGS}" \
316 QMAKE_LFLAGS_RELEASE= \
317 QMAKE_LFLAGS_DEBUG= \
322 eerror "Running qmake has failed! (see above for details)"
323 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"