Object
# File lib/pkg-config.rb, line 38 38: def clear_configure_args_cache 39: @native_pkg_config = nil 40: @custom_override_variables = nil 41: end
# File lib/pkg-config.rb, line 34 34: def custom_override_variables 35: @custom_override_variables ||= with_config("override-variables", "") 36: end
# File lib/pkg-config.rb, line 29 29: def native_pkg_config 30: @native_pkg_config ||= guess_native_pkg_config 31: end
# File lib/pkg-config.rb, line 101 101: def initialize(name, options={}) 102: @name = name 103: @options = options 104: path = @options[:path] || ENV["PKG_CONFIG_PATH"] 105: @paths = [path, guess_default_path].compact.join(SEPARATOR).split(SEPARATOR) 106: @paths.unshift(@options[:paths] || []) 107: @msvc_syntax = @options[:msvc_syntax] 108: @variables = @declarations = nil 109: override_variables = self.class.custom_override_variables 110: @override_variables = parse_override_variables(override_variables) 111: default_override_variables = @options[:override_variables] || {} 112: @override_variables = default_override_variables.merge(@override_variables) 113: end
# File lib/pkg-config.rb, line 44 44: def guess_native_pkg_config 45: pkg_config = with_config("pkg-config", ENV["PKG_CONFIG"] || "pkg-config") 46: pkg_config = Pathname.new(pkg_config) 47: unless pkg_config.absolute? 48: found_pkg_config = search_pkg_config_from_path(pkg_config) 49: pkg_config = found_pkg_config if found_pkg_config 50: end 51: unless pkg_config.absolute? 52: found_pkg_config = search_pkg_config_by_dln_find_exe(pkg_config) 53: pkg_config = found_pkg_config if found_pkg_config 54: end 55: pkg_config 56: end
# File lib/pkg-config.rb, line 66 66: def search_pkg_config_by_dln_find_exe(pkg_config) 67: begin 68: require "dl/import" 69: rescue LoadError 70: return nil 71: end 72: dln = Module.new 73: dln.module_eval do 74: if DL.const_defined?(:Importer) 75: extend DL::Importer 76: else 77: extend DL::Importable 78: end 79: begin 80: dlload RbConfig::CONFIG["LIBRUBY"] 81: rescue RuntimeError 82: return nil if $!.message == "unknown error" 83: return nil if /: image not found\z/ =~ $!.message 84: raise 85: rescue DL::DLError 86: return nil 87: end 88: extern "const char *dln_find_exe(const char *, const char *)" 89: end 90: path = dln.dln_find_exe(pkg_config.to_s, nil) 91: if path.size.zero? 92: nil 93: else 94: Pathname(path.to_s) 95: end 96: end
# File lib/pkg-config.rb, line 58 58: def search_pkg_config_from_path(pkg_config) 59: (ENV["PATH"] || "").split(SEPARATOR).each do |path| 60: try_pkg_config = Pathname(path) + pkg_config 61: return try_pkg_config if try_pkg_config.exist? 62: end 63: nil 64: end
# File lib/pkg-config.rb, line 127 127: def cflags 128: path_flags, other_flags = collect_cflags 129: (path_flags + other_flags).join(" ") 130: end
# File lib/pkg-config.rb, line 132 132: def cflags_only_I 133: collect_cflags[0].join(" ") 134: end
# File lib/pkg-config.rb, line 174 174: def declaration(name) 175: parse_pc if @declarations.nil? 176: expand_value(@declarations[name]) 177: end
# File lib/pkg-config.rb, line 165 165: def description 166: declaration("Description") 167: end
# File lib/pkg-config.rb, line 115 115: def exist? 116: not pc.nil? 117: end
# File lib/pkg-config.rb, line 136 136: def libs 137: path_flags, other_flags = collect_libs 138: (path_flags + other_flags).join(" ") 139: end
# File lib/pkg-config.rb, line 151 151: def libs_only_L 152: collect_libs[0].find_all do |arg| 153: if @msvc_syntax 154: /\A\/libpath:/ =~ arg 155: else 156: /\A-L/ =~ arg 157: end 158: end.join(" ") 159: end
# File lib/pkg-config.rb, line 141 141: def libs_only_l 142: collect_libs[1].find_all do |arg| 143: if @msvc_syntax 144: /\.lib\z/ =~ arg 145: else 146: /\A-l/ =~ arg 147: end 148: end.join(" ") 149: end
# File lib/pkg-config.rb, line 119 119: def requires 120: parse_requires(declaration("Requires")) 121: end
# File lib/pkg-config.rb, line 123 123: def requires_private 124: parse_requires(declaration("Requires.private")) 125: end
# File lib/pkg-config.rb, line 188 188: def collect_cflags 189: all_cflags = (requires_private + requires.reverse).collect do |package| 190: self.class.new(package, @options).cflags 191: end 192: all_cflags = [declaration("Cflags")] + all_cflags 193: all_cflags = all_cflags.join(" ").gsub(/-I /, '-I').split.uniq 194: path_flags, other_flags = all_cflags.partition {|flag| /\A-I/ =~ flag} 195: path_flags = path_flags.reject do |flag| 196: flag == "-I/usr/include" 197: end 198: if @msvc_syntax 199: path_flags = path_flags.collect do |flag| 200: flag.gsub(/\A-I/, "/I") 201: end 202: end 203: [path_flags, other_flags] 204: end
# File lib/pkg-config.rb, line 206 206: def collect_libs 207: all_libs = requires.collect do |package| 208: self.class.new(package, @options).libs 209: end 210: all_libs = [declaration("Libs")] + all_libs 211: all_libs = all_libs.join(" ").gsub(/-([Ll]) /, '\1').split.uniq 212: path_flags, other_flags = all_libs.partition {|flag| /\A-L/ =~ flag} 213: path_flags = path_flags.reject do |flag| 214: /\A-L\/usr\/lib(?:64)?\z/ =~ flag 215: end 216: if @msvc_syntax 217: path_flags = path_flags.collect do |flag| 218: flag.gsub(/\A-L/, "/libpath:") 219: end 220: other_flags = other_flags.collect do |flag| 221: if /\A-l/ =~ flag 222: "#{$POSTMATCH}.lib" 223: else 224: flag 225: end 226: end 227: end 228: [path_flags, other_flags] 229: end
# File lib/pkg-config.rb, line 265 265: def expand_value(value) 266: return nil if value.nil? 267: value.gsub(/\$\{(#{IDENTIFIER_RE})\}/) do 268: variable($1) 269: end 270: end
# File lib/pkg-config.rb, line 272 272: def guess_default_path 273: default_path = ["/usr/local/lib64/pkgconfig", 274: "/usr/local/lib/pkgconfig", 275: "/usr/local/libdata/pkgconfig", 276: "/opt/local/lib/pkgconfig", 277: "/usr/lib64/pkgconfig", 278: "/usr/lib/pkgconfig", 279: "/usr/X11/lib/pkgconfig/", 280: "/usr/share/pkgconfig"].join(SEPARATOR) 281: libdir = ENV["PKG_CONFIG_LIBDIR"] 282: default_path = [libdir, default_path].join(SEPARATOR) if libdir 283: 284: pkg_config = self.class.native_pkg_config 285: return default_path unless pkg_config.absolute? 286: [(pkg_config.parent.parent + "lib" + "pkgconfig").to_s, 287: (pkg_config.parent.parent + "libdata" + "pkgconfig").to_s, 288: default_path].join(SEPARATOR) 289: end
# File lib/pkg-config.rb, line 256 256: def parse_override_variables(override_variables) 257: variables = {} 258: override_variables.split(",").each do |variable| 259: name, value = variable.split("=", 2) 260: variables[name] = value 261: end 262: variables 263: end
# File lib/pkg-config.rb, line 232 232: def parse_pc 233: raise ".pc for #{@name} doesn't exist." unless exist? 234: @variables = {} 235: @declarations = {} 236: File.open(pc) do |input| 237: input.each_line do |line| 238: line = line.gsub(/#.*/, '').strip 239: next if line.empty? 240: case line 241: when /^(#{IDENTIFIER_RE})=/ 242: @variables[$1] = $POSTMATCH.strip 243: when /^(#{IDENTIFIER_RE}):/ 244: @declarations[$1] = $POSTMATCH.strip 245: end 246: end 247: end 248: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.