From: nobu.nokada@... Date: 2002-02-08T02:20:04+09:00 Subject: Re: mkmf, extconf.rb Hi, At Thu, 7 Feb 2002 19:22:28 +0900, Hugh Sasse Staff Elec Eng wrote: > > > Further to my suggestions in Ruby-Talk:31391, about adding methods to > > > mkmf so that rules can be added to makefiles, I have "lashed together" > > > the following patch. It works with an array of dependencies, but before > > > I test all the combinations of arguments permitted, has anyone any > > > comments? > > > > I guess you can do it with `depend' file. > > I have found that bit of code in mkmf: (snip) > I don't think you can use this for adding more make rules, because it is > not completely transparent. Suppose your action includes ruby code > which does 'gsub(/\.o\b/, ".#{$OBJEXT}")'. This will get rendered as > "gsub(/\.#{$OBJEXT}\b/" etc. It's sure not to be designed for general purpose. > Maybe this could be extracted to a method, and have the substitution > optional? def add_rules(rules) open("Makefile", "a") do |f| if defined? yield rules.each {|l| f << yield l} else f << rules end end end # or as you wrote in [ruby-talk:33238], append to $makerules. $makerules = "" def add_rules(rules) f = $makerules if defined? yield rules.each {|l| f << yield l} else f << rules end end # And then add_rules("depend") {|l| l.gsub(/\.o\b/, ".#{$OBJEXT}")} add_rules << EOM # rules EOM # or maybe, Makerules = [] def Makerules.add(rules, &block) self << [rules, block] end def Makerules.write(to) each {|r, b| b ? r.each {|l| to << b.call(l)} : to << l} end -- Nobu Nakada