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