kde5-functions.eclass 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: kde5-functions.eclass
  4. # @MAINTAINER:
  5. # kde@gentoo.org
  6. # @BLURB: Common ebuild functions for KDE 5 packages
  7. # @DESCRIPTION:
  8. # This eclass contains all functions shared by the different eclasses,
  9. # for KDE 5 ebuilds.
  10. if [[ -z ${_KDE5_FUNCTIONS_ECLASS} ]]; then
  11. _KDE5_FUNCTIONS_ECLASS=1
  12. inherit toolchain-funcs versionator
  13. # @ECLASS-VARIABLE: EAPI
  14. # @DESCRIPTION:
  15. # Currently EAPI 6 is supported.
  16. case ${EAPI} in
  17. 6) ;;
  18. *) die "EAPI=${EAPI:-0} is not supported" ;;
  19. esac
  20. # determine the build type
  21. if [[ ${PV} = *9999* ]]; then
  22. KDE_BUILD_TYPE="live"
  23. else
  24. KDE_BUILD_TYPE="release"
  25. fi
  26. export KDE_BUILD_TYPE
  27. case ${CATEGORY} in
  28. kde-frameworks)
  29. [[ ${KDE_BUILD_TYPE} = live ]] && : ${FRAMEWORKS_MINIMAL:=9999}
  30. ;;
  31. kde-plasma)
  32. if ! [[ $(get_version_component_range 2) -le 8 && $(get_version_component_range 3) -lt 50 ]]; then
  33. : ${QT_MINIMAL:=5.7.1}
  34. fi
  35. if [[ ${KDE_BUILD_TYPE} = live ]]; then
  36. : ${FRAMEWORKS_MINIMAL:=9999}
  37. : ${QT_MINIMAL:=5.7.1}
  38. fi
  39. ;;
  40. esac
  41. # @ECLASS-VARIABLE: QT_MINIMAL
  42. # @DESCRIPTION:
  43. # Minimal Qt version to require for the package.
  44. : ${QT_MINIMAL:=5.6.1}
  45. # @ECLASS-VARIABLE: FRAMEWORKS_MINIMAL
  46. # @DESCRIPTION:
  47. # Minimal Frameworks version to require for the package.
  48. : ${FRAMEWORKS_MINIMAL:=5.29.0}
  49. # @ECLASS-VARIABLE: PLASMA_MINIMAL
  50. # @DESCRIPTION:
  51. # Minimal Plasma version to require for the package.
  52. : ${PLASMA_MINIMAL:=5.4.1}
  53. # @ECLASS-VARIABLE: KDE_APPS_MINIMAL
  54. # @DESCRIPTION:
  55. # Minimal KDE Applications version to require for the package.
  56. : ${KDE_APPS_MINIMAL:=14.12.0}
  57. # @ECLASS-VARIABLE: KDE_GCC_MINIMAL
  58. # @DEFAULT_UNSET
  59. # @DESCRIPTION:
  60. # Minimal GCC version to require for the package.
  61. # @ECLASS-VARIABLE: KDEBASE
  62. # @DESCRIPTION:
  63. # This gets set to a non-zero value when a package is considered a
  64. # kdevelop ebuild.
  65. if [[ ${KMNAME-${PN}} = kdevelop ]]; then
  66. KDEBASE=kdevelop
  67. elif [[ ${KMNAME} = kde-l10n || ${PN} = kde-l10n ]]; then
  68. KDEBASE=kdel10n
  69. fi
  70. debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
  71. # @ECLASS-VARIABLE: KDE_SCM
  72. # @DESCRIPTION:
  73. # SCM to use if this is a live ebuild.
  74. : ${KDE_SCM:=git}
  75. case ${KDE_SCM} in
  76. git) ;;
  77. *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
  78. esac
  79. # @FUNCTION: _check_gcc_version
  80. # @INTERNAL
  81. # @DESCRIPTION:
  82. # Determine if the current GCC version is acceptable, otherwise die.
  83. _check_gcc_version() {
  84. if [[ ${MERGE_TYPE} != binary && -v KDE_GCC_MINIMAL ]] && tc-is-gcc; then
  85. local version=$(gcc-version)
  86. local major=${version%.*}
  87. local minor=${version#*.}
  88. local min_major=${KDE_GCC_MINIMAL%.*}
  89. local min_minor=${KDE_GCC_MINIMAL#*.}
  90. debug-print "GCC version check activated"
  91. debug-print "Version detected:"
  92. debug-print " - Full: ${version}"
  93. debug-print " - Major: ${major}"
  94. debug-print " - Minor: ${minor}"
  95. debug-print "Version required:"
  96. debug-print " - Major: ${min_major}"
  97. debug-print " - Minor: ${min_minor}"
  98. [[ ${major} -lt ${min_major} ]] || \
  99. ( [[ ${major} -eq ${min_major} && ${minor} -lt ${min_minor} ]] ) \
  100. && die "Sorry, but gcc-${KDE_GCC_MINIMAL} or later is required for this package (found ${version})."
  101. fi
  102. }
  103. # @FUNCTION: _add_category_dep
  104. # @INTERNAL
  105. # @DESCRIPTION:
  106. # Implementation of add_plasma_dep, add_frameworks_dep, add_kdeapps_dep,
  107. # and finally, add_qt_dep.
  108. _add_category_dep() {
  109. debug-print-function ${FUNCNAME} "$@"
  110. local category=${1}
  111. local package=${2}
  112. local use=${3}
  113. local version=${4}
  114. local slot=${5}
  115. if [[ -n ${use} ]] ; then
  116. local use="[${use}]"
  117. fi
  118. if [[ -n ${version} ]] ; then
  119. local operator=">="
  120. local version="-$(get_version_component_range 1-3 ${version})"
  121. fi
  122. if [[ -n ${slot} ]] ; then
  123. slot=":${slot}"
  124. elif [[ ${SLOT%\/*} = 4 || ${SLOT%\/*} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
  125. slot=":${SLOT%\/*}"
  126. fi
  127. echo " ${operator}${category}/${package}${version}${slot}${use}"
  128. }
  129. # @FUNCTION: add_frameworks_dep
  130. # @USAGE: <package> [USE flags] [minimum version]
  131. # @DESCRIPTION:
  132. # Create proper dependency for kde-frameworks/ dependencies.
  133. # This takes 1 to 4 arguments. The first being the package name, the optional
  134. # second is additional USE flags to append, and the optional third is the
  135. # version to use instead of the automatic version (use sparingly). In addition,
  136. # the optional fourth argument defines slot+operator instead of automatic slot
  137. # (use even more sparingly).
  138. # The output of this should be added directly to DEPEND/RDEPEND, and may be
  139. # wrapped in a USE conditional (but not an || conditional without an extra set
  140. # of parentheses).
  141. add_frameworks_dep() {
  142. debug-print-function ${FUNCNAME} "$@"
  143. if [[ $# -gt 4 ]]; then
  144. die "${FUNCNAME} was called with too many arguments"
  145. fi
  146. local version
  147. if [[ -n ${3} ]]; then
  148. version=${3}
  149. elif [[ ${CATEGORY} = kde-frameworks ]]; then
  150. version=$(get_version_component_range 1-2)
  151. elif [[ -z "${version}" ]] ; then
  152. version=${FRAMEWORKS_MINIMAL}
  153. fi
  154. _add_category_dep kde-frameworks "${1}" "${2}" "${version}" "${4}"
  155. }
  156. # @FUNCTION: add_plasma_dep
  157. # @USAGE: <package> [USE flags] [minimum version]
  158. # @DESCRIPTION:
  159. # Create proper dependency for kde-plasma/ dependencies.
  160. # This takes 1 to 4 arguments. The first being the package name, the optional
  161. # second is additional USE flags to append, and the optional third is the
  162. # version to use instead of the automatic version (use sparingly). In addition,
  163. # the optional fourth argument defines slot+operator instead of automatic slot
  164. # (use even more sparingly).
  165. # The output of this should be added directly to DEPEND/RDEPEND, and may be
  166. # wrapped in a USE conditional (but not an || conditional without an extra set
  167. # of parentheses).
  168. add_plasma_dep() {
  169. debug-print-function ${FUNCNAME} "$@"
  170. if [[ $# -gt 4 ]]; then
  171. die "${FUNCNAME} was called with too many arguments"
  172. fi
  173. local version
  174. if [[ -n ${3} ]]; then
  175. version=${3}
  176. elif [[ ${CATEGORY} = kde-plasma ]]; then
  177. version=${PV}
  178. elif [[ -z "${version}" ]] ; then
  179. version=${PLASMA_MINIMAL}
  180. fi
  181. _add_category_dep kde-plasma "${1}" "${2}" "${version}" "${4}"
  182. }
  183. # @FUNCTION: add_kdeapps_dep
  184. # @USAGE: <package> [USE flags] [minimum version]
  185. # @DESCRIPTION:
  186. # Create proper dependency for kde-apps/ dependencies.
  187. # This takes 1 to 4 arguments. The first being the package name, the optional
  188. # second is additional USE flags to append, and the optional third is the
  189. # version to use instead of the automatic version (use sparingly). In addition,
  190. # the optional fourth argument defines slot+operator instead of automatic slot
  191. # (use even more sparingly).
  192. # The output of this should be added directly to DEPEND/RDEPEND, and may be
  193. # wrapped in a USE conditional (but not an || conditional without an extra set
  194. # of parentheses).
  195. add_kdeapps_dep() {
  196. debug-print-function ${FUNCNAME} "$@"
  197. if [[ $# -gt 4 ]]; then
  198. die "${FUNCNAME} was called with too many arguments"
  199. fi
  200. local version
  201. if [[ -n ${3} ]]; then
  202. version=${3}
  203. elif [[ ${CATEGORY} = kde-apps ]]; then
  204. version=${PV}
  205. elif [[ -z "${version}" ]] ; then
  206. # In KDE applications world, 5.9999 > yy.mm.x
  207. if [[ ${PV} = 5.9999 || ${PV} = 9999 ]]; then
  208. version=5.9999
  209. else
  210. version=${KDE_APPS_MINIMAL}
  211. fi
  212. fi
  213. _add_category_dep kde-apps "${1}" "${2}" "${version}" "${4}"
  214. }
  215. # @FUNCTION: add_qt_dep
  216. # @USAGE: <package> [USE flags] [minimum version]
  217. # @DESCRIPTION:
  218. # Create proper dependency for dev-qt/ dependencies.
  219. # This takes 1 to 4 arguments. The first being the package name, the optional
  220. # second is additional USE flags to append, and the optional third is the
  221. # version to use instead of the automatic version (use sparingly). In addition,
  222. # the optional fourth argument defines slot+operator instead of automatic slot
  223. # (use even more sparingly).
  224. # The output of this should be added directly to DEPEND/RDEPEND, and may be
  225. # wrapped in a USE conditional (but not an || conditional without an extra set
  226. # of parentheses).
  227. add_qt_dep() {
  228. debug-print-function ${FUNCNAME} "$@"
  229. if [[ $# -gt 4 ]]; then
  230. die "${FUNCNAME} was called with too many arguments"
  231. fi
  232. local version
  233. local slot=${4}
  234. if [[ -n ${3} ]]; then
  235. version=${3}
  236. elif [[ -z "${version}" ]]; then
  237. version=${QT_MINIMAL}
  238. fi
  239. if [[ -z ${slot} ]]; then
  240. slot="5"
  241. fi
  242. _add_category_dep dev-qt "${1}" "${2}" "${version}" "${slot}"
  243. }
  244. # @FUNCTION: get_kde_version
  245. # @DESCRIPTION:
  246. # Translates an ebuild version into a major.minor KDE SC
  247. # release version. If no version is specified, ${PV} is used.
  248. get_kde_version() {
  249. local ver=${1:-${PV}}
  250. local major=$(get_major_version ${ver})
  251. local minor=$(get_version_component_range 2 ${ver})
  252. local micro=$(get_version_component_range 3 ${ver})
  253. if [[ ${ver} == 9999 ]]; then
  254. echo live
  255. else
  256. (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
  257. fi
  258. }
  259. # @FUNCTION: kde_l10n2lingua
  260. # @USAGE: <l10n>...
  261. # @INTERNAL
  262. # @DESCRIPTION:
  263. # Output KDE lingua flag name(s) (without prefix(es)) appropriate for
  264. # given l10n(s).
  265. kde_l10n2lingua() {
  266. local l
  267. for l; do
  268. case ${l} in
  269. ca-valencia) echo ca@valencia;;
  270. sr-ijekavsk) echo sr@ijekavian;;
  271. sr-Latn-ijekavsk) echo sr@ijekavianlatin;;
  272. sr-Latn) echo sr@latin;;
  273. uz-Cyrl) echo uz@cyrillic;;
  274. *) echo "${l/-/_}";;
  275. esac
  276. done
  277. }
  278. # @FUNCTION: punt_bogus_dep
  279. # @USAGE: <prefix> <dependency>
  280. # @DESCRIPTION:
  281. # Removes a specified dependency from a find_package call with multiple components.
  282. punt_bogus_dep() {
  283. local prefix=${1}
  284. local dep=${2}
  285. if [[ ! -e "CMakeLists.txt" ]]; then
  286. return
  287. fi
  288. pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
  289. # pcregrep returns non-zero on no matches/error
  290. if [[ $? != 0 ]] ; then
  291. return
  292. fi
  293. local length=$(wc -l "${T}/bogus${dep}" | cut -d " " -f 1)
  294. local first=$(head -n 1 "${T}/bogus${dep}" | cut -d ":" -f 1)
  295. local last=$(( ${length} + ${first} - 1))
  296. sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
  297. if [[ ${length} = 1 ]] ; then
  298. sed -e "/find_package\s*(\s*${prefix}\(\s\+\(REQUIRED\|CONFIG\|COMPONENTS\|\${[A-Z0-9_]*}\)\)\+\s*)/Is/^/# removed by kde5-functions.eclass - /" -i CMakeLists.txt || die
  299. fi
  300. }
  301. fi