xref: /trunk/main/solenv/bin/macosx-create-bundle (revision cdf0e10c)
1#!/bin/sh
2#*************************************************************************
3#
4# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5#
6# Copyright 2000, 2010 Oracle and/or its affiliates.
7#
8# OpenOffice.org - a multi-platform office productivity suite
9#
10# This file is part of OpenOffice.org.
11#
12# OpenOffice.org is free software: you can redistribute it and/or modify
13# it under the terms of the GNU Lesser General Public License version 3
14# only, as published by the Free Software Foundation.
15#
16# OpenOffice.org is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19# GNU Lesser General Public License version 3 for more details
20# (a copy is included in the LICENSE file that accompanied this code).
21#
22# You should have received a copy of the GNU Lesser General Public License
23# version 3 along with OpenOffice.org.  If not, see
24# <http://www.openoffice.org/license.html>
25# for a copy of the LGPLv3 License.
26#
27#*************************************************************************
28
29# Documentation
30# -------------
31#
32# The purpose of this script to take Mac OS X executables and shared libraries
33# and package them into the required Mac OS X bundle format.
34#
35# This script has the following usage:
36# 	macosx-create-bundle file1 [file2] ... [fileN]
37#
38# Note that file1 through fileN can in either of the following formats:
39# - A file name
40# - A file name and a directory to look for missing files. To use this option,
41#   use the following format:
42#     filename=directory
43#
44# The file argument is the file that you want to package into a Mac OS X
45# bundle. Currently, this script will only package executables and shared
46# libraries.
47#
48# The output for each executable will be a bundle named <file>.app and
49# the output for each shared library will be a symlink from libfoo.jnilib
50# back to libfoo.dylib.
51# These output directories will be in the same directory as the executable or
52# shared library.
53
54# Code
55# ----
56
57# Parse command line arguments
58if [ $# = 0 ]; then
59	printf "macosx-create-bundle: error: incorrect number of arguments\n" >&2
60	printf "Usage: macosx-create-bundle file1 [file2] ... [fileN]\n" >&2
61	exit 1
62fi
63
64while [ $# != 0 ]; do
65	inputfile=`echo "$1" | awk -F= '{print $1}'`
66	sourcedir=`echo "$1" | awk -F= '{print $2}'`
67
68	shift
69
70	inputfilename=`basename "$inputfile"`
71	outputdir=`dirname "$inputfile"`
72
73	solverlibdir="$SOLARVERSION/$INPATH/lib"
74	locallibdir="../../../../lib"
75
76	solverbindir="$SOLARVERSION/$INPATH/bin"
77	localbindir="../../.."
78
79	# Determine file type
80	filetype=`file -L "$inputfile"`
81
82	# Create bundle based on file type
83	if printf "$filetype" | grep -q 'Mach-O executable'; then
84
85		# Do nothing as this step is obsolete
86        :
87
88	elif printf "$filetype" | grep -q 'Mach-O dynamically linked shared library'; then
89		# Screen out lib\w+static libraries as they are not used directly
90		if ! printf "$inputfilename" | grep -q -x -E 'lib\w+static.*\.dylib'; then
91			# Create jnilib link
92			inputjnilibname="`basename $inputfilename .dylib`.jnilib"
93			if [ ! -L "$outputdir/$inputjnilibname" ]; then
94				rm -Rf "$outputdir/$inputjnilibname"
95			fi
96			# Link jnilib
97			ln -sf "$inputfilename" "$outputdir/$inputjnilibname"
98
99			#printf "macosx-create-bundle: $outputdir/$inputjnilibname successfully created\n"
100		fi
101	else
102		printf "macosx-create-bundle: error: file is not an executable or shared library.\n" >&2
103		exit 1
104	fi
105done
106