Class: PackageConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pkg-config.rb

Constant Summary collapse

SEPARATOR =
File::PATH_SEPARATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ PackageConfig

Returns a new instance of PackageConfig.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/pkg-config.rb', line 117

def initialize(name, options={})
  @name = name
  @options = options
  path = @options[:path] || ENV["PKG_CONFIG_PATH"]
  @paths = [path, guess_default_path].compact.join(SEPARATOR).split(SEPARATOR)
  @paths.unshift(*(@options[:paths] || []))
  @paths = normalize_paths(@paths)
  @msvc_syntax = @options[:msvc_syntax]
  @variables = @declarations = nil
  override_variables = self.class.custom_override_variables
  @override_variables = parse_override_variables(override_variables)
  default_override_variables = @options[:override_variables] || {}
  @override_variables = default_override_variables.merge(@override_variables)
end

Instance Attribute Details

#msvc_syntaxObject

Returns the value of attribute msvc_syntax.



116
117
118
# File 'lib/pkg-config.rb', line 116

def msvc_syntax
  @msvc_syntax
end

#pathsObject (readonly)

Returns the value of attribute paths.



115
116
117
# File 'lib/pkg-config.rb', line 115

def paths
  @paths
end

Class Method Details

.clear_configure_args_cacheObject



42
43
44
45
# File 'lib/pkg-config.rb', line 42

def clear_configure_args_cache
  @native_pkg_config = nil
  @custom_override_variables = nil
end

.custom_override_variablesObject



38
39
40
# File 'lib/pkg-config.rb', line 38

def custom_override_variables
  @custom_override_variables ||= with_config("override-variables", "")
end

.native_pkg_configObject



33
34
35
# File 'lib/pkg-config.rb', line 33

def native_pkg_config
  @native_pkg_config ||= guess_native_pkg_config
end

Instance Method Details

#cflagsObject



144
145
146
147
# File 'lib/pkg-config.rb', line 144

def cflags
  path_flags, other_flags = collect_cflags
  (other_flags + path_flags).join(" ")
end

#cflags_only_IObject



149
150
151
# File 'lib/pkg-config.rb', line 149

def cflags_only_I
  collect_cflags[0].join(" ")
end

#cflags_only_otherObject



153
154
155
# File 'lib/pkg-config.rb', line 153

def cflags_only_other
  collect_cflags[1].join(" ")
end

#declaration(name) ⇒ Object



195
196
197
198
# File 'lib/pkg-config.rb', line 195

def declaration(name)
  parse_pc if @declarations.nil?
  expand_value(@declarations[name])
end

#descriptionObject



186
187
188
# File 'lib/pkg-config.rb', line 186

def description
  declaration("Description")
end

#exist?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/pkg-config.rb', line 132

def exist?
  not pc_path.nil?
end

#libsObject



157
158
159
160
# File 'lib/pkg-config.rb', line 157

def libs
  path_flags, other_flags = collect_libs
  (path_flags + other_flags).join(" ")
end

#libs_only_lObject



162
163
164
165
166
167
168
169
170
# File 'lib/pkg-config.rb', line 162

def libs_only_l
  collect_libs[1].find_all do |arg|
    if @msvc_syntax
      /\.lib\z/ =~ arg
    else
      /\A-l/ =~ arg
    end
  end.join(" ")
end

#libs_only_LObject



172
173
174
175
176
177
178
179
180
# File 'lib/pkg-config.rb', line 172

def libs_only_L
  collect_libs[0].find_all do |arg|
    if @msvc_syntax
      /\A\/libpath:/ =~ arg
    else
      /\A-L/ =~ arg
    end
  end.join(" ")
end

#pc_pathObject



200
201
202
203
204
205
206
# File 'lib/pkg-config.rb', line 200

def pc_path
  @paths.each do |path|
    _pc_path = File.join(path, "#{@name}.pc")
    return _pc_path if File.exist?(_pc_path)
  end
  nil
end

#requiresObject



136
137
138
# File 'lib/pkg-config.rb', line 136

def requires
  parse_requires(declaration("Requires"))
end

#requires_privateObject



140
141
142
# File 'lib/pkg-config.rb', line 140

def requires_private
  parse_requires(declaration("Requires.private"))
end

#variable(name) ⇒ Object



190
191
192
193
# File 'lib/pkg-config.rb', line 190

def variable(name)
  parse_pc if @variables.nil?
  expand_value(@override_variables[name] || @variables[name])
end

#versionObject



182
183
184
# File 'lib/pkg-config.rb', line 182

def version
  declaration("Version")
end