# -*- ruby -*-

$LOAD_PATH.unshift("./lib")
require 'gnome2-raketask'

libffi_lib_dir     = nil
libffi_include_dir = nil

package = GNOME2Package.new do |_package|
  libffi_lib_dir     = File.join(_package.win32.absolute_binary_dir, "lib")
  libffi_include_dir = File.join(_package.win32.absolute_binary_dir, "include")

  _package.summary = "Ruby/GLib2 is a Ruby binding of GLib-2.x."
  _package.description = "Ruby/GLib2 is a Ruby binding of GLib-2.x."
  _package.dependency.gem.runtime = [["pkg-config", ">= 0"]]
  _package.dependency.gem.development = [["test-unit", ">= 2"]]
  _package.win32.packages = []
  _package.win32.dependencies = ["zlib", "libffi", "gettext-runtime"]
  _package.win32.build_packages = [
    {
      :name => "glib",
      :download_site => :gnome,
      :label => "GLib",
      :version => "2.36.0",
      :configure_args => [
        "LIBFFI_CFLAGS=-I#{libffi_include_dir}",
        "LIBFFI_LIBS=-L#{libffi_lib_dir} -lffi",
        "--disable-modular-tests",
      ],
      :compression_method => "xz",
    },
    {
      :name => "gmp",
      :download_base_url => "ftp://ftp.gmplib.org/pub/gmp-5.1.0",
      :label => "GNU MP",
      :version => "5.1.0",
      :configure_args => [
        "--disable-static",
        "--enable-shared",
      ],
      :compression_method => "bz2",
    },
    {
      :name => "nettle",
      :download_base_url => "http://www.lysator.liu.se/~nisse/archive",
      :label => "Nettle",
      :version => "2.5",
      :configure_args => [],
    },
    {
      :name => "gnutls",
      :download_base_url => "ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1",
      :label => "GnuTLS",
      :version => "3.1.10",
      :configure_args => [
        "--with-libnettle-prefix=#{_package.win32.absolute_binary_dir}"
      ],
      :compression_method => "xz",
    },
    {
      :name => "glib-networking",
      :download_site => :gnome,
      :label => "glib-networking",
      :version => "2.36.0",
      :configure_args => [
        "--without-libproxy",
        "--without-gnome-proxy",
        "--without-ca-certificates",
      ],
      :compression_method => "xz",
    },
  ]
end
package.define_tasks

namespace :win32 do
  namespace :libffi do
    namespace :header do
      desc "Move libffi headers to include/"
      task :fix do
        libffi_version = "libffi-3.0.6"
        mv(Dir.glob(File.join(libffi_lib_dir, libffi_version, "include", "*.h")),
           libffi_include_dir)
        rm_rf(File.join(libffi_lib_dir, libffi_version))
      end
    end
  end

  namespace :downloader do
    task :after => ["win32:libffi:header:fix"]
  end
end
