1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> 3 <head> 4 <meta charset="utf-8" /> 5 <meta name="generator" content="pandoc" /> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> 7 <title>Building the JDK</title> 8 <style> 9 code{white-space: pre-wrap;} 10 span.smallcaps{font-variant: small-caps;} 11 div.columns{display: flex; gap: min(4vw, 1.5em);} 12 div.column{flex: auto; overflow-x: auto;} 13 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} 14 ul.task-list{list-style: none;} 15 ul.task-list li input[type="checkbox"] { 16 width: 0.8em; 17 margin: 0 0.8em 0.2em -1.6em; 18 vertical-align: middle; 19 } 20 .display.math{display: block; text-align: center; margin: 0.5rem auto;} 21 </style> 22 <link rel="stylesheet" href="../make/data/docs-resources/resources/jdk-default.css" /> 23 <style type="text/css">pre, code, tt { color: #1d6ae5; }</style> 24 <!--[if lt IE 9]> 25 <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script> 26 <![endif]--> 27 </head> 28 <body> 29 <header id="title-block-header"> 30 <h1 class="title">Building the JDK</h1> 31 </header> 32 <nav id="TOC" role="doc-toc"> 33 <ul> 34 <li><a href="#tldr-instructions-for-the-impatient" 35 id="toc-tldr-instructions-for-the-impatient">TL;DR (Instructions for the 36 Impatient)</a></li> 37 <li><a href="#introduction" id="toc-introduction">Introduction</a></li> 38 <li><a href="#getting-the-source-code" 39 id="toc-getting-the-source-code">Getting the Source Code</a> 40 <ul> 41 <li><a href="#special-considerations" 42 id="toc-special-considerations">Special Considerations</a></li> 43 </ul></li> 44 <li><a href="#build-hardware-requirements" 45 id="toc-build-hardware-requirements">Build Hardware Requirements</a> 46 <ul> 47 <li><a href="#building-on-x86" id="toc-building-on-x86">Building on 48 x86</a></li> 49 <li><a href="#building-on-aarch64" id="toc-building-on-aarch64">Building 50 on aarch64</a></li> 51 <li><a href="#building-on-32-bit-arm" 52 id="toc-building-on-32-bit-arm">Building on 32-bit arm</a></li> 53 </ul></li> 54 <li><a href="#operating-system-requirements" 55 id="toc-operating-system-requirements">Operating System Requirements</a> 56 <ul> 57 <li><a href="#windows" id="toc-windows">Windows</a></li> 58 <li><a href="#macos" id="toc-macos">macOS</a></li> 59 <li><a href="#linux" id="toc-linux">Linux</a></li> 60 <li><a href="#aix" id="toc-aix">AIX</a></li> 61 </ul></li> 62 <li><a href="#native-compiler-toolchain-requirements" 63 id="toc-native-compiler-toolchain-requirements">Native Compiler 64 (Toolchain) Requirements</a> 65 <ul> 66 <li><a href="#gcc" id="toc-gcc">gcc</a></li> 67 <li><a href="#clang" id="toc-clang">clang</a></li> 68 <li><a href="#apple-xcode" id="toc-apple-xcode">Apple Xcode</a></li> 69 <li><a href="#microsoft-visual-studio" 70 id="toc-microsoft-visual-studio">Microsoft Visual Studio</a></li> 71 <li><a href="#ibm-xl-cc" id="toc-ibm-xl-cc">IBM XL C/C++</a></li> 72 </ul></li> 73 <li><a href="#boot-jdk-requirements" id="toc-boot-jdk-requirements">Boot 74 JDK Requirements</a> 75 <ul> 76 <li><a href="#getting-jdk-binaries" 77 id="toc-getting-jdk-binaries">Getting JDK binaries</a></li> 78 </ul></li> 79 <li><a href="#external-library-requirements" 80 id="toc-external-library-requirements">External Library Requirements</a> 81 <ul> 82 <li><a href="#freetype" id="toc-freetype">FreeType</a></li> 83 <li><a href="#cups" id="toc-cups">CUPS</a></li> 84 <li><a href="#x11" id="toc-x11">X11</a></li> 85 <li><a href="#alsa" id="toc-alsa">ALSA</a></li> 86 <li><a href="#libffi" id="toc-libffi">libffi</a></li> 87 </ul></li> 88 <li><a href="#build-tools-requirements" 89 id="toc-build-tools-requirements">Build Tools Requirements</a> 90 <ul> 91 <li><a href="#autoconf" id="toc-autoconf">Autoconf</a></li> 92 <li><a href="#gnu-make" id="toc-gnu-make">GNU Make</a></li> 93 <li><a href="#gnu-bash" id="toc-gnu-bash">GNU Bash</a></li> 94 </ul></li> 95 <li><a href="#running-configure" id="toc-running-configure">Running 96 Configure</a> 97 <ul> 98 <li><a href="#common-configure-arguments" 99 id="toc-common-configure-arguments">Common Configure Arguments</a></li> 100 <li><a href="#configure-control-variables" 101 id="toc-configure-control-variables">Configure Control 102 Variables</a></li> 103 </ul></li> 104 <li><a href="#running-make" id="toc-running-make">Running Make</a> 105 <ul> 106 <li><a href="#common-make-targets" id="toc-common-make-targets">Common 107 Make Targets</a></li> 108 <li><a href="#make-control-variables" 109 id="toc-make-control-variables">Make Control Variables</a></li> 110 </ul></li> 111 <li><a href="#running-tests" id="toc-running-tests">Running 112 Tests</a></li> 113 <li><a href="#signing" id="toc-signing">Signing</a> 114 <ul> 115 <li><a href="#macos-1" id="toc-macos-1">macOS</a></li> 116 </ul></li> 117 <li><a href="#cross-compiling" 118 id="toc-cross-compiling">Cross-compiling</a> 119 <ul> 120 <li><a href="#cross-compiling-the-easy-way-with-openjdk-devkits" 121 id="toc-cross-compiling-the-easy-way-with-openjdk-devkits">Cross 122 compiling the easy way with OpenJDK devkits</a></li> 123 <li><a href="#boot-jdk-and-build-jdk" 124 id="toc-boot-jdk-and-build-jdk">Boot JDK and Build JDK</a></li> 125 <li><a href="#specifying-the-target-platform" 126 id="toc-specifying-the-target-platform">Specifying the Target 127 Platform</a></li> 128 <li><a href="#toolchain-considerations" 129 id="toc-toolchain-considerations">Toolchain Considerations</a></li> 130 <li><a href="#native-libraries" id="toc-native-libraries">Native 131 Libraries</a></li> 132 <li><a href="#cross-compiling-with-debian-sysroots" 133 id="toc-cross-compiling-with-debian-sysroots">Cross compiling with 134 Debian sysroots</a></li> 135 <li><a href="#building-for-armaarch64" 136 id="toc-building-for-armaarch64">Building for ARM/aarch64</a></li> 137 <li><a href="#building-for-musl" id="toc-building-for-musl">Building for 138 musl</a></li> 139 <li><a href="#verifying-the-build" 140 id="toc-verifying-the-build">Verifying the Build</a></li> 141 </ul></li> 142 <li><a href="#build-performance" id="toc-build-performance">Build 143 Performance</a> 144 <ul> 145 <li><a href="#disk-speed" id="toc-disk-speed">Disk Speed</a></li> 146 <li><a href="#virus-checking" id="toc-virus-checking">Virus 147 Checking</a></li> 148 <li><a href="#ccache" id="toc-ccache">Ccache</a></li> 149 <li><a href="#precompiled-headers" 150 id="toc-precompiled-headers">Precompiled Headers</a></li> 151 <li><a href="#icecc-icecream" id="toc-icecc-icecream">Icecc / 152 icecream</a></li> 153 <li><a href="#using-the-javac-server" 154 id="toc-using-the-javac-server">Using the javac server</a></li> 155 <li><a href="#building-the-right-target" 156 id="toc-building-the-right-target">Building the Right Target</a></li> 157 </ul></li> 158 <li><a href="#troubleshooting" 159 id="toc-troubleshooting">Troubleshooting</a> 160 <ul> 161 <li><a href="#locating-the-source-of-the-error" 162 id="toc-locating-the-source-of-the-error">Locating the Source of the 163 Error</a></li> 164 <li><a href="#fixing-unexpected-build-failures" 165 id="toc-fixing-unexpected-build-failures">Fixing Unexpected Build 166 Failures</a></li> 167 <li><a href="#specific-build-issues" 168 id="toc-specific-build-issues">Specific Build Issues</a></li> 169 <li><a href="#getting-help" id="toc-getting-help">Getting Help</a></li> 170 </ul></li> 171 <li><a href="#reproducible-builds" 172 id="toc-reproducible-builds">Reproducible Builds</a></li> 173 <li><a href="#hints-and-suggestions-for-advanced-users" 174 id="toc-hints-and-suggestions-for-advanced-users">Hints and Suggestions 175 for Advanced Users</a> 176 <ul> 177 <li><a href="#bash-completion" id="toc-bash-completion">Bash 178 Completion</a></li> 179 <li><a href="#using-multiple-configurations" 180 id="toc-using-multiple-configurations">Using Multiple 181 Configurations</a></li> 182 <li><a href="#handling-reconfigurations" 183 id="toc-handling-reconfigurations">Handling Reconfigurations</a></li> 184 <li><a href="#using-fine-grained-make-targets" 185 id="toc-using-fine-grained-make-targets">Using Fine-Grained Make 186 Targets</a></li> 187 </ul></li> 188 <li><a href="#understanding-the-build-system" 189 id="toc-understanding-the-build-system">Understanding the Build 190 System</a> 191 <ul> 192 <li><a href="#configurations" 193 id="toc-configurations">Configurations</a></li> 194 <li><a href="#build-output-structure" 195 id="toc-build-output-structure">Build Output Structure</a></li> 196 <li><a href="#fixpath" id="toc-fixpath">Fixpath</a></li> 197 <li><a href="#native-debug-symbols" id="toc-native-debug-symbols">Native 198 Debug Symbols</a></li> 199 <li><a href="#autoconf-details" id="toc-autoconf-details">Autoconf 200 Details</a></li> 201 <li><a href="#developing-the-build-system-itself" 202 id="toc-developing-the-build-system-itself">Developing the Build System 203 Itself</a></li> 204 </ul></li> 205 <li><a href="#contributing-to-the-jdk" 206 id="toc-contributing-to-the-jdk">Contributing to the JDK</a></li> 207 <li><a href="#editing-this-document" 208 id="toc-editing-this-document">Editing this document</a></li> 209 </ul> 210 </nav> 211 <h2 id="tldr-instructions-for-the-impatient">TL;DR (Instructions for the 212 Impatient)</h2> 213 <p>If you are eager to try out building the JDK, these simple steps 214 works most of the time. They assume that you have installed Git (and 215 Cygwin if running on Windows) and cloned the top-level JDK repository 216 that you want to build.</p> 217 <ol type="1"> 218 <li><p><a href="#getting-the-source-code">Get the complete source 219 code</a>:<br /> 220 <code>git clone https://git.openjdk.org/jdk/</code></p></li> 221 <li><p><a href="#running-configure">Run configure</a>:<br /> 222 <code>bash configure</code></p> 223 <p>If <code>configure</code> fails due to missing dependencies (to 224 either the <a 225 href="#native-compiler-toolchain-requirements">toolchain</a>, <a 226 href="#build-tools-requirements">build tools</a>, <a 227 href="#external-library-requirements">external libraries</a> or the <a 228 href="#boot-jdk-requirements">boot JDK</a>), most of the time it prints 229 a suggestion on how to resolve the situation on your platform. Follow 230 the instructions, and try running <code>bash configure</code> 231 again.</p></li> 232 <li><p><a href="#running-make">Run make</a>:<br /> 233 <code>make images</code></p></li> 234 <li><p>Verify your newly built JDK:<br /> 235 <code>./build/*/images/jdk/bin/java -version</code></p></li> 236 <li><p><a href="##running-tests">Run basic tests</a>:<br /> 237 <code>make run-test-tier1</code></p></li> 238 </ol> 239 <p>If any of these steps failed, or if you want to know more about build 240 requirements or build functionality, please continue reading this 241 document.</p> 242 <h2 id="introduction">Introduction</h2> 243 <p>The JDK is a complex software project. Building it requires a certain 244 amount of technical expertise, a fair number of dependencies on external 245 software, and reasonably powerful hardware.</p> 246 <p>If you just want to use the JDK and not build it yourself, this 247 document is not for you. See for instance <a 248 href="http://openjdk.org/install">OpenJDK installation</a> for some 249 methods of installing a prebuilt JDK.</p> 250 <h2 id="getting-the-source-code">Getting the Source Code</h2> 251 <p>Make sure you are getting the correct version. As of JDK 10, the 252 source is no longer split into separate repositories so you only need to 253 clone one single repository. At the <a 254 href="https://git.openjdk.org/">OpenJDK Git site</a> you can see a list 255 of all available repositories. If you want to build an older version, 256 e.g. JDK 11, it is recommended that you get the <code>jdk11u</code> 257 repo, which contains incremental updates, instead of the 258 <code>jdk11</code> repo, which was frozen at JDK 11 GA.</p> 259 <p>If you are new to Git, a good place to start is the book <a 260 href="https://git-scm.com/book/en/v2">Pro Git</a>. The rest of this 261 document assumes a working knowledge of Git.</p> 262 <h3 id="special-considerations">Special Considerations</h3> 263 <p>For a smooth building experience, it is recommended that you follow 264 these rules on where and how to check out the source code.</p> 265 <ul> 266 <li><p>Do not check out the source code in a path which contains spaces. 267 Chances are the build will not work. This is most likely to be an issue 268 on Windows systems.</p></li> 269 <li><p>Do not check out the source code in a path which has a very long 270 name or is nested many levels deep. Chances are you will hit an OS 271 limitation during the build.</p></li> 272 <li><p>Put the source code on a local disk, not a network share. If 273 possible, use an SSD. The build process is very disk intensive, and 274 having slow disk access will significantly increase build times. If you 275 need to use a network share for the source code, see below for 276 suggestions on how to keep the build artifacts on a local disk.</p></li> 277 <li><p>On Windows, if using <a href="#cygwin">Cygwin</a>, extra care 278 must be taken to make sure the environment is consistent. It is 279 recommended that you follow this procedure:</p> 280 <ul> 281 <li><p>Create the directory that is going to contain the top directory 282 of the JDK clone by using the <code>mkdir</code> command in the Cygwin 283 bash shell. That is, do <em>not</em> create it using Windows Explorer. 284 This will ensure that it will have proper Cygwin attributes, and that 285 it's children will inherit those attributes.</p></li> 286 <li><p>Do not put the JDK clone in a path under your Cygwin home 287 directory. This is especially important if your user name contains 288 spaces and/or mixed upper and lower case letters.</p></li> 289 <li><p>You need to install a git client. You have two choices, Cygwin 290 git or Git for Windows. Unfortunately there are pros and cons with each 291 choice.</p> 292 <ul> 293 <li><p>The Cygwin <code>git</code> client has no line ending issues and 294 understands Cygwin paths (which are used throughout the JDK build 295 system). However, it does not currently work well with the Skara CLI 296 tooling. Please see the <a 297 href="https://wiki.openjdk.org/display/SKARA/Skara#Skara-Git">Skara wiki 298 on Git clients</a> for up-to-date information about the Skara git client 299 support.</p></li> 300 <li><p>The <a href="https://gitforwindows.org">Git for Windows</a> 301 client has issues with line endings, and do not understand Cygwin paths. 302 It does work well with the Skara CLI tooling, however. To alleviate the 303 line ending problems, make sure you set <code>core.autocrlf</code> to 304 <code>false</code> (this is asked during installation).</p></li> 305 </ul></li> 306 </ul> 307 <p>Failure to follow this procedure might result in hard-to-debug build 308 problems.</p></li> 309 </ul> 310 <h2 id="build-hardware-requirements">Build Hardware Requirements</h2> 311 <p>The JDK is a massive project, and require machines ranging from 312 decent to powerful to be able to build in a reasonable amount of time, 313 or to be able to complete a build at all.</p> 314 <p>We <em>strongly</em> recommend usage of an SSD disk for the build, 315 since disk speed is one of the limiting factors for build 316 performance.</p> 317 <h3 id="building-on-x86">Building on x86</h3> 318 <p>At a minimum, a machine with 2-4 cores is advisable, as well as 2-4 319 GB of RAM. (The more cores to use, the more memory you need.) At least 6 320 GB of free disk space is required.</p> 321 <p>Even for 32-bit builds, it is recommended to use a 64-bit build 322 machine, and instead create a 32-bit target using 323 <code>--with-target-bits=32</code>.</p> 324 <h3 id="building-on-aarch64">Building on aarch64</h3> 325 <p>At a minimum, a machine with 8 cores is advisable, as well as 8 GB of 326 RAM. (The more cores to use, the more memory you need.) At least 6 GB of 327 free disk space is required.</p> 328 <p>If you do not have access to sufficiently powerful hardware, it is 329 also possible to use <a href="#cross-compiling">cross-compiling</a>.</p> 330 <h4 id="branch-protection">Branch Protection</h4> 331 <p>In order to use Branch Protection features in the VM, 332 <code>--enable-branch-protection</code> must be used. This option 333 requires C++ compiler support (GCC 9.1.0+ or Clang 10+). The resulting 334 build can be run on both machines with and without support for branch 335 protection in hardware. Branch Protection is only supported for Linux 336 targets.</p> 337 <h3 id="building-on-32-bit-arm">Building on 32-bit arm</h3> 338 <p>This is not recommended. Instead, see the section on <a 339 href="#cross-compiling">Cross-compiling</a>.</p> 340 <h2 id="operating-system-requirements">Operating System 341 Requirements</h2> 342 <p>The mainline JDK project supports Linux, macOS, AIX and Windows. 343 Support for other operating system, e.g. BSD, exists in separate "port" 344 projects.</p> 345 <p>In general, the JDK can be built on a wide range of versions of these 346 operating systems, but the further you deviate from what is tested on a 347 daily basis, the more likely you are to run into problems.</p> 348 <p>This table lists the OS versions used by Oracle when building the 349 JDK. Such information is always subject to change, but this table is up 350 to date at the time of writing.</p> 351 <table> 352 <thead> 353 <tr class="header"> 354 <th style="text-align: left;">Operating system</th> 355 <th style="text-align: left;">Vendor/version used</th> 356 </tr> 357 </thead> 358 <tbody> 359 <tr class="odd"> 360 <td style="text-align: left;">Linux</td> 361 <td style="text-align: left;">Oracle Enterprise Linux 6.4 / 7.6</td> 362 </tr> 363 <tr class="even"> 364 <td style="text-align: left;">macOS</td> 365 <td style="text-align: left;">Mac OS X 10.13 (High Sierra)</td> 366 </tr> 367 <tr class="odd"> 368 <td style="text-align: left;">Windows</td> 369 <td style="text-align: left;">Windows Server 2012 R2</td> 370 </tr> 371 </tbody> 372 </table> 373 <p>The double version numbers for Linux are due to the hybrid model used 374 at Oracle, where header files and external libraries from an older 375 version are used when building on a more modern version of the OS.</p> 376 <p>The Build Group has a wiki page with <a 377 href="https://wiki.openjdk.org/display/Build/Supported+Build+Platforms">Supported 378 Build Platforms</a>. From time to time, this is updated by contributors 379 to list successes or failures of building on different platforms.</p> 380 <h3 id="windows">Windows</h3> 381 <p>Windows XP is not a supported platform, but all newer Windows should 382 be able to build the JDK.</p> 383 <p>On Windows, it is important that you pay attention to the 384 instructions in the <a href="#special-considerations">Special 385 Considerations</a>.</p> 386 <p>Windows is the only non-POSIX OS supported by the JDK, and as such, 387 requires some extra care. A POSIX support layer is required to build on 388 Windows. Currently, the only supported such layers are Cygwin, Windows 389 Subsystem for Linux (WSL), and MSYS2. (MSYS is no longer supported due 390 to an outdated bash; While OpenJDK can be built with MSYS2, support for 391 it is still experimental, so build failures and unusual errors are not 392 uncommon.)</p> 393 <p>Internally in the build system, all paths are represented as 394 Unix-style paths, e.g. <code>/cygdrive/c/git/jdk/Makefile</code> rather 395 than <code>C:\git\jdk\Makefile</code>. This rule also applies to input 396 to the build system, e.g. in arguments to <code>configure</code>. So, 397 use <code>--with-msvcr-dll=/cygdrive/c/msvcr100.dll</code> rather than 398 <code>--with-msvcr-dll=c:\msvcr100.dll</code>. For details on this 399 conversion, see the section on <a href="#fixpath">Fixpath</a>.</p> 400 <h4 id="cygwin">Cygwin</h4> 401 <p>A functioning <a href="http://www.cygwin.com/">Cygwin</a> environment 402 is required for building the JDK on Windows. If you have a 64-bit OS, we 403 strongly recommend using the 64-bit version of Cygwin.</p> 404 <p><strong>Note:</strong> Cygwin has a model of continuously updating 405 all packages without any easy way to install or revert to a specific 406 version of a package. This means that whenever you add or update a 407 package in Cygwin, you might (inadvertently) update tools that are used 408 by the JDK build process, and that can cause unexpected build 409 problems.</p> 410 <p>The JDK requires GNU Make 4.0 or greater in Cygwin. This is usually 411 not a problem, since Cygwin currently only distributes GNU Make at a 412 version above 4.0.</p> 413 <p>Apart from the basic Cygwin installation, the following packages must 414 also be installed:</p> 415 <ul> 416 <li><code>autoconf</code></li> 417 <li><code>make</code></li> 418 <li><code>zip</code></li> 419 <li><code>unzip</code></li> 420 </ul> 421 <p>Often, you can install these packages using the following command 422 line:</p> 423 <pre><code><path to Cygwin setup>/setup-x86_64 -q -P autoconf -P make -P unzip -P zip</code></pre> 424 <p>Unfortunately, Cygwin can be unreliable in certain circumstances. If 425 you experience build tool crashes or strange issues when building on 426 Windows, please check the Cygwin FAQ on the <a 427 href="https://cygwin.com/faq/faq.html#faq.using.bloda">"BLODA" list</a> 428 and the section on <a 429 href="https://cygwin.com/faq/faq.html#faq.using.fixing-fork-failures">fork() 430 failures</a>.</p> 431 <h4 id="windows-subsystem-for-linux-wsl">Windows Subsystem for Linux 432 (WSL)</h4> 433 <p>Windows 10 1809 or newer is supported due to a dependency on the 434 wslpath utility and support for environment variable sharing through 435 WSLENV. Version 1803 can work but intermittent build failures have been 436 observed.</p> 437 <p>It's possible to build both Windows and Linux binaries from WSL. To 438 build Windows binaries, you must use a Windows boot JDK (located in a 439 Windows-accessible directory). To build Linux binaries, you must use a 440 Linux boot JDK. The default behavior is to build for Windows. To build 441 for Linux, pass 442 <code>--build=x86_64-unknown-linux-gnu --openjdk-target=x86_64-unknown-linux-gnu</code> 443 to <code>configure</code>.</p> 444 <p>If building Windows binaries, the source code must be located in a 445 Windows- accessible directory. This is because Windows executables (such 446 as Visual Studio and the boot JDK) must be able to access the source 447 code. Also, the drive where the source is stored must be mounted as 448 case-insensitive by changing either /etc/fstab or /etc/wsl.conf in WSL. 449 Individual directories may be corrected using the fsutil tool in case 450 the source was cloned before changing the mount options.</p> 451 <p>Note that while it's possible to build on WSL, testing is still not 452 fully supported.</p> 453 <h3 id="macos">macOS</h3> 454 <p>Apple is using a quite aggressive scheme of pushing OS updates, and 455 coupling these updates with required updates of Xcode. Unfortunately, 456 this makes it difficult for a project such as the JDK to keep pace with 457 a continuously updated machine running macOS. See the section on <a 458 href="#apple-xcode">Apple Xcode</a> on some strategies to deal with 459 this.</p> 460 <p>It is recommended that you use at least Mac OS X 10.13 (High Sierra). 461 At the time of writing, the JDK has been successfully compiled on macOS 462 10.12 (Sierra).</p> 463 <p>The standard macOS environment contains the basic tooling needed to 464 build, but for external libraries a package manager is recommended. The 465 JDK uses <a href="https://brew.sh/">homebrew</a> in the examples, but 466 feel free to use whatever manager you want (or none).</p> 467 <h3 id="linux">Linux</h3> 468 <p>It is often not much problem to build the JDK on Linux. The only 469 general advice is to try to use the compilers, external libraries and 470 header files as provided by your distribution.</p> 471 <p>The basic tooling is provided as part of the core operating system, 472 but you will most likely need to install developer packages.</p> 473 <p>For apt-based distributions (Debian, Ubuntu, etc), try this:</p> 474 <pre><code>sudo apt-get install build-essential</code></pre> 475 <p>For rpm-based distributions (Fedora, Red Hat, etc), try this:</p> 476 <pre><code>sudo yum groupinstall "Development Tools"</code></pre> 477 <p>For Alpine Linux, aside from basic tooling, install the GNU versions 478 of some programs:</p> 479 <pre><code>sudo apk add build-base bash grep zip</code></pre> 480 <h3 id="aix">AIX</h3> 481 <p>Please consult the AIX section of the <a 482 href="https://wiki.openjdk.org/display/Build/Supported+Build+Platforms">Supported 483 Build Platforms</a> OpenJDK Build Wiki page for details about which 484 versions of AIX are supported.</p> 485 <h2 id="native-compiler-toolchain-requirements">Native Compiler 486 (Toolchain) Requirements</h2> 487 <p>Large portions of the JDK consists of native code, that needs to be 488 compiled to be able to run on the target platform. In theory, toolchain 489 and operating system should be independent factors, but in practice 490 there's more or less a one-to-one correlation between target operating 491 system and toolchain. There are ongoing efforts to loosen this strict 492 coupling between compiler and operating system (see <a 493 href="https://bugs.openjdk.org/browse/JDK-8288293">JDK-8288293</a>) but 494 it will likely be a very long time before this goal can be realized.</p> 495 <table> 496 <thead> 497 <tr class="header"> 498 <th>Operating system</th> 499 <th>Supported toolchain</th> 500 </tr> 501 </thead> 502 <tbody> 503 <tr class="odd"> 504 <td>Linux</td> 505 <td>gcc, clang</td> 506 </tr> 507 <tr class="even"> 508 <td>macOS</td> 509 <td>Apple Xcode (using clang)</td> 510 </tr> 511 <tr class="odd"> 512 <td>AIX</td> 513 <td>IBM XL C/C++</td> 514 </tr> 515 <tr class="even"> 516 <td>Windows</td> 517 <td>Microsoft Visual Studio</td> 518 </tr> 519 </tbody> 520 </table> 521 <p>Please see the individual sections on the toolchains for version 522 recommendations. As a reference, these versions of the toolchains are 523 used, at the time of writing, by Oracle for the daily builds of the JDK. 524 It should be possible to compile the JDK with both older and newer 525 versions, but the closer you stay to this list, the more likely you are 526 to compile successfully without issues.</p> 527 <table> 528 <thead> 529 <tr class="header"> 530 <th>Operating system</th> 531 <th>Toolchain version</th> 532 </tr> 533 </thead> 534 <tbody> 535 <tr class="odd"> 536 <td>Linux</td> 537 <td>gcc 11.2.0</td> 538 </tr> 539 <tr class="even"> 540 <td>macOS</td> 541 <td>Apple Xcode 10.1 (using clang 10.0.0)</td> 542 </tr> 543 <tr class="odd"> 544 <td>Windows</td> 545 <td>Microsoft Visual Studio 2022 update 17.1.0</td> 546 </tr> 547 </tbody> 548 </table> 549 <p>All compilers are expected to be able to compile to the C99 language 550 standard, as some C99 features are used in the source code. Microsoft 551 Visual Studio doesn't fully support C99 so in practice shared code is 552 limited to using C99 features that it does support.</p> 553 <h3 id="gcc">gcc</h3> 554 <p>The minimum accepted version of gcc is 5.0. Older versions will 555 generate a warning by <code>configure</code> and are unlikely to 556 work.</p> 557 <p>The JDK is currently known to be able to compile with at least 558 version 11.2 of gcc.</p> 559 <p>In general, any version between these two should be usable.</p> 560 <h3 id="clang">clang</h3> 561 <p>The minimum accepted version of clang is 3.5. Older versions will not 562 be accepted by <code>configure</code>.</p> 563 <p>To use clang instead of gcc on Linux, use 564 <code>--with-toolchain-type=clang</code>.</p> 565 <h3 id="apple-xcode">Apple Xcode</h3> 566 <p>The oldest supported version of Xcode is 8.</p> 567 <p>You will need the Xcode command line developer tools to be able to 568 build the JDK. (Actually, <em>only</em> the command line tools are 569 needed, not the IDE.) The simplest way to install these is to run:</p> 570 <pre><code>xcode-select --install</code></pre> 571 <p>When updating Xcode, it is advisable to keep an older version for 572 building the JDK. To use a specific version of Xcode you have multiple 573 options:</p> 574 <ul> 575 <li>Use <code>xcode-select -s</code> before running 576 <code>configure</code>, e.g. 577 <code>xcode-select -s /Applications/Xcode13.1.app</code>. The drawback 578 is that the setting is system wide and you may have to revert it after 579 an OpenJDK build.</li> 580 <li>Use configure option <code>--with-xcode-path</code>, e.g. 581 <code>configure --with-xcode-path=/Applications/Xcode13.1.app</code> 582 This allows using a specific Xcode version for an OpenJDK build, 583 independently of the active Xcode version by 584 <code>xcode-select</code>.</li> 585 </ul> 586 <p>If you have recently (inadvertently) updated your OS and/or Xcode 587 version, and the JDK can no longer be built, please see the section on 588 <a href="#problems-with-the-build-environment">Problems with the Build 589 Environment</a>, and <a href="#getting-help">Getting Help</a> to find 590 out if there are any recent, non-merged patches available for this 591 update.</p> 592 <h3 id="microsoft-visual-studio">Microsoft Visual Studio</h3> 593 <p>The minimum accepted version is Visual Studio 2019 version 16.8. 594 (Note that this version is often presented as "MSVC 14.28", and reported 595 by cl.exe as 19.28.) Older versions will not be accepted by 596 <code>configure</code> and will not work. The maximum accepted version 597 of Visual Studio is 2022.</p> 598 <p>If you have multiple versions of Visual Studio installed, 599 <code>configure</code> will by default pick the latest. You can request 600 a specific version to be used by setting 601 <code>--with-toolchain-version</code>, e.g. 602 <code>--with-toolchain-version=2022</code>.</p> 603 <p>If you have Visual Studio installed but <code>configure</code> fails 604 to detect it, it may be because of <a href="#spaces-in-path">spaces in 605 path</a>.</p> 606 <h3 id="ibm-xl-cc">IBM XL C/C++</h3> 607 <p>Please consult the AIX section of the <a 608 href="https://wiki.openjdk.org/display/Build/Supported+Build+Platforms">Supported 609 Build Platforms</a> OpenJDK Build Wiki page for details about which 610 versions of XLC are supported.</p> 611 <h2 id="boot-jdk-requirements">Boot JDK Requirements</h2> 612 <p>Paradoxically, building the JDK requires a pre-existing JDK. This is 613 called the "boot JDK". The boot JDK does not, however, have to be a JDK 614 built directly from the source code available in the OpenJDK Community. 615 If you are porting the JDK to a new platform, chances are that there 616 already exists another JDK for that platform that is usable as boot 617 JDK.</p> 618 <p>The rule of thumb is that the boot JDK for building JDK major version 619 <em>N</em> should be a JDK of major version <em>N-1</em>, so for 620 building JDK 9 a JDK 8 would be suitable as boot JDK. However, the JDK 621 should be able to "build itself", so an up-to-date build of the current 622 JDK source is an acceptable alternative. If you are following the 623 <em>N-1</em> rule, make sure you've got the latest update version, since 624 JDK 8 GA might not be able to build JDK 9 on all platforms.</p> 625 <p>Early in the release cycle, version <em>N-1</em> may not yet have 626 been released. In that case, the preferred boot JDK will be version 627 <em>N-2</em> until version <em>N-1</em> is available.</p> 628 <p>If the boot JDK is not automatically detected, or the wrong JDK is 629 picked, use <code>--with-boot-jdk</code> to point to the JDK to use.</p> 630 <h3 id="getting-jdk-binaries">Getting JDK binaries</h3> 631 <p>JDK binaries for Linux, Windows and macOS can be downloaded from <a 632 href="http://jdk.java.net">jdk.java.net</a>. An alternative is to 633 download the <a 634 href="http://www.oracle.com/technetwork/java/javase/downloads">Oracle 635 JDK</a>. Another is the <a href="https://adoptopenjdk.net/">Adopt 636 OpenJDK Project</a>, which publishes experimental prebuilt binaries for 637 various platforms.</p> 638 <p>On Linux you can also get a JDK from the Linux distribution. On 639 apt-based distros (like Debian and Ubuntu), 640 <code>sudo apt-get install openjdk-<VERSION>-jdk</code> is 641 typically enough to install a JDK <VERSION>. On rpm-based distros 642 (like Fedora and Red Hat), try 643 <code>sudo yum install java-<VERSION>-openjdk-devel</code>.</p> 644 <h2 id="external-library-requirements">External Library 645 Requirements</h2> 646 <p>Different platforms require different external libraries. In general, 647 libraries are not optional - that is, they are either required or not 648 used.</p> 649 <p>If a required library is not detected by <code>configure</code>, you 650 need to provide the path to it. There are two forms of the 651 <code>configure</code> arguments to point to an external library: 652 <code>--with-<LIB>=<path></code> or 653 <code>--with-<LIB>-include=<path to include> --with-<LIB>-lib=<path to lib></code>. 654 The first variant is more concise, but require the include files and 655 library files to reside in a default hierarchy under this directory. In 656 most cases, it works fine.</p> 657 <p>As a fallback, the second version allows you to point to the include 658 directory and the lib directory separately.</p> 659 <h3 id="freetype">FreeType</h3> 660 <p>FreeType2 from <a href="http://www.freetype.org/">The FreeType 661 Project</a> is not required on any platform. The exception is on 662 Unix-based platforms when configuring such that the build artifacts will 663 reference a system installed library, rather than bundling the JDK's own 664 copy.</p> 665 <ul> 666 <li>To install on an apt-based Linux, try running 667 <code>sudo apt-get install libfreetype6-dev</code>.</li> 668 <li>To install on an rpm-based Linux, try running 669 <code>sudo yum install freetype-devel</code>.</li> 670 <li>To install on Alpine Linux, try running 671 <code>sudo apk add freetype-dev</code>.</li> 672 <li>To install on macOS, try running 673 <code>brew install freetype</code>.</li> 674 </ul> 675 <p>Use <code>--with-freetype-include=<path></code> and 676 <code>--with-freetype-lib=<path></code> if <code>configure</code> 677 does not automatically locate the platform FreeType files.</p> 678 <h3 id="cups">CUPS</h3> 679 <p>CUPS, <a href="http://www.cups.org">Common UNIX Printing System</a> 680 header files are required on all platforms, except Windows. Often these 681 files are provided by your operating system.</p> 682 <ul> 683 <li>To install on an apt-based Linux, try running 684 <code>sudo apt-get install libcups2-dev</code>.</li> 685 <li>To install on an rpm-based Linux, try running 686 <code>sudo yum install cups-devel</code>.</li> 687 <li>To install on Alpine Linux, try running 688 <code>sudo apk add cups-dev</code>.</li> 689 </ul> 690 <p>Use <code>--with-cups=<path></code> if <code>configure</code> 691 does not properly locate your CUPS files.</p> 692 <h3 id="x11">X11</h3> 693 <p>Certain <a href="http://www.x.org/">X11</a> libraries and include 694 files are required on Linux.</p> 695 <ul> 696 <li>To install on an apt-based Linux, try running 697 <code>sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev</code>.</li> 698 <li>To install on an rpm-based Linux, try running 699 <code>sudo yum install libXtst-devel libXt-devel libXrender-devel libXrandr-devel libXi-devel</code>.</li> 700 <li>To install on Alpine Linux, try running 701 <code>sudo apk add libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev</code>.</li> 702 </ul> 703 <p>Use <code>--with-x=<path></code> if <code>configure</code> does 704 not properly locate your X11 files.</p> 705 <h3 id="alsa">ALSA</h3> 706 <p>ALSA, <a href="https://www.alsa-project.org/">Advanced Linux Sound 707 Architecture</a> is required on Linux. At least version 0.9.1 of ALSA is 708 required.</p> 709 <ul> 710 <li>To install on an apt-based Linux, try running 711 <code>sudo apt-get install libasound2-dev</code>.</li> 712 <li>To install on an rpm-based Linux, try running 713 <code>sudo yum install alsa-lib-devel</code>.</li> 714 <li>To install on Alpine Linux, try running 715 <code>sudo apk add alsa-lib-dev</code>.</li> 716 </ul> 717 <p>Use <code>--with-alsa=<path></code> if <code>configure</code> 718 does not properly locate your ALSA files.</p> 719 <h3 id="libffi">libffi</h3> 720 <p>libffi, the <a href="http://sourceware.org/libffi">Portable Foreign 721 Function Interface Library</a> is required when building the Zero 722 version of Hotspot.</p> 723 <ul> 724 <li>To install on an apt-based Linux, try running 725 <code>sudo apt-get install libffi-dev</code>.</li> 726 <li>To install on an rpm-based Linux, try running 727 <code>sudo yum install libffi-devel</code>.</li> 728 <li>To install on Alpine Linux, try running 729 <code>sudo apk add libffi-dev</code>.</li> 730 </ul> 731 <p>Use <code>--with-libffi=<path></code> if <code>configure</code> 732 does not properly locate your libffi files.</p> 733 <h2 id="build-tools-requirements">Build Tools Requirements</h2> 734 <h3 id="autoconf">Autoconf</h3> 735 <p>The JDK requires <a 736 href="http://www.gnu.org/software/autoconf">Autoconf</a> on all 737 platforms. At least version 2.69 is required.</p> 738 <ul> 739 <li>To install on an apt-based Linux, try running 740 <code>sudo apt-get install autoconf</code>.</li> 741 <li>To install on an rpm-based Linux, try running 742 <code>sudo yum install autoconf</code>.</li> 743 <li>To install on Alpine Linux, try running 744 <code>sudo apk add autoconf</code>.</li> 745 <li>To install on macOS, try running 746 <code>brew install autoconf</code>.</li> 747 <li>To install on Windows, try running 748 <code><path to Cygwin setup>/setup-x86_64 -q -P autoconf</code>.</li> 749 </ul> 750 <p>If <code>configure</code> has problems locating your installation of 751 autoconf, you can specify it using the <code>AUTOCONF</code> environment 752 variable, like this:</p> 753 <pre><code>AUTOCONF=<path to autoconf> configure ...</code></pre> 754 <h3 id="gnu-make">GNU Make</h3> 755 <p>The JDK requires <a href="http://www.gnu.org/software/make">GNU 756 Make</a>. No other flavors of make are supported.</p> 757 <p>At least version 3.81 of GNU Make must be used. For distributions 758 supporting GNU Make 4.0 or above, we strongly recommend it. GNU Make 4.0 759 contains useful functionality to handle parallel building (supported by 760 <code>--with-output-sync</code>) and speed and stability 761 improvements.</p> 762 <p>Note that <code>configure</code> locates and verifies a properly 763 functioning version of <code>make</code> and stores the path to this 764 <code>make</code> binary in the configuration. If you start a build 765 using <code>make</code> on the command line, you will be using the 766 version of make found first in your <code>PATH</code>, and not 767 necessarily the one stored in the configuration. This initial make will 768 be used as "bootstrap make", and in a second stage, the make located by 769 <code>configure</code> will be called. Normally, this will present no 770 issues, but if you have a very old <code>make</code>, or a non-GNU Make 771 <code>make</code> in your path, this might cause issues.</p> 772 <p>If you want to override the default make found by 773 <code>configure</code>, use the <code>MAKE</code> configure variable, 774 e.g. <code>configure MAKE=/opt/gnu/make</code>.</p> 775 <h3 id="gnu-bash">GNU Bash</h3> 776 <p>The JDK requires <a href="http://www.gnu.org/software/bash">GNU 777 Bash</a>. No other shells are supported.</p> 778 <p>At least version 3.2 of GNU Bash must be used.</p> 779 <h2 id="running-configure">Running Configure</h2> 780 <p>To build the JDK, you need a "configuration", which consists of a 781 directory where to store the build output, coupled with information 782 about the platform, the specific build machine, and choices that affect 783 how the JDK is built.</p> 784 <p>The configuration is created by the <code>configure</code> script. 785 The basic invocation of the <code>configure</code> script looks like 786 this:</p> 787 <pre><code>bash configure [options]</code></pre> 788 <p>This will create an output directory containing the configuration and 789 setup an area for the build result. This directory typically looks like 790 <code>build/linux-x64-server-release</code>, but the actual name depends 791 on your specific configuration. (It can also be set directly, see <a 792 href="#using-multiple-configurations">Using Multiple 793 Configurations</a>). This directory is referred to as 794 <code>$BUILD</code> in this documentation.</p> 795 <p><code>configure</code> will try to figure out what system you are 796 running on and where all necessary build components are. If you have all 797 prerequisites for building installed, it should find everything. If it 798 fails to detect any component automatically, it will exit and inform you 799 about the problem.</p> 800 <p>Some command line examples:</p> 801 <ul> 802 <li><p>Create a 32-bit build for Windows with FreeType2 in 803 <code>C:\freetype-i586</code>: 804 <code>bash configure --with-freetype=/cygdrive/c/freetype-i586 --with-target-bits=32</code></p></li> 805 <li><p>Create a debug build with the <code>server</code> JVM and DTrace 806 enabled: 807 <code>bash configure --enable-debug --with-jvm-variants=server --enable-dtrace</code></p></li> 808 </ul> 809 <h3 id="common-configure-arguments">Common Configure Arguments</h3> 810 <p>Here follows some of the most common and important 811 <code>configure</code> argument.</p> 812 <p>To get up-to-date information on <em>all</em> available 813 <code>configure</code> argument, please run:</p> 814 <pre><code>bash configure --help</code></pre> 815 <p>(Note that this help text also include general autoconf options, like 816 <code>--dvidir</code>, that is not relevant to the JDK. To list only 817 JDK-specific features, use <code>bash configure --help=short</code> 818 instead.)</p> 819 <h4 id="configure-arguments-for-tailoring-the-build">Configure Arguments 820 for Tailoring the Build</h4> 821 <ul> 822 <li><code>--enable-debug</code> - Set the debug level to 823 <code>fastdebug</code> (this is a shorthand for 824 <code>--with-debug-level=fastdebug</code>)</li> 825 <li><code>--with-debug-level=<level></code> - Set the debug level, 826 which can be <code>release</code>, <code>fastdebug</code>, 827 <code>slowdebug</code> or <code>optimized</code>. Default is 828 <code>release</code>. <code>optimized</code> is variant of 829 <code>release</code> with additional Hotspot debug code.</li> 830 <li><code>--with-native-debug-symbols=<method></code> - Specify if 831 and how native debug symbols should be built. Available methods are 832 <code>none</code>, <code>internal</code>, <code>external</code>, 833 <code>zipped</code>. Default behavior depends on platform. See <a 834 href="#native-debug-symbols">Native Debug Symbols</a> for more 835 details.</li> 836 <li><code>--with-version-string=<string></code> - Specify the 837 version string this build will be identified with.</li> 838 <li><code>--with-version-<part>=<value></code> - A group of 839 options, where <code><part></code> can be any of <code>pre</code>, 840 <code>opt</code>, <code>build</code>, <code>major</code>, 841 <code>minor</code>, <code>security</code> or <code>patch</code>. Use 842 these options to modify just the corresponding part of the version 843 string from the default, or the value provided by 844 <code>--with-version-string</code>.</li> 845 <li><code>--with-jvm-variants=<variant>[,<variant>...]</code> 846 - Build the specified variant (or variants) of Hotspot. Valid variants 847 are: <code>server</code>, <code>client</code>, <code>minimal</code>, 848 <code>core</code>, <code>zero</code>, <code>custom</code>. Note that not 849 all variants are possible to combine in a single build.</li> 850 <li><code>--enable-jvm-feature-<feature></code> or 851 <code>--disable-jvm-feature-<feature></code> - Include (or 852 exclude) <code><feature></code> as a JVM feature in Hotspot. You 853 can also specify a list of features to be enabled, separated by space or 854 comma, as 855 <code>--with-jvm-features=<feature>[,<feature>...]</code>. 856 If you prefix <code><feature></code> with a <code>-</code>, it 857 will be disabled. These options will modify the default list of features 858 for the JVM variant(s) you are building. For the <code>custom</code> JVM 859 variant, the default list is empty. A complete list of valid JVM 860 features can be found using <code>bash configure --help</code>.</li> 861 <li><code>--with-target-bits=<bits></code> - Create a target 862 binary suitable for running on a <code><bits></code> platform. Use 863 this to create 32-bit output on a 64-bit build platform, instead of 864 doing a full cross-compile. (This is known as a <em>reduced</em> 865 build.)</li> 866 </ul> 867 <p>On Linux, BSD and AIX, it is possible to override where Java by 868 default searches for runtime/JNI libraries. This can be useful in 869 situations where there is a special shared directory for system JNI 870 libraries. This setting can in turn be overridden at runtime by setting 871 the <code>java.library.path</code> property.</p> 872 <ul> 873 <li><code>--with-jni-libpath=<path></code> - Use the specified 874 path as a default when searching for runtime libraries.</li> 875 </ul> 876 <h4 id="configure-arguments-for-native-compilation">Configure Arguments 877 for Native Compilation</h4> 878 <ul> 879 <li><code>--with-devkit=<path></code> - Use this devkit for 880 compilers, tools and resources</li> 881 <li><code>--with-sysroot=<path></code> - Use this directory as 882 sysroot</li> 883 <li><code>--with-extra-path=<path>[;<path>]</code> - Prepend 884 these directories to the default path when searching for all kinds of 885 binaries</li> 886 <li><code>--with-toolchain-path=<path>[;<path>]</code> - 887 Prepend these directories when searching for toolchain binaries 888 (compilers etc)</li> 889 <li><code>--with-extra-cflags=<flags></code> - Append these flags 890 when compiling JDK C files</li> 891 <li><code>--with-extra-cxxflags=<flags></code> - Append these 892 flags when compiling JDK C++ files</li> 893 <li><code>--with-extra-ldflags=<flags></code> - Append these flags 894 when linking JDK libraries</li> 895 </ul> 896 <h4 id="configure-arguments-for-external-dependencies">Configure 897 Arguments for External Dependencies</h4> 898 <ul> 899 <li><code>--with-boot-jdk=<path></code> - Set the path to the <a 900 href="#boot-jdk-requirements">Boot JDK</a></li> 901 <li><code>--with-freetype=<path></code> - Set the path to <a 902 href="#freetype">FreeType</a></li> 903 <li><code>--with-cups=<path></code> - Set the path to <a 904 href="#cups">CUPS</a></li> 905 <li><code>--with-x=<path></code> - Set the path to <a 906 href="#x11">X11</a></li> 907 <li><code>--with-alsa=<path></code> - Set the path to <a 908 href="#alsa">ALSA</a></li> 909 <li><code>--with-libffi=<path></code> - Set the path to <a 910 href="#libffi">libffi</a></li> 911 <li><code>--with-jtreg=<path></code> - Set the path to JTReg. See 912 <a href="#running-tests">Running Tests</a></li> 913 </ul> 914 <p>Certain third-party libraries used by the JDK (libjpeg, giflib, 915 libpng, lcms and zlib) are included in the JDK repository. The default 916 behavior of the JDK build is to use the included ("bundled") versions of 917 libjpeg, giflib, libpng and lcms. For zlib, the system lib (if present) 918 is used except on Windows and AIX. However the bundled libraries may be 919 replaced by an external version. To do so, specify <code>system</code> 920 as the <code><source></code> option in these arguments. (The 921 default is <code>bundled</code>).</p> 922 <ul> 923 <li><code>--with-libjpeg=<source></code> - Use the specified 924 source for libjpeg</li> 925 <li><code>--with-giflib=<source></code> - Use the specified source 926 for giflib</li> 927 <li><code>--with-libpng=<source></code> - Use the specified source 928 for libpng</li> 929 <li><code>--with-lcms=<source></code> - Use the specified source 930 for lcms</li> 931 <li><code>--with-zlib=<source></code> - Use the specified source 932 for zlib</li> 933 </ul> 934 <p>On Linux, it is possible to select either static or dynamic linking 935 of the C++ runtime. The default is static linking, with dynamic linking 936 as fallback if the static library is not found.</p> 937 <ul> 938 <li><code>--with-stdc++lib=<method></code> - Use the specified 939 method (<code>static</code>, <code>dynamic</code> or 940 <code>default</code>) for linking the C++ runtime.</li> 941 </ul> 942 <h3 id="configure-control-variables">Configure Control Variables</h3> 943 <p>It is possible to control certain aspects of <code>configure</code> 944 by overriding the value of <code>configure</code> variables, either on 945 the command line or in the environment.</p> 946 <p>Normally, this is <strong>not recommended</strong>. If used 947 improperly, it can lead to a broken configuration. Unless you're well 948 versed in the build system, this is hard to use properly. Therefore, 949 <code>configure</code> will print a warning if this is detected.</p> 950 <p>However, there are a few <code>configure</code> variables, known as 951 <em>control variables</em> that are supposed to be overridden on the 952 command line. These are variables that describe the location of tools 953 needed by the build, like <code>MAKE</code> or <code>GREP</code>. If any 954 such variable is specified, <code>configure</code> will use that value 955 instead of trying to autodetect the tool. For instance, 956 <code>bash configure MAKE=/opt/gnumake4.0/bin/make</code>.</p> 957 <p>If a configure argument exists, use that instead, e.g. use 958 <code>--with-jtreg</code> instead of setting <code>JTREGEXE</code>.</p> 959 <p>Also note that, despite what autoconf claims, setting 960 <code>CFLAGS</code> will not accomplish anything. Instead use 961 <code>--with-extra-cflags</code> (and similar for <code>cxxflags</code> 962 and <code>ldflags</code>).</p> 963 <h2 id="running-make">Running Make</h2> 964 <p>When you have a proper configuration, all you need to do to build the 965 JDK is to run <code>make</code>. (But see the warning at <a 966 href="#gnu-make">GNU Make</a> about running the correct version of 967 make.)</p> 968 <p>When running <code>make</code> without any arguments, the default 969 target is used, which is the same as running <code>make default</code> 970 or <code>make jdk</code>. This will build a minimal (or roughly minimal) 971 set of compiled output (known as an "exploded image") needed for a 972 developer to actually execute the newly built JDK. The idea is that in 973 an incremental development fashion, when doing a normal make, you should 974 only spend time recompiling what's changed (making it purely 975 incremental) and only do the work that's needed to actually run and test 976 your code.</p> 977 <p>The output of the exploded image resides in <code>$BUILD/jdk</code>. 978 You can test the newly built JDK like this: 979 <code>$BUILD/jdk/bin/java -version</code>.</p> 980 <h3 id="common-make-targets">Common Make Targets</h3> 981 <p>Apart from the default target, here are some common make targets:</p> 982 <ul> 983 <li><code>hotspot</code> - Build all of hotspot (but only hotspot)</li> 984 <li><code>hotspot-<variant></code> - Build just the specified jvm 985 variant</li> 986 <li><code>images</code> or <code>product-images</code> - Build the JDK 987 image</li> 988 <li><code>docs</code> or <code>docs-image</code> - Build the 989 documentation image</li> 990 <li><code>test-image</code> - Build the test image</li> 991 <li><code>all</code> or <code>all-images</code> - Build all images 992 (product, docs and test)</li> 993 <li><code>bootcycle-images</code> - Build images twice, second time with 994 newly built JDK (good for testing)</li> 995 <li><code>clean</code> - Remove all files generated by make, but not 996 those generated by configure</li> 997 <li><code>dist-clean</code> - Remove all files, including 998 configuration</li> 999 </ul> 1000 <p>Run <code>make help</code> to get an up-to-date list of important 1001 make targets and make control variables.</p> 1002 <p>It is possible to build just a single module, a single phase, or a 1003 single phase of a single module, by creating make targets according to 1004 these followin patterns. A phase can be either of <code>gensrc</code>, 1005 <code>gendata</code>, <code>copy</code>, <code>java</code>, 1006 <code>launchers</code>, or <code>libs</code>. See <a 1007 href="#using-fine-grained-make-targets">Using Fine-Grained Make 1008 Targets</a> for more details about this functionality.</p> 1009 <ul> 1010 <li><code><phase></code> - Build the specified phase and 1011 everything it depends on</li> 1012 <li><code><module></code> - Build the specified module and 1013 everything it depends on</li> 1014 <li><code><module>-<phase></code> - Compile the specified 1015 phase for the specified module and everything it depends on</li> 1016 </ul> 1017 <p>Similarly, it is possible to clean just a part of the build by 1018 creating make targets according to these patterns:</p> 1019 <ul> 1020 <li><code>clean-<outputdir></code> - Remove the subdir in the 1021 output dir with the name</li> 1022 <li><code>clean-<phase></code> - Remove all build results related 1023 to a certain build phase</li> 1024 <li><code>clean-<module></code> - Remove all build results related 1025 to a certain module</li> 1026 <li><code>clean-<module>-<phase></code> - Remove all build 1027 results related to a certain module and phase</li> 1028 </ul> 1029 <h3 id="make-control-variables">Make Control Variables</h3> 1030 <p>It is possible to control <code>make</code> behavior by overriding 1031 the value of <code>make</code> variables, either on the command line or 1032 in the environment.</p> 1033 <p>Normally, this is <strong>not recommended</strong>. If used 1034 improperly, it can lead to a broken build. Unless you're well versed in 1035 the build system, this is hard to use properly. Therefore, 1036 <code>make</code> will print a warning if this is detected.</p> 1037 <p>However, there are a few <code>make</code> variables, known as 1038 <em>control variables</em> that are supposed to be overridden on the 1039 command line. These make up the "make time" configuration, as opposed to 1040 the "configure time" configuration.</p> 1041 <h4 id="general-make-control-variables">General Make Control 1042 Variables</h4> 1043 <ul> 1044 <li><code>JOBS</code> - Specify the number of jobs to build with. See <a 1045 href="#build-performance">Build Performance</a>.</li> 1046 <li><code>LOG</code> - Specify the logging level and functionality. See 1047 <a href="#checking-the-build-log-file">Checking the Build Log 1048 File</a></li> 1049 <li><code>CONF</code> and <code>CONF_NAME</code> - Selecting the 1050 configuration(s) to use. See <a 1051 href="#using-multiple-configurations">Using Multiple 1052 Configurations</a></li> 1053 </ul> 1054 <h4 id="test-make-control-variables">Test Make Control Variables</h4> 1055 <p>These make control variables only make sense when running tests. 1056 Please see <strong>Testing the JDK</strong> (<a 1057 href="testing.html">html</a>, <a href="testing.md">markdown</a>) for 1058 details.</p> 1059 <ul> 1060 <li><code>TEST</code></li> 1061 <li><code>TEST_JOBS</code></li> 1062 <li><code>JTREG</code></li> 1063 <li><code>GTEST</code></li> 1064 </ul> 1065 <h4 id="advanced-make-control-variables">Advanced Make Control 1066 Variables</h4> 1067 <p>These advanced make control variables can be potentially unsafe. See 1068 <a href="#hints-and-suggestions-for-advanced-users">Hints and 1069 Suggestions for Advanced Users</a> and <a 1070 href="#understanding-the-build-system">Understanding the Build 1071 System</a> for details.</p> 1072 <ul> 1073 <li><code>SPEC</code></li> 1074 <li><code>CONF_CHECK</code></li> 1075 <li><code>COMPARE_BUILD</code></li> 1076 <li><code>JDK_FILTER</code></li> 1077 <li><code>SPEC_FILTER</code></li> 1078 </ul> 1079 <h2 id="running-tests">Running Tests</h2> 1080 <p>Most of the JDK tests are using the <a 1081 href="http://openjdk.org/jtreg">JTReg</a> test framework. Make sure that 1082 your configuration knows where to find your installation of JTReg. If 1083 this is not picked up automatically, use the 1084 <code>--with-jtreg=<path to jtreg home></code> option to point to 1085 the JTReg framework. Note that this option should point to the JTReg 1086 home, i.e. the top directory, containing <code>lib/jtreg.jar</code> 1087 etc.</p> 1088 <p>The <a href="https://wiki.openjdk.org/display/Adoption">Adoption 1089 Group</a> provides recent builds of jtreg <a 1090 href="https://ci.adoptopenjdk.net/view/Dependencies/job/dependency_pipeline/lastSuccessfulBuild/artifact/jtreg/">here</a>. 1091 Download the latest <code>.tar.gz</code> file, unpack it, and point 1092 <code>--with-jtreg</code> to the <code>jtreg</code> directory that you 1093 just unpacked.</p> 1094 <p>Building of Hotspot Gtest suite requires the source code of Google 1095 Test framework. The top directory, which contains both 1096 <code>googletest</code> and <code>googlemock</code> directories, should 1097 be specified via <code>--with-gtest</code>. The minimum supported 1098 version of Google Test is 1.13.0, whose source code can be obtained:</p> 1099 <ul> 1100 <li>by downloading and unpacking the source bundle from <a 1101 href="https://github.com/google/googletest/releases/tag/v1.13.0">here</a></li> 1102 <li>or by checking out <code>v1.13.0</code> tag of 1103 <code>googletest</code> project: 1104 <code>git clone -b v1.13.0 https://github.com/google/googletest</code></li> 1105 </ul> 1106 <p>To execute the most basic tests (tier 1), use:</p> 1107 <pre><code>make run-test-tier1</code></pre> 1108 <p>For more details on how to run tests, please see <strong>Testing the 1109 JDK</strong> (<a href="testing.html">html</a>, <a 1110 href="testing.md">markdown</a>).</p> 1111 <h2 id="signing">Signing</h2> 1112 <h3 id="macos-1">macOS</h3> 1113 <p>Modern versions of macOS require applications to be signed and 1114 notarizied before distribution. See Apple's documentation for more 1115 background on what this means and how it works. To help support this, 1116 the JDK build can be configured to automatically sign all native 1117 binaries, and the JDK bundle, with all the options needed for successful 1118 notarization, as well as all the entitlements required by the JDK. To 1119 enable <code>hardened</code> signing, use configure parameter 1120 <code>--with-macosx-codesign=hardened</code> and configure the signing 1121 identity you wish to use with 1122 <code>--with-macosx-codesign-identity=<identity></code>. The 1123 identity refers to a signing identity from Apple that needs to be 1124 preinstalled on the build host.</p> 1125 <p>When not signing for distribution with the hardened option, the JDK 1126 build will still attempt to perform <code>adhoc</code> signing to add 1127 the special entitlement <code>com.apple.security.get-task-allow</code> 1128 to each binary. This entitlement is required to be able to dump core 1129 files from a process. Note that adding this entitlement makes the build 1130 invalid for notarization, so it is only added when signing in 1131 <code>debug</code> mode. To explicitly enable this kind of adhoc 1132 signing, use configure parameter 1133 <code>--with-macosx-codesign=debug</code>. It will be enabled by default 1134 in most cases.</p> 1135 <p>It's also possible to completely disable any explicit codesign 1136 operations done by the JDK build using the configure parameter 1137 <code>--without-macosx-codesign</code>. The exact behavior then depends 1138 on the architecture. For macOS on x64, it (at least at the time of this 1139 writing) results in completely unsigned binaries that should still work 1140 fine for development and debugging purposes. On aarch64, the Xcode 1141 linker will apply a default "adhoc" signing, without any entitlements. 1142 Such a build does not allow dumping core files.</p> 1143 <p>The default mode "auto" will try for <code>hardened</code> signing if 1144 the debug level is <code>release</code> and either the default identity 1145 or the specified identity is valid. If hardened isn't possible, then 1146 <code>debug</code> signing is chosen if it works. If nothing works, the 1147 codesign build step is disabled.</p> 1148 <h2 id="cross-compiling">Cross-compiling</h2> 1149 <p>Cross-compiling means using one platform (the <em>build</em> 1150 platform) to generate output that can ran on another platform (the 1151 <em>target</em> platform).</p> 1152 <p>The typical reason for cross-compiling is that the build is performed 1153 on a more powerful desktop computer, but the resulting binaries will be 1154 able to run on a different, typically low-performing system. Most of the 1155 complications that arise when building for embedded is due to this 1156 separation of <em>build</em> and <em>target</em> systems.</p> 1157 <p>This requires a more complex setup and build procedure. This section 1158 assumes you are familiar with cross-compiling in general, and will only 1159 deal with the particularities of cross-compiling the JDK. If you are new 1160 to cross-compiling, please see the <a 1161 href="https://en.wikipedia.org/wiki/Cross_compiler#External_links">external 1162 links at Wikipedia</a> for a good start on reading materials.</p> 1163 <p>Cross-compiling the JDK requires you to be able to build both for the 1164 build platform and for the target platform. The reason for the former is 1165 that we need to build and execute tools during the build process, both 1166 native tools and Java tools.</p> 1167 <p>If all you want to do is to compile a 32-bit version, for the same 1168 OS, on a 64-bit machine, consider using 1169 <code>--with-target-bits=32</code> instead of doing a full-blown 1170 cross-compilation. (While this surely is possible, it's a lot more work 1171 and will take much longer to build.)</p> 1172 <h3 id="cross-compiling-the-easy-way-with-openjdk-devkits">Cross 1173 compiling the easy way with OpenJDK devkits</h3> 1174 <p>The OpenJDK build system provides out-of-the box support for creating 1175 and using so called devkits. A <code>devkit</code> is basically a 1176 collection of a cross-compiling toolchain and a sysroot environment 1177 which can easily be used together with the <code>--with-devkit</code> 1178 configure option to cross compile the OpenJDK. On Linux/x86_64, the 1179 following command:</p> 1180 <pre><code>bash configure --with-devkit=<devkit-path> --openjdk-target=ppc64-linux-gnu && make</code></pre> 1181 <p>will configure and build OpenJDK for Linux/ppc64 assuming that 1182 <code><devkit-path></code> points to a Linux/x86_64 to Linux/ppc64 1183 devkit.</p> 1184 <p>Devkits can be created from the <code>make/devkit</code> directory by 1185 executing:</p> 1186 <pre><code>make [ TARGETS="<TARGET_TRIPLET>+" ] [ BASE_OS=<OS> ] [ BASE_OS_VERSION=<VER> ]</code></pre> 1187 <p>where <code>TARGETS</code> contains one or more 1188 <code>TARGET_TRIPLET</code>s of the form described in <a 1189 href="https://sourceware.org/autobook/autobook/autobook_17.html">section 1190 3.4 of the GNU Autobook</a>. If no targets are given, a native toolchain 1191 for the current platform will be created. Currently, at least the 1192 following targets are known to work:</p> 1193 <table> 1194 <thead> 1195 <tr class="header"> 1196 <th style="text-align: left;">Supported devkit targets</th> 1197 </tr> 1198 </thead> 1199 <tbody> 1200 <tr class="odd"> 1201 <td style="text-align: left;">x86_64-linux-gnu</td> 1202 </tr> 1203 <tr class="even"> 1204 <td style="text-align: left;">aarch64-linux-gnu</td> 1205 </tr> 1206 <tr class="odd"> 1207 <td style="text-align: left;">arm-linux-gnueabihf</td> 1208 </tr> 1209 <tr class="even"> 1210 <td style="text-align: left;">ppc64-linux-gnu</td> 1211 </tr> 1212 <tr class="odd"> 1213 <td style="text-align: left;">ppc64le-linux-gnu</td> 1214 </tr> 1215 <tr class="even"> 1216 <td style="text-align: left;">s390x-linux-gnu</td> 1217 </tr> 1218 </tbody> 1219 </table> 1220 <p><code>BASE_OS</code> must be one of "OEL6" for Oracle Enterprise 1221 Linux 6 or "Fedora" (if not specified "OEL6" will be the default). If 1222 the base OS is "Fedora" the corresponding Fedora release can be 1223 specified with the help of the <code>BASE_OS_VERSION</code> option (with 1224 "27" as default version). If the build is successful, the new devkits 1225 can be found in the <code>build/devkit/result</code> subdirectory:</p> 1226 <pre><code>cd make/devkit 1227 make TARGETS="ppc64le-linux-gnu aarch64-linux-gnu" BASE_OS=Fedora BASE_OS_VERSION=21 1228 ls -1 ../../build/devkit/result/ 1229 x86_64-linux-gnu-to-aarch64-linux-gnu 1230 x86_64-linux-gnu-to-ppc64le-linux-gnu</code></pre> 1231 <p>Notice that devkits are not only useful for targeting different build 1232 platforms. Because they contain the full build dependencies for a system 1233 (i.e. compiler and root file system), they can easily be used to build 1234 well-known, reliable and reproducible build environments. You can for 1235 example create and use a devkit with GCC 7.3 and a Fedora 12 sysroot 1236 environment (with glibc 2.11) on Ubuntu 14.04 (which doesn't have GCC 1237 7.3 by default) to produce OpenJDK binaries which will run on all Linux 1238 systems with runtime libraries newer than the ones from Fedora 12 (e.g. 1239 Ubuntu 16.04, SLES 11 or RHEL 6).</p> 1240 <h3 id="boot-jdk-and-build-jdk">Boot JDK and Build JDK</h3> 1241 <p>When cross-compiling, make sure you use a boot JDK that runs on the 1242 <em>build</em> system, and not on the <em>target</em> system.</p> 1243 <p>To be able to build, we need a "Build JDK", which is a JDK built from 1244 the current sources (that is, the same as the end result of the entire 1245 build process), but able to run on the <em>build</em> system, and not 1246 the <em>target</em> system. (In contrast, the Boot JDK should be from an 1247 older release, e.g. JDK 8 when building JDK 9.)</p> 1248 <p>The build process will create a minimal Build JDK for you, as part of 1249 building. To speed up the build, you can use 1250 <code>--with-build-jdk</code> to <code>configure</code> to point to a 1251 pre-built Build JDK. Please note that the build result is unpredictable, 1252 and can possibly break in subtle ways, if the Build JDK does not 1253 <strong>exactly</strong> match the current sources.</p> 1254 <h3 id="specifying-the-target-platform">Specifying the Target 1255 Platform</h3> 1256 <p>You <em>must</em> specify the target platform when cross-compiling. 1257 Doing so will also automatically turn the build into a cross-compiling 1258 mode. The simplest way to do this is to use the 1259 <code>--openjdk-target</code> argument, e.g. 1260 <code>--openjdk-target=arm-linux-gnueabihf</code>. or 1261 <code>--openjdk-target=aarch64-oe-linux</code>. This will automatically 1262 set the <code>--host</code> and <code>--target</code> options for 1263 autoconf, which can otherwise be confusing. (In autoconf terminology, 1264 the "target" is known as "host", and "target" is used for building a 1265 Canadian cross-compiler.)</p> 1266 <p>If <code>--build</code> has not been explicitly passed to configure, 1267 <code>--openjdk-target</code> will autodetect the build platform and 1268 internally set the flag automatically, otherwise the platform that was 1269 explicitly passed to <code>--build</code> will be used instead.</p> 1270 <h3 id="toolchain-considerations">Toolchain Considerations</h3> 1271 <p>You will need two copies of your toolchain, one which generates 1272 output that can run on the target system (the normal, or 1273 <em>target</em>, toolchain), and one that generates output that can run 1274 on the build system (the <em>build</em> toolchain). Note that 1275 cross-compiling is only supported for gcc at the time being. The gcc 1276 standard is to prefix cross-compiling toolchains with the target 1277 denominator. If you follow this standard, <code>configure</code> is 1278 likely to pick up the toolchain correctly.</p> 1279 <p>The <em>build</em> toolchain will be autodetected just the same way 1280 the normal <em>build</em>/<em>target</em> toolchain will be autodetected 1281 when not cross-compiling. If this is not what you want, or if the 1282 autodetection fails, you can specify a devkit containing the 1283 <em>build</em> toolchain using <code>--with-build-devkit</code> to 1284 <code>configure</code>, or by giving <code>BUILD_CC</code> and 1285 <code>BUILD_CXX</code> arguments.</p> 1286 <p>It is often helpful to locate the cross-compilation tools, headers 1287 and libraries in a separate directory, outside the normal path, and 1288 point out that directory to <code>configure</code>. Do this by setting 1289 the sysroot (<code>--with-sysroot</code>) and appending the directory 1290 when searching for cross-compilations tools 1291 (<code>--with-toolchain-path</code>). As a compact form, you can also 1292 use <code>--with-devkit</code> to point to a single directory, if it is 1293 correctly setup. (See <code>basics.m4</code> for details.)</p> 1294 <h3 id="native-libraries">Native Libraries</h3> 1295 <p>You will need copies of external native libraries for the 1296 <em>target</em> system, present on the <em>build</em> machine while 1297 building.</p> 1298 <p>Take care not to replace the <em>build</em> system's version of these 1299 libraries by mistake, since that can render the <em>build</em> machine 1300 unusable.</p> 1301 <p>Make sure that the libraries you point to (ALSA, X11, etc) are for 1302 the <em>target</em>, not the <em>build</em>, platform.</p> 1303 <h4 id="alsa-1">ALSA</h4> 1304 <p>You will need alsa libraries suitable for your <em>target</em> 1305 system. For most cases, using Debian's pre-built libraries work 1306 fine.</p> 1307 <p>Note that alsa is needed even if you only want to build a headless 1308 JDK.</p> 1309 <ul> 1310 <li><p>Go to <a href="https://www.debian.org/distrib/packages">Debian 1311 Package Search</a> and search for the <code>libasound2</code> and 1312 <code>libasound2-dev</code> packages for your <em>target</em> system. 1313 Download them to /tmp.</p></li> 1314 <li><p>Install the libraries into the cross-compilation toolchain. For 1315 instance:</p></li> 1316 </ul> 1317 <pre><code>cd /tools/gcc-linaro-arm-linux-gnueabihf-raspbian-2012.09-20120921_linux/arm-linux-gnueabihf/libc 1318 dpkg-deb -x /tmp/libasound2_1.0.25-4_armhf.deb . 1319 dpkg-deb -x /tmp/libasound2-dev_1.0.25-4_armhf.deb .</code></pre> 1320 <ul> 1321 <li>If alsa is not properly detected by <code>configure</code>, you can 1322 point it out by <code>--with-alsa</code>.</li> 1323 </ul> 1324 <h4 id="x11-1">X11</h4> 1325 <p>You will need X11 libraries suitable for your <em>target</em> system. 1326 For most cases, using Debian's pre-built libraries work fine.</p> 1327 <p>Note that X11 is needed even if you only want to build a headless 1328 JDK.</p> 1329 <ul> 1330 <li><p>Go to <a href="https://www.debian.org/distrib/packages">Debian 1331 Package Search</a>, search for the following packages for your 1332 <em>target</em> system, and download them to /tmp/target-x11:</p> 1333 <ul> 1334 <li>libxi</li> 1335 <li>libxi-dev</li> 1336 <li>x11proto-core-dev</li> 1337 <li>x11proto-input-dev</li> 1338 <li>x11proto-kb-dev</li> 1339 <li>x11proto-render-dev</li> 1340 <li>x11proto-xext-dev</li> 1341 <li>libice-dev</li> 1342 <li>libxrender</li> 1343 <li>libxrender-dev</li> 1344 <li>libxrandr-dev</li> 1345 <li>libsm-dev</li> 1346 <li>libxt-dev</li> 1347 <li>libx11</li> 1348 <li>libx11-dev</li> 1349 <li>libxtst</li> 1350 <li>libxtst-dev</li> 1351 <li>libxext</li> 1352 <li>libxext-dev</li> 1353 </ul></li> 1354 <li><p>Install the libraries into the cross-compilation toolchain. For 1355 instance:</p> 1356 <pre><code> cd /tools/gcc-linaro-arm-linux-gnueabihf-raspbian-2012.09-20120921_linux/arm-linux-gnueabihf/libc/usr 1357 mkdir X11R6 1358 cd X11R6 1359 for deb in /tmp/target-x11/*.deb ; do dpkg-deb -x $deb . ; done 1360 mv usr/* . 1361 cd lib 1362 cp arm-linux-gnueabihf/* . 1363 ``` 1364 1365 You can ignore the following messages. These libraries are not needed to 1366 successfully complete a full JDK build.</code></pre> 1367 <p>cp: cannot stat 1368 <code>arm-linux-gnueabihf/libICE.so': No such file or directory cp: cannot stat</code>arm-linux-gnueabihf/libSM.so': 1369 No such file or directory cp: cannot stat 1370 `arm-linux-gnueabihf/libXt.so': No such file or directory ```</p></li> 1371 <li><p>If the X11 libraries are not properly detected by 1372 <code>configure</code>, you can point them out by 1373 <code>--with-x</code>.</p></li> 1374 </ul> 1375 <h3 id="cross-compiling-with-debian-sysroots">Cross compiling with 1376 Debian sysroots</h3> 1377 <p>Fortunately, you can create sysroots for foreign architectures with 1378 tools provided by your OS. On Debian/Ubuntu systems, one could use 1379 <code>qemu-deboostrap</code> to create the <em>target</em> system 1380 chroot, which would have the native libraries and headers specific to 1381 that <em>target</em> system. After that, we can use the cross-compiler 1382 on the <em>build</em> system, pointing into chroot to get the build 1383 dependencies right. This allows building for foreign architectures with 1384 native compilation speed.</p> 1385 <p>For example, cross-compiling to AArch64 from x86_64 could be done 1386 like this:</p> 1387 <ul> 1388 <li><p>Install cross-compiler on the <em>build</em> system: 1389 <code>apt install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu</code></p></li> 1390 <li><p>Create chroot on the <em>build</em> system, configuring it for 1391 <em>target</em> system: 1392 <code>sudo qemu-debootstrap \ --arch=arm64 \ --verbose \ --include=fakeroot,symlinks,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype6-dev,libpng-dev,libffi-dev \ --resolve-deps \ buster \ ~/sysroot-arm64 \ http://httpredir.debian.org/debian/</code></p></li> 1393 <li><p>Make sure the symlinks inside the newly created chroot point to 1394 proper locations: 1395 <code>sudo chroot ~/sysroot-arm64 symlinks -cr .</code></p></li> 1396 <li><p>Configure and build with newly created chroot as 1397 sysroot/toolchain-path: 1398 <code>sh ./configure \ --openjdk-target=aarch64-linux-gnu \ --with-sysroot=~/sysroot-arm64 make images ls build/linux-aarch64-server-release/</code></p></li> 1399 </ul> 1400 <p>The build does not create new files in that chroot, so it can be 1401 reused for multiple builds without additional cleanup.</p> 1402 <p>The build system should automatically detect the toolchain paths and 1403 dependencies, but sometimes it might require a little nudge with:</p> 1404 <ul> 1405 <li><p>Native compilers: override <code>CC</code> or <code>CXX</code> 1406 for <code>./configure</code></p></li> 1407 <li><p>Freetype lib location: override <code>--with-freetype-lib</code>, 1408 for example <code>${sysroot}/usr/lib/${target}/</code></p></li> 1409 <li><p>Freetype includes location: override 1410 <code>--with-freetype-include</code> for example 1411 <code>${sysroot}/usr/include/freetype2/</code></p></li> 1412 <li><p>X11 libraries location: override <code>--x-libraries</code>, for 1413 example <code>${sysroot}/usr/lib/${target}/</code></p></li> 1414 </ul> 1415 <p>Architectures that are known to successfully cross-compile like this 1416 are:</p> 1417 <table> 1418 <thead> 1419 <tr class="header"> 1420 <th style="text-align: left;">Target</th> 1421 <th style="text-align: left;">Debian tree</th> 1422 <th style="text-align: left;">Debian arch</th> 1423 <th style="text-align: left;"><code>--openjdk-target=...</code></th> 1424 <th><code>--with-jvm-variants=...</code></th> 1425 </tr> 1426 </thead> 1427 <tbody> 1428 <tr class="odd"> 1429 <td style="text-align: left;">x86</td> 1430 <td style="text-align: left;">buster</td> 1431 <td style="text-align: left;">i386</td> 1432 <td style="text-align: left;">i386-linux-gnu</td> 1433 <td>(all)</td> 1434 </tr> 1435 <tr class="even"> 1436 <td style="text-align: left;">arm</td> 1437 <td style="text-align: left;">buster</td> 1438 <td style="text-align: left;">armhf</td> 1439 <td style="text-align: left;">arm-linux-gnueabihf</td> 1440 <td>(all)</td> 1441 </tr> 1442 <tr class="odd"> 1443 <td style="text-align: left;">aarch64</td> 1444 <td style="text-align: left;">buster</td> 1445 <td style="text-align: left;">arm64</td> 1446 <td style="text-align: left;">aarch64-linux-gnu</td> 1447 <td>(all)</td> 1448 </tr> 1449 <tr class="even"> 1450 <td style="text-align: left;">ppc64le</td> 1451 <td style="text-align: left;">buster</td> 1452 <td style="text-align: left;">ppc64el</td> 1453 <td style="text-align: left;">powerpc64le-linux-gnu</td> 1454 <td>(all)</td> 1455 </tr> 1456 <tr class="odd"> 1457 <td style="text-align: left;">s390x</td> 1458 <td style="text-align: left;">buster</td> 1459 <td style="text-align: left;">s390x</td> 1460 <td style="text-align: left;">s390x-linux-gnu</td> 1461 <td>(all)</td> 1462 </tr> 1463 <tr class="even"> 1464 <td style="text-align: left;">mipsle</td> 1465 <td style="text-align: left;">buster</td> 1466 <td style="text-align: left;">mipsel</td> 1467 <td style="text-align: left;">mipsel-linux-gnu</td> 1468 <td>zero</td> 1469 </tr> 1470 <tr class="odd"> 1471 <td style="text-align: left;">mips64le</td> 1472 <td style="text-align: left;">buster</td> 1473 <td style="text-align: left;">mips64el</td> 1474 <td style="text-align: left;">mips64el-linux-gnueabi64</td> 1475 <td>zero</td> 1476 </tr> 1477 <tr class="even"> 1478 <td style="text-align: left;">armel</td> 1479 <td style="text-align: left;">buster</td> 1480 <td style="text-align: left;">arm</td> 1481 <td style="text-align: left;">arm-linux-gnueabi</td> 1482 <td>zero</td> 1483 </tr> 1484 <tr class="odd"> 1485 <td style="text-align: left;">ppc</td> 1486 <td style="text-align: left;">sid</td> 1487 <td style="text-align: left;">powerpc</td> 1488 <td style="text-align: left;">powerpc-linux-gnu</td> 1489 <td>zero</td> 1490 </tr> 1491 <tr class="even"> 1492 <td style="text-align: left;">ppc64be</td> 1493 <td style="text-align: left;">sid</td> 1494 <td style="text-align: left;">ppc64</td> 1495 <td style="text-align: left;">powerpc64-linux-gnu</td> 1496 <td>(all)</td> 1497 </tr> 1498 <tr class="odd"> 1499 <td style="text-align: left;">m68k</td> 1500 <td style="text-align: left;">sid</td> 1501 <td style="text-align: left;">m68k</td> 1502 <td style="text-align: left;">m68k-linux-gnu</td> 1503 <td>zero</td> 1504 </tr> 1505 <tr class="even"> 1506 <td style="text-align: left;">alpha</td> 1507 <td style="text-align: left;">sid</td> 1508 <td style="text-align: left;">alpha</td> 1509 <td style="text-align: left;">alpha-linux-gnu</td> 1510 <td>zero</td> 1511 </tr> 1512 <tr class="odd"> 1513 <td style="text-align: left;">sh4</td> 1514 <td style="text-align: left;">sid</td> 1515 <td style="text-align: left;">sh4</td> 1516 <td style="text-align: left;">sh4-linux-gnu</td> 1517 <td>zero</td> 1518 </tr> 1519 </tbody> 1520 </table> 1521 <h3 id="building-for-armaarch64">Building for ARM/aarch64</h3> 1522 <p>A common cross-compilation target is the ARM CPU. When building for 1523 ARM, it is useful to set the ABI profile. A number of pre-defined ABI 1524 profiles are available using <code>--with-abi-profile</code>: 1525 arm-vfp-sflt, arm-vfp-hflt, arm-sflt, armv5-vfp-sflt, armv6-vfp-hflt. 1526 Note that soft-float ABIs are no longer properly supported by the 1527 JDK.</p> 1528 <h3 id="building-for-musl">Building for musl</h3> 1529 <p>Just like it's possible to cross-compile for a different CPU, it's 1530 possible to cross-compile for musl libc on a glibc-based <em>build</em> 1531 system. A devkit suitable for most target CPU architectures can be 1532 obtained from <a href="https://musl.cc">musl.cc</a>. After installing 1533 the required packages in the sysroot, configure the build with 1534 <code>--openjdk-target</code>:</p> 1535 <pre><code>sh ./configure --with-jvm-variants=server \ 1536 --with-boot-jdk=$BOOT_JDK \ 1537 --with-build-jdk=$BUILD_JDK \ 1538 --openjdk-target=x86_64-unknown-linux-musl \ 1539 --with-devkit=$DEVKIT \ 1540 --with-sysroot=$SYSROOT</code></pre> 1541 <p>and run <code>make</code> normally.</p> 1542 <h3 id="verifying-the-build">Verifying the Build</h3> 1543 <p>The build will end up in a directory named like 1544 <code>build/linux-arm-normal-server-release</code>.</p> 1545 <p>Inside this build output directory, the <code>images/jdk</code> will 1546 contain the newly built JDK, for your <em>target</em> system.</p> 1547 <p>Copy these folders to your <em>target</em> system. Then you can run 1548 e.g. <code>images/jdk/bin/java -version</code>.</p> 1549 <h2 id="build-performance">Build Performance</h2> 1550 <p>Building the JDK requires a lot of horsepower. Some of the build 1551 tools can be adjusted to utilize more or less of resources such as 1552 parallel threads and memory. The <code>configure</code> script analyzes 1553 your system and selects reasonable values for such options based on your 1554 hardware. If you encounter resource problems, such as out of memory 1555 conditions, you can modify the detected values with:</p> 1556 <ul> 1557 <li><p><code>--with-num-cores</code> -- number of cores in the build 1558 system, e.g. <code>--with-num-cores=8</code>.</p></li> 1559 <li><p><code>--with-memory-size</code> -- memory (in MB) available in 1560 the build system, e.g. <code>--with-memory-size=1024</code></p></li> 1561 </ul> 1562 <p>You can also specify directly the number of build jobs to use with 1563 <code>--with-jobs=N</code> to <code>configure</code>, or 1564 <code>JOBS=N</code> to <code>make</code>. Do not use the <code>-j</code> 1565 flag to <code>make</code>. In most cases it will be ignored by the 1566 makefiles, but it can cause problems for some make targets.</p> 1567 <p>It might also be necessary to specify the JVM arguments passed to the 1568 Boot JDK, using e.g. <code>--with-boot-jdk-jvmargs="-Xmx8G"</code>. 1569 Doing so will override the default JVM arguments passed to the Boot 1570 JDK.</p> 1571 <p>At the end of a successful execution of <code>configure</code>, you 1572 will get a performance summary, indicating how well the build will 1573 perform. Here you will also get performance hints. If you want to build 1574 fast, pay attention to those!</p> 1575 <p>If you want to tweak build performance, run with 1576 <code>make LOG=info</code> to get a build time summary at the end of the 1577 build process.</p> 1578 <h3 id="disk-speed">Disk Speed</h3> 1579 <p>If you are using network shares, e.g. via NFS, for your source code, 1580 make sure the build directory is situated on local disk (e.g. by 1581 <code>ln -s /localdisk/jdk-build $JDK-SHARE/build</code>). The 1582 performance penalty is extremely high for building on a network share; 1583 close to unusable.</p> 1584 <p>Also, make sure that your build tools (including Boot JDK and 1585 toolchain) is located on a local disk and not a network share.</p> 1586 <p>As has been stressed elsewhere, do use SSD for source code and build 1587 directory, as well as (if possible) the build tools.</p> 1588 <h3 id="virus-checking">Virus Checking</h3> 1589 <p>The use of virus checking software, especially on Windows, can 1590 <em>significantly</em> slow down building of the JDK. If possible, turn 1591 off such software, or exclude the directory containing the JDK source 1592 code from on-the-fly checking.</p> 1593 <h3 id="ccache">Ccache</h3> 1594 <p>The JDK build supports building with ccache when using gcc or clang. 1595 Using ccache can radically speed up compilation of native code if you 1596 often rebuild the same sources. Your milage may vary however, so we 1597 recommend evaluating it for yourself. To enable it, make sure it's on 1598 the path and configure with <code>--enable-ccache</code>.</p> 1599 <h3 id="precompiled-headers">Precompiled Headers</h3> 1600 <p>By default, the Hotspot build uses preccompiled headers (PCH) on the 1601 toolchains were it is properly supported (clang, gcc, and Visual 1602 Studio). Normally, this speeds up the build process, but in some 1603 circumstances, it can actually slow things down.</p> 1604 <p>You can experiment by disabling precompiled headers using 1605 <code>--disable-precompiled-headers</code>.</p> 1606 <h3 id="icecc-icecream">Icecc / icecream</h3> 1607 <p><a href="http://github.com/icecc/icecream">icecc/icecream</a> is a 1608 simple way to setup a distributed compiler network. If you have multiple 1609 machines available for building the JDK, you can drastically cut 1610 individual build times by utilizing it.</p> 1611 <p>To use, setup an icecc network, and install icecc on the build 1612 machine. Then run <code>configure</code> using 1613 <code>--enable-icecc</code>.</p> 1614 <h3 id="using-the-javac-server">Using the javac server</h3> 1615 <p>To speed up compilation of Java code, especially during incremental 1616 compilations, the javac server is automatically enabled in the 1617 configuration step by default. To explicitly enable or disable the javac 1618 server, use either <code>--enable-javac-server</code> or 1619 <code>--disable-javac-server</code>.</p> 1620 <h3 id="building-the-right-target">Building the Right Target</h3> 1621 <p>Selecting the proper target to build can have dramatic impact on 1622 build time. For normal usage, <code>jdk</code> or the default target is 1623 just fine. You only need to build <code>images</code> for shipping, or 1624 if your tests require it.</p> 1625 <p>See also <a href="#using-fine-grained-make-targets">Using 1626 Fine-Grained Make Targets</a> on how to build an even smaller subset of 1627 the product.</p> 1628 <h2 id="troubleshooting">Troubleshooting</h2> 1629 <p>If your build fails, it can sometimes be difficult to pinpoint the 1630 problem or find a proper solution.</p> 1631 <h3 id="locating-the-source-of-the-error">Locating the Source of the 1632 Error</h3> 1633 <p>When a build fails, it can be hard to pinpoint the actual cause of 1634 the error. In a typical build process, different parts of the product 1635 build in parallel, with the output interlaced.</p> 1636 <h4 id="build-failure-summary">Build Failure Summary</h4> 1637 <p>To help you, the build system will print a failure summary at the 1638 end. It looks like this:</p> 1639 <pre><code>ERROR: Build failed for target 'hotspot' in configuration 'linux-x64' (exit code 2) 1640 1641 === Output from failing command(s) repeated here === 1642 * For target hotspot_variant-server_libjvm_objs_psMemoryPool.o: 1643 /localhome/git/jdk-sandbox/hotspot/src/share/vm/services/psMemoryPool.cpp:1:1: error: 'failhere' does not name a type 1644 ... (rest of output omitted) 1645 1646 * All command lines available in /localhome/git/jdk-sandbox/build/linux-x64/make-support/failure-logs. 1647 === End of repeated output === 1648 1649 === Make failed targets repeated here === 1650 lib/CompileJvm.gmk:207: recipe for target '/localhome/git/jdk-sandbox/build/linux-x64/hotspot/variant-server/libjvm/objs/psMemoryPool.o' failed 1651 make/Main.gmk:263: recipe for target 'hotspot-server-libs' failed 1652 === End of repeated output === 1653 1654 Hint: Try searching the build log for the name of the first failed target. 1655 Hint: If caused by a warning, try configure --disable-warnings-as-errors.</code></pre> 1656 <p>Let's break it down! First, the selected configuration, and the 1657 top-level target you entered on the command line that caused the failure 1658 is printed.</p> 1659 <p>Then, between the 1660 <code>Output from failing command(s) repeated here</code> and 1661 <code>End of repeated output</code> the first lines of output (stdout 1662 and stderr) from the actual failing command is repeated. In most cases, 1663 this is the error message that caused the build to fail. If multiple 1664 commands were failing (this can happen in a parallel build), output from 1665 all failed commands will be printed here.</p> 1666 <p>The path to the <code>failure-logs</code> directory is printed. In 1667 this file you will find a <code><target>.log</code> file that 1668 contains the output from this command in its entirety, and also a 1669 <code><target>.cmd</code>, which contain the complete command line 1670 used for running this command. You can re-run the failing command by 1671 executing <code>. <path to failure-logs>/<target>.cmd</code> 1672 in your shell.</p> 1673 <p>Another way to trace the failure is to follow the chain of make 1674 targets, from top-level targets to individual file targets. Between 1675 <code>Make failed targets repeated here</code> and 1676 <code>End of repeated output</code> the output from make showing this 1677 chain is repeated. The first failed recipe will typically contain the 1678 full path to the file in question that failed to compile. Following 1679 lines will show a trace of make targets why we ended up trying to 1680 compile that file.</p> 1681 <p>Finally, some hints are given on how to locate the error in the 1682 complete log. In this example, we would try searching the log file for 1683 "<code>psMemoryPool.o</code>". Another way to quickly locate make errors 1684 in the log is to search for "<code>] Error</code>" or 1685 "<code>***</code>".</p> 1686 <p>Note that the build failure summary will only help you if the issue 1687 was a compilation failure or similar. If the problem is more esoteric, 1688 or is due to errors in the build machinery, you will likely get empty 1689 output logs, and <code>No indication of failed target found</code> 1690 instead of the make target chain.</p> 1691 <h4 id="checking-the-build-log-file">Checking the Build Log File</h4> 1692 <p>The output (stdout and stderr) from the latest build is always stored 1693 in <code>$BUILD/build.log</code>. The previous build log is stored as 1694 <code>build.log.old</code>. This means that it is not necessary to 1695 redirect the build output yourself if you want to process it.</p> 1696 <p>You can increase the verbosity of the log file, by the 1697 <code>LOG</code> control variable to <code>make</code>. If you want to 1698 see the command lines used in compilations, use 1699 <code>LOG=cmdlines</code>. To increase the general verbosity, use 1700 <code>LOG=info</code>, <code>LOG=debug</code> or <code>LOG=trace</code>. 1701 Both of these can be combined with <code>cmdlines</code>, e.g. 1702 <code>LOG=info,cmdlines</code>. The <code>debug</code> log level will 1703 show most shell commands executed by make, and <code>trace</code> will 1704 show all. Beware that both these log levels will produce a massive build 1705 log!</p> 1706 <h3 id="fixing-unexpected-build-failures">Fixing Unexpected Build 1707 Failures</h3> 1708 <p>Most of the time, the build will fail due to incorrect changes in the 1709 source code.</p> 1710 <p>Sometimes the build can fail with no apparent changes that have 1711 caused the failure. If this is the first time you are building the JDK 1712 on this particular computer, and the build fails, the problem is likely 1713 with your build environment. But even if you have previously built the 1714 JDK with success, and it now fails, your build environment might have 1715 changed (perhaps due to OS upgrades or similar). But most likely, such 1716 failures are due to problems with the incremental rebuild.</p> 1717 <h4 id="problems-with-the-build-environment">Problems with the Build 1718 Environment</h4> 1719 <p>Make sure your configuration is correct. Re-run 1720 <code>configure</code>, and look for any warnings. Warnings that appear 1721 in the middle of the <code>configure</code> output is also repeated at 1722 the end, after the summary. The entire log is stored in 1723 <code>$BUILD/configure.log</code>.</p> 1724 <p>Verify that the summary at the end looks correct. Are you indeed 1725 using the Boot JDK and native toolchain that you expect?</p> 1726 <p>By default, the JDK has a strict approach where warnings from the 1727 compiler is considered errors which fail the build. For very new or very 1728 old compiler versions, this can trigger new classes of warnings, which 1729 thus fails the build. Run <code>configure</code> with 1730 <code>--disable-warnings-as-errors</code> to turn of this behavior. (The 1731 warnings will still show, but not make the build fail.)</p> 1732 <h4 id="problems-with-incremental-rebuilds">Problems with Incremental 1733 Rebuilds</h4> 1734 <p>Incremental rebuilds mean that when you modify part of the product, 1735 only the affected parts get rebuilt. While this works great in most 1736 cases, and significantly speed up the development process, from time to 1737 time complex interdependencies will result in an incorrect build result. 1738 This is the most common cause for unexpected build problems.</p> 1739 <p>Here are a suggested list of things to try if you are having 1740 unexpected build problems. Each step requires more time than the one 1741 before, so try them in order. Most issues will be solved at step 1 or 1742 2.</p> 1743 <ol type="1"> 1744 <li><p>Make sure your repository is up-to-date</p> 1745 <p>Run <code>git pull origin master</code> to make sure you have the 1746 latest changes.</p></li> 1747 <li><p>Clean build results</p> 1748 <p>The simplest way to fix incremental rebuild issues is to run 1749 <code>make clean</code>. This will remove all build results, but not the 1750 configuration or any build system support artifacts. In most cases, this 1751 will solve build errors resulting from incremental build 1752 mismatches.</p></li> 1753 <li><p>Completely clean the build directory.</p> 1754 <p>If this does not work, the next step is to run 1755 <code>make dist-clean</code>, or removing the build output directory 1756 (<code>$BUILD</code>). This will clean all generated output, including 1757 your configuration. You will need to re-run <code>configure</code> after 1758 this step. A good idea is to run <code>make print-configuration</code> 1759 before running <code>make dist-clean</code>, as this will print your 1760 current <code>configure</code> command line. Here's a way to do 1761 this:</p> 1762 <pre><code>make print-configuration > current-configuration 1763 make dist-clean 1764 bash configure $(cat current-configuration) 1765 make</code></pre></li> 1766 <li><p>Re-clone the Git repository</p> 1767 <p>Sometimes the Git repository gets in a state that causes the product 1768 to be un-buildable. In such a case, the simplest solution is often the 1769 "sledgehammer approach": delete the entire repository, and re-clone it. 1770 If you have local changes, save them first to a different location using 1771 <code>git format-patch</code>.</p></li> 1772 </ol> 1773 <h3 id="specific-build-issues">Specific Build Issues</h3> 1774 <h4 id="clock-skew">Clock Skew</h4> 1775 <p>If you get an error message like this:</p> 1776 <pre><code>File 'xxx' has modification time in the future. 1777 Clock skew detected. Your build may be incomplete.</code></pre> 1778 <p>then the clock on your build machine is out of sync with the 1779 timestamps on the source files. Other errors, apparently unrelated but 1780 in fact caused by the clock skew, can occur along with the clock skew 1781 warnings. These secondary errors may tend to obscure the fact that the 1782 true root cause of the problem is an out-of-sync clock.</p> 1783 <p>If you see these warnings, reset the clock on the build machine, run 1784 <code>make clean</code> and restart the build.</p> 1785 <h4 id="out-of-memory-errors">Out of Memory Errors</h4> 1786 <p>On Windows, you might get error messages like this:</p> 1787 <pre><code>fatal error - couldn't allocate heap 1788 cannot create ... Permission denied 1789 spawn failed</code></pre> 1790 <p>This can be a sign of a Cygwin problem. See the information about 1791 solving problems in the <a href="#cygwin">Cygwin</a> section. Rebooting 1792 the computer might help temporarily.</p> 1793 <h4 id="spaces-in-path">Spaces in Path</h4> 1794 <p>On Windows, when configuring, <code>fixpath.sh</code> may report that 1795 some directory names have spaces. Usually, it assumes those directories 1796 have <a 1797 href="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-8dot3name">short 1798 paths</a>. You can run <code>fsutil file setshortname</code> in 1799 <code>cmd</code> on certain directories, such as 1800 <code>Microsoft Visual Studio</code> or <code>Windows Kits</code>, to 1801 assign arbitrary short paths so <code>configure</code> can access 1802 them.</p> 1803 <h3 id="getting-help">Getting Help</h3> 1804 <p>If none of the suggestions in this document helps you, or if you find 1805 what you believe is a bug in the build system, please contact the Build 1806 Group by sending a mail to <a 1807 href="mailto:build-dev@openjdk.org">build-dev@openjdk.org</a>. Please 1808 include the relevant parts of the configure and/or build log.</p> 1809 <p>If you need general help or advice about developing for the JDK, you 1810 can also contact the Adoption Group. See the section on <a 1811 href="#contributing-to-openjdk">Contributing to OpenJDK</a> for more 1812 information.</p> 1813 <h2 id="reproducible-builds">Reproducible Builds</h2> 1814 <p>Build reproducibility is the property of getting exactly the same 1815 bits out when building, every time, independent on who builds the 1816 product, or where. This is for many reasons a harder goal than it 1817 initially appears, but it is an important goal, for security reasons and 1818 others. Please see <a 1819 href="https://reproducible-builds.org">Reproducible Builds</a> for more 1820 information about the background and reasons for reproducible 1821 builds.</p> 1822 <p>Currently, it is not possible to build OpenJDK fully reproducibly, 1823 but getting there is an ongoing effort.</p> 1824 <p>An absolute prerequisite for building reproducible is to speficy a 1825 fixed build time, since time stamps are embedded in many file formats. 1826 This is done by setting the <code>SOURCE_DATE_EPOCH</code> environment 1827 variable, which is an <a 1828 href="https://reproducible-builds.org/docs/source-date-epoch/">industry 1829 standard</a>, that many tools, such as gcc, recognize, and use in place 1830 of the current time when generating output.</p> 1831 <p>To generate reproducible builds, you must set 1832 <code>SOURCE_DATE_EPOCH</code> before running <code>configure</code>. 1833 The value in <code>SOURCE_DATE_EPOCH</code> will be stored in the 1834 configuration, and used by <code>make</code>. Setting 1835 <code>SOURCE_DATE_EPOCH</code> before running <code>make</code> will 1836 have no effect on the build.</p> 1837 <p>You must also make sure your build does not rely on 1838 <code>configure</code>'s default adhoc version strings. Default adhoc 1839 version strings <code>OPT</code> segment include user name and source 1840 directory. You can either override just the <code>OPT</code> segment 1841 using <code>--with-version-opt=<any fixed string></code>, or you 1842 can specify the entire version string using 1843 <code>--with-version-string=<your version></code>.</p> 1844 <p>This is a typical example of how to build the JDK in a reproducible 1845 way:</p> 1846 <pre><code>export SOURCE_DATE_EPOCH=946684800 1847 bash configure --with-version-opt=adhoc 1848 make</code></pre> 1849 <p>Note that regardless if you specify a source date for 1850 <code>configure</code> or not, the JDK build system will set 1851 <code>SOURCE_DATE_EPOCH</code> for all build tools when building. If 1852 <code>--with-source-date</code> has the value <code>current</code> 1853 (which is the default unless <code>SOURCE_DATE_EPOCH</code> is found by 1854 in the environment by <code>configure</code>), the source date value 1855 will be determined at configure time.</p> 1856 <p>There are several aspects of reproducible builds that can be 1857 individually adjusted by <code>configure</code> arguments. If any of 1858 these are given, they will override the value derived from 1859 <code>SOURCE_DATE_EPOCH</code>. These arguments are:</p> 1860 <ul> 1861 <li><p><code>--with-source-date</code></p> 1862 <p>This option controls how the JDK build sets 1863 <code>SOURCE_DATE_EPOCH</code> when building. It can be set to a value 1864 describing a date, either an epoch based timestamp as an integer, or a 1865 valid ISO-8601 date.</p> 1866 <p>It can also be set to one of the special values <code>current</code>, 1867 <code>updated</code> or <code>version</code>. <code>current</code> means 1868 that the time of running <code>configure</code> will be used. 1869 <code>version</code> will use the nominal release date for the current 1870 JDK version. <code>updated</code>, which means that 1871 <code>SOURCE_DATE_EPOCH</code> will be set to the current time each time 1872 you are running <code>make</code>. All choices, except for 1873 <code>updated</code>, will set a fixed value for the source date 1874 timestamp.</p> 1875 <p>When <code>SOURCE_DATE_EPOCH</code> is set, the default value for 1876 <code>--with-source-date</code> will be the value given by 1877 <code>SOURCE_DATE_EPOCH</code>. Otherwise, the default value is 1878 <code>current</code>.</p></li> 1879 <li><p><code>--with-hotspot-build-time</code></p> 1880 <p>This option controls the build time string that will be included in 1881 the hotspot library (<code>libjvm.so</code> or <code>jvm.dll</code>). 1882 When the source date is fixed (e.g. by setting 1883 <code>SOURCE_DATE_EPOCH</code>), the default value for 1884 <code>--with-hotspot-build-time</code> will be an ISO 8601 1885 representation of that time stamp. Otherwise the default value will be 1886 the current time when building hotspot.</p></li> 1887 <li><p><code>--with-copyright-year</code></p> 1888 <p>This option controls the copyright year in some generated text files. 1889 When the source date is fixed (e.g. by setting 1890 <code>SOURCE_DATE_EPOCH</code>), the default value for 1891 <code>--with-copyright-year</code> will be the year of that time stamp. 1892 Otherwise the default is the current year at the time of running 1893 configure. This can be overridden by 1894 <code>--with-copyright-year=<year></code>.</p></li> 1895 <li><p><code>--enable-reproducible-build</code></p> 1896 <p>This option controls some additional behavior needed to make the 1897 build reproducible. When the source date is fixed (e.g. by setting 1898 <code>SOURCE_DATE_EPOCH</code>), this flag will be turned on by default. 1899 Otherwise, the value is determined by heuristics. If it is explicitly 1900 turned off, the build might not be reproducible.</p></li> 1901 </ul> 1902 <h2 id="hints-and-suggestions-for-advanced-users">Hints and Suggestions 1903 for Advanced Users</h2> 1904 <h3 id="bash-completion">Bash Completion</h3> 1905 <p>The <code>configure</code> and <code>make</code> commands tries to 1906 play nice with bash command-line completion (using 1907 <code><tab></code> or <code><tab><tab></code>). To use 1908 this functionality, make sure you enable completion in your 1909 <code>~/.bashrc</code> (see instructions for bash in your operating 1910 system).</p> 1911 <p>Make completion will work out of the box, and will complete valid 1912 make targets. For instance, typing <code>make jdk-i<tab></code> 1913 will complete to <code>make jdk-image</code>.</p> 1914 <p>The <code>configure</code> script can get completion for options, but 1915 for this to work you need to help <code>bash</code> on the way. The 1916 standard way of running the script, <code>bash configure</code>, will 1917 not be understood by bash completion. You need <code>configure</code> to 1918 be the command to run. One way to achieve this is to add a simple helper 1919 script to your path:</p> 1920 <pre><code>cat << EOT > /tmp/configure 1921 #!/bin/bash 1922 if [ \$(pwd) = \$(cd \$(dirname \$0); pwd) ] ; then 1923 echo >&2 "Abort: Trying to call configure helper recursively" 1924 exit 1 1925 fi 1926 1927 bash \$PWD/configure "\$@" 1928 EOT 1929 chmod +x /tmp/configure 1930 sudo mv /tmp/configure /usr/local/bin</code></pre> 1931 <p>Now <code>configure --en<tab>-dt<tab></code> will result 1932 in <code>configure --enable-dtrace</code>.</p> 1933 <h3 id="using-multiple-configurations">Using Multiple 1934 Configurations</h3> 1935 <p>You can have multiple configurations for a single source repository. 1936 When you create a new configuration, run 1937 <code>configure --with-conf-name=<name></code> to create a 1938 configuration with the name <code><name></code>. Alternatively, 1939 you can create a directory under <code>build</code> and run 1940 <code>configure</code> from there, e.g. 1941 <code>mkdir build/<name> && cd build/<name> && bash ../../configure</code>.</p> 1942 <p>Then you can build that configuration using 1943 <code>make CONF_NAME=<name></code> or 1944 <code>make CONF=<pattern></code>, where 1945 <code><pattern></code> is a substring matching one or several 1946 configurations, e.g. <code>CONF=debug</code>. The special empty pattern 1947 (<code>CONF=</code>) will match <em>all</em> available configuration, so 1948 <code>make CONF= hotspot</code> will build the <code>hotspot</code> 1949 target for all configurations. Alternatively, you can execute 1950 <code>make</code> in the configuration directory, e.g. 1951 <code>cd build/<name> && make</code>.</p> 1952 <h3 id="handling-reconfigurations">Handling Reconfigurations</h3> 1953 <p>If you update the repository and part of the configure script has 1954 changed, the build system will force you to re-run 1955 <code>configure</code>.</p> 1956 <p>Most of the time, you will be fine by running <code>configure</code> 1957 again with the same arguments as the last time, which can easily be 1958 performed by <code>make reconfigure</code>. To simplify this, you can 1959 use the <code>CONF_CHECK</code> make control variable, either as 1960 <code>make CONF_CHECK=auto</code>, or by setting an environment 1961 variable. For instance, if you add <code>export CONF_CHECK=auto</code> 1962 to your <code>.bashrc</code> file, <code>make</code> will always run 1963 <code>reconfigure</code> automatically whenever the configure script has 1964 changed.</p> 1965 <p>You can also use <code>CONF_CHECK=ignore</code> to skip the check for 1966 a needed configure update. This might speed up the build, but comes at 1967 the risk of an incorrect build result. This is only recommended if you 1968 know what you're doing.</p> 1969 <p>From time to time, you will also need to modify the command line to 1970 <code>configure</code> due to changes. Use 1971 <code>make print-configuration</code> to show the command line used for 1972 your current configuration.</p> 1973 <h3 id="using-fine-grained-make-targets">Using Fine-Grained Make 1974 Targets</h3> 1975 <p>The default behavior for make is to create consistent and correct 1976 output, at the expense of build speed, if necessary.</p> 1977 <p>If you are prepared to take some risk of an incorrect build, and know 1978 enough of the system to understand how things build and interact, you 1979 can speed up the build process considerably by instructing make to only 1980 build a portion of the product.</p> 1981 <h4 id="building-individual-modules">Building Individual Modules</h4> 1982 <p>The safe way to use fine-grained make targets is to use the module 1983 specific make targets. All source code in the JDK is organized so it 1984 belongs to a module, e.g. <code>java.base</code> or 1985 <code>jdk.jdwp.agent</code>. You can build only a specific module, by 1986 giving it as make target: <code>make jdk.jdwp.agent</code>. If the 1987 specified module depends on other modules (e.g. <code>java.base</code>), 1988 those modules will be built first.</p> 1989 <p>You can also specify a set of modules, just as you can always specify 1990 a set of make targets: 1991 <code>make jdk.crypto.cryptoki jdk.crypto.ec jdk.crypto.mscapi</code></p> 1992 <h4 id="building-individual-module-phases">Building Individual Module 1993 Phases</h4> 1994 <p>The build process for each module is divided into separate phases. 1995 Not all modules need all phases. Which are needed depends on what kind 1996 of source code and other artifact the module consists of. The phases 1997 are:</p> 1998 <ul> 1999 <li><code>gensrc</code> (Generate source code to compile)</li> 2000 <li><code>gendata</code> (Generate non-source code artifacts)</li> 2001 <li><code>copy</code> (Copy resource artifacts)</li> 2002 <li><code>java</code> (Compile Java code)</li> 2003 <li><code>launchers</code> (Compile native executables)</li> 2004 <li><code>libs</code> (Compile native libraries)</li> 2005 </ul> 2006 <p>You can build only a single phase for a module by using the notation 2007 <code>$MODULE-$PHASE</code>. For instance, to build the 2008 <code>gensrc</code> phase for <code>java.base</code>, use 2009 <code>make java.base-gensrc</code>.</p> 2010 <p>Note that some phases may depend on others, e.g. <code>java</code> 2011 depends on <code>gensrc</code> (if present). Make will build all needed 2012 prerequisites before building the requested phase.</p> 2013 <h4 id="skipping-the-dependency-check">Skipping the Dependency 2014 Check</h4> 2015 <p>When using an iterative development style with frequent quick 2016 rebuilds, the dependency check made by make can take up a significant 2017 portion of the time spent on the rebuild. In such cases, it can be 2018 useful to bypass the dependency check in make.</p> 2019 <blockquote> 2020 <p><strong>Note that if used incorrectly, this can lead to a broken 2021 build!</strong></p> 2022 </blockquote> 2023 <p>To achieve this, append <code>-only</code> to the build target. For 2024 instance, <code>make jdk.jdwp.agent-java-only</code> will <em>only</em> 2025 build the <code>java</code> phase of the <code>jdk.jdwp.agent</code> 2026 module. If the required dependencies are not present, the build can 2027 fail. On the other hand, the execution time measures in 2028 milliseconds.</p> 2029 <p>A useful pattern is to build the first time normally (e.g. 2030 <code>make jdk.jdwp.agent</code>) and then on subsequent builds, use the 2031 <code>-only</code> make target.</p> 2032 <h4 id="rebuilding-part-of-java.base-jdk_filter">Rebuilding Part of 2033 java.base (JDK_FILTER)</h4> 2034 <p>If you are modifying files in <code>java.base</code>, which is the by 2035 far largest module in the JDK, then you need to rebuild all those files 2036 whenever a single file has changed. (This inefficiency will hopefully be 2037 addressed in JDK 10.)</p> 2038 <p>As a hack, you can use the make control variable 2039 <code>JDK_FILTER</code> to specify a pattern that will be used to limit 2040 the set of files being recompiled. For instance, 2041 <code>make java.base JDK_FILTER=javax/crypto</code> (or, to combine 2042 methods, <code>make java.base-java-only JDK_FILTER=javax/crypto</code>) 2043 will limit the compilation to files in the <code>javax.crypto</code> 2044 package.</p> 2045 <h2 id="understanding-the-build-system">Understanding the Build 2046 System</h2> 2047 <p>This section will give you a more technical description on the 2048 details of the build system.</p> 2049 <h3 id="configurations">Configurations</h3> 2050 <p>The build system expects to find one or more configuration. These are 2051 technically defined by the <code>spec.gmk</code> in a subdirectory to 2052 the <code>build</code> subdirectory. The <code>spec.gmk</code> file is 2053 generated by <code>configure</code>, and contains in principle the 2054 configuration (directly or by files included by 2055 <code>spec.gmk</code>).</p> 2056 <p>You can, in fact, select a configuration to build by pointing to the 2057 <code>spec.gmk</code> file with the <code>SPEC</code> make control 2058 variable, e.g. <code>make SPEC=$BUILD/spec.gmk</code>. While this is not 2059 the recommended way to call <code>make</code> as a user, it is what is 2060 used under the hood by the build system.</p> 2061 <h3 id="build-output-structure">Build Output Structure</h3> 2062 <p>The build output for a configuration will end up in 2063 <code>build/<configuration name></code>, which we refer to as 2064 <code>$BUILD</code> in this document. The <code>$BUILD</code> directory 2065 contains the following important directories:</p> 2066 <pre><code>buildtools/ 2067 configure-support/ 2068 hotspot/ 2069 images/ 2070 jdk/ 2071 make-support/ 2072 support/ 2073 test-results/ 2074 test-support/</code></pre> 2075 <p>This is what they are used for:</p> 2076 <ul> 2077 <li><p><code>images</code>: This is the directory were the output of the 2078 <code>*-image</code> make targets end up. For instance, 2079 <code>make jdk-image</code> ends up in <code>images/jdk</code>.</p></li> 2080 <li><p><code>jdk</code>: This is the "exploded image". After 2081 <code>make jdk</code>, you will be able to launch the newly built JDK by 2082 running <code>$BUILD/jdk/bin/java</code>.</p></li> 2083 <li><p><code>test-results</code>: This directory contains the results 2084 from running tests.</p></li> 2085 <li><p><code>support</code>: This is an area for intermediate files 2086 needed during the build, e.g. generated source code, object files and 2087 class files. Some noteworthy directories in <code>support</code> is 2088 <code>gensrc</code>, which contains the generated source code, and the 2089 <code>modules_*</code> directories, which contains the files in a 2090 per-module hierarchy that will later be collapsed into the 2091 <code>jdk</code> directory of the exploded image.</p></li> 2092 <li><p><code>buildtools</code>: This is an area for tools compiled for 2093 the build platform that are used during the rest of the build.</p></li> 2094 <li><p><code>hotspot</code>: This is an area for intermediate files 2095 needed when building hotspot.</p></li> 2096 <li><p><code>configure-support</code>, <code>make-support</code> and 2097 <code>test-support</code>: These directories contain files that are 2098 needed by the build system for <code>configure</code>, <code>make</code> 2099 and for running tests.</p></li> 2100 </ul> 2101 <h3 id="fixpath">Fixpath</h3> 2102 <p>Windows path typically look like <code>C:\User\foo</code>, while Unix 2103 paths look like <code>/home/foo</code>. Tools with roots from Unix often 2104 experience issues related to this mismatch when running on Windows.</p> 2105 <p>In the JDK build, we always use Unix paths internally, and only just 2106 before calling a tool that does not understand Unix paths do we convert 2107 them to Windows paths.</p> 2108 <p>This conversion is done by the <code>fixpath</code> tool, which is a 2109 small wrapper that modifies unix-style paths to Windows-style paths in 2110 command lines. Fixpath is compiled automatically by 2111 <code>configure</code>.</p> 2112 <h3 id="native-debug-symbols">Native Debug Symbols</h3> 2113 <p>Native libraries and executables can have debug symbol (and other 2114 debug information) associated with them. How this works is very much 2115 platform dependent, but a common problem is that debug symbol 2116 information takes a lot of disk space, but is rarely needed by the end 2117 user.</p> 2118 <p>The JDK supports different methods on how to handle debug symbols. 2119 The method used is selected by <code>--with-native-debug-symbols</code>, 2120 and available methods are <code>none</code>, <code>internal</code>, 2121 <code>external</code>, <code>zipped</code>.</p> 2122 <ul> 2123 <li><p><code>none</code> means that no debug symbols will be generated 2124 during the build.</p></li> 2125 <li><p><code>internal</code> means that debug symbols will be generated 2126 during the build, and they will be stored in the generated 2127 binary.</p></li> 2128 <li><p><code>external</code> means that debug symbols will be generated 2129 during the build, and after the compilation, they will be moved into a 2130 separate <code>.debuginfo</code> file. (This was previously known as 2131 FDS, Full Debug Symbols).</p></li> 2132 <li><p><code>zipped</code> is like <code>external</code>, but the 2133 .debuginfo file will also be zipped into a <code>.diz</code> 2134 file.</p></li> 2135 </ul> 2136 <p>When building for distribution, <code>zipped</code> is a good 2137 solution. Binaries built with <code>internal</code> is suitable for use 2138 by developers, since they facilitate debugging, but should be stripped 2139 before distributed to end users.</p> 2140 <h3 id="autoconf-details">Autoconf Details</h3> 2141 <p>The <code>configure</code> script is based on the autoconf framework, 2142 but in some details deviate from a normal autoconf 2143 <code>configure</code> script.</p> 2144 <p>The <code>configure</code> script in the top level directory of the 2145 JDK is just a thin wrapper that calls 2146 <code>make/autoconf/configure</code>. This in turn will run 2147 <code>autoconf</code> to create the runnable (generated) configure 2148 script, as <code>.build/generated-configure.sh</code>. Apart from being 2149 responsible for the generation of the runnable script, the 2150 <code>configure</code> script also provides functionality that is not 2151 easily expressed in the normal Autoconf framework. As part of this 2152 functionality, the generated script is called.</p> 2153 <p>The build system will detect if the Autoconf source files have 2154 changed, and will trigger a regeneration of the generated script if 2155 needed. You can also manually request such an update by 2156 <code>bash configure autogen</code>.</p> 2157 <p>In previous versions of the JDK, the generated script was checked in 2158 at <code>make/autoconf/generated-configure.sh</code>. This is no longer 2159 the case.</p> 2160 <h3 id="developing-the-build-system-itself">Developing the Build System 2161 Itself</h3> 2162 <p>This section contains a few remarks about how to develop for the 2163 build system itself. It is not relevant if you are only making changes 2164 in the product source code.</p> 2165 <p>While technically using <code>make</code>, the make source files of 2166 the JDK does not resemble most other Makefiles. Instead of listing 2167 specific targets and actions (perhaps using patterns), the basic modus 2168 operandi is to call a high-level function (or properly, macro) from the 2169 API in <code>make/common</code>. For instance, to compile all classes in 2170 the <code>jdk.internal.foo</code> package in the <code>jdk.foo</code> 2171 module, a call like this would be made:</p> 2172 <pre><code>$(eval $(call SetupJavaCompilation, BUILD_FOO_CLASSES, \ 2173 SETUP := GENERATE_OLDBYTECODE, \ 2174 SRC := $(TOPDIR)/src/jkd.foo/share/classes, \ 2175 INCLUDES := jdk/internal/foo, \ 2176 BIN := $(SUPPORT_OUTPUTDIR)/foo_classes, \ 2177 ))</code></pre> 2178 <p>By encapsulating and expressing the high-level knowledge of 2179 <em>what</em> should be done, rather than <em>how</em> it should be done 2180 (as is normal in Makefiles), we can build a much more powerful and 2181 flexible build system.</p> 2182 <p>Correct dependency tracking is paramount. Sloppy dependency tracking 2183 will lead to improper parallelization, or worse, race conditions.</p> 2184 <p>To test for/debug race conditions, try running 2185 <code>make JOBS=1</code> and <code>make JOBS=100</code> and see if it 2186 makes any difference. (It shouldn't).</p> 2187 <p>To compare the output of two different builds and see if, and how, 2188 they differ, run <code>$BUILD1/compare.sh -o $BUILD2</code>, where 2189 <code>$BUILD1</code> and <code>$BUILD2</code> are the two builds you 2190 want to compare.</p> 2191 <p>To automatically build two consecutive versions and compare them, use 2192 <code>COMPARE_BUILD</code>. The value of <code>COMPARE_BUILD</code> is a 2193 set of variable=value assignments, like this:</p> 2194 <pre><code>make COMPARE_BUILD=CONF=--enable-new-hotspot-feature:MAKE=hotspot</code></pre> 2195 <p>See <code>make/InitSupport.gmk</code> for details on how to use 2196 <code>COMPARE_BUILD</code>.</p> 2197 <p>To analyze build performance, run with <code>LOG=trace</code> and 2198 check <code>$BUILD/build-trace-time.log</code>. Use <code>JOBS=1</code> 2199 to avoid parallelism.</p> 2200 <p>Please check that you adhere to the <a 2201 href="http://openjdk.org/groups/build/doc/code-conventions.html">Code 2202 Conventions for the Build System</a> before submitting patches.</p> 2203 <h2 id="contributing-to-the-jdk">Contributing to the JDK</h2> 2204 <p>So, now you've built your JDK, and made your first patch, and want to 2205 contribute it back to the OpenJDK Community.</p> 2206 <p>First of all: Thank you! We gladly welcome your contribution. 2207 However, please bear in mind that the JDK is a massive project, and we 2208 must ask you to follow our rules and guidelines to be able to accept 2209 your contribution.</p> 2210 <p>The official place to start is the <a 2211 href="http://openjdk.org/contribute/">'How to contribute' page</a>. 2212 There is also an official (but somewhat outdated and skimpy on details) 2213 <a href="http://openjdk.org/guide/">Developer's Guide</a>.</p> 2214 <p>If this seems overwhelming to you, the Adoption Group is there to 2215 help you! A good place to start is their <a 2216 href="https://wiki.openjdk.org/display/Adoption/New+Contributor">'New 2217 Contributor' page</a>, or start reading the comprehensive <a 2218 href="https://adoptopenjdk.gitbooks.io/adoptopenjdk-getting-started-kit/en/">Getting 2219 Started Kit</a>. The Adoption Group will also happily answer any 2220 questions you have about contributing. Contact them by <a 2221 href="http://mail.openjdk.org/mailman/listinfo/adoption-discuss">mail</a> 2222 or <a href="http://openjdk.org/irc/">IRC</a>.</p> 2223 <h2 id="editing-this-document">Editing this document</h2> 2224 <p>If you want to contribute changes to this document, edit 2225 <code>doc/building.md</code> and then run 2226 <code>make update-build-docs</code> to generate the same changes in 2227 <code>doc/building.html</code>.</p> 2228 </body> 2229 </html> --- EOF ---