[cairo-commit] rcairo/packages/cairo/ext cairo.def, NONE, 1.1 extconf.rb, 1.6, 1.7 pkg-config.rb, NONE, 1.1 rb_cairo.h, 1.5, 1.6

Kouhei Sutou commit at pdx.freedesktop.org
Mon Oct 3 20:08:43 PDT 2005


Committed by: kou

Update of /cvs/cairo/rcairo/packages/cairo/ext
In directory gabe:/tmp/cvs-serv10159/packages/cairo/ext

Modified Files:
	extconf.rb rb_cairo.h 
Added Files:
	cairo.def pkg-config.rb 
Log Message:
Support Win32 platform.

* packages/cairo/ext/rb_cairo.h: Support Win32 platform.
* packages/cairo/ext/extconf.rb: ditto.
* packages/cairo/ext/cairo.def: Added.
* packages/cairo/ext/pkg-config.rb: Added. This file is from
  Ruby/GLib.


--- NEW FILE: cairo.def ---
EXPORTS
    Init_cairo
    rb_mCairo             DATA
    rb_cCairo_Context     DATA
    rb_cCairo_Matrix      DATA
    rb_cCairo_Pattern     DATA
    rb_cCairo_FontFace    DATA
    rb_cCairo_FontExtents DATA
    rb_cCairo_TextExtents DATA
    rb_cCairo_Glyph       DATA
    rb_cCairo_Surface     DATA
    rb_cairo_context_from_ruby_object
    rb_cairo_context_to_ruby_object
    rb_cairo_matrix_from_ruby_object
    rb_cairo_matrix_to_ruby_object
    rb_cairo_pattern_from_ruby_object
    rb_cairo_pattern_to_ruby_object
    rb_cairo_font_face_from_ruby_object
    rb_cairo_font_face_to_ruby_object
    rb_cairo_font_extents_from_ruby_object
    rb_cairo_font_extents_to_ruby_object
    rb_cairo_text_extents_from_ruby_object
    rb_cairo_text_extents_to_ruby_object
    rb_cairo_glyph_from_ruby_object
    rb_cairo_glyph_to_ruby_object
    rb_cairo_surface_from_ruby_object
    rb_cairo_surface_to_ruby_object
    

Index: extconf.rb
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/extconf.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- extconf.rb	29 Sep 2005 06:53:47 -0000	1.6
+++ extconf.rb	4 Oct 2005 03:08:41 -0000	1.7
@@ -1,26 +1,67 @@
 #!/usr/bin/env ruby
-# vim: filetype=ruby:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+# vim: filetype=ruby:expandtab:shiftwidth=2:tabstop=8:softtabstop=2 :
 
 require 'mkmf'
+require 'pkg-config'
 require 'fileutils'
 
-pkg = "cairo"
-modname = "cairo"
-major, minor, micro = 1, 0, 0
+# from mkmf-gnome2.rb
+STDOUT.print("checking for GCC... ")
+STDOUT.flush
+if macro_defined?("__GNUC__", "")
+  STDOUT.print "yes\n"
+  $CFLAGS += ' -Wall' 
+  $cc_is_gcc = true
+else
+  STDOUT.print "no\n"
+  $cc_is_gcc = false
+end
 
-check_version = Proc.new do
-  modversion = `#{$PKGCONFIG} --modversion #{pkg}`.chomp
-  ver = modversion.split(".").collect{|item| item.to_i}
-  (0..2).each {|i| ver[i] ||= 0}
-  (ver <=> [major, minor, micro]) >= 0
+def check_win32()
+  STDOUT.print("checking for Win32 OS... ")
+  STDOUT.flush
+  if /mingw/ =~ RUBY_PLATFORM
+    STDOUT.print "yes\n"
+    if $cc_is_gcc
+      if /^2\./ =~ `#{Config::CONFIG['CC']} -dumpversion`.chomp
+        $CFLAGS += ' -fnative-struct'
+      else
+        $CFLAGS += ' -mms-bitfields'
+      end
+    end
+  else
+    STDOUT.print "no\n"
+  end
 end
 
