These can be used to detect the OS during compiling on Free Pascal and Lazarus.
One version is this one, looks elegant:
{$if defined(WINDOWS)}
{$elseif defined(UNIX)}
{$if defined(LINUX)}
{$elseif defined(BSD)}
{$if defined(DARWIN)} // MacOSX
{$endif}
{$endif}
{$elseif defined(MAC)} // Classic Macs
{$else}
{$endif}
Another is this one, which is more common:
{$IFDEF WINDOWS}
{$ENDIF}
{$IFDEF UNIX}
{$IFDEF LINUX}
{$ENDIF}
{$IFDEF BSD}
{$IFDEF DARWIN} // MacOSX
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$IFDEF MAC} // Classic Macs
{$ENDIF}
Ref: