Use #if rather than #ifdef to check HAVE_* macros.
Implement global mutex (for use by scripting languages).