Generating standard alone C programs

Another one of my wishes is a command line option to generate a
standalone C program in source form, independent of any object files or
libraries. I know there is a way to achieve
that by including all the needed dynamic sources, but that’s too much
work, not to mention you have to know which files to include. Pure C
sources are more portable, especially if
you need to embed the generated C code in places where linking user land
libraries is prohibited (e.g. OS kernels, device drivers). Combined with
point 3, it can also show those >>doubtful C programmers that there really
is no magic nor dirty tricks. It would be a big win.

Say you use a function named ‘foo’ in your code. The ATS2 compiler needs to
know the interface of ‘foo’ but it does not care whether ‘foo’ is
implemented.
So what is asked above is essentially a tool that can find out where ‘foo’
is implemented (or which implementation of ‘foo’ should be used). I can
think of
omething to implement right away, but it would probably a better idea to
see how this (or something similar) is supported other languages.