myspell.eclass 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # Author: Kevin F. Quinn <kevquinn@gentoo.org>
  4. # Packages: app-dicts/myspell-*
  5. # Maintainer: maintainer-needed@gentoo.org
  6. inherit multilib
  7. EXPORT_FUNCTIONS src_install pkg_preinst pkg_postinst
  8. IUSE=""
  9. SLOT="0"
  10. # tar, gzip, bzip2 are included in the base profile, but not unzip
  11. DEPEND="app-arch/unzip"
  12. # Dictionaries don't have any runtime dependencies
  13. # Myspell dictionaries can be used by hunspell, openoffice and others
  14. RDEPEND=""
  15. # The destination directory for myspell dictionaries
  16. MYSPELL_DICTBASE="/usr/share/myspell"
  17. # Legacy variable for dictionaries installed before eselect-oodict existed
  18. # so has to remain for binpkg support. This variable is unmaintained -
  19. # if you have a problem with it, emerge app-eselect/eselect-oodict.
  20. # The location for openoffice softlinks
  21. MYSPELL_OOOBASE="/usr/lib/openoffice/share/dict/ooo"
  22. # set array "fields" to the elements of $1, separated by $2.
  23. # This saves having to muck about with IFS all over the place.
  24. set_fields() {
  25. local old_IFS
  26. old_IFS="${IFS}"
  27. IFS=$2
  28. fields=($1)
  29. IFS="${old_IFS}"
  30. }
  31. # language is the second element of the ebuild name
  32. # myspell-<lang>-<version>
  33. get_myspell_lang() {
  34. local fields
  35. set_fields "${P}" "-"
  36. echo ${fields[1]}
  37. }
  38. get_myspell_suffixes() {
  39. case $1 in
  40. DICT) echo ".aff .dic" ;;
  41. HYPH) echo ".dic" ;;
  42. THES) echo ".dat .idx" ;;
  43. esac
  44. }
  45. # OOo dictionary files are held on the mirrors, rather than
  46. # being fetched direct from the OOo site as upstream doesn't
  47. # change the name when they rebuild the dictionaries.
  48. # <lang>-<country>.zip becomes myspell-<lang>-<country>-version.zip
  49. get_myspell_ooo_uri() {
  50. local files fields newfile filestem srcfile dict uris
  51. files=()
  52. uris=""
  53. for dict in \
  54. "${MYSPELL_SPELLING_DICTIONARIES[@]}" \
  55. "${MYSPELL_HYPHENATION_DICTIONARIES[@]}" \
  56. "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
  57. set_fields "${dict}" ","
  58. newfile=${fields[4]// }
  59. for file in "${files[@]}"; do
  60. [[ ${file} == ${newfile} ]] && continue 2
  61. done
  62. filestem=${newfile/.zip}
  63. files=("${files[@]}" "${newfile}")
  64. srcfile="myspell-${filestem}-${PV}.zip"
  65. [[ -z ${uris} ]] &&
  66. uris="mirror://gentoo/${srcfile}" ||
  67. uris="${uris} mirror://gentoo/${srcfile}"
  68. done
  69. echo "${uris}"
  70. }
  71. [[ -z ${SRC_URI} ]] && SRC_URI=$(get_myspell_ooo_uri)
  72. # Format of dictionary.lst files (from OOo standard
  73. # dictionary.lst file):
  74. #
  75. # List of All Dictionaries to be Loaded by OpenOffice
  76. # ---------------------------------------------------
  77. # Each Entry in the list have the following space delimited fields
  78. #
  79. # Field 0: Entry Type "DICT" - spellchecking dictionary
  80. # "HYPH" - hyphenation dictionary
  81. # "THES" - thesaurus files
  82. #
  83. # Field 1: Language code from Locale "en" or "de" or "pt" ...
  84. #
  85. # Field 2: Country Code from Locale "US" or "GB" or "PT"
  86. #
  87. # Field 3: Root name of file(s) "en_US" or "hyph_de" or "th_en_US"
  88. # (do not add extensions to the name)
  89. # Format of MYSPELL_[SPELLING|HYPHENATION|THESAURUS]_DICTIONARIES:
  90. #
  91. # Field 0: Language code
  92. # Field 1: Country code
  93. # Field 2: Root name of dictionary files
  94. # Field 3: Description
  95. # Field 4: Archive filename
  96. #
  97. # This format is from the available.lst, hyphavail.lst and
  98. # thesavail.lst files on the openoffice.org repository.
  99. myspell_src_install() {
  100. local filen fields entry dictlst
  101. cd "${WORKDIR}"
  102. # Install the dictionary, hyphenation and thesaurus files.
  103. # Create dictionary.lst.<lang> file containing the parts of
  104. # OOo's dictionary.lst file for this language, indicating
  105. # which dictionaries are relevant for each country variant
  106. # of the language.
  107. insinto ${MYSPELL_DICTBASE}
  108. dictlst="dictionary.lst.$(get_myspell_lang)"
  109. echo "# Autogenerated by ${CATEGORY}/${P}" > ${dictlst}
  110. for entry in "${MYSPELL_SPELLING_DICTIONARIES[@]}"; do
  111. set_fields "${entry}" ","
  112. echo "DICT ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
  113. doins ${fields[2]}.aff || die "Missing ${fields[2]}.aff"
  114. doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
  115. done
  116. for entry in "${MYSPELL_HYPHENATION_DICTIONARIES[@]}"; do
  117. set_fields "${entry}" ","
  118. echo "HYPH ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
  119. doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
  120. done
  121. for entry in "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
  122. set_fields "${entry}" ","
  123. echo "THES ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
  124. doins ${fields[2]}.dat || die "Missing ${fields[2]}.dat"
  125. doins ${fields[2]}.idx || die "Missing ${fields[2]}.idx"
  126. done
  127. doins ${dictlst} || die "Failed to install ${dictlst}"
  128. # Install any txt files (usually README.txt) as documentation
  129. for filen in *.txt; do
  130. [[ -s ${filen} ]] && dodoc ${filen}
  131. done
  132. }
  133. # Add entries in dictionary.lst.<lang> to OOo dictionary.lst
  134. # and create softlinks indicated by dictionary.lst.<lang>
  135. myspell_pkg_postinst() {
  136. # Update for known applications
  137. if has_version ">=app-eselect/eselect-oodict-20060706"; then
  138. if has_version app-office/openoffice; then
  139. eselect oodict set myspell-$(get_myspell_lang)
  140. fi
  141. if has_version app-office/openoffice-bin; then
  142. # On AMD64, openoffice-bin is 32-bit so force ABI
  143. has_multilib_profile && ABI=x86
  144. eselect oodict set myspell-$(get_myspell_lang) --libdir $(get_libdir)
  145. fi
  146. return
  147. fi
  148. if has_version app-eselect/eselect-oodict; then
  149. eselect oodict set myspell-$(get_myspell_lang)
  150. return
  151. fi
  152. # Legacy code for dictionaries installed before eselect-oodict existed
  153. # so has to remain for binpkg support. This code is unmaintained -
  154. # if you have a problem with it, emerge app-eselect/eselect-oodict.
  155. [[ -d ${MYSPELL_OOOBASE} ]] || return
  156. # This stuff is here, not in src_install, as the softlinks are
  157. # deliberately _not_ listed in the package database.
  158. local dictlst entry fields prefix suffix suffixes filen
  159. # Note; can only reach this point if ${MYSPELL_DICTBASE}/${dictlst}
  160. # was successfully installed
  161. dictlst="dictionary.lst.$(get_myspell_lang)"
  162. while read entry; do
  163. fields=(${entry})
  164. [[ ${fields[0]:0:1} == "#" ]] && continue
  165. [[ -f ${MYSPELL_OOOBASE}/dictionary.lst ]] || \
  166. touch ${MYSPELL_OOOBASE}/dictionary.lst
  167. grep "^${fields[0]} ${fields[1]} ${fields[2]} " \
  168. ${MYSPELL_OOOBASE}/dictionary.lst > /dev/null 2>&1 ||
  169. echo "${entry}" >> ${MYSPELL_OOOBASE}/dictionary.lst
  170. for suffix in $(get_myspell_suffixes ${fields[0]}); do
  171. filen="${fields[3]}${suffix}"
  172. [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
  173. rm -f ${MYSPELL_OOOBASE}/${filen}
  174. [[ ! -f ${MYSPELL_OOOBASE}/${filen} ]] &&
  175. ln -s ${MYSPELL_DICTBASE}/${filen} \
  176. ${MYSPELL_OOOBASE}/${filen}
  177. done
  178. done < ${MYSPELL_DICTBASE}/${dictlst}
  179. }
  180. # Remove softlinks and entries in dictionary.lst - uses
  181. # dictionary.<lang>.lst from /usr/share/myspell
  182. # Done in preinst (prerm happens after postinst, which overwrites
  183. # the dictionary.<lang>.lst file)
  184. myspell_pkg_preinst() {
  185. # Update for known applications
  186. if has_version ">=app-eselect/eselect-oodict-20060706"; then
  187. if has_version app-office/openoffice; then
  188. # When building from source, the default library path is correct
  189. eselect oodict unset myspell-$(get_myspell_lang)
  190. fi
  191. if has_version app-office/openoffice-bin; then
  192. # On AMD64, openoffice-bin is 32-bit, so get 32-bit library directory
  193. has_multilib_profile && ABI=x86
  194. eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
  195. fi
  196. eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
  197. return
  198. fi
  199. # Previous versions of eselect-oodict didn't cater for -bin on amd64
  200. if has_version app-eselect/eselect-oodict; then
  201. eselect oodict unset myspell-$(get_myspell_lang)
  202. return
  203. fi
  204. # Legacy code for dictionaries installed before eselect-oodict existed
  205. # Don't delete this; needed for uninstalls and binpkg support.
  206. # This code is unmaintained - if you have a problem with it,
  207. # emerge app-eselect/eselect-oodict.
  208. local filen dictlst entry fields removeentry suffix
  209. dictlst="dictionary.lst.$(get_myspell_lang)"
  210. [[ -d ${MYSPELL_OOOBASE} ]] || return
  211. [[ -f ${MYSPELL_DICTBASE}/${dictlst} ]] || return
  212. while read entry; do
  213. fields=(${entry})
  214. [[ ${fields[0]:0:1} == "#" ]] && continue
  215. [[ ${fields[3]} == "" ]] && continue
  216. # Remove entry from dictionary.lst
  217. sed -i -e "/^${fields[0]} ${fields[1]} ${fields[2]} ${fields[3]}$/ { d }" \
  218. ${MYSPELL_OOOBASE}/dictionary.lst
  219. # See if any other entries in dictionary.lst match the current
  220. # dictionary type and filename
  221. grep "^${fields[0]} .* ${fields[3]}$" ${MYSPELL_OOOBASE}/dictionary.lst \
  222. 2>&1 > /dev/null && continue
  223. # If no other entries match, remove relevant symlinks
  224. for suffix in $(get_myspell_suffixes ${fields[0]}); do
  225. filen="${fields[3]}${suffix}"
  226. ewarn "Removing entry ${MYSPELL_OOOBASE}/${filen}"
  227. [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
  228. rm -f ${MYSPELL_OOOBASE}/${filen}
  229. done
  230. done < ${MYSPELL_DICTBASE}/${dictlst}
  231. }