[cairo-commit] rcairo ChangeLog, 1.197, 1.198 extconf.rb, 1.7, 1.8 pkg-config.rb, 1.1, 1.2

Kouhei Sutou commit at pdx.freedesktop.org
Sat Feb 23 23:26:09 PST 2008


Committed by: kou

Update of /cvs/cairo/rcairo
In directory kemper:/tmp/cvs-serv28801

Modified Files:
	ChangeLog extconf.rb pkg-config.rb 
Log Message:
* src/rb_cairo_context.c: fixed declaration position.
* extconf.rb: RUBY_ -> RB_.
* pkg-config.rb: implemented pkg-config for cross compiling with Wine.


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/rcairo/ChangeLog,v
retrieving revision 1.197
retrieving revision 1.198
diff -u -d -r1.197 -r1.198
--- ChangeLog	21 Feb 2008 13:30:19 -0000	1.197
+++ ChangeLog	24 Feb 2008 07:26:52 -0000	1.198
@@ -1,3 +1,11 @@
+2008-02-24  Kouhei Sutou  <kou at cozmixng.org>
+
+	* src/rb_cairo_context.c: fixed declaration position.
+
+	* extconf.rb: RUBY_ -> RB_.
+
+	* pkg-config.rb: implemented pkg-config for cross compiling with Wine.
+
 2008-02-21  Kouhei Sutou  <kou at cozmixng.org>
 
 	* src/cairo.def, src/rb_cairo.h, src/rb_cairo_surface.c:

Index: extconf.rb
===================================================================
RCS file: /cvs/cairo/rcairo/extconf.rb,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- extconf.rb	18 Jan 2008 04:00:16 -0000	1.7
+++ extconf.rb	24 Feb 2008 07:26:52 -0000	1.8
@@ -84,7 +84,7 @@
 
 check_win32
 set_output_lib(File.basename(modname))
-$defs << "-DRUBY_CAIRO_COMPILATION"
+$defs << "-DRB_CAIRO_COMPILATION"
 create_makefile(modname, srcdir)
 
 makefile = File.read("Makefile")

Index: pkg-config.rb
===================================================================
RCS file: /cvs/cairo/rcairo/pkg-config.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pkg-config.rb	10 Mar 2007 11:54:17 -0000	1.1
+++ pkg-config.rb	24 Feb 2008 07:26:52 -0000	1.2
@@ -1,89 +1,169 @@
-#
-# 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 "rbconfig"
 
 require 'mkmf'
 require 'shellwords'
+require 'English'
+require 'pathname'
 
-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'
+class PackageConfig
+  attr_accessor :msvc_syntax
+  def initialize(name, path=nil, msvc_syntax=false)
+    @name = name
+    @path = path || ENV["PKG_CONFIG_PATH"] || guess_path
+    @msvc_syntax = msvc_syntax
+    @variables = @declarations = nil
   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]
-  }
+  def exist?
+    not pc.nil?
+  end
 
-  module_function
-  def exist?(pkg)
-    system("#{@@cmd} --exists #{pkg}")
+  def requires
+    parse_requires(declaration("Requires"))
   end
 
-  def libs(pkg)
-    `#{@@cmd} --libs #{pkg}`.chomp
+  def requires_private
+    parse_requires(declaration("Requires.private"))
   end
 
-  def libs_only_L(pkg)
-    `#{@@cmd} --libs-only-L #{pkg}`.chomp
+  def cflags
+    all_cflags = (requires_private + requires.reverse).collect do |package|
+      self.class.new(package, @path, @msvc_syntax).cflags
+    end
+    all_cflags = [declaration("Cflags")] + all_cflags
+    all_cflags = all_cflags.join(" ").gsub(/-I /, '-I').split.uniq
+    path_flags, other_flags = all_cflags.partition {|flag| /\A-I/ =~ flag}
+    path_flags = path_flags.reject do |flag|
+      flag == "-I/usr/include"
+    end
+    (other_flags + path_flags).join(" ")
   end
 
-  def libs_only_l(pkg)
-    `#{@@cmd} --libs-only-l #{pkg}`.chomp
+  def libs
+    all_libs = requires.collect do |package|
+      self.class.new(package, @path, @msvc_syntax).libs
+    end
+    all_libs = [declaration("Libs")] + all_libs
+    all_libs = all_libs.join(" ").gsub(/-([Ll]) /, '\1').split.uniq
+    path_flags, other_flags = all_libs.partition {|flag| /\A-L/ =~ flag}
+    path_flags = path_flags.reject do |flag|
+      /\A-L\/usr\/lib(?:64)?\z/ =~ flag
+    end
+    libs = (other_flags + path_flags).join(" ")
+    if @msvc_syntax
+      libs = libs.gsub(/\A-L/, "/libpath:")
+      libs = libs.gsub(/\A-l(\S+)/) {"#{$1}.lib"}
+    end
+    libs
   end
 