-STDOUT.print("checking for #{pkg} version (>= #{major}.#{minor}.#{micro})... ")
+def set_output_lib(target_name)
+  filename = "libruby-#{target_name}.a"
+  if /cygwin|mingw/ =~ RUBY_PLATFORM
+    $defs << "-DRUBY_CAIRO_PLATFORM_WIN32"
+    if RUBY_VERSION > "1.8.0"
+      $DLDFLAGS << ",--out-implib=#{filename}" if filename
+    elsif RUBY_VERSION > "1.8"
+      CONFIG["DLDFLAGS"].gsub!(/ -Wl,--out-implib=[^ ]+/, '')
+      CONFIG["DLDFLAGS"] << " -Wl,--out-implib=#{filename}" if filename
+    else
+      CONFIG["DLDFLAGS"].gsub!(/ --output-lib\s+[^ ]+/, '')
+      CONFIG["DLDFLAGS"] << " --output-lib #{filename}" if filename
+    end
+  end
+end
 
-if pkg_config(pkg) and check_version.call
-  STDOUT.print("yes\n")
-  create_makefile(modname)
-else
-  STDOUT.print("no\n")
-  FileUtils.rm_f("Makefile")
+def setup_win32(target_name)
+  check_win32
+  set_output_lib(target_name)
 end
+
+
+pkg = "cairo"
+modname = "cairo"
+major, minor, micro = 1, 0, 0
+
+PKGConfig.have_package(pkg, major, minor, micro) or exit 1
+
+setup_win32(modname)
+$defs << "-DRUBY_CAIRO_COMPILATION"
+create_makefile(modname)

--- NEW FILE: pkg-config.rb ---
#
# pkg-config.rb
#
# Wrapper of pkg-config tool.
#
# Copyright(C) 2003-2005 Ruby-GNOME2 Project.
#
# This program is licenced under the same
# license of Ruby-GNOME2.
#

require 'mkmf'
require 'shellwords'

module PKGConfig
  @@cmd = with_config('pkg-config', ENV["PKG_CONFIG"] ||  'pkg-config')
  if /mswin32/ =~ RUBY_PLATFORM and /^cl\b/ =~ Config::CONFIG['CC']
    @@cmd += ' --msvc-syntax'
  end

  @@list = {}
  `#{@@cmd} --list-all`.chomp.split(/\n/).each{|v| 
    pkg, name, desc = /(\S+?)\s+(.*?)\s-\s(.*)/.match(v).to_a[1..3]
    @@list[pkg] = [name, desc]
  }

  module_function
  def exist?(pkg)
    system("#{@@cmd} --exists #{pkg}")
  end

  def libs(pkg)
    `#{@@cmd} --libs #{pkg}`.chomp
  end

  def libs_only_L(pkg)
    `#{@@cmd} --libs-only-L #{pkg}`.chomp
  end

  def libs_only_l(pkg)
    `#{@@cmd} --libs-only-l #{pkg}`.chomp
  end

  def cflags(pkg)
    `#{@@cmd} --cflags #{pkg}`.chomp
  end

  def cflags_only_I(pkg)
    `#{@@cmd} --cflags-only-I #{pkg}`.chomp
  end

  def cflags_only_other(pkg)
    `#{@@cmd} --cflags-only-other #{pkg}`.chomp
  end

  def variable(pkg, var)
    `#{@@cmd} --variable=#{var} #{pkg}`.chomp
  end

  def modversion(pkg)
    `#{@@cmd} --modversion #{pkg}`.chomp
  end

  def version
    `#{@@cmd} --version`.chomp
  end

  def list_all
    # Returns [pkg, name, description]
    @@list.keys.collect{|key| [key] + @@list[key]}.sort
  end

  def name(pkg)
    @@list[pkg][0]
  end

  def description(pkg)
    @@list[pkg][1]
  end

  def provides(pkg)
    `#{@@cmd} --print-provides #{pkg}`.chomp
  end

  def requires(pkg)
    `#{@@cmd} --print-requires #{pkg}`.chomp.gsub("\n", ", ") 
  end

  def check_version?(pkg, major = 0, minor = 0, micro = 0)
    return false unless exist?(pkg)
    ver = modversion(pkg).split(".").collect{|item| item.to_i}
    (0..2).each {|i| ver[i] = 0 unless ver[i]}

    (ver[0] > major ||
     (ver[0] == major && ver[1] > minor) ||
     (ver[0] == major && ver[1] == minor &&
      ver[2] >= micro))
  end

  def have_package(pkg, major = 0, minor = 0, micro = 0)
    if major > 0
      STDOUT.print("checking for #{pkg} version (>= #{major}.#{minor}.#{micro})... ")
    else
      STDOUT.print("checking for #{pkg}... ")
    end
    STDOUT.flush
    if check_version?(pkg, major, minor, micro)
      STDOUT.print "yes\n"
      libraries = libs_only_l(pkg)
      dldflags = libs(pkg)
      dldflags = (Shellwords.shellwords(dldflags) - Shellwords.shellwords(libraries)).map{|s| /\s/ =~ s ? "\"#{s}\"" : s }.join(' ')
      $libs   += ' ' + libraries
      if /mswin32/ =~ RUBY_PLATFORM
	$DLDFLAGS += ' ' + dldflags
      else
	$LDFLAGS += ' ' + dldflags
      end
      $CFLAGS += ' ' + cflags(pkg)
      true
    else
      STDOUT.print "no\n"
      false
    end
  end
