]>
git.saurik.com Git - apple/coreosmakefiles.git/blob - bin/ar.sh
9bad047d1722a88e4f9ddfc4a986b88711df5a5d
2 # Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 # @APPLE_LICENSE_HEADER_START@
6 # This file contains Original Code and/or Modifications of Original Code
7 # as defined in and that are subject to the Apple Public Source License
8 # Version 2.0 (the 'License'). You may not use this file except in
9 # compliance with the License. Please obtain a copy of the License at
10 # http://www.opensource.apple.com/apsl/ and read it before using this
13 # The Original Code and all software distributed under the License are
14 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 # Please see the License for the specific language governing rights and
19 # limitations under the License.
21 # @APPLE_LICENSE_HEADER_END@
23 # Wrapper around ar which behaves more like ar.
24 # Problem is Rhapsody's ar doesn't work on a file that's been ranlib'ed
25 # and some makefiles want to edit ranlib'ed archives.
27 # The interesting and functional routine here in unranlib().
28 # The "main" code, which wraps ar, is a hack and may not parse the
29 # arguments correctly, but seems to work for most uses of ar, where
30 # the library is argv[2].
32 # Wilfredo Sanchez Jr. | wsanchez@apple.com
33 # Copyright 1998 Apple Computer, Inc.
42 if [ -z "${PATH}" ]; then
43 export PATH
=${MyPath};
45 export PATH
=${PATH}:${MyPath};
58 local name
="$(basename ${archive})";
59 local dir
="/tmp/unranlib.$$/${name}";
61 local archs
="$(file ${archive} | \
62 grep '(for architecture' | \
66 for arch
in ${archs}; do
67 local archdir
="${dir}/${arch}";
68 mkdir -p "${archdir}";
70 lipo
-thin "${arch}" "${archive}" -o "${archdir}/${name}";
72 ( cd "${archdir}" && ar -xo "./${name}"; );
75 for ofile
in `find "${archdir}" -name \*.o`; do
76 ofiles
="${ofiles} $(basename ${ofile})";
81 ofiles
=$(echo ${ofiles} | tr ' ' '\012' | sort | uniq);
84 for ofile
in ${ofiles}; do
85 lipo
-create $(find "${dir}" -name "${ofile}" -print) -o "${dir}/${ofile}";
88 ( cd "${dir}" && ar -cr "${name}" ${ofiles}; );
90 mv "${dir}/${name}" "${archive}";
96 rm -rf "/tmp/unranlib.$$";
100 # Handle command line
103 # This is totally bogus, but enough for now.
106 if [ -f "${archive}" ] &&
107 file "${archive}" | grep -E 'Mach-O (fat file|universal binary)' > /dev
/null
; then
109 # File is fat. Undo ranlib.
110 unranlib
"${archive}";