Consistently save and restore LIBS, LDFLAGS and CPPFLAGS in DBD detection.