1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: qmake-utils.eclass
9 # Davide Pesavento <pesa@gentoo.org>
10 # @BLURB: Common functions for qmake-based packages.
12 # Utility eclass providing wrapper functions for Qt4 and Qt5 qmake.
14 # This eclass does not set any metadata variables nor export any phase
15 # functions. It can be inherited safely.
17 if [[ -z ${_QMAKE_UTILS_ECLASS} ]]; then
20 [[ ${EAPI:-0} == [012345] ]] && inherit multilib
21 inherit eutils toolchain-funcs
23 # @FUNCTION: qt4_get_bindir
25 # Echoes the directory where Qt4 binaries are installed.
26 # EPREFIX is already prepended to the returned path.
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.
45 # @FUNCTION: qt4_get_libdir
47 # Echoes the directory where Qt4 libraries are installed.
49 echo /usr/$(get_libdir)/qt4
52 # @FUNCTION: qt4_get_mkspecsdir
54 # Echoes the directory where Qt4 mkspecs are installed.
55 qt4_get_mkspecsdir() {
56 echo /usr/share/qt4/mkspecs
59 # @FUNCTION: qt4_get_plugindir
61 # Echoes the directory where Qt4 plugins are installed.
63 echo $(qt4_get_libdir)/plugins
66 # @FUNCTION: qt5_get_bindir
68 # Echoes the directory where Qt5 binaries are installed.
69 # EPREFIX is already prepended to the returned path.
71 has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
73 echo ${EPREFIX}$(qt5_get_libdir)/qt5/bin
76 # @FUNCTION: qt5_get_headerdir
78 # Echoes the directory where Qt5 headers are installed.
83 # @FUNCTION: qt5_get_libdir
85 # Echoes the directory where Qt5 libraries are installed.
87 echo /usr/$(get_libdir)
90 # @FUNCTION: qt5_get_mkspecsdir
92 # Echoes the directory where Qt5 mkspecs are installed.
93 qt5_get_mkspecsdir() {
94 echo $(qt5_get_libdir)/qt5/mkspecs
97 # @FUNCTION: qt5_get_plugindir
99 # Echoes the directory where Qt5 plugins are installed.
100 qt5_get_plugindir() {
101 echo $(qt5_get_libdir)/qt5/plugins
104 # @FUNCTION: qmake-utils_find_pro_file
105 # @RETURN: zero or one qmake .pro file names
108 # Outputs a project file name that can be passed to eqmake.
109 # 0 *.pro files found --> outputs null string;
110 # 1 *.pro file found --> outputs its name;
111 # 2 or more *.pro files found --> if "${PN}.pro" or
112 # "$(basename ${S}).pro" are there, outputs one of them.
113 qmake-utils_find_pro_file() {
114 local dir_name=$(basename "${S}")
116 # set nullglob to avoid expanding *.pro to the literal
117 # string "*.pro" when there are no matching files
118 eshopts_push -s nullglob
119 local pro_files=(*.pro)
122 case ${#pro_files[@]} in
129 for pro_file in "${pro_files[@]}"; do
130 if [[ ${pro_file%.pro} == ${dir_name} || ${pro_file%.pro} == ${PN} ]]; then
139 # @VARIABLE: EQMAKE4_EXCLUDE
142 # List of files to be excluded from eqmake4 CONFIG processing.
143 # Paths are relative to the current working directory (usually ${S}).
145 # Example: EQMAKE4_EXCLUDE="ignore/me.pro foo/*"
148 # @USAGE: [project_file] [parameters to qmake]
150 # Wrapper for Qt4's qmake. If project_file is not specified, eqmake4 looks
151 # for one in the current directory (non-recursively). If multiple project
152 # files are found, then ${PN}.pro is used, if it exists, otherwise eqmake4
153 # will not be able to continue.
155 # All other arguments are appended unmodified to qmake command line.
157 # For recursive build systems, i.e. those based on the subdirs template,
158 # you should run eqmake4 on the top-level project file only, unless you
159 # have a valid reason to do otherwise. During the building, qmake will
160 # be automatically re-invoked with the right arguments on every directory
161 # specified inside the top-level project file.
163 debug-print-function ${FUNCNAME} "$@"
165 has "${EAPI:-0}" 0 1 2 && use !prefix && EPREFIX=
167 ebegin "Running qmake"
169 local qmake_args=("$@")
171 # Check if the project file name was passed as first argument. If not, look for candidates.
172 local regexp='.*\.pro'
173 if ! [[ ${1} =~ ${regexp} ]]; then
174 local project_file=$(qmake-utils_find_pro_file)
175 if [[ -z ${project_file} ]]; then
177 eerror "No project files found in '${PWD}'"
178 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
182 qmake_args+=("${project_file}")
185 # Make sure the CONFIG variable is correctly set for both release and debug builds.
186 local config_add=release
187 local config_remove=debug
188 if use_if_iuse debug; then
190 config_remove=release
193 local awkscript='BEGIN {
194 printf "### eqmake4 was here ###\n" > file;
195 printf "CONFIG -= debug_and_release %s\n", remove >> file;
196 printf "CONFIG += %s\n\n", add >> file;
199 /^[[:blank:]]*CONFIG[[:blank:]]*[\+\*]?=/ {
200 if (gsub("\\<((" remove ")|(debug_and_release))\\>", "") > 0) {
204 /^[[:blank:]]*CONFIG[[:blank:]]*-=/ {
205 if (gsub("\\<" add "\\>", "") > 0) {
216 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_push -o noglob
221 for excl in ${EQMAKE4_EXCLUDE}; do
222 [[ ${file} == ${excl} ]] && continue 2
224 grep -q '^### eqmake4 was here ###$' "${file}" && continue
227 rm -f "${file}" || echo FAIL
228 awk -v file="${file}" \
229 -v add=${config_add} \
230 -v remove=${config_remove} \
231 -- "${awkscript}" || echo FAIL
234 if [[ ${retval} == 1 ]]; then
235 einfo " - fixed CONFIG in ${file}"
236 elif [[ ${retval} != 0 ]]; then
237 eerror " - error while processing ${file}"
238 die "eqmake4 failed to process ${file}"
240 done < <(find . -type f -name '*.pr[io]' -printf '%P\n' 2>/dev/null)
242 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_pop
244 "$(qt4_get_bindir)"/qmake \
246 QMAKE_AR="$(tc-getAR) cqs" \
247 QMAKE_CC="$(tc-getCC)" \
248 QMAKE_CXX="$(tc-getCXX)" \
249 QMAKE_LINK="$(tc-getCXX)" \
250 QMAKE_LINK_C="$(tc-getCC)" \
251 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
254 QMAKE_CFLAGS="${CFLAGS}" \
255 QMAKE_CFLAGS_RELEASE= \
256 QMAKE_CFLAGS_DEBUG= \
257 QMAKE_CXXFLAGS="${CXXFLAGS}" \
258 QMAKE_CXXFLAGS_RELEASE= \
259 QMAKE_CXXFLAGS_DEBUG= \
260 QMAKE_LFLAGS="${LDFLAGS}" \
261 QMAKE_LFLAGS_RELEASE= \
262 QMAKE_LFLAGS_DEBUG= \
263 QMAKE_LIBDIR_QT="${EPREFIX}$(qt4_get_libdir)" \
264 QMAKE_LIBDIR_X11="${EPREFIX}/usr/$(get_libdir)" \
265 QMAKE_LIBDIR_OPENGL="${EPREFIX}/usr/$(get_libdir)" \
270 eerror "Running qmake has failed! (see above for details)"
271 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
278 # @USAGE: [arguments for qmake]
280 # Wrapper for Qt5's qmake. All arguments are passed to qmake.
282 # For recursive build systems, i.e. those based on the subdirs template,
283 # you should run eqmake5 on the top-level project file only, unless you
284 # have a valid reason to do otherwise. During the building, qmake will
285 # be automatically re-invoked with the right arguments on every directory
286 # specified inside the top-level project file.
288 debug-print-function ${FUNCNAME} "$@"
290 ebegin "Running qmake"
292 "$(qt5_get_bindir)"/qmake \
294 QMAKE_AR="$(tc-getAR) cqs" \
295 QMAKE_CC="$(tc-getCC)" \
296 QMAKE_LINK_C="$(tc-getCC)" \
297 QMAKE_LINK_C_SHLIB="$(tc-getCC)" \
298 QMAKE_CXX="$(tc-getCXX)" \
299 QMAKE_LINK="$(tc-getCXX)" \
300 QMAKE_LINK_SHLIB="$(tc-getCXX)" \
301 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
304 QMAKE_CFLAGS="${CFLAGS}" \
305 QMAKE_CFLAGS_RELEASE= \
306 QMAKE_CFLAGS_DEBUG= \
307 QMAKE_CXXFLAGS="${CXXFLAGS}" \
308 QMAKE_CXXFLAGS_RELEASE= \
309 QMAKE_CXXFLAGS_DEBUG= \
310 QMAKE_LFLAGS="${LDFLAGS}" \
311 QMAKE_LFLAGS_RELEASE= \
312 QMAKE_LFLAGS_DEBUG= \
317 eerror "Running qmake has failed! (see above for details)"
318 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"