texlive-common.eclass 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # Copyright 1999-2014 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: texlive-common.eclass
  4. # @MAINTAINER:
  5. # tex@gentoo.org
  6. # @AUTHOR:
  7. # Original Author: Alexis Ballier <aballier@gentoo.org>
  8. # @BLURB: Provide various functions used by both texlive-core and texlive modules
  9. # @DESCRIPTION:
  10. # Purpose: Provide various functions used by both texlive-core and texlive
  11. # modules.
  12. #
  13. # Note that this eclass *must* not assume the presence of any standard tex tool
  14. case "${EAPI:-0}" in
  15. 0|1|2)
  16. die "EAPI='${EAPI}' is not supported anymore"
  17. ;;
  18. *)
  19. ;;
  20. esac
  21. TEXMF_PATH=/usr/share/texmf
  22. TEXMF_DIST_PATH=/usr/share/texmf-dist
  23. TEXMF_VAR_PATH=/var/lib/texmf
  24. # @FUNCTION: texlive-common_handle_config_files
  25. # @DESCRIPTION:
  26. # Has to be called in src_install after having installed the files in ${D}
  27. # This function will move the relevant files to /etc/texmf and symling them
  28. # from their original location. This is to allow easy update of texlive's
  29. # configuration
  30. texlive-common_handle_config_files() {
  31. # Handle config files properly
  32. [ -d "${ED}${TEXMF_PATH}" ] || return
  33. cd "${ED}${TEXMF_PATH}"
  34. for f in $(find . -name '*.cnf' -type f -o -name '*.cfg' -type f | sed -e "s:\./::g") ; do
  35. if [ "${f#*config}" != "${f}" -o "${f#doc}" != "${f}" -o "${f#source}" != "${f}" -o "${f#tex}" != "${f}" ] ; then
  36. continue
  37. fi
  38. dodir /etc/texmf/$(dirname ${f}).d
  39. einfo "Moving (and symlinking) ${EPREFIX}${TEXMF_PATH}/${f} to ${EPREFIX}/etc/texmf/$(dirname ${f}).d"
  40. mv "${ED}/${TEXMF_PATH}/${f}" "${ED}/etc/texmf/$(dirname ${f}).d" || die "mv ${f} failed."
  41. dosym /etc/texmf/$(dirname ${f}).d/$(basename ${f}) ${TEXMF_PATH}/${f}
  42. done
  43. }
  44. # @FUNCTION: texlive-common_is_file_present_in_texmf
  45. # @DESCRIPTION:
  46. # Return if a file is present in the texmf tree
  47. # Call it from the directory containing texmf and texmf-dist
  48. texlive-common_is_file_present_in_texmf() {
  49. local mark="${T}/$1.found"
  50. [ -d texmf ] && find texmf -name $1 -exec touch "${mark}" \;
  51. [ -d texmf-dist ] && find texmf-dist -name $1 -exec touch "${mark}" \;
  52. [ -f "${mark}" ]
  53. }
  54. # @FUNCTION: texlive-common_do_symlinks
  55. # @USAGE: < src > < dest >
  56. # @DESCRIPTION:
  57. # Mimic the install_link function of texlinks
  58. #
  59. # Should have the same behavior as the one in /usr/bin/texlinks
  60. # except that it is under the control of the package manager
  61. # Note that $1 corresponds to $src and $2 to $dest in this function
  62. # ( Arguments are switched because texlinks main function sends them switched )
  63. # This function should not be called from an ebuild, prefer etexlinks that will
  64. # also do the fmtutil file parsing.
  65. texlive-common_do_symlinks() {
  66. while [ $# != 0 ]; do
  67. case $1 in
  68. cont-??|metafun|mptopdf)
  69. einfo "Symlink $1 skipped (special case)"
  70. ;;
  71. mf)
  72. einfo "Symlink $1 -> $2 skipped (texlive-core takes care of it)"
  73. ;;
  74. *)
  75. if [ $1 = $2 ];
  76. then
  77. einfo "Symlink $1 -> $2 skipped"
  78. elif [ -e "${ED}/usr/bin/$1" -o -L "${ED}/usr/bin/$1" ];
  79. then
  80. einfo "Symlink $1 skipped (file exists)"
  81. else
  82. einfo "Making symlink from $1 to $2"
  83. dosym $2 /usr/bin/$1
  84. fi
  85. ;;
  86. esac
  87. shift; shift;
  88. done
  89. }
  90. # @FUNCTION: etexlinks
  91. # @USAGE: < file >
  92. # @DESCRIPTION:
  93. # Mimic texlinks on a fmtutil format file
  94. #
  95. # $1 has to be a fmtutil format file like fmtutil.cnf
  96. # etexlinks foo will install the symlinks that texlinks --cnffile foo would have
  97. # created. We cannot use texlinks with portage as it is not DESTDIR aware.
  98. # (It would not fail but will not create the symlinks if the target is not in
  99. # the same dir as the source)
  100. # Also, as this eclass must not depend on a tex distribution to be installed we
  101. # cannot use texlinks from here.
  102. etexlinks() {
  103. # Install symlinks from formats to engines
  104. texlive-common_do_symlinks $(sed '/^[ ]*#/d; /^[ ]*$/d' "$1" | awk '{print $1, $2}')
  105. }
  106. # @FUNCTION: dobin_texmf_scripts
  107. # @USAGE: < file1 file2 ... >
  108. # @DESCRIPTION:
  109. # Symlinks a script from the texmf tree to /usr/bin. Requires permissions to be
  110. # correctly set for the file that it will point to.
  111. dobin_texmf_scripts() {
  112. while [ $# -gt 0 ] ; do
  113. local trg=$(basename ${1} | sed 's,\.[^/]*$,,' | tr '[:upper:]' '[:lower:]')
  114. einfo "Installing ${1} as ${trg} bin wrapper"
  115. [ -x "${ED}/usr/share/${1}" ] || die "Trying to install a non existing or non executable symlink to /usr/bin: ${1}"
  116. dosym ../share/${1} /usr/bin/${trg} || die "failed to install ${1} as $trg"
  117. shift
  118. done
  119. }
  120. # @FUNCTION: etexmf-update
  121. # @USAGE: In ebuilds' pkg_postinst and pkg_postrm phases
  122. # @DESCRIPTION:
  123. # Runs texmf-update if it is available and prints a warning otherwise. This
  124. # function helps in factorizing some code.
  125. etexmf-update() {
  126. if has_version 'app-text/texlive-core' ; then
  127. if [ "$ROOT" = "/" ] && [ -x "${EPREFIX}"/usr/sbin/texmf-update ] ; then
  128. "${EPREFIX}"/usr/sbin/texmf-update
  129. else
  130. ewarn "Cannot run texmf-update for some reason."
  131. ewarn "Your texmf tree might be inconsistent with your configuration"
  132. ewarn "Please try to figure what has happened"
  133. fi
  134. fi
  135. }
  136. # @FUNCTION: efmtutil-sys
  137. # @USAGE: In ebuilds' pkg_postinst to force a rebuild of TeX formats.
  138. # @DESCRIPTION:
  139. # Runs fmtutil-sys if it is available and prints a warning otherwise. This
  140. # function helps in factorizing some code.
  141. efmtutil-sys() {
  142. if has_version 'app-text/texlive-core' ; then
  143. if [ "$ROOT" = "/" ] && [ -x "${EPREFIX}"/usr/bin/fmtutil-sys ] ; then
  144. einfo "Rebuilding formats"
  145. "${EPREFIX}"/usr/bin/fmtutil-sys --all &> /dev/null
  146. else
  147. ewarn "Cannot run fmtutil-sys for some reason."
  148. ewarn "Your formats might be inconsistent with your installed ${PN} version"
  149. ewarn "Please try to figure what has happened"
  150. fi
  151. fi
  152. }