createMacosxDevkit.sh revision 1532:206dae1f6320
1#!/bin/bash
2#
3# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5#
6# This code is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License version 2 only, as
8# published by the Free Software Foundation.  Oracle designates this
9# particular file as subject to the "Classpath" exception as provided
10# by Oracle in the LICENSE file that accompanied this code.
11#
12# This code is distributed in the hope that it will be useful, but WITHOUT
13# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15# version 2 for more details (a copy is included in the LICENSE file that
16# accompanied this code).
17#
18# You should have received a copy of the GNU General Public License version
19# 2 along with this work; if not, write to the Free Software Foundation,
20# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21#
22# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23# or visit www.oracle.com if you need additional information or have any
24# questions.
25#
26
27# This script copies part of an Xcode installer into a devkit suitable
28# for building OpenJDK and OracleJDK. The installation .dmg files for Xcode
29# and the aux tools need to be available.
30# erik.joelsson@oracle.com
31
32USAGE="$0 <Xcode.dmg> <XQuartz.dmg> [<auxtools.dmg>]"
33
34if [ "$1" = "" ] || [ "$2" = "" ]; then
35    echo $USAGE
36    exit 1
37fi
38
39XCODE_DMG="$1"
40XQUARTZ_DMG="$2"
41AUXTOOLS_DMG="$3"
42
43SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)"
44BUILD_DIR="${SCRIPT_DIR}/../../build/devkit"
45
46# Mount XCODE_DMG
47if [ -e "/Volumes/Xcode" ]; then
48    hdiutil detach /Volumes/Xcode
49fi
50hdiutil attach $XCODE_DMG
51
52# Find the version of Xcode
53XCODE_VERSION="$(/Volumes/Xcode/Xcode.app/Contents/Developer/usr/bin/xcodebuild -version \
54    | awk '/Xcode/ { print $2 }' )"
55
56DEVKIT_ROOT="${BUILD_DIR}/Xcode${XCODE_VERSION}-devkit"
57DEVKIT_BUNDLE="${DEVKIT_ROOT}.tar.gz"
58
59echo "Xcode version: $XCODE_VERSION"
60echo "Creating devkit in $DEVKIT_ROOT"
61
62################################################################################
63# Copy files to root
64mkdir -p $DEVKIT_ROOT
65if [ ! -d $DEVKIT_ROOT/Xcode.app ]; then
66    echo "Copying Xcode.app..."
67    cp -RH "/Volumes/Xcode/Xcode.app" $DEVKIT_ROOT/
68fi
69# Trim out some seemingly unneeded parts to save space.
70rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Applications
71rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/iPhone*
72rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/Documentation
73rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/usr/share/man
74if [ -e $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk ]; then
75    rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
76    rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/share/man
77fi
78
79hdiutil detach /Volumes/Xcode
80
81################################################################################
82# Copy Freetype into sysroot
83if [ -e "/Volumes/XQuartz-*" ]; then
84    hdiutil detach /Volumes/XQuartz-*
85fi
86hdiutil attach $XQUARTZ_DMG
87
88echo "Copying freetype..."
89rm -rf /tmp/XQuartz
90pkgutil --expand /Volumes/XQuartz-*/XQuartz.pkg /tmp/XQuartz/
91rm -rf /tmp/x11
92mkdir /tmp/x11
93cd /tmp/x11
94cat /tmp/XQuartz-*/x11.pkg/Payload | gunzip -dc |cpio -i
95
96cp -RH opt/X11/include/freetype2 \
97    $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/
98cp -RH opt/X11/include/ft2build.h \
99    $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/
100cp -RH opt/X11/lib/libfreetype.* \
101    $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/
102
103cd -
104
105hdiutil detach /Volumes/XQuartz-*
106
107################################################################################
108# Optionally copy PackageMaker
109
110if [ -e "$AUXTOOLS_DMG" ]; then
111    if [ -e "/Volumes/Auxiliary Tools" ]; then
112        hdiutil detach "/Volumes/Auxiliary Tools"
113    fi
114    hdiutil attach $AUXTOOLS_DMG
115
116    echo "Copying PackageMaker.app..."
117    cp -RH "/Volumes/Auxiliary Tools/PackageMaker.app" $DEVKIT_ROOT/
118
119    hdiutil detach "/Volumes/Auxiliary Tools"
120fi
121
122################################################################################
123# Generate devkit.info
124
125echo-info() {
126    echo "$1" >> $DEVKIT_ROOT/devkit.info
127}
128
129echo "Generating devkit.info..."
130rm -f $DEVKIT_ROOT/devkit.info
131echo-info "# This file describes to configure how to interpret the contents of this devkit"
132echo-info "DEVKIT_NAME=\"Xcode $XCODE_VERSION (devkit)\""
133echo-info "DEVKIT_TOOLCHAIN_PATH=\"\$DEVKIT_ROOT/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:\$DEVKIT_ROOT/Xcode.app/Contents/Developer/usr/bin\""
134echo-info "DEVKIT_SYSROOT=\"\$DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk\""
135echo-info "DEVKIT_EXTRA_PATH=\"\$DEVKIT_ROOT/PackageMaker.app/Contents/MacOS:\$DEVKIT_TOOLCHAIN_PATH\""
136
137################################################################################
138# Copy this script
139
140echo "Copying this script..."
141cp $0 $DEVKIT_ROOT/
142
143################################################################################
144# Create bundle
145
146echo "Creating bundle..."
147(cd $DEVKIT_ROOT && tar c - . | gzip - > "$DEVKIT_BUNDLE")
148