This looks great.

Just one tiny request, instead of:

#if !HAVE_FOO
old_code
#else 
use_foo
#endif

Avoid the "!" and do:

#if HAVE_FOO
use_foo
#else
old_code
#endif