xref: /aoo42x/main/solenv/bin/macosx-create-bundle (revision c8ec31d6)
1cdf0e10cSrcweir#!/bin/sh
2e76eebc6SAndrew Rist#**************************************************************
3e76eebc6SAndrew Rist#
4e76eebc6SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
5e76eebc6SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
6e76eebc6SAndrew Rist#  distributed with this work for additional information
7e76eebc6SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
8e76eebc6SAndrew Rist#  to you under the Apache License, Version 2.0 (the
9e76eebc6SAndrew Rist#  "License"); you may not use this file except in compliance
10e76eebc6SAndrew Rist#  with the License.  You may obtain a copy of the License at
11e76eebc6SAndrew Rist#
12e76eebc6SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
13e76eebc6SAndrew Rist#
14e76eebc6SAndrew Rist#  Unless required by applicable law or agreed to in writing,
15e76eebc6SAndrew Rist#  software distributed under the License is distributed on an
16e76eebc6SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17e76eebc6SAndrew Rist#  KIND, either express or implied.  See the License for the
18e76eebc6SAndrew Rist#  specific language governing permissions and limitations
19e76eebc6SAndrew Rist#  under the License.
20e76eebc6SAndrew Rist#
21e76eebc6SAndrew Rist#**************************************************************
22cdf0e10cSrcweir
23cdf0e10cSrcweir# Documentation
24cdf0e10cSrcweir# -------------
25cdf0e10cSrcweir#
26cdf0e10cSrcweir# The purpose of this script to take Mac OS X executables and shared libraries
27cdf0e10cSrcweir# and package them into the required Mac OS X bundle format.
28cdf0e10cSrcweir#
29cdf0e10cSrcweir# This script has the following usage:
30cdf0e10cSrcweir# 	macosx-create-bundle file1 [file2] ... [fileN]
31cdf0e10cSrcweir#
32cdf0e10cSrcweir# Note that file1 through fileN can in either of the following formats:
33cdf0e10cSrcweir# - A file name
34cdf0e10cSrcweir# - A file name and a directory to look for missing files. To use this option,
35cdf0e10cSrcweir#   use the following format:
36cdf0e10cSrcweir#     filename=directory
37cdf0e10cSrcweir#
38cdf0e10cSrcweir# The file argument is the file that you want to package into a Mac OS X
39cdf0e10cSrcweir# bundle. Currently, this script will only package executables and shared
40cdf0e10cSrcweir# libraries.
41cdf0e10cSrcweir#
42cdf0e10cSrcweir# The output for each executable will be a bundle named <file>.app and
43cdf0e10cSrcweir# the output for each shared library will be a symlink from libfoo.jnilib
44cdf0e10cSrcweir# back to libfoo.dylib.
45cdf0e10cSrcweir# These output directories will be in the same directory as the executable or
46cdf0e10cSrcweir# shared library.
47cdf0e10cSrcweir
48cdf0e10cSrcweir# Code
49cdf0e10cSrcweir# ----
50cdf0e10cSrcweir
51cdf0e10cSrcweir# Parse command line arguments
52cdf0e10cSrcweirif [ $# = 0 ]; then
53cdf0e10cSrcweir	printf "macosx-create-bundle: error: incorrect number of arguments\n" >&2
54cdf0e10cSrcweir	printf "Usage: macosx-create-bundle file1 [file2] ... [fileN]\n" >&2
55cdf0e10cSrcweir	exit 1
56cdf0e10cSrcweirfi
57cdf0e10cSrcweir
58cdf0e10cSrcweirwhile [ $# != 0 ]; do
59cdf0e10cSrcweir	inputfile=`echo "$1" | awk -F= '{print $1}'`
60cdf0e10cSrcweir	sourcedir=`echo "$1" | awk -F= '{print $2}'`
61cdf0e10cSrcweir
62cdf0e10cSrcweir	shift
63cdf0e10cSrcweir
64cdf0e10cSrcweir	inputfilename=`basename "$inputfile"`
65cdf0e10cSrcweir	outputdir=`dirname "$inputfile"`
66cdf0e10cSrcweir
67cdf0e10cSrcweir	solverlibdir="$SOLARVERSION/$INPATH/lib"
68cdf0e10cSrcweir	locallibdir="../../../../lib"
69cdf0e10cSrcweir
70cdf0e10cSrcweir	solverbindir="$SOLARVERSION/$INPATH/bin"
71cdf0e10cSrcweir	localbindir="../../.."
72cdf0e10cSrcweir
73cdf0e10cSrcweir	# Determine file type
74cdf0e10cSrcweir	filetype=`file -L "$inputfile"`
75cdf0e10cSrcweir
76cdf0e10cSrcweir	# Create bundle based on file type
77*c8ec31d6SHerbert Dürr	if printf "$filetype" | grep -q 'Mach-O.* executable'; then
78cdf0e10cSrcweir
79cdf0e10cSrcweir		# Do nothing as this step is obsolete
80cdf0e10cSrcweir        :
81cdf0e10cSrcweir
82*c8ec31d6SHerbert Dürr	elif printf "$filetype" | grep -q 'Mach-O.* dynamically linked shared library'; then
83cdf0e10cSrcweir		# Screen out lib\w+static libraries as they are not used directly
84cdf0e10cSrcweir		if ! printf "$inputfilename" | grep -q -x -E 'lib\w+static.*\.dylib'; then
85cdf0e10cSrcweir			# Create jnilib link
86cdf0e10cSrcweir			inputjnilibname="`basename $inputfilename .dylib`.jnilib"
87cdf0e10cSrcweir			if [ ! -L "$outputdir/$inputjnilibname" ]; then
88cdf0e10cSrcweir				rm -Rf "$outputdir/$inputjnilibname"
89cdf0e10cSrcweir			fi
90cdf0e10cSrcweir			# Link jnilib
91cdf0e10cSrcweir			ln -sf "$inputfilename" "$outputdir/$inputjnilibname"
92cdf0e10cSrcweir
93cdf0e10cSrcweir			#printf "macosx-create-bundle: $outputdir/$inputjnilibname successfully created\n"
94cdf0e10cSrcweir		fi
95cdf0e10cSrcweir	else
96659ed23bSHerbert Dürr		printf "macosx-create-bundle: error: \"$inputfile\" is not an executable or shared library.\n" >&2
97cdf0e10cSrcweir		exit 1
98cdf0e10cSrcweir	fi
99cdf0e10cSrcweirdone
100