https://wiki.octave.org/wiki/api.php?action=feedcontributions&user=Bpabbott&feedformat=atomOctave - User contributions [en]2024-03-28T19:18:56ZUser contributionsMediaWiki 1.39.2https://wiki.octave.org/wiki/index.php?title=GNU_Octave_Wiki&diff=9183GNU Octave Wiki2016-06-03T21:49:10Z<p>Bpabbott: /* Installing */</p>
<hr />
<div>[https://www.gnu.org/software/octave/ GNU Octave] is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments. It also provides extensive graphics capabilities for data visualization and manipulation. GNU Octave is normally used through its interactive interface ([https://en.wikipedia.org/wiki/Command-line_interface CLI] and [https://en.wikipedia.org/wiki/Graphical_user_interface GUI]), but it can also be used to write non-interactive programs. The GNU Octave language is quite similar to Matlab so that most programs are easily portable.<br />
<br />
== [[:Category:Installation|Installing]] ==<br />
<br />
Get installers and sources from http://octave.org/download ([[Octave_for_MacOS_X#Installing_a_Mac_OS_X_Bundle|Beta installer for Mac OS X]]). Some installation instructions given [[Octave_for_Debian_systems|here]].<br />
<br />
{{Note|GNU Octave {{Release}} is the current stable release}}<br />
<br />
== News ==<br />
<br />
* {{Release Date}} '''GNU Octave {{Release}}''' has been released (see above)!<br />
<br />
== Getting help with GNU Octave ==<br />
<br />
* Read the [https://www.gnu.org/software/octave/doc/interpreter GNU Octave documentation]<br />
* The [[FAQ|frequently asked questions (FAQ)]] list is good place to start with answers to questions regarding [[FAQ#General|what is Octave]], [[FAQ#Licensing_issues|licensing]], [[FAQ#What.27s_new_in_Octave|new features]], [[FAQ#What_documentation_exists_for_Octave.3F|documentation]], [[FAQ#Installation_issues_and_problems|installation]], [[FAQ#Coding|coding]], [[FAQ#How_can_I_get_involved_in_Octave_development.3F|contributing to Octave]], and more, are found there.<br />
* Continue reading this wiki and feel free to add further content (please check that it is not already part of, or belongs in, the documentation and read the [[Contribution guidelines]]).<br />
* [https://www.gnu.org/software/octave/support.html Other support options]<br />
<br><br />
<br />
__TOC__<br />
<br />
== Advanced topics ==<br />
<br />
Below is a temporary attempt to organize the "most wanted" pages of the Wiki. A list of all pages on the wiki can be seen [[Special:AllPages|here]]. To locate something specific, try the wiki's search box, or prepend {{Codeline|<nowiki>site:wiki.octave.org</nowiki>}} to a [https://www.google.com/search?&q=site%3Awiki.octave.org Google search]. Please read the [[Contribution guidelines]] first, if you want to contribute to this Wiki.<br />
<br />
=== [[:Category:Packages|Packages]] ===<br />
* [[OEP:pkg|Installing packages]]<br />
* [[Creating packages]]<br />
<br />
==== [[Octave-Forge]] ====<br />
<br />
See also the list of Forge Wiki pages: [[:Category:Octave-Forge]]<br />
<br />
* [[bim_package|bim package]] Solve Partial Differential Equaltions with a Finite Element method<br />
* [[Control_package|Control package]]<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/CGI_programming_with_Octave CGI] Common Gateway Interface for Octave<br />
* [[Dataframe_package|Dataframe package]] cell arrays on steroids<br />
* [[Dicom_package|Dicom package]]<br />
* [[Fem-fenics|fem-fenics]] Interface to [http://fenicsproject.org/ FEnics] FEM library<br />
* [[Geometry_package|Geometry package]]<br />
* [[Image_acquisition_package|Image acquisition package]] Capture images, for example from v4l2 hardware like webcams<br />
* [[Instrument_control__package|Instrument control package]]<br />
* [[Interval_package|Interval package]] Real-valued interval arithmetic<br />
* [[IO_package|I/O package]]<br />
* [[Java_package|Java package]]<br />
* [[Mechanics_package|Mechanics package]]<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/NcArray ncArray] High-level interface of accessing a single or a collection of NetCDF files as a multi-dimensional array<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/Octave-netcdf netcdf] matlab-compatible NetCDF package<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/NetCDF_toolbox_for_Octave octcdf] NetCDF package (old)<br />
* [[ocs_package|OCS package]] Octave Circuit Simulator<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/Optimal_interpolation_Fortran_module_with_Octave_interface optiminterp] Optimal interpolation<br />
* [[Parallel_package|Parallel package]]<br />
* [[Sockets_package|Sockets package]]<br />
* [[Symbolic package|Symbolic package]]<br />
* [[TISEAN_package|TISEAN package]]<br />
* [[Video_package|Video package]]<br />
* [[sci_cosim|Scilab co-simulation package]]<br />
<br />
=== [[:Category:Editors|Editors]] ===<br />
* [[Gedit]]<br />
* [[Emacs]]<br />
* [[Nano]]<br />
* [[Vim]]<br />
* [[Kate]]<br />
* [http://octclipse.sourceforge.net Octclipse] (Windows and GNU/Linux only. The Octclipse developers are seeking individuals to assist with MacOS X support.)<br />
* [https://sites.google.com/site/domainmathide/ DomainMath IDE] (Windows,GNU/Linux and Mac OS.)<br />
* [https://bitbucket.org/jgpallero/octave-sh GNU Octave syntax highlight files] (Syntax highlight definitions for some editors. Contibutions are welcome)<br />
<br />
=== [[:Category:Resources|Tutorials/Examples]] ===<br />
* [[Octave Basics]] - For those just getting started.<br />
* [https://staff.ti.bfh.ch/sha1/Labs/PWF/Documentation/OctaveAtBFH.pdf Octave introduction script]<br />
* [[Tips and tricks]] - Guidelines to improve your coding skills.<br />
* [[Cookbook]] - Several simple and useful examples.<br />
* [[Octave load]] - Use liboctave functions to load variables from a file in Octave's binary format. <br />
* [[Fortran]] - Accessing liboctave from a Fortran 2003 program.<br />
* [[Octave fun]] - Coding can be fun -- miscellaneous more or less funny scripts<br />
* [[Video tutorials]]<br />
* [[:Category:Plotting tutorials|Plotting tutorials]]<br />
* [[Interfacing Octave with other languages]]<br />
* [http://www.amiq.com/consulting/2014/11/21/how-to-connect-systemverilog-with-octave/ How to Connect SystemVerilog with Octave]<br />
<br />
=== [[:Category:Development|Development]] ===<br />
In addition to these links, there is a longer list of links relevant to (especially novice) developers at the page [[Developers]].<br />
* [[2015 Code Sprint]] - Worldwide Octave Code Sprint to be held Dec. 12th, 2015.<br />
<br />
* [[Doxygen]] - C++ code documentation<br />
* [[International Characters Support]] - Using Octave in your own language.<br />
* [[Octave for Microsoft Windows]]<br />
* [[Octave for MacOS X]]<br />
* [[Octave for GNU/Linux]] and [[Octave for other Unix systems|other Unix systems]]<br />
<br />
==== [[:Category:Building|Building]] ====<br />
* [[Building]]<br />
* [[Continuous Build]]<br />
* [[Enable large arrays: Build octave such that it can use arrays larger than 2Gb.|Building Octave to use large arrays]]<br />
<br />
==== [[:Category:Testing|Testing]] ====<br />
* [[Tests|Testing source code]]<br />
==== [[:Category:Packaging|Packaging]] ====<br />
* [[Create a MacOS X App Bundle Using MacPorts]]<br />
* [[Windows_Installer|Create a Windows Installer using MXE]]<br />
<br />
=== [[:Category:Academia|Academia]] ===<br />
* [[Publications using Octave]] - A compilation of scientific publications making reference to GNU Octave (add yours!).<br />
<br />
=== [[:Category:Project Ideas|Project Ideas]] ===<br />
* [[Projects]]<br />
* [[Summer of Code Project Ideas]]<br />
<br />
== External Links ==<br />
* [http://www.gnu.org/software/octave/ Octave Homepage]<br />
* [http://octave.sourceforge.net/ Octave Forge]<br />
* [https://savannah.gnu.org/bugs/?group=octave GNU Octave - Bug Tracker]<br />
* [https://savannah.gnu.org/task/?group=octave GNU Octave - Task Tracker]<br />
* [https://savannah.gnu.org/patch/?group=octave GNU Octave - Patch Tracker]<br />
* [https://savannah.gnu.org/hg/?group=octave GNU Octave - Mercurial Repositories]<br />
* [http://planet.octave.org Planet Octave] (collection of blog feeds featuring Octave developers and Summer of Code students)</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=9182Octave for macOS2016-06-03T11:05:40Z<p>Bpabbott: /* Installing a Mac OS X Bundle */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of June 2016):<br />
<br />
*The 4.0.x are current releases.<br />
*The 3.8.x are previous releases.<br />
*The 3.6.x are old releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
Good progress has been made on creating a reliable App bundle for Octave on Mac OS X. Approaches using [http://www.macports.org MacPorts] and [http://brew.sh Homebrew] have been considered.<br />
<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_gui_402.dmg?dl=0 download Octave 4.0.2 with graphical user interface] (OS X 10.9+),<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_cli_402.dmg?dl=0 download Octave 4.0.2 with command line interface] (OS X 10.9+)<br />
<br />
The wiki includes a [[Create_a_MacOS_X_App_Bundle_Using_Homebrew| tutorial]] on how the application bundle is created using Homebrew. The [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|Macports approach]] has been abandoned.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite and OS X 10.11 El Capitan==<br />
[http://deepneural.blogspot.fr/p/welcome.html Configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===Xcode Dependency===<br />
<br />
Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install Xcode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) in the first place:<br />
<br />
'''MacPorts Installation'''<br />
*Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at [http://guide.macports.org/#installing.xcode MacPorts' installation instructions].<br />
*Install the appropriate [https://www.macports.org/install.php MacPorts version] for your OS X version. If you had installed Mac Ports in the past already, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
<br />
'''Preliminary Port Installations''' <br />
*Because of a problem with the "atlas" port - on which Octave depends - it is necessary to build it with the here specified variant prior to the Octave port installation: {{Codeline|sudo port install atlas +gcc5}}. This can last for many hours. Do this overnight. If a prior atlas installation failed, do {{Codeline|sudo port clean atlas}} before reinstallation.<br />
*Octave depends on arpack, too. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' variant instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
<br />
'''Octave Installation'''<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +qtgui+gui}} 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 some time.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.4 the variants ''atlas'', ''gcc5'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle [https://www.java.com/ Java website] for Download. The following command works fine: {{Codeline|sudo port install octave +qtgui+gui+java+metis}}<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}. To close the graphic window of gnuplot use the Octave command {{Codeline|close()}} to get rid of the Gnuplot instance instead of using the close button of the window.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install Xcode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
or if Octave is in your default path:<br />
<br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
<br />
or if you wish to start the GUI by default, without a terminal:<br />
<br />
do shell script "/path/to/octave --force-gui"<br />
<br />
(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)<br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_Homebrew&diff=9181Create a MacOS X App Bundle Using Homebrew2016-06-03T00:18:05Z<p>Bpabbott: /* Known limitations */</p>
<hr />
<div>==Introduction==<br />
<br />
This tutorial explains how to build Octave.app (version >4) using [http://brew.sh Homebrew]. It is recommended that users either <br />
<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_gui_402.dmg?dl=0 download Octave 4.0.2 with graphical user interface] (OS X 10.9+),<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_cli_402.dmg?dl=0 download Octave 4.0.2 with command line interface] (OS X 10.9+)<br />
<br />
==Prerequisites==<br />
* Install [https://developer.apple.com/xcode/download/ Xcode] via the Mac App Store.<br />
* Install the command line tools by {{Codeline|xcode-select --install}}.<br />
* Optional: install [https://xquartz.macosforge.org/landing/ XQuartz], e.g. if you want to use Gnuplot with X11 backend.<br />
<br />
==Creating the App Bundle and Disk Image==<br />
The script "[https://raw.githubusercontent.com/schoeps/octave_installer/master/install_octave.sh install_octave.sh]" from the github repository<br />
<br />
https://github.com/schoeps/octave_installer<br />
<br />
will ask some questions, e.g. regarding the installation path ({{Codeline|/Applications/Octave.app}} is recommended) or whether Octave should be compiled with or without graphical user interface and finally whether a disk image should be created or not. If you choose to install to the Applications folder then the script needs to run with administration rights.<br />
<br />
The script installs all necessary dependencies of octave via [http://brew.sh homebrew]; it's using [http://www.openblas.net openblas] instead of Apple's native implementation.<br />
<br />
==Known limitations==<br />
* Plotting should work with Gnuplot and Qt graphic toolkits. However, sometimes it takes a long time to initialize. <br />
* the application bundle is not relocatable (must be placed in the /Applications directory).<br />
* [ctrl]+c crashes the GUI, cf. [https://savannah.gnu.org/bugs/index.php?37672 Bug 37672].<br />
<br />
[[Category:Macintosh platform]]<br />
[[Category:Packaging]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_Homebrew&diff=9180Create a MacOS X App Bundle Using Homebrew2016-06-03T00:17:07Z<p>Bpabbott: /* Known limitations */</p>
<hr />
<div>==Introduction==<br />
<br />
This tutorial explains how to build Octave.app (version >4) using [http://brew.sh Homebrew]. It is recommended that users either <br />
<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_gui_402.dmg?dl=0 download Octave 4.0.2 with graphical user interface] (OS X 10.9+),<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_cli_402.dmg?dl=0 download Octave 4.0.2 with command line interface] (OS X 10.9+)<br />
<br />
==Prerequisites==<br />
* Install [https://developer.apple.com/xcode/download/ Xcode] via the Mac App Store.<br />
* Install the command line tools by {{Codeline|xcode-select --install}}.<br />
* Optional: install [https://xquartz.macosforge.org/landing/ XQuartz], e.g. if you want to use Gnuplot with X11 backend.<br />
<br />
==Creating the App Bundle and Disk Image==<br />
The script "[https://raw.githubusercontent.com/schoeps/octave_installer/master/install_octave.sh install_octave.sh]" from the github repository<br />
<br />
https://github.com/schoeps/octave_installer<br />
<br />
will ask some questions, e.g. regarding the installation path ({{Codeline|/Applications/Octave.app}} is recommended) or whether Octave should be compiled with or without graphical user interface and finally whether a disk image should be created or not. If you choose to install to the Applications folder then the script needs to run with administration rights.<br />
<br />
The script installs all necessary dependencies of octave via [http://brew.sh homebrew]; it's using [http://www.openblas.net openblas] instead of Apple's native implementation.<br />
<br />
==Known limitations==<br />
* Plotting should work with gnuplot and qt backends. However, sometimes it takes a long time to initialize. <br />
* the app bundle is not relocatable (must be placed in the /Applications directory).<br />
* [ctrl]+c crashes the GUI, cf. [https://savannah.gnu.org/bugs/index.php?37672 Bug 37672].<br />
<br />
[[Category:Macintosh platform]]<br />
[[Category:Packaging]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_Homebrew&diff=9179Create a MacOS X App Bundle Using Homebrew2016-06-03T00:09:52Z<p>Bpabbott: /* Introduction */</p>
<hr />
<div>==Introduction==<br />
<br />
This tutorial explains how to build Octave.app (version >4) using [http://brew.sh Homebrew]. It is recommended that users either <br />
<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_gui_402.dmg?dl=0 download Octave 4.0.2 with graphical user interface] (OS X 10.9+),<br />
* [https://dl.dropboxusercontent.com/u/2079838/octave_cli_402.dmg?dl=0 download Octave 4.0.2 with command line interface] (OS X 10.9+)<br />
<br />
==Prerequisites==<br />
* Install [https://developer.apple.com/xcode/download/ Xcode] via the Mac App Store.<br />
* Install the command line tools by {{Codeline|xcode-select --install}}.<br />
* Optional: install [https://xquartz.macosforge.org/landing/ XQuartz], e.g. if you want to use Gnuplot with X11 backend.<br />
<br />
==Creating the App Bundle and Disk Image==<br />
The script "[https://raw.githubusercontent.com/schoeps/octave_installer/master/install_octave.sh install_octave.sh]" from the github repository<br />
<br />
https://github.com/schoeps/octave_installer<br />
<br />
will ask some questions, e.g. regarding the installation path ({{Codeline|/Applications/Octave.app}} is recommended) or whether Octave should be compiled with or without graphical user interface and finally whether a disk image should be created or not. If you choose to install to the Applications folder then the script needs to run with administration rights.<br />
<br />
The script installs all necessary dependencies of octave via [http://brew.sh homebrew]; it's using [http://www.openblas.net openblas] instead of Apple's native implementation.<br />
<br />
==Known limitations==<br />
* Plotting should work with gnuplot and qt backends. However, sometimes it takes a long time to initialize. <br />
* the app bundle is not relocatable<br />
* [ctrl]+c crashes the GUI, cf. [https://savannah.gnu.org/bugs/index.php?37672 Bug 37672] <br />
<br />
[[Category:Macintosh platform]]<br />
[[Category:Packaging]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=9178Octave for macOS2016-06-03T00:07:50Z<p>Bpabbott: Elevate the visibility of the app bundle using Homebrew</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of June 2016):<br />
<br />
*The 4.0.x are current releases.<br />
*The 3.8.x are previous releases.<br />
*The 3.6.x are old releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
Good progress has been made on creating a reliable App bundle for Octave on Mac OS X. Approaches using [http://www.macports.org MacPorts] and [http://brew.sh Homebrew] have been considered. A [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|wiki page documenting the Homebrew approach]] is available. A mature beta application bundle is available, and instructions on how to the application bundle is created is available at the link. As the Homebrew approach provides a simpler solution, the [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|Macports approach]] has been abandoned.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite and OS X 10.11 El Capitan==<br />
[http://deepneural.blogspot.fr/p/welcome.html Configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===Xcode Dependency===<br />
<br />
Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install Xcode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) in the first place:<br />
<br />
'''MacPorts Installation'''<br />
*Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at [http://guide.macports.org/#installing.xcode MacPorts' installation instructions].<br />
*Install the appropriate [https://www.macports.org/install.php MacPorts version] for your OS X version. If you had installed Mac Ports in the past already, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
<br />
'''Preliminary Port Installations''' <br />
*Because of a problem with the "atlas" port - on which Octave depends - it is necessary to build it with the here specified variant prior to the Octave port installation: {{Codeline|sudo port install atlas +gcc5}}. This can last for many hours. Do this overnight. If a prior atlas installation failed, do {{Codeline|sudo port clean atlas}} before reinstallation.<br />
*Octave depends on arpack, too. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' variant instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
<br />
'''Octave Installation'''<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +qtgui+gui}} 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 some time.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.4 the variants ''atlas'', ''gcc5'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle [https://www.java.com/ Java website] for Download. The following command works fine: {{Codeline|sudo port install octave +qtgui+gui+java+metis}}<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}. To close the graphic window of gnuplot use the Octave command {{Codeline|close()}} to get rid of the Gnuplot instance instead of using the close button of the window.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install Xcode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
or if Octave is in your default path:<br />
<br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
<br />
or if you wish to start the GUI by default, without a terminal:<br />
<br />
do shell script "/path/to/octave --force-gui"<br />
<br />
(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)<br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=9162Octave for macOS2016-05-22T20:28:23Z<p>Bpabbott: /* Installing a Mac OS X Bundle */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite and OS X 10.11 El Capitan==<br />
[http://deepneural.blogspot.fr/p/welcome.html Configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===Xcode Dependency===<br />
<br />
Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install Xcode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) in the first place:<br />
<br />
'''MacPorts Installation'''<br />
*Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at [http://guide.macports.org/#installing.xcode MacPorts' installation instructions].<br />
*Install the appropriate [https://www.macports.org/install.php MacPorts version] for your OS X version. If you had installed Mac Ports in the past already, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
<br />
'''Preliminary Port Installations''' <br />
*Because of a problem with the "atlas" port - on which Octave depends - it is necessary to build it with the here specified variant prior to the Octave port installation: {{Codeline|sudo port install atlas +gcc5}}. This can last for many hours. Do this overnight. If a prior atlas installation failed, do {{Codeline|sudo port clean atlas}} before reinstallation.<br />
*Octave depends on arpack, too. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' variant instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
<br />
'''Octave Installation'''<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +qtgui+gui}} 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 some time.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.4 the variants ''atlas'', ''gcc5'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle [https://www.java.com/ Java website] for Download. The following command works fine: {{Codeline|sudo port install octave +qtgui+gui+java+metis}}<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}. To close the graphic window of gnuplot use the Octave command {{Codeline|close()}} to get rid of the Gnuplot instance instead of using the close button of the window.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install Xcode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
or if Octave is in your default path:<br />
<br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
<br />
or if you wish to start the GUI by default, without a terminal:<br />
<br />
do shell script "/path/to/octave --force-gui"<br />
<br />
(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)<br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
Good progress has been made on creating a reliable App bundle for Octave on Mac OS X. Approaches using [http://www.macports.org MacPorts] and [http://brew.sh Homebrew] have been developed. Information on a Macports approach is available [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]], and information is also averrable for the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew approach]]. As the Homebrew approach provides a simpler solution, the Macports approach has been abandoned.<br />
<br />
An App bundle for Octave on Mac OS X is not presently available, but could become available soon. For those eager to install the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew App bundle]], creating the App bundle is largely automated and can be accomplished with minimal technical expertise. <br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=9161Octave for macOS2016-05-22T20:27:55Z<p>Bpabbott: /* Installing a Mac OS X Bundle */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite and OS X 10.11 El Capitan==<br />
[http://deepneural.blogspot.fr/p/welcome.html Configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===Xcode Dependency===<br />
<br />
Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install Xcode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) in the first place:<br />
<br />
'''MacPorts Installation'''<br />
*Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at [http://guide.macports.org/#installing.xcode MacPorts' installation instructions].<br />
*Install the appropriate [https://www.macports.org/install.php MacPorts version] for your OS X version. If you had installed Mac Ports in the past already, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
<br />
'''Preliminary Port Installations''' <br />
*Because of a problem with the "atlas" port - on which Octave depends - it is necessary to build it with the here specified variant prior to the Octave port installation: {{Codeline|sudo port install atlas +gcc5}}. This can last for many hours. Do this overnight. If a prior atlas installation failed, do {{Codeline|sudo port clean atlas}} before reinstallation.<br />
*Octave depends on arpack, too. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' variant instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
<br />
'''Octave Installation'''<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +qtgui+gui}} 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 some time.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.4 the variants ''atlas'', ''gcc5'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle [https://www.java.com/ Java website] for Download. The following command works fine: {{Codeline|sudo port install octave +qtgui+gui+java+metis}}<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}. To close the graphic window of gnuplot use the Octave command {{Codeline|close()}} to get rid of the Gnuplot instance instead of using the close button of the window.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install Xcode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
or if Octave is in your default path:<br />
<br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
<br />
or if you wish to start the GUI by default, without a terminal:<br />
<br />
do shell script "/path/to/octave --force-gui"<br />
<br />
(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)<br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
Good progress has been made on creating a reliable App bundle for Octave on Mac OS X. Approaches using [http://www.macports.org MacPorts] and [http://brew.sh Homebrew] have been developed. Information on a Macports approach is available [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]], and information is also averrable for the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew approach]]. As the Homebrew approach provides a simpler solution, the Macports approach has been abandoned.<br />
<br />
A App bundle for Octave on Mac OS X is not presently available, but should become available soon. For those eager to install the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew App bundle]], creating the App bundle is largely automated and can be accomplished with minimal technical expertise. <br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=9160Octave for macOS2016-05-22T20:24:41Z<p>Bpabbott: /* Installing a Mac OS X Bundle */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite and OS X 10.11 El Capitan==<br />
[http://deepneural.blogspot.fr/p/welcome.html Configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===Xcode Dependency===<br />
<br />
Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install Xcode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) in the first place:<br />
<br />
'''MacPorts Installation'''<br />
*Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at [http://guide.macports.org/#installing.xcode MacPorts' installation instructions].<br />
*Install the appropriate [https://www.macports.org/install.php MacPorts version] for your OS X version. If you had installed Mac Ports in the past already, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
<br />
'''Preliminary Port Installations''' <br />
*Because of a problem with the "atlas" port - on which Octave depends - it is necessary to build it with the here specified variant prior to the Octave port installation: {{Codeline|sudo port install atlas +gcc5}}. This can last for many hours. Do this overnight. If a prior atlas installation failed, do {{Codeline|sudo port clean atlas}} before reinstallation.<br />
*Octave depends on arpack, too. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' variant instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
<br />
'''Octave Installation'''<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +qtgui+gui}} 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 some time.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.4 the variants ''atlas'', ''gcc5'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle [https://www.java.com/ Java website] for Download. The following command works fine: {{Codeline|sudo port install octave +qtgui+gui+java+metis}}<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}. To close the graphic window of gnuplot use the Octave command {{Codeline|close()}} to get rid of the Gnuplot instance instead of using the close button of the window.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install Xcode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
or if Octave is in your default path:<br />
<br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
<br />
or if you wish to start the GUI by default, without a terminal:<br />
<br />
do shell script "/path/to/octave --force-gui"<br />
<br />
(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)<br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
Good progress has been made on creating a reliable App bundle for Octave on Mac OS X. Approaches using [http://www.macports.org MacPorts] and [http://brew.sh Homebrew] have been developed. Information on a Macports approach is available [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]], but has been abandoned in favor of the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew approach]].<br />
<br />
A App bundle for Octave on Mac OS X is not presently available, but should become available soon. For those eager to install the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew App bundle]], creating the App bundle is largely automated and can be accomplished with minimal technical expertise. <br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=9139Octave for macOS2016-05-17T00:43:21Z<p>Bpabbott: /* Installing a Mac OS X Bundle */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite and OS X 10.11 El Capitan==<br />
[http://deepneural.blogspot.fr/p/welcome.html Configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===Xcode Dependency===<br />
<br />
Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install Xcode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) in the first place:<br />
<br />
'''MacPorts Installation'''<br />
*Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at [http://guide.macports.org/#installing.xcode MacPorts' installation instructions].<br />
*Install the appropriate [https://www.macports.org/install.php MacPorts version] for your OS X version. If you had installed Mac Ports in the past already, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
<br />
'''Preliminary Port Installations''' <br />
*Because of a problem with the "atlas" port - on which Octave depends - it is necessary to build it with the here specified variant prior to the Octave port installation: {{Codeline|sudo port install atlas +gcc5}}. This can last for many hours. Do this overnight. If a prior atlas installation failed, do {{Codeline|sudo port clean atlas}} before reinstallation.<br />
*Octave depends on arpack, too. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' variant instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
<br />
'''Octave Installation'''<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +qtgui+gui}} 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 some time.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.4 the variants ''atlas'', ''gcc5'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle [https://www.java.com/ Java website] for Download. The following command works fine: {{Codeline|sudo port install octave +qtgui+gui+java+metis}}<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}. To close the graphic window of gnuplot use the Octave command {{Codeline|close()}} to get rid of the Gnuplot instance instead of using the close button of the window.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install Xcode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
or if Octave is in your default path:<br />
<br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
<br />
or if you wish to start the GUI by default, without a terminal:<br />
<br />
do shell script "/path/to/octave --force-gui"<br />
<br />
(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)<br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
Good progress has been made on creating a reliable App bundle for Octave on Mac OS X. Approaches using [http://www.macports.org MacPorts] and [http://brew.sh Homebrew] have been under development. Information on the Macports approach is available [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]], but has been abandoned in favor of the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew approach]].<br />
<br />
A App bundle for Octave on Mac OS X is not presently available, but should become available soon. For those eager to install the [[Create_a_MacOS_X_App_Bundle_Using_Homebrew|Homebrew App bundle]], creating the App bundle is largely automated and can be accomplished with minimal technical expertise. <br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=9138Octave for macOS2016-05-16T13:43:41Z<p>Bpabbott: /* Create a launcher app with AppleScript */ remove <code></code> formatting and its buggy behavior</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite and OS X 10.11 El Capitan==<br />
[http://deepneural.blogspot.fr/p/welcome.html Configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===Xcode Dependency===<br />
<br />
Each package manager requires that Xcode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's Xcode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with Xcode already installed avoid installing Kenneth's solution, as it may break your existing Xcode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install Xcode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from Xcode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
Following instructions are made for MacPorts 2.3.4 on Mac OS X 10.11 (El Capitan) in the first place:<br />
<br />
'''MacPorts Installation'''<br />
*Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools" as described at [http://guide.macports.org/#installing.xcode MacPorts' installation instructions].<br />
*Install the appropriate [https://www.macports.org/install.php MacPorts version] for your OS X version. If you had installed Mac Ports in the past already, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
<br />
'''Preliminary Port Installations''' <br />
*Because of a problem with the "atlas" port - on which Octave depends - it is necessary to build it with the here specified variant prior to the Octave port installation: {{Codeline|sudo port install atlas +gcc5}}. This can last for many hours. Do this overnight. If a prior atlas installation failed, do {{Codeline|sudo port clean atlas}} before reinstallation.<br />
*Octave depends on arpack, too. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' variant instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
<br />
'''Octave Installation'''<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +qtgui+gui}} 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 some time.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.4 the variants ''atlas'', ''gcc5'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). If you need Java support add the new Java variant (+java). A installed Java JRE is mandatory. Go To the Oracle [https://www.java.com/ Java website] for Download. The following command works fine: {{Codeline|sudo port install octave +qtgui+gui+java+metis}}<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}. To close the graphic window of gnuplot use the Octave command {{Codeline|close()}} to get rid of the Gnuplot instance instead of using the close button of the window.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install Xcode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from Xcode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
or if Octave is in your default path:<br />
<br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
<br />
or if you wish to start the GUI by default, without a terminal:<br />
<br />
do shell script "/path/to/octave --force-gui"<br />
<br />
(e.g. Homebrew installs Octave to '/usr/local/bin/octave' by default)<br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
A reliable App bundle for Octave on Mac OS X is not presently available. The developers would like to be able to provide an App bundle, but need volunteers to support the effort. An approach for producing an App Bundle using [http://www.macports.org MacPorts] is being documented [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]]. This approach shows promise, but a few problems must be resolved before a bundle will become available.<br />
<br />
Octave and many other software packages may be installed and updated using one of the three package managers available for Mac OS X. To install using a package manager, see the section on [[Octave_for_MacOS_X#Package_Managers|Package Managers]].<br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=6137Octave for macOS2015-04-10T12:33:03Z<p>Bpabbott: /* Using Aquaterm with Gnuplot */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite==<br />
[http://deepneural.blogspot.fr/p/instructions-1_10.html Instructions and configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===XCode Dependency===<br />
<br />
Each package manager requires that XCode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's XCode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with XCode already installed avoid installing Kenneth's solution, as it may break your existing XCode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from XCode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install "XCode" via the Mac App Store and the "XCode Command Line Tools" as described at [http://www.macports.org/install.php MacPorts' installation instructions]. If your are running Mac OS X 10.9 (Mavericks) or 10.10 (Yosemite) you just need to type {{Codeline|xcode-select --install}} in the terminal and press the "Install" button of the appearing dialog box.<br />
* If you have MacPorts already installed sooner, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +gui}} 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.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.3 the variants ''atlas'', ''gcc49'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). For the experimental GUI add variant +gui (see above). If you need Java support add the new Java variant (+java).<br />
*Octave depends on arpack. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install XCode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from XCode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot --with-aquaterm --with-qt4</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
<code><br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
</code><br />
<br />
or if Octave is in your default path:<br />
<br />
<code><br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
</code><br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
A reliable App bundle for Octave on Mac OS X is not presently available. The developers would like to be able to provide an App bundle, but need volunteers to support the effort. An approach for producing an App Bundle using [http://www.macports.org MacPorts] is being documented [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]]. This approach shows promise, but a few problems must be resolved before a bundle will become available.<br />
<br />
Octave and many other software packages may be installed and updated using one of the three package managers available for Mac OS X. To install using a package manager, see the section on [[Octave_for_MacOS_X#Package_Managers|Package Managers]].<br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=6136Octave for macOS2015-04-10T12:31:20Z<p>Bpabbott: /* Simple Installation Instructions */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Octave server VM installer for OSX 10.10 Yosemite==<br />
[http://deepneural.blogspot.fr/p/instructions-1_10.html Instructions and configuration files] that cause Vagrant to automatically download and configure an Octave server VM under OS X including 10.10 Yosemite. The install process pulls down the latest stable Linux version of Octave at the time of installation. All software used in running this server VM is open source (Vagrant, VirtualBox, Octave). The Octave server will run headless, and display the Octave GUI and graphics on the host via the Mac's native X-windows server. The recommended configuration ensures that by default user files written by the GUI are in a folder shared with the Mac's filesystem, and the VM suspends automatically when the user quits the GUI. Any edited files then persist in the Mac's shared folder.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===XCode Dependency===<br />
<br />
Each package manager requires that XCode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's XCode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with XCode already installed avoid installing Kenneth's solution, as it may break your existing XCode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from XCode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install "XCode" via the Mac App Store and the "XCode Command Line Tools" as described at [http://www.macports.org/install.php MacPorts' installation instructions]. If your are running Mac OS X 10.9 (Mavericks) or 10.10 (Yosemite) you just need to type {{Codeline|xcode-select --install}} in the terminal and press the "Install" button of the appearing dialog box.<br />
* If you have MacPorts already installed sooner, update it first by typing {{Codeline|sudo port selfupdate}} and {{Codeline|sudo port upgrade outdated}} in the terminal.<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave}} or if you want the experimental graphic user interface (GUI) {{Codeline|sudo port install octave +gui}} 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.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave}}. In MacPorts 2.3.3 the variants ''atlas'', ''gcc49'' and ''glgui'' are installed by default (marked with '+' sign in {{Codeline|port variants octave}} output). For the experimental GUI add variant +gui (see above). If you need Java support add the new Java variant (+java).<br />
*Octave depends on arpack. Unfortunately arpack is installed with the ''accelerate'' variant by default. The ''accelerate'' variant uses Apple's Vector Libraries which have some known bugs that can cause Octave to crash if using certain functions in arpack. To avoid this install arpack with the ''atlas'' instead of the ''accelerate'' variant {{Codeline|sudo port install arpack -accelerate+atlas}}. You can even do this after you installed Octave. The new variant become active by default.<br />
*If Octave crashes when plotting use the Gnuplot graphic toolkit instead of FLTK. Type {{Codeline|graphics_toolkit('gnuplot')}} in Octave before plotting. For using the nicer wxt-terminal of Gnuplot, type {{Codeline|setenv("GNUTERM","wxt")}} in Octave. To make this the standard behavior append both commands in one of Octave's startup files e.g. your {{Codeline|~/.octaverc}}.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install XCode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from XCode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}} (Now you don't need to install it manually, it would be installed by dependency), and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install octave</pre><br />
This would install octave with the default dependencies. Note that the default dependencies include java runtime environment. If you do not have java installed, homebrew would guide you to do that. Or you can type {{Codeline|brew install octave --without-java}} to remove its dependency on java.<br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
<pre>brew update && brew upgrade</pre><br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours, but precompiled binary packages called 'bottles' are available with default options for Octave and many of its dependencies.<br />
<br />
Octave has an experimental built-in GUI (developed using Qt lib) installed by default so that gnuplot and other tools could use it directly. Gnuplot will build with Qt support if Octave's Qt-based GUI is enabled. You do not need to install an X server in most situations. Note: On Snow Leopard, Octave requires an X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}. See also {{Codeline|brew info octave}} for recommended settings.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
====Using Aquaterm with Gnuplot====<br />
When using {{Codeline|gnuplot}} as the graphics toolkit, if the {{Codeline|aqua}} terminal is not supported by {{Codeline|gnuplot}}, follow the steps below to resolve the problem.<br />
<br />
*Uninstall {{Codeline|gnuplot}}<br />
<pre>brew uninstall gnuplot</pre><br />
*Install [http://aquaterm.sourceforge.net Aquaterm]<br />
*Install {{Codeline|gnuplot}}<br />
<pre>brew install gnuplot</pre><br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
<code><br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
</code><br />
<br />
or if Octave is in your default path:<br />
<br />
<code><br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
</code><br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
A reliable App bundle for Octave on Mac OS X is not presently available. The developers would like to be able to provide an App bundle, but need volunteers to support the effort. An approach for producing an App Bundle using [http://www.macports.org MacPorts] is being documented [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]]. This approach shows promise, but a few problems must be resolved before a bundle will become available.<br />
<br />
Octave and many other software packages may be installed and updated using one of the three package managers available for Mac OS X. To install using a package manager, see the section on [[Octave_for_MacOS_X#Package_Managers|Package Managers]].<br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=5236Octave for macOS2014-12-15T17:53:31Z<p>Bpabbott: /* Simple Installation Instructions */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===XCode Dependency===<br />
<br />
Each package manager requires that XCode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's XCode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with XCode already installed avoid installing Kenneth's solution, as it may break your existing XCode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from XCode's Apple Menu > Preferences > Downloads on 10.7 or 10.8, and use {{Codeline|<nowiki>sudo xcode-select --install</nowiki>}} on 10.9 or 10.10 .<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For OS X 10.8-10.10, enabling the binary distribution during the initial setup will save you a lot of build time. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave with GUI support, type {{Codeline|<nowiki>fink install octave-qtmac</nowiki>}} or {{Codeline|<nowiki>fink install octave-qtx11</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas-qtmac}} or {{Codeline|octave-atlas-qtx11}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take many hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package may be installed by typing {{Codeline|fink install control-atlas-oct382}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
*Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave +atlas+docs}} 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.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave-devel}}. It is recommended that the user include {{Codeline|+atlas+docs}}. This will avoid bugs present in Apple's vecLib and enable support for Octave's {{Codeline|doc()}} function.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install XCode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from XCode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}}, and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install gcc<br />
brew install octave</pre><br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
brew update && brew upgrade<br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours.<br />
Note: On Snow Leopard, Octave requires a X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
<code><br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
</code><br />
<br />
or if Octave is in your default path:<br />
<br />
<code><br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
</code><br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
A reliable App bundle for Octave on Mac OS X is not presently available. The developers would like to be able to provide an App bundle, but need volunteers to support the effort. An approach for producing an App Bundle using [http://www.macports.org MacPorts] is being documented [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]]. This approach shows promise, but a few problems must be resolved before a bundle will become available.<br />
<br />
Octave and many other software packages may be installed and updated using one of the three package managers available for Mac OS X. To install using a package manager, see the section on [[Octave_for_MacOS_X#Package_Managers|Package Managers]].<br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=4891Octave for macOS2014-05-17T00:37:12Z<p>Bpabbott: /* Simple Installation Instructions */</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. <br />
GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of January 2014):<br />
<br />
*The 3.8.x are current releases.<br />
*The 3.6.x are previous releases.<br />
*The 3.4.x are very old releases.<br />
<br />
==Binary installer for OSX 10.9.1==<br />
<br />
A [http://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/2013-12-30%20binary%20installer%20of%20Octave%203.8.0%20for%20OSX%2010.9.1%20%28beta%29/ binary installer] for Mavericks can be found on Octave Forge.<br />
<br />
This installer will install all binaries for GNU Octave 3.8.0 itself and its dependencies under <br />
<br />
/usr/local/octave/3.8.0 <br />
<br />
And will create two entries in the Applications folder <br />
<br />
/Applications/Octave-cli.app <br />
/Applications/Octave-gui.app <br />
<br />
Which will start Octave in CLI and GUI mode respectively, these are just small wrappers containing a startup script and an icon to allow launching Octave from the Finder. <br />
<br />
If you wish to uninstall GNU Octave 3.8.0 and all other software installed by this installer you can simply move the three folders listed above to the Trash. Notice that you will need to authenticate with an administrator password to be allowed to do so.<br />
<br />
You may need to override Gatekeeper to allow installation. You may find instructions about how to do this on [http://support.apple.com/kb/ht5290 this page] in the section labeled "How to open an app from a unidentified developer and exempt it from Gatekeeper". <br />
<br />
In short: <br />
<br />
* In Finder, Control-click or right click the icon of the app. <br />
* Select Open from the top of contextual menu that appears. <br />
* Click Open in the dialog box. If prompted, enter an administrator name and password. <br />
<br />
This installer is known to work on OSX 10.9.1, you may try, at your own risk, to use it for installing on other system versions but it is not guaranteed to work.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://brew.sh/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===XCode Dependency===<br />
<br />
Each package manager requires that XCode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's XCode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with XCode already installed avoid installing Kenneth's solution, as it may break your existing XCode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from XCode's Apple Menu > Preferences > Downloads.<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave, type {{Codeline|<nowiki>sudo fink install octave</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package for Lion may be installed by typing {{Codeline|fink install control-atlas-oct362}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
*Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave +atlas+docs}} 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.<br />
*Note that {{Codeline|octave-devel}} has been replaced by {{Codeline|octave}}, see [https://trac.macports.org/changeset/114034 MacPorts Revision 114034].<br />
*The variant installed may be important to the user's experience. The available variants for {{Codeline|octave}} are displayed by typing {{Codeline|port variants octave-devel}}. It is recommended that the user include {{Codeline|+atlas+docs}}. This will avoid bugs present in Apple's vecLib and enable support for Octave's {{Codeline|doc()}} function.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install XCode via the Mac App Store.<br />
** For Mac OS 10.9 (Mavericks) install the command line tools by {{Codeline|xcode-select --install}}.<br />
** For earlier versions of Mac OS, install the command line tools from XCode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* If running Mountain Lion (Mac OS 10.8) or later, install [https://xquartz.macosforge.org/landing/ XQuartz].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}}, and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install gfortran<br />
brew install octave</pre><br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
brew update && brew upgrade<br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours.<br />
Note: On Snow Leopard, Octave requires a X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. The [http://jatinganhotra.com/blog/2014/01/21/installing-octave-on-os-x-10-dot-9-mavericks/ post by Jatin Ganhotra] may also be helpful. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
<code><br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
</code><br />
<br />
or if Octave is in your default path:<br />
<br />
<code><br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
</code><br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
A reliable App bundle for Octave on Mac OS X is not presently available. The developers would like to be able to provide an App bundle, but need volunteers to support the effort. An approach for producing an App Bundle using [http://www.macports.org MacPorts] is being documented [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]]. This approach shows promise, but a few problems must be resolved before a bundle will become available.<br />
<br />
Octave and many other software packages may be installed and updated using one of the three package managers available for Mac OS X. To install using a package manager, see the section on [[Octave_for_MacOS_X#Package_Managers|Package Managers]].<br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}<br />
<br />
[[Category:Installation]]<br />
[[Category:Macintosh platform]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Bug_Fix_List_-_3.8_Release&diff=3296Bug Fix List - 3.8 Release2013-10-22T17:54:42Z<p>Bpabbott: /* Bugs with severity >= 4 */</p>
<hr />
<div>The following bugs must be fixed prior to release. See also the [[Release 3.8]] goals.<br />
<br />
Use <pre><strike> ... </strike></pre> to cross an item off the list when it has been done. Sign up for a bug by filling in the Owner field so people won't duplicate each other's work.<br />
<br />
== Bugs with severity >= 4 ==<br />
<br />
* <strike> Owner:jwe {{bug|33304}} power operator precedence and direction </strike><br />
* Owner:??? {{bug|40246}} OpenGL should test data and abort plot if range > float range<br />
* Owner:??? {{bug|40312}} GUI asks to reload a saved file<br />
* Owner: ??? {{bug|40350}} pager does not work on MacOSX<br />
* Owner: ??? {{bug|40242}} FLTK + GUI = crash on MacOSX<br />
<br />
== Bugs marked as regressions ==<br />
<br />
* Owner:??? {{bug|40347}} figure () fails when called from script file<br />
* Owner:??? {{bug|40333}} print with legend modifies axis position<br />
* Owner:jwe {{bug|40342}} help "FolderName" to print Contents.m files does not work properly.<br />
* <strike> Owner:??? {{bug|40301}} MinGW/MXE - urlwrite won't load, but urlread does. </strike><br />
* Owner:??? {{bug|39925}} imagesc crash Plotting with OpenGL<br />
* <strike> Owner:??? {{bug|39524}} m-file profiler returning inaccurate first line </strike><br />
* Owner:??? {{bug|38236}} invoking script in demo block to define variables causes errors<br />
* Owner:??? {{bug|37672}} GUI doesn't react to CTRL+C<br />
* <strike> Owner:rik {{bug|37410}} image.m has a wrong check for linearly-spaced x and y </strike><br />
* <strike> Owner:jwe {{bug|31287}} Certain assignments of empty arrays give errors (Matlab incompatibility) </strike><br />
* Owner:??? {{bug|40256}} gnuplot - datetick doesn't remove previous X-grid, -ticks & labels<br />
* <strike> Owner:rik {{bug|40260}} edit_history doing run_history instead </strike><br />
<br />
== Bugs marked as Crash ==<br />
<br />
It would be nice to fix these, but they don't require resolution before the release.<br />
<br />
* <strike> Owner:rik {{bug|40308}} segfault on plot with colorbar </strike><br />
* <strike> Owner:dbateman {{bug|40305}} real (sparse (2i)) creates bad internally formatted sparse matrix </strike><br />
* <strike> Owner:carandrag {{bug|40267}} imread ('default.img') causes segfault </strike><br />
* Owner:??? {{bug|40242}} FLTK + GUI = crash on MacOSX<br />
* Owner:??? {{bug|40121}} Using dbquit from within a callback causes a segfault<br />
* <strike> Owner:??? {{bug|40068}} Crashing when calling imread </strike><br />
* Owner:??? {{bug|40044}} *** glibc detected *** gnuplot: double free or corruption (fasttop): 0x08d72878 ***<br />
* Owner:??? {{bug|39587}} Assertion failure with profexplore after profile erroneous use: Assertion `active_fcn != call_tree' failed.<br />
* Owner:??? {{bug|39586}} Assertion failure with profexplore valid use: Assertion `fcn_id == fcn' failed.<br />
* Owner:??? {{bug|39273}} lu SIGSEGV when used with 2 output variables with --enable-64<br />
* <strike> Owner:mappel {{bug|38789}} segfault on exit after failing to load HDF5 file </strike><br />
* <strike> Owner:??? {{bug|38616}} memory leak in regexprep </strike><br />
* Owner:??? {{bug|38584}} setting linestyle to "none" for fill object causes error (gnuplot)<br />
* Owner:??? {{bug|38305}} file dialog causes crash<br />
* Owner:??? {{bug|38280}} imfinfo() crashes on 64 bit, but not 32 bit builds<br />
* <strike> Owner:??? {{bug|37928}} GUI crashes with french locale </strike><br />
* <strike> Owner:rik {{bug|37927}} set (gcf, "parent", gcf) -> seg-fault </strike><br />
* <strike> Owner:rik {{bug|37750}} segfault with 'set(gca, "parent", gca)' </strike><br />
* Owner:??? {{bug|37344}} GUI Octave freezes when plotting is used with OpenBLAS<br />
* Owner:??? {{bug|37205}} running tests with valgrind: possible memory issues and segfault<br />
* Owner:??? {{bug|36067}} bug in exist() when checking for a faulty mex/oct file<br />
* <strike> Owner:rik {{bug|35687}} crash with axes("position", []) </strike><br />
* Owner:??? {{bug|33296}} calling "keyboard" function through "builtin" function appears to enter in an infinite loop<br />
* <strike> Owner:mtm {{bug|32176}} infinite loop if PS1 contains deleted current directory </strike></div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Bug_Fix_List_-_3.8_Release&diff=3288Bug Fix List - 3.8 Release2013-10-20T12:45:50Z<p>Bpabbott: /* Bugs with severity >= 4 */</p>
<hr />
<div>The following bugs must be fixed prior to release. See also the [[Release 3.8]] goals.<br />
<br />
Use <pre><strike> ... </strike></pre> to cross an item off the list when it has been done. Sign up for a bug by filling in the Owner field so people won't duplicate each other's work.<br />
<br />
== Bugs with severity >= 4 ==<br />
<br />
* <strike> Owner:jwe {{bug|33304}} power operator precedence and direction </strike><br />
* Owner:??? {{bug|40246}} OpenGL should test data and abort plot if range > float range<br />
* Owner:??? {{bug|40312}} GUI asks to reload a saved file<br />
<br />
== Bugs marked as regressions ==<br />
<br />
* Owner:??? {{bug|40301}} MinGW/MXE - urlwrite won't load, but urlread does.<br />
* Owner:??? {{bug|39925}} imagesc crash Plotting with OpenGL<br />
* <strike> Owner:??? {{bug|39524}} m-file profiler returning inaccurate first line </strike><br />
* Owner:??? {{bug|38236}} invoking script in demo block to define variables causes errors<br />
* Owner:??? {{bug|37672}} GUI doesn't react to CTRL+C<br />
* <strike> Owner:rik {{bug|37410}} image.m has a wrong check for linearly-spaced x and y </strike><br />
* <strike> Owner:jwe {{bug|31287}} Certain assignments of empty arrays give errors (Matlab incompatibility) </strike><br />
* Owner:??? {{bug|40256}} gnuplot - datetick doesn't remove previous X-grid, -ticks & labels<br />
* <strike> Owner:rik {{bug|40260}} edit_history doing run_history instead </strike><br />
<br />
== Bugs marked as Crash ==<br />
<br />
It would be nice to fix these, but they don't require resolution before the release.<br />
<br />
* <strike> Owner:rik {{bug|40308}} segfault on plot with colorbar </strike><br />
* <strike> Owner:dbateman {{bug|40305}} real (sparse (2i)) creates bad internally formatted sparse matrix </strike><br />
* Owner:??? {{bug|40267}} imread ('default.img') causes segfault<br />
* Owner:??? {{bug|40242}} FLTK + GUI = crash on MacOSX<br />
* Owner:??? {{bug|40121}} Using dbquit from within a callback causes a segfault<br />
* <strike> Owner:??? {{bug|40068}} Crashing when calling imread </strike><br />
* Owner:??? {{bug|40044}} *** glibc detected *** gnuplot: double free or corruption (fasttop): 0x08d72878 ***<br />
* Owner:??? {{bug|39587}} Assertion failure with profexplore after profile erroneous use: Assertion `active_fcn != call_tree' failed.<br />
* Owner:??? {{bug|39586}} Assertion failure with profexplore valid use: Assertion `fcn_id == fcn' failed.<br />
* Owner:??? {{bug|39273}} lu SIGSEGV when used with 2 output variables with --enable-64<br />
* <strike> Owner:mappel {{bug|38789}} segfault on exit after failing to load HDF5 file </strike><br />
* <strike> Owner:??? {{bug|38616}} memory leak in regexprep </strike><br />
* Owner:??? {{bug|38584}} setting linestyle to "none" for fill object causes error (gnuplot)<br />
* Owner:??? {{bug|38305}} file dialog causes crash<br />
* Owner:??? {{bug|38280}} imfinfo() crashes on 64 bit, but not 32 bit builds<br />
* <strike> Owner:??? {{bug|37928}} GUI crashes with french locale </strike><br />
* <strike> Owner:rik {{bug|37927}} set (gcf, "parent", gcf) -> seg-fault </strike><br />
* <strike> Owner:rik {{bug|37750}} segfault with 'set(gca, "parent", gca)' </strike><br />
* Owner:??? {{bug|37344}} GUI Octave freezes when plotting is used with OpenBLAS<br />
* Owner:??? {{bug|37205}} running tests with valgrind: possible memory issues and segfault<br />
* Owner:??? {{bug|36067}} bug in exist() when checking for a faulty mex/oct file<br />
* <strike> Owner:rik {{bug|35687}} crash with axes("position", []) </strike><br />
* Owner:??? {{bug|33296}} calling "keyboard" function through "builtin" function appears to enter in an infinite loop<br />
* <strike> Owner:mtm {{bug|32176}} infinite loop if PS1 contains deleted current directory </strike></div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Bug_Fix_List_-_3.8_Release&diff=3287Bug Fix List - 3.8 Release2013-10-20T12:45:18Z<p>Bpabbott: /* Bugs with severity >= 4 */</p>
<hr />
<div>The following bugs must be fixed prior to release. See also the [[Release 3.8]] goals.<br />
<br />
Use <pre><strike> ... </strike></pre> to cross an item off the list when it has been done. Sign up for a bug by filling in the Owner field so people won't duplicate each other's work.<br />
<br />
== Bugs with severity >= 4 ==<br />
<br />
* <strike> Owner:jwe {{bug|33304}} power operator precedence and direction </strike><br />
* Owner: ??? {{bug|40246}} OpenGL should test data and abort plot if range > float range<br />
* Owner: ??? {{bug|40312}} GUI asks to reload a saved file<br />
<br />
== Bugs marked as regressions ==<br />
<br />
* Owner:??? {{bug|40301}} MinGW/MXE - urlwrite won't load, but urlread does.<br />
* Owner:??? {{bug|39925}} imagesc crash Plotting with OpenGL<br />
* <strike> Owner:??? {{bug|39524}} m-file profiler returning inaccurate first line </strike><br />
* Owner:??? {{bug|38236}} invoking script in demo block to define variables causes errors<br />
* Owner:??? {{bug|37672}} GUI doesn't react to CTRL+C<br />
* <strike> Owner:rik {{bug|37410}} image.m has a wrong check for linearly-spaced x and y </strike><br />
* <strike> Owner:jwe {{bug|31287}} Certain assignments of empty arrays give errors (Matlab incompatibility) </strike><br />
* Owner:??? {{bug|40256}} gnuplot - datetick doesn't remove previous X-grid, -ticks & labels<br />
* <strike> Owner:rik {{bug|40260}} edit_history doing run_history instead </strike><br />
<br />
== Bugs marked as Crash ==<br />
<br />
It would be nice to fix these, but they don't require resolution before the release.<br />
<br />
* <strike> Owner:rik {{bug|40308}} segfault on plot with colorbar </strike><br />
* <strike> Owner:dbateman {{bug|40305}} real (sparse (2i)) creates bad internally formatted sparse matrix </strike><br />
* Owner:??? {{bug|40267}} imread ('default.img') causes segfault<br />
* Owner:??? {{bug|40242}} FLTK + GUI = crash on MacOSX<br />
* Owner:??? {{bug|40121}} Using dbquit from within a callback causes a segfault<br />
* <strike> Owner:??? {{bug|40068}} Crashing when calling imread </strike><br />
* Owner:??? {{bug|40044}} *** glibc detected *** gnuplot: double free or corruption (fasttop): 0x08d72878 ***<br />
* Owner:??? {{bug|39587}} Assertion failure with profexplore after profile erroneous use: Assertion `active_fcn != call_tree' failed.<br />
* Owner:??? {{bug|39586}} Assertion failure with profexplore valid use: Assertion `fcn_id == fcn' failed.<br />
* Owner:??? {{bug|39273}} lu SIGSEGV when used with 2 output variables with --enable-64<br />
* <strike> Owner:mappel {{bug|38789}} segfault on exit after failing to load HDF5 file </strike><br />
* <strike> Owner:??? {{bug|38616}} memory leak in regexprep </strike><br />
* Owner:??? {{bug|38584}} setting linestyle to "none" for fill object causes error (gnuplot)<br />
* Owner:??? {{bug|38305}} file dialog causes crash<br />
* Owner:??? {{bug|38280}} imfinfo() crashes on 64 bit, but not 32 bit builds<br />
* <strike> Owner:??? {{bug|37928}} GUI crashes with french locale </strike><br />
* <strike> Owner:rik {{bug|37927}} set (gcf, "parent", gcf) -> seg-fault </strike><br />
* <strike> Owner:rik {{bug|37750}} segfault with 'set(gca, "parent", gca)' </strike><br />
* Owner:??? {{bug|37344}} GUI Octave freezes when plotting is used with OpenBLAS<br />
* Owner:??? {{bug|37205}} running tests with valgrind: possible memory issues and segfault<br />
* Owner:??? {{bug|36067}} bug in exist() when checking for a faulty mex/oct file<br />
* <strike> Owner:rik {{bug|35687}} crash with axes("position", []) </strike><br />
* Owner:??? {{bug|33296}} calling "keyboard" function through "builtin" function appears to enter in an infinite loop<br />
* <strike> Owner:mtm {{bug|32176}} infinite loop if PS1 contains deleted current directory </strike></div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=FAQ&diff=3284FAQ2013-10-19T23:33:22Z<p>Bpabbott: /* How can I know more about Octave GUI? */ comment out reference to Jacob's blog</p>
<hr />
<div>This is a list of frequently asked questions (FAQ) for GNU Octave users.<br />
<br />
We are always looking for new questions (with answers), better answers, or both. Feel free to edit this page with your changes. If you have general questions about GNU Octave, or need help for something that is not covered by the Octave manual or the FAQ, please use the [https://mailman.cae.wisc.edu/listinfo/help-octave help@octave.org mailing list].<br />
<br />
This FAQ is intended to supplement, not replace, the GNU Octave manual. Before posting a question to the [https://mailman.cae.wisc.edu/listinfo/help-octave help@octave.org mailing list], you should first check to see if the topic is covered in the manual.<br />
<br />
=General=<br />
<br />
==What is Octave?==<br />
<br />
GNU Octave is a high-level interactive language, primarily intended for numerical computations, that is mostly compatible with Matlab.<br />
<br />
GNU Octave can do arithmetic for real, complex or integer-valued scalars and matrices, solve sets of nonlinear algebraic equations, integrate functions over finite and infinite intervals, and integrate systems of ordinary differential and differential-algebraic equations.<br />
<br />
GNU Octave uses the GNU readline library to handle reading and editing input. By default, the line editing commands are similar to the cursor movement commands used by GNU Emacs, and a vi-style line editing interface is also available. At the end of each session, the command history is saved, so that commands entered during previous sessions are not lost.<br />
<br />
The GNU Octave distribution includes a 650+ page Texinfo manual. Access to the complete text of the manual is available via the doc command at the GNU Octave prompt.<br />
<br />
==What is Octave-Forge?==<br />
[http://octave.sourceforge.net/ Octave-Forge] is a collection of packages for GNU Octave, something similar to the Matlab toolboxes. When talking about the two projects at the same time, GNU Octave is usually referred to as Octave core (or just ''core''). [http://octave.sourceforge.net/ Octave-Forge] also serves as a test bed for code that may eventually end up in the core, and distributes binaries for systems with a lack of developers tools (mainly Windows).<br />
<br />
==Who uses Octave?==<br />
<br />
Lots of people. It seems that universities use it for research and teaching, companies of all sizes, for development, individuals. This question comes often on Octave mailing lists, see [[Who Uses Octave?]] for a few answers<br />
<br />
==Who develops Octave?==<br />
<br />
Discussions about writing the software that would eventually become Octave started in about 1988 with James B. Rawlings and John W. Eaton at the University of Texas. John W. Eaton was the original author of Octave, starting full-time development in February 1992. He is still the primary maintainer. The community of users/developers has in addition contributed some code and fuels the discussion on the mailing lists help@octave.org (user forum), maintainers@octave.org (development issues).<br />
<br />
==Why "Octave"?==<br />
<br />
Octave's name has nothing to do with music. It's named after [http://en.wikipedia.org/wiki/Octave_Levenspiel Octave Levenspiel], a former professor of John who was famous for his ability to do quick back-of-the-envelope calculations. You can hear John pronounce the name "Octave" a few times [http://videolectures.net/mloss08_eaton_oct/ in this video]. We hope that GNU Octave will help perform computations with the same ease as Dr. Levenspiel.<br />
<br />
==Why <em>GNU</em> Octave?==<br />
<br />
The GNU Project was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system.<br />
<br />
GNU is a recursive acronym for “GNU's Not Unix”; it is pronounced guh-noo, approximately like canoe.<br />
<br />
The Free Software Foundation (FSF) is the principal organizational sponsor of the GNU Project.<br />
<br />
Octave became GNU Octave in 1997 (beginning with version 2.0.6). This meant agreeing to consider Octave a part of the GNU Project and support the efforts of the FSF. A big part of this effort is to adhere to the [http://www.gnu.org/prep/standards/standards.html GNU coding standards] and to benefit from GNU's infrastructure (e.g. [http://hg.savannah.gnu.org/hgweb/octave/ code hosting] and [http://bugs.octave.org bug tracking]). Additionally, Octave receives [https://my.fsf.org/donate/working-together/octave sponsorship] from the FSF's Working Together fund. However, Octave is not and has never been developed by the FSF.<br />
<br />
For more information about the GNU project, see http://www.gnu.org.<br />
<br />
==What version should I use?==<br />
<br />
In general, you will find the latest version on http://www.octave.org/download.html. It is recommended to use the stable version of octave for general use, and the development version if you want the latest features and are willing to tolerate instability.<br />
<br />
A list of user-visible changes since the last release is available in the file NEWS. The file ChangeLog in the source distribution contains a more detailed record of changes made since the last release.<br />
<br />
==On what platforms does Octave run?==<br />
<br />
Octave runs on various Unices—at least Linux and Solaris, Mac OS X, Windows and anything you can compile it on. Binary distributions exist at least for Debian, SUSE, Fedora and RedHat Linuxes (Intel and AMD CPUs, at least), for Mac OS X and Windows' 98, 2000, XP, Vista, and 7.<br />
<br />
Two and three dimensional plotting is fully supported using gnuplot and an experimental OpenGL backend.<br />
<br />
The underlying numerical solvers are currently standard Fortran ones like LAPACK, LINPACK, ODEPACK, the BLAS, etc., packaged in a library of C++ classes. If possible, the Fortran subroutines are compiled with the system's Fortran compiler, and called directly from the C++ functions. If that's not possible, you can still compile Octave if you have the free Fortran to C translator f2c.<br />
<br />
Octave is also free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 3, as published by the Free Software Foundation, or at your option any later version.<br />
<br />
==Why are the developers planning to replace Gnuplot with an OpenGL backend?==<br />
<br />
The development of Octave is committed to being both compatible with Matlab and adding additional features. Toward those ends, the development community has chosen to introduce a native OpenGL backend that supports Matlab handle graphics and its uicontrols. The introduction of the experimental fltk graphics toolkit is the first product of this effort. As of the 3.6.N series, the fltk toolkit is approximately as advanced as is the Gnuplot toolkit. It is not yet decided if the fltk toolkit is to become the default backend, or if another OpenGL implementation will replace Gnuplot as the default backend (An QtOpenGL toolkit is also under development).<br />
<br />
==How can I cite Octave?==<br />
<br />
Pointing to http://www.octave.org is good, because that gives people a direct way to find out more. If citation of a URL is allowed by the publisher you can use this entry:<br />
<br />
<nowiki>@MISC{octave:2012,<br />
author = {{Octave community}},<br />
keywords = {Octave,Software},<br />
title = {{GNU/Octave}},<br />
url = {www.gnu.org/software/octave/},<br />
year = {2012}<br />
}</nowiki><br />
<br />
if you also want to point to a traditional reference, then you can cite the Octave manual:<br />
<br />
<nowiki>@BOOK{eaton:2008,<br />
author = {{John W. Eaton}, {David Bateman} and {Søren Hauberg}},<br />
title = {GNU Octave Manual Version 3},<br />
publisher = {Network Theory Limited},<br />
year = {2008},<br />
isbn = {0-9546120-6-X}<br />
}</nowiki><br />
<br />
<br />
If you want to acknowledge Octave instead of citing it, you can use text such as this:<br />
<br />
<blockquote><br />
The data has been numerically analyzed with the free software package GNU Octave.<br />
</blockquote><br />
<br />
or<br />
<br />
<blockquote><br />
This work made use of the free software package GNU Octave, and the authors are grateful for the support of the Octave development community.<br />
</blockquote><br />
<br />
==When will feature X be released or implemented?==<br />
When it's ready, sooner if you help. Send us patches if you can. We like patches. If you can't, some developers may be convinced to work on your specific problem for some money.<br />
<br />
==How can I get involved in Octave development?==<br />
<br />
Be around. Be social. Participate in the help and maintainers' mailing lists. Find things about Octave you don't like, and start thinking about how to fix them. Many people who now contribute to Octave first spent several years helping in the mailing list before they started to delve into the code. A good way to learn Octave is to understand the problems other people are having with it, so being helpful in the mailing lists not only helps Octave as a whole, but it also prepares you to be a better Octave contributor.<br />
<br />
If you feel ready to dive right into the code, [http://www.gnu.org/software/octave/get-involved.html here are some instructions on how to do so]. Make sure you read {{Path|etc/HACKING}} for guidance.<br />
<br />
We also need help with this wiki and the manual. These are also important tasks. The documentation is easier to patch, so you can discuss improvements to it and submit patches. Or just edit this wiki! <br />
<br />
Accurate bug reporting is also very useful. Find and report bugs [http://www.gnu.org/software/octave/bugs.html], making an attempt to diagnose them. Eventually, you will also know how to fix them. If you want to help with bug reports or patches, subscribe to [https://savannah.gnu.org/mail/?group=octave the bug tracker mailing list]. You'll get updates on all bug activity, and you can jump in when you see something you can help with.<br />
<br />
Also look at our [[Projects]] and [[Summer of Code Project Ideas]] if you need specific inspiration for coding tasks that we would like to get done.<br />
<br />
=Licensing issues=<br />
<br />
==If I write code using Octave do I have to release it under the GPL?==<br />
<br />
The answer depends on precisely how the code is written and how it works.<br />
<br />
Code written entirely in the scripting language of Octave (interpreted code in .m files) may be released under the terms of whatever license you choose.<br />
<br />
Code written using Octave's native plug-in interface (also known as a .oct file) necessarily links with Octave internals and is considered a derivative work of Octave and therefore must be released under terms that are compatible with the GPL.<br />
<br />
Code written using Octave's implementation of the Matlab MEX interface may be released under the terms of whatever license you choose, provided that the following conditions are met:<br />
<br />
# The plugin should not use any bindings that are specific to Octave. In other words, the MEX file must use the MEX interface only, and not also call on other Octave internals. It should be possible in principle to use the MEX file with other programs that implement the MEX interface (e.g., Matlab).<br />
# The MEX file should not be distributed together with Octave in such a way that they effectively create a single work. For example, you should not distribute the MEX file and Octave together in a single package such that Octave automatically loads and runs the MEX file when it starts up. There are other possible ways that you might effectively create a single work; this is just one example.<br />
<br />
A program that embeds the Octave interpreter (e.g., by calling the "octave_main" function), or that calls functions from Octave's libraries (e.g., liboctinterp, liboctave, or libcruft) is considered a derivative work of Octave and therefore must be released under terms that are compatible with the GPL.<br />
<br />
==Since the MEX interface allows plugins to be distributed under terms that are incompatible with the GPL, does this mean that you are encouraging people to write non-free software for Octave?==<br />
<br />
No. The original reason for implementing the MEX interface for Octave was to allow Octave to run free software that uses MEX files (the particular goal was to run SundialsTB in Octave). The intent was to liberate that software from Matlab and increase the amount of free software available to Octave users, not to enable people to write proprietary code for Octave. For the good of the community, we strongly encourage users of Octave to release the code they write for Octave under terms that are compatible with the GPL.<br />
<br />
==I wrote a program that links with Octave libraries and I don't want to release it under the terms of the GPL. Will you change the license of the Octave libraries for me?==<br />
<br />
No. Instead of asking us to change the licensing terms for Octave, we recommend that you release your program under terms that are compatible with the GPL so that the free software community can benefit from your work the same as you have benefited from the work of all the people who have contributed to Octave.<br />
<br />
==Why can't I use code from File Exchange in Octave? It's released under a BSD license!==<br />
<br />
When one downloads code from File Exchange and use it on non Mathworks software (such as Octave), they are violating the Matlab central [http://www.mathworks.co.uk/matlabcentral/termsofuse.html Terms of Use]. While the [http://en.wikipedia.org/wiki/BSD_licenses BSD licenses] does allow one to use such code in Octave, it also allows others to further impose restrictions which Mathworks does through the terms of Use of their site.:<br />
<br />
{{quote|text=Content submitted to File Exchange may only be used with MathWorks products.|sign=Matlab central|source=[http://www.mathworks.co.uk/matlabcentral/termsofuse.html#content Terms of Use 2iii]}}<br />
<br />
While interpretations of this vary, it should be safe to use the code if you contact the author directly and have them send you the code personally.<br />
<br />
If you need that code or think that the code is useful, please write the authors asking them to release under a free license. Some examples of letters/email sent to authors can be found in the page [[Asking_for_package_to_be_released_under_GPL:_examples|Asking for package to be released under GPL: examples]].<br />
<br />
Feel free to remix and reuse, just make sure you use your name!<br />
<br />
=What's new in Octave=<br />
==What's new in version series 3.6.N and 3.7.N of Octave==<br />
<br />
Several new features have been added to the 3.6.N series. The full details are in the NEWS file, but in brief 3.6.N series brings:<br />
<br />
* Perl compatible regular expressions<br />
* A profiler has been added.<br />
* Broadcasting enabled for all built-in binary element-wise operators.<br />
* The statistical distribution functions have been overhauled.<br />
* The functions strread(), textscan(), and textread() have been rewritten.<br />
* Performance of all m-file string functions has been improved.<br />
* The qhull geometry functions have been revamped.<br />
* Date/time functions have been updated.<br />
* Matlab compatible preference functions have been added.<br />
* Various handle graphics functions have been introduced.<br />
* The parfor keyword is now recognized.<br />
<br />
==Features added in version series 3.4.N and 3.5.N of Octave==<br />
Here are some features that have been around since 3.4.N<br />
<br />
* Many improvements to native OpenGL plotting<br />
* ARPACK now distributed with Octave<br />
* Indexing optimisations<br />
* FTP object using libcurl<br />
* Better consistency with ismatrix, issquare, and issymetric<br />
* Function handles aware of overloaded functions<br />
* More efficient matrix division by making a single LAPACK call<br />
* Other optimisations in matrix operations<br />
* bsxfun optimised for basic arithmetic functions<br />
* Matlab-style ignoring of output arguments using {{Codeline|~}}<br />
* Many optimisations of the accumarray function<br />
* Sparse matrix indexing has been rewritten for speed<br />
* Configuration pseudo-variables like page_screen_output accept a "local" option argument to limit their scope to function scope<br />
* The pkg command now accepts a -forge option to pull packages directly from Octave-forge<br />
* Several dlmread improvements<br />
* Octave now uses gnulib for better cross-platform compatibility<br />
<br />
==Features added in version series 3.2.N and 3.3.N of Octave==<br />
Here are some features that have been around since 3.2.N<br />
<br />
* integer types<br />
* fixed point arithmetic<br />
* sparse matrices<br />
* linear programming code based on GLPK<br />
* 64-bit compilation support<br />
* gzipped files and stream and consequently support of Matlab v7 files<br />
* better support for both msvc and mingw<br />
* a fully compatible MEX interface<br />
* many many other minor features and compatibility changes<br />
* an experimental OpenGL graphics toolkit to replace gnuplot<br />
* object orient programming<br />
* block comments<br />
* imwrite and imread (based on the GraphicsMagick library)<br />
* Lazy transpose <br/> Special treatment in the parser of things like "a' * b", where the transpose is never explicitly formed but a flag is rather passed to the underlying LAPACK code.<br />
* Single precision type<br />
* Improved array indexing <br/> The underlying code used for indexing of arrays has been completely rewritten and so the indexing of arrays is now significantly faster.<br />
<br />
==Features available since 2.1.N==<br />
Here are some older features that have been around since 2.1.N:<br />
<br />
* NDArrays<br />
* cells<br />
<br />
==Coming in a future release==<br />
The 3.7.N series is the current development release and will become a 3.8.N release in the future. This series brings the following new features:<br />
<br />
* JIT compiling in the interpreter (speeds up loops)<br />
* A GUI for Octave (based on Qt4)<br />
* The default graphics toolkit is planned to be changed from Gnuplot to an OpenGL fltk toolkit.<br />
<br />
=What documentation exists for Octave?=<br />
<br />
Besides the current wiki, there are other important sources of documentation and help for Octave.<br />
<br />
==What documentation exists for Octave?==<br />
<br />
The Octave distribution includes a 650+ page manual that is also distributed under the terms of the GNU GPL. It is available on the web at http://www.gnu.org/software/octave/doc/interpreter/ and you will also find there instructions on how to order a paper version.<br />
<br />
The complete text of the Octave manual is also available using the GNU Info system via the GNU Emacs, info, or xinfo programs, or by using the {{Codeline|doc}} command to start the GNU info browser directly from the Octave prompt.<br />
<br />
If you have problems using this documentation, or find that some topic is not adequately explained, indexed, or cross-referenced, please report it on http://bugs.octave.org.<br />
<br />
==Getting additional help==<br />
<br />
If you can't find an answer to your question, the help@octave.org mailing list is available for questions related to using, installing, and porting Octave that are not adequately answered by the Octave manual or by this document.<br />
<br />
==User community==<br />
<br />
To subscribe to the list, go to http://www.octave.org/archive.html and follow the link to the subscription page for the list.<br />
<br />
Please do not send requests to be added or removed from the mailing list, or other administrative trivia to the list itself.<br />
<br />
An archive of old postings to the help-octave mailing list is maintained on http://www.octave.org/archive.html.<br />
<br />
You will also find some user advice and code spread over the web. Good starting points are the Octave Wiki http://wiki.octave.org and Octave-Forge http://octave.sourceforge.net<br />
<br />
We also have [http://webchat.freenode.net?channels=octave&uio=d4 an IRC chat room], <code>#octave</code> in Freenode.<br />
<br />
==I think I have found a bug in Octave.==<br />
<br />
“I think I have found a bug in Octave, but I'm not sure. How do I know, and who should I tell?”<br />
<br />
First, see the section [http://www.octave.org/bugs.html on bugs and bug reports in the Octave manual]. When you report a bug, make sure to describe the type of computer you are using, the version of the operating system it is running, and the version of Octave that you are using. Also provide enough code and configuration details of your operating system so that the Octave maintainers can duplicate your bug.<br />
<br />
=How can I obtain Octave?=<br />
<br />
==Source code==<br />
<br />
Source code is available on the Octave development site, where you are sure to get the latest version.<br />
<br />
* http://www.octave.org/download.html<br />
* ftp://ftp.octave.org/pub/octave/<br />
<br />
Since Octave is distributed under the terms of the GPL, you can get Octave from a friend who has a copy, or from the Octave website.<br />
<br />
==Pre-compiled binary packages==<br />
<br />
The Octave project does not distribute binary packages, but other projects do. For an up-to-date listing of packagers, see:<br />
<br />
* http://www.octave.org/download.html<br />
* [[Build From Source]]<br />
<br />
As of today, Octave binaries are available at least on Debian, Ubuntu, RedHat, Suse and Fedora GNU/Linuxen, Mac OS X, Windows' 98, 2000 and XP, Vista, and 7.<br />
<br />
==How do I get a copy of Octave for (some other platform)?==<br />
<br />
Octave currently runs on Unix-like systems, Mac OS X, and Windows. It should be possible to make Octave work on other systems as well. If you are interested in porting Octave to other systems, please contact [mailto:maintainers@octave.org the maintainers' mailing list].<br />
<br />
=Installation issues and problems= <br />
<br />
Octave 3.4 requires approximately 1.3 GB of disk storage to unpack and compile from source (considerably less if you don't compile with debugging symbols). Once installed, Octave requires approximately 355 MB of disk space (again, considerably less if you don't compile with debugging symbols, approximately 50 MB).<br />
<br />
Check out the page [[Installation]] for more detailed information about installing Octave.<br />
<br />
==What else do I need?==<br />
<br />
To compile Octave, you will need a recent version of GNU Make. You will also need GCC 4.3 or later, although GCC 4.4 or later is recommended.<br />
<br />
'''You must have GNU Make to compile octave'''. Octave's Makefiles use features of GNU Make that are not present in other versions of make. GNU Make is very portable and easy to install.<br />
<br />
==Can I compile Octave with another C++ compiler?==<br />
<br />
Yes, but development is done primarily with GCC, so you may hit some incompatibilities. Octave is intended to be portable to any standard conforming compiler. If you have difficulties that you think are bugs, please report them to the http://bugs.octave.org bug tracker, or ask for help on the [mailto:help@octave.org mailing list].<br />
<br />
== How do I install ''all'' Octave packages? ==<br />
Do not do it! Really, there is no reason to do this. Octave Forge has many packages for different needs but it's unlikely that you need all of them. The common misconception is that the more packages one installs, the more complete and powerful its octave installation will be be. However, in the same way one would ''never'' install all perl modules, ruby gems or python packages (because it simply makes no sense), one should not install all octave packages. This isn't desirable and it's not even possible.<br />
<br />
Packages should be installed and loaded selectively. Note that some packages are meant to shadow core functions changing the way Octave works, and different packages can have different implementations of a function with the same name, leading to unpredictable results. Others are just broken or crappy and will break your system. What's worse, some of them packages are even loaded automatically at startup so you may be screwing your octave installation without even realizing it.<br />
<br />
=Coding=<br />
<br />
==What features are unique to Octave?==<br />
<br />
Although most of the Octave language will be familiar to Matlab users, it has some unique features of its own.<br />
<br />
=== Functions defined on the command-line===<br />
Functions can be defined by entering code on the command line, a feature not supported by Matlab. For example, you may type:<br />
<br />
octave:1> function s = hello_string (to_who)<br />
> ## Say hello<br />
> if nargin<1, to_who = "World"; end<br />
> s = ["Hello ",\<br />
> to_who];<br />
> endfunction<br />
octave:2> hello_string ("Moon")<br />
ans = Hello Moon<br />
<br />
As a natural extension of this, functions can also be defined in script files (m-files whose first non-comment line isn't {{Codeline|function out &#61; foo (...)}})<br />
<br />
===Comments with #===<br />
<br />
The pound character, {{Codeline|#}}, may be used to start comments, in addition to {{Codeline|%}}. See the previous example. The major advantage of this is that as {{Codeline|#}} is also a comment character for unix script files, any file that starts with a string like {{Codeline|#! /usr/bin/octave -q}} will be treated as an octave script and be executed by octave.<br />
<br />
===Strings delimited by double quotes "===<br />
<br />
The double quote, {{Codeline|"}}, may be used to delimit strings, in addition to the single quote {{Codeline|'}}. See the previous example. Also, double-quoted strings include backslash interpretation (like C++, C, and Perl) while single quoted are uninterpreted (like Matlab and Perl).<br />
<br />
===Line continuation by backslash===<br />
<br />
Lines can be continued with a backslash, {{Codeline|\}}, in addition to three points {{Codeline|...}}. See the previous example.<br />
<br />
===Informative block closing===<br />
<br />
You may close function, for, while, if, ... blocks with endfunction, endfor, endwhile, ... keywords in addition to using end. As with Matlab, the end (or endfunction) keyword that marks the end of a function defined in a .m file is optional.<br />
<br />
===Coherent syntax===<br />
<br />
Indexing other things than variables is possible, as in:<br />
<br />
octave:1> [3 1 4 1 5 9](3)<br />
ans = 4<br />
octave:2> cos([0 pi pi/4 7])(3)<br />
ans = 0.70711<br />
<br />
In Matlab, it is for example necessary to assign the intermediate result {{Codeline|cos([0 pi pi/4 7])}} to a variable before it can be indexed again.<br />
<br />
===Exclamation mark as not operator===<br />
<br />
The exclamation mark {{Codeline|!}} (aka “Bang!”) is a negation operator, just like the tilde {{Codeline|~}}:<br />
<br />
octave:1> if ! strcmp (program_name, "octave"),<br />
> "It's an error"<br />
> else<br />
> "It works!"<br />
> end<br />
ans = It works!<br />
Note however that Matlab uses the {{Codeline|!}} operator for shell escapes, for which Octave requires using the system command.<br />
<br />
===Increment and decrement operators===<br />
<br />
If you like the {{Codeline|++}}, {{Codeline|+&#61;}} etc operators, rejoice! Octave includes the C-like increment and decrement operators {{Codeline|++}} and {{Codeline|--}} in both their prefix and postfix forms, in addition to {{Codeline|+-}}, {{Codeline|-&#61;}}, {{Codeline|*&#61;}}, {{Codeline|/&#61;}}, {{Codeline|^&#61;}}, {{Codeline|.*&#61;}}, {{Codeline|./&#61;}}, and {{Codeline|.^&#61;}}.<br />
<br />
For example, to pre-increment the variable x, you would write {{Codeline|++x}}. This would add one to x and then return the new value of x as the result of the expression. It is exactly the same as the expression {{Codeline|x &#61; x + 1}}.<br />
<br />
To post-increment a variable x, you would write {{Codeline|x++}}. This adds one to the variable x, but returns the value that x had prior to incrementing it. For example, if x is equal to 2, the result of the expression x++ is 2, and the new value of x is 3.<br />
<br />
For matrix and vector arguments, the increment and decrement operators work on each element of the operand.<br />
<br />
===Unwind-protect===<br />
<br />
In addition to try-catch blocks, Octave supports an alternative form of exception handling modeled after the unwind-protect form of Lisp. The general form of an unwind_protect block looks like this:<br />
<br />
unwind_protect<br />
body<br />
unwind_protect_cleanup<br />
cleanup<br />
end_unwind_protect<br />
<br />
Where body and cleanup are both optional and may contain any Octave expressions or commands. The statements in cleanup are guaranteed to be executed regardless of how control exits body.<br />
<br />
The unwind_protect statement is often used to reliably restore the values of global variables that need to be temporarily changed.<br />
<br />
Matlab can be made to do something similar with their {{Codeline|OnCleanUp}} function that was introduced in 2008a. Octave also has {{Codeline|onCleanup}} since version 3.4.0.<br />
<br />
===Built-in ODE and DAE solvers===<br />
<br />
Octave includes LSODE, DASSL and DASPK for solving systems of stiff ordinary differential and differential-algebraic equations. These functions are built in to the interpreter.<br />
<br />
==How does Octave solve linear systems?==<br />
<br />
In addition to consulting Octave's source for the precise details, you can read the Octave manual for a complete high-level description of the algorithm that Octave uses to decide how to solve a particular linear system, e.g. how the backslash operator {{Codeline|A\x}} will be interpreted. Sections [http://www.gnu.org/software/octave/doc/interpreter/Techniques-Used-for-Linear-Algebra.html#Techniques-Used-for-Linear-Algebra Techniques Used for Linear Algebra] and [http://www.gnu.org/software/octave/doc/interpreter/Sparse-Linear-Algebra.html Linear Algebra on Sparse Matrices] from the manual describe this procedure.<br />
<br />
=How do I...?=<br />
<br />
==How do I execute an Octave script?==<br />
<br />
First of all, make sure you understand [http://www.gnu.org/software/octave/doc/interpreter/Script-Files.html the difference between script files and function files]. If you want to execute a function defined in a file, just call the function like any other Octave function: <code>foo(arg1, arg2);</code><br />
<br />
To execute a script from within Octave, just type its name without the .m extension. Thus, if you have a script called <code>foo.m</code>, just type <code>foo</code> from within Octave to execute it. You have to make sure that the script is in your current path. Type <code>path</code> in Octave to see what this path is, and type <code>pwd</code> to print the working directory (where you're currently standing). The current working directory is referred to as "." in the <code>path</code>.<br />
<br />
If the script name has characters that are not valid for an Octave identifier, or if you do not want to use addpath to add the script's location to the current path, you can use the <code>run</code> function instead:<br />
<br />
octave> run("Script Name With Spaces.m")<br />
octave> run("/opt/local/foo.m")<br />
<br />
An alternative is to run the script from outside Octave by calling Octave from your operating system shell. Unlike calling the script from inside Octave, this also allows you to pass arguments from the shell into the script, which the script can access using the <code>argv</code> command:<br />
<br />
$ octave the-script.m arg1 arg2<br />
<br />
In a Unix environment, if the script has a [http://en.wikipedia.org/wiki/Shebang_%28Unix%29 shebang] (e.g. <code>#!/usr/bin/octave</code>) and executable permissions, you can call it like any other Unix program with arguments:<br />
<br />
$ ./the-script arg1 arg2<br />
<br />
If you call the script from the shell and it's plotting, please note [[#When I try plotting from a script, why am I not seeing anything?|how to plot when running a script from the shell]].<br />
<br />
==do xxxx?==<br />
<br />
You are probably looking for the function ''lookfor''. This function searches the help text of all functions for a specific string and returns a list of functions. Note that by default it will only search the first line of the help text (check ''help lookfor'' at the octave prompt for more). The following example helps to find the function to calculate correlation coefficient in a matrix:<br />
<br />
octave> lookfor correlation<br />
corr2 Returns the correlation coefficient between I and J.<br />
cor Compute correlation.<br />
corrcoef Compute correlation.<br />
spearman Compute Spearman's rank correlation coefficient RHO for each of the variables sp<br />
autocor Return the autocorrelations from lag 0 to H of vector X.<br />
<br />
Also, there's a high chance that the function name has a suggestive name, and so you can try auto-completion to get some hints. For the previous example, typing ''corr'' at the octave promp followed by pressing [Tab] twice would suggest the following:<br />
<br />
octave> corr<br />
corr2 corrcoef<br />
<br />
==How do I erase a figure?== <br />
<br />
closeplot(); <br />
closefig(number)<br />
<br />
==How do I set the number of displayed decimals?==<br />
<br />
octave:1> format long<br />
octave:2> pi<br />
pi = 3.14159265358979<br />
octave:3> format short<br />
octave:4> pi<br />
pi = 3.1416<br />
<br />
==How do I call an octave function from C++?==<br />
<br />
*Here is an untested code snippet for calling rand([9000,1]), modified from a post by HerberFarnsworth? to help-octave on 2003-05-01:<br />
<br />
#include <octave/oct.h><br />
...<br />
ColumnVector NumRands(2);<br />
NumRands(0) = 9000;<br />
NumRands(1) = 1;<br />
octave_value_list f_arg, f_ret;<br />
f_arg(0) = octave_value(NumRands);<br />
f_ret = feval("rand",f_arg,1);<br />
Matrix unis(f_ret(0).matrix_value());<br />
<br />
==How do I change colour/line definition in gnuplot postscript?==<br />
Here is a awk script to get a rainbow colour map<br />
<br />
#!/bin/awk -f<br />
<br />
BEGIN {<br />
split("0 4 6 7 5 3 1 2 8", rainbow, " ");<br />
split("7 3 1 0 2 4 6 5 8", invraim, " ");<br />
}<br />
<br />
$1 ~ /\/LT[0-8]/ {<br />
n = substr($1, 4, 1);<br />
if (n == 0)<br />
lt = "{ PL [] 0.9 0.1 0.1 DL } def";<br />
else if (n == 1)<br />
lt = "{ PL [4 dl 2 dl] 0.1 .75 0.1 DL } def";<br />
else if (n == 2)<br />
lt = "{ PL [2 dl 3 dl] 0.1 0.1 0.9 DL } def";<br />
else if (n == 3)<br />
lt = "{ PL [1 dl 1.5 dl] 0.9 0 0.8 DL } def";<br />
else if (n == 4)<br />
lt = "{ PL [5 dl 2 dl 1 dl 2 dl] 0.1 0.8 0.8 DL } def";<br />
else if (n == 5)<br />
lt = "{ PL [4 dl 3 dl 1 dl 3 dl] 0.9 0.8 0.2 DL } def";<br />
else if (n == 6)<br />
lt = "{ PL [2 dl 2 dl 2 dl 4 dl] 0.5 0.3 0.1 DL } def";<br />
else if (n == 7)<br />
lt = "{ PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.4 0 DL } def";<br />
else if (n == 8)<br />
lt = "{ PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def";<br />
$0 = sprintf("/LT%d %s", rainbow[n+1], lt);<br />
##$0 = sprintf("/LT%x %s", invraim[n+1], lt);<br />
##$0 = sprintf("/LT%x %s", n, lt);<br />
}<br />
<br />
{ print; }<br />
<br />
==How do I tell if a file exists?==<br />
<br />
Look at functions like exist, file_in_path.. and the other functions that their descriptions point to.<br />
<br />
<br />
==How do I create a plot without a window popping up (ie, a plot to a file)?==<br />
<br />
figure(1, "visible", "off");<br />
plot(sin(1:100));<br />
print -deps "/tmp/sin.eps"<br />
<br />
One can set that behaviour as default:<br />
<br />
set(0, 'defaultfigurevisible', 'off');<br />
<br />
== How do I make Octave use more precision? ==<br />
<br />
Octave's default numerical type is IEEE 754 doubles, a.k.a. hardware floats. This type has 52 bits of precision or about 16 decimal digits. It's implemented in your computer's hardware, in your CPU, so it's '''fast'''. This type is assumed throughout for Octave's calculations.<br />
<br />
You can use a few other built-in types. The int64 type will have 63 bits of precision. One bit is used for the sign, but if you don't want to lose that bit, uint64 can be used instead. These types, however, cannot represent numbers as large as the default double type, and can only represent integers. Furthermore, there is no way to represent integer literals, so if you do <br />
<br />
<syntaxhighlight lang="Octave">uint64(18446744073709551610);</syntaxhighlight><br />
<br />
the literal "18446744073709551610" first gets converted to a double precision type, so <code>uint64</code>'s additional precision is lost. Instead, initialise the <code>uint64</code> with smaller numbers and perform a computation to get the larger number you want. E.g., <br />
<br />
<syntaxhighlight lang="Octave">uint64(999999999999999) * 10000</syntaxhighlight><br />
<br />
would produce value 9999999999999990000, which is close to the maximum possible value for the uint64 type, but can't be at the moment input directly, doing uint64(9999999999999990000), due to the mentioned error of rounding.<br />
<br />
Alternatively, one may use arbitrary precision arithmetic, which has as much precision as is practical to hold in your computer's memory. The ''symbolic'' package, when it works, has a vpa() function for arbitrary precision arithmetic. Note that arbitrary precision arithmetic must be implemented '''in software''' which makes it much slower than hardware floats.<br />
<br />
At present, however, the symbolic package is almost useless, since even when you get it to compile and not crash, it cannot handle any array type, which hardly helps for an array-oriented language like Octave. If this limitation is not important to you, attempt to use the symbolic package. If you would like to get this fixed, [http://octave.1599824.n4.nabble.com/Internal-Precision-Symbolic-tp4645257p4645594.html Jordi Gutiérrez Hermoso has volunteered] to fix the package for 5000 USD, which can be obtained from a kickstarter compaign.<br />
<br />
Consider carefully if your problem really needs more precision. Often if you're running out of precision the problem lies fundamentally in your methods being [http://en.wikipedia.org/wiki/Numerical_stability numerically unstable], so more precision will not help you here. If you absolutely must use arbitrary-precision arithmetic, you're at present better off using a CAS instead of Octave. An example of such a CAS is [http://sagemath.org Sage].<br />
<br />
=Common problems=<br />
<br />
==I am running a script that should produce output during execution but I don't see anything until it has finished==<br />
<br />
By default Octave is set to pass its screen output through a pager (usually the default pager is "less") which allows<br />
things such as navigating through the output with arrow keys or searching for text or regular expressions within the output.<br />
The pager only displays the output after it's finished receiving it, so when it is active you'll not be able to see anything until your script has terminated. To change this behavior temporarily or permanently you may want to use one of the options described [http://www.gnu.org/software/octave/doc/interpreter/Paging-Screen-Output.html here].<br />
<br />
==When I try plotting from a script, why am I not seeing anything?==<br />
<br />
If you are running an Octave script that includes a plotting command, the script and Octave may terminate immediately. So the plot window does show up, but immediately closes when Octave finishes execution. Alternatively, if using fltk, the plot window needs a readline loop to show up (the time when Octave is sitting around doing nothing waiting for interactive input).<br />
<br />
A common solution is to put a {{Codeline|pause}} command at the end of your script.<br />
<br />
==How do I get sound input or output in Windows?== <br />
Sound I/O is badly broken on anything that isn't using Linux's Open Sound System. Nowadays, this usually doesn't even include Linux, since OSS is frequently considered "legacy". All of the audio functions in Octave are badly in need of a rewrite so that they actually work.<br />
<br />
==I cannot install a package. Octave complains about a missing mkoctfile.==<br />
<br />
You should normally use your distribution's packages. For Debian and Fedora, Octave package '''foo''' will be a deb or rpm called '''octave-foo''', and you should install that instead using apt or yum.<br />
<br />
If you really need to build Octave packages from source to install them, you'll need mkoctfile. Most distributions split Octave into several packages. The script mkoctfile is then part of a separate package:<br />
<br />
* Debian/Ubuntu: {{Codeline|octave-headers}} or {{Codeline|liboctave-dev}}<br />
<br />
* Fedora: {{Codeline|octave-devel}}<br />
<br />
== I'm having problem XXX using the latest Octave version ==<br />
<br />
Please be more specific. What is the latest version, according to you? If you mean the latest released version, be aware that you may still have an older version due to whatever distribution method you're using. There may be a newer version available that you're not aware of due to the distribution method you're using to get Octave, and in most cases, there is a way to get a newer version via your distribution method (see other wiki pages for [[Octave_for_GNU/Linux|GNU/Linux]], [[Octave_for_MacOS_X|Mac OSX]], and [[Octave_for_Windows|Windows]]).<br />
<br />
If you mean the latest Mercurial revision, please specify which one that is. "Latest tip" is not informative, because from the time you wrote "latest tip" to the time someone reads that message, "latest tip" might have changed meaning. Also, you might be standing on a different commit than what "hg tip" says. The tip may be on a different branch, or you might have updated to a different revision different from what "hg tip" says.<br />
<br />
Instead, report the output of "hg summary" or "hg id". Also please use hashes instead or in addition to revision numbers. Revision numbers are just a convenience and only make sense in your local repo, and might not coincide with what someone sees on their own repo. Hashes are globally unique across all repos.<br />
<br />
If your problem truly persists with the latest version, as indicated [http://www.gnu.org/software/octave/download.html here], then by all means report a bug or ask for help, but don't be surprised if volunteers are less inclined to help you with a problem that only exists in an older version of Octave.<br />
<br />
== Why is this floating point computation wrong? ==<br />
<br />
Floating point arithmetic is an approximation '''in binary''' to arithmetic on real or complex numbers. Just like you cannot represent 1/3 exactly in decimal arithmetic (0.333333 is only a rough approximation to 1/3), you cannot represent some fractions like <math>1/10</math> exactly in base 2. In binary, the representation to one tenth is <math>0.\overline{00011}</math> where the bar indicates that it repeats infinitely (like how <math>1/3 = 0.\overline{3}</math> in decimal). Because this infinite repetition cannot be represented exactly with a finite number of digits, rounding errors occur for values that appear to be exact in decimal but are in fact approximations in binary, such as for example how 0.3 - 0.2 - 0.1 is not equal to zero.<br />
<br />
This isn't an Octave bug. It happens with any program that uses [http://en.wikipedia.org/wiki/IEEE_754 IEEE 754 floating point arithmetic]. The reason why Octave and other programs use IEEE 754 floats is that they are ''fast'', because they are implemented in hardware. Unless you are using very exotic hardware, Octave will use your computer's processor for floating point arithmetic.<br />
<br />
Like death and taxes, rounding errors are a fact of life. You cannot avoid them. You can only move a rounding error from one part of a computation to another, or you can use more precision and delay the rounding error. One way to delay the rounding error is to use arbitrary precision arithmetic, which is inevitably slower as it has to be implemented in software instead of hardware. You may use the vpa function from the symbolic package for this purpose.<br />
<br />
To learn more about floating point arithmetic, consult [http://en.wikipedia.org/wiki/Floating_point_arithmetic its Wikipedia article] or the classical reference [http://floating-point-gui.de/ What Every Computer Scientist Should Know About Floating Point Arithmetic].<br />
<br />
== I have installed a package but still get a "foo undefined" error ==<br />
<br />
You have probably forgotten to load the package. Use {{Codeline|pkg load package-name}} to load it. Most packages are no longer loaded automatically to avoid surprises. See reasoning on related FAQ [[FAQ#How_do_I_install_all_Octave_packages.3F|how do I install all Octave packages]]. If you want a specific package to be loaded by default at startup, consider adding the {{Codeline|pkg load}} command on your {{path|.octaverc}} file.<br />
<br />
=Porting programs from Matlab to Octave=<br />
<br />
People often ask<br />
<br />
<blockquote><br />
I wrote some code for Matlab, and I want to get it running under Octave. Is there anything I should watch out for?<br />
</blockquote><br />
<br />
or alternatively<br />
<br />
<blockquote><br />
I wrote some code in Octave, and want to share it with Matlab users. Is there anything I should watch out for?<br />
</blockquote><br />
<br />
which is not quite the same thing. There are still a number of differences between Octave and Matlab, however in general differences between the two are considered as bugs. Octave might consider that the bug is in Matlab and do nothing about it, but generally functionality is almost identical. If you find an important functional difference between Octave behavior and Matlab, then you should send a description of this difference (with code illustrating the difference, if possible) to http://bugs.octave.org.<br />
<br />
Furthermore, Octave adds a few syntactical extensions to Matlab that might cause some issues when exchanging files between Matlab and Octave users. As both Octave and Matlab are under constant development the information in this section is subject to change at anytime.<br />
<br />
You should also look at the page http://octave.sourceforge.net/packages.html and http://octave.sourceforge.net/doc/ that has a function reference that is up to date. You can use this function reference to see the number of octave function that are available and their Matlab compatibility.<br />
<br />
==How is Octave different from Matlab?==<br />
<br />
The major differences between Octave 3.4.N and Matlab R2010b are:<br />
<br />
===Nested Functions===<br />
Octave has limited support for nested functions. That is<br />
<br />
function y = foo (x)<br />
y = bar(x)<br />
function y = bar (x)<br />
y = ...;<br />
end<br />
end<br />
<br />
is equivalent to<br />
<br />
function y = foo (x)<br />
y = bar(x)<br />
end<br />
function y = bar (x)<br />
y = ...;<br />
end<br />
<br />
The main difference with Matlab is a matter of scope. While nested functions have access to the parent function's scope in Matlab, no such thing is available in Octave, due to how Octave essentially “un-nests” nested functions.<br />
<br />
The authors of Octave consider the nested function scoping rules of Matlab to be more problems than they are worth as they introduce difficult to find bugs as inadvertently modifying a variable in a nested function that is also used in the parent is particularly easy for those not attentive to detail.<br />
<br />
===Differences in core syntax===<br />
<br />
There a few core Matlab syntaxes that are not accepted by Octave, these being<br />
<br />
* Some limitations on the use of function handles. The major difference is related to nested function scoping rules (as above) and their use with function handles.<br />
<br />
* Some limitations of variable argument lists on the LHS of an expression, though the most common types are accepted.<br />
<br />
* Matlab classdef object oriented programming is not yet supported, though work is underway in a branch of the development tree.<br />
<br />
===Differences in core functions===<br />
<br />
A large number of the Matlab core functions (ie those that are in the core and not a toolbox) are implemented, and certainly all of the commonly used ones. There are a few functions that aren't implemented, usually to do with specific missing Octave functionality (GUI, DLL, Java, ActiveX, DDE, web, and serial functions). Some of the core functions have limitations that aren't in the Matlab version. For example the sprandn function can not force a particular condition number for the matrix like Matlab can.<br />
<br />
===Just-In-Time compiler===<br />
<br />
Matlab includes a "Just-In-Time" compiler. This compiler allows the acceleration of for-loops in Matlab to almost native performance with certain restrictions. The JIT must know the return type of all functions called in the loops and so you can't include user functions in the loop of JIT optimized loops. Octave doesn't have a JIT and so to some might seem slower than Matlab. For this reason you must vectorize your code as much as possible. The MathWorks themselves have a good document discussing vectorization at http://www.mathworks.com/support/tech-notes/1100/1109.html.<br />
<br />
===Compiler===<br />
<br />
On a related point, there is no Octave compiler, and so you can't convert your Octave code into a binary for additional speed or distribution. There have been several aborted attempts at creating an Octave compiler. Should the JIT compiler above ever be implemented, an Octave compiler should be more feasible.<br />
<br />
===Graphic handles===<br />
<br />
Up to Octave 2.9.9 there was no support for graphic handles in Octave itself. In the 3.2.N versions of Octave and beyond the support for graphics handles is converging towards full compatibility. The patch function is currently limited to 2-D patches, due to an underlying limitation in gnuplot, but the experimental OpenGL backend is starting to see an implementation of 3-D patches.<br />
<br />
===GUI functions ===<br />
<br />
There are no Matlab compatible GUI functions yet. This might be an issue if you intend to exchange Octave code with Matlab users. There are a number of bindings from Octave to {{Forge|tcl-octave|Tcl/Tk}}, [http://octaviz.sourceforge.net/index.php? VTK] and {{Forge|zenity}} for example, that can be used for a GUI, but these are not Matlab compatible. Work on a Matlab compatible GUI is in an alpha stage in the QtHandles project, which may form part of a future release of Octave.<br />
<br />
===Simulink===<br />
<br />
Octave itself includes no Simulink support. Typically the simulink models lag research and are less flexible, so shouldn't really be used in a research environment. However, some Matlab users that try to use Octave complain about this lack.<br />
<br />
===MEX-Files===<br />
<br />
Octave includes an API to the Matlab MEX interface. However, as MEX is an API to the internals of Matlab and the internals of Octave differ from Matlab, there is necessarily a manipulation of the data to convert from a MEX interface to the Octave equivalent. This is notable for all complex matrices, where Matlab stores complex arrays as real and imaginary parts, whereas Octave respects the C99/C++ standards of co-locating the real/imag parts in memory. Also due to the way Matlab allows access to the arrays passed through a pointer, the MEX interface might require copies of arrays (even non complex ones).<br />
<br />
===Block comments===<br />
<br />
Block comments denoted by {{Codeline|#{}} and {{Codeline|#&#125;}} markers (or {{Codeline|%{}} and {{Codeline|%&#125;}}) are supported by Octave with some limitations. The major limitation is that block comments are not supported within [] or {}.<br />
<br />
===Mat-File format===<br />
<br />
There are some differences in the mat v5 file format accepted by Octave. Matlab recently introduced the "-V7.3" save option which is an HDF5 format which is particularly useful for 64-bit platforms where the standard Matlab format can not correctly save variables. Octave accepts HDF5 files, but is not yet compatible with the "-v7.3" versions produced by Matlab.<br />
<br />
Although Octave can load inline function handles saved by Matlab, it can not yet save them.<br />
<br />
Finally, Some multi-byte Unicode characters aren't yet treated in mat-files.<br />
<br />
===Profiler===<br />
<br />
Thanks to Daniel Kraft's 2011 Google Summer of Code project, Octave has a profiler since version 3.6.0. However, at the moment it only produces text output and has its own makeshift interface for hierarchical profiling.<br />
<br />
===Toolboxes===<br />
<br />
Octave is a community project and so the toolboxes that exist are donated by those interested in them through [[Octave Forge]]. These might be lacking in certain functionality relative to the Matlab toolboxes, and might not exactly duplicate the Matlab functionality or interface.<br />
<br />
===Short-circuit {{Codeline|&}} and {{Codeline|&#124;}} operators===<br />
<br />
The {{Codeline|&}} and {{Codeline|&#124;}} operators in Matlab short-circuit when included in a condition (e.g. an {{Codeline|if}} or {{Codeline|while}} statement) and not otherwise. In Octave only the {{Codeline|&&}} and {{Codeline|&#124;&#124;}} short circuit. Note that this means that<br />
<br />
if (a | b)<br />
...<br />
end<br />
<br />
and<br />
<br />
t = a | b;<br />
if t<br />
...<br />
end<br />
<br />
have different semantics in Matlab. This is really a Matlab bug, but there is too much code out there that relies on this behaviour to change it. Prefer the {{Codeline|&#124;&#124;}} and {{Codeline|&&}} operators in {{Codeline|if}} statements if possible. If you need to use code written for Matlab that depends on this buggy behaviour, you can enable it since Octave 3.4.0 with the following command:<br />
<br />
do_braindead_shortcircuit_evaluation(1)<br />
<br />
Note that the difference with Matlab is also significant when either argument is a function with side effects or if the first argument is a scalar and the second argument is an empty matrix. For example, note the difference between<br />
<br />
t = 1 | []; ## results in [], so...<br />
if (t) 1, end ## in if ([]), this is false.<br />
<br />
and<br />
<br />
if (1 | []) 1, end ## short circuits so condition is true.<br />
<br />
Another case that is documented in the Matlab manuals is that<br />
<br />
t = [1, 1] | [1, 2, 3]; ## error<br />
if ([1, 1] | [1, 2, 3]) 1, end ## OK<br />
<br />
Also Matlab requires the operands of {{Codeline|&&}} and {{Codeline|&#124;&#124;}} to be scalar values but Octave does not (it just applies the rule that for an operand to be considered true, every element of the object must be nonzero or logically true).<br />
<br />
Finally, note the inconsistence of thinking of the condition of an {{Codeline|if}} statement as being equivalent to {{Codeline|all(X(:))}} when {{Codeline|X}} is a matrix. This is true for all cases EXCEPT empty matrices:<br />
<br />
if ([0, 1]) == if (all ([0, 1])) ==> i.e., condition is false.<br />
if ([1, 1]) == if (all ([1, 1])) ==> i.e., condition is true.<br />
<br />
However,<br />
<br />
if ([])<br />
<br />
is not the same as<br />
<br />
if (all ([]))<br />
<br />
because, despite the name, the {{Codeline|all}} is really returning true if none of the elements of the matrix are zero, and since there are no elements, well, none of them are zero. This is an example of [http://en.wikipedia.org/wiki/Vacuous_truth vacuous truth]. But, somewhere along the line, someone decided that {{Codeline|if ([])}} should be false. Mathworks probably thought it just looks wrong to have {{Codeline|[]}} be true in this context even if you can use logical gymnastics to convince yourself that "all" the elements of an empty matrix are nonzero. Octave however duplicates this behavior for {{Codeline|if}} statements containing empty matrices.<br />
<br />
===Solvers for singular, under- and over-determined matrices===<br />
<br />
Matlab's solvers as used by the operators mldivide (\) and mrdivide (/), use a different approach than Octave's in the case of singular, under-, or over-determined matrices. In the case of a singular matrix, Matlab returns the result given by the LU decomposition, even though the underlying solver has flagged the result as erroneous. Octave has made the choice of falling back to a minimum norm solution of matrices that have been flagged as singular which arguably is a better result for these cases.<br />
<br />
In the case of under- or over-determined matrices, Octave continues to use a minimum norm solution, whereas Matlab uses an approach that is equivalent to<br />
<br />
function x = mldivide (A, b)<br />
m = rows(A);<br />
[Q, R, E] = qr(A);<br />
x = [A \ b, E(:, 1:m) * (R(:, 1:m) \ (Q' * b))]<br />
end<br />
<br />
While this approach is certainly faster and uses less memory than Octave's minimum norm approach, this approach seems to be inferior in other ways.<br />
<br />
A numerical question arises: how big can the null space component become, relative to the minimum-norm solution? Can it be nicely bounded, or can it be arbitrarily big? Consider this example:<br />
<br />
m = 10;<br />
n = 10000;<br />
A = ones(m, n) + 1e-6 * randn(m,n);<br />
b = ones(m, 1) + 1e-6 * randn(m,1);<br />
norm(A \ b)<br />
<br />
while Octave's minimum-norm values are around 3e-2, Matlab's results are 50-times larger. For another issue, try this code:<br />
<br />
m = 5;<br />
n = 100;<br />
j = floor(m * rand(1, n)) + 1;<br />
b = ones(m, 1);<br />
A = zeros(m, n);<br />
A(sub2ind(size(A),j,1:n)) = 1;<br />
x = A \ b;<br />
[dummy,p] = sort(rand(1,n));<br />
y = A(:,p)\b;<br />
norm(x(p)-y)<br />
<br />
It shows that unlike in Octave, mldivide in Matlab is not invariant with respect to column permutations. If there are multiple columns of the same norm, permuting columns of the matrix gets you different result than permuting the solution vector. This will surprise many users.<br />
<br />
Since the mldivide (\) and mrdivide (/) operators are often part of a more complex expression, where there is no room to react to warnings or flags, it should prefer intelligence (robustness) to speed, and so the Octave developers are firmly of the opinion that Octave's approach for singular, under- and over-determined matrices is a better choice than Matlab's.<br />
<br />
===Octave extensions===<br />
<br />
The extensions in Octave over Matlab syntax are very useful, but might cause issues when sharing with Matlab users. A list of the major extensions that should be avoided to be compatible with Matlab are:<br />
<br />
Comments in octave can be marked with {{Codeline|#}}. This allows POSIX systems to have the first line as {{Codeline|#! octave -q}} and mark the script itself executable. Matlab doesn't have this feature due to the absence of comments starting with {{Codeline|#}}".<br />
<br />
Code blocks like if, for, while, etc can be terminated with block specific terminations like endif. Matlab doesn't have this and all blocks must be terminated with end.<br />
<br />
Octave has a lisp-like {{Codeline|unwind_protect}} block that allows blocks of code that terminate in an error to ensure that the variables that are touched are restored. You can do something similar with try/catch combined with {{Codeline|rethrow (lasterror ())}} in Matlab, however rethrow and lasterror are only available in Octave 2.9.10 and later. Matlab 2008a also introduced {{Codeline|OnCleanUp}} that is similar to {{Codeline|unwind_protect}}, except that the object created by this function has to be explicitly cleared in order for the cleanup code to run.<br />
<br />
Note that using try/catch combined with {{Codeline|rethrow (lasterror ())}} can not guarantee that global variables will be correctly reset, as it won't catch user interrupts with Ctrl-C. For example<br />
<br />
global a<br />
a = 1;<br />
try<br />
_a = a;<br />
a = 2<br />
while true<br />
end<br />
catch<br />
fprintf ('caught interrupt\n');<br />
a = _a;<br />
rethrow (lasterror());<br />
end<br />
<br />
compared to<br />
<br />
global a<br />
a = 1;<br />
unwind_protect<br />
_a = a;<br />
a = 2<br />
while true<br />
end<br />
unwind_protect_cleanup<br />
fprintf ('caught interrupt\n');<br />
a = _a;<br />
end<br />
<br />
Typing Ctrl-C in the first case returns the user directly to the prompt, and the variable ''a'' is not reset to the saved value. In the second case the variable ''a'' is reset correctly. Therefore Matlab gives no safe way of temporarily changing global variables.<br />
<br />
Indexing can be applied to all objects in Octave and not just variables. Therefore {{Codeline|sin(x)(1:10)}} for example is perfectly valid in Octave but not Matlab. To do the same in Matlab you must do {{Codeline|y &#61; sin(x); y &#61; y([1:10]);}}<br />
<br />
Octave has the operators {{Codeline|++}}, {{Codeline|–}}, {{Codeline|-&#61;}}, {{Codeline|+&#61;}}, {{Codeline|*&#61;}}, etc. As Matlab doesn't, if you are sharing code these should be avoided.<br />
<br />
Character strings in Octave can be denoted with double or single quotes. There is a subtle difference between the two in that escaped characters like {{Codeline|\n}} (newline), {{Codeline|\t}} (tab), etc are interpreted in double quoted strings but not single quoted strings. This difference is important on Windows platforms where the {{Codeline|\}} character is used in path names, and so single quoted strings should be used in paths. Matlab doesn't have double quoted strings and so they should be avoided if the code will be transferred to a Matlab user.<br />
<br />
=GUI=<br />
This is a small section but it's probably one of the most frequent questions.<br />
<br />
==Is there a GUI for Octave?==<br />
No.<br />
<br />
==Is there a GUI planned for Octave?==<br />
Yes, and is already in development. You can download the [http://www.gnu.org/software/octave/get-involved.html Octave repository] and compile the development branch yourself (it seems to be stable enough for use and the 3.6.2 binaries for windows already have it). Testing is always welcomed, and patches even more. Note that despite being called Octave GUI, it is ''not'' a separate project. It is simply the ''Octave GUI'', the Octave Graphical User Interface, just like the Octave prompt, Octave interpreter, etc are not separate projects (not to be confused with the completely unrelated but similarly named, GUI Octave project).<br />
<br />
==How come there's still no GUI for Octave?==<br />
The Octave prompt is really really good and that's what the Octave developers use. Octave is a community project which means that it has the functionalities that its users are willing to spend time implementing. Since Octave developers do not need a GUI (some actually would not use one if it existed), they have no reason to make one. Also, many people on the community are of the opinion that using a GUI slows down the learning of the language.<br />
<br />
==I want Octave developers to work on a GUI?==<br />
If you would like the Octave developers to implement a GUI for you, consider the same route taken by others that want a specific function/capability to be implemented. Some of the Octave developers will work as coders for hire. Ask on the [http://www.gnu.org/software/octave/get-involved.html maintainers mailing list]. This is not unlike paying a builder to add an extra room to your house. The fact there is no GUI in Octave only shows that there is not enough interest for it (despite the amount of time people asking for it).<br />
<br />
==What about all the Octave GUIs I find on Google?==<br />
None of the GUIs for Octave that have been developed thus far are part of Octave and there is a reason for it. All of them fail at a very important point, integration with Octave. They treat Octave as a foreign black box using pipes for communication, an approach that is bound to eventually fail. This includes QtOctave (now abandoned and incompatible with newer versions of Octave), Xoctave (which is proprietary and commercial) and GUI Octave (which is proprietary and the author is not interested to share his code to preserve its "artistic integrity").<br />
<br />
Quint was a project for an Octave GUI that actually tried to do it right. Eventually it was merged into the Octave repository and is now under development under the name Octave GUI (this is not a separate project anymore, it is simply the ''Octave GUI'' and not to be confused with the completely unrelated but similarly-named, GUI Octave project).<br />
<br />
==QtOctave has been abandoned. Why are you working on yet another GUI rather than trying to fix QtOctave?==<br />
Read previous question. The approach taken by QtOctave for interacting with Octave is bound to fail. Yes, it could be fixed and made to work again for the latest octave release but this would not be a permanent fix and would eventually fail again. A [http://octave-gsoc2012.blogspot.ie/2012/06/why-not-take-existing-gui.html longer explanation] has already been written as part of GSoC2012.<br />
<br />
Yes, QtOctave is a useful tool, looks beautiful and we are thankful to its developers for working on such a nice tool plus making it libre. We are in no way saying the opposite. However, it will ''never'' be stable. The Octave GUI being developed now uses code from many different projects, we are trying to not reinvent the wheel. But we want something that will achieve stability.<br />
<br />
==What about GUI Octave?==<br />
GUI Octave is not part of the Octave project despite its very deceptive name. Not only is a different project, it is also very inappropriate for this piece of closed-source software to occupy the name "GUI Octave" with the hostile anti free-software stance the developer has taken. It advertises itself as a "completely free" wrapper to "GNU Octave". It must be explicit that it is not free software as understood by GNU. This is deceptive.<br />
<br />
==How can I know more about Octave GUI?==<br />
This is being developed as part of the Octave project so subscribe to the [http://www.gnu.org/software/octave/get-involved.html maintainers mailing list]. When you checkout the Octave repository, you'll find the GUI source on the development/default [http://hg.savannah.gnu.org/hgweb/octave/branches branch].<br />
<br />
<!-- You may also read [http://octave-gsoc2012.blogspot.ca/ Jacob's blog posts about the topic.] --><br />
<br />
==I'm having problem XXX using GUI Octave, XOctave, QtOctave, etc?==<br />
Install Octave only, without any of the non-supported by GUIs and see if the problem disappears.</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Octave_for_macOS&diff=2779Octave for macOS2013-05-23T19:49:57Z<p>Bpabbott: /* Installing a Mac OS X Bundle */ fix link</p>
<hr />
<div>GNU Octave is primarily developed on GNU/Linux and other POSIX conformant systems. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
About version numbers (as of May 2012):<br />
*The 3.6.x are current releases.<br />
*The 3.4.x are previous releases.<br />
*The 3.2.x are very old releases.<br />
<br />
==Manual Installation from Source==<br />
<br />
The page [[Octave for Mac]] provides minimalistic instructions for building Octave from source on Mac OS X. Additional [http://www.gnu.org/software/octave/support.html support] for those who need assistance in building Octave is available.<br />
<br />
==Package Managers==<br />
<br />
A package manager is a software tool to automate the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites.<br />
Packages are distributions of software, applications and data. Packages also contain metadata, such as the software's name, description of its purpose, version number, vendor, checksums, and a list of dependencies necessary for the software to run properly. Upon installation, metadata is stored in a local package database.<br />
Operating systems based on Linux and other Unix-like systems typically consist of hundreds or even thousands of distinct software packages; in the former case, a package management system is a convenience, in the latter case it becomes essential.<br />
<br />
There are three reputable package managers available for Mac OS X. GNU Octave for Mac OS X is readily available using [http://en.wikipedia.org/wiki/Package_management_system package managers] such as [http://www.finkproject.org/ Fink], [http://www.macports.org/ MacPorts], and [http://mxcl.github.com/homebrew/ Homebrew].<br />
<br />
The most recent version of Fink's Octave package, MacPorts' Octave port, and Homebrew's Octave formula are generally not the same. Please check the web sites for these package managers to determine if the version of Octave you desire is available.<br />
<br />
===XCode Dependency===<br />
<br />
Each package manager requires that XCode be installed. In part this is to provide an initial set of development tools. It *may* be possible to substitute the [https://github.com/kennethreitz/osx-gcc-installer Mac OS X gcc Installer] by Kenneth Reitz, but this alternative has not yet been tested. If any curious/industrious users experiment with using Kenneth's solution over Apple's XCode, please let Octave's developers know of the results. Or, if you prefer, just update the itemized list below. It is recommended that users with XCode already installed avoid installing Kenneth's solution, as it may break your existing XCode installation.<br />
* Fink: The Mac OS X gcc Installer has not been tested.<br />
* MacPorts: The Mac OS X gcc Installer has not been tested.<br />
* Homebrew: The Mac OS X gcc Installer has not been tested.<br />
<br />
===Fink===<br />
<br />
[http://www.finkproject.org/ The Fink project] is an effort to port and package open-source Unix programs to Mac OS X. Fink uses [http://en.wikipedia.org/wiki/Dpkg dpkg] and [http://en.wikipedia.org/wiki/Advanced_Packaging_Tool APT] ([http://en.wikipedia.org/wiki/Debian Debian's] package management system), as well as its own frontend program, fink (which is implemented as a set of [http://en.wikipedia.org/wiki/Perl_module Perl modules]).<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from XCode's Apple Menu > Preferences > Downloads.<br />
*Follow [http://www.finkproject.org/download/srcdist.php Fink's installation instructions]. For those who prefer it, there is a GUI available for Fink, [http://finkcommander.sourceforge.net Fink Commander].<br />
*Fink has excellent support for Octave and includes recent as well as dated versions. A list of what Fink has available for Octave is [http://pdb.finkproject.org/pdb/browse.php?summary=octave here]. To install the latest Octave, type {{Codeline|<nowiki>sudo fink install octave</nowiki>}} at the Terminal's command line. For those running the 64 bit version of Fink, it is recommended that {{Codeline|octave-atlas}} be installed instead as there are some bugs/features with Apple's vecLib for the X86_64 architecture. Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours.<br />
* Fink should also be used to install [[http://octave.sourceforge.net/packages.php packages] for Octave. For example, the control systems package for Lion may be installed by typing {{Codeline|fink install control-atlas-oct362}} at a terminals command line.<br />
<br />
For the {{Codeline|doc()}} function to be supported by Octave, either the unversioned {{Codeline|octave}}, {{Codeline|octave-atlas}}, or {{Codeline|octave-ref}} package must be installed. Essentially, those features used at run-time which don't have a version somewhere in the file path are included in these packages.<br />
<br />
===MacPorts===<br />
<br />
[http://www.macports.org/ MacPorts], formerly called DarwinPorts, is a package management system that simplifies the installation of software on the Mac OS 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.<br />
<br />
====Simple Installation Instructions====<br />
<br />
*Install XCode via the Mac App Store.<br />
*Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
*MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|sudo port install octave-devel +atlas+docs}} 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.<br />
*The variant installed may be important to the user's experience. The available variants for {Codeline|octave-devel} are displayed by typing {{Codeline|port variants octave-devel}}. It is recommended that the user include {{Codeline|+atlas+docs}}. This will avoid bugs present in Apple's vecLib and enable support for Octave's {{Codeline|doc()}} function.<br />
<br />
===Homebrew===<br />
<br />
Homebrew is a package management system that simplifies the installation of software on Mac OS X. It is a free/open source software project to simplify installation of other free/open source software. It is similar in aim and function to MacPorts and Fink. It was written by Max Howell and has gained popularity in the Ruby on Rails community and earned praise for its extensibility.<br />
<br />
====Simple Installation Instructions====<br />
<br />
First, install Homebrew:<br />
*Install XCode via the Mac App Store.<br />
** Once installed, install the Command Line Tools from XCode's Apple Menu > Preferences > Downloads.<br />
*Follow [https://github.com/mxcl/homebrew/wiki/installation Homebrew's installation instructions].<br />
* Import the scientific computing packages, including Octave:<br />
<pre>brew tap homebrew/science</pre><br />
<br />
To install Octave, update to the latest package definitions, install {{Codeline|gfortran}}, and then Octave:<br />
<pre>brew update && brew upgrade<br />
brew install gfortran<br />
brew install octave</pre><br />
<br />
Note: If brew complains about not having a formula for octave, the following command should fix it:<br />
<pre>brew tap --repair</pre><br />
<br />
The command below upgrades Octave and its dependencies to the latest Homebrew-supported versions:<br />
brew update && brew upgrade<br />
<br />
Octave has many dependencies which will be downloaded and installed prior to Octave. The entire installation process can take a few hours.<br />
Note: On Snow Leopard, Octave requires a X server. If you install without, Homebrew will guide you to the XQuartz project (https://xquartz.macosforge.org) where you can download this.<br />
<br />
You might find that you need to add:<br />
<br />
<pre>setenv ("GNUTERM", "X11")</pre><br />
<br />
to your octaverc file, normally located at {{Codeline|/usr/local/share/octave/site/m/startup}}.<br />
<br />
In case of trouble, see the [https://github.com/mxcl/homebrew/wiki/troubleshooting Homebrew Troubleshooting Guide], which assists in diagnosing problems and craft useful bug reports. Bugs may be reported at [https://github.com/Homebrew/homebrew-science/issues?state=open Homebrew-science's issue tracker].<br />
<br />
==Create a launcher app with AppleScript==<br />
<br />
* Open the "AppleScript Editor" application<br />
* write the following text in the editor window:<br />
<br />
<code><br />
<br />
tell application "Terminal"<br />
do script "/path/to/octave; exit"<br />
end tell<br />
<br />
</code><br />
<br />
or if Octave is in your default path:<br />
<br />
<code><br />
tell application "Terminal"<br />
do script "`which octave`; exit"<br />
end tell<br />
</code><br />
<br />
* Select "Save as ..." from the "File" menu<br />
* In the menu that appears, select "Application" from the "File format" menu, then navigate to the "Applications" folder and save your script there as "Octave.app"<br />
<br />
To change the application icon <br />
<br />
* Open [http://wiki.octave.org/File:Icon.png this link] in a web browser, right-click and select "copy image".<br />
* Select "Octave.app" in the Finder, then press command-i to bring up the file info dialog.<br />
* In the file info dialog, select the icon (in the top left) and press command-v to paste the Octave icon over it.<br />
<br />
==Installing a Mac OS X Bundle==<br />
<br />
A reliable App bundle for Octave on Mac OS X is not presently available. The developers would like to be able to provide an App bundle, but need volunteers to support the effort. An approach for producing an App Bundle using [http://www.macports.org MacPorts] is being documented [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|here]]. This approach shows promise, but a few problems must be resolved before a bundle will become available.<br />
<br />
Octave and many other software packages may be installed and updated using one of the three package managers available for Mac OS X. To install using a package manager, see the section on [[Octave_for_MacOS_X#Package_Managers|Package Managers]].<br />
<br />
{{Warning|Octave-Forge does have [https://sourceforge.net/projects/octave/files/Octave%20MacOSX%20Binary/ App bundles] for old Octave, versions and have problems running on Mac OS 10.6 and above. The latest App bundle does not provide full support for the printing, or the documentation features of Octave. Other features may be missing as well. For individuals who'd like to use it anyway please carefully follow the instructions for [[Installing Mac OS X Bundle]].}}</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2776Create a MacOS X App Bundle Using MacPorts2013-05-19T09:10:14Z<p>Bpabbott: /* Produce a DMG for Octave and its dependencies */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command. For macports 2.1.3, having the <code>xorg-libx11</code> as a dependency for Octave has been found to cause the <code>port mdmg octave-local ...</code> command to fail. The <code>xorg-libx11</code> dependency may be avoided by specifying <code>-x11+no_x11-docs</code> as variants and by dropping the dependence to <code>transfig</code> (which has <code>xpm</code> as a dependency and <code>xpm</code> depends upon several <code>xorg-*</code> ports.<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] has been prepared, which does not depend upon METIS and does depend upon <code>epstool</code>, and <code>pstoedit</code> (there is no <code>transfig</code> dependency since it generates an <code>xorg-libx11</code> dependency). After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
<span style="color: green;"> If run from a fresh macports installation (i.e. no ports have yet been installed), then this command should complete with no errors.</span> If ports have already been installed, then errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. <span style="color: red;">One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave </span> (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated (<code> gtk2 </code> in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's <code>work</code> directory. If a local portfile is used, a symbolic link to the <code>work</code> directory will be placed in the directory containing the portfile. In this instance the DMG can be found in <code>~/ports/math/octave-local/work</code>.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle <code>texlive</code> port as well as <code>xorg-libx11</code> and several other <code>xorg-*</code> ports.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2775Create a MacOS X App Bundle Using MacPorts2013-05-19T09:08:52Z<p>Bpabbott: /* Produce a DMG for Octave and its dependencies */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command. For macports 2.1.3, having the <code>xorg-libx11</code> as a dependency for Octave has been found to cause the <code>port mdmg octave-local ...</code> command to fail. The <code>xorg-libx11</code> dependency may be avoided by specifying <code>-x11+no_x11-docs</code> as variants and by dropping the dependence to <code>transfig</code> (which has <code>xpm</code> as a dependency and <code>xpm</code> depends upon several <code>xorg-*</code> ports.<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] has been prepared, which does not depend upon METIS and does depend upon <code>epstool</code>, and <code>pstoedit</code> (there is no <code>transfig</code> dependency since it generates an <code>xorg-libx11</code> dependency). After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
<span style="color: green;"> If run from a fresh macports installation (i.e. no ports have yet been installed), then this command should complete with no errors.</span> If ports have already been installed, then errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. <span style="color: red;">One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave </span> (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated (<code> gtk2 </code> in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's <code>work</code> directory. If a local portfile is used, a symbolic link to the <code>work</code> directory will be placed in the directory containing the portfile. In this instance the DMG can be found in <code>~/ports/math/octave-local/work</code>.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2774Create a MacOS X App Bundle Using MacPorts2013-05-19T09:08:18Z<p>Bpabbott: /* Produce a DMG for Octave and its dependencies */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command. For macports 2.1.3, having the <code>xorg-libx11</code> as a dependency for Octave has been found to cause the <code>port mdmg octave-local ...</code> command to fail. The <code>xorg-libx11</code> dependency may be avoided by specifying <code>-x11+no_x11-docs</code> as variants and by dropping the dependence to <code>transfig</code> (which has <code>xpm</code> as a dependency and <code>xpm</code> depends upon several <code>xorg-*</code> ports.<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] has been prepared, which does not depend upon METIS and does depend upon <code>epstool</code>, and <code>pstoedit</code> (there is no <code>transfig</code> dependency since it generates an <code>xorg-libx11</code> dependency). After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
<span style="color: green;"> If run from a fresh macports installation (i.e. no ports have yet been installed), then this command should complete with no errors.</span> If ports have already been installed, then errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. <span style="color: red;">One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave </span> (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated (<code> gtk2 </code> in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's <code>work</code> directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in <code>~/ports/math/octave-local/work</code>.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2773Create a MacOS X App Bundle Using MacPorts2013-05-19T09:07:25Z<p>Bpabbott: /* Produce a DMG for Octave and its dependencies */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command. For macports 2.1.3, having the <code>xorg-libx11</code> as a dependency for Octave has been found to cause the <code>port mdmg octave-local ...</code> command to fail. The <code>xorg-libx11</code> dependency may be avoided by specifying <code>-x11+no_x11-docs</code> as variants and by dropping the dependence to <code>transfig</code> (which has <code>xpm</code> as a dependency and <code>xpm</code> depends upon several <code>xorg-*</code> ports.<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] has been prepared, which does not depend upon METIS and does depend upon <code>epstool</code>, and <code>pstoedit</code> (there is no <code>transfig</code> dependency since it generates an <code>xorg-libx11</code> dependency). After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
<span style="color: green;"> If run from a fresh macports installation (i.e. no ports have yet been installed), then this command should complete with no errors.</span> If ports have already been installed, then errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. <span style="color: red;">One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave </span> (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated (<code> gtk2 </code> in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile&diff=2772Prototype MacPorts PortFile2013-05-19T09:03:03Z<p>Bpabbott: </p>
<hr />
<div>This prototype [http://www.macports.org/ MacPorts] portfile is intended to be used to produce a [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|Octave App bundle for MacOS X]]. Before using it, please verify that the ''version'' number of Octave is correct. If a change is made to the file, it is recommended that the ''revision'' number be incremented to ensure that MacPorts recognizes that the port is outdated and in need of being upgraded.<br />
<br />
This portfile deviates significantly from the Octave portfile provided by MacPorts. Specifically, this portfile has fltk-devel, epstool, pstoedit, and transfig as required dependencies. In addition, METIS has been removed, as it's license is not compatible with GPL. Since the <code>transfig</code> port ultimately includes <code>xord-libx11</code> which triggers an error during the <code>port mdmg</code> the <code>transfig</code> port has also been removed.<br />
<br />
<nowiki># -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4<br />
# $Id: Portfile 106065 2013-05-14 09:28:04Z ryandesign@macports.org $<br />
<br />
PortSystem 1.0<br />
<br />
name octave-local<br />
version 3.6.4<br />
revision 3<br />
conflicts octave, octave-devel<br />
categories math science<br />
maintainers michaelld openmaintainer<br />
license GPL-3<br />
platforms darwin<br />
<br />
description a Matlab-like environment for numerical analysis<br />
long_description Octave provides a convenient command line interface \<br />
for solving linear and nonlinear problems numerically, \<br />
using a language that is mostly compatible with Matlab. \<br />
It is easily extensible and customizable via \<br />
user-defined functions or using dynamically loaded \<br />
modules written in e.g. C++, C or Fortran.<br />
<br />
homepage http://www.gnu.org/software/octave/<br />
master_sites gnu:octave<br />
dist_subdir octave<br />
distname octave-${version}<br />
use_bzip2 yes<br />
<br />
checksums rmd160 b0356f0c5d9366b8129d72ac58bbde837fee1a95 \<br />
sha256 fa185df9591f5d740f4d37ff6eaf06db576fdd3e0ddd9d0737365799e5d1c962<br />
<br />
depends_build port:bison \<br />
port:flex \<br />
port:gawk \<br />
port:gperf \<br />
port:grep \<br />
path:bin/perl:perl5 \<br />
port:pkgconfig \<br />
port:texinfo<br />
<br />
depends_lib port:curl \<br />
port:fftw-3 \<br />
port:fftw-3-single \<br />
port:ftgl \<br />
port:ghostscript \<br />
port:glpk \<br />
port:GraphicsMagick \<br />
port:gnuplot \<br />
port:gsed \<br />
port:hdf5-18 \<br />
port:less \<br />
port:ncurses \<br />
port:pcre \<br />
port:qhull \<br />
port:qrupdate \<br />
port:readline \<br />
port:SuiteSparse<br />
<br />
depends_run port:epstool \<br />
port:pstoedit<br />
<br />
# allow us to disable checking for FLTK<br />
# via the environment variable "FLTK_CONFIG"<br />
patchfiles-append patch-configure.diff<br />
<br />
universal_variant no<br />
<br />
# octave requires a fortran compiler, so require the use of one of the<br />
# MacPorts GCC ports (for now).<br />
<br />
compiler.blacklist gcc-3.3 gcc-4.0 gcc-4.2 llvm-gcc-4.2 \<br />
apple-gcc-4.0 apple-gcc-4.2 clang macports-clang-2.9 \<br />
macports-clang-3.0 macports-clang-3.1 macports-clang-3.2 \<br />
macports-clang-3.3 macports-llvm-gcc-4.2<br />
<br />
configure.args --disable-dependency-tracking \<br />
--without-x \<br />
--disable-docs \<br />
--with-cholmod="-lcholmod" \<br />
--with-umfpack="-lumfpack -lSuiteSparse"<br />
<br />
# octave uses a number of other ports to create sources from template:<br />
# perl, gawk, gsed, flex, bison, texinfo. Make sure these are the<br />
# MacPorts' versions. Python is not used if perl is available, so<br />
# clear it out. grep is checked for in 'configure', but not used<br />
# except inside that script; include it here for completion.<br />
configure.perl ${prefix}/bin/perl<br />
configure.python ' '<br />
configure.awk ${prefix}/bin/gawk<br />
configure.env-append GREP="${prefix}/bin/grep" \<br />
FLTK_CONFIG=no \<br />
SED="${prefix}/bin/gsed" \<br />
TEXI2DVI="${prefix}/bin/texi2dvi" \<br />
TEXI2PDF="${prefix}/bin/texi2pdf" \<br />
APPLE_CXX="/usr/bin/g++"<br />
configure.cppflags<br />
configure.ldflags<br />
<br />
pre-build {<br />
reinplace "/'display\.cc'/s@\$(CXX)@\$(APPLE_CXX)@g" \<br />
${worksrcpath}/src/Makefile<br />
}<br />
<br />
build.env-append APPLE_CXX="/usr/bin/g++"<br />
<br />
test.run yes<br />
test.target check<br />
<br />
platform darwin 11 {<br />
# 10.7 requires an extra patch; this patch will break the build on<br />
# 10.6 and prior, so apply it only under 10.7.<br />
patchfiles-append patch-src-display.cc.diff<br />
}<br />
<br />
platform darwin 12 {<br />
# In 10.8 patch is required as above, also<br />
# the LANG environment variable needs to<br />
# be set to "C" otherwise /usr/bin/sed<br />
# fails with an error, if you installed gsed<br />
# with default name this should have no effect.<br />
<br />
patchfiles-append patch-src-display.cc.diff<br />
build.args-append LANG="C"<br />
}<br />
<br />
<br />
variant gcc43 description {build with the macports gcc43 toolchain} conflicts gcc48 gcc47 gcc46 gcc45 gcc44 g95 {}<br />
<br />
variant gcc44 description {build with the macports gcc44 toolchain} conflicts gcc48 gcc47 gcc46 gcc45 gcc43 g95 {}<br />
<br />
variant gcc45 description {build with the macports gcc45 toolchain} conflicts gcc48 gcc47 gcc46 gcc44 gcc43 g95 {}<br />
<br />
variant gcc46 description {build with the macports gcc46 toolchain} conflicts gcc48 gcc47 gcc45 gcc44 gcc43 g95 {}<br />
<br />
variant gcc47 description {build with the macports gcc47 toolchain} conflicts gcc48 gcc46 gcc45 gcc44 gcc43 g95 {}<br />
<br />
variant gcc48 description {build with the macports gcc48 toolchain} conflicts gcc47 gcc46 gcc45 gcc44 gcc43 g95 {}<br />
<br />
variant g95 description {build with g95} conflicts gcc48 gcc47 gcc46 gcc45 gcc44 gcc43 {<br />
depends_build-append port:g95<br />
configure.f77 "${prefix}/bin/g95"<br />
}<br />
<br />
variant atlas description {use BLAS from ATLAS} conflicts accelerate {<br />
depends_lib-append port:atlas<br />
}<br />
<br />
variant accelerate description {use BLAS from Apple's Accelerate.framework} conflicts atlas {<br />
depends_lib-append port:dotwrp<br />
configure.args-append --with-blas="-ldotwrp -Wl,-framework -Wl,Accelerate"<br />
configure.args-append --with-lapack="-Wl,-framework -Wl,Accelerate"<br />
}<br />
<br />
if {[variant_isset g95]} {<br />
default_variants +accelerate<br />
} elseif {![variant_isset accelerate]} {<br />
default_variants +atlas<br />
}<br />
<br />
# check for GCC / G95 variants. The default here must match the<br />
# default found in the 'atlas' port (but, this is not checked for).<br />
<br />
# check for setting the default variant (gcc47)<br />
<br />
if { ![variant_isset gcc43] && ![variant_isset gcc44] && \<br />
![variant_isset gcc45] && ![variant_isset gcc46] && \<br />
![variant_isset gcc47] && ![variant_isset gcc48] && \<br />
![variant_isset g95] } {<br />
default_variants +gcc47<br />
}<br />
<br />
# check if the user disabled just the default variant: -gcc47<br />
<br />
if { ![variant_isset gcc43] && ![variant_isset gcc44] && \<br />
![variant_isset gcc45] && ![variant_isset gcc46] && \<br />
![variant_isset gcc47] && ![variant_isset gcc48] && \<br />
![variant_isset g95] } {<br />
pre-fetch {<br />
error "You must select one of the compiler variants."<br />
}<br />
}<br />
<br />
set gcc_version ""<br />
if {[variant_isset gcc43]} {<br />
set gcc_version "4.3"<br />
} elseif {[variant_isset gcc44]} {<br />
set gcc_version "4.4"<br />
} elseif {[variant_isset gcc45]} {<br />
set gcc_version "4.5"<br />
} elseif {[variant_isset gcc46]} {<br />
set gcc_version "4.6"<br />
} elseif {[variant_isset gcc47]} {<br />
set gcc_version "4.7"<br />
} elseif {[variant_isset gcc48]} {<br />
set gcc_version "4.8"<br />
}<br />
<br />
if {${gcc_version} != ""} {<br />
set gcc_version_join [join [split ${gcc_version} "."] ""]<br />
configure.ldflags "-L${prefix}/lib/gcc${gcc_version_join}"<br />
configure.ldflags-append -lstdc++ \<br />
-lgfortran<br />
depends_build-append port:gcc${gcc_version_join}<br />
configure.compiler macports-gcc-${gcc_version}<br />
}<br />
<br />
variant docs description {Enable creation and installation of documentation} {<br />
depends_run-append port:texlive-basic<br />
# latex needed for lcircle10 font etc.<br />
depends_build-append port:texlive-latex<br />
configure.args-replace s|--disable-docs|--enable-docs|<br />
}<br />
<br />
variant x11 description {Enable use of X11} {<br />
configure.args-replace s|--without-x|--with-x|<br />
configure.args-append --x-includes=${prefix}<br />
}<br />
<br />
variant fltk description {Include FLTK for graphical front-end} {<br />
depends_lib-append path:lib/libfltk.dylib:fltk<br />
configure.env-delete FLTK_CONFIG=no<br />
}<br />
<br />
livecheck.type regex<br />
livecheck.url http://www.gnu.org/software/octave/news.html<br />
livecheck.regex Version (\\d+(\\.\\d+)*)<br />
<br />
</nowiki></div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile&diff=2771Prototype MacPorts PortFile2013-05-19T09:00:43Z<p>Bpabbott: new portfile for Octave 3.6.4</p>
<hr />
<div>This prototype [http://www.macports.org/ MacPorts] portfile is intended to be used to produce a [[Create_a_MacOS_X_App_Bundle_Using_MacPorts|Octave App bundle for MacOS X]]. Before using it, please verify that the ''version'' number of Octave is correct. If a change is made to the file, it is recommended that the ''revision'' number be incremented to ensure that MacPorts recognizes that the port is outdated and in need of being upgraded.<br />
<br />
This portfile deviates significantly from the Octave portfile provided by MacPorts. Specifically, this portfile has fltk-devel, epstool, pstoedit, and transfig as required dependencies. In addition, METIS has been removed, as it's license is not compatible with GPL.<br />
<br />
<nowiki># -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4<br />
# $Id: Portfile 106065 2013-05-14 09:28:04Z ryandesign@macports.org $<br />
<br />
PortSystem 1.0<br />
<br />
name octave-local<br />
version 3.6.4<br />
revision 3<br />
conflicts octave, octave-devel<br />
categories math science<br />
maintainers michaelld openmaintainer<br />
license GPL-3<br />
platforms darwin<br />
<br />
description a Matlab-like environment for numerical analysis<br />
long_description Octave provides a convenient command line interface \<br />
for solving linear and nonlinear problems numerically, \<br />
using a language that is mostly compatible with Matlab. \<br />
It is easily extensible and customizable via \<br />
user-defined functions or using dynamically loaded \<br />
modules written in e.g. C++, C or Fortran.<br />
<br />
homepage http://www.gnu.org/software/octave/<br />
master_sites gnu:octave<br />
dist_subdir octave<br />
distname octave-${version}<br />
use_bzip2 yes<br />
<br />
checksums rmd160 b0356f0c5d9366b8129d72ac58bbde837fee1a95 \<br />
sha256 fa185df9591f5d740f4d37ff6eaf06db576fdd3e0ddd9d0737365799e5d1c962<br />
<br />
depends_build port:bison \<br />
port:flex \<br />
port:gawk \<br />
port:gperf \<br />
port:grep \<br />
path:bin/perl:perl5 \<br />
port:pkgconfig \<br />
port:texinfo<br />
<br />
depends_lib port:curl \<br />
port:fftw-3 \<br />
port:fftw-3-single \<br />
port:ftgl \<br />
port:ghostscript \<br />
port:glpk \<br />
port:GraphicsMagick \<br />
port:gnuplot \<br />
port:gsed \<br />
port:hdf5-18 \<br />
port:less \<br />
port:ncurses \<br />
port:pcre \<br />
port:qhull \<br />
port:qrupdate \<br />
port:readline \<br />
port:SuiteSparse<br />
<br />
depends_run port:epstool \<br />
port:pstoedit<br />
<br />
# allow us to disable checking for FLTK<br />
# via the environment variable "FLTK_CONFIG"<br />
patchfiles-append patch-configure.diff<br />
<br />
universal_variant no<br />
<br />
# octave requires a fortran compiler, so require the use of one of the<br />
# MacPorts GCC ports (for now).<br />
<br />
compiler.blacklist gcc-3.3 gcc-4.0 gcc-4.2 llvm-gcc-4.2 \<br />
apple-gcc-4.0 apple-gcc-4.2 clang macports-clang-2.9 \<br />
macports-clang-3.0 macports-clang-3.1 macports-clang-3.2 \<br />
macports-clang-3.3 macports-llvm-gcc-4.2<br />
<br />
configure.args --disable-dependency-tracking \<br />
--without-x \<br />
--disable-docs \<br />
--with-cholmod="-lcholmod" \<br />
--with-umfpack="-lumfpack -lSuiteSparse"<br />
<br />
# octave uses a number of other ports to create sources from template:<br />
# perl, gawk, gsed, flex, bison, texinfo. Make sure these are the<br />
# MacPorts' versions. Python is not used if perl is available, so<br />
# clear it out. grep is checked for in 'configure', but not used<br />
# except inside that script; include it here for completion.<br />
configure.perl ${prefix}/bin/perl<br />
configure.python ' '<br />
configure.awk ${prefix}/bin/gawk<br />
configure.env-append GREP="${prefix}/bin/grep" \<br />
FLTK_CONFIG=no \<br />
SED="${prefix}/bin/gsed" \<br />
TEXI2DVI="${prefix}/bin/texi2dvi" \<br />
TEXI2PDF="${prefix}/bin/texi2pdf" \<br />
APPLE_CXX="/usr/bin/g++"<br />
configure.cppflags<br />
configure.ldflags<br />
<br />
pre-build {<br />
reinplace "/'display\.cc'/s@\$(CXX)@\$(APPLE_CXX)@g" \<br />
${worksrcpath}/src/Makefile<br />
}<br />
<br />
build.env-append APPLE_CXX="/usr/bin/g++"<br />
<br />
test.run yes<br />
test.target check<br />
<br />
platform darwin 11 {<br />
# 10.7 requires an extra patch; this patch will break the build on<br />
# 10.6 and prior, so apply it only under 10.7.<br />
patchfiles-append patch-src-display.cc.diff<br />
}<br />
<br />
platform darwin 12 {<br />
# In 10.8 patch is required as above, also<br />
# the LANG environment variable needs to<br />
# be set to "C" otherwise /usr/bin/sed<br />
# fails with an error, if you installed gsed<br />
# with default name this should have no effect.<br />
<br />
patchfiles-append patch-src-display.cc.diff<br />
build.args-append LANG="C"<br />
}<br />
<br />
<br />
variant gcc43 description {build with the macports gcc43 toolchain} conflicts gcc48 gcc47 gcc46 gcc45 gcc44 g95 {}<br />
<br />
variant gcc44 description {build with the macports gcc44 toolchain} conflicts gcc48 gcc47 gcc46 gcc45 gcc43 g95 {}<br />
<br />
variant gcc45 description {build with the macports gcc45 toolchain} conflicts gcc48 gcc47 gcc46 gcc44 gcc43 g95 {}<br />
<br />
variant gcc46 description {build with the macports gcc46 toolchain} conflicts gcc48 gcc47 gcc45 gcc44 gcc43 g95 {}<br />
<br />
variant gcc47 description {build with the macports gcc47 toolchain} conflicts gcc48 gcc46 gcc45 gcc44 gcc43 g95 {}<br />
<br />
variant gcc48 description {build with the macports gcc48 toolchain} conflicts gcc47 gcc46 gcc45 gcc44 gcc43 g95 {}<br />
<br />
variant g95 description {build with g95} conflicts gcc48 gcc47 gcc46 gcc45 gcc44 gcc43 {<br />
depends_build-append port:g95<br />
configure.f77 "${prefix}/bin/g95"<br />
}<br />
<br />
variant atlas description {use BLAS from ATLAS} conflicts accelerate {<br />
depends_lib-append port:atlas<br />
}<br />
<br />
variant accelerate description {use BLAS from Apple's Accelerate.framework} conflicts atlas {<br />
depends_lib-append port:dotwrp<br />
configure.args-append --with-blas="-ldotwrp -Wl,-framework -Wl,Accelerate"<br />
configure.args-append --with-lapack="-Wl,-framework -Wl,Accelerate"<br />
}<br />
<br />
if {[variant_isset g95]} {<br />
default_variants +accelerate<br />
} elseif {![variant_isset accelerate]} {<br />
default_variants +atlas<br />
}<br />
<br />
# check for GCC / G95 variants. The default here must match the<br />
# default found in the 'atlas' port (but, this is not checked for).<br />
<br />
# check for setting the default variant (gcc47)<br />
<br />
if { ![variant_isset gcc43] && ![variant_isset gcc44] && \<br />
![variant_isset gcc45] && ![variant_isset gcc46] && \<br />
![variant_isset gcc47] && ![variant_isset gcc48] && \<br />
![variant_isset g95] } {<br />
default_variants +gcc47<br />
}<br />
<br />
# check if the user disabled just the default variant: -gcc47<br />
<br />
if { ![variant_isset gcc43] && ![variant_isset gcc44] && \<br />
![variant_isset gcc45] && ![variant_isset gcc46] && \<br />
![variant_isset gcc47] && ![variant_isset gcc48] && \<br />
![variant_isset g95] } {<br />
pre-fetch {<br />
error "You must select one of the compiler variants."<br />
}<br />
}<br />
<br />
set gcc_version ""<br />
if {[variant_isset gcc43]} {<br />
set gcc_version "4.3"<br />
} elseif {[variant_isset gcc44]} {<br />
set gcc_version "4.4"<br />
} elseif {[variant_isset gcc45]} {<br />
set gcc_version "4.5"<br />
} elseif {[variant_isset gcc46]} {<br />
set gcc_version "4.6"<br />
} elseif {[variant_isset gcc47]} {<br />
set gcc_version "4.7"<br />
} elseif {[variant_isset gcc48]} {<br />
set gcc_version "4.8"<br />
}<br />
<br />
if {${gcc_version} != ""} {<br />
set gcc_version_join [join [split ${gcc_version} "."] ""]<br />
configure.ldflags "-L${prefix}/lib/gcc${gcc_version_join}"<br />
configure.ldflags-append -lstdc++ \<br />
-lgfortran<br />
depends_build-append port:gcc${gcc_version_join}<br />
configure.compiler macports-gcc-${gcc_version}<br />
}<br />
<br />
variant docs description {Enable creation and installation of documentation} {<br />
depends_run-append port:texlive-basic<br />
# latex needed for lcircle10 font etc.<br />
depends_build-append port:texlive-latex<br />
configure.args-replace s|--disable-docs|--enable-docs|<br />
}<br />
<br />
variant x11 description {Enable use of X11} {<br />
configure.args-replace s|--without-x|--with-x|<br />
configure.args-append --x-includes=${prefix}<br />
}<br />
<br />
variant fltk description {Include FLTK for graphical front-end} {<br />
depends_lib-append path:lib/libfltk.dylib:fltk<br />
configure.env-delete FLTK_CONFIG=no<br />
}<br />
<br />
livecheck.type regex<br />
livecheck.url http://www.gnu.org/software/octave/news.html<br />
livecheck.regex Version (\\d+(\\.\\d+)*)<br />
<br />
</nowiki></div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2770Create a MacOS X App Bundle Using MacPorts2013-05-19T08:55:19Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command. For macports 2.1.3, having the <code>xorg-libx11</code> as a dependency for Octave has been found to cause the <code>port mdmg octave-local ...</code> command to fail. The <code>xorg-libx11</code> dependency may be avoided by specifying <code>-x11+no_x11-docs</code> as variants and by dropping the dependence to <code>transfig</code> (which has <code>xpm</code> as a dependency and <code>xpm</code> depends upon several <code>xorg-*</code> ports.<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] has been prepared, which does not depend upon METIS and does depend upon <code>epstool</code>, and <code>pstoedit</code> (there is no <code>transfig</code> dependency since it generates an <code>xorg-libx11</code> dependency). After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
<span style="color: green;"> If run from a fresh macports installation (i.e. no ports have yet been installed), then this command should complete with no errors.</span> If ports have already been installed, then errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. <span style="color: red;">One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave </span> (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2769Create a MacOS X App Bundle Using MacPorts2013-05-19T08:36:37Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] has been prepared, which does not depend upon METIS and does depend upon <code>epstool</code>, and <code>pstoedit</code> (there is no <code>transfig</code> dependency since it generates an <code>xorg-libx11</code> dependency). After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
<span style="color: green;"> If run from a fresh macports installation (i.e. no ports have yet been installed), then this command should complete with no errors.</span> If ports have already been installed, then errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. <span style="color: red;">One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave </span> (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2768Create a MacOS X App Bundle Using MacPorts2013-05-19T08:33:53Z<p>Bpabbott: /* Install Dependencies with Specific Variants */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon <code>epstool</code>, <code>pstoedit</code>, and <code>transfig</code> has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
<span style="color: green;"> If run from a fresh macports installation (i.e. no ports have yet been installed), then this command should complete with no errors.</span> If ports have already been installed, then errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. <span style="color: red;">One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave </span> (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2767Create a MacOS X App Bundle Using MacPorts2013-05-19T08:28:09Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon <code>epstool</code>, <code>pstoedit</code>, and <code>transfig</code> has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate</code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2766Create a MacOS X App Bundle Using MacPorts2013-05-19T08:27:37Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon <code>epstool</code>, <code>pstoedit</code>, and <code>transfig</code> has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack</code> and <code>qrupdate<\code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2765Create a MacOS X App Bundle Using MacPorts2013-05-19T08:26:53Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon <code>epstool</code>, <code>pstoedit</code>, and <code>transfig</code> has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack<\code> and <code>qrupdate<\code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47</code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2764Create a MacOS X App Bundle Using MacPorts2013-05-19T08:26:22Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon <code>epstool</code>, <code>pstoedit</code>, and <code>transfig</code> has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack<\code> and <code>qrupdate<\code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</code> variant is also recommended as all of Octave's dependents have a <code>+gcc47<code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2763Create a MacOS X App Bundle Using MacPorts2013-05-19T08:25:49Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon <code>epstool</code>, <code>pstoedit</code>, and <code>transfig</code> has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's accelerate framework should also be avoided for <code>arpack<\code> and <code>qrupdate<\code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using <code>+atlas</code> make sure none of the dependents are using <code>+accelarate</code>. Also, make sure no dependents are using the <code>+universal</code> variant. Using the <code>+gcc47</codeL variant is also recommended as all of Octave's dependents have a <code>+gcc47<code> variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of <code>octave-local</code> which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2762Create a MacOS X App Bundle Using MacPorts2013-05-19T02:51:44Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon <code>epstool</code>, <code>pstoedit</code>, and <code>transfig</code> has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's accelerate framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for <code>arpack<\code> and <code>qrupdate<\code>. To install the recommended variants, use the <code>port</code> commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2761Create a MacOS X App Bundle Using MacPorts2013-05-19T02:49:28Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 <code>print</code> feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named <code>ports</code>. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the <code>+atlas</code> variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2760Create a MacOS X App Bundle Using MacPorts2013-05-19T02:37:07Z<p>Bpabbott: /* Produce a DMG for Octave and its dependencies */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2759Create a MacOS X App Bundle Using MacPorts2013-05-19T01:38:03Z<p>Bpabbott: /* Produce a DMG for Octave and its dependencies */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+quartz" do not match original selection "".<br />
Please use the same variants again, perform 'port clean gtk2' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-local returned: Processing of port gtk2 failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean gtk2</nowiki><br />
<br />
The ports <code>cctools</code> and <code>curl</code> consistently need to be cleaned prior to the <code>port mdmg octave-local ...</code> command. The reason for this is not understood (yet), but one hint is seen during the compilation of the DMG.<br />
<br />
<pre>Portfile changed since last build; discarding previous state.</pre><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both <code>macros.texi</code>, <code>octave.info</code>, and the <code>octave.info-#</code> files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle (one possibility is that the <code>+docs</code> variant is not used. Including the <code>+docs</code> variant would bundle many of the <code>xorg</code> ports as well as all of <code>texlive</code>.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2758Create a MacOS X App Bundle Using MacPorts2013-05-19T01:23:30Z<p>Bpabbott: /* Install MacPorts */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
===Install Dependencies with Specific Variants===<br />
<br />
There may be problems bundling some dependencies. For example, bundling the <code>xorg-libx11</code> port may fail. To alleviate this problem (or similar ones), the problematic port can be avoided as a dependency. The command used to produce the octave-local DMG, <code>port mdmg octave-local +variant1+variant2+etc</code>, applies the listed variants to each of the dependencies. Therefore, it is necessary to provide a proper aggregate list of dependencies. For Octave 3.6.4, the list below were sufficient.<br />
<br />
<pre>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis+llvm32+ssl+qt</pre><br />
<br />
Errors during the execution of this command are likely and may be resolved by modifying the variant(s) of installed packages, and/or modifying the list of variants used to produce the <code>octave-local</code> DMG. One of Octave's dependencies, <code>transfig</code>, requires port <code>xpm</code>, which requires many xorg ports that may cause the <code>port mdmg ...</code> command to fail. To alleviate this problem, the <code>transfig</code> port can be eliminated as a run-time dependency for Octave (can the <code>transfig</code> portfile be modified to eliminate the <code>xpm</code> dependency?).<br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2757Create a MacOS X App Bundle Using MacPorts2013-05-19T01:07:30Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2756Create a MacOS X App Bundle Using MacPorts2013-05-19T01:04:46Z<p>Bpabbott: /* Install MacPorts */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local sudo port install octave-local @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2755Create a MacOS X App Bundle Using MacPorts2013-05-19T01:01:23Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local sudo port install octave-devel @3.6.4+atlas+fltk+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port rdeps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2754Create a MacOS X App Bundle Using MacPorts2013-05-19T00:54:22Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the user's Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2753Create a MacOS X App Bundle Using MacPorts2013-05-19T00:53:52Z<p>Bpabbott: /* Install an Octave Port */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis METIS]. To avoid license violations do not bundle Metis with Octave and then distribute to others. In order to eliminate the Metis dependency, a local portfile may be used, and edited to remove metis. 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A third motivation for a local portfile is to provide additional flexibility in resolving problems with creating an Octave DMG using the <code>port mdmg ...</code> command .<br />
<br />
A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared. After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the users Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2752Create a MacOS X App Bundle Using MacPorts2013-05-18T15:05:06Z<p>Bpabbott: /* Caveats */</p>
<hr />
<div>== Caveats ==<br />
<br />
Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
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 [http://guide.macports.org/chunked/development.local-repositories.html local portfile repository be created] and the local portfile placed there.<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared.<br />
<br />
After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the users Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2751Create a MacOS X App Bundle Using MacPorts2013-05-18T15:03:50Z<p>Bpabbott: /* Caveats */</p>
<hr />
<div>== Caveats ==<br />
<br />
{{Warning|Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libx11</code> port. Review the output of the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> to identify the ports whose variants must be modified to avoid <code>gcc45</code> and <code>xorg-libx11</code>. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
}}<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
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 [http://guide.macports.org/chunked/development.local-repositories.html local portfile repository be created] and the local portfile placed there.<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared.<br />
<br />
After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the users Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2750Create a MacOS X App Bundle Using MacPorts2013-05-18T14:56:21Z<p>Bpabbott: /* Caveats */</p>
<hr />
<div>== Caveats ==<br />
<br />
{{Warning|Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libX11</code> port. To identify the why x11 is needed the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> may be used. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
* Once the dependencies are resolved, the DMG may be created by <code>sudo port mdmg octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code>.<br />
}}<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
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 [http://guide.macports.org/chunked/development.local-repositories.html local portfile repository be created] and the local portfile placed there.<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared.<br />
<br />
After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the users Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2749Create a MacOS X App Bundle Using MacPorts2013-05-18T14:52:35Z<p>Bpabbott: /* Caveats */</p>
<hr />
<div>== Caveats ==<br />
<br />
{{Warning|Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47-x11+no_x11-metis</code> command fails when bundling the <code>xorg-libX11</code> port. To identify the why x11 is needed the command <code>port rdeps octave-devel @3.6.4+atlas+fltk+gcc47-x11+no_x11-metis</code> may be used. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
}}<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
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 [http://guide.macports.org/chunked/development.local-repositories.html local portfile repository be created] and the local portfile placed there.<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared.<br />
<br />
After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the users Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2748Create a MacOS X App Bundle Using MacPorts2013-05-18T14:47:56Z<p>Bpabbott: /* Caveats */</p>
<hr />
<div>== Caveats ==<br />
<br />
{{Warning|Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libX11</code> port. To identify the why x11 is needed the command <code>port rdeps octave-devel @3.6.4_3+atlas+fltk+gcc47-x11+no_x11</code> may be used. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed. This means that Xfig output is not available using Octave's <code>print()</code> function/command.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
}}<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
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 [http://guide.macports.org/chunked/development.local-repositories.html local portfile repository be created] and the local portfile placed there.<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared.<br />
<br />
After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the users Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbotthttps://wiki.octave.org/wiki/index.php?title=Create_a_MacOS_X_App_Bundle_Using_MacPorts&diff=2747Create a MacOS X App Bundle Using MacPorts2013-05-18T14:47:11Z<p>Bpabbott: /* Caveats */</p>
<hr />
<div>== Caveats ==<br />
<br />
{{Warning|Since the initial success with producing a bundle, two things have changed on the Macports end.<br />
* gcc-4.7 must be used, as some dependencies are no longer supported by gcc-4.5. To look for ports using a <code>gcc45</code> variant, type <code>port rdeps gcc45</code> at the terminal's command line.<br />
* The <code>sudo port mdmg octave-devel @3.6.4+atlas+docs+fltk+gcc47</code> command fails when bundling the <code>xorg-libX11</code> port. To identify the why x11 is needed the command <code>port rdeps octave-devel @3.6.4_3+atlas+fltk+gcc47-x11+no_x11</code> may be used. There is one dependency (<code>Transfig</code>) for which <code>x11</code> is not optional. To resolve this, the <code>octave-devel</code> Portfile must be modified and the <code>Transfig</code> run-time dependency removed.<br />
* While editing the Portfile for <code>octave-devel</code>, the references to <code>metis</code> should also be removed to avoid a GPL violation.<br />
<br />
This means that Xfig output is not available using Octave's <code>print()</code> function/command.}}<br />
<br />
==Install MacPorts==<br />
<br />
[http://www.macports.org/ 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.<br />
<br />
An itemized overview of a MacPorts install is below.<br />
<br />
* Install XCode: This is done via the MacOS X App Store.<br />
* Follow [http://www.macports.org/install.php MacPorts' installation instructions].<br />
* MacPorts has good support for Octave. A list of what MacPorts has available for Octave is [http://www.macports.org/ports.php?by=name&substr=octave here]. To install the most recent version of Octave, type {{Codeline|<nowiki>sudo port install octave-devel</nowiki>}} 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.<br />
<br />
MacPorts has historically been rather good a maintaining their Octave portfiles. However, there are times when the maintainers fall behind. If the current version of the [http://www.macports.org/ports.php?by=name&substr=octave-devel octave-devel] port isn't current, it will be necessary to produce a local portfile. For the remainder of this page, it is assume a local portfile is being used and that the port name is {{Codeline|<nowiki>octave-local</nowiki>}}.<br />
<br />
===Install an Octave Port===<br />
<br />
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 [http://guide.macports.org/chunked/development.local-repositories.html local portfile repository be created] and the local portfile placed there.<br />
<br />
MacPorts' Octave port includes the non-GPL [http://glaros.dtc.umn.edu/gkhome/views/metis 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 {{Codeline|<nowiki>print</nowiki>}} feature. The missing dependencies are [http://www.macports.org/ports.php?by=name&substr=epstool epstool], [http://www.macports.org/ports.php?by=name&substr=pstoedit pstoedit], and [http://www.macports.org/ports.php?by=name&substr=transfig transfig]. A [[Prototype MacPorts PortFile|prototype portfile]] which does not depend upon METIS and does depend upon epstool, pstoedit, and transfig has been prepared.<br />
<br />
After [http://guide.macports.org/chunked/development.local-repositories.html creating a local portfile repository] an Octave portfile may be added to the local repository using the commands below.<br />
<nowiki>mkdir -p ~/ports/math/octave-local<br />
cp ~/Desktop/portfile ~/ports/math/octave-local</nowiki><br />
This assumes the Octave portfile had been placed on the users Desktop, and that the local portfile repository is located in the users home folder and named {{Codeline|<nowiki>ports</nowiki>}}. After adding the portfile, the local repository must be indexed for MacPorts to recognize it.<br />
<nowiki>cd ~/ports<br />
portindex -f</nowiki><br />
Once indexed the local Octave port may be installed.<br />
<nowiki>sudo port install octave-local +atlas+gcc47</nowiki><br />
<br />
The use of the {{Codeline|+atlas}} variant is encouraged as bugs exist for Apple's {{Codeline|accelerate}} framework in both MacOS 10.6 and 10.7. Octave's developers have included a fix for MacOS 10.6, but the fix does not work for MacOS 10.7. There is some commentary on this in various developers discussion forums. For example, see [https://github.com/mxcl/homebrew/issues/6649 this Homebrew thread (Octave 3.4 fails on lion)], [https://stat.ethz.ch/pipermail/r-sig-mac/2011-September/008564.html this R-Sig-Mac thread (R 2.13.1-patched, vecLib problem on Lion)], and [http://list.coin-or.org/pipermail/ipopt/2011-October/002610.html the COIN-OR thread (Ipopt - problems on OS X 10.7 Lion)]. Use of Apple's {{Codeline|accelerate}} framework should also be avoided for {{Codeline|arpack}} and {{Codeline|qrupdate}}. To install the recommended variants, use the {{Codeline|port}} commands below.<br />
<br />
<nowiki>port install arpack +atlas+gcc47<br />
port install qrupdate +atlas+gcc47</nowiki><br />
<br />
As a precaution against unexpected problems and a bloated App bundle, using consistent variants for Octave and its dependents is suggested. For example, when using {{Codeline|+atlas}} make sure none of the dependents are using {{Codeline|+accelarate}}. Also, make sure no dependents are using the {{Codeline|+universal}} variant. Using the {{Codeline|+gcc47}} variant is also recommended as all of Octave's dependents have a {{Codeline|+gcc47}} variant. At the very least, following these suggestions will reduce the size of the bundle. The name of Octave's dependent ports may be determined by the command below.<br />
<br />
<nowiki>port deps octave-local</nowiki><br />
<br />
The installed variants for each port may be determined by the command below. Be sure to replace "<portname>" with the name of the port.<br />
<br />
<nowiki>port installed <portname></nowiki><br />
<br />
Once an Octave port is installed the command below may be used to determine / verify the version and variants of {{Codeline|<nowiki>octave-local</nowiki>}} which are installed.<br />
<br />
<nowiki>port installed octave-local</nowiki><br />
<br />
==Create the MacOS X App Bundle==<br />
<br />
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 AppleScript Editor. Third, the shell script which the App bundle runs is needed. This script will be used to launch the [http://en.wikipedia.org/wiki/Terminal_(OS_X) 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''.<br />
<br />
===Produce a DMG for Octave and its dependencies===<br />
<br />
MacPorts provides a feature for [http://guide.macports.org/index.html#using.binaries.binary-packages 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.<br />
<br />
<nowiki>sudo port mdmg octave-local</nowiki><br />
<br />
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.<br />
<br />
<nowiki>sudo port mdmg octave-local @<version>+variant1+variant2</nowiki><br />
<br />
In the event errors such as the one below are encountered, the ports implicated ({{Codeline|<nowiki>t1lib</nowiki>}} in this case) must be clean prior to creating the dmg.<br />
<br />
<nowiki><br />
Error: Requested variants "+x11" do not match original selection "".<br />
Please use the same variants again, perform 'port clean t1lib' or specify the force option (-f).<br />
Error: org.macports.mpkg for port octave-devel returned: Processing of port t1lib failed</nowiki><br />
<br />
Be sure to clean each of the problematic ports prior to each attempt to create the dmg.<br />
<br />
<nowiki>sudo port clean cairo ; sudo port clean cctools ; sudo port clean pango ; sudo port clean t1lib</nowiki><br />
<br />
The DMG will be placed in the port's {{Codeline|<nowiki>work</nowiki>}} directory. If a local portfile is used, a symbolic link to the {{Codeline|<nowiki>work</nowiki>}} directory will be placed in the directory containing the portfile. In this instance the DMG can be found in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
<br />
The DMG produced using the [http://www.octave.org/wiki/index.php?title=Prototype_MacPorts_PortFile prototype portfile's] does not include everything needed for Octave. Both {{Codeline|macros.texi}}, {{Codeline|octave.info}}, and the {{Codeline|octave.info-#}} files are missing. Until the cause for these missing files is identified and resolved, they will have to be copied manually to the App bundle.<br />
<br />
===Create an Application Template for Octave===<br />
<br />
[[File:AppleScriptEditor.png|350px|thumb|right|Apple Script Editor Dialog (click to enlarge)]]<br />
<br />
The itemized instructions below describe how to create an application template for Ocave using the AppleScript Editor.<br />
* Run the "AppleScript Editor" and enter the script below.<br />
<nowiki># Run the octave shell script that has be bundled.<br />
tell application "Terminal"<br />
# The script "launch_octave" will call the octave shell script and then close<br />
# this AppleScript when octave exits.<br />
do script quoted form of POSIX path of (path to me) & "Contents/Resources/bin/launch_octave '" & (name of me) & "'; sleep 1; exit"<br />
end tell</nowiki><br />
* Choose "Save As..." from the <b>File</b> menu.<br />
** Specify the application name in the <b>Save As:</b> field. For this example, use "Octave-3.7.0+.app".<br />
** The <b>Where:</b> field specifies the location the application template will be saved to.<br />
** The <b>File Format:</b> pull down should be set to "Application".<br />
** Of the <b>Options</b>, only "Stay Open" should be checked.<br />
** Click on <b>Save</b>.<br />
<br />
The [[launch_octave|launch_octave]] shell script runs the Octave shell script and uses AppleScript to tell the App bundle to quit when Octave exits.<br />
<br />
The default applet.icns file which is included in the App bundle template by the AppleScript editor should be replaced by a MacOS X version of [http://www.octave.org/wiki/index.php?title=File:Icon.png Octave's icon]. This MacOS version was produced using the ''Icon Composer'' developers utility and a png with a transparent background. The Icon Composer is part of Xcode's developer's tools. Its home is {{Codeline|<nowiki>/Developer/Applications/Icon Composer.app</nowiki>}}.<br />
<br />
===Populate the App Bundle===<br />
<br />
To populate the App bundle template with Octave and its dependencies, from MacPorts, follow the itemize instructions below. <br />
* Move the MacPorts Octave DMG to the Desktop. If a local portfile was used and the location of the local repository was {{Codeline|<nowiki>~/ports</nowiki>}}, the DMG will be located in {{Codeline|<nowiki>~/ports/math/octave-local/work</nowiki>}}.<br />
* Save the original MacPorts installation.<br />
<nowiki>sudo mv /opt /opt-save</nowiki><br />
* Install the MacPorts Octave DMG, which as placed on the MacOS X Desktop. Installing the DMG will create a new {{Codeline|<nowiki>/opt</nowiki>}} directory containing Octave and all its build and run-time dependencies. To avoid conflict with the original MacPorts installation.<br />
* Place the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]] in the same directory as the App bundle template created using the AppleScript Editor.<br />
* Populate the App bundle by running the script below from the directory containing the App bundle template and the [[MacOS_X_App_Octave_Shell_Script| Octave shell script]].<br />
<nowiki>#! /bin/sh<br />
VERSION=3.7.0+<br />
APP=Octave<br />
FULLAPP="${APP}-${VERSION}.app"<br />
MACPORTS_PREFIX="/opt/local/"<br />
cp -pRf ${MACPORTS_PREFIX} ${FULLAPP}/Contents/Resources/.<br />
rm ${FULLAPP}/Contents/Resources/lib/*.a<br />
rm ${FULLAPP}/Contents/Resources/bin/octave<br />
cp launch_octave ${FULLAPP}/Contents/Resources/bin/.<br />
cp octave ${FULLAPP}/Contents/Resources/bin/.<br />
mkdir ${FULLAPP}/Contents/Resources/Applications<br />
cp /Applications/MacPorts/AquaTerm.app ${FULLAPP}/Contents/Resources/Applications</nowiki><br />
* Restore the original MacPorts installation.<br />
<nowiki>sudo rm -r /opt<br />
sudo mv /opt-save /opt</nowiki><br />
<br />
The Octave App bundle for MacOS X is now ready to run.<br />
<br />
===Create an Installer DMG===<br />
<br />
The GPL'd [http://dmgcreator.sourceforge.net/en/ dmgCreater] is a Mac OS X Application which allows simple and easy creation of customized dmg disk images with custom background images. It ensures the correct presentation of the disk image's content irrespective of the current Finder configuration.<br />
<br />
A short list of features from the dmgCreator sourceforge page are;<br />
<br />
* Create compressed and internet enabled DMG files, i.e. for software distribution.<br />
* Add a background image and a custom volume icon to your disk image.<br />
* Add a symbolic link to the Applications folder for easy installation.<br />
* Show localized license agreements when mounting the disk image. They have to be accepted by the user in order to access the contents.<br />
* Content positioning at a pixel level.<br />
* The disk image's content will always look the same, irrespective of the user's finder configuration.<br />
<br />
==Running Octave from the Terminal's Command Line==<br />
<br />
The bundled Octave may be run from a terminal command line using the command below.<br />
<nowiki>/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave</nowiki><br />
To create a symbolic link in your path that runs the bundled Octave, us the command below.<br />
<nowiki>ln -s /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave /usr/local/bin/octave</nowiki><br />
If the link does not work, be sure that {{Codeline|<nowiki>/usr/local/bin</nowiki>}} is in your shell path. If it is not in your path, it may be added by editing {{Codeline|<nowiki>~/.profile</nowiki>}}. Just add the line below to the end of the file.<br />
<nowiki>export PATH="${PATH}:/usr/local/bin"</nowiki><br />
<br />
==Problems, Restrictions, and Annoyances of the App Bundle==<br />
<br />
* In the past, the App bundle did not run if there were spaces in its path. A solution to this problem has been applied, but is not fully tested.<br />
* The [[MacOS_X_App_Octave_Shell_Script|Octave shell script]] used to run Octave is designed to ensure that the bundled version of AquaTerm is used by Octave. This was done because binary incompatibilities have been encountered between the bundled Gnuplot and AquaTerm applications provided by other sources. If Octave/Gnuplot appear to have a problem producing a plot using AquaTerm, verify that Aquaterm is running. If it is not, then quit and relaunch the Octave App. If an Aquaterm application is running, please verify that it is the one bundled with Octave.<br />
* Executables built by MacPorts may include features specific to the MacOS X version the executables were build on. As a result, the Octave App bundle may ''not'' run on a different version of MacOS X.<br />
* The {{Codeline|<nowiki>mex</nowiki>}} and {{Codeline|<nowiki>mkoctfile</nowiki>}} functions have not been tested. Although the App bundle does include a gcc toolset, some debugging is expected before this will work reliably.<br />
* When Octave is running, clicking on Octave's icon in the dock has no effect. This is because the App bundle runs a shell script which launches Terminal.app which runs Octave. To locate the Octave session, click on the Terminal.app.<br />
* Only one instance of the App may be run by clicking on the app. Multiple instances may be run from the command line.<br />
* The Octave binary may attempt to load an library whose version number is older than the one it intended to link to (at build time). This will produce an error like to one below. If this happens, please report the error.<br />
<nowiki>dyld: Library not loaded: /opt/local/libiconv.2.dylib</nowiki><br />
<br />
===Fixing "{{Codeline|dyld: Library not loaded}}" Errors===<br />
If an error such as the one above is encountered, it is likely due to the Bundle looking in the original install path rather than in the App bundle for the library. This can be fixed using the developer utility [https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/install_name_tool.1.html {{Codeline|install_name_tool}}].<br />
<br />
To point to the correct location for the library, first determine the library's location in the App bundle. In this instance the library's path is {{Codeline|Octave-3.7.0+.app/Contents/Resources/lib/libiconv.2.dylib}}. Next open a Terminal session, {{Codeline|cd}} to the Resources directory and repair Octave's binary.<br />
<nowiki>cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin<br />
install_name_tool -change /opt/local/libiconv.2.dylib @executable_path/../lib/libiconv.2.dylib Octave-3.7.0+</nowiki><br />
To check the binary for other occurances of this problem, type the command below.<br />
<nowiki>otool -L Octave-3.7.0+</nowiki><br />
Some m-file functions has been written to automate the application of the {{Codeline|otool}} utility toward making the binary executable and dynamically loadable libraries included in the App bundle relocatable. The four m-file functions to accomplish this are itemized below.<br />
<br />
* [[dylibs_fix.m]]<br />
<nowiki> -- Function File: fix_dylibs (EXEBIN, LIBDIR, DRYRUN)<br />
Make the executable and dynamic libraries relocatable. The inputs<br />
are;<br />
<br />
EXEBIN<br />
The full file name of the executable binary for the App<br />
bundle. The default is `bin/Octave-3.7.0+';<br />
<br />
LIBDIR<br />
The full path to the directory containing the App bundle's<br />
dynamic libraries. The default is `lib'.<br />
<br />
DRYRUN<br />
If TRUE, the `install_name_tool' commands are printed to the<br />
command line and are not executed (i.e. the install names and<br />
paths to the dependent libraries are not changed). The<br />
default is TRUE.<br />
<br />
Using `install_name_tool' the portion of the built in dynamic<br />
library paths external to the App bundles are replaced with the<br />
token `@executable_path'. Ths will modify the paths in both the<br />
EXEBIN and the the dynamic libraries and allow the application to<br />
be relocated with no risk that the binary executable and libraries<br />
are unable to locate the dynamic libraries they depend upon.<br />
<br />
In addition to correcting the location information for the<br />
dependent's of EXEBIN, the LIBDIR is searched recursively to<br />
locate all dynamic libraries present in the App bundle. Both<br />
their install names and the locations of their dependents will<br />
also be fixed.<br />
<br />
Using the default, this script expects to find a `bin' and `lib'<br />
directory in the current working directory.</nowiki><br />
* [[dylibs_find.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_find (DIRECTORY)<br />
Recursively finds all dylibs in DIRECTORY, and returns a structure<br />
with fields `name', `location', and `dependents'. The DIRECTORY<br />
defaults to the present working directory.<br />
<br />
`name'<br />
Is the name of a dynamic library.<br />
<br />
`location'<br />
Is the path to the named dynamic library.<br />
<br />
`dependents'<br />
Is a cellstr array listing the dynamic libraries the named<br />
library depends upon.<br />
<br />
`islink'<br />
Logical scalar indicating whether the file is a symbolic link<br />
to a dynamically loadable library.</nowiki><br />
* [[dylibs_get_deps.m]]<br />
<nowiki> -- Function File: dylibs = dylibs_get_deps (NAME)<br />
-- Function File: = dylibs_get_deps (NAME, ROOT)<br />
Extracts the dependent libary names from the named binary, NAME.<br />
If ROOT is specified, the only libraries returned will have paths<br />
which begin with one of the cell-strings contained by ROOT.<br />
<br />
The defaults for ROOT are `{"/opt/local/", "/sw/", "/usr/local/",<br />
"@executable_path"}'. These root paths are intended to match all<br />
the relocatable libraries which should be included in an App<br />
bundle. The first and second entries correspond to the MacPorts<br />
and Fink installation directories, respectively.</nowiki><br />
<br />
* [[dylibs_isdylib.m]]<br />
<nowiki> -- Function File: result = dylibs_isdylib (FILENAME)<br />
Determines if the filename qualifies as a dynamically loaded<br />
library. The RESULT is TRUE for dylib-files, oct-files, and<br />
mex-files. The result is FALSE for all other files.<br />
<br />
This function isn't sophisticated. It only examines the file<br />
extension.</nowiki><br />
<br />
To apply these scripts, change the current directory to {{Codeline|Octave-3.7.0+.app/Contents/Resources}}, and enter the command below.<br />
<nowiki>dylibs_fix ("bin/octave-3.7.0+", "lib", false)</nowiki><br />
The script will mirror each of the {{Codeline|otool}} commands to the screen. Errors and/or warnings are given if any libraries are found to be missing in the bundle.<br />
<br />
===Reducing the Size===<br />
The App bundle is large. It's size may be significantly reduced by deleting the static libraries.<br />
<nowiki>find "Octave-3.7.0+.app/Contents/Resources/lib/." -name "*.a" -exec rm -f {} \;</nowiki><br />
<br />
==Testing==<br />
Those interested in testing an App bundle can try [https://dl.dropbox.com/u/14845154/Octave-X86_64-3.7.0%2Bv12.dmg (Dated: Sep 8, 2012 at 15:46 PM)]. The link will be periodically updated. The DMG is large (472+ MB). I kindly ask those with the patience to download it, to report results to bpabbott at mac dot com. Alternatively, if a bug is found [https://savannah.gnu.org/bugs/?group=octave file a bug report]. When reporting on your experience, please include;<br />
* The version of MacOS X you are running.<br />
** Note: This App bundle will ''not'' run on Mac OS 10.5 or earlier.<br />
* The Mac's processor (found under "About This Mac").<br />
** Note: This App bundle will ''only'' run on 64 bit Intel processors (X86_64).<br />
** If the App bundle doesn't run, it may necessary to enable 64 bit mode. See Apple's support page for instructions ⇒ [http://support.apple.com/kb/HT3773 OS X: Starting up with the 32-bit or 64-bit kernel];<br />
* Whether you have Fink, Homebrew, or MacPorts installed.<br />
* For intricate problems, please provide enough information so that others may duplicate it.<br />
===Testing Results===<br />
Results reported by some volunteers testing an App bundle are below. As some of the reported results are inconsistent, individuals are cautioned not interpret these results as definitive. However, the App bundle does appear to run reliably on X86_64 based Macs running MacOS 10.6 and above.<br />
* An App bundle built for arch=X86_64 on an Intel Core i7 MacBook Pro running MacOS 10.7 was found to run on the following;<br />
:* Macbook Pro (X86_64 architecture) running MacOS 10.8.1.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with MacPorts installed.<br />
:* MacBook Pro (Intel Core i7) running MacOS 10.7 with no MacPorts, and no Fink, installed.<br />
* The App bundle did not run on Intel Core (2) Duo processors, as [http://en.wikipedia.org/wiki/X86-64#Intel_64_implementations they are not 64 bit].;<br />
:* MacBook (Intel Core Duo) running MacOS 10.6 with no MacPorts, and no Fink, installed. The error encountered is below.<br />
<nowiki>$ cd /Applications/Octave-3.7.0+.app/Contents/Resources/bin/<br />
$ ./octave<br />
The application cannot be opened because it has an incorrect executable format.<br />
./octave: line 124: /Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+: Bad CPU type in executable</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with Fink installed. The error encountered is below. Enabling 64 bit did not effect this problem. It may be possible for resolved this as the bundled AquaTerm.app functions properly.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
:* MacMini (Intel Core 2 Duo) running MacOS 10.6 with no Fink or MacPorts installed. The error encountered is below.<br />
<nowiki>terminate called after throwing an instance of '__gnu_cxx::__concurrence_lock_error'<br />
what(): __gnu_cxx::__concurrence_lock_error</nowiki><br />
* If anyone has advice on how to resolve any of the above errors, please send an email to bpabbott at mac dot com.<br />
<br />
==TODO List==<br />
List of what can be done to improve the MacOS X App bundle.<br />
* The {{Codeline|macros.texi}} file doesn't install properly. It should be in {{Codeline|share/octave/3.7.0+/etc}}, but doesn't show up.<br />
* [[Enable "linestyle" functionality for Gnuplot's x11 terminal]]<br />
* Test the ability to compile mex-files and oct-files.<br />
** Necessary changes<br />
*** Use the environment variable OCTAVE_HOME in mkoctfile to point to the bundled developer tools and libraries.<br />
*** Same for octave_confgure-3.7.0+<br />
*** Over-ride the built-in octave_configure_info and use an m-file version that replaces the original MacPorts prefix with the OCTAVE_HOME environment variable set by the bundle.<br />
*** The bundled mkoctfile references the gcc4.4 libraries instead of the gcc4.7 libraries that are actually bundled. This needs to be corrected.<br />
** With the above changes [http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html {{Codeline|mkoctfile helloworld.cc}}] fails with the error below. This is likely due to the {{Codeline|Octave-3.7.0+.app/Contents/Resources/bin/octave}} script over-riding the build environment variables normally set by {{Codeline|mkoctfile}}.<br />
*** Rely on {{Codeline|mkoctfile}} to setup the oct-file build environment (i.e. don't set any of it up in the {{Codeline|.../Octave-3.7.0+.app/Contents/Resources/bin/octave}} script.<br />
*** Since {{Codeline|mkoctfile}} uses it, {{Codeline|gsed}} needs to be added as a run time dependency in the [[Prototype MacPorts PortFile|MacPorts portfile]]. Check to verify that other build time dependencies are not also need.<br />
<nowiki>mkoctfile -v helloworld.cc<br />
<br />
ld: library not found for -lgcc<br />
collect2: ld returned 1 exit status<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" \<br />
-c -I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" -fPIC \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave"/.. \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+/octave" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/Octave-3.7.0+" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/curl" \<br />
-I"/Applications/Octave-3.7.0+.app/Contents/Resources/include/readline" \<br />
helloworld.cc -o helloworld.o<br />
<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/g++-mp-4.7" -bundle -bundle_loader \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/bin/octave-3.7.0+" -o helloworld.oct helloworld.o \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/octave/3.7.0+" \<br />
-L"/Applications/Octave-3.7.0+.app/Contents/Resources/lib" -loctinterp -loctave -lcruft \<br />
"/Applications/Octave-3.7.0+.app/Contents/Resources/lib/gcc47/libstdc++.6.dylib"</nowiki><br />
* Should the contents of the la-files, in {{Codeline|Octave-3.7.0+.app/Resources/lib}}, be changed to reflect to use the {{Codeline|@executable_path}} token.<br />
** These files are from libtool. For limited development, such as building oct-files and mex-files, are they needed at all?<br />
* Use AppleScript Editor to record the creation of the App bundle template.<br />
** This will allow for a fully automatic build of an App bundle from a shell script.<br />
* Also use an AppleScript to record the creation of a MacOS X Octave icon.<br />
[[Category:Mac]]</div>Bpabbott