Class: PackageConfig

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

Defined Under Namespace

Classes: Error, NotFoundError

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.



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/pkg-config.rb', line 261

def initialize(name, options={})
  if Pathname(name).absolute?
    @pc_path = name
    @path_position = 0
    @name = File.basename(@pc_path, ".*")
  else
    @pc_path = nil
    @path_position = nil
    @name = name
  end
  @options = options
  path = @options[:path] || ENV["PKG_CONFIG_PATH"]
  @paths = [path, self.class.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.



260
261
262
# File 'lib/pkg-config.rb', line 260

def msvc_syntax
  @msvc_syntax
end

#nameObject (readonly)

Returns the value of attribute name.



258
259
260
# File 'lib/pkg-config.rb', line 258

def name
  @name
end

#pathsObject (readonly)

Returns the value of attribute paths.



259
260
261
# File 'lib/pkg-config.rb', line 259

def paths
  @paths
end

Class Method Details

.clear_configure_args_cacheObject



57
58
59
60
61
62
# File 'lib/pkg-config.rb', line 57

def clear_configure_args_cache
  @native_pkg_config = nil
  @native_pkg_config_prefix = nil
  @default_path = nil
  @custom_override_variables = nil
end

.custom_override_variablesObject



53
54
55
# File 'lib/pkg-config.rb', line 53

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

.default_pathObject



48
49
50
# File 'lib/pkg-config.rb', line 48

def default_path
  @default_path ||= compute_default_path
end

.native_pkg_configObject



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

def native_pkg_config
  @native_pkg_config ||= guess_native_pkg_config
end

.native_pkg_config_prefixObject



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

def native_pkg_config_prefix
  @native_pkg_config_prefix ||= compute_native_pkg_config_prefix
end

Instance Method Details

#cflagsObject



296
297
298
299
# File 'lib/pkg-config.rb', line 296

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

#cflags_only_IObject



301
302
303
# File 'lib/pkg-config.rb', line 301

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

#cflags_only_otherObject



305
306
307
# File 'lib/pkg-config.rb', line 305

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

#declaration(name) ⇒ Object



347
348
349
350
# File 'lib/pkg-config.rb', line 347

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

#descriptionObject



338
339
340
# File 'lib/pkg-config.rb', line 338

def description
  declaration("Description")
end

#exist?Boolean

Returns:

  • (Boolean)


284
285
286
# File 'lib/pkg-config.rb', line 284

def exist?
  not pc_path.nil?
end

#libsObject



309
310
311
312
# File 'lib/pkg-config.rb', line 309

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

#libs_only_lObject



314
315
316
317
318
319
320
321
322
# File 'lib/pkg-config.rb', line 314

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



324
325
326
327
328
329
330
331
332
# File 'lib/pkg-config.rb', line 324

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



352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/pkg-config.rb', line 352

def pc_path
  if @pc_path
    return @pc_path if File.exist?(@pc_path)
  else
    @paths.each_with_index do |path, i|
      _pc_path = File.join(path, "#{@name}.pc")
      if File.exist?(_pc_path)
        @path_position = i + 1
        return _pc_path
      end
    end
  end
  nil
end

#requiresObject



288
289
290
# File 'lib/pkg-config.rb', line 288

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

#requires_privateObject



292
293
294
# File 'lib/pkg-config.rb', line 292

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

#variable(name) ⇒ Object



342
343
344
345
# File 'lib/pkg-config.rb', line 342

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

#versionObject



334
335
336
# File 'lib/pkg-config.rb', line 334

def version
  declaration("Version")
end