Sha256: 6e0abd4ee54f65a773f08d0be99b1e17f8f327658621275552d9e2e53a8d85c6

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 KB

Contents

# Access to information from pkg-config(1)
class PkgConfig
    class NotFound < RuntimeError
        attr_reader :name

        def initialize(name)
            @name = name
        end

        def to_s
            "#{name} is not available to pkg-config"
        end
    end

    # The module name
    attr_reader :name
    # The module version
    attr_reader :version

    # Create a PkgConfig object for the package +name+
    # Raises PkgConfig::NotFound if the module does not exist
    def initialize(name)
        unless system("pkg-config --exists #{name}")
            raise NotFound.new(name), "pkg-config package '#{name}' not found"
        end

        @name    = name
        @version = `pkg-config --modversion #{name}`.chomp.strip
        @actions = Hash.new
        @variables = Hash.new
    end

    ACTIONS = %w[cflags cflags-only-I cflags-only-other
                 libs libs-only-L libs-only-l libs-only-other static].freeze
    ACTIONS.each do |action|
        define_method(action.tr('-', '_')) do
            @actions[action] ||= `pkg-config --#{action} #{name}`.chomp.strip
        end
    end

    def respond_to_missing?(varname, _include_all)
        varname =~ /^\w+$/
    end

    def method_missing(varname, *args, &proc)
        if args.empty?
            unless (value = @variables[varname])
                value = `pkg-config --variable=#{varname} #{name}`.chomp.strip
                @variables[varname] = value
            end
            return value
        end
        super
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
autobuild-1.21.0 lib/autobuild/pkgconfig.rb
autobuild-1.20.0 lib/autobuild/pkgconfig.rb
autobuild-1.19.0 lib/autobuild/pkgconfig.rb
autobuild-1.18.1 lib/autobuild/pkgconfig.rb
autobuild-1.18.0 lib/autobuild/pkgconfig.rb