File: retrieve.rake

package info (click to toggle)
ruby-dataobjects-mysql 0.10.17-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 372 kB
  • sloc: ansic: 1,420; ruby: 653; sh: 30; makefile: 13
file content (67 lines) | stat: -rw-r--r-- 2,345 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
begin
  gem 'rake-compiler', '~>0.7'
  require 'rake/clean'
  require 'rake/extensioncompiler'

  # download mysql library and headers
  directory "vendor"

  # only on Windows or cross platform compilation
  def dlltool(dllname, deffile, libfile)
    # define if we are using GCC or not
    if Rake::ExtensionCompiler.mingw_gcc_executable then
      dir = File.dirname(Rake::ExtensionCompiler.mingw_gcc_executable)
      tool = case RUBY_PLATFORM
        when /mingw/
          File.join(dir, 'dlltool.exe')
        when /linux|darwin/
          File.join(dir, "#{Rake::ExtensionCompiler.mingw_host}-dlltool")
      end
      return "#{tool} --dllname #{dllname} --def #{deffile} --output-lib #{libfile}"
    else
      if RUBY_PLATFORM =~ /mswin/ then
        tool = 'lib.exe'
      else
        fail "Unsupported platform for cross-compilation (please, contribute some patches)."
      end
      return "#{tool} /DEF:#{deffile} /OUT:#{libfile}"
    end
  end

  file "vendor/mysql-noinstall-#{BINARY_VERSION}-win32.zip" => ['vendor'] do |t|
    base_version = BINARY_VERSION.gsub(/\.[0-9]+$/, '')
    url = "http://mysql.proserve.nl/Downloads/MySQL-#{base_version}/#{File.basename(t.name)}"
    when_writing "downloading #{t.name}" do
      cd File.dirname(t.name) do
        sh "wget -c #{url} || curl -L -C - -O #{url}"
      end
    end
  end

  file "vendor/mysql-#{BINARY_VERSION}-win32/include/mysql.h" => ["vendor/mysql-noinstall-#{BINARY_VERSION}-win32.zip"] do |t|
    full_file = File.expand_path(t.prerequisites.last)
    when_writing "creating #{t.name}" do
      cd "vendor" do
        sh "unzip #{full_file} mysql-#{BINARY_VERSION}-win32/bin/** mysql-#{BINARY_VERSION}-win32/include/** mysql-#{BINARY_VERSION}-win32/lib/**"
      end
      # update file timestamp to avoid Rake perform this extraction again.
      touch t.name
    end
  end

  # clobber vendored packages
  CLOBBER.include('vendor')

  # vendor:mysql
  task 'vendor:mysql' => ["vendor/mysql-#{BINARY_VERSION}-win32/include/mysql.h"]

  # hook into cross compilation vendored mysql dependency
  if RUBY_PLATFORM =~ /mingw|mswin/ then
    Rake::Task['compile'].prerequisites.unshift 'vendor:mysql'
  else
    if Rake::Task.tasks.map {|t| t.name }.include? 'cross'
      Rake::Task['cross'].prerequisites.unshift 'vendor:mysql'
    end
  end
rescue LoadError
end