Implement flexible target specification

See commit message.
This should be enabled for freebsd?