1
0

ar-lib 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. #! /bin/sh
  2. # Wrapper for Microsoft lib.exe
  3. me=ar-lib
  4. scriptversion=2024-06-19.01; # UTC
  5. # Copyright (C) 2010-2024 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 <https://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* | MSYS*)
  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 | msys)
  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. Report bugs to <bug-automake@gnu.org>.
  97. GNU Automake home page: <https://www.gnu.org/software/automake/>.
  98. General help using GNU software: <https://www.gnu.org/gethelp/>.
  99. EOF
  100. exit $?
  101. ;;
  102. -v | --v*)
  103. echo "$me (GNU Automake) $scriptversion"
  104. exit $?
  105. ;;
  106. esac
  107. if test $# -lt 3; then
  108. func_error "you must specify a program, an action and an archive"
  109. fi
  110. AR=$1
  111. shift
  112. while :
  113. do
  114. if test $# -lt 2; then
  115. func_error "you must specify a program, an action and an archive"
  116. fi
  117. case $1 in
  118. -lib | -LIB \
  119. | -ltcg | -LTCG \
  120. | -machine* | -MACHINE* \
  121. | -subsystem* | -SUBSYSTEM* \
  122. | -verbose | -VERBOSE \
  123. | -wx* | -WX* )
  124. AR="$AR $1"
  125. shift
  126. ;;
  127. -nologo | -NOLOGO)
  128. # We always invoke AR with -nologo, so don't need to add it again.
  129. shift
  130. ;;
  131. *)
  132. action=$1
  133. shift
  134. break
  135. ;;
  136. esac
  137. done
  138. orig_archive=$1
  139. shift
  140. func_file_conv "$orig_archive"
  141. archive=$file
  142. # strip leading dash in $action
  143. action=${action#-}
  144. delete=
  145. extract=
  146. list=
  147. quick=
  148. replace=
  149. index=
  150. create=
  151. while test -n "$action"
  152. do
  153. case $action in
  154. d*) delete=yes ;;
  155. x*) extract=yes ;;
  156. t*) list=yes ;;
  157. q*) quick=yes ;;
  158. r*) replace=yes ;;
  159. s*) index=yes ;;
  160. S*) ;; # the index is always updated implicitly
  161. c*) create=yes ;;
  162. u*) ;; # TODO: don't ignore the update modifier
  163. v*) ;; # TODO: don't ignore the verbose modifier
  164. *)
  165. func_error "unknown action specified"
  166. ;;
  167. esac
  168. action=${action#?}
  169. done
  170. case $delete$extract$list$quick$replace,$index in
  171. yes,* | ,yes)
  172. ;;
  173. yesyes*)
  174. func_error "more than one action specified"
  175. ;;
  176. *)
  177. func_error "no action specified"
  178. ;;
  179. esac
  180. if test -n "$delete"; then
  181. if test ! -f "$orig_archive"; then
  182. func_error "archive not found"
  183. fi
  184. for member
  185. do
  186. case $1 in
  187. @*)
  188. func_at_file "${1#@}" -REMOVE "$archive"
  189. ;;
  190. *)
  191. func_file_conv "$1"
  192. $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
  193. ;;
  194. esac
  195. done
  196. elif test -n "$extract"; then
  197. if test ! -f "$orig_archive"; then
  198. func_error "archive not found"
  199. fi
  200. if test $# -gt 0; then
  201. for member
  202. do
  203. case $1 in
  204. @*)
  205. func_at_file "${1#@}" -EXTRACT "$archive"
  206. ;;
  207. *)
  208. func_file_conv "$1"
  209. $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
  210. ;;
  211. esac
  212. done
  213. else
  214. $AR -NOLOGO -LIST "$archive" | tr -d '\r' | sed -e 's/\\/\\\\/g' \
  215. | while read member
  216. do
  217. $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
  218. done
  219. fi
  220. elif test -n "$quick$replace"; then
  221. if test ! -f "$orig_archive"; then
  222. if test -z "$create"; then
  223. echo "$me: creating $orig_archive"
  224. fi
  225. orig_archive=
  226. else
  227. orig_archive=$archive
  228. fi
  229. for member
  230. do
  231. case $1 in
  232. @*)
  233. func_file_conv "${1#@}"
  234. set x "$@" "@$file"
  235. ;;
  236. *)
  237. func_file_conv "$1"
  238. set x "$@" "$file"
  239. ;;
  240. esac
  241. shift
  242. shift
  243. done
  244. if test -n "$orig_archive"; then
  245. $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
  246. else
  247. $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
  248. fi
  249. elif test -n "$list"; then
  250. if test ! -f "$orig_archive"; then
  251. func_error "archive not found"
  252. fi
  253. $AR -NOLOGO -LIST "$archive" || exit $?
  254. fi