updatefat 919 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/bin/sh

# creates or updates a fat binary by replacing or adding a new architecture.
# the target file doesn't need to exist - it will be created if not
# already present

if [ -z "$1" -o -z "$2" ]; then
    echo ""
    echo " Usage: updatefat <target> <new-file>"
    echo ""
    echo "  Works even if <target> doesn't exist or is not fat."
    echo ""
    exit 1
fi

thisarch=`lipo -detailed_info "$2"|sed -n 's/.\{0,\}architecture:* \(.\{1,\}\)/\1/p'`
if [ -z "$thisarch" ]; then
    echo "Cannot find out architecture of $2" >&2
    exit 2
fi

#echo "architecture: $thisarch";
if [ -e "$1" ]; then \
24
    if lipo -detailed_info "$1"|grep "architecture:* $thisarch\$" > /dev/null; then
25 26 27 28 29 30 31 32 33 34 35
	if lipo -info "$1"|grep ^Non-fat > /dev/null; then
	    lipo -create "$2" -o "$1"
	else
	    lipo -replace "$thisarch" "$2" "$1" -o "$1"
	fi
    else
	lipo -create "$1" "$2" -o "$1"
    fi
else
    lipo -create "$2" -o "$1"
fi