@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
@c This is part of the GCC manual.
@c For copying conditions, see the file gcc.texi.

@node Installation
@chapter Installing GNU CC
@cindex installing GNU CC

Note most of this information is out of date and superseded by the
new GCC install manual @file{gcc/doc/install.texi}.  It is
provided for historical reference only.

@menu
* Configuration Files::  Files created by running @code{configure}.
* Configurations::    Configurations Supported by GNU CC.
* Cross-Compiler::   Building and installing a cross-compiler.
* VMS Install::   See below for installation on VMS.
* Collect2::	  How @code{collect2} works; how it finds @code{ld}.
* Header Dirs::   Understanding the standard header file directories.
@end menu

Here is the procedure for installing GNU CC on a GNU or Unix system.
See @ref{VMS Install}, for VMS systems.

@enumerate
@item
If you have chosen a configuration for GNU CC which requires other GNU
tools (such as GAS or the GNU linker) instead of the standard system
tools, install the required tools in the build directory under the names
@file{as}, @file{ld} or whatever is appropriate.  This will enable the
compiler to find the proper tools for compilation of the program
@file{enquire}.

Alternatively, you can do subsequent compilation using a value of the
@code{PATH} environment variable such that the necessary GNU tools come
before the standard system tools.

@item
Specify the host, build and target machine configurations.  You do this
when you run the @file{configure} script.

The @dfn{build} machine is the system which you are using, the
@dfn{host} machine is the system where you want to run the resulting
compiler (normally the build machine), and the @dfn{target} machine is
the system for which you want the compiler to generate code.

If you are building a compiler to produce code for the machine it runs
on (a native compiler), you normally do not need to specify any operands
to @file{configure}; it will try to guess the type of machine you are on
and use that as the build, host and target machines.  So you don't need
to specify a configuration when building a native compiler unless
@file{configure} cannot figure out what your configuration is or guesses
wrong.

In those cases, specify the build machine's @dfn{configuration name}
with the @option{--host} option; the host and target will default to be
the same as the host machine.  (If you are building a cross-compiler,
see @ref{Cross-Compiler}.)

Here is an example:

@smallexample
./configure --host=sparc-sun-sunos4.1
@end smallexample

A configuration name may be canonical or it may be more or less
abbreviated.

A canonical configuration name has three parts, separated by dashes.
It looks like this: @samp{@var{cpu}-@var{company}-@var{system}}.
(The three parts may themselves contain dashes; @file{configure}
can figure out which dashes serve which purpose.)  For example,
@samp{m68k-sun-sunos4.1} specifies a Sun 3.

You can also replace parts of the configuration by nicknames or aliases.
For example, @samp{sun3} stands for @samp{m68k-sun}, so
@samp{sun3-sunos4.1} is another way to specify a Sun 3.

You can specify a version number after any of the system types, and some
of the CPU types.  In most cases, the version is irrelevant, and will be
ignored.  So you might as well specify the version if you know it.

See @ref{Configurations}, for a list of supported configuration names and
notes on many of the configurations.  You should check the notes in that
section before proceeding any further with the installation of GNU CC.

@item
When running @code{configure}, you may also need to specify certain
additional options that describe variant hardware and software
configurations.  These are @option{--with-gnu-as}, @option{--with-gnu-ld},
@option{--with-stabs} and @option{--nfp}.

@table @samp
@item --with-gnu-as
If you will use GNU CC with the GNU assembler (GAS), you should declare
this by using the @option{--with-gnu-as} option when you run
@file{configure}.

Using this option does not install GAS.  It only modifies the output of
GNU CC to work with GAS.  Building and installing GAS is up to you.

Conversely, if you @emph{do not} wish to use GAS and do not specify
@option{--with-gnu-as} when building GNU CC, it is up to you to make sure
that GAS is not installed.  GNU CC searches for a program named
@code{as} in various directories; if the program it finds is GAS, then
it runs GAS.  If you are not sure where GNU CC finds the assembler it is
using, try specifying @option{-v} when you run it.

