Parent

Buildable

A buildable object like a library or executable

Attributes

buildable[RW]
cflags[RW]
distributable[RW]
enable[RW]
id[RW]
installable[RW]
ldadd[RW]
output[RW]
output_type[RW]
project[RW]
rpath[RW]
sources[RW]
topdir[RW]

Public Class Methods

new(options) click to toggle source
# File lib/makeconf/buildable.rb, line 10
  def initialize(options)
    raise ArgumentError unless options.kind_of?(Hash)
    default = {
        :id => options[:id],
        :buildable => true,
        :distributable => true,
        :installable => true,
        :extension => '',
        :cflags => [],
        :ldflags => [],
        :ldadd => [],
        :rpath => '',
        :topdir => '',
        :depends => [],
    }
    default.each do |k,v| 
      instance_variable_set('@' + k.to_s, v)
    end
    @output = id
    @output_type = nil      # filled in by the derived class

    # Filled in by sources=()
    @sources = []

    # Parse options

    # FIXME- consider adding support for:
    #%w{name enable distributable installable extension
#   topdir rpath}

    log.debug "Buildable options: " + options.pretty_inspect
      
    options.each do |k,v|
      log.debug "k=#{k} v=#{v.to_s}"
      case k
      when :id
        @id = v
      when :cc
        @cc = v
      when :cflags
        v = v.split(' ') if v.kind_of?(String)
        @cflags = v
      when :ldflags
        v = v.split(' ') if v.kind_of?(String)
        @ldflags = v
      when :ldadd
        v = v.split(' ') if v.kind_of?(String)
        @ldadd = v
      when :project
        @project = v
      when :buildable
        @buildable = v
      when :sources
        v = [ v ] if v.kind_of?(String)
        @sources = v
      else
        throw "Unrecognized option -- #{k}: #{v}"
      end
    end
    log.debug "Buildable parsed as: " + self.pretty_inspect

#FIXME: move some of these to the switch statement
#    # Parse simple textual child elements
#    %w{cflags ldflags ldadd depends sources}.each do |k|
#      instance_variable_set('@' + k, yaml[k]) if yaml.has_key? k
#    end

  end

Public Instance Methods

binary?() click to toggle source
# File lib/makeconf/buildable.rb, line 122
def binary?
  @output_type =~ /binary/
end
compile(cc) click to toggle source
# File lib/makeconf/androidproject.rb, line 361
def compile(cc)
end
expand_sources(x) click to toggle source
# File lib/makeconf/buildable.rb, line 79
  def expand_sources(x)
    log.info "expanding [#{x.to_s}] to source file list"
    raise ArgumentError('Wrong type') unless x.is_a? Array

    # Use glob(3) to expand the list of sources
    buf = []
    x.each do |src| 
      if src =~ /\*/
        buf << Dir.glob(src)
      else
        buf.push src
      end
    end
    buf.flatten

# TODO: elsewhere
    # Ensure that all source files exist
#@sources.each do |src|
#      throw ArgumentError("#{src} does not exist") unless File.exist? src
#    end

  end
finalize() click to toggle source
# File lib/makeconf/buildable.rb, line 126
def finalize
end
install(installer) click to toggle source

Install the output file(s)

# File lib/makeconf/buildable.rb, line 130
def install(installer)
  # By default, this does nothing.
  # Derived classes are expected to override this method.
end
library?() click to toggle source
# File lib/makeconf/buildable.rb, line 107
def library?
  @output_type == 'shared library' or @output_type == 'static library'
end
library_type() click to toggle source
# File lib/makeconf/buildable.rb, line 111
def library_type
  case @output_type
  when 'shared library'
  return :shared
  when 'static library'
  return :static
  else
  throw 'Not a library'
  end
end
makedepends() click to toggle source

Return a hash containing Makefile dependencies

# File lib/makeconf/buildable.rb, line 215
def makedepends
  res = []

  if @sources.nil?
     log.error self.to_s
     raise 'Missing sources'
  end

  # Generate the targets and rules for each translation unit
  expand_sources(@sources).each do |src|
    next if src =~ /\.o$/
    cc = @project.cc
    cc.flags = [ @cflags, '-E' ]
    cc.output = '-'
    cc.sources = src
    #TODO: topdir
    cmd = cc.command + Platform.dev_null_stderr
  end
  res
end
makefile_hook(makefile) click to toggle source

Last chance to put things into the Makefile

# File lib/makeconf/buildable.rb, line 141
def makefile_hook(makefile)
  # STUB
end
objects() click to toggle source

Return the list of intermediate object files

# File lib/makeconf/buildable.rb, line 103
def objects
   expand_sources(@sources).map { |x| x.gsub(/\.c$/, '.o') }
end
project_hook(project) click to toggle source

Creates things from configure.rb, for example generating pkgconfig.pc.in

# File lib/makeconf/buildable.rb, line 136
def project_hook(project)
  # STUB
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.