summaryrefslogtreecommitdiff
path: root/solenv/bin/macosx-create-bundle
blob: ba7d624e68f3275c4146cf30ec940de31235f2c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# 
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org.  If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************

# Documentation
# -------------
#
# The purpose of this script to take Mac OS X executables and shared libraries
# and package them into the required Mac OS X bundle format.
#
# This script has the following usage:
# 	macosx-create-bundle file1 [file2] ... [fileN]
#
# Note that file1 through fileN can in either of the following formats:
# - A file name
# - A file name and a directory to look for missing files. To use this option,
#   use the following format:
#     filename=directory
#
# The file argument is the file that you want to package into a Mac OS X
# bundle. Currently, this script will only package executables and shared
# libraries.
#
# The output for each executable will be a bundle named <file>.app and
# the output for each shared library will be a symlink from libfoo.jnilib 
# back to libfoo.dylib.
# These output directories will be in the same directory as the executable or
# shared library.

# Code
# ----

# Parse command line arguments
if [ $# = 0 ]; then
	printf "macosx-create-bundle: error: incorrect number of arguments\n" >&2
	printf "Usage: macosx-create-bundle file1 [file2] ... [fileN]\n" >&2
	exit 1
fi

while [ $# != 0 ]; do
	inputfile=`echo "$1" | awk -F= '{print $1}'`
	sourcedir=`echo "$1" | awk -F= '{print $2}'`

	shift

	inputfilename=`basename "$inputfile"`
	outputdir=`dirname "$inputfile"`

	solverlibdir="$SOLARVERSION/$INPATH/lib"
	locallibdir="../../../../lib"

	solverbindir="$SOLARVERSION/$INPATH/bin"
	localbindir="../../.."

	# Determine file type
	filetype=`file -L "$inputfile"`

	# Create bundle based on file type
	if printf "$filetype" | grep -q 'Mach-O executable'; then

		# Do nothing as this step is obsolete
        :

	elif printf "$filetype" | grep -q 'Mach-O dynamically linked shared library'; then
		# Screen out lib\w+static libraries as they are not used directly
		if ! printf "$inputfilename" | grep -q -x -E 'lib\w+static.*\.dylib'; then
			# Create jnilib link
			inputjnilibname="`basename $inputfilename .dylib`.jnilib"
			if [ ! -L "$outputdir/$inputjnilibname" ]; then
				rm -Rf "$outputdir/$inputjnilibname"
			fi
			# Link jnilib
			ln -sf "$inputfilename" "$outputdir/$inputjnilibname"

			printf "macosx-create-bundle: $outputdir/$inputjnilibname successfully created\n"
		fi
	else
		printf "macosx-create-bundle: error: file is not an executable or shared library.\n" >&2
		exit 1
	fi
done