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.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/pkg-config.rb', line 146

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, 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.



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

def msvc_syntax
  @msvc_syntax
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathsObject (readonly)

Returns the value of attribute paths.



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

def paths
  @paths
end

Class Method Details

.clear_configure_args_cacheObject



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

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

.custom_override_variablesObject



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

def custom_override_variables
  @custom_override_variables ||= with_config("override-variables", "")
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



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

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

#cflags_only_IObject



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

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

#cflags_only_otherObject



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

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

#declaration(name) ⇒ Object



232
233
234
235
# File 'lib/pkg-config.rb', line 232

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

#descriptionObject



223
224
225
# File 'lib/pkg-config.rb', line 223

def description
  declaration("Description")
end

#exist?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/pkg-config.rb', line 169

def exist?
  not pc_path.nil?
end

#libsObject



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

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

#libs_only_lObject



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

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



209
210
211
212
213
214
215
216
217
# File 'lib/pkg-config.rb', line 209

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



237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/pkg-config.rb', line 237

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



173
174
175
# File 'lib/pkg-config.rb', line 173

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

#requires_privateObject



177
178
179
# File 'lib/pkg-config.rb', line 177

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

#variable(name) ⇒ Object



227
228
229
230
# File 'lib/pkg-config.rb', line 227

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

#versionObject



219
220
221
# File 'lib/pkg-config.rb', line 219

def version
  declaration("Version")
end