Updated to deal with dependencies better and specifiy libdir explicitly