You can do it manually if you choose to do so.
Till a little over 10 years ago, there was no decent DFT tool and we all did stitch the scan chains manually in the netlist.
You can also write a script in perl or any other languages to stitch the scan chain. I haven't done it for insernal scan, but made a script to stitch the boundary scan chain in perl. However, if you want to take care of any other things such as reset/clock bypassing, it would be challenging.