From: Hugh Sasse Staff Elec Eng Date: 2002-02-08T03:06:16+09:00 Subject: Re: mkmf, extconf.rb On Fri, 8 Feb 2002 nobu.nokada@softhome.net wrote: > 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" [...] > > > 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 Yes, I like the idea of using a block > > # 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 > Whichever you are happiest with. "Global variables are maybe best avoided." seems to be a rule of thumb which may be relevant. I couldn't think of a good way round that at the time. > # And then > add_rules("depend") {|l| l.gsub(/\.o\b/, ".#{$OBJEXT}")} > Yes, > add_rules << EOM > # rules > EOM but I don't think you'd need that, you just to the call from extconf.rb (see below) rather than modifying the module mkmf itself. > > > # 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 > I would be happy with these. As far as I can see from my reading of `man make` appending the rules at the end of the makefile would be fine, so people could call this from extconf.rb and have it work: require mkmf create_makefile('thingy') add_rules < > -- > Nobu Nakada > Hugh