end

Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- rb_cairo.h	13 Sep 2005 16:22:29 -0000	1.5
+++ rb_cairo.h	4 Oct 2005 03:08:41 -0000	1.6
@@ -17,15 +17,25 @@
 
 #include "ruby.h"
 
-extern VALUE rb_mCairo;
-extern VALUE rb_cCairo_Context;
-extern VALUE rb_cCairo_Matrix;
-extern VALUE rb_cCairo_Pattern;
-extern VALUE rb_cCairo_FontFace;
-extern VALUE rb_cCairo_FontExtents;
-extern VALUE rb_cCairo_TextExtents;
-extern VALUE rb_cCairo_Glyph;
-extern VALUE rb_cCairo_Surface;
+#if defined(RUBY_CAIRO_PLATFORM_WIN32) && !defined(RUBY_CAIRO_STATIC_COMPILATION)
+#  ifdef RUBY_CAIRO_COMPILATION
+#    define RUBY_CAIRO_VAR __declspec(dllexport)
+#  else
+#    define RUBY_CAIRO_VAR extern __declspec(dllimport)
+#  endif
+#else
+#  define RUBY_CAIRO_VAR extern
+#endif
+
+RUBY_CAIRO_VAR VALUE rb_mCairo;
+RUBY_CAIRO_VAR VALUE rb_cCairo_Context;
+RUBY_CAIRO_VAR VALUE rb_cCairo_Matrix;
+RUBY_CAIRO_VAR VALUE rb_cCairo_Pattern;
+RUBY_CAIRO_VAR VALUE rb_cCairo_FontFace;
+RUBY_CAIRO_VAR VALUE rb_cCairo_FontExtents;
+RUBY_CAIRO_VAR VALUE rb_cCairo_TextExtents;
+RUBY_CAIRO_VAR VALUE rb_cCairo_Glyph;
+RUBY_CAIRO_VAR VALUE rb_cCairo_Surface;
 
 #define RVAL2CRCONTEXT(obj)     (rb_cairo_context_from_ruby_object(obj))
 #define CRCONTEXT2RVAL(cr)      (rb_cairo_context_to_ruby_object(cr))



More information about the cairo-commit mailing list