This is the first step in installing glibc-2. We first make sure that gcc is updated to the newest version, before we compile system-critical stuff. Here I describe how you compile gcc to produce native code: code that runs with your current libc-5 and on your current system. Compiling gcc as a cross-compiler is done later on.
Preparing for compilation
Even though this is a relative step-by-step guide, it would be wise to read the most important documentation yourself; especially the README and INSTALL files. The newest version as of the writing of this document is gcc-2.8.1; installation of newer versions may differ, and some of the patches may not apply cleanly.
You should apply at least the first patch; it is needed if you want to follow this step-by-step guide.
For old-time users of these pages: there is no longer any need for patches to enable a target alias and to use the glibc-version of assert.h, as both things are now the default. The C++ include dir can now also be set during configuration, and g++ always calls the correct compiler.
- Nicer installation
This patch makes make install run more cleanly. It also disables the installation of versions of binaries that start with the target alias name (we put them in a separate directory instead).
- (Optional) Disable strength reduction
There have been some reports that this flag (enabled by default by -O2) may be harmful. Other reports deny it, but say that strength reduction is not very useful on Intel processors anyway (due to a lack of general registers). With this patch -O2 does not enable strength reduction (-fstrength-reduce still enables it). This patch is probably not needed for gcc-2.8.1, but it will do no actual harm.
You can apply these patches by entering the gcc directory and using the following command:
patch -p1 -E < filename
Compiling and installing gcc
I will assume you use bash as shell; if not, some commands may slightly differ. I will explain each step.
./configure --with-gnu-as --with-gnu-ld --prefix=/usr \
We configure gcc to use the gnu assembler and loader, to live in /usr/... (instead of the default /usr/local/...), and to use the same host and target. Remember to replace those with the ones of your machine, but make sure host and target are the same.
We will first compile gcc with our old compiler, and than use that gcc to compile gcc again - in that way, bugs in the old compiler have a minimal chance of affecting your newly created compiler. To compile the compiler again, we only need the C-compiler - not the C++ and objective-C compilers. This shortens the compilation time.
This moves the compiler into a subdirectory, where it can live while we use it to compile the final compiler.
make CC="stage1/xgcc -Bstage1/" CFLAGS="-s -O2" \
This is a bit tricky. This command compiles the compiler we will install. The CC argument is needed to use the intermediate compiler the previous make installed in the stage1 directory. We want the final compiler to be optimized and stripped, so we specify those options in CFLAGS. And we want to call the target as specified by target_alias above.
make install CC="stage1/xgcc -Bstage1/" CFLAGS="-s -O2" \
Now we can install the compiler. Remember you must be root to do this. If you want to know what will be installed, you can add prefix=/tmp/usr to install the compiler at a temporary location. Do not forget to do a proper installation afterwards!
ln -sfn ../lib/gcc-lib/i486-linux-libc5/2.8.1/cpp /usr/bin/cpp
Many programs expect a version of cpp somewhere in the path. Really old programs (or programs for other Unixes) may even look for cpp in /lib/cpp; you might want to consider to create that link too.
ln -sfn gcc /usr/bin/cc
ln -sfn gcc /usr/i486-linux-libc5/bin/cc
ln -sfn ../../bin/gcc /usr/i486-linux-libc5/bin/gcc
ln -sfn g++ /usr/i486-linux-libc5/bin/c++
ln -sfn ../../bin/g++ /usr/i486-linux-libc5/bin/g++
ln -sfn ../../bin/protoize /usr/i486-linux-libc5/bin/protoize
ln -sfn ../../bin/unprotoize /usr/i486-linux-libc5/bin/unprotoize
None of these links are vital, but I recommend making them still. Many makefiles call your C-compiler as cc. And the links in /usr/i486-linux-libc5/bin will be useful later (believe me!).
Checking the installation
Calling gcc -v should output something like below now:
Reading specs from /usr/lib/gcc-lib/i486-linux-libc5/2.8.1/specs
gcc version 2.8.1
Calling gcc -print-search-dirs should output something like this:
You can find a manifest of all installed files below.
What to do if everything fails
If something went hideously wrong, and you can't compile at all anymore (which is unlikely), you can probably still use the old version of your compiler. Look in /usr/lib/gcc-lib, where a subdirectory for your old target should be, and beneath that a subdirectory for the old compiler version. If these are still present, you can probably still use the compiler if you use the following invocation:
gcc -V 188.8.131.52 -b i486-linux ....
Substitute the version and target names you found in the directory structure.