The systems where it makes a difference whether you use GAS are@*
@samp{hppa1.0-@var{any}-@var{any}}, @samp{hppa1.1-@var{any}-@var{any}},
@samp{i386-@var{any}-sysv}, @samp{i386-@var{any}-isc},@*
@samp{i860-@var{any}-bsd}, @samp{m68k-bull-sysv},@*
@samp{m68k-hp-hpux}, @samp{m68k-sony-bsd},@*
@samp{m68k-altos-sysv}, @samp{m68000-hp-hpux},@*
@samp{m68000-att-sysv}, @samp{@var{any}-lynx-lynxos},
and @samp{mips-@var{any}}).
On any other system, @option{--with-gnu-as} has no effect.

On the systems listed above (except for the HP-PA, for ISC on the
386, and for @samp{mips-sgi-irix5.*}), if you use GAS, you should also
use the GNU linker (and specify @option{--with-gnu-ld}).

@item --with-gnu-ld
Specify the option @option{--with-gnu-ld} if you plan to use the GNU
linker with GNU CC.

This option does not cause the GNU linker to be installed; it just
modifies the behavior of GNU CC to work with the GNU linker.
@c Specifically, it inhibits the installation of @code{collect2}, a program
@c which otherwise serves as a front-end for the system's linker on most
@c configurations.

@item --with-stabs
On MIPS based systems and on Alphas, you must specify whether you want
GNU CC to create the normal ECOFF debugging format, or to use BSD-style
stabs passed through the ECOFF symbol table.  The normal ECOFF debug
format cannot fully handle languages other than C.  BSD stabs format can
handle other languages, but it only works with the GNU debugger GDB.

Normally, GNU CC uses the ECOFF debugging format by default; if you
prefer BSD stabs, specify @option{--with-stabs} when you configure GNU
CC.

No matter which default you choose when you configure GNU CC, the user
can use the @option{-gcoff} and @option{-gstabs+} options to specify explicitly
the debug format for a particular compilation.

@option{--with-stabs} is meaningful on the ISC system on the 386, also, if
@option{--with-gas} is used.  It selects use of stabs debugging
information embedded in COFF output.  This kind of debugging information
supports C++ well; ordinary COFF debugging information does not.

@option{--with-stabs} is also meaningful on 386 systems running SVR4.  It
selects use of stabs debugging information embedded in ELF output.  The
C++ compiler currently (2.6.0) does not support the DWARF debugging
information normally used on 386 SVR4 platforms; stabs provide a
workable alternative.  This requires gas and gdb, as the normal SVR4
tools can not generate or interpret stabs.

@end table

@end enumerate

@node Configuration Files
@section Files Created by @code{configure}

Here we spell out what files will be set up by @code{configure}.  Normally
you need not be concerned with these files.

