# -*- ruby -*-
#
# Copyright (C) 2012-2017  Ruby-GNOME2 Project Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

$LOAD_PATH.unshift("./../glib2/lib")
require "gnome2/rake/package-task"

package_task = GNOME2::Rake::PackageTask.new do |package|
  package.summary = "Ruby/Clutter is a Ruby binding of Clutter."
  package.description = "Ruby/Clutter is a Ruby binding of Clutter."
  package.dependency.gem.runtime = [
    "cairo-gobject",
    "gobject-introspection",
    "pango"
  ]
  package.windows.packages = []
  package.windows.dependencies = []
  package.windows.build_dependencies = [
    "glib2",
    "atk",
    "pango",
    "gdk_pixbuf2",
    "gdk3",
    "gobject-introspection",
  ]
  package.windows.gobject_introspection_dependencies = [
    "atk",
    "pango",
    "gdk_pixbuf2",
    "gdk3",
  ]
  package.external_packages = [
    # Build note:
    #   We need to modify /usr/i686-w64-mingw32/include/GL/ directory because
    #   MinGW w64 bundles old OpenGL headers. Here are changes to build Cogl:
    #
    #   (1) Put the latest glext.h that can be downloaded from
    #       https://www.opengl.org/registry/api/GL/glext.h into
    #       /usr/share/mingw-w64/include/GL/ directory:
    #
    #         % wget https://www.opengl.org/registry/api/GL/glext.h
    #         % sudo install glext.h /usr/share/mingw-w64/include/GL/
    #
    #   (2) Add missing declarations and includes to
    #       /usr/share/mingw-w64/include/GL/gl.h:
    #
    #       Before:
    #         ...
    #         typedef double GLdouble;
    #         typedef double GLclampd;
    #         typedef void GLvoid;
    #
    #         #define GL_VERSION_1_1 1
    #         ...
    #
    #       After
    #         ...
    #         typedef double GLdouble;
    #         typedef double GLclampd;
    #         typedef void GLvoid;
    #
    #         typedef ptrdiff_t GLintptr;
    #         typedef ptrdiff_t GLsizeiptr;
    #         typedef char GLchar;
    #         #include <GL/glext.h>
    #
    #         #define GL_VERSION_1_1 1
    #         ...
    {
      :name => "cogl",
      :download_site => :gnome,
      :label => "Cogl",
      :version => "1.22.2",
      :compression_method => "xz",
      :windows => {
        :configure_args => [
          "--disable-glibtest",
          "--enable-introspection",
        ],
        :built_file => "bin/libcogl-20.dll",
      },
    },
    {
      :name => "json-glib",
      :download_site => :gnome,
      :label => "JSON-GLib",
      :version => "1.4.2",
      :compression_method => "xz",
      :windows => {
        :configure_args => [
          "--enable-introspection",
        ],
        :patches => [
          # "json-glib-1.0.2-add-missing-config-h.diff",
        ],
        :built_file => "bin/libjson-glib-1.0-0.dll",
      },
    },
    {
      :name => "clutter",
      :download_site => :gnome,
      :label => "Clutter",
      :version => "1.26.2",
      :compression_method => "xz",
      :windows => {
        :configure_args => [
          "--enable-introspection",
          "--enable-gdk-backend",
          "--enable-gdk-pixbuf",
        ],
        :build_concurrently => false,
        :built_file => "bin/libclutter-1.0-0.dll",
      },
    }
  ]
  package.cross_compiling do |spec|
    if /mingw|mswin/ =~ spec.platform.to_s
      spec.add_runtime_dependency("gdk3", "= #{package.version}")
    end
  end
end
package_task.define

if Rake::Task.task_defined?("native:clutter:i386-mingw32")
  Rake::Task["native:clutter:i386-mingw32"].prerequisites.clear
end
