#!/bin/bash

set -e
cd /tmp

COLUMN1="\\033[1G"

cat > conftest.c <<EOF
int a;
char b;
void c(void) {}
EOF

gcc -c conftest.c
ar cr conftest2.a conftest.o
START=`date +"%s"`

echo "checking whether ranlib is necessary with random result"
for i in {1..1000}; do
	cp -f conftest2.a conftest.a
	#strace -o mylog -v -v -s 80 -f ranlib conftest.a
	ranlib conftest.a
	if cmp -s conftest.a conftest2.a; then
		libc_cv_ranlib_necessary=no
		#mv -f mylog mylog-no
	else
		libc_cv_ranlib_necessary=yes
		#mv -f mylog mylog-yes
	fi
	echo -en "$COLUMN1$i $libc_cv_ranlib_necessary  "
	if test "$libc_cv_ranlib_necessary" = yes; then break; fi
done
TIMETOFAIL=$[`date +"%s"` - ${START}]
echo -e "\nyes after $i attempts and $TIMETOFAIL s"; 