Implement flexible target specification

See commit message.
Lost section header comment above this line.