Is this possible to install pure gcc
with header files on os x lion in a separate folder?
That way I could keep my OS clean and have all of my development tools in one place.
This is probably a very bad idea. It's going to be hard to do, many open source packages that use autoconf will get highly confused, you won't be able to use Homebrew/MacPorts/Fink, etc. And the end result will hardly be "vanilla"; it will be different from every other Mac development system in the world, and much harder to restore from scratch if you ever need to. Also, if you build stock gcc, rather than Apple-patched gcc, you won't have any of the Apple extensions (e.g., the -arch
flag).
You can get around some of these problems by copying at least one of the Xcode SDKs somewhere on your system, and just setting up your environment to always use that SDK. But some of them, there's just no way around. (For example, many configure scripts will be un-confused if you do that, but obviously that won't fix the -arch flag.)
So, I would strongly suggest installing Xcode, or at least installing the standalone Xcode Command Line Tools package (available from developer.apple.com), instead.
But what you want to do is doable.
First, there are some binary builds of gcc around, such as at these. That's probably the easiest way to go. And, once you've got a compiler, if it's not the one you want, you can always use it to compile the one you actually do want.
Alternatively, you can just install Command Line Tools, use that to build the gcc you want, then uninstall Command Line Tools.
Or you can install Command Line Tools on another Mac, use that to build gcc, and copy it over. (You can probably even do the build with Homebrew, and just copy over the /usr/local/Cellar/gcc and set up the symlinks.)
If you really like pain, you can cross-compile gcc from a totally different platform.