From: Hugh Sasse Staff Elec Eng Date: 2002-02-07T01:11:49+09:00 Subject: mkmf, extconf.rb 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? Hugh --- ./mkmf.rb.orig Wed Feb 6 14:12:20 2002 +++ ./mkmf.rb Wed Feb 6 15:57:34 2002 @@ -19,6 +19,10 @@ $sitelibdir = CONFIG["sitelibdir"] $sitearchdir = CONFIG["sitearchdir"] +# Variable to hold make rules so they can be added at the +# end of those derived by this script +$makerules = "" + if File.exist? Config::CONFIG["archdir"] + "/ruby.h" $hdrdir = $archdir elsif File.exist? $srcdir + "/ruby.h" @@ -361,6 +365,41 @@ /^\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir end +# Write a makefile rule out as a string +def create_make_rule(target, dependencies, actions) + rule = "#{target}:\t" + # This uses type dispatch -- strings and arrays both respond_to each + case dependencies + when String + rule << dependencies.chomp + when Array + dependencies.each { |dep| + rule << "#{dep.chomp} " + } + when nil + else + raise "$0: create_make_rule: dependencies" \ + "#{dependencies.inspect} of unknown type" + end + rule << "\n" + # String.each is String.each_line, so this will be + # the same as if an array has been passed + unless actions.nil? + # each will fail if actions is nil. + actions.each { |action| + rule << "\t#{action.chomp}\n" + } + end + rule << "\n" + return rule +end + +# Add a make rule to the Makefile which will be output +def add_make_rule(target, dependencies, actions) + $makerules << create_make_rule(target, dependencies, actions) +end + + def create_makefile(target, srcdir = File.dirname($0)) save_libs = $libs.dup save_libpath = $LIBPATH.dup @@ -496,6 +535,10 @@ site-install: $(sitearchdir)$(target_prefix)/$(DLLIB) +### Rules added through add_make_rule() +EOMF + mfile.printf "#{$makerules}\n" + mfile.printf <