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