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.

265 lines
5.5 KiB

11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
11 years ago
  1. #! /bin/sh
  2. # Wrapper for Microsoft lib.exe
  3. me=ar-lib
  4. scriptversion=2012-01-30.22; # UTC
  5. # Copyright (C) 2010, 2012 Free Software Foundation, Inc.
  6. # Written by Peter Rosin <peda@lysator.liu.se>.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # 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 License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. # As a special exception to the GNU General Public License, if you
  21. # distribute this file as part of a program that contains a
  22. # configuration script generated by Autoconf, you may include it under
  23. # the same distribution terms that you use for the rest of that program.
  24. # This file is maintained in Automake, please report
  25. # bugs to <bug-automake@gnu.org> or send patches to
  26. # <automake-patches@gnu.org>.
  27. # func_error message
  28. func_error ()
  29. {
  30. echo "$me: $1" 1>&2
  31. exit 1
  32. }
  33. file_conv=
  34. # func_file_conv build_file
  35. # Convert a $build file to $host form and store it in $file
  36. # Currently only supports Windows hosts.
  37. func_file_conv ()
  38. {
  39. file=$1
  40. case $file in
  41. / | /[!/]*) # absolute file, and not a UNC file
  42. if test -z "$file_conv"; then
  43. # lazily determine how to convert abs files
  44. case `uname -s` in
  45. MINGW*)
  46. file_conv=mingw
  47. ;;
  48. CYGWIN*)
  49. file_conv=cygwin
  50. ;;
  51. *)
  52. file_conv=wine
  53. ;;
  54. esac
  55. fi
  56. case $file_conv in
  57. mingw)
  58. file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
  59. ;;
  60. cygwin)
  61. file=`cygpath -m "$file" || echo "$file"`
  62. ;;
  63. wine)
  64. file=`winepath -w "$file" || echo "$file"`
  65. ;;
  66. esac
  67. ;;
  68. esac
  69. }
  70. # func_at_file at_file operation archive
  71. # Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
  72. # for each of them.
  73. # When interpreting the content of the @FILE, do NOT use func_file_conv,
  74. # since the user would need to supply preconverted file names to
  75. # binutils ar, at least for MinGW.
  76. func_at_file ()
  77. {
  78. operation=$2
  79. archive=$3
  80. at_file_contents=`cat "$1"`
  81. eval set x "$at_file_contents"
  82. shift
  83. for member
  84. do
  85. $AR -NOLOGO $operation:"$member" "$archive" || exit $?
  86. done
  87. }
  88. case $1 in
  89. '')
  90. func_error "no command. Try '$0 --help' for more information."
  91. ;;
  92. -h | --h*)
  93. cat <<EOF
  94. Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
  95. Members may be specified in a file named with @FILE.
  96. EOF
  97. exit $?
  98. ;;
  99. -v | --v*)
  100. echo "$me, version $scriptversion"
  101. exit $?
  102. ;;
  103. esac
  104. if test $# -lt 3; then
  105. func_error "you must specify a program, an action and an archive"
  106. fi
  107. AR=$1
  108. shift
  109. while :
  110. do
  111. if test $# -lt 2; then
  112. func_error "you must specify a program, an action and an archive"
  113. fi
  114. case $1 in
  115. -lib | -LIB \
  116. | -ltcg | -LTCG \
  117. | -machine* | -MACHINE* \
  118. | -subsystem* | -SUBSYSTEM* \
  119. | -verbose | -VERBOSE \
  120. | -wx* | -WX* )
  121. AR="$AR $1"
  122. shift
  123. ;;
  124. *)
  125. action=$1
  126. shift
  127. break
  128. ;;
  129. esac
  130. done
  131. orig_archive=$1
  132. shift
  133. func_file_conv "$orig_archive"
  134. archive=$file
  135. # strip leading dash in $action
  136. action=${action#-}
  137. delete=
  138. extract=
  139. list=
  140. replace=
  141. create=
  142. while test -n "$action"
  143. do
  144. case $action in
  145. d*) delete=yes ;;
  146. x*) extract=yes ;;
  147. t*) list=yes ;;
  148. r*) replace=yes ;;
  149. c*) create=yes ;;
  150. u*) ;; # TODO: don't ignore the update modifier
  151. v*) ;; # TODO: don't ignore the verbose modifier
  152. *)
  153. func_error "unknown action specified"
  154. ;;
  155. esac
  156. action=${action#?}
  157. done
  158. case $delete$extract$list$replace in
  159. yes)
  160. ;;
  161. yesyes*)
  162. func_error "more than one action specified"
  163. ;;
  164. *)
  165. func_error "no action specified"
  166. ;;
  167. esac
  168. if test -n "$delete"; then
  169. if test ! -f "$orig_archive"; then
  170. func_error "archive not found"
  171. fi
  172. for member
  173. do
  174. case $1 in
  175. @*)
  176. func_at_file "${1#@}" -REMOVE "$archive"
  177. ;;
  178. *)
  179. func_file_conv "$1"
  180. $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
  181. ;;
  182. esac
  183. done
  184. elif test -n "$extract"; then
  185. if test ! -f "$orig_archive"; then
  186. func_error "archive not found"
  187. fi
  188. if test $# -gt 0; then
  189. for member
  190. do
  191. case $1 in
  192. @*)
  193. func_at_file "${1#@}" -EXTRACT "$archive"
  194. ;;
  195. *)
  196. func_file_conv "$1"
  197. $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
  198. ;;
  199. esac
  200. done
  201. else
  202. $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member
  203. do
  204. $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
  205. done
  206. fi
  207. elif test -n "$replace"; then
  208. if test ! -f "$orig_archive"; then
  209. if test -z "$create"; then
  210. echo "$me: creating $orig_archive"
  211. fi
  212. orig_archive=
  213. else
  214. orig_archive=$archive
  215. fi
  216. for member
  217. do
  218. case $1 in
  219. @*)
  220. func_file_conv "${1#@}"
  221. set x "$@" "@$file"
  222. ;;
  223. *)
  224. func_file_conv "$1"
  225. set x "$@" "$file"
  226. ;;
  227. esac
  228. shift
  229. shift
  230. done
  231. if test -n "$orig_archive"; then
  232. $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
  233. else
  234. $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
  235. fi
  236. elif test -n "$list"; then
  237. if test ! -f "$orig_archive"; then
  238. func_error "archive not found"
  239. fi
  240. $AR -NOLOGO -LIST "$archive" || exit $?
  241. fi