The *BSD ports system suggest a way out
If you look at the *BSD port's system, which is furthest developed on FreeBSD, you see such integration with the package management tools.
It works really quite well; and is quite refined over the years. The basic concept of a port is just a 'makefile' which
has enough info to fetch the source, apply patches where needed, and then do that package its config/make. The install is defered a bit and can be combined with a binary package creation. Things like rc.d startup scripts are usually included, as are things like adding a username or group to files in /etc.
One could argue that it is very silly that the BSD community does massive effords in keeping the PORTs updated for virtually every piece of downloadable code (OS, and non OS) and that their work stays limited to just that one OS. For a very limited amounth of extra work you could add a few other unixes.