Class: PkgConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/autobuild/pkgconfig.rb

Overview

Access to information from pkg-config(1)

Defined Under Namespace

Classes: NotFound

Constant Summary collapse

ACTIONS =
%w[cflags cflags-only-I cflags-only-other
libs libs-only-L libs-only-l libs-only-other static].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PkgConfig

Create a PkgConfig object for the package name Raises PkgConfig::NotFound if the module does not exist



23
24
25
26
27
28
29
30
31
32
# File 'lib/autobuild/pkgconfig.rb', line 23

def initialize(name)
    unless system("pkg-config --exists #{name}")
        raise NotFound.new(name), "pkg-config package '#{name}' not found"
    end

    @name    = name
    @version = `pkg-config --modversion #{name}`.chomp.strip
    @actions = Hash.new
    @variables = Hash.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(varname, *args, &proc) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/autobuild/pkgconfig.rb', line 46

def method_missing(varname, *args, &proc)
    if args.empty?
        unless (value = @variables[varname])
            value = `pkg-config --variable=#{varname} #{name}`.chomp.strip
            @variables[varname] = value
        end
        return value
    end
    super
end

Instance Attribute Details

#nameObject (readonly)

The module name



17
18
19
# File 'lib/autobuild/pkgconfig.rb', line 17

def name
  @name
end

#versionObject (readonly)

The module version



19
20
21
# File 'lib/autobuild/pkgconfig.rb', line 19

def version
  @version
end

Instance Method Details

#respond_to_missing?(varname, _include_all) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/autobuild/pkgconfig.rb', line 42

def respond_to_missing?(varname, _include_all)
    varname =~ /^\w+$/
end