Default [Q] How to build any android version source code and flash on any device?

Firstly,apologies if this is not the right section.

We all know that android source code is available.So my question is how can I build the source code and install on any device?For example if I have an old device for which updates are not available.Can we just flash it with any android stock rom?Not talking about custom rom.


Can we take the source from github and just build and flash on our device?Because android is hardware independent? Like we can install ubuntu on any system?