How to perfectly compile OpenJDK with Mac 7

Source: Internet
Author: User
Tags echo message

The previous time in order to study the JVM, so went down the OpenJDK6 compiled a, because less sound card driver, and did not find how to solve, the results are always compiled unsuccessful, then give up. But recently debugging JDK source code, found a lot of debugging information is not, see my that hard ah. Just a friend successfully compiled OpenJDK7, I went to a trial, although under the success of CentOS, but I do not use the Mac, so I spent a little time again in the Mac to get once again. Overall is still smooth, now has been very happy to use.


1. It is important to select OS X version.

At present, my Mac version is 10.10, initially did not think so much, the configuration of the necessary information after the beginning of the compilation, the result is full screen error. A simple look after the discovery is compiled c file when the parameter is wrong, so check a bit, just know is LLVM version is too new, incompatible with the low version of some of the compilation parameters, specific can see this article http://yueyemaitian.iteye.com/blog/2038304 The 8th. I've changed the code, but it still compiles. At this time I think of a very simple way, since the high version is not possible, I will install a low version of the chant. Since the latest OS X cannot be installed in the lower version of Xcode (with Xcode installed LLVM), so go to a 10.8 OS X installed in the virtual machine, and then install a Xcode4.4, the address is appended.

After installing Xcode, you should manually download the LLVM installation. Open Xcode, create an empty project, then open preferences and find a place to start the installation as shown below (because I've already installed it, so it's installed)


The first step is to get this done.


2. Installing X11

The X11 is a graphics system used by the UNIX-based OS, and 10.8 of the previous OS X is self-bringing, but not since. For Mac, you need to install Xquartz, this has no version limit, go online under the latest version can. The reason for this is that the following error occurred while compiling the Policytools:

ld: library not found for -lX11

The back of this https://github.com/hgomez/obuildfactory/wiki/Building-and-Packaging-OpenJDK7-for-OSX to think about trying to install Xquartz to solve the problem.

To establish a soft connection for X11 after installation

sudo ln -s /usr/X11/include/X11 /usr/include/X11


3. Installing FreeType

A friend who compiles openjdk under Linux may have encountered a requirement to install FreeType, and then install and add the installation directory to the environment variable. But OS X is not the same, FreeType is not practical to install separately. Although the individual installation can let the pre-compilation check pass, but to the back still error, as for the reason I did not find. What about that? In fact, if the installation of X11,freetype is installed together, we can go to the X11 directory to see if there is freetype.

Although the installation of X11 comes with FreeType, the following error may occur during compilation:

error: freetype/config/ftheader.h: No such file or directory
is actually a directory problem, execute the following command is good:

sudo ln -s /usr/X11/include/freetype2/freetype/ /usr/X11/include/freetype

4. Configure Environment variables

OS x's environment variable configuration is relatively much simpler than compiling under Linux. You only need to configure the directories for the JDK and LLVM you need to compile.

Because many of the source code is compiled with native JDK, it is necessary to preinstall a lower version of the JDK, where we need to install JDK6. Once installed, locate the installation directory and add the following environment variables:

Export Alt_bootdir=/system/library/java/javavirtualmachines/1.6.0.jdk/contents/home
Typically, the installation directory should be in the/system/library/java/javavirtualmachines directory. If not, there is a trick to find. Since the JDK is installed, the system automatically creates a soft connection to the Java command under/usr/bin, so Execute "ls-l/usr/bin/java" to see where the command is pointing, and then follow along to find it.

LLVM is required to compile a class C file, so add its directory to the environment variable. Normally OS X installs the app to move the app to the applications directory, so when I first installed Xcode, I also moved him in, and if you put Xcode in a different directory, you can find the corresponding directory.

Export Alt_compiler_path=/applications/xcode.app/contents/developer/usr/bin

5. Get the compiled source code

According to the above 3rd get source code https://blogs.oracle.com/arungupta/entry/build_open_jdk_7_on if not installed HG need to self-install


Until now, the pre-compilation preparation has been completed. We can perform the pre-compilation check before make sanity. If the check passes, first look at the specific compile command:

Make Allow_downloads=true sa_apple_boot_java=true skip_debug_build=false skip_fastdebug_build=false ALWAYS_PASS_ Test_gamma=true hotspot_build_jobs= ' Sysctl-n hw.ncpu '
Here are two questions:

A. allow_downloads=true indicates that the download is allowed during compilation. Because some compiled modules, such as JAXP, are specified in the compilation script to download specific packages. Although I have not tried setting false will not affect the compilation, but it is recommended to set to true. But this brings another problem, download this kind of package is very time, sometimes will be in that card for a long time, so I found in the compilation script to control the download of the specific command, modify the changes and put the corresponding packet under the Thunderbolt into the correct directory, and then recompile again, you can successfully pass. I'll say it in detail later.

