Implement flexible target specification

See commit message.
@mneumann, is it?