qmake-utils.eclass 8.5 KB

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