-  def cflags(pkg)
-    `#{@@cmd} --cflags #{pkg}`.chomp
+  def libs_only_l
+    libs.split.find_all do |arg|
+      if @msvc_syntax
+        /\.lib\z/ =~ arg
+      else
+        /\A-l/ =~ arg
+      end
+    end.join(" ")
   end
 
-  def cflags_only_I(pkg)
-    `#{@@cmd} --cflags-only-I #{pkg}`.chomp
+  def version
+    declaration("Version")
   end
 
-  def cflags_only_other(pkg)
-    `#{@@cmd} --cflags-only-other #{pkg}`.chomp
+  private
+  def pc
+    @path.split(separator).each do |path|
+      pc_name = File.join(path, "#{@name}.pc")
+      return pc_name if File.exist?(pc_name)
+    end
+    return nil
   end
 
-  def variable(pkg, var)
-    `#{@@cmd} --variable=#{var} #{pkg}`.chomp
+  def separator
+    File.expand_path(".").index(":") ? ";" : ":"
   end
 
-  def modversion(pkg)
-    `#{@@cmd} --modversion #{pkg}`.chomp
+  def variable(name)
+    parse_pc if @variables.nil?
+    expand_value(@variables[name])
   end
 
-  def version
-    `#{@@cmd} --version`.chomp
+  def declaration(name)
+    parse_pc if @declarations.nil?
+    expand_value(@declarations[name])
   end
 
-  def list_all
-    # Returns [pkg, name, description]
-    @@list.keys.collect{|key| [key] + @@list[key]}.sort
+  IDENTIFIER_RE = /[\w\d_.]+/
+  def parse_pc
+    @variables = {}
+    @declarations = {}
+    File.open(pc) do |input|
+      input.each_line do |line|
+        line = line.gsub(/#.*/, '').strip
+        next if line.empty?
+        case line
+        when /^(#{IDENTIFIER_RE})=/
+          @variables[$1] = $POSTMATCH.strip
+        when /^(#{IDENTIFIER_RE}):/
+          @declarations[$1] = $POSTMATCH.strip
+        end
+      end
+    end
   end
 
-  def name(pkg)
-    @@list[pkg][0]
+  def parse_requires(requires)
+    return [] if requires.nil?
+    requires_without_version = requires.gsub(/[<>]?=\s*[\d.]+\s*/, '')
+    requires_without_version.split(/[,\s]+/)
   end
 
-  def description(pkg)
-    @@list[pkg][1]
+  def expand_value(value)
+    return nil if value.nil?
+    value.gsub(/\$\{(#{IDENTIFIER_RE})\}/) do
+      variable($1)
+    end
   end
 
-  def provides(pkg)
-    `#{@@cmd} --print-provides #{pkg}`.chomp
+  def guess_path
+    pkg_config = with_config("pkg-config", ENV["PKG_CONFIG"] || "pkg-config")
+    pkg_config = Pathname.new(pkg_config)
+    unless pkg_config.absolute?
+      require "dl/import"
+      dln = Module.new
+      dln.module_eval do
+        extend DL::Importable
+        dlload RbConfig::CONFIG["LIBRUBY"]
+        extern "const char *dln_find_exe(const char *, const char *)"
+      end
+      pkg_config = dln.dln_find_exe(pkg_config.to_s, nil)
+      return "/usr/local/lib/pkgconfig:/usr/lib/pkgconfig" if pkg_config.nil?
+      pkg_config = Pathname.new(pkg_config)
+    end
+    (pkg_config.parent.parent + "lib" + "pkgconfig").to_s
   end
+end
 
-  def requires(pkg)
-    `#{@@cmd} --print-requires #{pkg}`.chomp.gsub("\n", ", ") 
+module PKGConfig
+  module_function
+  def exist?(pkg)
+    PackageConfig.new(pkg).exist?
+  end
+
+  def libs(pkg)
+    PackageConfig.new(pkg).libs
+  end
+
+  def libs_only_l(pkg)
+    PackageConfig.new(pkg).libs_only_l
+  end
+
+  def cflags(pkg)
+    PackageConfig.new(pkg).cflags
+  end
+
+  def modversion(pkg)
+    PackageConfig.new(pkg).version
   end
 
   def check_version?(pkg, major = 0, minor = 0, micro = 0)
@@ -109,7 +189,9 @@
       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(' ')
+      dldflags = (Shellwords.shellwords(dldflags) -
+                  Shellwords.shellwords(libraries))
+      dldflags = dldflags.map {|s| /\s/ =~ s ? "\"#{s}\"" : s }.join(' ')
       $libs   += ' ' + libraries
       if /mswin32/ =~ RUBY_PLATFORM
 	$DLDFLAGS += ' ' + dldflags



More information about the cairo-commit mailing list