public
Description: Binary gem installation of the GCCXML project
Homepage: http://rubyforge.org/projects/rbplusplus
Clone URL: git://github.com/jameskilton/gccxml_gem.git
commit  90c371f421f6361f1c233190500aa190cc2118e8
tree    91a5dfe26aae1eb049eb5a67bdf52ba3f1898e95
parent  7e669e88d65340532257efe6f99d824f2c32a5e9
gccxml_gem / gccxml.rb
100644 58 lines (45 sloc) 1.474 kb
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
require 'rbconfig'
 
# This class takes care of finding and actually calling the gccxml executable,
# setting up certain use flags according to what was specified.
class GCCXML
 
  def initialize()
    @exe = find_exe.strip.chomp
    @includes = []
    @flags = []
  end
 
  # Add an include path for parsing
  def add_include(path)
    @includes << path
  end
 
  # Add extra CXXFLAGS to the command line
  def add_cxxflags(flags)
    @flags << flags
  end
 
  # Run gccxml on the header file(s), sending the output to the passed in
  # file.
  def parse(header_file, to_file)
    includes = @includes.flatten.uniq.map {|i| "-I#{i.chomp}"}.join(" ").chomp
    flags = @flags.flatten.join(" ").chomp
    cmd = "#{@exe} #{includes} #{flags} #{header_file} -fxml=#{to_file}"
    raise "Error executing gccxml command line: #{cmd}" unless system(cmd)
  end
 
  private
 
  def windows?
    RUBY_PLATFORM =~ /(mswin|cygwin)/
  end
 
  def find_exe
    ext = windows? ? ".exe" : ""
 
    path = File.expand_path(File.join(File.dirname(__FILE__), "bin", "gccxml#{ext}"))
    path.chomp!
 
    if `#{path} --version 2>&1` !~ /GCC-XML/
      if File.exists?(path)
        # This is the Rubygems <= 1.1.1 bug of not setting file attributes properly
        dir = File.expand_path(File.dirname(__FILE__))
        raise "Unable to execute gccxml. Please run 'sudo chmod -R a+x #{dir}'"
      else
        raise "Unable to find gccxml executable: #{path}"
      end
    end
 
    path
  end
 
end