There is not enough flash, RAM and CPU power in most router to make GNU make and gcc to work. So, in general that is not supported.
If you have some x86 based OpenWrt system, it is possible in theory, if you install several development oriented packages. You can see a list of compiler packages in the source repo https://github.com/openwrt/packages/tree/master/devel
(Those are compiled and downloadable for opkg installation, quite normally, so that is just for pointing out the possible paclage name for you.
I assume that you would need at least make, gcc, possibly patch, automake and autoconf etc.
I doubt that you will succeed in a "normal" router.
...and even on x86/ x86_64, a hello-world style source is about the most complex project that would compile on-target. OpenWrt is not self-hosting and development (library-)packages largely don:t exist.