#!/bin/sh

QFLAG=q

for archive in $(find ${1} -type f -name '*.darwin_1[012].*.tbz2'); do
    rm -rf /tmp/cxx_archives
    mkdir -p /tmp/cxx_archives

    METADATA=`tar -C /tmp/cxx_archives -xOj${QFLAG}f $archive ./+CONTENTS | fgrep @cxx_stdlib`
    if [ "$METADATA" ]; then
        CXX_STDLIB_OVERIDDEN=`echo "$METADATA" | fgrep @cxx_stdlib_overridden | cut -d " " -f 2`
        if [ "$CXX_STDLIB_OVERIDDEN" != "1" ]; then
            CXX_STDLIB=`echo "$METADATA" | fgrep "@cxx_stdlib " | cut -d " " -f 2`
            if [ "$CXX_STDLIB" = "libstdc++" ]; then
                echo $archive
                echo ${archive}.rmd160
            fi
        fi
        continue
    fi

    tar -C /tmp/cxx_archives -xjf $archive
    if find /tmp/cxx_archives -type f | xargs file | fgrep Mach-O | cut -d : -f 1 | xargs otool -L | grep -Eq 'libstdc\+\+[0-9.]*\.dylib \('; then
        echo $archive
        echo ${archive}.rmd160
    fi
done
rm -rf /tmp/cxx_archives
