prefix.eclass 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Copyright 1999-2009 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: prefix.eclass
  4. # @MAINTAINER:
  5. # Feel free to contact the Prefix team through <prefix@gentoo.org> if
  6. # you have problems, suggestions or questions.
  7. # @BLURB: Eclass to provide Prefix functionality
  8. # @DESCRIPTION:
  9. # Gentoo Prefix allows users to install into a self defined offset
  10. # located somewhere in the filesystem. Prefix ebuilds require
  11. # additional functions and variables which are defined by this eclass.
  12. # @ECLASS-VARIABLE: EPREFIX
  13. # @DESCRIPTION:
  14. # The offset prefix of a Gentoo Prefix installation. When Gentoo Prefix
  15. # is not used, ${EPREFIX} should be "". Prefix Portage sets EPREFIX,
  16. # hence this eclass has nothing to do here in that case.
  17. # Note that setting EPREFIX in the environment with Prefix Portage sets
  18. # Portage into cross-prefix mode.
  19. if [[ ! ${EPREFIX+set} ]]; then
  20. export EPREFIX=''
  21. fi
  22. # @FUNCTION: eprefixify
  23. # @USAGE: <list of to be eprefixified files>
  24. # @DESCRIPTION:
  25. # replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
  26. # dies if no arguments are given, a file does not exist, or changing a
  27. # file failed.
  28. eprefixify() {
  29. [[ $# -lt 1 ]] && die "at least one argument required"
  30. einfo "Adjusting to prefix ${EPREFIX:-/}"
  31. local x
  32. for x in "$@" ; do
  33. if [[ -e ${x} ]] ; then
  34. ebegin " ${x##*/}"
  35. sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
  36. eend $? || die "failed to eprefixify ${x}"
  37. else
  38. die "${x} does not exist"
  39. fi
  40. done
  41. return 0
  42. }
  43. # @FUNCTION: hprefixify
  44. # @USAGE: [ -w <line match> ] [-e <extended regex> ] <list of files>
  45. # @DESCRIPTION:
  46. # Tries a set of heuristics to prefixify the given files. Dies if no
  47. # arguments are given, a file does not exist, or changing a file failed.
  48. #
  49. # Additional extended regular expression can be passed by -e or
  50. # environment variable PREFIX_EXTRA_REGEX. The default heuristics can
  51. # be constrained to lines that match a sed expression passed by -w or
  52. # environment variable PREFIX_LINE_MATCH.
  53. # @EXAMPLE:
  54. # Only prefixify the 30th line,
  55. # hprefixify -w 30 configure
  56. # Only prefixify lines that contain "PATH",
  57. # hprefixify -w "/PATH/" configure
  58. # Also delete all the /opt/gnu search paths,
  59. # hprefixify -e "/\/opt\/gnu/d" configure
  60. hprefixify() {
  61. use prefix || return 0
  62. local PREFIX_EXTRA_REGEX PREFIX_LINE_MATCH xl=() x
  63. while [[ $# -gt 0 ]]; do
  64. case $1 in
  65. -e)
  66. PREFIX_EXTRA_REGEX="$2"
  67. shift
  68. ;;
  69. -w)
  70. PREFIX_LINE_MATCH="$2"
  71. shift
  72. ;;
  73. *)
  74. xl+=( "$1" )
  75. ;;
  76. esac
  77. shift
  78. done
  79. [[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required"
  80. einfo "Adjusting to prefix ${EPREFIX:-/}"
  81. for x in "${xl[@]}" ; do
  82. if [[ -e ${x} ]] ; then
  83. ebegin " ${x##*/}"
  84. sed -r \
  85. -e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt|run),\1${EPREFIX}/\2,g" \
  86. -e "${PREFIX_EXTRA_REGEX}" \
  87. -i "${x}"
  88. eend $? || die "failed to prefixify ${x}"
  89. else
  90. die "${x} does not exist"
  91. fi
  92. done
  93. }
  94. # @FUNCTION: prefixify_ro
  95. # @USAGE: prefixify_ro <file>.
  96. # @DESCRIPTION:
  97. # prefixify a read-only file.
  98. # copies the files to ${T}, prefixies it, echos the new file.
  99. # @EXAMPLE:
  100. # doexe "$(prefixify_ro "${FILESDIR}"/fix_libtool_files.sh)"
  101. # epatch "$(prefixify_ro "${FILESDIR}"/${PN}-4.0.2-path.patch)"
  102. prefixify_ro() {
  103. if [[ -e $1 ]] ; then
  104. local f=${1##*/}
  105. cp "$1" "${T}" || die "failed to copy file"
  106. local x="${T}"/${f}
  107. # redirect to stderr because stdout is used to
  108. # return the prefixified file.
  109. if grep -qs @GENTOO_PORTAGE_EPREFIX@ "${x}" ; then
  110. eprefixify "${T}"/${f} 1>&2
  111. else
  112. hprefixify "${T}"/${f} 1>&2
  113. fi
  114. echo "${x}"
  115. else
  116. die "$1 does not exist"
  117. fi
  118. }
  119. # vim: tw=72: