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.
7 # This script is used to unpack a .a file into object files.
11 # d - Output directory.
12 # a - List of possible locations of the archive.
13 # f - List of files to extract.
18 # Avoid things like -n messing up the grepping below.
21 while getopts "d:a:f:r:" flag
23 if [ "$flag" = "d" ]; then
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
34 for f in $lib_files; do
41 if [ -z "$lib_file" ]; then
42 echo "Failed to locate a static library."
47 if [ ! -f "$ar" ]; then
48 # Find the appropriate ar to use.
50 if [ -n "$AR_target" ]; then
52 elif [ -n "$AR" ]; then
57 obj_list="$($ar t $lib_file | grep '\.o$')"
59 function extract_object {
60 for f in $obj_list; do
63 if [ -z "$(echo $filename | grep $1)" ]; then
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
75 for f in $obj_files; do