]> git.saurik.com Git - apple/coreosmakefiles.git/blame - bin/ar.sh
CoreOSMakefiles-40.tar.gz
[apple/coreosmakefiles.git] / bin / ar.sh
CommitLineData
a44896e3
A
1#!/bin/sh
2# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3#
4# @APPLE_LICENSE_HEADER_START@
5#
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
11# file.
12#
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.
20#
21# @APPLE_LICENSE_HEADER_END@
22##
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.
26#
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].
31##
32# Wilfredo Sanchez Jr. | wsanchez@apple.com
33# Copyright 1998 Apple Computer, Inc.
34##
35
36##
37# Set up PATH
38##
39
40MyPath=/usr/bin:/bin;
41
42if [ -z "${PATH}" ]; then
43 export PATH=${MyPath};
44else
45 export PATH=${PATH}:${MyPath};
46fi
47
48##
49# Functions
50##
51
52unranlib ()
53{
54 local archive;
55
56 for archive in $*; do
57
58 local name="$(basename ${archive})";
59 local dir="/tmp/unranlib.$$/${name}";
60 local ofiles="";
61 local archs="$(file ${archive} | \
62 grep '(for architecture' | \
63 awk '{print $4}' | \
64 sed 's/)://')";
65
66 for arch in ${archs}; do
67 local archdir="${dir}/${arch}";
68 mkdir -p "${archdir}";
69
70 lipo -thin "${arch}" "${archive}" -o "${archdir}/${name}";
71
72 ( cd "${archdir}" && ar -xo "./${name}"; );
73
74 local ofile;
75 for ofile in `find "${archdir}" -name \*.o`; do
76 ofiles="${ofiles} $(basename ${ofile})";
77 done
78
79 done
80
81 ofiles=$(echo ${ofiles} | tr ' ' '\012' | sort | uniq);
82
83 local ofile;
84 for ofile in ${ofiles}; do
85 lipo -create $(find "${dir}" -name "${ofile}" -print) -o "${dir}/${ofile}";
86 done
87
88 ( cd "${dir}" && ar -cr "${name}" ${ofiles}; );
89
90 mv "${dir}/${name}" "${archive}";
91
92 rm -rf "${dir}";
93
94 done
95
96 rm -rf "/tmp/unranlib.$$";
97}
98
99##
100# Handle command line
101##
102
103# This is totally bogus, but enough for now.
104archive=$2;
105
106if [ -f "${archive}" ] &&
107 file "${archive}" | grep -E 'Mach-O (fat file|universal binary)' > /dev/null; then
108
109 # File is fat. Undo ranlib.
110 unranlib "${archive}";
111fi
112
113ar $*;