1#!/bin/bash
2#
3# Copyright (c) 2015, 2018, 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 creates a devkit for building OpenJDK on Solaris by copying
28# part of a Solaris Studio installation and cretaing a sysroot by installing
29# a limited set of system packages. It is assumed that a suitable pkg
30# publisher is configured for the system where the script is executed.
31#
32# Note that you will need to be able to sudo to root to run the pkg install
33# part of this script. It should not affect the running system, but only
34# install in a separate temporary image.
35#
36# The Solaris Studio installation must contain at least these packages:
37#developer/developerstudio-126/backend                12.6-1.0.0.1
38#developer/developerstudio-126/c++                    12.6-1.0.2.0
39#developer/developerstudio-126/cc                     12.6-1.0.1.0
40#developer/developerstudio-126/dbx                    12.6-1.0.0.1
41#developer/developerstudio-126/library/c++-libs       12.6-1.0.2.0
42#developer/developerstudio-126/library/c-libs         12.6-1.0.0.1
43#developer/developerstudio-126/library/f90-libs       12.6-1.0.0.1
44#developer/developerstudio-126/library/math-libs      12.6-1.0.0.1
45#developer/developerstudio-126/library/studio-gccrt   12.6-1.0.0.1
46#developer/developerstudio-126/studio-common          12.6-1.0.0.1
47#developer/developerstudio-126/studio-ja              12.6-1.0.0.1
48#developer/developerstudio-126/studio-legal           12.6-1.0.0.1
49#developer/developerstudio-126/studio-zhCN            12.6-1.0.0.1
50#
51# erik.joelsson@oracle.com
52
53USAGE="$0 <Solaris Studio installation>"
54
55if [ "$1" = "" ]; then
56  echo $USAGE
57  exit 1
58fi
59
60SOLARIS_STUDIO_VERSION=12u6
61SOLARIS_VERSION=11u3
62SOLARIS_ENTIRE_VERSION=0.5.11-0.175.3.20.0.6.0
63case `uname -p` in
64  i*)
65    ARCH=x86
66    ;;
67  sparc*)
68    ARCH=sparc
69    ;;
70esac
71
72SOLARIS_STUDIO_SRC=$1
73
74SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)"
75BUILD_DIR="${SCRIPT_DIR}/../../build/devkit"
76
77DEVKIT_NAME=SS${SOLARIS_STUDIO_VERSION}-Solaris${SOLARIS_VERSION}
78DEVKIT_ROOT=${BUILD_DIR}/${DEVKIT_NAME}
79BUNDLE_NAME=${DEVKIT_NAME}.tar.gz
80BUNDLE=${BUILD_DIR}/${BUNDLE_NAME}
81INSTALL_ROOT=${BUILD_DIR}/install-root-$SOLARIS_VERSION
82SYSROOT=${DEVKIT_ROOT}/sysroot
83SOLARIS_STUDIO_SUBDIR=SS${SOLARIS_STUDIO_VERSION}
84SOLARIS_STUDIO_DIR=${DEVKIT_ROOT}/${SOLARIS_STUDIO_SUBDIR}
85
86# Extract the publisher from the system
87if [ -z "${PUBLISHER_URI}" ]; then
88  PUBLISHER_URI="$(pkg publisher solaris | grep URI | awk '{ print $3 }')"
89fi
90
91if [ ! -d $INSTALL_ROOT ]; then
92  echo "Creating $INSTALL_ROOT and installing packages"
93  pkg image-create $INSTALL_ROOT
94  pkg -R $INSTALL_ROOT set-publisher -P -g ${PUBLISHER_URI} solaris
95  sudo pkg -R $INSTALL_ROOT install --accept entire@$SOLARIS_ENTIRE_VERSION \
96      system/install developer/gnu-binutils system/library/mmheap system/picl \
97      developer/assembler system/library/freetype-2
98else
99  echo "Skipping installing packages"
100fi
101
102if [ ! -d $SYSROOT ]; then
103  echo "Copying from $INSTALL_ROOT to $SYSROOT"
104  mkdir -p $SYSROOT
105  cp -rH $INSTALL_ROOT/lib $SYSROOT/
106  mkdir $SYSROOT/usr
107  cp -rH $INSTALL_ROOT/usr/lib $SYSROOT/usr/
108  cp -rH $INSTALL_ROOT/usr/include $SYSROOT/usr/
109  pkg -R $INSTALL_ROOT list > $SYSROOT/pkg-list.txt
110else
111  echo "Skipping copying to $SYSROOT"
112fi
113
114if [ ! -d $DEVKIT_ROOT/tools ]; then
115  # Some of the tools in sysroot are needed in the OpenJDK build. We need
116  # to copy them into a tools dir, including their specific libraries.
117  mkdir -p $DEVKIT_ROOT/tools/usr/bin $DEVKIT_ROOT/tools/lib/sparcv9 \
118      $DEVKIT_ROOT/tools/usr/gnu/bin $DEVKIT_ROOT/tools/usr/bin/sparcv9
119  cp $INSTALL_ROOT/usr/bin/{as,ar,nm,strip,ld,pigz,ldd} \
120       $DEVKIT_ROOT/tools/usr/bin/
121  cp $INSTALL_ROOT/usr/sbin/dtrace $DEVKIT_ROOT/tools/usr/bin/
122  cp $INSTALL_ROOT/usr/sbin/sparcv9/dtrace $DEVKIT_ROOT/tools/usr/bin/sparcv9/
123  cp -rH $INSTALL_ROOT/usr/gnu/bin/* $DEVKIT_ROOT/tools/usr/gnu/bin/
124  cp $INSTALL_ROOT/lib/sparcv9/{libelf.so*,libld.so*,liblddbg.so*} $DEVKIT_ROOT/tools/lib/sparcv9/
125  for t in $(ls $DEVKIT_ROOT/tools/usr/gnu/bin); do
126    if [ -f $DEVKIT_ROOT/tools/usr/gnu/bin/$t ]; then
127      ln -s ../gnu/bin/$t $DEVKIT_ROOT/tools/usr/bin/g$t
128    fi
129  done
130else
131  echo "Skipping copying to tools dir $DEVKIT_ROOT/tools"
132fi
133
134if [ ! -d $SOLARIS_STUDIO_DIR ]; then
135  echo "Copying Solaris Studio from $SOLARIS_STUDIO_SRC"
136  mkdir -p ${SOLARIS_STUDIO_DIR}
137  cp -rH $SOLARIS_STUDIO_SRC/. ${SOLARIS_STUDIO_DIR}/
138  # Solaris Studio 12.6 requires libmmheap.so.1 and libsunmath.so.1 to run, but
139  # these libs are not installed by default on all Solaris systems.
140  # Sneak them in from the sysroot to make it run OOTB on more systems.
141  cp $SYSROOT/lib/libsunmath.so.1 $SOLARIS_STUDIO_DIR/lib/compilers/sys/
142  cp $SYSROOT/lib/sparcv9/libsunmath.so.1 $SOLARIS_STUDIO_DIR/lib/compilers/sys/sparcv9/
143  cp $SYSROOT/lib/libmmheap.so.1 $SOLARIS_STUDIO_DIR/lib/compilers/sys/
144  cp $SYSROOT/lib/sparcv9/libmmheap.so.1 $SOLARIS_STUDIO_DIR/lib/compilers/sys/sparcv9/
145else
146  echo "Skipping copying of Solaris Studio"
147fi
148
149# Create the devkit.info file
150echo Creating devkit.info
151INFO_FILE=$DEVKIT_ROOT/devkit.info
152rm -f $INFO_FILE
153echo "# This file describes to configure how to interpret the contents of this devkit" >> $INFO_FILE
154echo "DEVKIT_NAME=\"Solaris Studio $SOLARIS_STUDIO_VERSION - Solaris $SOLARIS_VERSION - $ARCH\"" >> $INFO_FILE
155echo "DEVKIT_TOOLCHAIN_PATH=\"\$DEVKIT_ROOT/$SOLARIS_STUDIO_SUBDIR/bin:\$DEVKIT_ROOT/bin\"" >> $INFO_FILE
156echo "DEVKIT_EXTRA_PATH=\"\$DEVKIT_ROOT/tools/usr/bin\"" >> $INFO_FILE
157echo "DEVKIT_SYSROOT=\"\$DEVKIT_ROOT/sysroot\"" >> $INFO_FILE
158
159if [ ! -e $BUNDLE ]; then
160  GZIP=$(command -v pigz)
161  if [ -z "$GZIP" ]; then
162    GZIP="gzip"
163  fi
164  echo "Creating $BUNDLE from $DEVKIT_ROOT"
165  (cd $DEVKIT_ROOT && tar cf - . | $GZIP - > "$BUNDLE")
166else
167  echo "Skipping creation of $BUNDLE"
168fi
169