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