There are no pre-defined defines or such that's specific and standard for which OS you use, so the best is simply to define one yourself. If compiling for FreeBSD, then just do #define FreeBSD or if it's SunOS do #define SunOS.
Then you can check

#ifdef FreeBSD
/* Something here */
#elif defined(SunOS)
/* Something here */
#endif