Difference between revisions of "Gtk2Hs/Mac"

From HaskellWiki
Jump to navigation Jump to search
(copy from Gtk2hs main page)
 
(promote titles up 2)
Line 1: Line 1:
==== The Quick-Guide for OS X 10.6, 64bit, MacPorts ====
+
== The Quick-Guide for OS X 10.6, 64bit, MacPorts ==
   
 
Setbacks: old ghc (6.10.4 as of 2011-03-10)
 
Setbacks: old ghc (6.10.4 as of 2011-03-10)
Line 7: Line 7:
 
* execute: sudo port install ghc gtk2 gvfs cairo librsvg libglade2 gtkglext gtksourceview2 && sudo port install gtk2hs -universal
 
* execute: sudo port install ghc gtk2 gvfs cairo librsvg libglade2 gtkglext gtksourceview2 && sudo port install gtk2hs -universal
   
==== Using MacPorts and Snow Leopard ====
+
== Using MacPorts and Snow Leopard ==
   
 
This explains how to install Gtk2Hs-0.10.1 on Mac OS X 10.6 Snow Leopard, in combination with GTK+ from MacPorts.
 
This explains how to install Gtk2Hs-0.10.1 on Mac OS X 10.6 Snow Leopard, in combination with GTK+ from MacPorts.
Line 37: Line 37:
 
# sudo port upgrade --force-installed
 
# sudo port upgrade --force-installed
   
