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