Porting to Mac
From ASCEND
This page will be a record of progress towards getting ASCEND running on a Mac. Art Westerberg has the new Mac Mini (now his main computer) and a MacBook Air. John Pye also has a Intel Mac Mini, but uses Ubuntu for everyday work.
Contents |
Running from the console
Using fink it was fairly straightforward to get the ASCEND test suite, test.py running on ASCEND. For OS X 10.5, some fink selfupdate steps were required, see here for details:
You should install XCode from your OS X CD.
You should install gfortran-macosx-x86.dmg from http://gcc.gnu.org/wiki/GFortranBinaries
You should install scons using fink.
As of Aug 2009, you need to use subversion to download a working copy of the ASCEND repository trunk.
Build ASCEND using scons.
Test ASCEND using ./test.py TestCompiler.
This leads to a working version of ASCEND that can be used from the console with no GUI. Using Python scripting, it will now be possible to load and solve ASCEND models, but with no interactivity of any sort.
Running the PyGTK GUI
A package for PyGTK is available via Fink, but this package works against X11, so it's not running on native GTK. This means that Mac-like key-bindings are all a bit messed up, and it makes programs a bit difficult to use. For example, the "Alt" key, used in GTK to give access to menu keyboard shortcuts, doesn't work properly, because Mac uses that key for other things. Having said that, using fink, I managed to install pygtk-gtk-py26, then build and run the PyGTK GUI via X11. A screenshot:
Approximate steps required:
- install Xcode from OS X CD
- install X11 SDK from the OS X CD
- install updated X11 from Apple website
- install fink
- install pygtk2-gtk-py26 using fink (warning: this part takes a couple of hours, and involves a lot of (automatic) compiling from source. Also, fink will occasionally ask questions during the process)
- install scons using fink
- ln -s /sw/bin/python26 /sw/bin/python
- download current trunk ASCEND using svn
- scons
- pygtk/ascdev
There has been no work so far on installing the resulting GUI or packaging it for distribution.
The linking /sw/bin/python to python26 is a dirty hack and needs to be resolved.
Native GTK, maybe?
There is a 'native' version of GTK that works on Mac OS X, but you have to build it yourself from the source code.
ASCEND needs PyGTK, and doesn't actually link directly to GTK, so you just need to build PyGTK.
Steps are something like this:
- Make sure you have Xcode, subversion and git installed, as outlined at http://sourceforge.net/apps/trac/gtk-osx/wiki/Build
- Make sure you have not got any Fink paths (/sw/...) or MacPorts paths in your PATH. These will confuse GTK-OSX and jhbuild.
- Download the script http://downloads.sourceforge.net/sourceforge/gtk-osx/gtk-osx-build-setup.sh and run it using 'sh'.
- Edit the resulting ~/.jhbuildrc-custom file, adding 'build_policy = "updated-deps"' as a line at the end of the file (no single quotes).
- Run the initial build commands as listed http://sourceforge.net/apps/trac/gtk-osx/wiki/Build
- Build PyGTK using jhbuild build pygtk.
Now, with PyGTK installed, use the following PATH to prefer Mac Python to Fink Python:
export $PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/X11R6/bin:/sw/bin
then build ASCEND
cd ~/ascend scons -j2
and run it
pygtk/ascdev
ASCEND will start, but you will have to command-tab to the correct window, as it won't pop to the front automatically.
Here's a cool screenshot of ASCEND on Native GTK-Quartz on OS X!
Update According to John Ralls, we need to build ige-mac-integration *twice* somehow... not clear. The 'framework' releases are apparently out of date. More information here: https://sourceforge.net/apps/trac/gtk-osx/wiki/PyGtk
Update Looks like libglade builds fine with jhbuild, should work OK with PyGTK as well, hopefully.
Update Some sample code showing usage of ige-mac-integration is here: http://translate.svn.sourceforge.net/viewvc/translate/src/trunk/virtaal/virtaal/views/mainview.py?view=markup
Apparently it may also be possible to build against native GTK using macports, but not sure about fink.
Running the Tcl/Tk GUI
No work yet to determine what will be required to the Tcl/Tk GUI running on Mac.
It may be fairly straightforward to get this GUI running, possibly using these binaries for Tcl/Tk:
Packaging and distributing
It's recommended for most Mac applications that everything be distributed as an Application Bundle that just be dragged by the user into their Applications folder. This is certainly possible with ASCEND, but a problem is that the ASCEND Model Library is something that we would like users to see and interact with. We would like users to be able to see these folders and their contents easily using the Finder. Nesting the files within an Application bundle makes this rather difficult.
One option would be for the ASCEND application to unpack its model library to ~/Library/Application Support/ASCEND when the program is first run. This would require Python scripting, and would not be compatible with a shared installation of the Tcl/Tk GUI on the same system.
Another option would be to install the model library in /Library/Application Support/ASCEND/Models. This seems to be the right way forward, but it means that ASCEND can no longer just be dragged to the Applications folder to be installed. Instead, it would need an Installer to place the necessary files on the user's system.
It's worth noting that Mac editors like TextEdit can't peer into Application Bundles, but non-Mac editors like gedit can do so... they don't impose the same restriction on entering inside such bundles.
As a first attempt for getting everything running, it seems wise to take the simple application bundle approach.
We're not currently proposing to provide the Tcl/Tk GUI for Mac. This is a whole separate packaging problem.
We're not currently proposing to package libascend as a Framework for Mac, although that is an option, and would be appropriate if attempting to provide both Tcl/Tk and PyGTK GUIs on the same machine, and to make it easier for users to develop their own solvers, etc, on that platform.
The general opinion on GTK is that we should include it within out Application Bundle. From the linux point of view, this is terribly inefficient, but such things are standard practise on Mac, and we should respect that in the first instance.
The alternative of providing ASCEND to the Mac community as a Fink package was considered, however, according to Fink developers, the current 'stable' repository for Fink is very stagnant, so we are unlikely to be able to use that as a means for distribution.
If we want to distribute ASCEND as a multi-component thing (libascend framework, Tcl/Tk GUI, PyGTK, model library all separate) then we would need to use the Apple tool, PackageMaker, which allows developers to produce their own .pkg installers, apparently. http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html. It is preferable to distribute a simple Application Bundle within a .dmg Disk Image.
Creating ASCEND.app
To create the ASCEND application bundle
- scons -j2 install INSTALL_PREFIX=~/ascinst
- The bundle will appear as ~/ascinst/ASCEND.app
- TODO: add necessary GTK files to the .app!
- follow instructions below to turn it into a redistributable disk image
The file mac/Info.plist contains all the key-value stuff describing the application. We had to make changes to pygtk/ascend.in to accommodate the particularities of the Mac platform, too.
Creating a Disk Image (ASCEND-0.9.X.dmg)
Some instructions are here: http://www.wikihow.com/Make-a-DMG-File-on-a-Mac
In summary:
- use the Applications/Utilities/Disk Utility application
- create a new image large enough for your needs
- mount and open the image
- from the Terminal, run scons -j2 install INSTALL_PREFIX=(location of your disk image folder)
- set the folder background image to ~/ascend/mac/folder-background.png
- arrange the files so that they look OK, the folder-background arrow should point from the ASCEND.app to the Applications folder alias.
- return to the disk image program
- click 'convert' and convert to a compressed image (OK to overwrite)
- all done, you can double-click the image file now, and it should mount and appear as you wanted it.
Finding all the GTK files
To create a safely porting ASCEND.app, we need to embed all of GTK into the application bundle. The above application won't be complete until we achieve that.
Looks like a Python package called 'modulegraph' may be able to help with locating all the necessary files for satisfying Python 'import' dependencies.
Then, 'otool -L' can be used to find shared library dependencies.
There are also some other files such as bitmaps etc required for correct running of GTK, these will also need to be bundled.
The tool ige-mac-bundler seems to provide some degree of automation for this process, although it's more oriented for C application than Python.
The shell-script gimpguts.sh, available from GIMPskel.zip on this page also contains some code for pulling in the necessary bits of GTK for packaging.
Connecting to Apple Events
Currently, GTK on Mac has no support for receiving or sending Apple Events. This is a problem, because Mac OS X attempts to communicate using Apple Events when a file is to be opened. If the app is not listening for events, then nothing will happen.
However, there seems to be a workaround for the case of Python scripts: appscript, which contains a module called py-aem. It may be possible to incorporate this into ASCEND as a way for processing such events. There may be other similar modules, possible. Also, PyObjC may provide another way of creating event listeners.
According to GTK-OSX, there has not yet been any attempt to incorporate this stuff into ige-mac-integration, although it was agreed that it would be desirable to integrate it there (to benefit also C-based GTK applications ported to Mac).
An alternative approach might be to write a very small Carbon/Cocoa application that could do the event listening, and pass the events on to the main application.

