Create a MacOS X App Bundle Using MacPorts

From Octave
Jump to navigation Jump to search

Install MacPorts

MacPorts, formerly called DarwinPorts, is a package management system that simplifies the installation of software on the MacOS X and Darwin operating systems. It is a free/open source software project to simplify installation of other free/open source software. Similar in aim and function to Fink and the BSDs' ports collections, DarwinPorts was started in 2002 as part of the OpenDarwin project, with the involvement of a number of Apple Inc. employees including Landon Fuller, Kevin Van Vechten, and Jordan Hubbard.

An itemized overview of a MacPorts install is below.

  • Install XCode: This is done via the MacOS X App Store.
  • Follow MacPorts' installation instructions.
  • MacPorts has good support for Octave. A list of what MacPorts has available for Octave is here. To install the most recent version of Octave, type sudo port install octave-devel at the Terminal's command line. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours.

MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainer fall behind. If the current version of the octave-devel port isn't current, it will be necessary to produce a local portfile.

Install an Octave Port

For the purpose of creating an App bundle using MacPorts, an Octave port must be installed. A standard MacPorts port or a local port may be used. For a local portfile it is first required that a local portfile repository be created and the local portfile placed there.

MacPorts' Octave port includes the non-GPL METIS. To avoid license violations do not bundle Metis with Octave and then distribute to others. A second motivation to use a local portfile is that the portfiles for the 3.4.x and 3.6.x series did not include all dependencies for the print feature. The missing dependencies are epstool, pstoedit, and transfig. A prototype portfile which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared.

After creating a local portfile repository an Octave portfile may be added to the local repository using the commands below.

mkdir -p ~/ports/math/octave-local
cp ~/Desktop/portfile ~/ports/math/octave-local

This assumes the Octave portfile had been placed on the users Desktop. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.

cd ~/portfile
portindex -f

Once indexed the local Octave port may be installed.

sudo port install octave-local

Once an Octave port is installed the command below may be used to determine / verify the port's version and variants.

port installed <portname>

Create the MacOS X App Bundle

There are effectively four tasks needed to produce the App bundle. First, Octave and all its build and run-time dependencies must be extracted from the MacPorts installation. Second a App bundle template for running a shell script is required. This may be done using the MacOS X developer tool, Platypus. Third, the shell script which the App bundle runs is needed. This script will be used to launch the MacOS X Terminal app. This script is referred to as the App's shell script. Finally, a script for setting up the shell environment for Octave and running Octave is required. This script is referred to as the Octave shell script.

Produce a DMG for Octave and its dependencies

MacPorts provides a feature for producing binary packages with standalone binary installers that are precompiled; they do not require MacPorts on the target system. Binary files created with MacPorts may be either .pkg (Mac OS X Installer Packages), or RPM (RPM Package Manager) format. MacPorts may also process a .pkg package into a Mac OS X .dmg disk image file. The port command shown below will create a DMG type binary installer for the Octave port and all its dependencies.

sudo port mdmg <portname>

If more than one version of Octave is installed, or if more than one variant of Octave has been installed, the version and variant should be included.

sudo port mdmg <portname> @<version>+variant1+variant2

The DMG will be placed in the port's work directory. If a local portfile is used, a symbolic link to the work directory will be placed in the directory containing the portfile.

Use Platypus to produce a template for the App bundle

To creating an application bundle for MacOS X the utility, Platypus, is used. Platypus is a developer tool for the Mac OS X operating system which is intended to create native Mac OS X applications from interpreted scripts such as shell scripts or Perl, Ruby and Python programs.

A shell script intended to launch a MacOS X Terminal and run Octave will be used as the basis for the MacOS X App bundle.

  • Run the Platypus application.
  • Import Octave's Icon.
  • Set the "Script Type" to "Shell"
  • Specify the "Script Path".
    • Click on the "Select" button and select the App shell script used to launch the Terminal app.
  • Set the "Output" to "None".
  • Specify App Name (Octave-3.7.0).
  • Click the "Create" button.
  • Save the App bundle template to the location of your choice.

Populate the App Bundle

  • Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was ~/ports, the DMG will be located in ~/ports/math/octave-local/work.
  • Save the original MacPorts installation.
sudo mv /opt /opt-save
  • Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new /opt directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.
  • Place the Octave shell script in the same directory as the App bundle template created using Platypus.
  • Populate the App bundle by running the script below from the directory containing the Platypus App bundle template and the Octave shell script.
#! /bin/sh
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.
rm ${FULLAPP}/Contents/Resources/bin/octave
cp octave ${FULLAPP}/Contents/Resources/bin/.
mkdir ${FULLAPP}/Contents/Resources/Applications
cp /Applications/MacPorts/ ${FULLAPP}/Contents/Resources/Applications
  • Restore the original MacPorts installation.
sudo rm -r /opt
sudo mv /opt-save /opt

Problems and Restrictions of the App Bundle

  • The path to the App bundle must not contain spaces
  • Conflicts with other Aquaterm Installations
  • No Universal Builds
  • Limited MacOS Compatibility
  • Icon needs improvement