xref: /freebsd/contrib/ntp/sntp/libevent/build-aux/ar-lib (revision e43d33d286a1aa41b6fc6a209f28a18e8cd7437a)
1276da39aSCy Schubert#! /bin/sh
2276da39aSCy Schubert# Wrapper for Microsoft lib.exe
3276da39aSCy Schubert
4276da39aSCy Schubertme=ar-lib
5276da39aSCy Schubertscriptversion=2012-03-01.08; # UTC
6276da39aSCy Schubert
7*2d4e511cSCy Schubert# Copyright (C) 2010-2014 Free Software Foundation, Inc.
8276da39aSCy Schubert# Written by Peter Rosin <peda@lysator.liu.se>.
9276da39aSCy Schubert#
10276da39aSCy Schubert# This program is free software; you can redistribute it and/or modify
11276da39aSCy Schubert# it under the terms of the GNU General Public License as published by
12276da39aSCy Schubert# the Free Software Foundation; either version 2, or (at your option)
13276da39aSCy Schubert# any later version.
14276da39aSCy Schubert#
15276da39aSCy Schubert# This program is distributed in the hope that it will be useful,
16276da39aSCy Schubert# but WITHOUT ANY WARRANTY; without even the implied warranty of
17276da39aSCy Schubert# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18276da39aSCy Schubert# GNU General Public License for more details.
19276da39aSCy Schubert#
20276da39aSCy Schubert# You should have received a copy of the GNU General Public License
21276da39aSCy Schubert# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22276da39aSCy Schubert
23276da39aSCy Schubert# As a special exception to the GNU General Public License, if you
24276da39aSCy Schubert# distribute this file as part of a program that contains a
25276da39aSCy Schubert# configuration script generated by Autoconf, you may include it under
26276da39aSCy Schubert# the same distribution terms that you use for the rest of that program.
27276da39aSCy Schubert
28276da39aSCy Schubert# This file is maintained in Automake, please report
29276da39aSCy Schubert# bugs to <bug-automake@gnu.org> or send patches to
30276da39aSCy Schubert# <automake-patches@gnu.org>.
31276da39aSCy Schubert
32276da39aSCy Schubert
33276da39aSCy Schubert# func_error message
34276da39aSCy Schubertfunc_error ()
35276da39aSCy Schubert{
36276da39aSCy Schubert  echo "$me: $1" 1>&2
37276da39aSCy Schubert  exit 1
38276da39aSCy Schubert}
39276da39aSCy Schubert
40276da39aSCy Schubertfile_conv=
41276da39aSCy Schubert
42276da39aSCy Schubert# func_file_conv build_file
43276da39aSCy Schubert# Convert a $build file to $host form and store it in $file
44276da39aSCy Schubert# Currently only supports Windows hosts.
45276da39aSCy Schubertfunc_file_conv ()
46276da39aSCy Schubert{
47276da39aSCy Schubert  file=$1
48276da39aSCy Schubert  case $file in
49276da39aSCy Schubert    / | /[!/]*) # absolute file, and not a UNC file
50276da39aSCy Schubert      if test -z "$file_conv"; then
51276da39aSCy Schubert	# lazily determine how to convert abs files
52276da39aSCy Schubert	case `uname -s` in
53276da39aSCy Schubert	  MINGW*)
54276da39aSCy Schubert	    file_conv=mingw
55276da39aSCy Schubert	    ;;
56276da39aSCy Schubert	  CYGWIN*)
57276da39aSCy Schubert	    file_conv=cygwin
58276da39aSCy Schubert	    ;;
59276da39aSCy Schubert	  *)
60276da39aSCy Schubert	    file_conv=wine
61276da39aSCy Schubert	    ;;
62276da39aSCy Schubert	esac
63276da39aSCy Schubert      fi
64276da39aSCy Schubert      case $file_conv in
65276da39aSCy Schubert	mingw)
66276da39aSCy Schubert	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
67276da39aSCy Schubert	  ;;
68276da39aSCy Schubert	cygwin)
69276da39aSCy Schubert	  file=`cygpath -m "$file" || echo "$file"`
70276da39aSCy Schubert	  ;;
71276da39aSCy Schubert	wine)
72276da39aSCy Schubert	  file=`winepath -w "$file" || echo "$file"`
73276da39aSCy Schubert	  ;;
74276da39aSCy Schubert      esac
75276da39aSCy Schubert      ;;
76276da39aSCy Schubert  esac
77276da39aSCy Schubert}
78276da39aSCy Schubert
79276da39aSCy Schubert# func_at_file at_file operation archive
80276da39aSCy Schubert# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
81276da39aSCy Schubert# for each of them.
82276da39aSCy Schubert# When interpreting the content of the @FILE, do NOT use func_file_conv,
83276da39aSCy Schubert# since the user would need to supply preconverted file names to
84276da39aSCy Schubert# binutils ar, at least for MinGW.
85276da39aSCy Schubertfunc_at_file ()
86276da39aSCy Schubert{
87276da39aSCy Schubert  operation=$2
88276da39aSCy Schubert  archive=$3
89276da39aSCy Schubert  at_file_contents=`cat "$1"`
90276da39aSCy Schubert  eval set x "$at_file_contents"
91276da39aSCy Schubert  shift
92276da39aSCy Schubert
93276da39aSCy Schubert  for member
94276da39aSCy Schubert  do
95276da39aSCy Schubert    $AR -NOLOGO $operation:"$member" "$archive" || exit $?
96276da39aSCy Schubert  done
97276da39aSCy Schubert}
98276da39aSCy Schubert
99276da39aSCy Schubertcase $1 in
100276da39aSCy Schubert  '')
101276da39aSCy Schubert     func_error "no command.  Try '$0 --help' for more information."
102276da39aSCy Schubert     ;;
103276da39aSCy Schubert  -h | --h*)
104276da39aSCy Schubert    cat <<EOF
105276da39aSCy SchubertUsage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
106276da39aSCy Schubert
107276da39aSCy SchubertMembers may be specified in a file named with @FILE.
108276da39aSCy SchubertEOF
109276da39aSCy Schubert    exit $?
110276da39aSCy Schubert    ;;
111276da39aSCy Schubert  -v | --v*)
112276da39aSCy Schubert    echo "$me, version $scriptversion"
113276da39aSCy Schubert    exit $?
114276da39aSCy Schubert    ;;
115276da39aSCy Schubertesac
116276da39aSCy Schubert
117276da39aSCy Schubertif test $# -lt 3; then
118276da39aSCy Schubert  func_error "you must specify a program, an action and an archive"
119276da39aSCy Schubertfi
120276da39aSCy Schubert
121276da39aSCy SchubertAR=$1
122276da39aSCy Schubertshift
123276da39aSCy Schubertwhile :
124276da39aSCy Schubertdo
125276da39aSCy Schubert  if test $# -lt 2; then
126276da39aSCy Schubert    func_error "you must specify a program, an action and an archive"
127276da39aSCy Schubert  fi
128276da39aSCy Schubert  case $1 in
129276da39aSCy Schubert    -lib | -LIB \
130276da39aSCy Schubert    | -ltcg | -LTCG \
131276da39aSCy Schubert    | -machine* | -MACHINE* \
132276da39aSCy Schubert    | -subsystem* | -SUBSYSTEM* \
133276da39aSCy Schubert    | -verbose | -VERBOSE \
134276da39aSCy Schubert    | -wx* | -WX* )
135276da39aSCy Schubert      AR="$AR $1"
136276da39aSCy Schubert      shift
137276da39aSCy Schubert      ;;
138276da39aSCy Schubert    *)
139276da39aSCy Schubert      action=$1
140276da39aSCy Schubert      shift
141276da39aSCy Schubert      break
142276da39aSCy Schubert      ;;
143276da39aSCy Schubert  esac
144276da39aSCy Schubertdone
145276da39aSCy Schubertorig_archive=$1
146276da39aSCy Schubertshift
147276da39aSCy Schubertfunc_file_conv "$orig_archive"
148276da39aSCy Schubertarchive=$file
149276da39aSCy Schubert
150276da39aSCy Schubert# strip leading dash in $action
151276da39aSCy Schubertaction=${action#-}
152276da39aSCy Schubert
153276da39aSCy Schubertdelete=
154276da39aSCy Schubertextract=
155276da39aSCy Schubertlist=
156276da39aSCy Schubertquick=
157276da39aSCy Schubertreplace=
158276da39aSCy Schubertindex=
159276da39aSCy Schubertcreate=
160276da39aSCy Schubert
161276da39aSCy Schubertwhile test -n "$action"
162276da39aSCy Schubertdo
163276da39aSCy Schubert  case $action in
164276da39aSCy Schubert    d*) delete=yes  ;;
165276da39aSCy Schubert    x*) extract=yes ;;
166276da39aSCy Schubert    t*) list=yes    ;;
167276da39aSCy Schubert    q*) quick=yes   ;;
168276da39aSCy Schubert    r*) replace=yes ;;
169276da39aSCy Schubert    s*) index=yes   ;;
170276da39aSCy Schubert    S*)             ;; # the index is always updated implicitly
171276da39aSCy Schubert    c*) create=yes  ;;
172276da39aSCy Schubert    u*)             ;; # TODO: don't ignore the update modifier
173276da39aSCy Schubert    v*)             ;; # TODO: don't ignore the verbose modifier
174276da39aSCy Schubert    *)
175276da39aSCy Schubert      func_error "unknown action specified"
176276da39aSCy Schubert      ;;
177276da39aSCy Schubert  esac
178276da39aSCy Schubert  action=${action#?}
179276da39aSCy Schubertdone
180276da39aSCy Schubert
181276da39aSCy Schubertcase $delete$extract$list$quick$replace,$index in
182276da39aSCy Schubert  yes,* | ,yes)
183276da39aSCy Schubert    ;;
184276da39aSCy Schubert  yesyes*)
185276da39aSCy Schubert    func_error "more than one action specified"
186276da39aSCy Schubert    ;;
187276da39aSCy Schubert  *)
188276da39aSCy Schubert    func_error "no action specified"
189276da39aSCy Schubert    ;;
190276da39aSCy Schubertesac
191276da39aSCy Schubert
192276da39aSCy Schubertif test -n "$delete"; then
193276da39aSCy Schubert  if test ! -f "$orig_archive"; then
194276da39aSCy Schubert    func_error "archive not found"
195276da39aSCy Schubert  fi
196276da39aSCy Schubert  for member
197276da39aSCy Schubert  do
198276da39aSCy Schubert    case $1 in
199276da39aSCy Schubert      @*)
200276da39aSCy Schubert        func_at_file "${1#@}" -REMOVE "$archive"
201276da39aSCy Schubert        ;;
202276da39aSCy Schubert      *)
203276da39aSCy Schubert        func_file_conv "$1"
204276da39aSCy Schubert        $AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
205276da39aSCy Schubert        ;;
206276da39aSCy Schubert    esac
207276da39aSCy Schubert  done
208276da39aSCy Schubert
209276da39aSCy Schubertelif test -n "$extract"; then
210276da39aSCy Schubert  if test ! -f "$orig_archive"; then
211276da39aSCy Schubert    func_error "archive not found"
212276da39aSCy Schubert  fi
213276da39aSCy Schubert  if test $# -gt 0; then
214276da39aSCy Schubert    for member
215276da39aSCy Schubert    do
216276da39aSCy Schubert      case $1 in
217276da39aSCy Schubert        @*)
218276da39aSCy Schubert          func_at_file "${1#@}" -EXTRACT "$archive"
219276da39aSCy Schubert          ;;
220276da39aSCy Schubert        *)
221276da39aSCy Schubert          func_file_conv "$1"
222276da39aSCy Schubert          $AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
223276da39aSCy Schubert          ;;
224276da39aSCy Schubert      esac
225276da39aSCy Schubert    done
226276da39aSCy Schubert  else
227276da39aSCy Schubert    $AR -NOLOGO -LIST "$archive" | sed -e 's/\\/\\\\/g' | while read member
228276da39aSCy Schubert    do
229276da39aSCy Schubert      $AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
230276da39aSCy Schubert    done
231276da39aSCy Schubert  fi
232276da39aSCy Schubert
233276da39aSCy Schubertelif test -n "$quick$replace"; then
234276da39aSCy Schubert  if test ! -f "$orig_archive"; then
235276da39aSCy Schubert    if test -z "$create"; then
236276da39aSCy Schubert      echo "$me: creating $orig_archive"
237276da39aSCy Schubert    fi
238276da39aSCy Schubert    orig_archive=
239276da39aSCy Schubert  else
240276da39aSCy Schubert    orig_archive=$archive
241276da39aSCy Schubert  fi
242276da39aSCy Schubert
243276da39aSCy Schubert  for member
244276da39aSCy Schubert  do
245276da39aSCy Schubert    case $1 in
246276da39aSCy Schubert    @*)
247276da39aSCy Schubert      func_file_conv "${1#@}"
248276da39aSCy Schubert      set x "$@" "@$file"
249276da39aSCy Schubert      ;;
250276da39aSCy Schubert    *)
251276da39aSCy Schubert      func_file_conv "$1"
252276da39aSCy Schubert      set x "$@" "$file"
253276da39aSCy Schubert      ;;
254276da39aSCy Schubert    esac
255276da39aSCy Schubert    shift
256276da39aSCy Schubert    shift
257276da39aSCy Schubert  done
258276da39aSCy Schubert
259276da39aSCy Schubert  if test -n "$orig_archive"; then
260276da39aSCy Schubert    $AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
261276da39aSCy Schubert  else
262276da39aSCy Schubert    $AR -NOLOGO -OUT:"$archive" "$@" || exit $?
263276da39aSCy Schubert  fi
264276da39aSCy Schubert
265276da39aSCy Schubertelif test -n "$list"; then
266276da39aSCy Schubert  if test ! -f "$orig_archive"; then
267276da39aSCy Schubert    func_error "archive not found"
268276da39aSCy Schubert  fi
269276da39aSCy Schubert  $AR -NOLOGO -LIST "$archive" || exit $?
270276da39aSCy Schubertfi
271