Refactor config.m4 and start adding support for imagemagick 7