Factor out the code for determining output target name into generator.determine-target-name function, so that it can be easily reused.