1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: qmake-utils.eclass
8 # Davide Pesavento <pesa@gentoo.org>
9 # @SUPPORTED_EAPIS: 6 7
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] ]] && die "qmake-utils.eclass: unsupported EAPI=${EAPI:-0}"
22 inherit estack toolchain-funcs
24 # @FUNCTION: qt4_get_bindir
26 # Echoes the directory where Qt4 binaries are installed.
27 # EPREFIX is already prepended to the returned path.
29 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
31 local qtbindir=${EPREFIX}$(qt4_get_libdir)/bin
32 if [[ -d ${qtbindir} ]]; then
35 echo ${EPREFIX}/usr/bin
39 # @FUNCTION: qt4_get_headerdir
41 # Echoes the directory where Qt4 headers are installed.
43 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
47 # @FUNCTION: qt4_get_libdir
49 # Echoes the directory where Qt4 libraries are installed.
51 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
52 echo /usr/$(get_libdir)/qt4
55 # @FUNCTION: qt4_get_mkspecsdir
57 # Echoes the directory where Qt4 mkspecs are installed.
58 qt4_get_mkspecsdir() {
59 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
60 echo /usr/share/qt4/mkspecs
63 # @FUNCTION: qt4_get_plugindir
65 # Echoes the directory where Qt4 plugins are installed.
67 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
68 echo $(qt4_get_libdir)/plugins
71 # @FUNCTION: qt5_get_bindir
73 # Echoes the directory where Qt5 binaries are installed.
74 # EPREFIX is already prepended to the returned path.
76 echo ${EPREFIX}$(qt5_get_libdir)/qt5/bin
79 # @FUNCTION: qt5_get_headerdir
81 # Echoes the directory where Qt5 headers are installed.
86 # @FUNCTION: qt5_get_libdir
88 # Echoes the directory where Qt5 libraries are installed.
90 echo /usr/$(get_libdir)
93 # @FUNCTION: qt5_get_mkspecsdir
95 # Echoes the directory where Qt5 mkspecs are installed.
96 qt5_get_mkspecsdir() {
97 echo $(qt5_get_libdir)/qt5/mkspecs
100 # @FUNCTION: qt5_get_plugindir
102 # Echoes the directory where Qt5 plugins are installed.
103 qt5_get_plugindir() {
104 echo $(qt5_get_libdir)/qt5/plugins
107 # @FUNCTION: qmake-utils_find_pro_file
108 # @RETURN: zero or one qmake .pro file names
111 # Outputs a project file name that can be passed to eqmake.
112 # 0 *.pro files found --> outputs null string;
113 # 1 *.pro file found --> outputs its name;
114 # 2 or more *.pro files found --> if "${PN}.pro" or
115 # "$(basename ${S}).pro" are there, outputs one of them.
116 qmake-utils_find_pro_file() {
117 local dir_name=$(basename "${S}")
119 # set nullglob to avoid expanding *.pro to the literal
120 # string "*.pro" when there are no matching files
121 eshopts_push -s nullglob
122 local pro_files=(*.pro)
125 case ${#pro_files[@]} in
132 for pro_file in "${pro_files[@]}"; do
133 if [[ ${pro_file%.pro} == ${dir_name} || ${pro_file%.pro} == ${PN} ]]; then
142 # @VARIABLE: EQMAKE4_EXCLUDE
145 # List of files to be excluded from eqmake4 CONFIG processing.
146 # Paths are relative to the current working directory (usually ${S}).
148 # Example: EQMAKE4_EXCLUDE="ignore/me.pro foo/*"
151 # @USAGE: [project_file] [parameters to qmake]
153 # Wrapper for Qt4's qmake. If project_file is not specified, eqmake4 looks
154 # for one in the current directory (non-recursively). If multiple project
155 # files are found, then ${PN}.pro is used, if it exists, otherwise eqmake4
156 # will not be able to continue.
158 # All other arguments are appended unmodified to qmake command line.
160 # For recursive build systems, i.e. those based on the subdirs template,
161 # you should run eqmake4 on the top-level project file only, unless you
162 # have a valid reason to do otherwise. During the building, qmake will
163 # be automatically re-invoked with the right arguments on every directory
164 # specified inside the top-level project file.
166 debug-print-function ${FUNCNAME} "$@"
168 [[ ${EAPI:-0} == [0123456] ]] || die "${FUNCNAME[1]} is banned in EAPI 7 and later"
170 ebegin "Running qmake"
172 local qmake_args=("$@")
174 # Check if the project file name was passed as first argument. If not, look for candidates.
175 local regexp='.*\.pro'
176 if ! [[ ${1} =~ ${regexp} ]]; then
177 local project_file=$(qmake-utils_find_pro_file)
178 if [[ -z ${project_file} ]]; then
180 eerror "No project files found in '${PWD}'"
181 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
185 qmake_args+=("${project_file}")
188 # Make sure the CONFIG variable is correctly set for both release and debug builds.
189 local config_add=release
190 local config_remove=debug
191 if in_iuse debug && use debug; then
193 config_remove=release
196 local awkscript='BEGIN {
197 printf "### eqmake4 was here ###\n" > file;
198 printf "CONFIG -= debug_and_release %s\n", remove >> file;
199 printf "CONFIG += %s\n\n", add >> file;
202 /^[[:blank:]]*CONFIG[[:blank:]]*[\+\*]?=/ {
203 if (gsub("\\<((" remove ")|(debug_and_release))\\>", "") > 0) {
207 /^[[:blank:]]*CONFIG[[:blank:]]*-=/ {
208 if (gsub("\\<" add "\\>", "") > 0) {
219 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_push -o noglob
224 for excl in ${EQMAKE4_EXCLUDE}; do
225 [[ ${file} == ${excl} ]] && continue 2
227 grep -q '^### eqmake4 was here ###$' "${file}" && continue
230 rm -f "${file}" || echo FAIL
231 awk -v file="${file}" \
232 -v add=${config_add} \
233 -v remove=${config_remove} \
234 -- "${awkscript}" || echo FAIL
237 if [[ ${retval} == 1 ]]; then
238 einfo " - fixed CONFIG in ${file}"
239 elif [[ ${retval} != 0 ]]; then
240 eerror " - error while processing ${file}"
241 die "eqmake4 failed to process ${file}"
243 done < <(find . -type f -name '*.pr[io]' -printf '%P\n' 2>/dev/null)
245 [[ -n ${EQMAKE4_EXCLUDE} ]] && eshopts_pop
247 "$(qt4_get_bindir)"/qmake \
249 QMAKE_AR="$(tc-getAR) cqs" \
250 QMAKE_CC="$(tc-getCC)" \
251 QMAKE_CXX="$(tc-getCXX)" \
252 QMAKE_LINK="$(tc-getCXX)" \
253 QMAKE_LINK_C="$(tc-getCC)" \
254 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
257 QMAKE_CFLAGS="${CFLAGS}" \
258 QMAKE_CFLAGS_RELEASE= \
259 QMAKE_CFLAGS_DEBUG= \
260 QMAKE_CXXFLAGS="${CXXFLAGS}" \
261 QMAKE_CXXFLAGS_RELEASE= \
262 QMAKE_CXXFLAGS_DEBUG= \
263 QMAKE_LFLAGS="${LDFLAGS}" \
264 QMAKE_LFLAGS_RELEASE= \
265 QMAKE_LFLAGS_DEBUG= \
266 QMAKE_LIBDIR_QT="${EPREFIX}$(qt4_get_libdir)" \
267 QMAKE_LIBDIR_X11="${EPREFIX}/usr/$(get_libdir)" \
268 QMAKE_LIBDIR_OPENGL="${EPREFIX}/usr/$(get_libdir)" \
273 eerror "Running qmake has failed! (see above for details)"
274 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"
281 # @USAGE: [arguments for qmake]
283 # Wrapper for Qt5's qmake. All arguments are passed to qmake.
285 # For recursive build systems, i.e. those based on the subdirs template,
286 # you should run eqmake5 on the top-level project file only, unless you
287 # have a valid reason to do otherwise. During the building, qmake will
288 # be automatically re-invoked with the right arguments on every directory
289 # specified inside the top-level project file.
291 debug-print-function ${FUNCNAME} "$@"
293 ebegin "Running qmake"
295 "$(qt5_get_bindir)"/qmake \
297 QMAKE_AR="$(tc-getAR) cqs" \
298 QMAKE_CC="$(tc-getCC)" \
299 QMAKE_LINK_C="$(tc-getCC)" \
300 QMAKE_LINK_C_SHLIB="$(tc-getCC)" \
301 QMAKE_CXX="$(tc-getCXX)" \
302 QMAKE_LINK="$(tc-getCXX)" \
303 QMAKE_LINK_SHLIB="$(tc-getCXX)" \
304 QMAKE_OBJCOPY="$(tc-getOBJCOPY)" \
307 QMAKE_CFLAGS="${CFLAGS}" \
308 QMAKE_CFLAGS_RELEASE= \
309 QMAKE_CFLAGS_DEBUG= \
310 QMAKE_CXXFLAGS="${CXXFLAGS}" \
311 QMAKE_CXXFLAGS_RELEASE= \
312 QMAKE_CXXFLAGS_DEBUG= \
313 QMAKE_LFLAGS="${LDFLAGS}" \
314 QMAKE_LFLAGS_RELEASE= \
315 QMAKE_LFLAGS_DEBUG= \
320 eerror "Running qmake has failed! (see above for details)"
321 eerror "This shouldn't happen - please send a bug report to https://bugs.gentoo.org/"