#!/bin/bash

PROGNAME="${BASH_SOURCE[0]}"
HERE="$(cd "$(dirname "$PROGNAME")" &>/dev/null && pwd)"
READIES=$(cd $HERE/.. && pwd)
. $READIES/shibumi/defs

if ! is_command objdump; then
	xinstall binutils
fi

lib=$(ldconfig -p | awk -F'=>' '$2 ~ /libstdc++/{print $2}')
[[ -z $lib ]] && exit 1
if [[ $N == 1 ]]; then
	objdump -x $lib | grep -P '\sGLIBC(..)?_\d+\.\d+(\.\d+)?$' | cut -d' ' -f4 | grep GLIBCXX | cut -d. -f3 | sort -n | tail -1
elif [[ $ALL == 1 ]]; then
	objdump -x $lib | grep -P '\sGLIBC(..)?_\d+\.\d+(\.\d+)?$' | cut -d' ' -f4 | grep GLIBCXX | cut -d_ -f2
else
	objdump -x $lib | grep -P '\sGLIBC(..)?_\d+\.\d+(\.\d+)?$' | cut -d' ' -f4 | grep GLIBCXX | cut -d_ -f2 | tail -1
fi
