# -*- ruby -*-
#
# Copyright (C) 2011-2015  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/GStreamer is a Ruby binding for GStreamer."
  package.description = "Ruby/GStreamer is a Ruby binding for GStreamer."
  package.dependency.gem.runtime = ["glib2", "gobject-introspection"]
  package.windows.packages = []
  package.windows.dependencies = []
  package.windows.build_dependencies = [
    "glib2", "atk", "pango", "gdk_pixbuf2", "gtk2", "gobject-introspection",
  ]
  xiph_download_url_base = "http://downloads.xiph.org/releases"
  sf_net_download_url_base = "http://downloads.sourceforge.net/project"
  libmad_version = "0.15.1b"
  package.external_packages = [
    {
      :name => "libjpeg",
      :base_name => "jpeg-9b",
      :archive_base_name => "jpegsrc.v9b.tar.gz",
      :download_base_url => "http://www.ijg.org/files",
      :label => "libjpeg",
      :windows => {
        :configure_args => [],
        :built_file => "bin/libjpeg-9.dll",
      },
    },
    {
      :name => "sqlite-autoconf",
      :download_base_url => "http://www.sqlite.org/2016",
      :label => "SQLite",
      :version => "3140100",
      :compression_method => "gz",
      :windows => {
        :configure_args => [],
        :built_file => "bin/libsqlite3-0.dll",
      },
    },
    {
      :name => "libsoup",
      :download_site => :gnome,
      :label => "libsoup",
      :version => "2.62.0",
      :compression_method => "xz",
      :windows => {
        :configure_args => [
          "--enable-introspection",
          "--without-apache-httpd",
          "--disable-tls-check",
        ],
        :build_concurrently => false,
        :patches => [
        ],
        :built_file => "bin/libsoup-2.4-1.dll",
      },
    },
    {
      :name => "libogg",
      :download_base_url => "#{xiph_download_url_base}/ogg",
      :label => "Ogg",
      :version => "1.3.2",
      :windows => {
        :configure_args => [],
        :built_file => "bin/libogg-0.dll",
      },
    },
    {
      :name => "libvorbis",
      :download_base_url => "#{xiph_download_url_base}/vorbis",
      :label => "Vorbis",
      :version => "1.3.5",
      :windows => {
        :configure_args => [],
        :built_file => "bin/libvorbis-0.dll",
      },
    },
    {
      :name => "libtheora",
      :download_base_url => "#{xiph_download_url_base}/theora",
      :label => "Theora",
      :version => "1.1.1",
      :windows => {
        :configure_args => [
          "--disable-examples"
        ],
        :build_concurrently => false,
        :patches => [
          "libtheora-1.1.1-use-lf-in-def.diff",
        ],
        :built_file => "bin/libtheora-0.dll",
      },
    },
    # {
    #   :name => "libmad",
    #   :download_base_url => "#{sf_net_download_url_base}/mad/libmad/#{libmad_version}",
    #   :label => "MAD",
    #   :version => libmad_version,
    #   :windows => {
    #     :configure_args => ["CFLAGS=-O3 -march=i686"],
    #     :need_autoreconf => true,
    #     :patches => ["libmad-0.15.1b-fix-mingw-build.diff"],
    #   },
    # },
    {
      :name => "flac",
      :download_base_url => "#{xiph_download_url_base}/flac",
      :label => "FLAC",
      :version => "1.3.1",
      :compression_method => "xz",
      :windows => {
        :configure_args => ["--disable-cpplibs"],
        :built_file => "bin/libFLAC-8.dll",
      },
    },
    {
      :name => "opus",
      :download_base_url => "#{xiph_download_url_base}/opus",
      :label => "Opus",
      :version => "1.1.2",
      :windows => {
        :configure_args => [],
        :built_file => "bin/libopus-0.dll",
      },
    },
    {
      :name => "gstreamer",
      :download_site => :freedesktop_gstreamer,
      :label => "GStreamer",
      :version => "1.12.4",
      :compression_method => "xz",
      :windows => {
        :cc_args => "-std=gnu99",
        :configure_args => [
          "--disable-check",
          "--enable-introspection",
        ],
        :build_concurrently => false,
        :patches => [
        ],
        :need_autoreconf => true,
        :gobject_introspection_compiler_split_args => true,
        :built_file => "bin/libgstreamer-1.0-0.dll",
      },
    },
    {
      :name => "gst-plugins-base",
      :download_site => :freedesktop_gstreamer,
      :label => "GStreamer plugins (base)",
      :version => "1.12.4",
      :compression_method => "xz",
      :windows => {
        :configure_args => [
          "--enable-introspection",
        ],
        :cc_args => [
          "-std=gnu99",
        ],
        :build_concurrently => false,
        :patches => [
        ],
        :need_autoreconf => true,
        :gobject_introspection_compiler_split_args => true,
        :built_file => "lib/gstreamer-1.0/libgstgio.dll",
      },
    },
    {
      :name => "gst-plugins-good",
      :download_site => :freedesktop_gstreamer,
      :label => "GStreamer plugins (good)",
      :version => "1.12.4",
      :compression_method => "xz",
      :windows => {
        :configure_args => [
          "--disable-shout2",
        ],
        :gobject_introspection_compiler_split_args => true,
        :built_file => "lib/gstreamer-1.0/libgstcairo.dll",
      },
    },
    {
      :name => "gst-plugins-bad",
      :download_site => :freedesktop_gstreamer,
      :label => "GStreamer plugins (bad)",
      :version => "1.12.4",
      :compression_method => "xz",
      :windows => {
        :configure_args => ["--disable-librfb"],
        :cc_args => [
          "-std=gnu99",
        ],
        :need_autoreconf => true,
        :gobject_introspection_compiler_split_args => true,
        :patches => [
          "gst-plugins-bad-1.8.0-use-only-I.diff",
        ],
        :built_file => "lib/gstreamer-1.0/libgstmxf.dll",
      },
    },
    # {
    #   :name => "gst-plugins-ugly",
    #   :download_site => :freedesktop_gstreamer,
    #   :label => "GStreamer plugins (ugly)",
    #   :version => "1.8.0",
    #   :compression_method => "xz",
    #   :windows => {
    #     :configure_args => [],
    #     :gobject_introspection_compiler_split_args => true,
    #   },
    # },
    {
      :name => "gst-libav",
      :download_site => :freedesktop_gstreamer,
      :label => "GStreamer libav",
      :version => "1.12.4",
      :compression_method => "xz",
      :windows => {
        :configure_args => [
          "--with-libav-extra-configure=" +
            "--cross-prefix=#{package.windows.build_host}- " +
            "--target-os=mingw32 " +
            "--arch=#{package.windows.build_arch} " +
            "--pkg-config=pkg-config " +
            "--disable-gpl " +
            "--disable-yasm",
        ],
        :gobject_introspection_compiler_split_args => true,
        :built_file => "lib/gstreamer-1.0/libgstlibav.dll",
      },
      :bundled_packages => [
        {
          :name => "libav",
          :path => "gst-libs/ext/libav",
          :license_files => [
            "LICENSE.md",
            "CREDITS",
            "COPYING.GPLv2",
            "COPYING.GPLv3",
            "COPYING.LGPLv2.1",
            "COPYING.LGPLv3",
          ],
        }
      ],
    },
  ]
  package.cross_compiling do |spec|
    if /mingw|mswin/ =~ spec.platform.to_s
      spec.add_runtime_dependency("pango", ">= #{package.version}")
      spec.add_runtime_dependency("gdk_pixbuf2", ">= #{package.version}")
    end
  end
end
package_task.define
