Class: Magica::PackageConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/magica/package_config.rb

Constant Summary collapse

LIBRARY_PATH_RULE =
/-L([^\s]+)/
LIBRARY_RULE =
/-l([^\s]+)/
LIBRARY_FLAG_RULE =
/-[^lL][^\s]+/
INCLUDE_RULE =
/-I([^\s]+)/
DEFINE_RULE =
/-D([^\s]+)/
FLAG_RULE =
/-[^ID][^\s]+/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PackageConfig

Returns a new instance of PackageConfig.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/magica/package_config.rb', line 21

def initialize(name)
  fail "Cannot found library #{name}" unless system "pkg-config --exists #{name}"

  @package_libraries = `pkg-config --libs #{name}`.strip

  @library_paths = @package_libraries.scan(LIBRARY_PATH_RULE).flatten
  @libraries = @package_libraries.scan(LIBRARY_RULE).flatten
  @library_flags = @package_libraries.scan(LIBRARY_FLAG_RULE).flatten

  @package_cflags = `pkg-config --cflags #{name}`.strip
  @include_paths = @package_cflags.scan(INCLUDE_RULE).flatten
  @defines = @package_cflags.scan(DEFINE_RULE).flatten
  @flags = @package_cflags.scan(FLAG_RULE).flatten

  @version = `pkg-config --modversion #{name}`.strip
end

Instance Attribute Details

#definesObject (readonly)

Returns the value of attribute defines.



19
20
21
# File 'lib/magica/package_config.rb', line 19

def defines
  @defines
end

#flagsObject (readonly)

Returns the value of attribute flags.



19
20
21
# File 'lib/magica/package_config.rb', line 19

def flags
  @flags
end

#include_pathsObject (readonly)

Returns the value of attribute include_paths.



19
20
21
# File 'lib/magica/package_config.rb', line 19

def include_paths
  @include_paths
end

#librariesObject (readonly)

Returns the value of attribute libraries.



19
20
21
# File 'lib/magica/package_config.rb', line 19

def libraries
  @libraries
end

#library_flagsObject (readonly)

Returns the value of attribute library_flags.



19
20
21
# File 'lib/magica/package_config.rb', line 19

def library_flags
  @library_flags
end

#library_pathsObject (readonly)

Returns the value of attribute library_paths.



19
20
21
# File 'lib/magica/package_config.rb', line 19

def library_paths
  @library_paths
end

Class Method Details

.[](name) ⇒ Object



4
5
6
7
8
9
# File 'lib/magica/package_config.rb', line 4

def [](name)
  @packages ||= {}
  config = @packages[name.to_s]
  config = @packages[name.to_s] = PackageConfig.new(name) if config.nil?
  config
end