createMacosxDevkit.sh revision 1727:d0f163fcd4c8
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> <gnu make binary> [<auxtools.dmg>]"
33
34if [ "$1" = "" ] || [ "$2" = "" ]; then
35    echo $USAGE
36    exit 1
37fi
38
39XCODE_DMG="$1"
40XQUARTZ_DMG="$2"
41GNU_MAKE="$3"
42AUXTOOLS_DMG="$4"
43
44SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)"
45BUILD_DIR="${SCRIPT_DIR}/../../build/devkit"
46
47# Mount XCODE_DMG
48if [ -e "/Volumes/Xcode" ]; then
49    hdiutil detach /Volumes/Xcode
50fi
51hdiutil attach $XCODE_DMG
52
53# Find the version of Xcode
54XCODE_VERSION="$(/Volumes/Xcode/Xcode.app/Contents/Developer/usr/bin/xcodebuild -version \
55    | awk '/Xcode/ { print $2 }' )"
56SDK_VERSION="MacOSX10.9"
57if [ ! -e "/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/${SDK_VERSION}.sdk" ]; then
58    echo "Expected SDK version not found: ${SDK_VERSION}"
59    exit 1
60fi
61
62DEVKIT_ROOT="${BUILD_DIR}/Xcode${XCODE_VERSION}-${SDK_VERSION}"
63DEVKIT_BUNDLE="${DEVKIT_ROOT}.tar.gz"
64
65echo "Xcode version: $XCODE_VERSION"
66echo "Creating devkit in $DEVKIT_ROOT"
67
68################################################################################
69# Copy files to root
70mkdir -p $DEVKIT_ROOT
71if [ ! -d $DEVKIT_ROOT/Xcode.app ]; then
72    echo "Copying Xcode.app..."
73    cp -RH "/Volumes/Xcode/Xcode.app" $DEVKIT_ROOT/
74fi
75# Trim out some seemingly unneeded parts to save space.
76rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Applications
77rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/iPhone*
78rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/Documentation
79rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/usr/share/man
80( cd $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs \
81    && rm -rf `ls | grep -v ${SDK_VERSION}` )
82rm -rf $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/${SDK_VERSION}.sdk/usr/share/man
83
84hdiutil detach /Volumes/Xcode
85
86################################################################################
87# Copy Freetype into sysroot
88if [ -e "/Volumes/XQuartz-*" ]; then
89    hdiutil detach /Volumes/XQuartz-*
90fi
91hdiutil attach $XQUARTZ_DMG
92
93echo "Copying freetype..."
94rm -rf /tmp/XQuartz
95pkgutil --expand /Volumes/XQuartz-*/XQuartz.pkg /tmp/XQuartz/
96rm -rf /tmp/x11
97mkdir /tmp/x11
98cd /tmp/x11
99cat /tmp/XQuartz/x11.pkg/Payload | gunzip -dc | cpio -i
100
101mkdir -p $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/X11/include/
102mkdir -p $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/X11/lib/
103cp -RH opt/X11/include/freetype2 \
104    $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/X11/include/
105cp -RH opt/X11/include/ft2build.h \
106    $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/X11/include/
107cp -RH opt/X11/lib/libfreetype.* \
108    $DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/X11/lib/
109
110cd -
111
112hdiutil detach /Volumes/XQuartz-*
113
114################################################################################
115# Copy gnu make
116mkdir -p $DEVKIT_ROOT/bin
117cp $GNU_MAKE $DEVKIT_ROOT/bin
118
119################################################################################
120# Optionally copy PackageMaker
121
122if [ -e "$AUXTOOLS_DMG" ]; then
123    if [ -e "/Volumes/Auxiliary Tools" ]; then
124        hdiutil detach "/Volumes/Auxiliary Tools"
125    fi
126    hdiutil attach $AUXTOOLS_DMG
127
128    echo "Copying PackageMaker.app..."
129    cp -RH "/Volumes/Auxiliary Tools/PackageMaker.app" $DEVKIT_ROOT/
130
131    hdiutil detach "/Volumes/Auxiliary Tools"
132fi
133
134################################################################################
135# Generate devkit.info
136
137echo-info() {
138    echo "$1" >> $DEVKIT_ROOT/devkit.info
139}
140
141echo "Generating devkit.info..."
142rm -f $DEVKIT_ROOT/devkit.info
143echo-info "# This file describes to configure how to interpret the contents of this devkit"
144echo-info "# The parameters used to create this devkit were:"
145echo-info "# $*"
146echo-info "DEVKIT_NAME=\"Xcode $XCODE_VERSION (devkit)\""
147echo-info "DEVKIT_TOOLCHAIN_PATH=\"\$DEVKIT_ROOT/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:\$DEVKIT_ROOT/Xcode.app/Contents/Developer/usr/bin\""
148echo-info "DEVKIT_SYSROOT=\"\$DEVKIT_ROOT/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk\""
149echo-info "DEVKIT_EXTRA_PATH=\"\$DEVKIT_ROOT/bin:\$DEVKIT_ROOT/PackageMaker.app/Contents/MacOS:\$DEVKIT_TOOLCHAIN_PATH\""
150
151################################################################################
152# Copy this script
153
154echo "Copying this script..."
155cp $0 $DEVKIT_ROOT/
156
157################################################################################
158# Create bundle
159
160echo "Creating bundle..."
161(cd $DEVKIT_ROOT && tar c - . | gzip - > "$DEVKIT_BUNDLE")
162