@itemize @bullet
@item
@ifset INTERNALS
A file named @file{config.h} is created that contains a @samp{#include}
of the top-level config file for the machine you will run the compiler
on (@pxref{Config}).  This file is responsible for defining information
about the host machine.  It includes @file{tm.h}.
@end ifset
@ifclear INTERNALS
A file named @file{config.h} is created that contains a @samp{#include}
of the top-level config file for the machine you will run the compiler
on (@pxref{Config,,The Configuration File, gcc.info, Using and Porting
GCC}).  This file is responsible for defining information about the host
machine.  It includes @file{tm.h}.
@end ifclear

The top-level config file is located in the subdirectory @file{config}.
Its name is always @file{xm-@var{something}.h}; usually
@file{xm-@var{machine}.h}, but there are some exceptions.

If your system does not support symbolic links, you might want to
set up @file{config.h} to contain a @samp{#include} command which
refers to the appropriate file.

@item
A file named @file{tconfig.h} is created which includes the top-level config
file for your target machine.  This is used for compiling certain
programs to run on that machine.

@item
A file named @file{tm.h} is created which includes the
machine-description macro file for your target machine.  It should be in
the subdirectory @file{config} and its name is often
@file{@var{machine}.h}.

@item
The command file @file{configure} also constructs the file
@file{Makefile} by adding some text to the template file
@file{Makefile.in}.  The additional text comes from files in the
@file{config} directory, named @file{t-@var{target}} and
@file{x-@var{host}}.  If these files do not exist, it means nothing
needs to be added for a given target or host.
@end itemize

@node Configurations
@section Configurations Supported by GNU CC
@cindex configurations supported by GNU CC

Here are the possible CPU types:

@quotation
@c gmicro, fx80, spur and tahoe omitted since they don't work.
1750a, a29k, alpha, arm, avr, c@var{n}, clipper, dsp16xx, elxsi, fr30, h8300,
hppa1.0, hppa1.1, i370, i386, i486, i586, i686, i786, i860, i960, m32r,
m68000, m68k, m6811, m6812, m88k, mcore, mips, mipsel, mips64, mips64el,
mn10200, mn10300, ns32k, pdp11, powerpc, powerpcle, romp, rs6000, sh, sparc,
sparclite, sparc64, v850, vax, we32k.
@end quotation

Here are the recognized company names.  As you can see, customary
abbreviations are used rather than the longer official names.

@c What should be done about merlin, tek*, dolphin?
@quotation
acorn, alliant, altos, apollo, apple, att, bull,
cbm, convergent, convex, crds, dec, dg, dolphin,
elxsi, encore, harris, hitachi, hp, ibm, intergraph, isi,
mips, motorola, ncr, next, ns, omron, plexus,
sequent, sgi, sony, sun, tti, unicom, wrs.
@end quotation

The company name is meaningful only to disambiguate when the rest of
the information supplied is insufficient.  You can omit it, writing
just @samp{@var{cpu}-@var{system}}, if it is not needed.  For example,
@samp{vax-ultrix4.2} is equivalent to @samp{vax-dec-ultrix4.2}.

Here is a list of system types:

@quotation
386bsd, aix, acis, amigaos, aos, aout, aux, bosx, bsd, clix, coff, ctix, cxux,
dgux, dynix, ebmon, ecoff, elf, esix, freebsd, hms, genix, gnu, linux,
linux-gnu, hiux, hpux, iris, irix, isc, luna, lynxos, mach, minix, msdos, mvs,
netbsd, newsos, nindy, ns, osf, osfrose, ptx, riscix, riscos, rtu, sco, sim,
solaris, sunos, sym, sysv, udi, ultrix, unicos, uniplus, unos, vms, vsta,
vxworks, winnt, xenix.
@end quotation

@noindent
You can omit the system type; then @file{configure} guesses the
operating system from the CPU and company.

You can add a version number to the system type; this may or may not
make a difference.  For example, you can write @samp{bsd4.3} or
@samp{bsd4.4} to distinguish versions of BSD.  In practice, the version
number is most needed for @samp{sysv3} and @samp{sysv4}, which are often
treated differently.

@samp{linux-gnu} is the canonical name for the GNU/Linux target; however
GNU CC will also accept @samp{linux}.  The version of the kernel in use is
not relevant on these systems.  A suffix such as @samp{libc1} or @samp{aout}
distinguishes major versions of the C library; all of the suffixed versions
are obsolete.

If you specify an impossible combination such as @samp{i860-dg-vms},
then you may get an error message from @file{configure}, or it may
ignore part of the information and do the best it can with the rest.
@file{configure} always prints the canonical name for the alternative
that it used.  GNU CC does not support all possible alternatives.

Often a particular model of machine has a name.  Many machine names are
recognized as aliases for CPU/company combinations.  Thus, the machine
name @samp{sun3}, mentioned above, is an alias for @samp{m68k-sun}.
Sometimes we accept a company name as a machine name, when the name is
popularly used for a particular machine.  Here is a table of the known
machine names:

@quotation
3300, 3b1, 3b@var{n}, 7300, altos3068, altos,
apollo68, att-7300, balance,
convex-c@var{n}, crds, decstation-3100,
decstation, delta, encore,
fx2800, gmicro, hp7@var{nn}, hp8@var{nn},
hp9k2@var{nn}, hp9k3@var{nn}, hp9k7@var{nn},
hp9k8@var{nn}, iris4d, iris, isi68,
m3230, magnum, merlin, miniframe,
mmax, news-3600, news800, news, next,
pbd, pc532, pmax, powerpc, powerpcle, ps2, risc-news,
rtpc, sun2, sun386i, sun386, sun3,
sun4, symmetry, tower-32, tower.
@end quotation

@noindent
Remember that a machine name specifies both the cpu type and the company
name.
If you want to install your own homemade configuration files, you can
use @samp{local} as the company name to access them.  If you use
configuration @samp{@var{cpu}-local}, the configuration name
without the cpu prefix
is used to form the configuration file names.

Thus, if you specify @samp{m68k-local}, configuration uses
files @file{m68k.md}, @file{local.h}, @file{m68k.c},
@file{xm-local.h}, @file{t-local}, and @file{x-local}, all in the
directory @file{config/m68k}.

Here is a list of configurations that have special treatment or special
things you must know:

@table @samp
@item vax-dec-vms
See @ref{VMS Install}, for details on how to install GNU CC on VMS.
@end table

@node Cross-Compiler
@section Building and Installing a Cross-Compiler
@cindex cross-compiler, installation

GNU CC can function as a cross-compiler for many machines, but not all.

@itemize @bullet
@item
Cross-compilers for the Mips as target using the Mips assembler
currently do not work, because the auxiliary programs
@file{mips-tdump.c} and @file{mips-tfile.c} can't be compiled on
anything but a Mips.  It does work to cross compile for a Mips
if you use the GNU assembler and linker.

@item
Cross-compilers between machines with different floating point formats
have not all been made to work.  GNU CC now has a floating point
emulator with which these can work, but each target machine description
needs to be updated to take advantage of it.

@item
Cross-compilation between machines of different word sizes is
somewhat problematic and sometimes does not work.
@end itemize

Since GNU CC generates assembler code, you probably need a
cross-assembler that GNU CC can run, in order to produce object files.
If you want to link on other than the target machine, you need a
cross-linker as well.  You also need header files and libraries suitable
for the target machine that you can install on the host machine.

@menu
* Steps of Cross::      Using a cross-compiler involves several steps
                          that may be carried out on different machines.
* Configure Cross::     Configuring a cross-compiler.
* Tools and Libraries:: Where to put the linker and assembler, and the C library.
* Cross Headers::       Finding and installing header files
                          for a cross-compiler.
* Build Cross::         Actually compiling the cross-compiler.
@end menu

@node Steps of Cross
@subsection Steps of Cross-Compilation

To compile and run a program using a cross-compiler involves several
steps:

@itemize @bullet
@item
Run the cross-compiler on the host machine to produce assembler files
for the target machine.  This requires header files for the target
machine.

@item
Assemble the files produced by the cross-compiler.  You can do this
either with an assembler on the target machine, or with a
cross-assembler on the host machine.

@item
Link those files to make an executable.  You can do this either with a
linker on the target machine, or with a cross-linker on the host
machine.  Whichever machine you use, you need libraries and certain
startup files (typically @file{crt@dots{}.o}) for the target machine.
@end itemize

It is most convenient to do all of these steps on the same host machine,
since then you can do it all with a single invocation of GNU CC.  This
requires a suitable cross-assembler and cross-linker.  For some targets,
the GNU assembler and linker are available.

@node Configure Cross
@subsection Configuring a Cross-Compiler

To build GNU CC as a cross-compiler, you start out by running
@file{configure}.  Use the @option{--target=@var{target}} to specify the
target type.  If @file{configure} was unable to correctly identify the
system you are running on, also specify the @option{--build=@var{build}}
option.  For example, here is how to configure for a cross-compiler that
produces code for an HP 68030 system running BSD on a system that
@file{configure} can correctly identify:

@smallexample
./configure --target=m68k-hp-bsd4.3
@end smallexample

@node Tools and Libraries
@subsection Tools and Libraries for a Cross-Compiler

If you have a cross-assembler and cross-linker available, you should
install them now.  Put them in the directory
@file{/usr/local/@var{target}/bin}.  Here is a table of the tools
you should put in this directory:

@table @file
@item as
This should be the cross-assembler.

@item ld
This should be the cross-linker.

@item ar
This should be the cross-archiver: a program which can manipulate
archive files (linker libraries) in the target machine's format.

@item ranlib
This should be a program to construct a symbol table in an archive file.
@end table

The installation of GNU CC will find these programs in that directory,
and copy or link them to the proper place to for the cross-compiler to
find them when run later.

The easiest way to provide these files is to build the Binutils package
and GAS.  Configure them with the same @option{--host} and @option{--target}
options that you use for configuring GNU CC, then build and install
them.  They install their executables automatically into the proper
directory.  Alas, they do not support all the targets that GNU CC
supports.

If you want to install libraries to use with the cross-compiler, such as
a standard C library, put them in the directory
@file{/usr/local/@var{target}/lib}; installation of GNU CC copies
all the files in that subdirectory into the proper place for GNU CC to
find them and link with them.  Here's an example of copying some
libraries from a target machine:

@example
ftp @var{target-machine}
lcd /usr/local/@var{target}/lib
cd /lib
get libc.a
cd /usr/lib
get libg.a
get libm.a
quit
@end example

@noindent
The precise set of libraries you'll need, and their locations on
the target machine, vary depending on its operating system.

@cindex start files
Many targets require ``start files'' such as @file{crt0.o} and
@file{crtn.o} which are linked into each executable; these too should be
placed in @file{/usr/local/@var{target}/lib}.  There may be several
alternatives for @file{crt0.o}, for use with profiling or other
compilation options.  Check your target's definition of
@code{STARTFILE_SPEC} to find out what start files it uses.
Here's an example of copying these files from a target machine:

@example
ftp @var{target-machine}
lcd /usr/local/@var{target}/lib
prompt
cd /lib
mget *crt*.o
cd /usr/lib
mget *crt*.o
quit
@end example

@node Cross Headers
@subsection Cross-Compilers and Header Files

If you are cross-compiling a standalone program or a program for an
embedded system, then you may not need any header files except the few
that are part of GNU CC (and those of your program).  However, if you
intend to link your program with a standard C library such as
@file{libc.a}, then you probably need to compile with the header files
that go with the library you use.

The GNU C compiler does not come with these files, because (1) they are
system-specific, and (2) they belong in a C library, not in a compiler.

If the GNU C library supports your target machine, then you can get the
header files from there (assuming you actually use the GNU library when
you link your program).

If your target machine comes with a C compiler, it probably comes with
suitable header files also.  If you make these files accessible from the host
machine, the cross-compiler can use them also.

Otherwise, you're on your own in finding header files to use when
cross-compiling.

When you have found suitable header files, put them in the directory
@file{/usr/local/@var{target}/include}, before building the cross
compiler.  Then installation will run fixincludes properly and install
the corrected versions of the header files where the compiler will use
them.

Provide the header files before you build the cross-compiler, because
the build stage actually runs the cross-compiler to produce parts of
@file{libgcc.a}.  (These are the parts that @emph{can} be compiled with
GNU CC.)  Some of them need suitable header files.

Here's an example showing how to copy the header files from a target
machine.  On the target machine, do this:

@example
(cd /usr/include; tar cf - .) > tarfile
@end example

Then, on the host machine, do this:

@example
ftp @var{target-machine}
lcd /usr/local/@var{target}/include
get tarfile
quit
tar xf tarfile
@end example

@node Build Cross
@subsection Actually Building the Cross-Compiler

Now you can proceed just as for compiling a single-machine compiler
through the step of building stage 1.

If your target is exotic, you may need to provide the header file
@file{float.h}.One way to do this is to compile @file{enquire} and run
it on your target machine.  The job of @file{enquire} is to run on the
target machine and figure out by experiment the nature of its floating
point representation.  @file{enquire} records its findings in the header
file @file{float.h}.  If you can't produce this file by running
@file{enquire} on the target machine, then you will need to come up with
a suitable @file{float.h} in some other way (or else, avoid using it in
your programs).

Do not try to build stage 2 for a cross-compiler.  It doesn't work to
rebuild GNU CC as a cross-compiler using the cross-compiler, because
that would produce a program that runs on the target machine, not on the
host.  For example, if you compile a 386-to-68030 cross-compiler with
itself, the result will not be right either for the 386 (because it was
compiled into 68030 code) or for the 68030 (because it was configured
for a 386 as the host).  If you want to compile GNU CC into 68030 code,
whether you compile it on a 68030 or with a cross-compiler on a 386, you
must specify a 68030 as the host when you configure it.

To install the cross-compiler, use @samp{make install}, as usual.

@node VMS Install
@section Installing GNU CC on VMS
@cindex VMS installation
@cindex installing GNU CC on VMS

The VMS version of GNU CC is distributed in a backup saveset containing
both source code and precompiled binaries.

To install the @file{gcc} command so you can use the compiler easily, in
the same manner as you use the VMS C compiler, you must install the VMS CLD
file for GNU CC as follows:

@enumerate
@item
Define the VMS logical names @samp{GNU_CC} and @samp{GNU_CC_INCLUDE}
to point to the directories where the GNU CC executables
(@file{gcc-cpp.exe}, @file{gcc-cc1.exe}, etc.) and the C include files are
kept respectively.  This should be done with the commands:@refill

@smallexample
$ assign /system /translation=concealed -
  disk:[gcc.] gnu_cc
$ assign /system /translation=concealed -
  disk:[gcc.include.] gnu_cc_include
@end smallexample

@noindent
with the appropriate disk and directory names.  These commands can be
placed in your system startup file so they will be executed whenever
the machine is rebooted.  You may, if you choose, do this via the
@file{GCC_INSTALL.COM} script in the @file{[GCC]} directory.

@item
Install the @file{GCC} command with the command line:

@smallexample
$ set command /table=sys$common:[syslib]dcltables -
  /output=sys$common:[syslib]dcltables gnu_cc:[000000]gcc
$ install replace sys$common:[syslib]dcltables
@end smallexample

@item
To install the help file, do the following:

@smallexample
$ library/help sys$library:helplib.hlb gcc.hlp
@end smallexample

@noindent
Now you can invoke the compiler with a command like @samp{gcc /verbose
file.c}, which is equivalent to the command @samp{gcc -v -c file.c} in
Unix.
@end enumerate

If you wish to use GNU C++ you must first install GNU CC, and then
perform the following steps:

@enumerate
@item
Define the VMS logical name @samp{GNU_GXX_INCLUDE} to point to the
directory where the preprocessor will search for the C++ header files.
This can be done with the command:@refill

@smallexample
$ assign /system /translation=concealed -
  disk:[gcc.gxx_include.] gnu_gxx_include
@end smallexample

@noindent
with the appropriate disk and directory name.  If you are going to be
using a C++ runtime library, this is where its install procedure will install
its header files.

@item
Obtain the file @file{gcc-cc1plus.exe}, and place this in the same
directory that @file{gcc-cc1.exe} is kept.

The GNU C++ compiler can be invoked with a command like @samp{gcc /plus
/verbose file.cc}, which is equivalent to the command @samp{g++ -v -c
file.cc} in Unix.
@end enumerate

We try to put corresponding binaries and sources on the VMS distribution
tape.  But sometimes the binaries will be from an older version than the
sources, because we don't always have time to update them.  (Use the
@samp{/version} option to determine the version number of the binaries and
compare it with the source file @file{version.c} to tell whether this is
so.)  In this case, you should use the binaries you get to recompile the
sources.  If you must recompile, here is how:

@enumerate
@item
Execute the command procedure @file{vmsconfig.com} to set up the files
@file{tm.h}, @file{config.h}, @file{aux-output.c}, and @file{md.}, and
to create files @file{tconfig.h} and @file{hconfig.h}.  This procedure
also creates several linker option files used by @file{make-cc1.com} and
a data file used by @file{make-l2.com}.@refill

@smallexample
$ @@vmsconfig.com
@end smallexample

@item
Setup the logical names and command tables as defined above.  In
addition, define the VMS logical name @samp{GNU_BISON} to point at the
to the directories where the Bison executable is kept.  This should be
done with the command:@refill

@smallexample
$ assign /system /translation=concealed -
  disk:[bison.] gnu_bison
@end smallexample

You may, if you choose, use the @file{INSTALL_BISON.COM} script in the
@file{[BISON]} directory.

@item
Install the @samp{BISON} command with the command line:@refill

@smallexample
$ set command /table=sys$common:[syslib]dcltables -
  /output=sys$common:[syslib]dcltables -
  gnu_bison:[000000]bison
$ install replace sys$common:[syslib]dcltables
@end smallexample

@item
Type @samp{@@make-gcc} to recompile everything (alternatively, submit
the file @file{make-gcc.com} to a batch queue).  If you wish to build
the GNU C++ compiler as well as the GNU CC compiler, you must first edit
@file{make-gcc.com} and follow the instructions that appear in the
comments.@refill

@item
In order to use GCC, you need a library of functions which GCC compiled code
will call to perform certain tasks, and these functions are defined in the
file @file{libgcc2.c}.  To compile this you should use the command procedure
@file{make-l2.com}, which will generate the library @file{libgcc2.olb}.
@file{libgcc2.olb} should be built using the compiler built from
the same distribution that @file{libgcc2.c} came from, and
@file{make-gcc.com} will automatically do all of this for you.

To install the library, use the following commands:@refill

@smallexample
$ library gnu_cc:[000000]gcclib/delete=(new,eprintf)
$ library gnu_cc:[000000]gcclib/delete=L_*
$ library libgcc2/extract=*/output=libgcc2.obj
$ library gnu_cc:[000000]gcclib libgcc2.obj
@end smallexample

The first command simply removes old modules that will be replaced with
modules from @file{libgcc2} under different module names.  The modules
@code{new} and @code{eprintf} may not actually be present in your
@file{gcclib.olb}---if the VMS librarian complains about those modules
not being present, simply ignore the message and continue on with the
next command.  The second command removes the modules that came from the
previous version of the library @file{libgcc2.c}.

Whenever you update the compiler on your system, you should also update the
library with the above procedure.

@item
You may wish to build GCC in such a way that no files are written to the
directory where the source files reside.  An example would be the when
the source files are on a read-only disk.  In these cases, execute the
following DCL commands (substituting your actual path names):

@smallexample
$ assign dua0:[gcc.build_dir.]/translation=concealed, -
         dua1:[gcc.source_dir.]/translation=concealed  gcc_build
$ set default gcc_build:[000000]
@end smallexample

@noindent
where the directory @file{dua1:[gcc.source_dir]} contains the source
code, and the directory @file{dua0:[gcc.build_dir]} is meant to contain
all of the generated object files and executables.  Once you have done
this, you can proceed building GCC as described above.  (Keep in mind
that @file{gcc_build} is a rooted logical name, and thus the device
names in each element of the search list must be an actual physical
device name rather than another rooted logical name).

@item
@strong{If you are building GNU CC with a previous version of GNU CC,
you also should check to see that you have the newest version of the
assembler}.  In particular, GNU CC version 2 treats global constant
variables slightly differently from GNU CC version 1, and GAS version
1.38.1 does not have the patches required to work with GCC version 2.
If you use GAS 1.38.1, then @code{extern const} variables will not have
the read-only bit set, and the linker will generate warning messages
about mismatched psect attributes for these variables.  These warning
messages are merely a nuisance, and can safely be ignored.

If you are compiling with a version of GNU CC older than 1.33, specify
@samp{/DEFINE=("inline=")} as an option in all the compilations.  This
requires editing all the @code{gcc} commands in @file{make-cc1.com}.
(The older versions had problems supporting @code{inline}.)  Once you
have a working 1.33 or newer GNU CC, you can change this file back.

@item
If you want to build GNU CC with the VAX C compiler, you will need to
make minor changes in @file{make-cccp.com} and @file{make-cc1.com}
to choose alternate definitions of @code{CC}, @code{CFLAGS}, and
@code{LIBS}.  See comments in those files.  However, you must
also have a working version of the GNU assembler (GNU as, aka GAS) as
it is used as the back-end for GNU CC to produce binary object modules
and is not included in the GNU CC sources.  GAS is also needed to
compile @file{libgcc2} in order to build @file{gcclib} (see above);
@file{make-l2.com} expects to be able to find it operational in
@file{gnu_cc:[000000]gnu-as.exe}.

To use GNU CC on VMS, you need the VMS driver programs
@file{gcc.exe}, @file{gcc.com}, and @file{gcc.cld}.  They are
distributed with the VMS binaries (@file{gcc-vms}) rather than the
GNU CC sources.  GAS is also included in @file{gcc-vms}, as is Bison.

Once you have successfully built GNU CC with VAX C, you should use the
resulting compiler to rebuild itself.  Before doing this, be sure to
restore the @code{CC}, @code{CFLAGS}, and @code{LIBS} definitions in
@file{make-cccp.com} and @file{make-cc1.com}.  The second generation
compiler will be able to take advantage of many optimizations that must
be suppressed when building with other compilers.
@end enumerate

Under previous versions of GNU CC, the generated code would occasionally
give strange results when linked with the sharable @file{VAXCRTL} library.
Now this should work.

Even with this version, however, GNU CC itself should not be linked with
the sharable @file{VAXCRTL}.  The version of @code{qsort} in
@file{VAXCRTL} has a bug (known to be present in VMS versions V4.6
through V5.5) which causes the compiler to fail.

The executables are generated by @file{make-cc1.com} and
@file{make-cccp.com} use the object library version of @file{VAXCRTL} in
order to make use of the @code{qsort} routine in @file{gcclib.olb}.  If
you wish to link the compiler executables with the shareable image
version of @file{VAXCRTL}, you should edit the file @file{tm.h} (created
by @file{vmsconfig.com}) to define the macro @code{QSORT_WORKAROUND}.

@code{QSORT_WORKAROUND} is always defined when GNU CC is compiled with
VAX C, to avoid a problem in case @file{gcclib.olb} is not yet
available.

@node Collect2
@section @code{collect2}

GNU CC uses a utility called @code{collect2} on nearly all systems to arrange
to call various initialization functions at start time.

The program @code{collect2} works by linking the program once and
looking through the linker output file for symbols with particular names
indicating they are constructor functions.  If it finds any, it
creates a new temporary @samp{.c} file containing a table of them,
compiles it, and links the program a second time including that file.

@findex __main
@cindex constructors, automatic calls
The actual calls to the constructors are carried out by a subroutine
called @code{__main}, which is called (automatically) at the beginning
of the body of @code{main} (provided @code{main} was compiled with GNU
CC).  Calling @code{__main} is necessary, even when compiling C code, to
allow linking C and C++ object code together.  (If you use
@option{-nostdlib}, you get an unresolved reference to @code{__main},
since it's defined in the standard GCC library.  Include @option{-lgcc} at
the end of your compiler command line to resolve this reference.)

The program @code{collect2} is installed as @code{ld} in the directory
where the passes of the compiler are installed.  When @code{collect2}
needs to find the @emph{real} @code{ld}, it tries the following file
names:

@itemize @bullet
@item
@file{real-ld} in the directories listed in the compiler's search
directories.

@item
@file{real-ld} in the directories listed in the environment variable
@code{PATH}.

@item
The file specified in the @code{REAL_LD_FILE_NAME} configuration macro,
if specified.

@item
@file{ld} in the compiler's search directories, except that
@code{collect2} will not execute itself recursively.

@item
@file{ld} in @code{PATH}.
@end itemize

``The compiler's search directories'' means all the directories where
@code{gcc} searches for passes of the compiler.  This includes
directories that you specify with @option{-B}.

Cross-compilers search a little differently:

@itemize @bullet
@item
@file{real-ld} in the compiler's search directories.

@item
@file{@var{target}-real-ld} in @code{PATH}.

@item
The file specified in the @code{REAL_LD_FILE_NAME} configuration macro,
if specified.

@item
@file{ld} in the compiler's search directories.

@item
@file{@var{target}-ld} in @code{PATH}.
@end itemize

@code{collect2} explicitly avoids running @code{ld} using the file name
under which @code{collect2} itself was invoked.  In fact, it remembers
up a list of such names---in case one copy of @code{collect2} finds
another copy (or version) of @code{collect2} installed as @code{ld} in a
second place in the search path.

@code{collect2} searches for the utilities @code{nm} and @code{strip}
using the same algorithm as above for @code{ld}.

@node Header Dirs
@section Standard Header File Directories

@code{GCC_INCLUDE_DIR} means the same thing for native and cross.  It is
where GNU CC stores its private include files, and also where GNU CC
stores the fixed include files.  A cross compiled GNU CC runs
@code{fixincludes} on the header files in @file{$(tooldir)/include}.
(If the cross compilation header files need to be fixed, they must be
installed before GNU CC is built.  If the cross compilation header files
are already suitable for ISO C and GNU CC, nothing special need be
done).

@code{GPLUSPLUS_INCLUDE_DIR} means the same thing for native and cross.  It
is where @code{g++} looks first for header files.  The C++ library
installs only target independent header files in that directory.

@code{LOCAL_INCLUDE_DIR} is used only for a native compiler.  It is
normally @file{/usr/local/include}.  GNU CC searches this directory so
that users can install header files in @file{/usr/local/include}.

@code{CROSS_INCLUDE_DIR} is used only for a cross compiler.  GNU CC
doesn't install anything there.

@code{TOOL_INCLUDE_DIR} is used for both native and cross compilers.  It
is the place for other packages to install header files that GNU CC will
use.  For a cross-compiler, this is the equivalent of
@file{/usr/include}.  When you build a cross-compiler,
@code{fixincludes} processes any header files in this directory.
