Marlin already does that. The configuration options enable and disable different pieces of code. If some option is not enabled, the code for it will not be compiled into the image.
That is what the #ifdef SOME_OPTION lines do...
That is what the #ifdef SOME_OPTION lines do...