texlive-module.eclass 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. # Copyright 1999-2014 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: texlive-module.eclass
  4. # @MAINTAINER:
  5. # tex@gentoo.org
  6. # @AUTHOR:
  7. # Original Author: Alexis Ballier <aballier@gentoo.org>
  8. # @BLURB: Provide generic install functions so that modular texlive's texmf ebuild will only have to inherit this eclass
  9. # @DESCRIPTION:
  10. # Purpose: Provide generic install functions so that modular texlive's texmf ebuilds will
  11. # only have to inherit this eclass.
  12. # Ebuilds have to provide TEXLIVE_MODULE_CONTENTS variable that contains the list
  13. # of packages that it will install. (See below)
  14. #
  15. # For TeX Live versions prior to 2009, the ebuild was supposed to unpack the
  16. # texmf and texmf-dist directories to ${WORKDIR} (which is what the default
  17. # src_unpack does).
  18. # Starting from TeX Live 2009, the eclass provides a src_unpack function taking
  19. # care of unpacking and relocating the files that need it.
  20. #
  21. # It inherits texlive-common. Patching is supported via the PATCHES
  22. # bash array.
  23. # @ECLASS-VARIABLE: TEXLIVE_MODULE_CONTENTS
  24. # @DESCRIPTION:
  25. # The list of packages that will be installed. This variable will be expanded to
  26. # SRC_URI:
  27. # foo -> texlive-module-foo-${PV}.tar.xz
  28. # @ECLASS-VARIABLE: TEXLIVE_MODULE_DOC_CONTENTS
  29. # @DESCRIPTION:
  30. # The list of packages that will be installed if the doc useflag is enabled.
  31. # Expansion to SRC_URI is the same as for TEXLIVE_MODULE_CONTENTS.
  32. # @ECLASS-VARIABLE: TEXLIVE_MODULE_SRC_CONTENTS
  33. # @DESCRIPTION:
  34. # The list of packages that will be installed if the source useflag is enabled.
  35. # Expansion to SRC_URI is the same as for TEXLIVE_MODULE_CONTENTS.
  36. # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINSCRIPTS
  37. # @DESCRIPTION:
  38. # A space separated list of files that are in fact scripts installed in the
  39. # texmf tree and that we want to be available directly. They will be installed in
  40. # /usr/bin.
  41. # @ECLASS-VARIABLE: TEXLIVE_MODULE_BINLINKS
  42. # @DESCRIPTION:
  43. # A space separated list of links to add for BINSCRIPTS.
  44. # The systax is: foo:bar to create a symlink bar -> foo.
  45. # @ECLASS-VARIABLE: TL_PV
  46. # @DESCRIPTION:
  47. # Normally the module's PV reflects the TeXLive release it belongs to.
  48. # If this is not the case, TL_PV takes the version number for the
  49. # needed app-text/texlive-core.
  50. # @ECLASS-VARIABLE: TL_MODULE_INFORMATION
  51. # @DESCRIPTION:
  52. # Information to display about the package.
  53. # e.g. for enabling/disabling a feature
  54. # @ECLASS-VARIABLE: PATCHES
  55. # @DESCRIPTION:
  56. # Array variable specifying any patches to be applied.
  57. inherit texlive-common eutils
  58. case "${EAPI:-0}" in
  59. 0|1|2)
  60. die "EAPI='${EAPI}' is not supported anymore"
  61. ;;
  62. *)
  63. ;;
  64. esac
  65. HOMEPAGE="http://www.tug.org/texlive/"
  66. COMMON_DEPEND=">=app-text/texlive-core-${TL_PV:-${PV}}"
  67. IUSE="source"
  68. # Starting from TeX Live 2009, upstream provides .tar.xz modules.
  69. PKGEXT=tar.xz
  70. DEPEND="${COMMON_DEPEND}
  71. app-arch/xz-utils"
  72. for i in ${TEXLIVE_MODULE_CONTENTS}; do
  73. SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
  74. done
  75. # Forge doc SRC_URI
  76. [ -n "${PN##*documentation*}" ] && [ -n "${TEXLIVE_MODULE_DOC_CONTENTS}" ] && SRC_URI="${SRC_URI} doc? ("
  77. for i in ${TEXLIVE_MODULE_DOC_CONTENTS}; do
  78. SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
  79. done
  80. [ -n "${PN##*documentation*}" ] && [ -n "${TEXLIVE_MODULE_DOC_CONTENTS}" ] && SRC_URI="${SRC_URI} )"
  81. # Forge source SRC_URI
  82. if [ -n "${TEXLIVE_MODULE_SRC_CONTENTS}" ] ; then
  83. SRC_URI="${SRC_URI} source? ("
  84. for i in ${TEXLIVE_MODULE_SRC_CONTENTS}; do
  85. SRC_URI="${SRC_URI} mirror://gentoo/texlive-module-${i}-${PV}.${PKGEXT}"
  86. done
  87. SRC_URI="${SRC_URI} )"
  88. fi
  89. RDEPEND="${COMMON_DEPEND}"
  90. [ -z "${PN##*documentation*}" ] || IUSE="${IUSE} doc"
  91. # @ECLASS-VARIABLE: TEXLIVE_MODULE_OPTIONAL_ENGINE
  92. # @DESCRIPTION:
  93. # A space separated list of Tex engines that can be made optional.
  94. # e.g. "luatex luajittex"
  95. if [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] ; then
  96. for engine in ${TEXLIVE_MODULE_OPTIONAL_ENGINE} ; do
  97. IUSE="${IUSE} +${engine}"
  98. done
  99. fi
  100. S="${WORKDIR}"
  101. # @FUNCTION: texlive-module_src_unpack
  102. # @DESCRIPTION:
  103. # Only for TeX Live 2009 and later.
  104. # After unpacking, the files that need to be relocated are moved accordingly.
  105. RELOC_TARGET=texmf-dist
  106. texlive-module_src_unpack() {
  107. unpack ${A}
  108. grep RELOC tlpkg/tlpobj/* | awk '{print $2}' | sed 's#^RELOC/##' > "${T}/reloclist"
  109. { for i in $(<"${T}/reloclist"); do dirname $i; done; } | uniq > "${T}/dirlist"
  110. for i in $(<"${T}/dirlist"); do
  111. [ -d "${RELOC_TARGET}/${i}" ] || mkdir -p "${RELOC_TARGET}/${i}"
  112. done
  113. for i in $(<"${T}/reloclist"); do
  114. mv "${i}" "${RELOC_TARGET}"/$(dirname "${i}") || die "failed to relocate ${i} to ${RELOC_TARGET}/$(dirname ${i})"
  115. done
  116. }
  117. # @FUNCTION: texlive-module_src_prepare
  118. # @DESCRIPTION:
  119. # Apply patches from the PATCHES array and user patches, if any.
  120. texlive-module_src_prepare() {
  121. [[ ${#PATCHES[@]} -gt 0 ]] && epatch "${PATCHES[@]}"
  122. epatch_user
  123. }
  124. # @FUNCTION: texlive-module_add_format
  125. # @DESCRIPTION:
  126. # Creates/appends to a format.${PN}.cnf file for fmtutil.
  127. # It parses the AddFormat directive of tlpobj files to create it.
  128. # This will make fmtutil generate the formats when asked and allow the remaining
  129. # src_compile phase to build the formats.
  130. texlive-module_add_format() {
  131. local name engine mode patterns options
  132. eval $@
  133. einfo "Appending to format.${PN}.cnf for $@"
  134. [ -d texmf-dist/fmtutil ] || mkdir -p texmf-dist/fmtutil
  135. [ -f texmf-dist/fmtutil/format.${PN}.cnf ] || { echo "# Generated for ${PN} by texlive-module.eclass" > texmf-dist/fmtutil/format.${PN}.cnf; }
  136. [ -n "${TEXLIVE_MODULE_OPTIONAL_ENGINE}" ] && has ${engine} ${TEXLIVE_MODULE_OPTIONAL_ENGINE} && use !${engine} && mode="disabled"
  137. if [ "${mode}" = "disabled" ]; then
  138. printf "#! " >> texmf-dist/fmtutil/format.${PN}.cnf
  139. fi
  140. [ -z "${patterns}" ] && patterns="-"
  141. printf "${name}\t${engine}\t${patterns}\t${options}\n" >> texmf-dist/fmtutil/format.${PN}.cnf
  142. }
  143. # @FUNCTION: texlive-module_make_language_def_lines
  144. # @DESCRIPTION:
  145. # Creates a language.${PN}.def entry to put in /etc/texmf/language.def.d.
  146. # It parses the AddHyphen directive of tlpobj files to create it.
  147. texlive-module_make_language_def_lines() {
  148. local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
  149. eval $@
  150. einfo "Generating language.def entry for $@"
  151. [ -z "$lefthyphenmin" ] && lefthyphenmin="2"
  152. [ -z "$righthyphenmin" ] && righthyphenmin="3"
  153. echo "\\addlanguage{$name}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
  154. if [ -n "$synonyms" ] ; then
  155. for i in $(echo $synonyms | tr ',' ' ') ; do
  156. einfo "Generating language.def synonym $i for $@"
  157. echo "\\addlanguage{$i}{$file}{}{$lefthyphenmin}{$righthyphenmin}" >> "${S}/language.${PN}.def"
  158. done
  159. fi
  160. }
  161. # @FUNCTION: texlive-module_make_language_dat_lines
  162. # @DESCRIPTION:
  163. # Creates a language.${PN}.dat entry to put in /etc/texmf/language.dat.d.
  164. # It parses the AddHyphen directive of tlpobj files to create it.
  165. texlive-module_make_language_dat_lines() {
  166. local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
  167. eval $@
  168. einfo "Generating language.dat entry for $@"
  169. echo "$name $file" >> "${S}/language.${PN}.dat"
  170. if [ -n "$synonyms" ] ; then
  171. for i in $(echo $synonyms | tr ',' ' ') ; do
  172. einfo "Generating language.dat synonym $i for $@"
  173. echo "=$i" >> "${S}/language.${PN}.dat"
  174. done
  175. fi
  176. }
  177. # @FUNCTION: texlive-module_synonyms_to_language_lua_line
  178. # @DESCRIPTION:
  179. # Helper function for texlive-module_make_language_lua_lines to generate a
  180. # correctly formatted synonyms entry for language.dat.lua.
  181. texlive-module_synonyms_to_language_lua_line() {
  182. local prev=""
  183. for i in $(echo $@ | tr ',' ' ') ; do
  184. printf "${prev} '%s'" $i
  185. prev=","
  186. done
  187. }
  188. # @FUNCTION: texlive-module_make_language_lua_lines
  189. # @DESCRIPTION:
  190. # Only valid for TeXLive 2010 and later.
  191. # Creates a language.${PN}.dat.lua entry to put in
  192. # /etc/texmf/language.dat.lua.d.
  193. # It parses the AddHyphen directive of tlpobj files to create it.
  194. texlive-module_make_language_lua_lines() {
  195. local lefthyphenmin righthyphenmin synonyms name file file_patterns file_exceptions luaspecial
  196. local dest="${S}/language.${PN}.dat.lua"
  197. eval $@
  198. [ -z "$lefthyphenmin" ] && lefthyphenmin="2"
  199. [ -z "$righthyphenmin" ] && righthyphenmin="3"
  200. einfo "Generating language.dat.lua entry for $@"
  201. printf "\t['%s'] = {\n" "$name" >> "$dest"
  202. printf "\t\tloader = '%s',\n" "$file" >> "$dest"
  203. printf "\t\tlefthyphenmin = %s,\n\t\trighthyphenmin = %s,\n" "$lefthyphenmin" "$righthyphenmin" >> "$dest"
  204. printf "\t\tsynonyms = {%s },\n" "$(texlive-module_synonyms_to_language_lua_line "$synonyms")" >> "$dest"
  205. [ -n "$file_patterns" ] && printf "\t\tpatterns = '%s',\n" "$file_patterns" >> "$dest"
  206. [ -n "$file_exceptions" ] && printf "\t\thyphenation = '%s',\n" "$file_exceptions" >> "$dest"
  207. [ -n "$luaspecial" ] && printf "\t\tspecial = '%s',\n" "$luaspecial" >> "$dest"
  208. printf "\t},\n" >> "$dest"
  209. }
  210. # @FUNCTION: texlive-module_src_compile
  211. # @DESCRIPTION:
  212. # exported function:
  213. # Generates the config files that are to be installed in /etc/texmf;
  214. # texmf-update script will take care of merging the different config files for
  215. # different packages in a single one used by the whole tex installation.
  216. #
  217. # Once the config files are generated, we build the format files using fmtutil
  218. # (provided by texlive-core). The compiled format files will be sent to
  219. # texmf-var/web2c, like fmtutil defaults to but with some trick to stay in the
  220. # sandbox.
  221. texlive-module_src_compile() {
  222. # Generate config files from the tlpobj files provided by TeX Live 2008 and
  223. # later
  224. for i in "${S}"/tlpkg/tlpobj/*;
  225. do
  226. grep '^execute ' "${i}" | sed -e 's/^execute //' | tr ' \t' '##' >> "${T}/jobs"
  227. done
  228. for i in $(<"${T}/jobs");
  229. do
  230. j="$(echo $i | tr '#' ' ')"
  231. command=${j%% *}
  232. parameter=${j#* }
  233. case "${command}" in
  234. addMap)
  235. echo "Map ${parameter}" >> "${S}/${PN}.cfg";;
  236. addMixedMap)
  237. echo "MixedMap ${parameter}" >> "${S}/${PN}.cfg";;
  238. addKanjiMap)
  239. echo "KanjiMap ${parameter}" >> "${S}/${PN}.cfg";;
  240. addDvipsMap)
  241. echo "p +${parameter}" >> "${S}/${PN}-config.ps";;
  242. addDvipdfmMap)
  243. echo "f ${parameter}" >> "${S}/${PN}-config";;
  244. AddHyphen)
  245. texlive-module_make_language_def_lines "$parameter"
  246. texlive-module_make_language_dat_lines "$parameter"
  247. texlive-module_make_language_lua_lines "$parameter"
  248. ;;
  249. AddFormat)
  250. texlive-module_add_format "$parameter";;
  251. BuildFormat)
  252. einfo "Format $parameter already built.";;
  253. BuildLanguageDat)
  254. einfo "Language file $parameter already generated.";;
  255. *)
  256. die "No rule to proccess ${command}. Please file a bug."
  257. esac
  258. done
  259. # Build format files
  260. for i in texmf-dist/fmtutil/format*.cnf; do
  261. if [ -f "${i}" ]; then
  262. einfo "Building format ${i}"
  263. [ -d texmf-var ] || mkdir texmf-var
  264. [ -d texmf-var/web2c ] || mkdir texmf-var/web2c
  265. VARTEXFONTS="${T}/fonts" TEXMFHOME="${S}/texmf:${S}/texmf-dist:${S}/texmf-var"\
  266. env -u TEXINPUTS fmtutil --cnffile "${i}" --fmtdir "${S}/texmf-var/web2c" --all\
  267. || die "failed to build format ${i}"
  268. fi
  269. done
  270. # Delete ls-R files, these should not be created but better be certain they
  271. # do not end up being installed.
  272. find . -name 'ls-R' -delete
  273. }
  274. # @FUNCTION: texlive-module_src_install
  275. # @DESCRIPTION:
  276. # exported function:
  277. # Installs texmf and config files to the system.
  278. texlive-module_src_install() {
  279. for i in texmf-dist/fmtutil/format*.cnf; do
  280. [ -f "${i}" ] && etexlinks "${i}"
  281. done
  282. dodir /usr/share
  283. if [ -z "${PN##*documentation*}" ] || use doc; then
  284. [ -d texmf-doc ] && cp -pR texmf-doc "${ED}/usr/share/"
  285. else
  286. [ -d texmf/doc ] && rm -rf texmf/doc
  287. [ -d texmf-dist/doc ] && rm -rf texmf-dist/doc
  288. fi
  289. [ -d texmf ] && cp -pR texmf "${ED}/usr/share/"
  290. [ -d texmf-dist ] && cp -pR texmf-dist "${ED}/usr/share/"
  291. [ -d tlpkg ] && use source && cp -pR tlpkg "${ED}/usr/share/"
  292. insinto /var/lib/texmf
  293. [ -d texmf-var ] && doins -r texmf-var/*
  294. insinto /etc/texmf/updmap.d
  295. [ -f "${S}/${PN}.cfg" ] && doins "${S}/${PN}.cfg"
  296. insinto /etc/texmf/dvips.d
  297. [ -f "${S}/${PN}-config.ps" ] && doins "${S}/${PN}-config.ps"
  298. insinto /etc/texmf/dvipdfm/config
  299. [ -f "${S}/${PN}-config" ] && doins "${S}/${PN}-config"
  300. if [ -f "${S}/language.${PN}.def" ] ; then
  301. insinto /etc/texmf/language.def.d
  302. doins "${S}/language.${PN}.def"
  303. fi
  304. if [ -f "${S}/language.${PN}.dat" ] ; then
  305. insinto /etc/texmf/language.dat.d
  306. doins "${S}/language.${PN}.dat"
  307. fi
  308. if [ -f "${S}/language.${PN}.dat.lua" ] ; then
  309. insinto /etc/texmf/language.dat.lua.d
  310. doins "${S}/language.${PN}.dat.lua"
  311. fi
  312. [ -n "${TEXLIVE_MODULE_BINSCRIPTS}" ] && dobin_texmf_scripts ${TEXLIVE_MODULE_BINSCRIPTS}
  313. if [ -n "${TEXLIVE_MODULE_BINLINKS}" ] ; then
  314. for i in ${TEXLIVE_MODULE_BINLINKS} ; do
  315. [ -f "${ED}/usr/bin/${i%:*}" ] || die "Trying to install an invalid BINLINK. This should not happen. Please file a bug."
  316. dosym ${i%:*} /usr/bin/${i#*:}
  317. done
  318. fi
  319. texlive-common_handle_config_files
  320. TEXMF_PATH=${TEXMF_DIST_PATH} texlive-common_handle_config_files
  321. }
  322. # @FUNCTION: texlive-module_pkg_postinst
  323. # @DESCRIPTION:
  324. # exported function:
  325. # Run texmf-update to ensure the tex installation is consistent with the
  326. # installed texmf trees.
  327. texlive-module_pkg_postinst() {
  328. etexmf-update
  329. [ -n "${TL_MODULE_INFORMATION}" ] && elog "${TL_MODULE_INFORMATION}"
  330. }
  331. # @FUNCTION: texlive-module_pkg_postrm
  332. # @DESCRIPTION:
  333. # exported function:
  334. # Run texmf-update to ensure the tex installation is consistent with the
  335. # installed texmf trees.
  336. texlive-module_pkg_postrm() {
  337. etexmf-update
  338. }
  339. EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install \
  340. pkg_postinst pkg_postrm