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