Looks like this has a lot in common with deb-move - I don't know whether it's possible to factor this out into a Bash function within a Makefile, but that might be more maintainable. Probably not worth the effort if it's difficult.