quiet compiler warnings building with gcc and clang.

- define variables and functions as static when not declared by headers.
- remove some unused defines.
- other minor changes to quiet warnings.