Making Ruby-Gnome2-0.18.1 One-Click Installer for Windows: Draft

This document is aimed to replace http://ruby-gnome2.sourceforge.jp/hiki.cgi?compile_mingw
It's a revision of http://d.hatena.ne.jp/luna_8bit/20081207#1228616216.


You can also build a binary for Ruby-1.8.6-p111 along this process.

My Environment

C:\
    ruby-gnome2-dev\
        dist\ ...................... installation directory
        ruby-1.8.7-p72\ ............ ruby source code
        rcairo-1.6.3\ .............. rcairo source code
        ruby-gnome2-all-0.18.1\ .... ruby-gnome2 source code
        win32installer\...... ...... ruby-gnome2 win32installer source code
    GTK\ ........................... GTK
    MinGW\ ......................... MinGW
    msys\1.0\ ...................... MSYS
    Program Files\NSIS\ ............ NSIS

Set up Build Environment

The build process requires MinGW and Glade for Win32, and NSIS.

MinGW and MSYS

MinGW and MSYS are found at http://www.mingw.org/.
Download and install them with default options.
MSYS-1.0.11 and MSYS-DTK are not required.
I've experienced some trouble with build process of ruby-1.8.7-p72 on MSYS-1.0.11 with MSYS-DTK.

  • MinGW-5.1.4.exe
  • MSYS-1.0.10.exe
    • installed in C:\msys
Glade for Win32

Glade for Win32 is found at http://gladewin32.sourceforge.net/ .
Download "Gtk+ 2.x.x Development Environment" and install it with default options.

  • gtk-dev-2.12.9-win32-2.exe
    • installed in C:\GTK


Ruby-Gnome2-all depends on additional Gnome libraries, listed below.
They are found at http://ftp.gnome.org/pub/gnome/binaries/win32/ .
Download "foo-version.zip" and "foo-dev-version.zip", and extract them to C:\GTK.
I used GNOME 2.22 libraries.

  • GConf-2.20.0
  • ORBit2-2.14.3
  • gail-1.22.0
  • gnome-vfs.2.22.0
  • goocanvas-0.12
  • gtksourceview-1.8.5
  • gtksourceview-2.2.2
  • libbonobo-2.22.0
  • libbonoboui-2.22.0
  • libgnome-2.20.1
  • libgnomecanvas-2.22.0
  • libgnomeprint-1.12.1
  • libgnomeprintui-1.12.1
  • libgnomeui-2.22.1
  • libgnomeprint-2.12.1
  • libgnomeprintui-2.12.1
  • poppler-0.6.4 (poppler-data is required)


C:\GTK\lib\pkgconfig\cairo.pc bundled in current Glade for Win32 requires a modification.

--- cairo.pc.org        Sun Apr 20 01:14:48 2008
+++ cairo.pc    Sat Dec  6 19:34:08 2008
@@ -7,7 +7,7 @@
 Description: Multi-platform 2D graphics library
 Version: 1.6.4
 
-Requires.private: freetype2 >= 9.7.3 fontconfig libpng12 pixman-1 >= 0.10.0 
+Requires.private: freetype2 >= 9.7.3 fontconfig libpng12 
 Libs: -L${libdir} -lcairo
 Libs.private: -lz -lz -lm
 Cflags: -I${includedir}/cairo

pixman is statically linked to cairo-1.6.4-win32.
This trouble is fixed in cairo-1.6.4-2 found at http://ftp.gnome.org/pub/gnome/binaries/win32.
refernece: http://www.nabble.com/pixman-1-was-not-found-in-the-pkg-config-td16842574.html


Set environment values.

SET PKG_CONFIG_PATH=C:\GTK\lib\pkgconfig
SET PATH=C:\GTK\bin;%PATH%
NSIS

NSIS is found at http://nsis.sourceforge.net/.
Download and install with default options.

  • nsis-2.44-setup.exe
    • installed in C:\Program Files\NSIS

Launch MSYS

Launch MSYS and unset RUBYOPT.

unset RUBYOPT

Make sure PKG_CONFIG_PATH and other environment values are correctly set.

Build and Instal Ruby

You need to build and install Ruby-mingw32 before building Ruby-Gnome2.
Ruby source code is found at http://www.ruby-lang.org/.
I used ruby-1.8.7-p72.

melopan@unu /c/ruby-gnome2-dev/ruby-1.8.7-p72
$ ./configure --prefix=/ruby-gnome2-dev/dist
$ make
$ make install 

