setup-gettext 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/bin/sh
  2. #
  3. # setup-gettext - Provides compatibility with versions of gettext
  4. # from the 0.10.x series and 0.11.x.
  5. #
  6. # Copyright (C) 2002 Christian Hammond.
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License as
  10. # published by the Free Software Foundation; either version 2 of
  11. # the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public
  19. # License along with this program; if not, write to the Free
  20. # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. # MA 02111-1307 USA
  22. #
  23. VERSION=0.1.3
  24. VERBOSE=1
  25. parse_gettext_version() {
  26. GETTEXT_VERSION=`$GETTEXT_TOOL --version | sed -n 's/^.*\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\).*$/\1.\2.\3/p'`
  27. GETTEXT_MAJOR_VERSION=`echo $GETTEXT_VERSION | sed -n 's/^\([0-9]\+\).*/\1/p'`
  28. GETTEXT_MINOR_VERSION=`echo $GETTEXT_VERSION | sed -n 's/^[0-9]\+\.\([0-9]\+\).*/\1/p'`
  29. GETTEXT_MICRO_VERSION=`echo $GETTEXT_VERSION | sed -n 's/^[0-9]\+\.[0-9]\+\.\([0-9]\+\).*/\1/p'`
  30. }
  31. find_gettext() {
  32. GETTEXT_TOOL=autopoint
  33. (autopoint --version) < /dev/null > /dev/null 2>&1 || {
  34. GETTEXT_TOOL=gettextize
  35. (gettextize --version) < /dev/null > /dev/null 2>&1 || {
  36. GETTEXT_TOOL=
  37. }
  38. }
  39. }
  40. install() {
  41. [ -f configure.in ] && {
  42. cp configure.in .tmp-configure.in
  43. sed -e 's/^AM_GNU_GETTEXT\(.*\)$/AM_GNU_GETTEXT\1\
  44. AM_GNU_GETTEXT_VERSION(0.10.40)/' < .tmp-configure.in > configure.in
  45. rm .tmp-configure.in
  46. }
  47. [ -f configure.ac ] && {
  48. cp configure.ac .tmp-configure.ac
  49. sed -e 's/^AM_GNU_GETTEXT\(.*\)$/AM_GNU_GETTEXT\1\
  50. AM_GNU_GETTEXT_VERSION(0.10.40)/' < .tmp-configure.ac > configure.ac
  51. rm .tmp-configure.ac
  52. }
  53. [ -f autogen.sh ] && {
  54. cp autogen.sh .tmp-autogen.sh
  55. sed -e 's/\(gettextize\|autopoint\) --version/.\/setup-gettext --gettext-tool/1' -e 's/^\(echo.*|[\t ]*\)\?\(gettextize\|autopoint\) -.*$/.\/setup-gettext/1' < .tmp-autogen.sh > autogen.sh
  56. rm .tmp-autogen.sh
  57. }
  58. echo 'AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])' >> acinclude.m4
  59. }
  60. backup_m4() {
  61. [ -d m4 ] && mv m4 m4~
  62. }
  63. restore_m4() {
  64. [ -d m4~ ] && {
  65. rm -rf m4
  66. mv m4~ m4
  67. }
  68. }
  69. restore_files() {
  70. [ -f configure.in~ ] && mv -f configure.in~ configure.in
  71. [ -f configure.ac~ ] && mv -f configure.ac~ configure.ac
  72. [ -f Makefile.am~ ] && mv -f Makefile.am~ Makefile.am
  73. }
  74. abort() {
  75. restore_files
  76. restore_m4
  77. exit 1
  78. }
  79. # Main code
  80. find_gettext
  81. # See if a version of gettext and its tools are installed.
  82. if [ x$GETTEXT_TOOL = x ]; then
  83. echo
  84. echo "You do not have a version of gettext installed."
  85. echo "Please download one from your local package repository or"
  86. echo "from ftp://ftp.gnu.org/pub/gnu/gettext/"
  87. echo
  88. exit 1
  89. fi
  90. parse_gettext_version
  91. NUMVAR=$#
  92. if [ $NUMVAR -gt 0 ]; then
  93. if [ $NUMVAR -gt 1 ]; then
  94. echo "Only one option at a time!"
  95. exit 1
  96. elif [ $1 = "--gettext-tool" ]; then
  97. echo $GETTEXT_TOOL
  98. exit 0
  99. elif [ $1 = "--help" ]; then
  100. echo "setup-gettext v$VERSION"
  101. echo "Usage:"
  102. echo " --gettext-tool Returns gettextize or autopoint, depending"
  103. echo " on the version of gettext installed."
  104. echo " --gettext-version Returns the version of gettext installed."
  105. echo " --gettext-major-version Returns the major version of gettext installed."
  106. echo " --gettext-minor-version Returns the minor version of gettext installed."
  107. echo " --gettext-micro-version Returns the micro version of gettext installed."
  108. echo " --help Displays this help screen."
  109. echo
  110. exit 0
  111. elif [ $1 = "--version" ]; then
  112. echo $VERSION
  113. exit 0
  114. elif [ $1 = "--gettext-version" ]; then
  115. echo $GETTEXT_VERSION
  116. exit 0
  117. elif [ $1 = "--gettext-major-version" ]; then
  118. echo $GETTEXT_MAJOR_VERSION
  119. exit 0
  120. elif [ $1 = "--gettext-minor-version" ]; then
  121. echo $GETTEXT_MINOR_VERSION
  122. exit 0
  123. elif [ $1 = "--gettext-micro-version" ]; then
  124. echo $GETTEXT_MICRO_VERSION
  125. exit 0
  126. elif [ $1 = "--install" ]; then
  127. install
  128. echo "setup-gettext installed."
  129. exit 0
  130. elif [ $1 = "--happy-url" ]; then
  131. echo http://gaim.sf.net/forkgettext.jpg
  132. exit 0
  133. elif [ $1 = "--verbose" ]; then
  134. VERBOSE=1
  135. else
  136. echo "Invalid option '$1'"
  137. exit 1
  138. fi
  139. fi
  140. # Okay, run the main stuff
  141. if [ "$GETTEXT_TOOL" = "autopoint" ]; then
  142. backup_m4
  143. [ $VERBOSE -eq 1 ] && echo " autopoint --force"
  144. echo n | autopoint --force || abort
  145. restore_m4
  146. else
  147. if [ $GETTEXT_MINOR_VERSION -eq 11 ]; then
  148. backup_m4
  149. # Gettext is pure evil. It DEMANDS that we press Return no matter
  150. # what. This gets rid of their happy "feature" of doom.
  151. [ $VERBOSE -eq 1 ] && \
  152. echo " gettextize --copy --force --intl --no-changelog"
  153. sed 's:read .*< /dev/tty::' `which gettextize` > .temp-gettextize
  154. chmod +x .temp-gettextize
  155. echo n | ./.temp-gettextize --copy --force --intl --no-changelog || abort
  156. rm .temp-gettextize
  157. restore_files
  158. restore_m4
  159. [ -f po/Makevars.template ] && mv po/Makevars.template po/Makevars
  160. else
  161. [ $VERBOSE -eq 1 ] && echo " gettextize --copy --force --intl"
  162. echo n | gettextize --copy --force --intl || exit;
  163. fi
  164. fi