B. Skip_debug_build=false Skip_fastdebug_build=false These two indicate whether the compiled JDK or hotspot can be DEBUG. Fastdebug is supposed to provide a simple debug function, and if you want full debug, the Skip_debug_build must be set to false. But here is a reminder, if you want to debug JDK can see the debug information, such as variable name, only need to skip_fastdebug_build set to False

If neither of these issues is a problem, then you can press ENTER. If Debug and Fastdebug are both false and compiled with a virtual machine, the time will be longer, and you may need to find a longer movie to kill. The result of the final compilation is this:



J2sdk-image is your own compiled JDK, you can use it directly. As for the contents of the other catalogue, let's figure it out for you.


Now for the next allow_downloads=true problem.


How many packages to download during compilation I'm not sure, but I personally encountered a total of three downloads for a long time:

Jaxp145_01.zip, Jdk7-jaf-2010_08_19.zip, Jdk7-jaxws2_2_4-b03-2011_05_27.zip

As I said before, we can modify the compilation script to skip the download and use what we have already downloaded, but the actual compilation process, the three packages corresponding to the compilation script is generated dynamically, so you can only wait until he stuck there, to stop and find the script to modify it. So because of these three packages, we need to stop 3 times altogether. It's a bit sore, but it's a lot better than sticking around all the time.


Suppose we compile a normal version, that is, non-debug and non-fastdebug. Here's an example of how to modify the script for Jaxp145_01.zip:

Script location: openjdk root directory/build/macosx-universal/jaxp/build/xml_generated/build-drop-jaxp_src.xml

Find the following section:

<!--Download bundles from a URL. --><target name= "-jaxp_src-url-bundle"    depends= "init,-jaxp_src-ready,-jaxp_src-url-should-be-used"        if= "jaxp_src.url.should.be.used"        unless= "Jaxp_src.ready" >    <echo message= "downloading from ${ Jaxp_src.master.bundle.url} "/>    <dirname property=" Jaxp_src.bundle.dirname "file=" ${jaxp_ Src.bundle.copy} "/>    <mkdir dir=" ${jaxp_src.bundle.dirname} "/>    <delete file=" ${jaxp_ Src.bundle.copy}.temp "/>    <delete file=" ${jaxp_src.bundle.copy} "/>    <get src=" ${jaxp_ Src.master.bundle.url} "dest=" ${jaxp_src.bundle.copy}.temp "/>    <move file=" ${jaxp_src.bundle.copy}.temp "Tofile=" ${jaxp_src.bundle.copy} "/>    <property name=" Jaxp_src.master.bundle.found "value=" true "/> </target>
It is clear that the Get command on line fourth shows that the package is downloaded from a URL, and that a. temp file is created, and then the. Temp is removed when the download is finished. So let's change the text to the following:

<!-- Download bundles from a URL. --><target name= "-jaxp_src-url-bundle" depends= "Init,-jaxp_src-ready,-jaxp_src-url-should-be-used" if= "J Axp_src.url.should.be.used "unless=" Jaxp_src.ready "> <echo message=" Downloading from ${jaxp_src.master.bun Dle.url} "/> <dirname property=" jaxp_src.bundle.dirname "file=" ${jaxp_src.bundle.copy} "/> <mkdir dir=" ${  Jaxp_src.bundle.dirname} "/> <!--<delete file=" ${jaxp_src.bundle.copy}.temp "/>-<!--<delete File= "${jaxp_src.bundle.copy}"/>-<!--<get src= "${jaxp_src.master.bundle.url}" dest= "${jaxp_ Src.bundle.copy}.temp "/>-<!--<move file=" ${jaxp_src.bundle.copy}.temp "tofile=" ${jaxp_ Src.bundle.copy} "/>--<property name=" Jaxp_src.master.bundle.found "value=" true "/></target> 
The reason to comment out the two-line delete is to avoid deleting the package we put in when compiling.


After the script is modified, download the corresponding package and put it in the corresponding directory. Addresses for Jaxp145_01.zip are:

OPENJDK root directory/build/macosx-universal/jaxp/drop/bundles


Finally recompile, this section will pass smoothly. The other two packages are the same, and you can modify and recompile with this example.




--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------

Resources:

OS X10.8 and Xcode4.4 http://mac.pcbeta.com/thread-91877-1-1.html

LLVM compilation failure due to high version http://yueyemaitian.iteye.com/blog/2038304

compiling versions of OpenJDK Https://github.com/hgomez/obuildfactory/wiki in Linux and OS X environments

ftheader.h not found (i.e. FreeType path problem)http://luchanghong.com/python/2012/07/24/ Compile-captchaimage-error-cause-freetype-could-not-found.html


How to perfectly compile OpenJDK with Mac 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.