From e8f5d6e985b9e73ded8aac7f1cbdfa63605a099a Mon Sep 17 00:00:00 2001 From: blusseau Date: Sat, 12 Sep 2009 07:38:50 +0000 Subject: [PATCH] 2009-09-12 Yves Blusseau Change clean rules to properly remove files * genmk.rb: add new clean rules * Makefile.in (clean): add the new targets (mostlyclean): likewise --- ChangeLog | 8 ++++++++ Makefile.in | 4 ++-- genmk.rb | 55 +++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64b77d04d..0428aa726 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-09-12 Yves Blusseau + + Change clean rules to properly remove files + + * genmk.rb: add new clean rules + * Makefile.in (clean): add the new targets + (mostlyclean): likewise + 2009-09-11 Colin Watson * include/grub/ntfs.h (struct grub_fshelp_node): Change `size' diff --git a/Makefile.in b/Makefile.in index 7c5adbc61..ff84afb7b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -326,10 +326,10 @@ uninstall: rm -f $(DESTDIR)$(libdir)/grub/$$dest; \ done -clean: +clean: $(CLEAN_IMAGE_TARGETS) $(CLEAN_MODULE_TARGETS) $(CLEAN_UTILITY_TARGETS) -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) -mostlyclean: clean +mostlyclean: clean $(MOSTLYCLEAN_IMAGE_TARGETS) $(MOSTLYCLEAN_MODULE_TARGETS) $(MOSTLYCLEAN_UTILITY_TARGETS) -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) distclean: mostlyclean diff --git a/genmk.rb b/genmk.rb index 4aedb25c4..50bf88fe1 100644 --- a/genmk.rb +++ b/genmk.rb @@ -39,11 +39,13 @@ class Image def initialize(dir, name) @dir = dir @name = name + @rule_count = 0 end attr_reader :dir, :name def rule(sources) prefix = @name.to_var + @rule_count += 1 exe = @name.suffix('exec') objs = sources.collect do |src| raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src @@ -53,8 +55,16 @@ class Image deps = objs.collect {|obj| obj.suffix('d')} deps_str = deps.join(' ') - "CLEANFILES += #{@name} #{exe} #{objs_str} -MOSTLYCLEANFILES += #{deps_str} +" +clean-image-#{@name}.#{@rule_count}: + rm -f #{@name} #{exe} #{objs_str} + +CLEAN_IMAGE_TARGETS += clean-image-#{@name}.#{@rule_count} + +mostlyclean-image-#{@name}.#{@rule_count}: + rm -f #{deps_str} + +MOSTLYCLEAN_IMAGE_TARGETS += mostlyclean-image-#{@name}.#{@rule_count} ifneq ($(TARGET_APPLE_CC),1) #{@name}: #{exe} @@ -94,11 +104,13 @@ class PModule def initialize(dir, name) @dir = dir @name = name + @rule_count = 0 end attr_reader :dir, :name def rule(sources) prefix = @name.to_var + @rule_count += 1 objs = sources.collect do |src| raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src prefix + '-' + src.to_obj @@ -114,12 +126,23 @@ class PModule mod_name = File.basename(@name, '.mod') symbolic_name = mod_name.sub(/\.[^\.]*$/, '') - "CLEANFILES += #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym} +" +clean-module-#{@name}.#{@rule_count}: + rm -f #{@name} #{mod_obj} #{mod_src} #{pre_obj} #{objs_str} #{undsym} + +CLEAN_MODULE_TARGETS += clean-module-#{@name}.#{@rule_count} + ifneq ($(#{prefix}_EXPORTS),no) -CLEANFILES += #{defsym} +clean-module-#{@name}-symbol.#{@rule_count}: + rm -f #{defsym} + +CLEAN_MODULE_TARGETS += clean-module-#{@name}-symbol.#{@rule_count} DEFSYMFILES += #{defsym} endif -MOSTLYCLEANFILES += #{deps_str} +mostlyclean-module-#{@name}.#{@rule_count}: + rm -f #{deps_str} + +MOSTLYCLEAN_MODULE_TARGETS += mostlyclean-module-#{@name}.#{@rule_count} UNDSYMFILES += #{undsym} ifneq ($(TARGET_APPLE_CC),1) @@ -164,6 +187,7 @@ endif " + objs.collect_with_index do |obj, i| src = sources[i] fake_obj = File.basename(src).suffix('o') + extra_target = obj.sub(/\.[^\.]*$/, '') + '-extra' command = 'cmd-' + obj.suffix('lst') fs = 'fs-' + obj.suffix('lst') partmap = 'partmap-' + obj.suffix('lst') @@ -178,7 +202,11 @@ endif $(TARGET_CC) -I#{dir} -I$(srcdir)/#{dir} $(TARGET_CPPFLAGS) #{extra_flags} $(TARGET_#{flag}) $(#{prefix}_#{flag}) -MD -c -o $@ $< -include #{dep} -CLEANFILES += #{command} #{fs} #{partmap} #{handler} #{parttool} +clean-module-#{extra_target}.#{@rule_count}: + rm -f #{command} #{fs} #{partmap} #{handler} #{parttool} + +CLEAN_MODULE_TARGETS += clean-module-#{extra_target}.#{@rule_count} + COMMANDFILES += #{command} FSFILES += #{fs} PARTTOOLFILES += #{parttool} @@ -219,6 +247,7 @@ class Utility def initialize(dir, name) @dir = dir @name = name + @rule_count = 0 end def print_tail() prefix = @name.to_var @@ -231,6 +260,7 @@ class Utility def rule(sources) prefix = @name.to_var + @rule_count += 1 objs = sources.collect do |src| raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src prefix + '-' + src.to_obj @@ -239,8 +269,17 @@ class Utility deps = objs.collect {|obj| obj.suffix('d')} deps_str = deps.join(' '); - "CLEANFILES += #{@name}$(EXEEXT) #{objs_str} -MOSTLYCLEANFILES += #{deps_str} + " +clean-utility-#{@name}.#{@rule_count}: + rm -f #{@name}$(EXEEXT) #{objs_str} + +CLEAN_UTILITY_TARGETS += clean-utility-#{@name}.#{@rule_count} + +mostlyclean-utility-#{@name}.#{@rule_count}: + rm -f #{deps_str} + +MOSTLYCLEAN_UTILITY_TARGETS += mostlyclean-utility-#{@name}.#{@rule_count} + #{prefix}_OBJECTS += #{objs_str} " + objs.collect_with_index do |obj, i|