Hi, In the current build system, all source files to build an executable must reside in a single rmk file, this makes it difficult to break down the build system in more logical blocks. This patch fixes this by utilizing some tricks of GNU make.
First, you can specify the dependence of target in multiple lines, for example: aa: aa.o aa: bb.o $^ represent all dependence, so aa: aa.o gcc -oaa $^ aa: bb.o is the same as aa: aa.o bb.o gcc -oaa aa.o bb.o Second, you can use ifdef so that only the first occurrence would define a rule, for example: ifdef aa_DEFINED aa: aa.o else aa: aa.o gcc -oaa $^ aa_DEFINED=1 endif ifdef aa_DEFINED aa: bb.o else aa: bb.o gcc -oaa $^ aa_DEFINED=1 endif Then, this two blocks can be placed in different makefile, in any order. Third, there could be other dependence file that would cause problem with gcc, but we can filter them out by replacing $^ with $(filter %o,$^). I've post the patch file for genmk.rb, it only changes the rules for *_UTILITIES, but this applies to other targets as well. This is an example to show how to move source file resolve.c of grub_mkelfimage from common.rmk to i386.rmk. diff --git a/conf/common.rmk b/conf/common.rmk index dc78df9..3402faf 100644 --- a/conf/common.rmk +++ b/conf/common.rmk @@ -2,8 +2,9 @@ # For grub-mkelfimage. bin_UTILITIES += grub-mkelfimage -grub_mkelfimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \ - util/resolve.c +#grub_mkelfimage_SOURCES = util/elf/grub-mkimage.c util/misc.c \ +# util/resolve.c +grub_mkelfimage_SOURCES = util/elf/grub-mkimage.c util/misc.c util/elf/grub-mkimage.c_DEPENDENCIES = Makefile # For grub-probe. diff --git a/conf/i386.rmk b/conf/i386.rmk index 89496ae..8e9e582 100644 --- a/conf/i386.rmk +++ b/conf/i386.rmk @@ -1,5 +1,8 @@ # -*- makefile -*- +bin_UTILITIES += grub-mkelfimage +grub_mkelfimage_SOURCES = util/resolve.c + pkglib_MODULES += cpuid.mod cpuid_mod_SOURCES = commands/i386/cpuid.c cpuid_mod_CFLAGS = $(COMMON_CFLAGS) -- Bean
diff --git a/genmk.rb b/genmk.rb index e3866c1..30efbc5 100644 --- a/genmk.rb +++ b/genmk.rb @@ -235,8 +235,13 @@ class Utility "CLEANFILES += #...@name}$(EXEEXT) #{objs_str} MOSTLYCLEANFILES += #{deps_str} +ifdef #...@name}_defined +...@name}: #{objs_str} +else #...@name}: $(#{prefix}_DEPENDENCIES) #{objs_str} - $(CC) -o $@ #{objs_str} $(LDFLAGS) $(#{prefix}_LDFLAGS) + $(CC) -o $@ $(filter %.o,$^) $(LDFLAGS) $(#{prefix}_LDFLAGS) +...@name}_defined=1 +endif " + objs.collect_with_index do |obj, i| src = sources[i]
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel