Tweak autotools

Use system provided libs
Use better checks for lib versions
Switch to autoreconf
Update compile flags