improved shell script for building libraries