Skip to contentSkip to conversation

Support splitting SOURCE in multiple rmk files

PATCH In review Bean 4 participants 11 messages Jun 24, 2009 – Jun 27, 2009

lore
Share & tools
lore

Bean

author
#0 lore raw

PATCH 1/1 Support splitting SOURCE in multiple rmk files

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.

conf/common.rmk +3 -2
index dc78df9..3402faf 100644
@@ -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.
conf/i386.rmk +3 -0
index 89496ae..8e9e582 100644
@@ -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)
Signature · 1 line
Bean
genmk.rb +6 -1
index e3866c1..30efbc5 100644
@@ -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]
#1 lore raw
Quoted 21 lines · Bean
conf/common.rmk +3 -2
index dc78df9..3402faf 100644
@@ -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.
conf/i386.rmk +0 -0
index 89496ae..8e9e582 100644

conf/i386.rmk line 8

Quoted 8 lines
conf/i386.rmk +3 -0
@@ -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)

This looks very confusing. If what is actually doing is append a new string to the grub_mkelfimage_SOURCES variable, why not with "+=" ?

"=" means override the previous value.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#2 lore raw
Quoted 34 lines · Robert Millan
Quoted 26 lines · Bean
conf/common.rmk +0 -0
index dc78df9..3402faf 100644
@@ -2,8 +2,9 @@
 
  # For grub-mkelfimage.

 bin_UTILITIES += grub-mkelfimage

conf/common.rmk +3 -2
-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.

conf/i386.rmk +3 -0
index 89496ae..8e9e582 100644
@@ -1,5 +1,8 @@
  # -*- makefile -*-
 
+bin_UTILITIES += grub-mkelfimage
+grub_mkelfimage_SOURCES = util/resolve.c
+
Quoted 3 lines

 pkglib_MODULES += cpuid.mod
 cpuid_mod_SOURCES = commands/i386/cpuid.c
 cpuid_mod_CFLAGS = $(COMMON_CFLAGS)

This looks very confusing.  If what is actually doing is append a new string to the grub_mkelfimage_SOURCES variable, why not with "+=" ?

Quoted 1 line

"=" means override the previous value.

Hi,

You can use = or +=, actually the macro is used by genmk.rb to generate the rules, it's not used by Makefile itself, so no problem overriding it.

Quoted 14 lines

--
Robert Millan

 The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 1 line
Bean
#3 lore raw

Sory for not being present last few days - I split my time between non-grub things and making zfs work welll in grub2 (I'm already able to boot FreeBSD off ZFS with branch I have in my personal repo)

Quoted 7 lines

Hi,

You can use = or +=, actually the macro is used by genmk.rb to generate the rules, it's not used by Makefile itself, so no problem overriding it.

+= is clearer and using it may avoid problems in future. Also I suggest having a look at my patch about the same subject.

Quoted 28 lines
Quoted 6 lines

--
Robert Millan

The DRM opt-in fallacy: "Your data belongs to us. We will decide when

(and

Quoted 9 lines

how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

--
Bean

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
author
#4 lore raw
Quoted 4 lines · Vladimir 'phcoder' Serbinenko

Sory for not being present last few days - I split my time between non-grub things and making zfs work welll in grub2 (I'm already able to boot FreeBSD off ZFS with branch I have in my personal repo)

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

Hi,

You can use = or +=, actually the macro is used by genmk.rb to generate the rules, it's not used by Makefile itself, so no problem overriding it.

+= is clearer and using it may avoid problems in future. Also I suggest having a look at my patch about the same subject.

Hi,

Oh, could you give me a link ?

Quoted 43 lines
Quoted 20 lines
Quoted 12 lines

--
Robert Millan

 The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
 how) you may access your data; but nobody's threatening your freedom:
we
 still allow you to remove your data and not access it at all."

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Quoted 8 lines

--
Bean

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

--
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 1 line
Bean
#5 lore raw
In reply to Bean
Quoted 10 lines · Bean
Quoted 10 lines
Quoted 6 lines
conf/i386.rmk +3 -0
+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)

This looks very confusing.  If what is actually doing is append a new string to the grub_mkelfimage_SOURCES variable, why not with "+=" ?

Quoted 7 lines
Quoted 1 line

"=" means override the previous value.

Hi,

You can use = or +=, actually the macro is used by genmk.rb to generate the rules, it's not used by Makefile itself, so no problem overriding it.

Yes, but using = to generate a rule that actually means += is very confusing. Please don't do that.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#6 lore raw
In reply to Bean
Quoted 3 lines · Bean

You can use = or +=, actually the macro is used by genmk.rb to generate the rules, it's not used by Makefile itself, so no problem overriding it.

While at that, it would be nice to use a special notation for the partial dependencies.

Something like:

aa:+ aa.o
aa:+ bb.o

Please don't use "_DEFINED" to mean "rule emitted", it's confusing.

Signature · 2 lines
Regards,
Pavel Roskin
author
#7 lore raw
Quoted 6 lines · Pavel Roskin
Quoted 3 lines · Bean

You can use = or +=, actually the macro is used by genmk.rb to generate the rules, it's not used by Makefile itself, so no problem overriding it.

Quoted 7 lines

While at that, it would be nice to use a special notation for the partial dependencies.

Something like:

aa:+ aa.o
aa:+ bb.o

Hi,

Is this new syntax for GNU make ? My version report error when using :+ .

Quoted 2 lines

Please don't use "_DEFINED" to mean "rule emitted", it's confusing.

How about _RULES_DEFINED ?

Quoted 11 lines

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 1 line
Bean
#8 lore raw
Quoted 5 lines · Bean
Quoted 3 lines · Pavel Roskin

While at that, it would be nice to use a special notation for the partial dependencies.

Quoted 8 lines
Quoted 4 lines

Something like:

aa:+ aa.o
aa:+ bb.o

Hi,

Is this new syntax for GNU make ? My version report error when using :+ .

No. I suggested syntax that would indicate that it's not a complete make rule.

If we use Ruby to join the rules, we can replace ":+" with ":" in the result.

Quoted 3 lines
Quoted 1 line

Please don't use "_DEFINED" to mean "rule emitted", it's confusing.

How about _RULES_DEFINED ?

I'm fine with anything that is descriptive.

Signature · 2 lines
Regards,
Pavel Roskin
author
#9 lore raw
Quoted 13 lines · Pavel Roskin
Quoted 12 lines · Bean
Quoted 7 lines · Pavel Roskin

While at that, it would be nice to use a special notation for the partial dependencies.

Something like:

aa:+ aa.o
aa:+ bb.o

Hi,

Quoted 7 lines
Quoted 1 line

Is this new syntax for GNU make ? My version report error when using :+ .

No.  I suggested syntax that would indicate that it's not a complete make rule.

If we use Ruby to join the rules, we can replace ":+" with ":" in the result.

Hi,

Oh, actually aa: aa.o is already a ruby generated rule, it doesn't exist in rmk file. The original line from rmk would be something like this:

aa_SOURCES += aa.c

Signature · 1 line
Bean
#10 lore raw
Quoted 5 lines · Bean

Oh, actually aa: aa.o is already a ruby generated rule, it doesn't exist in rmk file. The original line from rmk would be something like this:

aa_SOURCES += aa.c

I see. Sorry for the noise.

Signature · 2 lines
Regards,
Pavel Roskin