You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.7 KiB

  1. # -*-eselect-*- vim: ft=eselect
  2. # Copyright 2005-2020 Gentoo Authors
  3. # Distributed under the terms of the GNU General Public License v2 or later
  4. inherit config multilib
  5. DESCRIPTION="Manage the LuaJIT symlink"
  6. MAINTAINER="mva@gentoo.org"
  7. VERSION="1"
  8. # sort function for luajit versions, to be used in a pipe
  9. sort_luajit_versions() {
  10. local vsort="sort --version-sort"
  11. ${vsort} </dev/null &>/dev/null || vsort=sort
  12. sed -e 's/^\(luajit-\)\?\([[:digit:].]\+\)[-_]beta/\2 0 &/' \
  13. -e 't;s/^\(luajit-\)\?\([[:digit:].]\+\)/\2 1 &/' \
  14. | LC_ALL=C ${vsort} | sed 's/.* //'
  15. }
  16. # find a list of luajit symlink targets
  17. find_targets() {
  18. local f
  19. for f in $(find "${EROOT}"/usr/bin/ -type f -iname 'luajit-[[:digit:]]*'); do
  20. basename "${f}"
  21. done | sort_luajit_versions
  22. }
  23. get_libdirs() {
  24. local dir libdirs
  25. for dir in $(list_libdirs); do
  26. [[ -L ${EROOT}/usr/${dir} ]] && continue
  27. ls "${EROOT}"/usr/${dir}/libluajit*.* > /dev/null 2>&1 || continue
  28. libdirs+=' '/usr/${dir}
  29. done
  30. echo ${libdirs:-/usr/lib}
  31. }
  32. # remove the luajit symlink
  33. remove_symlinks() {
  34. for dir in $(get_libdirs) ; do
  35. [[ -L "${dir}/libluajit-5.1.so" ]] && rm "${dir}/libluajit-5.1.so"
  36. [[ -L "${dir}/libluajit-5.1.a" ]] && rm "${dir}/libluajit-5.1.a"
  37. [[ -L "${dir}/pkgconfig/luajit.pc" ]] && rm "${dir}/pkgconfig/luajit.pc"
  38. done
  39. [[ -L "${EROOT}/usr/bin/luajit" ]] && rm "${EROOT}/usr/bin/luajit"
  40. rm -f "${EROOT}"/usr/share/man/man1/luajit.1{,.gz,.bz2,.lzma} &>/dev/null
  41. }
  42. # set the luajit symlink
  43. set_symlinks() {
  44. local target=$1
  45. if is_number "${target}"; then
  46. local targets=( $(find_targets) )
  47. target=${targets[target-1]}
  48. fi
  49. if [[ -z ${target} ]]; then
  50. die -q "Target \"$1\" doesn't appear to be valid!"
  51. elif [[ -f ${EROOT}/usr/bin/${target} ]]; then
  52. ln -s "${target}" "${EROOT}/usr/bin/luajit"
  53. for dir in $(get_libdirs) ; do
  54. [[ -e "${dir}/lib${target}.so" ]] && ln -s "lib${target}.so" "${dir}/libluajit-5.1.so"
  55. [[ -e "${dir}/lib${target}.a" ]] && ln -s "lib${target}.a" "${dir}/libluajit-5.1.a"
  56. [[ -e "${dir}/pkgconfig/${target}.pc" ]] && ln -s "${target}.pc" "${dir}/pkgconfig/luajit.pc"
  57. done
  58. for orig in "${EROOT}"/usr/share/man/man1/$target.1* ; do
  59. ln -s "$(basename ${orig})" "${orig/$target/luajit}"
  60. done
  61. else
  62. die -q "Target \"$1\" doesn't appear to be valid!"
  63. fi
  64. }
  65. ### show action ###
  66. describe_show() {
  67. echo "Show the current luajit symlink"
  68. }
  69. do_show() {
  70. write_list_start "Current luajit symlink:"
  71. if [[ -L ${EROOT}/usr/bin/luajit ]]; then
  72. local SV=$(readlink "${EROOT}/usr/bin/luajit")
  73. write_kv_list_entry "${SV%/}"
  74. else
  75. write_kv_list_entry "(unset)"
  76. fi
  77. }
  78. ### list action ###
  79. describe_list() {
  80. echo "List available luajit symlink targets"
  81. }
  82. do_list() {
  83. local i targets=( $(find_targets) )
  84. write_list_start "Available luajit symlink targets:"
  85. local SV=$(readlink "${EROOT}/usr/bin/luajit")
  86. for (( i = 0; i < ${#targets[@]}; i++ )); do
  87. [[ ${targets[i]} = \
  88. $(basename "${SV}") ]] \
  89. && targets[i]=$(highlight_marker "${targets[i]}")
  90. done
  91. write_numbered_list -m "(none found)" "${targets[@]}"
  92. }
  93. ### set action ###
  94. describe_set() {
  95. echo "Set a new luajit symlink target"
  96. }
  97. describe_set_parameters() {
  98. echo "<target>"
  99. }
  100. describe_set_options() {
  101. echo "target : Target name or number (from 'list' action)"
  102. }
  103. do_set() {
  104. [[ -z $1 ]] && die -q "You didn't tell me what to set the symlink to"
  105. [[ $# -gt 1 ]] && die -q "Too many parameters"
  106. if [[ -L ${EROOT}/usr/bin/luajit ]]; then
  107. # existing symlink
  108. remove_symlinks || die -q "Couldn't remove existing symlink"
  109. set_symlinks "$1" || die -q "Couldn't set a new symlink"
  110. elif [[ -e ${EROOT}/usr/bin/luajit ]]; then
  111. # we have something strange
  112. die -q "${EROOT}/usr/bin/luajit exists but is not a symlink"
  113. else
  114. set_symlinks "$1" || die -q "Couldn't set a new symlink"
  115. fi
  116. }