Object
A Makefile is a collection of targets and rules used to build software.
# File lib/makeconf/makefile.rb, line 87 def add_dependency(target,depends) add_target(target, [depends], []) unless @targets.has_key? target @targets[target].add_dependency(depends) end
# File lib/makeconf/makefile.rb, line 54 def add_rule(target, rule) add_target(target, [], []) unless @targets.has_key? target @targets[target].add_rule(rule) end
# File lib/makeconf/makefile.rb, line 46 def add_target(object,depends = [], rules = []) if object.kind_of?(Target) @targets[object.objs] = object else @targets[object] = Target.new(object,depends,rules) end end
Add a file to be removed during 'make clean' TODO: optimize by eliminating multiple rm(1) fork/exec
# File lib/makeconf/makefile.rb, line 77 def clean(path) add_rule('clean', Platform.rm(Platform.pathspec(path))) end
# File lib/makeconf/makefile.rb, line 23 def define_conditional_variable(cvar) throw "invalid argument" unless cvar.kind_of?(Makefile::Conditional) @cond_vars.push(cvar) end
Define a variable within the Makefile
# File lib/makeconf/makefile.rb, line 17 def define_variable(lval,op,rval) throw "invalid arguments" if lval.nil? or op.nil? throw "variable `#{lval}' is undefined" if rval.nil? @vars[lval] = [ op, rval ] end
Add a file to be removed during 'make distclean' TODO: optimize by eliminating multiple rm(1) fork/exec
# File lib/makeconf/makefile.rb, line 83 def distclean(path) add_rule('distclean', Platform.rm(Platform.pathspec(path))) end
Add a file to the tarball during 'make dist'
# File lib/makeconf/makefile.rb, line 60 def distribute(path) path = [ path ] if path.kind_of? String path.each do |src| # FIXME: support Windows backslashery if src =~ /\// dst = '$(distdir)/' + File.dirname(src) @targets['distdir'].mkdir(dst) @targets['distdir'].cp(src, dst) else @targets['distdir'].cp(src, '$(distdir)') end end end
# File lib/makeconf/makefile.rb, line 92 def make_dist(project,version) distdir = project + '-' + version.to_s # XXX-FIXME this should come from the Project distfile = project + '-' + version.to_s + '.tar.gz' tg = Target.new(distfile) tg.add_rule(Platform.rmdir(distdir)) tg.add_rule("mkdir " + distdir) tg.add_rule('$(MAKE) distdir distdir=' + distdir) if Platform.is_windows? # FIXME - Not implemented yet else tg.add_rule("rm -rf #{distdir}.tar #{distdir}.tar.gz") tg.add_rule("tar cf #{distdir}.tar #{distdir}") tg.add_rule("gzip #{distdir}.tar") tg.add_rule("rm -rf #{distdir}") clean("#{distdir}.tar.gz") end @targets[distfile] = tg end
# File lib/makeconf/makefile.rb, line 32 def merge!(src) return if src.nil? throw 'invalid argument' unless src.is_a?(Makefile) @vars.merge!(src.vars) @cond_vars.concat(src.cond_vars) src.targets.each do |k,v| if targets.has_key?(k) targets[k].merge!(v) else targets[k] = (v) end end end
# File lib/makeconf/makefile.rb, line 28 def target(object) @targets[object] end
# File lib/makeconf/makefile.rb, line 114 def to_s res = '' @vars.sort.each { |x,y| res += [x, y[0], y[1]].join(' ') + "\n" } res += "\n\n" res += ## Detect the canonical system type of the system we are building on# (build) and the system the package runs on (host)# BUILD_CPU=$(shell uname -m)HOST_CPU=$(BUILD_CPU)BUILD_VENDOR=unknownHOST_VENDOR=$(BUILD_VENDOR)BUILD_KERNEL=$(shell uname | tr '[A-Z]' '[a-z]')HOST_KERNEL=$(BUILD_KERNEL)BUILD_SYSTEM=gnuHOST_SYSTEM=$(BUILD_SYSTEM)BUILD_TYPE=$(BUILD_CPU)-$(BUILD_VENDOR)-$(BUILD_KERNEL)-$(BUILD_SYSTEM)HOST_TYPE=$(HOST_CPU)-$(HOST_VENDOR)-$(HOST_KERNEL)-$(HOST_SYSTEM)# Allow variables to be overridden via a ./configure script that outputs config.mk# FIXME -- requires GNU Make-include config.mk @cond_vars.each { |x| res += x.to_make } res += "default: all\n" targets.each { |x,y| throw "#{x} is broken" unless y.is_a? Target } @targets.sort.each { |x,y| res += y.to_s } res end
Generated with the Darkfish Rdoc Generator 2.