Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / unpack_lib_posix.sh
1 #!/bin/bash -e
2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 # This script is used to unpack a .a file into object files.
8 #
9 # Arguments:
10 #
11 # d - Output directory.
12 # a - List of possible locations of the archive.
13 # f - List of files to extract.
14 #
15
16 export LC_ALL=C
17
18 # Avoid things like -n messing up the grepping below.
19 unset GREP_OPTIONS
20
21 while getopts "d:a:f:r:" flag
22 do
23   if [ "$flag" = "d" ]; then
24     out_dir=$OPTARG
25   elif [ "$flag" = "a" ]; then
26     lib_files="$OPTARG $lib_files"
27   elif [ "$flag" = "f" ]; then
28     obj_files="$OPTARG $obj_files"
29   elif [ "$flag" = "r" ]; then
30     ar=$OPTARG
31   fi
32 done
33
34 for f in $lib_files; do
35   if [ -a $f ]; then
36     lib_file=$f
37     break
38   fi
39 done
40
41 if [ -z "$lib_file" ]; then
42   echo "Failed to locate a static library."
43   false
44   exit
45 fi
46
47 if [ ! -f "$ar" ]; then
48   # Find the appropriate ar to use.
49   ar="ar"
50   if [ -n "$AR_target" ]; then
51     ar=$AR_target
52   elif [ -n "$AR" ]; then
53     ar=$AR
54   fi
55 fi
56
57 obj_list="$($ar t $lib_file | grep '\.o$')"
58
59 function extract_object {
60   for f in $obj_list; do
61     filename="${f##*/}"
62
63     if [ -z "$(echo $filename | grep $1)" ]; then
64       continue
65     fi
66
67     # Only echo this if debugging.
68     # echo "Extract $filename from archive to $out_dir/$1."
69     $ar p $lib_file $filename > $out_dir/$1
70     [ -s $out_dir/$1 ] || exit 1
71     break
72   done
73 }
74
75 for f in $obj_files; do
76   extract_object $f
77 done