lib/utilrb/pkgconfig.rb
# Loads the information contained in +path+
Loads the information contained in +path+
Loads the information contained in + path +
def load(path, preset_variables = Hash.new)
            @path = path
            @file = File.readlines(path).map(&:strip)
            raw_variables = preset_variables.dup
            raw_fields    = Hash.new
            running_line = nil
            @file = file.map do |line|
                line.gsub! /\s*#.*$/, ''
                line = line.strip
                next if line.empty?
                value = line.gsub(/\\$/, '')
                if running_line
                    running_line << " " << value
                end
                if line =~ /\\$/
                    running_line ||= value
                elsif running_line
                    running_line = nil
                else
                    value
                end
            end.compact
            file.each do |line|
                case line
                when /^(#{VAR_NAME_RX})\s*=(.*)/
                    raw_variables[$1] = $2.strip
                when /^(#{FIELD_NAME_RX}):\s*(.*)/
                    raw_fields[$1] = $2.strip
                else
                    raise NotImplementedError, "#{path}: cannot parse pkg-config line #{line.inspect}"
                end
            end
            while variables.size != raw_variables.size
                raw_variables.each do |name, value|
                    value = expand_variables(value, raw_variables, name)
                    raw_variables[name] = value
                    if value !~ /\$\{#{VAR_NAME_RX}\}/
                        variables[name] = value
                    end
                end
            end
            raw_fields.each do |name, value|
                if SHELL_VARS.include?(name) 
                    value = Shellwords.shellsplit(value)
                    value.map! do |v|
                        expand_variables(v, variables, name)
                    end
                else
                    value = expand_variables(value, variables, name)
                end
                fields[name] = value
            end
            @raw_version = (fields['Version'] || '')
            @version = raw_version.split('.').map { |v| Integer(v) if v =~ /^\d+$/ }.compact
            @description = (fields['Description'] || '')
            @requires  = PkgConfig.parse_dependencies(fields['Requires'] || '')
            @requires_private  = PkgConfig.parse_dependencies(fields['Requires.private'] || '')
            @conflicts = PkgConfig.parse_dependencies(fields['Conflicts'] || '')
            @cflags = fields['Cflags'] || []
            @requires.each do |pkg|
                @cflags.concat(pkg.raw_cflags)
            end
            @requires_private.each do |pkg|
                @cflags.concat(pkg.raw_cflags)
            end
            @cflags.uniq!
            @cflags.delete('-I/usr/include')
            @ldflags = Hash.new
            @ldflags[false] = fields['Libs'] || []
            @ldflags[false].delete('-L/usr/lib')
            @ldflags[false].uniq!
            @ldflags[true] = @ldflags[false] + (fields['Libs.private'] || [])
            @ldflags[true].delete('-L/usr/lib')
            @ldflags[true].uniq!
            @ldflags_with_requires = {
                true => @ldflags[true].dup,
                false => @ldflags[false].dup
            }
            @requires.each do |pkg|
                @ldflags_with_requires[true].concat(pkg.raw_ldflags_with_requires[true])
                @ldflags_with_requires[false].concat(pkg.raw_ldflags_with_requires[false])
            end
            @requires_private.each do |pkg|
                @ldflags_with_requires[true].concat(pkg.raw_ldflags_with_requires[true])
            end
        end
def load ( path , preset_variables = Hash . new ) @path = path @file = File . readlines ( path ) . map ( & :strip ) raw_variables = preset_variables . dup raw_fields = Hash . new running_line = nil @file = file . map do | line | line . gsub! / \s *#.*$ / , '' line = line . strip next if line . empty? value = line . gsub ( / \\ $ / , '' ) if running_line running_line << " " << value end if line =~ / \\ $ / running_line ||= value elsif running_line running_line = nil else value end end . compact file . each do | line | case line when / ^( #{ VAR_NAME_RX } ) \s *=(.*) / raw_variables [ $1 ] = $2 . strip when / ^( #{ FIELD_NAME_RX } ): \s *(.*) / raw_fields [ $1 ] = $2 . strip else raise NotImplementedError , "#{path}: cannot parse pkg-config line #{line.inspect}" end end while variables . size != raw_variables . size raw_variables . each do | name , value | value = expand_variables ( value , raw_variables , name ) raw_variables [ name ] = value if value !~ / \$ \{ #{ VAR_NAME_RX } \} / variables [ name ] = value end end end raw_fields . each do | name , value | if SHELL_VARS . include? ( name ) value = Shellwords . shellsplit ( value ) value . map! do | v | expand_variables ( v , variables , name ) end else value = expand_variables ( value , variables , name ) end fields [ name ] = value end @raw_version = ( fields [ 'Version' ] || '' ) @version = raw_version . split ( '.' ) . map { | v | Integer ( v ) if v =~ / ^ \d +$ / } . compact @description = ( fields [ 'Description' ] || '' ) @requires = PkgConfig . parse_dependencies ( fields [ 'Requires' ] || '' ) @requires_private = PkgConfig . parse_dependencies ( fields [ 'Requires.private' ] || '' ) @conflicts = PkgConfig . parse_dependencies ( fields [ 'Conflicts' ] || '' ) @cflags = fields [ 'Cflags' ] || [ ] @requires . each do | pkg | @cflags . concat ( pkg . raw_cflags ) end @requires_private . each do | pkg | @cflags . concat ( pkg . raw_cflags ) end @cflags . uniq! @cflags . delete ( '-I/usr/include' ) @ldflags = Hash . new @ldflags [ false ] = fields [ 'Libs' ] || [ ] @ldflags [ false ] . delete ( '-L/usr/lib' ) @ldflags [ false ] . uniq! @ldflags [ true ] = @ldflags [ false ] + ( fields [ 'Libs.private' ] || [ ] ) @ldflags [ true ] . delete ( '-L/usr/lib' ) @ldflags [ true ] . uniq! @ldflags_with_requires = { true => @ldflags [ true ] . dup , false => @ldflags [ false ] . dup } @requires . each do | pkg | @ldflags_with_requires [ true ] . concat ( pkg . raw_ldflags_with_requires [ true ] ) @ldflags_with_requires [ false ] . concat ( pkg . raw_ldflags_with_requires [ false ] ) end @requires_private . each do | pkg | @ldflags_with_requires [ true ] . concat ( pkg . raw_ldflags_with_requires [ true ] ) end end
Loads the information contained in +path+
Loads the information contained in + path +
# Resolve the variables # Shell-split the fields, and expand the variables in them # Initialize the main flags # Get the requires/conflicts # And finally resolve the compilation flags
path
<not_specific>
preset_variables
<not_specific>
new
<not_specific>