Implement flexible target specification

See commit message.
This is currently commented out unconditionally for windows, perhaps the merge brought it back by accident?