Note that prefix is "/ruby-gnome2-dev/dist", not "/c/ruby-gnome2-dev/dist".
I'm not sure why it is.

Build and Install rcairo

rcairo source code is found at http://cairographics.org/releases/.
I used rcairo-1.6.3.

melopan@unu /c/ruby-gnome2-dev/rcairo-1.6.3
$ /c/ruby-gnome2-dev/dist/bin/ruby.exe extconf.rb --ruby=/c/ruby-gnome2-dev/dist/bin/ruby.exe --with-override-variables=prefix=/c/GTK
$ make
$ make install 

Option "--with-override-variables=prefix=/c/GTK" is required.
This is because package config files in Glade for Win32 have "/target" as property "prefix", and pkg-config.rb uses it to look up GTK headers and libraries.

Modify Ruby-Gnome2 Source Code

Ruby-Gnome2 source code is found at http://ruby-gnome2.sourceforge.jp/.
I used ruby-gnome2-all-0.18.1.


This process requires some modifications to downloaded files.

  • for rbbonobo-main.c: Windows has no X
  • for rbgnome.h: There's a collision between sys/time.h and ruby/win32/win32.h
  • for rbart_canvas.c: There are collisions of boolean and INT32 between jpeglib and MinGW libraries
    • using boolean in jpeglib
    • using INT32 in MinGW libraries
Index: bonobo/src/rbbonobo-main.c
===================================================================
--- bonobo/src/rbbonobo-main.c	(revision 3612)
+++ bonobo/src/rbbonobo-main.c	(working copy)
@@ -97,7 +97,9 @@
 rbonobo_setup_x_error_handler(self)
     VALUE self;
 {
+#ifndef __MINGW32__
     bonobo_setup_x_error_handler();
+#endif
     return self;
 }
 
Index: gnome/src/rbgnome.h
===================================================================
--- gnome/src/rbgnome.h	(revision 3612)
+++ gnome/src/rbgnome.h	(working copy)
@@ -20,7 +20,9 @@
 
 #define ENABLE_NLS 1
 
+#ifndef __MINGW32__
 #include <sys/time.h>
+#endif
 #include <gnome.h>
 
 #undef PATH_SEP
Index: libart/src/rbart_canvas.c
===================================================================
--- libart/src/rbart_canvas.c	(revision 3612)
+++ libart/src/rbart_canvas.c	(working copy)
@@ -11,7 +11,17 @@
 
 **********************************************************************/
 
+#ifdef __MINGW32__
+#define XMD_H
+#endif
+
+#ifdef __MINGW32__
+#define boolean boolean2
 #include "rbart.h"
+#undef boolean
+#else
+#include "rbart.h"
+#endif
 
 #include <jpeglib.h>
 #include <png.h>

Build Ruby-Gnome2

Set environment value CAIRO_PATH=$(rcairo source directory).

export CAIRO_PATH=/c/ruby-gnome2-dev/rcairo-1.6.3

Build glib at first. But DO NOT install.

melopan@unu /c/ruby-gnome2-dev/ruby-gnome2-all-0.18.1/glib
$ /c/ruby-gnome2-dev/dist/bin/ruby.exe extconf.rb --ruby=/c/ruby-gnome2-dev/dist/bin/ruby.exe
$ make

Build remaining targets. But DO NOT install.

melopan@unu /c/ruby-gnome2-dev/ruby-gnome2-all-0.18.1
$ /c/ruby-gnome2-dev/dist/bin/ruby.exe extconf.rb --ruby=/c/ruby-gnome2-dev/dist/bin/ruby.exe
$ make

Build process of gnomecanvas, gnomeprint, gnomeprintui fail at first.
Do make them again.

$ make

Then all the configured targets are built.
Built targets and ignored ones are listed below.

-----
Target libraries: glib, gdkpixbuf, pango, atk, gtk, bonobo, bonoboui, gconf, gnome, 
gnomecanvas, gnomeprint, gnomeprintui, gnomevfs, goocanvas, gtkglext, gtksourceview, 
gtksourceview2, libart, libglade, poppler, rsvg
Ignored libraries: gstreamer, gtkhtml2, gtkmozembed, libgda, panel-applet, vte
-----

Install Rake

Installer building process requires rake.


Add installation directory to PATH.

export PATH=/c/ruby-gnome2-dev/dist/bin:$PATH