==== Using the GTK+ OS X Framework ====
+
== Using the GTK+ OS X Framework ==
   
 
This explains how to install Gtk2Hs on Macs using the native [http://gtk-osx.sourceforge.net/ GTK+ OS X Framework], a port of GTK+ to the Mac that does '''not''' depend on X11, and hence, is better integrated into the Mac desktop - i.e., menus actually appear in the menu bar, where they belong. It also avoids the often tedious installation of GTK+ via MacPorts. However, it misses support for optional Gtk2Hs packages that are currently not supported by the [http://gtk-osx.sourceforge.net/ GTK+ OS X Framework], most notably support for Glade. It does include support for Cairo, though.
 
This explains how to install Gtk2Hs on Macs using the native [http://gtk-osx.sourceforge.net/ GTK+ OS X Framework], a port of GTK+ to the Mac that does '''not''' depend on X11, and hence, is better integrated into the Mac desktop - i.e., menus actually appear in the menu bar, where they belong. It also avoids the often tedious installation of GTK+ via MacPorts. However, it misses support for optional Gtk2Hs packages that are currently not supported by the [http://gtk-osx.sourceforge.net/ GTK+ OS X Framework], most notably support for Glade. It does include support for Cairo, though.
Line 58: Line 58:
 
NB: Thanks to Ross Mellgren for his post on the gtk2hs-users list that outlined the use of <tt>PKG_CONFIG_PATH</tt>.
 
NB: Thanks to Ross Mellgren for his post on the gtk2hs-users list that outlined the use of <tt>PKG_CONFIG_PATH</tt>.
   
==== Article as of Mid 2008 ====
+
== Article as of Mid 2008 ==
 
Installing Gtk2Hs on Mac requires some finesse, at least until Haskell Libary Platform is built or ghc-6.8.3 is
 
Installing Gtk2Hs on Mac requires some finesse, at least until Haskell Libary Platform is built or ghc-6.8.3 is
 
available in macports. (These are planned for late 2008.)
 
available in macports. (These are planned for late 2008.)
Line 100: Line 100:
 
sudo make install
 
sudo make install
   
==== Recent experiences ====
+
== Recent experiences ==
 
I successfully installed the latest version on Mac OS 10.5 by:
 
I successfully installed the latest version on Mac OS 10.5 by:
 
* Installing Macports.
 
* Installing Macports.

Revision as of 14:33, 29 August 2011

The Quick-Guide for OS X 10.6, 64bit, MacPorts

Setbacks: old ghc (6.10.4 as of 2011-03-10)

  • Install MacPorts (macports.org)
  • Add +universal to /opt/local/etc/macports/variants.conf (not needed on 32bit)
  • execute: sudo port install ghc gtk2 gvfs cairo librsvg libglade2 gtkglext gtksourceview2 && sudo port install gtk2hs -universal

Using MacPorts and Snow Leopard

This explains how to install Gtk2Hs-0.10.1 on Mac OS X 10.6 Snow Leopard, in combination with GTK+ from MacPorts.

  • Install the Haskell Platform for Mac
  • Download gtk2hs from gtk2hs website and untar it.
  • Install gtk, cairo, etc. from MacPorts like this (note that the +universal is needed; if you already installed gtk or one of its dependencies, it is recommended you reinstall those as detailed in the NB at the end of this section).
sudo port install gtk +universal
  • go to the directory where gtk2hs is untarred and run
./configure --disable-split-objs --disable-gio
make
sudo make install

Alternatively, if you wish to follow the Mac OS X style of directory layout, you can use this configure command instead:

./configure --with-pkgconf=/Users/username/.ghc/i386-darwin-6.10.4/package.conf --prefix=/Users/username/Library/Haskell/packages/gtk2hs --disable-split-objs --disable-gio

Where username is your username ofcourse. Right now you should be able to run the demos. Unfortunately, to build any libraries depending on gtk2hs, such as Chart, you need to edit one more file. You will need to find "package.conf" for your ghc by doing

ghc-pkg list

In the output you will see the full directory to your package.conf file. In this file, you need to search for "gthread", and everywhere you can find it, add "/opt/local/lib" (with quotes) to the libraryDirs array before it.

If all went well, it should be properly installed now.

NB: If compiling fails with architecture errors for certain dynlibs, you need to reinstall the packages these dynlibs belong to with +universal by doing

sudo port upgrade packagename --enforce-variants +universal

Alternatively, and this is recommended, you can follow the steps on Haskell On Snow Leopard Blogpost to immediately add the universal variant of each package:

  1. Edit /opt/local/macports/variants.conf and add +universal to the end of this file
  2. sudo port selfupdate
  3. sudo port sync
  4. sudo port upgrade --force-installed

Using the GTK+ OS X Framework

This explains how to install Gtk2Hs on Macs using the native GTK+ OS X Framework, a port of GTK+ to the Mac that does not depend on X11, and hence, is better integrated into the Mac desktop - i.e., menus actually appear in the menu bar, where they belong. It also avoids the often tedious installation of GTK+ via MacPorts. However, it misses support for optional Gtk2Hs packages that are currently not supported by the GTK+ OS X Framework, most notably support for Glade. It does include support for Cairo, though.

Here is how to install the library:

  1. Download and install GTK+ OS X Framework (this uses the standard Mac package installer).
  2. Install pkg-config, either by compiling it from source or via MacPorts.
  3. Download and unpack the Gtk2Hs tar ball from the Gtk2Hs download page (I tested 0.10.0).
  4. Configure with (you may want to remove the two backslashes and put everything on one line)
     env PKG_CONFIG_PATH=/Library/Frameworks/Cairo.framework/Resources/dev/lib/pkgconfig:\ 
     /Library/Frameworks/GLib.framework/Resources/dev/lib/pkgconfig:\ 
     /Library/Frameworks/Gtk.framework/Resources/dev/lib/pkgconfig ./configure --disable-gio
  1. Build with
     make
  1. Install (to /usr/local/ unless a --prefix option was passed to configure) with
     sudo make install

The library is now registered with the package database of the GHC you used for compiling.

NB: Thanks to Ross Mellgren for his post on the gtk2hs-users list that outlined the use of PKG_CONFIG_PATH.

Article as of Mid 2008

Installing Gtk2Hs on Mac requires some finesse, at least until Haskell Libary Platform is built or ghc-6.8.3 is available in macports. (These are planned for late 2008.)

sudo port install glade3 libglade2 gstreamer gst-plugins-base gtksourceview cairo librsvg gtkglext firefox
  • Update PKG_CONFIG_PATH (for libraries)
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/local/lib/pkgconfig
  • Update ghc to use macports libs: Edit your main ghc driver program and change the last line to:
exec $GHCBIN $TOPDIROPT ${1+"$@"} -L/opt/local/lib -I/opt/local/include
./configure --enable-docs --enable-profiling

...

**************************************************
* Configuration completed successfully.           
*                                                 
* The following packages will be built:           
*                                                 
* glib          : yes                             
* gtk           : yes                             
* glade         : yes              
* cairo         : yes                 
* svgcairo      : yes              
* gtkglext      : yes              
* gconf         : yes                 
* sourceview    : yes            
* mozembed      : yes              
* soegtk        : yes                             
* gnomevfs      : yes              
* gstreamer     : yes             
* documentation : yes                    
*                                                 
* Now do "(g)make" followed by "(g)make install"
**************************************************
  • Build and Install:
make 
sudo make install

Recent experiences

I successfully installed the latest version on Mac OS 10.5 by:

  • Installing Macports.
  • sudo port install ghc
  • sudo port install gtk2hs - which does not complete successfully. It does however, install the appropriate dependencies. Note that there are so many, you may need to install a couple of times due to time outs etc.. The build of Gtk2HS will fail, but that is ok - continue as below. Also note that ghc configure will give up if your perl5.8 is not new enough, if so deactivate it and try again.
  • Remove the build directory under /opt/.../build/gtk2hs
  • Download Gtk2Hs via darcs as per the gtk2hs download instructions
  • do a sudo port install automake
  • do a sudo port install alex
  • do a sudo port install happy (Note this also fails and must be built from source. See the Happy page for details.)
  • Follow the build instructions on the the gtk2hs download page. I would suggest using ./configure --prefix=/opt/local to get it in the same place as ports - personal preference though.

Good luck - as usual, your mileage may vary.