Compile environment

The environment that

Ubuntu 20.04.1 LTS

OpenJDK jdk8-b120

Note: Ubuntu configures apt installation source as Ali source to improve loading speed

Setup Setup apt install Ariyuan

  1. Set apt to install Ariyuan
sudo cp /ect/apt/sources.list /etc/apt/sources.list.bak
Copy the code
  1. Add Ali source
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted  universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverseCopy the code
  1. Update the source
sudo apt-get update
sudo apt-get upgrade
Copy the code

Download the JDK source code locally

Openjdk.java.net/ github source address: github.com/openjdk/ my download address: gitee.com/zhengsh/jdk

Download command:

#I have synchronized openJDK code to Gitee because github domestic network is too slow
~/javawork$ git clone https://gitee.com/zhengsh/jdk.git
Copy the code

compiling

  1. Install the open – JDK – 8

    sudo apt-get install openjdk-8-jdk
    Copy the code
  2. Compile the code

    #compiling
    bash ./configure
    Copy the code
  3. Configure: error: Cannot find GNU make 3.81 or newer! Please put it in the path, or add e.g. MAKE=/opt/gmake3.81/ MAKE as argument to configure

    #My make is not installed
    sudo apt-get install make
    
    #If other tips you can refer to the Java bug https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8027567
    Copy the code
  4. Configure: error: Could not find a C compiler. You might be able to fix this by running ‘sudo apt-get install build-essential’.

    #Install the build - essential
    sudo apt-get install build-essential
    Copy the code
  5. Configure: error: Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). You might be able to fix this by running ‘sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev’.

    #Install libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev
    #Note that libx11-dev's X is lowercase
    sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev
    Copy the code
  6. Configure: error: Could not find cups! You might be able to fix this by running ‘sudo apt-get install libcups2-dev’.

    #Install libcups2 - dev
    sudo apt-get install libcups2-dev
    Copy the code
  7. Configure: error: Could not find freetype! Configure: Error: Could not find freetype! You might be able to fix this by running ‘sudo apt-get install libfreetype6-dev’.

    #Install libfreetype6 - dev
    sudo apt-get install libfreetype6-dev
    Copy the code
  8. Configure: error: Could not find alsa! Configure: Error: Could not find alsa! You might be able to fix this by running ‘sudo apt-get install libasound2-dev’.

    #Install libasound2 - dev
    sudo apt-get install libasound2-dev
    Copy the code
  9. Successful tip

    Tools summary: * Boot JDK: Openjdk version "1.8.0_275" OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1-20.04-b01 Server VM (build 25.275-b01, mixed mode) (at /usr/lib/jvm/java-8-openJDK-amd64) * C Compiler: X86_64-linux-gnu -gcc-9 (Ubuntu 9.3.0-17ubuntu1-20.04) version 9.3.0 (at /usr/bin/x86_64-linux-gnu-gcc-9) * C++ Compiler: X86_64 -linux-gnu-g++-9 (Ubuntu 9.3.0-17ubuntu1-20.04) version 9.3.0 (at /usr/bin/x86_64-linux-gnu-g++-9) Build performance summary: * Cores to use: 1 * Memory limit: 3936 MB * ccache status: not installed (consider installing) Build performance tip: ccache gives a tremendous speedup for C++ recompilations. You do not have ccache installed. Try installing it. You might  be able to fix this by running 'sudo apt-get install ccache'.Copy the code
  10. make all

    #Error message, (solution lowers GCC version)
    make[6]: *** [/home/zsh/javawork/jdk/hotspot/make/linux/makefiles/vm.make:297: precompiled.hpp.gch] Error 1
    make[5]: *** [/home/zsh/javawork/jdk/hotspot/make/linux/makefiles/top.make:119: the_vm] Error 2
    make[4]: *** [/home/zsh/javawork/jdk/hotspot/make/linux/Makefile:289: product] Error 2
    make[3]: *** [Makefile:217: generic_build2] Error 2
    make[2]: *** [Makefile:167: product] Error 2
    make[1]: *** [HotspotWrapper.gmk:45: /home/zsh/javawork/jdk/build/linux-x86_64-normal-server-release/hotspot/_hotspot.timestamp] Error 2
    make: *** [/home/zsh/javawork/jdk//make/Main.gmk:109: hotspot-only] Error 2
    
    # gcc --versionGCC (Ubuntu 9.3.0-17Ubuntu1-20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is Free Software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    #Install GCC 4.8 g + + 4.8Sudo apt-get install -y GCC -4.8 sudo apt-get install -y g++-4.8
    #Re-establish the soft connectionRun the following command to run the /usr/bin directory: sudo rm -r GCC -sf gcc4.8 GCC -r g++ sudo ln -sf G + + 4.8 g + +
    #Query the GCC version againGCC --version GCC (Ubuntu 4.8.5-4Ubuntu 8) 4.8.5 Copyright (C) 2015 Free Software Foundation, Inc. This is Free Software;  see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Copy the code

    Make all Success message is displayed

    ----- Build times -------
    Start 2020-12-12 22:17:38
    End   2020-12-12 22:51:31
    00:00:54 corba
    00:01:03 demos
    00:04:57 docs
    00:16:08 hotspot
    00:01:06 images
    00:00:35 jaxp
    00:01:05 jaxws
    00:06:49 jdk
    00:00:54 langtools
    00:00:21 nashorn
    00:33:53 TOTAL
    -------------------------
    Finished building OpenJDK for target 'all'
    
    Copy the code

Compile successfully

CD/javawork/JDK/build/Linux - x86_64 - normal - server - release/JDK/bin/Java version # to compile its success its version"1.8.0 comes with - internal"
    OpenJDK Runtime Environment (build 1.8. 0-internal-zsh_2020_12_12_22_17-b00)
    OpenJDK 64-Bit Server VM (build 25.0-b62, mixed mode)
Copy the code

conclusion

  1. In fact, I didn’t read the special tutorial, so I referred to the OpenJdkREADMEThe file is then combined with prompts to solve the problem Google solves the problem.
  2. System requirements: It is recommended that the VM use 4 cores and 8 GB memory. Otherwise, the process takes a long time.
  3. This is all at the setup level, and I’ll continue to refine the notes on OpenJDK