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