-
Notifications
You must be signed in to change notification settings - Fork 0
/
ar.sh
executable file
·95 lines (70 loc) · 1.83 KB
/
ar.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh
##
# Wrapper around ar which behaves more like ar.
# Problem is Rhapsody's ar doesn't work on a file that's been ranlib'ed
# and some makefiles want to edit ranlib'ed archives.
#
# The interesting and functional routine here in unranlib().
# The "main" code, which wraps ar, is a hack and may not parse the
# arguments correctly, but seems to work for most uses of ar, where
# the library is argv[2].
##
# Wilfredo Sanchez Jr. | wsanchez@apple.com
# Copyright 1998 Apple Computer, Inc.
##
##
# Set up PATH
##
MyPath=/usr/bin:/bin;
if [ -z "${PATH}" ]; then
export PATH=${MyPath};
else
export PATH=${PATH}:${MyPath};
fi
##
# Functions
##
unranlib ()
{
local archive;
for archive in $*; do
local name="$(basename ${archive})";
local dir="/tmp/unranlib.$$/${name}";
local ofiles="";
local archs="$(file ${archive} | \
grep '(for architecture' | \
awk '{print $4}' | \
sed 's/)://')";
for arch in ${archs}; do
local archdir="${dir}/${arch}";
mkdir -p "${archdir}";
lipo -thin "${arch}" "${archive}" -o "${archdir}/${name}";
( cd "${archdir}" && ar -xo "./${name}"; );
local ofile;
for ofile in `find "${archdir}" -name \*.o`; do
ofiles="${ofiles} $(basename ${ofile})";
done
done
ofiles=$(echo ${ofiles} | tr ' ' '\012' | sort | uniq);
local ofile;
for ofile in ${ofiles}; do
lipo -create $(find "${dir}" -name "${ofile}" -print) -o "${dir}/${ofile}";
done
( cd "${dir}" && ar -cr "${name}" ${ofiles}; );
mv "${dir}/${name}" "${archive}";
rm -rf "${dir}";
done
rm -rf "/tmp/unranlib.$$";
}
##
# Handle command line
##
# This is totally bogus, but enough for now.
archive=$2;
if [ -f "${archive}" ] &&
file "${archive}" | grep 'Mach-O fat file' > /dev/null; then
# File is fat. Undo ranlib.
unranlib "${archive}";
fi
ar $*;
ranlib $2;