Fix -Wundef warnings

Use `#ifdef` or `defined` instead of `#if`.