Fix SunOS build

This fixes SunOS build, as tested on SmartOS.

Short summary of changes:

  * make `strcasecmp` available by defining `_XPG4_2`
  * disable SSP
  * link all the libraries we need
  * migrate APIs which have been changed since the SunOS stuff was last touched
  * vendor some variables which aren't around on all illumos distros