Install rake in the installation directory.
rake is found at http://rake.rubyforge.org/.

melopan@unu /c/ruby-gnome2-dev/rake-0.8.3
$ /c/ruby-gnome2-dev/dist/bin/ruby.exe install.rb

Modify win32installer/Rakefile

This build process requires some modifications of win32installer/Rakefile.

Index: Rakefile
===================================================================
--- Rakefile	(revision 3612)
+++ Rakefile	(working copy)
@@ -28,7 +28,7 @@
 # Don't touch below
 #
 desc "Call all other tasks"
-task :default => [:copyglade, :copydoc, :copyrcairo, :copyrgnome2]
+task :default => [:copyglade, :copydoc, :copysamples, :copyrcairo, :copyrgnome2]
 
 desc "Copy gtk libs from GTK_DIR to GTK dir"
 task :copygtk do
@@ -105,7 +105,8 @@
   mkdir_p dest_dir unless File.exist? dest_dir
   cp_r(File.join(sitelibdir, "cairo.rb"), dest_dir)
   mkdir_p File.join(dest_dir, "cairo") unless File.exist? File.join(dest_dir, "cairo")
-  cp_r(Dir.glob(File.join(sitelibdir, "cairo")), File.join(dest_dir, "cairo"))
+  mkdir_p File.join(dest_dir, "i386-msvcrt") unless File.exist? File.join(dest_dir, "i386-msvcrt")
+  cp_r(Dir.glob(File.join(sitelibdir, "cairo")), dest_dir)
   cp_r(Dir.glob(File.join(sitelibdir, "i386-msvcrt", "cairo.so")), File.join(dest_dir, "i386-msvcrt"))
   cp_r(Dir.glob(File.join(sitelibdir, "i386-msvcrt", "rb_cairo.h")), File.join(dest_dir, "i386-msvcrt"))
 end
@@ -119,14 +120,18 @@
       path.gsub!(/[\r\n]/, "")
       dest_path = path.gsub(/^.*site_ruby/, "ruby/lib/ruby/site_ruby")
       mkdir_p dest_path unless File.exist? dest_path
-      cp_r(File.join(path, File.basename(filename)), dest_path)
+      if path != dest_path
+        cp_r(File.join(path, File.basename(filename)), dest_path)
+      end
     elsif /chmod 0644/ =~ line
       path = line.split(/ /)[2]
       path.gsub!(/[\r\n]/, "")
       dest_path = path.gsub(/^.*site_ruby/, "ruby/lib/ruby/site_ruby")
       dest_path = File.dirname(dest_path)
       mkdir_p dest_path unless File.exist? dest_path
-      cp_r(path, dest_path)
+      if path != dest_path
+        cp_r(path, dest_path)
+      end
     end
   end
 end

Edit win32installer/Rakefile, setup.nsi, and other documents

Edit Rakefile

# You need the gladewin32 devel package not runtime.
GTK_DIR     = "c:/GTK" 
CAIRO_DIR   = "c:/ruby-gnome2-dev/rcairo-1.6.3"
MINGW_DIR   = "c:\\MinGW"
MSYS_DIR    = "c:\\msys\\1.0"
NSIS_DIR    = "C:\\Program Files\\NSIS"
RGNOME2_DIR = "c:/ruby-gnome2-dev/ruby-gnome2-all-0.18.1"
INSTALL_LOG = File.join(RGNOME2_DIR, "install.log")

Edit setup.nsi

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Ruby-GNOME2"
!define PRODUCT_VERSION "0.18.0-1"
!define PRODUCT_PUBLISHER "Kouhei Sutou"
!define PRODUCT_WEB_SITE "http://ruby-gnome2.sourceforge.jp/"

Modify ChangeLog.txt, HOWTO.txt, NEWS_win32.txt, README_win32.txt.

Install and Enumerate Ruby-Gnome2 files

melopan@unu /c/ruby-gnome2-dev/win32installer
$ rake makeinstall

install.log is created in ruby-gnome2 source directory.

Copy GTK binaries to the working directory

melopan@unu /c/ruby-gnome2-dev/win32installer
$ rake copygtk

Copy ruby-gnome2 and rcairo binaries to the working directory

melopan@unu /c/ruby-gnome2-dev/win32installer
$ rake

Make installer

melopan@unu /c/ruby-gnome2-dev/win32installer
rake makensis