Remove lfs-uefi.txt symlink
[linux_from_scratch_hints.git] / PREVIOUS_FORMAT / gcc_multiple_versions.txt
blobbc532e38b46392298181dc8b5f6216d98fb3f617
2 TITLE:          Multiple GCC Installations
3 LFS VERSION:    All
4 AUTHOR:         Eric Crahen <crahen@cse.buffalo.edu>
6 SYNOPSIS:
8         
9         This is a set of instructions for people interested in installing 
10         and using several versions of gcc on thier system. The compiler's
11         public interfaces are renamed to include version numbers (e.g.
12         gcc-2.95.3), version specific dependancies, such as includes and 
13         shared libraries are storeed in different locations and evironment 
14         variables replace can be used to select a compiler (rather than 
15         global names such as /usr/bin or /lib/cpp)
18 OBTAIN THE SOURCE:
21         First, you need to obtain the version of gcc you wish to compile 
22         and install along with any patches that come with it. The example, 
23         will demonstrate how to install two common versions of the compiler.
24         
25         EGCS-1.1.2:
27         ftp://sourceware.cygnus.com/pub/gcc/old-releases/egcs/
28         http://gcc.gnu.org/install/glibc-2.2.patch
30         GCC-2.95.3:
32         ftp://ftp.gnu.org/pub/gnu/gcc/
35 COMPILE THE SOURCE & INSTALL:
37         
38         Next, the source needs to be configured. This is done in the usual 
39         way, the important configuration options are the following:
40   
42         --enable-version-specific-runtime-libs
44         Keeps the version specific runtime libraries in a compiler specific 
45         directory rather than placing them right in ${libdir}. You can read 
46         more about this in the gcc documentation (install/CONFIGURE).
48         --program-transform-name
50         Transforms the binary file names when they are installed using a 
51         sed regular expression. This option will be used to append the version
52         number as a suffix to the binary names. You can read more about this 
53         by running configure (./configure --help).
56         The following two examples demonstrate a typical use of these options.
58         ECGS-1.1.2:
60         sed -e s/gcc-2.95.2/egcs-1.1.2/ glibc-2.2.patch | patch -p0; \
61         mkdir egcs-build && cd egcs-build && \
62         ../egcs-1.1.2/configure --prefix=/usr  \
63         --enable-languages --enable-languages=c,c++ \
64         --enable-threads=posix \
65         --enable-version-specific-runtime-libs \
66         --program-transform-name="s/\\\\(.*\\\\)/\\\\1-2.91.66/" && \
67         make bootstrap && make install && \
68         ln -s /usr/bin/gcc-2.91.66 cc-2.91.66
69         
70         GCC-2.95.3:
72         bzip2 -dc gcc-2.95.3-2.patch.bz2 | patch -Np1; &&
73         mkdir ../gcc-build && cd ../gcc-build &&
74         ../gcc-2.95.3/configure --prefix=/usr \
75         --enable-languages --enable-languages=c,c++ \
76         --enable-threads=posix \
77         --enable-version-specific-runtime-libs \
78         --program-transform-name="s/\\\\(.*\\\\)/\\\\1-2.95.3/" && \
79         make bootstrap && make install \
80         ln -s /usr/bin/gcc-2.95.3 cc-2.95.3
83 CONFIGURE YOUR ENVIRONMENT:
86         To configure the environment, several variables need to be set. One
87         is the PATH, it should include the path to wherever the binaries
88         have been installed. If the binaries are installed in a location like
89         /usr/bin then that location needs to be in your PATH. The two 
90         variables that are used to select the compiler also need to be set.
91         These are CC and CXX and they should point to cc-version and 
92         c++-version respectively.
94         For example, if you want gcc-2.95.3 to be the default, the following
95         commands can be used.
97         CC=cc-2.95.3 && \
98         CXX=c++-2.95.3 && \
99         export CC CXX
101         These commands can be placed in an rc file that will be executed when 
102         your shell is spawned. For example, /etc/profile or ~/.bashrc.
103         
104         GNU tools, such as autoconf or make can detect your compiler by 
105         looking at these variables. In most cases, there is nothing extra that
106         will need to be done to use these variables to select a compiler. 
107         However, there are exceptions and there are notes at the end of the 
108         document about those exceptions.
111 SELECTING A DIFFERENT COMPILER:
113         
114         Selecting a different compiler simply becomes a matter of chaning 
115         the value of the CC and CXX variables.
117         For instance, to switch from the currently selected compiler to 
118         egcs the following commands can be used 
120         CC=cc-2.91.66 && \
121         CXX=c++-2.91.66 && \
122         export CC CXX
126 NOTES:
130         1.) The '--program-transform-name' option doesn't do anything!?
133         This is can be frustrating because you won't find the error until
134         you have compiled and installed the source and notices the binary
135         names have not changed. The reason is almost certainly because the
136         regular expression has not been escaped properly. Test your expression
137         with sed and quadruple the number of \'s used to escape it.
139         Why? Well, suppose you want to add a suffix to a word. The following 
140         sed expression does this. You need to escape special characters for 
141         sed.
143         echo name | sed -e "s/\(.*\)/\1-suffix/"
144         
145         If you want to get that expression into a Makefile as a string that 
146         the Makefile will eventually execute, you have to escape that 
147         expression.
149         s/\\(.*\\)/\\1-suffix/
151         So, to get the string show above from a shell prompt into any program 
152         you have to escape it again for the shell. So you end up with,
154         s/\\\\(.*\\\\)/\\\\1-suffix/
156         And the configure option becomes,
158         --program-transform-name="s/\\\\(.*\\\\)/\\\\1-suffix/"
161         2.) Things compile, but they are broken!?
164         You may be are mixing compiler versions. Make sure your CC and CXX
165         variables are both using the binaries with the same suffix.
166         
168         DON'T (suffixes are mismatched)
170         CC=cc-2.91.66
171         CXX=cc-2.95.3
173         DO (suffixes are matched)
175         CC=cc-2.95.3 
176         CXX=cc-2.95.3
179         3.) glibc doesn't compile now!?
181         Because glibc assumes your c preprocessor is named cpp and is
182         located in /lib/cpp you may have difficulty compiling glibc.
183         To make glibc choose the correct preprocessor binary the following
184         path can be applied to the source for glibc-2.2.4 so the correct
185         compiler will be chosen for a linux system.
187 cat > glibc-2.2.4-cpp0.patch << "EOF"            
189 2002-20 Eric Crahen <crahen@cse.buffalo.edu>
191 Make sunrpc compile selecting the version specific 
192 c preprocessor reported by whatever gcc CC points at.
194 --- glibc-2.2.4-vanilla/sunrpc/rpc_main.c       Thu Apr 12 17:02:07 2001
195 +++ glibc-2.2.4/sunrpc/rpc_main.c       Sun Jan 20 20:35:51 2002
196 @@ -1323,7 +1323,7 @@
197                     return 0;
198                   {
199                     size_t len = strlen (argv[i]);
200 -                   pathbuf = malloc (len + 5);
201 +                   pathbuf = malloc (len + 6);
202                     if (pathbuf == NULL)
203                       {
204                         perror (cmdname);
205 @@ -1331,7 +1331,7 @@
206                       }
207                     stpcpy (stpcpy (pathbuf,
208                                     argv[i]),
209 -                           "/cpp");
210 +                           "/cpp0");
211                     CPP = pathbuf;
212                     cppDefined = 1;
213                     goto nextarg;
214 --- glibc-2.2.4-vanilla/sunrpc/Makefile Mon Jul 23 13:55:17 2001
215 +++ glibc-2.2.4/sunrpc/Makefile Sun Jan 20 20:31:26 2002
216 @@ -126,8 +126,8 @@
217         $(+link)
219  # Tell rpcgen where to find the C preprocessor.
220 -rpcgen-cmd = $(built-program-cmd) -Y `$(CC) -print-file-name=cpp | \
221 -                                     sed 's|/cpp$$||'`
222 +rpcgen-cmd = $(built-program-cmd) -Y `$(CC) -print-file-name=cpp0 | \
223 +                                     sed 's|/cpp0$$||'`
225  # Install the rpc data base file.
226  $(inst_sysconfdir)/rpc: etc.rpc $(+force)
230         4.) The kernel doesn't compile now!?
233         In the kernel, 'gcc' is hard coded gcc into the Makefile. One way to 
234         overcome this is to use sed.
236         sed -e s/gcc/$CC/ Makefile | make -f - dep && \
237         sed -e s/gcc/$CC/ Makefile | make -f - modules && \
238         sed -e s/gcc/$CC/ Makefile | make -f - modules_install && \
239         sed -e s/gcc/$CC/ Makefile | make -f - bzImage
242         5.) XFree86 doesn't compile now / An X11 program doesn't compile !?
245         Compiling this is tricky when you don't have a common name for your 
246         compiler. XFree86 is setup using imake which keeps a database of 
247         dependancies. Typically, imake assumes certain compilers are installed
248         and looks for them using the common names and locations /lib/cpp and 
249         /usr/bin/gcc. These assumptions can be changed by updating the correct
250         configuration file in the xc/config/cf directory.
252         For a linux system, you can update that file with the following 
253         commands.
255         cp config/cf/linux.cf config/cf/linux.cf.orig && \
256         IMAKECPP=`$CC -print-file-name=cpp0` && export IMAKECPP && \
257         sed -e "s/gcc/$CC/;s/.++/$CXX/;" config/cf/linux.cf.orig > \
258         /tmp/linux.cf && \
259         sed -e s,\\\/lib\\\/cpp,`echo $IMAKECPP | sed 's|/|\\\\/|g'`, \
260         /tmp/linux.cf | sed '/# define CppCmd/a \
261         # ifndef RawCppCmd \
262         #  define RawCppCmd CppCmd -A- \
263         # endif \
264         ' > config/cf/linux.cf && \
265         rm -f /tmp/linux.cf
267         The top part of this command allows both make and imake to 
268         use the compiler names you specify in CC and CXX.
270         The lower portion,
272         sed '/# define CppCmd/a\
273         # ifndef RawCppCmd \
274         #  define RawCppCmd CppCmd -A- \
275         # endif \
276         '
277         Tells the preprocessor to use the correct undef option. 
278         By default, it will attempt to used -undef, which may not 
279         work with your compiler depending on the version and how you've 
280         compiled it. The wrong undef option will cause you to end up with
281         a bunch of blank man pages.
283         Some X11 program use imake, so you might want to place those 
284         first few lines (those that define IMAKECPP) in an rc file.
285         
286         6.) Another program doesn't compile now!?
289         I've shown two of the trickier programs to compile. The vast majority
290         of source not configurable using autoconf will set a variable for the 
291         compiler in a Makefile. To overcome that, all that needs to be done is 
292         to override that variable.
294         You can tell make to look at your environment using 'make -e'.
295         OR
296         You can set some vairables 'using make VAR=val'.
297         
299         7.) My cross compiler isn't renamed!?
302         This is because of how gcc built. You can change the 
303         program_transform_name variable in the Makefile, but you can't change 
304         the program_transform_cross_name variable. To update that you'd need
305         to edit the Makefile template in the gcc subdirectory of your gcc 
306         source tree. Below is a patch for this that will patch the two
307         compilers used as examples throughout the document.
309 cat > gcc-cross-rename.patch << "EOF"            
311 2002-21 Eric Crahen <crahen@cse.buffalo.edu>
312         
313         * Rename the cross compiler binaries to have a version
314           suffix for GCC-2.95.3 and EGCS-1.1.2
316 --- gcc-2.95.3/gcc/Makefile.in.orig     Mon Jan 21 09:19:33 2002
317 +++ gcc-2.95.3/gcc/Makefile.in  Mon Jan 21 09:20:47 2002
318 @@ -2569,7 +2569,7 @@
319           $(INSTALL_PROGRAM) xgcc$(exeext) $(bindir)/$(GCC_INSTALL_NAME)$(exeext); \
320           rm -f $(bindir)/$(target_alias)-gcc-1$(exeext); \
321           $(LN) $(bindir)/$(GCC_INSTALL_NAME)$(exeext) $(bindir)/$(target_alias)-gcc-1$(exeext); \
322 -         mv $(bindir)/$(target_alias)-gcc-1$(exeext) $(bindir)/$(target_alias)-gcc$(exeext); \
323 +         mv $(bindir)/$(target_alias)-gcc-1$(exeext) $(bindir)/$(target_alias)-gcc-2.95.3$(exeext); \
324         fi
326  # Install the info files.
328 --- egcs-1.1.2/gcc/Makefile.in.orig     Mon Jan 21 08:41:22 2002
329 +++ egcs-1.1.2/gcc/Makefile.in  Mon Jan 21 08:57:45 2002
330 @@ -2403,7 +2403,7 @@
331           $(INSTALL_PROGRAM) xgcc$(exeext) $(bindir)/$(GCC_INSTALL_NAME)$(exeext); \
332           rm -f $(bindir)/$(target_alias)-gcc-1$(exeext); \
333           $(LN) $(bindir)/$(GCC_INSTALL_NAME)$(exeext) $(bindir)/$(target_alias)-gcc-1$(exeext); \
334 -         mv $(bindir)/$(target_alias)-gcc-1$(exeext) $(bindir)/$(target_alias)-gcc$(exeext); \
335 +         mv $(bindir)/$(target_alias)-gcc-1$(exeext) $(bindir)/$(target_alias)-gcc-2.91.66$(exeext); \
336         fi
338  # Install the info files.