kde4-functions.eclass 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: kde4-functions.eclass
  4. # @MAINTAINER:
  5. # kde@gentoo.org
  6. # @BLURB: Common ebuild functions for KDE 4 packages
  7. # @DESCRIPTION:
  8. # This eclass contains all functions shared by the different eclasses,
  9. # for KDE 4 ebuilds.
  10. if [[ -z ${_KDE4_FUNCTIONS_ECLASS} ]]; then
  11. _KDE4_FUNCTIONS_ECLASS=1
  12. inherit versionator
  13. # @ECLASS-VARIABLE: EAPI
  14. # @DESCRIPTION:
  15. # Currently kde4 eclasses support EAPI 5 and 6.
  16. case ${EAPI} in
  17. 5|6) : ;;
  18. *) die "EAPI=${EAPI:-0} is not supported" ;;
  19. esac
  20. # @ECLASS-VARIABLE: KDE_OVERRIDE_MINIMAL
  21. # @DESCRIPTION:
  22. # For use only in very few well-defined cases; normally it should be unset.
  23. # If this variable is set, all calls to add_kdebase_dep return a dependency on
  24. # at least this version, independent of the version of the package itself.
  25. # If you know exactly that one specific NEW KDE component builds and runs fine
  26. # with all the rest of KDE at an OLDER version, you can set this old version here.
  27. # Warning- may lead to general instability and kill your pet targh.
  28. # @ECLASS-VARIABLE: KDEBASE
  29. # @DESCRIPTION:
  30. # This gets set to a non-zero value when a package is considered a kde or
  31. # kdevelop ebuild.
  32. if [[ ${CATEGORY} = kde-base || ${CATEGORY} == kde-plasma || ${CATEGORY} = kde-apps || ${CATEGORY} = kde-frameworks ]]; then
  33. debug-print "${ECLASS}: KDEBASE ebuild recognized"
  34. KDEBASE=kde-base
  35. elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
  36. KDEBASE=kdevelop
  37. fi
  38. debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
  39. # determine the build type
  40. if [[ ${PV} = *9999* ]]; then
  41. KDE_BUILD_TYPE="live"
  42. else
  43. KDE_BUILD_TYPE="release"
  44. fi
  45. export KDE_BUILD_TYPE
  46. # Set reponame and SCM for modules that have fully migrated to git
  47. # (hack - it's here because it needs to be before SCM inherits from kde4-base)
  48. if [[ ${KDE_BUILD_TYPE} == live ]]; then
  49. case "${KMNAME}" in
  50. kdebase-workspace)
  51. EGIT_REPONAME=${EGIT_REPONAME:=kde-workspace}
  52. ;;
  53. kdebase-runtime)
  54. EGIT_REPONAME=${EGIT_REPONAME:=kde-runtime}
  55. ;;
  56. esac
  57. fi
  58. # @ECLASS-VARIABLE: KDE_SCM
  59. # @DESCRIPTION:
  60. # If this is a live package which scm does it use
  61. # Everything else uses git by default
  62. KDE_SCM="${KDE_SCM:-git}"
  63. case ${KDE_SCM} in
  64. svn|git) ;;
  65. *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
  66. esac
  67. # @FUNCTION: kde4_lingua_to_l10n
  68. # @USAGE: <lingua>...
  69. # @INTERNAL
  70. # @DESCRIPTION:
  71. # Output l10n flag name(s) (without prefix(es)) appropriate for given KDE
  72. # locale(s).
  73. kde4_lingua_to_l10n() {
  74. local l
  75. for l; do
  76. case ${l} in
  77. ca@valencia) echo ca-valencia;;
  78. sr@ijekavian) echo sr-ijekavsk;;
  79. sr@ijekavianlatin) echo sr-Latn-ijekavsk;;
  80. sr@latin|sr@Latn) echo sr-Latn;;
  81. uz@cyrillic) echo uz-Cyrl;;
  82. *@*) die "${FUNCNAME}: Unhandled KDE_LINGUAS: ${l}";;
  83. *) echo "${l/_/-}";;
  84. esac
  85. done
  86. }
  87. # @ECLASS-VARIABLE: KDE_LINGUAS
  88. # @DESCRIPTION:
  89. # This is a whitespace-separated list of translations this ebuild supports.
  90. # These translations are automatically added to IUSE. Therefore ebuilds must set
  91. # this variable before inheriting any eclasses. To enable only selected
  92. # translations, ebuilds must call enable_selected_linguas(). kde4-{base,meta}.eclass does
  93. # this for you.
  94. #
  95. # Example: KDE_LINGUAS="de en_GB nl"
  96. if [[ ${KDE_BUILD_TYPE} != live || -n ${KDE_LINGUAS_LIVE_OVERRIDE} ]]; then
  97. for _lingua in $(kde4_lingua_to_l10n ${KDE_LINGUAS}); do
  98. IUSE="${IUSE} l10n_${_lingua}"
  99. done
  100. fi
  101. # @FUNCTION: buildsycoca
  102. # @DESCRIPTION:
  103. # Function to rebuild the KDE System Configuration Cache.
  104. # All KDE ebuilds should run this in pkg_postinst and pkg_postrm.
  105. buildsycoca() {
  106. debug-print-function ${FUNCNAME} "$@"
  107. # We no longer need to run kbuildsycoca4, as kded does that automatically, as needed
  108. # fix permission for some directories
  109. for x in usr/share/{config,kde4}; do
  110. DIRS=${EROOT}usr
  111. [[ -d "${EROOT}${x}" ]] || break # nothing to do if directory does not exist
  112. # fixes Bug 318237
  113. if use userland_BSD ; then
  114. [[ $(stat -f %p "${EROOT}${x}") != 40755 ]]
  115. local stat_rtn="$?"
  116. else
  117. [[ $(stat --format=%a "${EROOT}${x}") != 755 ]]
  118. local stat_rtn=$?
  119. fi
  120. if [[ $stat_rtn != 1 ]] ; then
  121. ewarn "QA Notice:"
  122. ewarn "Package ${PN} is breaking ${EROOT}${x} permissions."
  123. ewarn "Please report this issue to gentoo bugzilla."
  124. einfo "Permissions will get adjusted automatically now."
  125. find "${EROOT}${x}" -type d -print0 | xargs -0 chmod 755
  126. fi
  127. done
  128. }
  129. # @FUNCTION: comment_all_add_subdirectory
  130. # @USAGE: [list of directory names]
  131. # @DESCRIPTION:
  132. # Recursively comment all add_subdirectory instructions in listed directories,
  133. # except those in cmake/.
  134. comment_all_add_subdirectory() {
  135. find "$@" -name CMakeLists.txt -print0 | grep -vFzZ "./cmake" | \
  136. xargs -0 sed -i \
  137. -e '/^[[:space:]]*add_subdirectory/s/^/#DONOTCOMPILE /' \
  138. -e '/^[[:space:]]*ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
  139. -e '/^[[:space:]]*macro_optional_add_subdirectory/s/^/#DONOTCOMPILE /' \
  140. -e '/^[[:space:]]*MACRO_OPTIONAL_ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
  141. || die "${LINENO}: Initial sed died"
  142. }
  143. # @FUNCTION: enable_selected_linguas
  144. # @DESCRIPTION:
  145. # Enable translations based on L10N settings and translations supported by
  146. # the package (see KDE_LINGUAS). By default, translations are found in "${S}"/po
  147. # but this default can be overridden by defining KDE_LINGUAS_DIR.
  148. enable_selected_linguas() {
  149. debug-print-function ${FUNCNAME} "$@"
  150. local x
  151. # @ECLASS-VARIABLE: KDE_LINGUAS_DIR
  152. # @DESCRIPTION:
  153. # Specified folder where application translations are located.
  154. # Can be defined as array of folders where translations are located.
  155. # Note that space separated list of dirs is not supported.
  156. # Default value is set to "po".
  157. if [[ "$(declare -p KDE_LINGUAS_DIR 2>/dev/null 2>&1)" == "declare -a"* ]]; then
  158. debug-print "$FUNCNAME: we have these subfolders defined: ${KDE_LINGUAS_DIR}"
  159. for x in ${KDE_LINGUAS_DIR[@]}; do
  160. _enable_selected_linguas_dir ${x}
  161. done
  162. else
  163. KDE_LINGUAS_DIR=${KDE_LINGUAS_DIR:="po"}
  164. _enable_selected_linguas_dir ${KDE_LINGUAS_DIR}
  165. fi
  166. }
  167. # @FUNCTION: enable_selected_doc_linguas
  168. # @DESCRIPTION:
  169. # Enable only selected L10N enabled doc folders.
  170. enable_selected_doc_linguas() {
  171. debug-print-function ${FUNCNAME} "$@"
  172. # @ECLASS-VARIABLE: KDE_DOC_DIRS
  173. # @DESCRIPTION:
  174. # Variable specifying whitespace separated patterns for documentation locations.
  175. # Default is "doc/%lingua"
  176. KDE_DOC_DIRS=${KDE_DOC_DIRS:='doc/%lingua'}
  177. local linguas
  178. for pattern in ${KDE_DOC_DIRS}; do
  179. local handbookdir=`dirname ${pattern}`
  180. local translationdir=`basename ${pattern}`
  181. # Do filename pattern supplied, treat as directory
  182. [[ ${handbookdir} = '.' ]] && handbookdir=${translationdir} && translationdir=
  183. [[ -d ${handbookdir} ]] || die 'wrong doc dir specified'
  184. if ! use handbook; then
  185. # Disable whole directory
  186. sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
  187. -e "/ADD_SUBDIRECTORY[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
  188. -i CMakeLists.txt || die 'failed to comment out all handbooks'
  189. else
  190. # Disable subdirectories recursively
  191. comment_all_add_subdirectory "${handbookdir}"
  192. # In certain packages, the default handbook is en_US instead of the usual en. Since there is no en_US 'translation',
  193. # it makes no sense to add to KDE_LINGUAS which causes this type of handbook to not be installed.
  194. if [[ -d "${handbookdir}/en_US" && ! -d "${handbookdir}/en" ]]; then
  195. mv "${handbookdir}/en_US" "${handbookdir}/en" || die
  196. sed -e "s/en_US/en/" -i "${handbookdir}/CMakeLists.txt"
  197. fi
  198. # Add requested translations
  199. local lingua
  200. for lingua in en ${KDE_LINGUAS}; do
  201. if [[ ${lingua} = en ]] || use "l10n_$(kde4_lingua_to_l10n "${lingua}")"; then
  202. if [[ -d ${handbookdir}/${translationdir//%lingua/${lingua}} ]]; then
  203. sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${translationdir//%lingua/${lingua}}/s/^#DONOTCOMPILE //" \
  204. -e "/ADD_SUBDIRECTORY[[:space:]]*([[:space:]]*${translationdir//%lingua/${lingua}}/s/^#DONOTCOMPILE //" \
  205. -i "${handbookdir}"/CMakeLists.txt && ! has ${lingua} ${linguas} && linguas="${linguas} ${lingua}"
  206. fi
  207. fi
  208. done
  209. fi
  210. done
  211. [[ -n "${linguas}" ]] && einfo "Enabling handbook translations:${linguas}"
  212. }
  213. # Functions handling KMLOADLIBS and KMSAVELIBS
  214. # @FUNCTION: save_library_dependencies
  215. # @DESCRIPTION:
  216. # Add exporting CMake dependencies for current package
  217. save_library_dependencies() {
  218. local depsfile="${T}/${PN}"
  219. ebegin "Saving library dependencies in ${depsfile##*/}"
  220. echo "EXPORT_LIBRARY_DEPENDENCIES(\"${depsfile}\")" >> "${S}/CMakeLists.txt" || \
  221. die "Failed to save the library dependencies."
  222. eend $?
  223. }
  224. # @FUNCTION: install_library_dependencies
  225. # @DESCRIPTION:
  226. # Install generated CMake library dependencies to /var/lib/kde
  227. install_library_dependencies() {
  228. local depsfile="${T}/${PN}"
  229. ebegin "Installing library dependencies as ${depsfile##*/}"
  230. insinto /var/lib/kde
  231. doins "${depsfile}" || die "Failed to install library dependencies."
  232. eend $?
  233. }
  234. # @FUNCTION: load_library_dependencies
  235. # @DESCRIPTION:
  236. # Inject specified library dependencies in current package
  237. load_library_dependencies() {
  238. local pn i depsfile
  239. ebegin "Injecting library dependencies from '${KMLOADLIBS}'"
  240. i=0
  241. for pn in ${KMLOADLIBS} ; do
  242. ((i++))
  243. depsfile="${EPREFIX}/var/lib/kde/${pn}"
  244. [[ -r ${depsfile} ]] || depsfile="${EPREFIX}/var/lib/kde/${pn}:$(get_kde_version)"
  245. [[ -r ${depsfile} ]] || die "Depsfile '${depsfile}' not accessible. You probably need to reinstall ${pn}."
  246. sed -i -e "${i}iINCLUDE(\"${depsfile}\")" "${S}/CMakeLists.txt" || \
  247. die "Failed to include library dependencies for ${pn}"
  248. done
  249. eend $?
  250. }
  251. # @FUNCTION: add_kdeapps_dep
  252. # @DESCRIPTION:
  253. # Create proper dependency for kde-apps/ dependencies.
  254. # This takes 1 to 3 arguments. The first being the package name, the optional
  255. # second is additional USE flags to append, and the optional third is the
  256. # version to use instead of the automatic version (use sparingly).
  257. # The output of this should be added directly to DEPEND/RDEPEND, and may be
  258. # wrapped in a USE conditional (but not an || conditional without an extra set
  259. # of parentheses).
  260. add_kdeapps_dep() {
  261. debug-print-function ${FUNCNAME} "$@"
  262. local ver
  263. if [[ -n ${3} ]]; then
  264. ver=${3}
  265. elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
  266. ver=${KDE_OVERRIDE_MINIMAL}
  267. elif [[ ${KDEBASE} != kde-base ]]; then
  268. ver=${KDE_MINIMAL}
  269. # if building kde-apps, live master or stable-live branch,
  270. # use the final SC version since there are no further general releases.
  271. # except when it is kdepim split packages, which rely on same-version deps
  272. elif [[ ${CATEGORY} == kde-apps || ${PV} == *9999 ]] && [[ ${KMNAME} != "kdepim" ]]; then
  273. ver=4.14.3
  274. else
  275. ver=${PV}
  276. fi
  277. [[ -z ${1} ]] && die "Missing parameter"
  278. #FIXME
  279. # Drop aqua= from kf5 packages
  280. echo " >=kde-apps/${1}-${ver}:4[aqua=${2:+,${2}}]"
  281. }
  282. # @FUNCTION: add_kdebase_dep
  283. # @DESCRIPTION:
  284. # Create proper dependency for kde-base/ dependencies.
  285. # This takes 1 to 3 arguments. The first being the package name, the optional
  286. # second is additional USE flags to append, and the optional third is the
  287. # version to use instead of the automatic version (use sparingly).
  288. # The output of this should be added directly to DEPEND/RDEPEND, and may be
  289. # wrapped in a USE conditional (but not an || conditional without an extra set
  290. # of parentheses).
  291. add_kdebase_dep() {
  292. debug-print-function ${FUNCNAME} "$@"
  293. local ver
  294. if [[ -n ${3} ]]; then
  295. ver=${3}
  296. elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
  297. ver=${KDE_OVERRIDE_MINIMAL}
  298. elif [[ ${KDEBASE} != kde-base ]]; then
  299. ver=${KDE_MINIMAL}
  300. # if building live master or kde-apps, use the final SC version
  301. # since there are no further general releases.
  302. elif [[ ${CATEGORY} == kde-apps || ${PV} == 9999 ]]; then
  303. ver=4.14.3
  304. # if building a live version branch (eg. 4.11.49.9999) use the major version
  305. elif [[ ${PV} == *.9999 ]]; then
  306. ver=$(get_kde_version)
  307. else
  308. ver=${PV}
  309. fi
  310. [[ -z ${1} ]] && die "Missing parameter"
  311. echo " >=kde-base/${1}-${ver}:4[aqua=${2:+,${2}}]"
  312. }
  313. # local function to enable specified translations for specified directory
  314. # used from kde4-functions_enable_selected_linguas function
  315. _enable_selected_linguas_dir() {
  316. local lingua linguas sr_mess wp
  317. local dir=${1}
  318. [[ -d ${dir} ]] || die "linguas dir \"${dir}\" does not exist"
  319. comment_all_add_subdirectory "${dir}"
  320. pushd "${dir}" > /dev/null || die
  321. # fix all various crazy sr@Latn variations
  322. # this part is only ease for ebuilds, so there wont be any die when this
  323. # fail at any point
  324. sr_mess="sr@latn sr@latin sr@Latin"
  325. for wp in ${sr_mess}; do
  326. [[ -e ${wp}.po ]] && mv "${wp}.po" "sr@Latn.po"
  327. if [[ -d ${wp} ]]; then
  328. # move dir and fix cmakelists
  329. mv "${wp}" "sr@Latn"
  330. sed -i \
  331. -e "s:${wp}:sr@Latn:g" \
  332. CMakeLists.txt
  333. fi
  334. done
  335. for lingua in ${KDE_LINGUAS}; do
  336. if [[ -e ${lingua}.po ]]; then
  337. mv "${lingua}.po" "${lingua}.po.old"
  338. fi
  339. done
  340. for lingua in ${KDE_LINGUAS}; do
  341. if use "l10n_$(kde4_lingua_to_l10n ${lingua})" ; then
  342. if [[ -d ${lingua} ]]; then
  343. linguas="${linguas} ${lingua}"
  344. sed -e "/add_subdirectory([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
  345. -e "/ADD_SUBDIRECTORY([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
  346. -i CMakeLists.txt || die "Sed to uncomment linguas_${lingua} failed."
  347. fi
  348. if [[ -e ${lingua}.po.old ]]; then
  349. linguas="${linguas} ${lingua}"
  350. mv "${lingua}.po.old" "${lingua}.po"
  351. fi
  352. fi
  353. done
  354. [[ -n ${linguas} ]] && echo ">>> Enabling languages: ${linguas}"
  355. popd > /dev/null || die
  356. }
  357. # @FUNCTION: get_kde_version
  358. # @DESCRIPTION:
  359. # Translates an ebuild version into a major.minor KDE SC
  360. # release version. If no version is specified, ${PV} is used.
  361. get_kde_version() {
  362. local ver=${1:-${PV}}
  363. local major=$(get_major_version ${ver})
  364. local minor=$(get_version_component_range 2 ${ver})
  365. local micro=$(get_version_component_range 3 ${ver})
  366. if [[ ${ver} == 9999 ]]; then
  367. echo live
  368. else
  369. (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
  370. fi
  371. }
  372. fi