| 1 | <html lang="en"><head>
|
|---|
| 2 | <title>Installing GCC: Building</title>
|
|---|
| 3 | <meta http-equiv="Content-Type" content="text/html">
|
|---|
| 4 | <meta name=description content="Installing GCC: Building">
|
|---|
| 5 | <meta name=generator content="makeinfo 4.0">
|
|---|
| 6 | <link href="http://texinfo.org/" rel=generator-home>
|
|---|
| 7 | </head><body>
|
|---|
| 8 |
|
|---|
| 9 | <p>N<p>ow that GCC is configured, you are ready to build the compiler and
|
|---|
| 10 | runtime libraries.
|
|---|
| 11 |
|
|---|
| 12 | <p>We <strong>highly</strong> recommend that GCC be built using GNU make;
|
|---|
| 13 | other versions may work, then again they might not.
|
|---|
| 14 | GNU make is required for compiling GNAT (the Ada compiler) and the Java
|
|---|
| 15 | runtime library.
|
|---|
| 16 |
|
|---|
| 17 | <p>(For example, many broken versions of make will fail if you use the
|
|---|
| 18 | recommended setup where <var>objdir</var> is different from <var>srcdir</var>.
|
|---|
| 19 | Other broken versions may recompile parts of the compiler when
|
|---|
| 20 | installing the compiler.)
|
|---|
| 21 |
|
|---|
| 22 | <p>Some commands executed when making the compiler may fail (return a
|
|---|
| 23 | nonzero status) and be ignored by <code>make</code>. These failures, which
|
|---|
| 24 | are often due to files that were not found, are expected, and can safely
|
|---|
| 25 | be ignored.
|
|---|
| 26 |
|
|---|
| 27 | <p>It is normal to have compiler warnings when compiling certain files.
|
|---|
| 28 | Unless you are a GCC developer, you can generally ignore these warnings
|
|---|
| 29 | unless they cause compilation to fail.
|
|---|
| 30 |
|
|---|
| 31 | <p>On certain old systems, defining certain environment variables such as
|
|---|
| 32 | <code>CC</code> can interfere with the functioning of <code>make</code>.
|
|---|
| 33 |
|
|---|
| 34 | <p>If you encounter seemingly strange errors when trying to build the
|
|---|
| 35 | compiler in a directory other than the source directory, it could be
|
|---|
| 36 | because you have previously configured the compiler in the source
|
|---|
| 37 | directory. Make sure you have done all the necessary preparations.
|
|---|
| 38 |
|
|---|
| 39 | <p>If you build GCC on a BSD system using a directory stored in an old System
|
|---|
| 40 | V file system, problems may occur in running <code>fixincludes</code> if the
|
|---|
| 41 | System V file system doesn't support symbolic links. These problems
|
|---|
| 42 | result in a failure to fix the declaration of <code>size_t</code> in
|
|---|
| 43 | <code>sys/types.h</code>. If you find that <code>size_t</code> is a signed type and
|
|---|
| 44 | that type mismatches occur, this could be the cause.
|
|---|
| 45 |
|
|---|
| 46 | <p>The solution is not to use such a directory for building GCC.
|
|---|
| 47 |
|
|---|
| 48 | <p>When building from CVS or snapshots, or if you modify parser sources,
|
|---|
| 49 | you need the Bison parser generator installed. Any version 1.25 or
|
|---|
| 50 | later should work; older versions may also work. If you do not modify
|
|---|
| 51 | parser sources, releases contain the Bison-generated files and you do
|
|---|
| 52 | not need Bison installed to build them.
|
|---|
| 53 |
|
|---|
| 54 | <p>When building from CVS or snapshots, or if you modify Texinfo
|
|---|
| 55 | documentation, you need version 4.1 or later of Texinfo installed if you
|
|---|
| 56 | want Info documentation to be regenerated. Releases contain Info
|
|---|
| 57 | documentation pre-built for the unmodified documentation in the release.
|
|---|
| 58 |
|
|---|
| 59 | <h2><a name="TOC0">Building a native compiler</h2>
|
|---|
| 60 |
|
|---|
| 61 | <p>For a native build issue the command <code>make bootstrap</code>. This
|
|---|
| 62 | will build the entire GCC system, which includes the following steps:
|
|---|
| 63 |
|
|---|
| 64 | <ul>
|
|---|
| 65 | <li>Build host tools necessary to build the compiler such as texinfo, bison,
|
|---|
| 66 | gperf.
|
|---|
| 67 |
|
|---|
| 68 | <li>Build target tools for use by the compiler such as binutils (bfd,
|
|---|
| 69 | binutils, gas, gprof, ld, and opcodes)
|
|---|
| 70 | if they have been individually linked
|
|---|
| 71 | or moved into the top level GCC source tree before configuring.
|
|---|
| 72 |
|
|---|
| 73 | <li>Perform a 3-stage bootstrap of the compiler.
|
|---|
| 74 |
|
|---|
| 75 | <li>Perform a comparison test of the stage2 and stage3 compilers.
|
|---|
| 76 |
|
|---|
| 77 | <li>Build runtime libraries using the stage3 compiler from the previous step.
|
|---|
| 78 |
|
|---|
| 79 | </ul>
|
|---|
| 80 |
|
|---|
| 81 | <p>If you are short on disk space you might consider <code>make
|
|---|
| 82 | bootstrap-lean</code> instead. This is identical to <code>make
|
|---|
| 83 | bootstrap</code> except that object files from the stage1 and
|
|---|
| 84 | stage2 of the 3-stage bootstrap of the compiler are deleted as
|
|---|
| 85 | soon as they are no longer needed.
|
|---|
| 86 |
|
|---|
| 87 | <p>If you want to save additional space during the bootstrap and in
|
|---|
| 88 | the final installation as well, you can build the compiler binaries
|
|---|
| 89 | without debugging information as in the following example. This will save
|
|---|
| 90 | roughly 40% of disk space both for the bootstrap and the final installation.
|
|---|
| 91 | (Libraries will still contain debugging information.)
|
|---|
| 92 |
|
|---|
| 93 | <pre> make CFLAGS='-O' LIBCFLAGS='-g -O2' \
|
|---|
| 94 | LIBCXXFLAGS='-g -O2 -fno-implicit-templates' bootstrap
|
|---|
| 95 | </pre>
|
|---|
| 96 |
|
|---|
| 97 | <p>If you wish to use non-default GCC flags when compiling the stage2 and
|
|---|
| 98 | stage3 compilers, set <code>BOOT_CFLAGS</code> on the command line when doing
|
|---|
| 99 | <code>make bootstrap</code>. Non-default optimization flags are less well
|
|---|
| 100 | tested here than the default of <code>-g -O2</code>, but should still work.
|
|---|
| 101 | In a few cases, you may find that you need to specify special flags such
|
|---|
| 102 | as <code>-msoft-float</code> here to complete the bootstrap; or, if the
|
|---|
| 103 | native compiler miscompiles the stage1 compiler, you may need to work
|
|---|
| 104 | around this, by choosing <code>BOOT_CFLAGS</code> to avoid the parts of the
|
|---|
| 105 | stage1 compiler that were miscompiled, or by using <code>make
|
|---|
| 106 | bootstrap4</code> to increase the number of stages of bootstrap.
|
|---|
| 107 |
|
|---|
| 108 | <p>If you used the flag <code>--enable-languages=<small>...</small></code> to restrict
|
|---|
| 109 | the compilers to be built, only those you've actually enabled will be
|
|---|
| 110 | built. This will of course only build those runtime libraries, for
|
|---|
| 111 | which the particular compiler has been built. Please note,
|
|---|
| 112 | that re-defining <code>LANGUAGES</code> when calling <code>make bootstrap</code>
|
|---|
| 113 | <strong>does not</strong> work anymore!
|
|---|
| 114 |
|
|---|
| 115 | <p>If the comparison of stage2 and stage3 fails, this normally indicates
|
|---|
| 116 | that the stage2 compiler has compiled GCC incorrectly, and is therefore
|
|---|
| 117 | a potentially serious bug which you should investigate and report. (On
|
|---|
| 118 | a few systems, meaningful comparison of object files is impossible; they
|
|---|
| 119 | always appear "different". If you encounter this problem, you will
|
|---|
| 120 | need to disable comparison in the <code>Makefile</code>.)
|
|---|
| 121 |
|
|---|
| 122 | <h2><a name="TOC1">Building a cross compiler</h2>
|
|---|
| 123 |
|
|---|
| 124 | <p>We recommend reading the
|
|---|
| 125 | <a href="http://www.objsw.com/CrossGCC/">crossgcc FAQ</a>
|
|---|
| 126 | for information about building cross compilers.
|
|---|
| 127 |
|
|---|
| 128 | <p>When building a cross compiler, it is not generally possible to do a
|
|---|
| 129 | 3-stage bootstrap of the compiler. This makes for an interesting problem
|
|---|
| 130 | as parts of GCC can only be built with GCC.
|
|---|
| 131 |
|
|---|
| 132 | <p>To build a cross compiler, we first recommend building and installing a
|
|---|
| 133 | native compiler. You can then use the native GCC compiler to build the
|
|---|
| 134 | cross compiler. The installed native compiler needs to be GCC version
|
|---|
| 135 | 2.95 or later.
|
|---|
| 136 |
|
|---|
| 137 | <p>Assuming you have already installed a native copy of GCC and configured
|
|---|
| 138 | your cross compiler, issue the command <code>make</code>, which performs the
|
|---|
| 139 | following steps:
|
|---|
| 140 |
|
|---|
| 141 | <ul>
|
|---|
| 142 | <li>Build host tools necessary to build the compiler such as texinfo, bison,
|
|---|
| 143 | gperf.
|
|---|
| 144 |
|
|---|
| 145 | <li>Build target tools for use by the compiler such as binutils (bfd,
|
|---|
| 146 | binutils, gas, gprof, ld, and opcodes)
|
|---|
| 147 | if they have been individually linked or moved into the top level GCC source
|
|---|
| 148 | tree before configuring.
|
|---|
| 149 |
|
|---|
| 150 | <li>Build the compiler (single stage only).
|
|---|
| 151 |
|
|---|
| 152 | <li>Build runtime libraries using the compiler from the previous step.
|
|---|
| 153 | </ul>
|
|---|
| 154 |
|
|---|
| 155 | <p>Note that if an error occurs in any step the make process will exit.
|
|---|
| 156 |
|
|---|
| 157 | <h2><a name="TOC2">Building in parallel</h2>
|
|---|
| 158 |
|
|---|
| 159 | <p>If you have a multiprocessor system you can use <code>make bootstrap
|
|---|
| 160 | MAKE="make -j 2" -j 2</code> or just <code>make -j 2 bootstrap</code>
|
|---|
| 161 | for GNU Make 3.79 and above instead of just <code>make bootstrap</code>
|
|---|
| 162 | when building GCC. You can use a bigger number instead of two if
|
|---|
| 163 | you like. In most cases, it won't help to use a number bigger than
|
|---|
| 164 | the number of processors in your machine.
|
|---|
| 165 |
|
|---|
| 166 | <h2><a name="TOC3">Building the Ada compiler</h2>
|
|---|
| 167 |
|
|---|
| 168 | <p>In order to build GNAT, the Ada compiler, you need a working GNAT
|
|---|
| 169 | compiler (GNAT version 3.13 or later, or GCC version 3.1 or later),
|
|---|
| 170 | since the Ada front end is written in Ada (with some
|
|---|
| 171 | GNAT-specific extensions), and GNU make.
|
|---|
| 172 |
|
|---|
| 173 | <p>However, you do not need a full installation of GNAT, just the GNAT
|
|---|
| 174 | binary <code>gnat1</code>, a copy of <code>gnatbind</code>, and a compiler driver
|
|---|
| 175 | which can deal with Ada input (by invoking the <code>gnat1</code> binary).
|
|---|
| 176 | You can specify this compiler driver by setting the <code>ADAC</code>
|
|---|
| 177 | environment variable at the configure step. <code>configure</code> can
|
|---|
| 178 | detect the driver automatically if it has got a common name such as
|
|---|
| 179 | <code>gcc</code> or <code>gnatgcc</code>. Of course, you still need a working
|
|---|
| 180 | C compiler (the compiler driver can be different or not).
|
|---|
| 181 | <code>configure</code> does not test whether the GNAT installation works
|
|---|
| 182 | and has a sufficiently recent version; if too old a GNAT version is
|
|---|
| 183 | installed, the build will fail unless <code>--enable-languages</code> is
|
|---|
| 184 | used to disable building the Ada front end.
|
|---|
| 185 |
|
|---|
| 186 | <p>Additional build tools (such as <code>gnatmake</code>) or a working GNAT
|
|---|
| 187 | run-time library installation are usually <em>not</em> required. However,
|
|---|
| 188 | if you want to bootstrap the compiler using a minimal version of GNAT,
|
|---|
| 189 | you have to issue the following commands before invoking <code>make
|
|---|
| 190 | bootstrap</code> (this assumes that you start with an unmodified and consistent
|
|---|
| 191 | source distribution):
|
|---|
| 192 |
|
|---|
| 193 | <pre> cd <var>srcdir</var>/gcc/ada
|
|---|
| 194 | touch treeprs.ads [es]info.h nmake.ad[bs]
|
|---|
| 195 | </pre>
|
|---|
| 196 |
|
|---|
| 197 | <p>At the moment, the GNAT library and several tools for GNAT are not built
|
|---|
| 198 | by <code>make bootstrap</code>. You have to invoke
|
|---|
| 199 | <code>make gnatlib_and_tools</code> in the <code><var>objdir</var>/gcc</code>
|
|---|
| 200 | subdirectory before proceeding with the next steps.
|
|---|
| 201 |
|
|---|
| 202 | <p>For example, you can build a native Ada compiler by issuing the
|
|---|
| 203 | following commands (assuming <code>make</code> is GNU make):
|
|---|
| 204 |
|
|---|
| 205 | <pre> cd <var>objdir</var>
|
|---|
| 206 | <var>srcdir</var>/configure --enable-languages=c,ada
|
|---|
| 207 | cd <var>srcdir</var>/gcc/ada
|
|---|
| 208 | touch treeprs.ads [es]info.h nmake.ad[bs]
|
|---|
| 209 | cd <var>objdir</var>
|
|---|
| 210 | make bootstrap
|
|---|
| 211 | cd gcc
|
|---|
| 212 | make gnatlib_and_tools
|
|---|
| 213 | cd ..
|
|---|
| 214 | </pre>
|
|---|
| 215 |
|
|---|
| 216 | <p>Currently, when compiling the Ada front end, you cannot use the parallel
|
|---|
| 217 | build feature described in the previous section.
|
|---|
| 218 |
|
|---|
| 219 | <hr />
|
|---|
| 220 | <p>
|
|---|
| 221 | <a href="./index.html">Return to the GCC Installation page</a>
|
|---|
| 222 |
|
|---|
| 223 | </body></html>
|
|---|
| 224 |
|
|---|