* [RFC] Kbuild: allow code re-use across different directories
@ 2011-08-20 0:37 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-08-20 0:37 UTC (permalink / raw)
To: linux-kbuild; +Cc: Arnaud Lacombe, linux-kernel, linux-arm-kernel
Hi folks,
The attached patch modify Kbuild to allow to directly re-use code in multiple
directory without having to go through a copy. Technically, it changes Kbuild to
use by default the VPATH feature of GNU make and provides accessors for Makefile
to change it indirectly.
Considering:
arch/foo/lib:
fancy.c
We want to be able to build it with -DPANTS=32 in the kernel, but the
bootloader requires -DPANTS_SIZE=30.
Currently we would do, either:
arch/foo/lib/Makefile
LDFLAGS_fancy.o := -DPANTS=32
obj-y += fancy.o
and, either:
arch/foo/boot/Makefile:
LDFLAGS_fancy.o := -DPANTS=30
obj-y += fancy.o
$(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
$(call cmd,shipped)
or
arch/foo/boot/Makefile:
LDFLAGS_fancy.o := -DPANTS=30
obj-y += fancy.o
$(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
$(call cmd,cc_c_o)
The former implies an extra copy of the source file, the latter expose Kbuild
internal function.
With the attached patch, we would do:
arch/foo/boot/Makefile:
LDFLAGS_fancy.o := -DPANTS=30
obj-y += fancy.o
vpath-y += $(srctree)/arch/foo/lib
and let GNU make do the job.
Comments welcome,
- Arnaud
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
---
Makefile | 5 +++--
scripts/Makefile.build | 24 +++++++++++++++---------
scripts/Makefile.lib | 17 ++++++++++++-----
3 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/Makefile b/Makefile
index b4ca4e1..db7f7f5 100644
--- a/Makefile
+++ b/Makefile
@@ -154,9 +154,10 @@ objtree := $(CURDIR)
src := $(srctree)
obj := $(objtree)
-VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
+KBUILD_VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
+VPATH := $(KBUILD_VPATH)
-export srctree objtree VPATH
+export srctree objtree KBUILD_VPATH
# SUBARCH tells the usermode build what the underlying arch is. That is set
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index a0fd502..ac539d7 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -18,6 +18,8 @@ always :=
targets :=
subdir-y :=
subdir-m :=
+vpath-y :=
+vpath-m :=
EXTRA_AFLAGS :=
EXTRA_CFLAGS :=
EXTRA_CPPFLAGS :=
@@ -37,6 +39,7 @@ include scripts/Kbuild.include
# For backward compatibility check that these variables do not change
save-cflags := $(CFLAGS)
+save-vpath := $(VPATH)
# The filename Kbuild has precedence over Makefile
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
@@ -48,6 +51,9 @@ ifeq ($(KBUILD_NOPEDANTIC),)
ifneq ("$(save-cflags)","$(CFLAGS)")
$(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS)
endif
+ ifneq ("$(save-vpath)","$(VPATH)")
+ $(error VPATH was changed in "$(kbuild-file)". Please uses vpath-y)
+ endif
endif
#
@@ -198,13 +204,13 @@ $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
-$(obj)/%.s: $(src)/%.c FORCE
+$(obj)/%.s: %.c FORCE
$(call if_changed_dep,cc_s_c)
quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
-$(obj)/%.i: $(src)/%.c FORCE
+$(obj)/%.i: %.c FORCE
$(call if_changed_dep,cc_i_c)
cmd_gensymtypes = \
@@ -219,7 +225,7 @@ cmd_cc_symtypes_c = \
$(call cmd_gensymtypes,true,$@) >/dev/null; \
test -s $@ || rm -f $@
-$(obj)/%.symtypes : $(src)/%.c FORCE
+$(obj)/%.symtypes : %.c FORCE
$(call cmd,cc_symtypes_c)
# C (.c) files
@@ -301,13 +307,13 @@ define rule_cc_o_c
endef
# Built-in and composite module parts
-$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
+$(obj)/%.o: %.c $(recordmcount_source) FORCE
$(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_c)
# Single-part modules are special since we need to mark them in $(MODVERDIR)
-$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
+$(single-used-m): %.o: %.c $(recordmcount_source) FORCE
$(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_c)
@{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
@@ -317,7 +323,7 @@ quiet_cmd_cc_lst_c = MKLST $@
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
System.map $(OBJDUMP) > $@
-$(obj)/%.lst: $(src)/%.c FORCE
+$(obj)/%.lst: %.c FORCE
$(call if_changed_dep,cc_lst_c)
# Compile assembler sources (.S)
@@ -331,13 +337,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
-$(obj)/%.s: $(src)/%.S FORCE
+$(obj)/%.s: %.S FORCE
$(call if_changed_dep,as_s_S)
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
-$(obj)/%.o: $(src)/%.S FORCE
+$(obj)/%.o: %.S FORCE
$(call if_changed_dep,as_o_S)
targets += $(real-objs-y) $(real-objs-m) $(lib-y)
@@ -349,7 +355,7 @@ quiet_cmd_cpp_lds_S = LDS $@
cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
-D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
-$(obj)/%.lds: $(src)/%.lds.S FORCE
+$(obj)/%.lds: %.lds.S FORCE
$(call if_changed_dep,cpp_lds_S)
# Build the compiled-in targets
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index aeea84a..b57b621 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -46,6 +46,13 @@ obj-m := $(filter-out %/, $(obj-m))
subdir-ym := $(sort $(subdir-y) $(subdir-m))
+#
+vpath-ym := $(vpath-y) $(vpath-m)
+VPATH := $(KBUILD_VPATH)
+VPATH += $(srctree)/$(src)
+VPATH += $(obj)
+VPATH += $(vpath-ym)
+
# if $(foo-objs) exists, foo.o is a composite object
multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
@@ -167,7 +174,7 @@ ifdef REGENERATE_PARSERS
quiet_cmd_gperf = GPERF $@
cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
-$(src)/%.hash.c_shipped: $(src)/%.gperf
+$(src)/%.hash.c_shipped: %.gperf
$(call cmd,gperf)
# LEX
@@ -177,7 +184,7 @@ LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
quiet_cmd_flex = LEX $@
cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
-$(src)/%.lex.c_shipped: $(src)/%.l
+$(src)/%.lex.c_shipped: %.l
$(call cmd,flex)
# YACC
@@ -187,13 +194,13 @@ YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
quiet_cmd_bison = YACC $@
cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
-$(src)/%.tab.c_shipped: $(src)/%.y
+$(src)/%.tab.c_shipped: %.y
$(call cmd,bison)
quiet_cmd_bison_h = YACC $@
cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
-$(src)/%.tab.h_shipped: $(src)/%.y
+$(src)/%.tab.h_shipped: %.y
$(call cmd,bison_h)
endif
@@ -204,7 +211,7 @@ endif
quiet_cmd_shipped = SHIPPED $@
cmd_shipped = cat $< > $@
-$(obj)/%: $(src)/%_shipped
+$(obj)/%: %_shipped
$(call cmd,shipped)
# Commands useful for building a boot image
--
1.7.6.153.g78432
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-08-20 0:37 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-08-20 0:37 UTC (permalink / raw)
To: linux-arm-kernel
Hi folks,
The attached patch modify Kbuild to allow to directly re-use code in multiple
directory without having to go through a copy. Technically, it changes Kbuild to
use by default the VPATH feature of GNU make and provides accessors for Makefile
to change it indirectly.
Considering:
arch/foo/lib:
fancy.c
We want to be able to build it with -DPANTS=32 in the kernel, but the
bootloader requires -DPANTS_SIZE=30.
Currently we would do, either:
arch/foo/lib/Makefile
LDFLAGS_fancy.o := -DPANTS=32
obj-y += fancy.o
and, either:
arch/foo/boot/Makefile:
LDFLAGS_fancy.o := -DPANTS=30
obj-y += fancy.o
$(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
$(call cmd,shipped)
or
arch/foo/boot/Makefile:
LDFLAGS_fancy.o := -DPANTS=30
obj-y += fancy.o
$(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
$(call cmd,cc_c_o)
The former implies an extra copy of the source file, the latter expose Kbuild
internal function.
With the attached patch, we would do:
arch/foo/boot/Makefile:
LDFLAGS_fancy.o := -DPANTS=30
obj-y += fancy.o
vpath-y += $(srctree)/arch/foo/lib
and let GNU make do the job.
Comments welcome,
- Arnaud
Cc: linux-kernel at vger.kernel.org
Cc: linux-arm-kernel at lists.infradead.org
---
Makefile | 5 +++--
scripts/Makefile.build | 24 +++++++++++++++---------
scripts/Makefile.lib | 17 ++++++++++++-----
3 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/Makefile b/Makefile
index b4ca4e1..db7f7f5 100644
--- a/Makefile
+++ b/Makefile
@@ -154,9 +154,10 @@ objtree := $(CURDIR)
src := $(srctree)
obj := $(objtree)
-VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
+KBUILD_VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
+VPATH := $(KBUILD_VPATH)
-export srctree objtree VPATH
+export srctree objtree KBUILD_VPATH
# SUBARCH tells the usermode build what the underlying arch is. That is set
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index a0fd502..ac539d7 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -18,6 +18,8 @@ always :=
targets :=
subdir-y :=
subdir-m :=
+vpath-y :=
+vpath-m :=
EXTRA_AFLAGS :=
EXTRA_CFLAGS :=
EXTRA_CPPFLAGS :=
@@ -37,6 +39,7 @@ include scripts/Kbuild.include
# For backward compatibility check that these variables do not change
save-cflags := $(CFLAGS)
+save-vpath := $(VPATH)
# The filename Kbuild has precedence over Makefile
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
@@ -48,6 +51,9 @@ ifeq ($(KBUILD_NOPEDANTIC),)
ifneq ("$(save-cflags)","$(CFLAGS)")
$(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS)
endif
+ ifneq ("$(save-vpath)","$(VPATH)")
+ $(error VPATH was changed in "$(kbuild-file)". Please uses vpath-y)
+ endif
endif
#
@@ -198,13 +204,13 @@ $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
-$(obj)/%.s: $(src)/%.c FORCE
+$(obj)/%.s: %.c FORCE
$(call if_changed_dep,cc_s_c)
quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
-$(obj)/%.i: $(src)/%.c FORCE
+$(obj)/%.i: %.c FORCE
$(call if_changed_dep,cc_i_c)
cmd_gensymtypes = \
@@ -219,7 +225,7 @@ cmd_cc_symtypes_c = \
$(call cmd_gensymtypes,true,$@) >/dev/null; \
test -s $@ || rm -f $@
-$(obj)/%.symtypes : $(src)/%.c FORCE
+$(obj)/%.symtypes : %.c FORCE
$(call cmd,cc_symtypes_c)
# C (.c) files
@@ -301,13 +307,13 @@ define rule_cc_o_c
endef
# Built-in and composite module parts
-$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
+$(obj)/%.o: %.c $(recordmcount_source) FORCE
$(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_c)
# Single-part modules are special since we need to mark them in $(MODVERDIR)
-$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
+$(single-used-m): %.o: %.c $(recordmcount_source) FORCE
$(call cmd,force_checksrc)
$(call if_changed_rule,cc_o_c)
@{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
@@ -317,7 +323,7 @@ quiet_cmd_cc_lst_c = MKLST $@
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
System.map $(OBJDUMP) > $@
-$(obj)/%.lst: $(src)/%.c FORCE
+$(obj)/%.lst: %.c FORCE
$(call if_changed_dep,cc_lst_c)
# Compile assembler sources (.S)
@@ -331,13 +337,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
-$(obj)/%.s: $(src)/%.S FORCE
+$(obj)/%.s: %.S FORCE
$(call if_changed_dep,as_s_S)
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
-$(obj)/%.o: $(src)/%.S FORCE
+$(obj)/%.o: %.S FORCE
$(call if_changed_dep,as_o_S)
targets += $(real-objs-y) $(real-objs-m) $(lib-y)
@@ -349,7 +355,7 @@ quiet_cmd_cpp_lds_S = LDS $@
cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
-D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
-$(obj)/%.lds: $(src)/%.lds.S FORCE
+$(obj)/%.lds: %.lds.S FORCE
$(call if_changed_dep,cpp_lds_S)
# Build the compiled-in targets
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index aeea84a..b57b621 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -46,6 +46,13 @@ obj-m := $(filter-out %/, $(obj-m))
subdir-ym := $(sort $(subdir-y) $(subdir-m))
+#
+vpath-ym := $(vpath-y) $(vpath-m)
+VPATH := $(KBUILD_VPATH)
+VPATH += $(srctree)/$(src)
+VPATH += $(obj)
+VPATH += $(vpath-ym)
+
# if $(foo-objs) exists, foo.o is a composite object
multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
@@ -167,7 +174,7 @@ ifdef REGENERATE_PARSERS
quiet_cmd_gperf = GPERF $@
cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
-$(src)/%.hash.c_shipped: $(src)/%.gperf
+$(src)/%.hash.c_shipped: %.gperf
$(call cmd,gperf)
# LEX
@@ -177,7 +184,7 @@ LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
quiet_cmd_flex = LEX $@
cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
-$(src)/%.lex.c_shipped: $(src)/%.l
+$(src)/%.lex.c_shipped: %.l
$(call cmd,flex)
# YACC
@@ -187,13 +194,13 @@ YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
quiet_cmd_bison = YACC $@
cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
-$(src)/%.tab.c_shipped: $(src)/%.y
+$(src)/%.tab.c_shipped: %.y
$(call cmd,bison)
quiet_cmd_bison_h = YACC $@
cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
-$(src)/%.tab.h_shipped: $(src)/%.y
+$(src)/%.tab.h_shipped: %.y
$(call cmd,bison_h)
endif
@@ -204,7 +211,7 @@ endif
quiet_cmd_shipped = SHIPPED $@
cmd_shipped = cat $< > $@
-$(obj)/%: $(src)/%_shipped
+$(obj)/%: %_shipped
$(call cmd,shipped)
# Commands useful for building a boot image
--
1.7.6.153.g78432
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-08-20 0:37 ` Arnaud Lacombe
@ 2011-08-22 8:42 ` Cong Wang
-1 siblings, 0 replies; 35+ messages in thread
From: Cong Wang @ 2011-08-22 8:42 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: linux-kbuild, linux-kernel, linux-arm-kernel
于 2011年08月20日 08:37, Arnaud Lacombe 写道:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
...
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
Just note that don't forget to update Documentation/kbuild/makefiles.txt. ;)
Thanks.
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-08-22 8:42 ` Cong Wang
0 siblings, 0 replies; 35+ messages in thread
From: Cong Wang @ 2011-08-22 8:42 UTC (permalink / raw)
To: linux-arm-kernel
? 2011?08?20? 08:37, Arnaud Lacombe ??:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
...
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
Just note that don't forget to update Documentation/kbuild/makefiles.txt. ;)
Thanks.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-08-20 0:37 ` Arnaud Lacombe
@ 2011-08-30 0:31 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-08-30 0:31 UTC (permalink / raw)
To: linux-kbuild, Nicolas Pitre
Cc: Arnaud Lacombe, linux-kernel, linux-arm-kernel
Hi,
On Fri, Aug 19, 2011 at 8:37 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
>
> Considering:
>
> arch/foo/lib:
> fancy.c
>
> We want to be able to build it with -DPANTS=32 in the kernel, but the
> bootloader requires -DPANTS_SIZE=30.
>
> Currently we would do, either:
>
> arch/foo/lib/Makefile
> LDFLAGS_fancy.o := -DPANTS=32
> obj-y += fancy.o
>
> and, either:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,shipped)
>
> or
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,cc_c_o)
>
> The former implies an extra copy of the source file, the latter expose Kbuild
> internal function.
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
>
Nicolas, I guess you were the one who was interested for a generic way
to do such code re-use, did you had any chance to test the quoted
patch ?
Thanks,
- Arnaud
> Comments welcome,
> - Arnaud
>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
>
> ---
> Makefile | 5 +++--
> scripts/Makefile.build | 24 +++++++++++++++---------
> scripts/Makefile.lib | 17 ++++++++++++-----
> 3 files changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index b4ca4e1..db7f7f5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -154,9 +154,10 @@ objtree := $(CURDIR)
> src := $(srctree)
> obj := $(objtree)
>
> -VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
> +KBUILD_VPATH := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
> +VPATH := $(KBUILD_VPATH)
>
> -export srctree objtree VPATH
> +export srctree objtree KBUILD_VPATH
>
>
> # SUBARCH tells the usermode build what the underlying arch is. That is set
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index a0fd502..ac539d7 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -18,6 +18,8 @@ always :=
> targets :=
> subdir-y :=
> subdir-m :=
> +vpath-y :=
> +vpath-m :=
> EXTRA_AFLAGS :=
> EXTRA_CFLAGS :=
> EXTRA_CPPFLAGS :=
> @@ -37,6 +39,7 @@ include scripts/Kbuild.include
>
> # For backward compatibility check that these variables do not change
> save-cflags := $(CFLAGS)
> +save-vpath := $(VPATH)
>
> # The filename Kbuild has precedence over Makefile
> kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
> @@ -48,6 +51,9 @@ ifeq ($(KBUILD_NOPEDANTIC),)
> ifneq ("$(save-cflags)","$(CFLAGS)")
> $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS)
> endif
> + ifneq ("$(save-vpath)","$(VPATH)")
> + $(error VPATH was changed in "$(kbuild-file)". Please uses vpath-y)
> + endif
> endif
>
> #
> @@ -198,13 +204,13 @@ $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
> quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
> cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
>
> -$(obj)/%.s: $(src)/%.c FORCE
> +$(obj)/%.s: %.c FORCE
> $(call if_changed_dep,cc_s_c)
>
> quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
> cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
>
> -$(obj)/%.i: $(src)/%.c FORCE
> +$(obj)/%.i: %.c FORCE
> $(call if_changed_dep,cc_i_c)
>
> cmd_gensymtypes = \
> @@ -219,7 +225,7 @@ cmd_cc_symtypes_c = \
> $(call cmd_gensymtypes,true,$@) >/dev/null; \
> test -s $@ || rm -f $@
>
> -$(obj)/%.symtypes : $(src)/%.c FORCE
> +$(obj)/%.symtypes : %.c FORCE
> $(call cmd,cc_symtypes_c)
>
> # C (.c) files
> @@ -301,13 +307,13 @@ define rule_cc_o_c
> endef
>
> # Built-in and composite module parts
> -$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
> +$(obj)/%.o: %.c $(recordmcount_source) FORCE
> $(call cmd,force_checksrc)
> $(call if_changed_rule,cc_o_c)
>
> # Single-part modules are special since we need to mark them in $(MODVERDIR)
>
> -$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
> +$(single-used-m): %.o: %.c $(recordmcount_source) FORCE
> $(call cmd,force_checksrc)
> $(call if_changed_rule,cc_o_c)
> @{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
> @@ -317,7 +323,7 @@ quiet_cmd_cc_lst_c = MKLST $@
> $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
> System.map $(OBJDUMP) > $@
>
> -$(obj)/%.lst: $(src)/%.c FORCE
> +$(obj)/%.lst: %.c FORCE
> $(call if_changed_dep,cc_lst_c)
>
> # Compile assembler sources (.S)
> @@ -331,13 +337,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
> quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
> cmd_as_s_S = $(CPP) $(a_flags) -o $@ $<
>
> -$(obj)/%.s: $(src)/%.S FORCE
> +$(obj)/%.s: %.S FORCE
> $(call if_changed_dep,as_s_S)
>
> quiet_cmd_as_o_S = AS $(quiet_modtag) $@
> cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
>
> -$(obj)/%.o: $(src)/%.S FORCE
> +$(obj)/%.o: %.S FORCE
> $(call if_changed_dep,as_o_S)
>
> targets += $(real-objs-y) $(real-objs-m) $(lib-y)
> @@ -349,7 +355,7 @@ quiet_cmd_cpp_lds_S = LDS $@
> cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
> -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
>
> -$(obj)/%.lds: $(src)/%.lds.S FORCE
> +$(obj)/%.lds: %.lds.S FORCE
> $(call if_changed_dep,cpp_lds_S)
>
> # Build the compiled-in targets
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index aeea84a..b57b621 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -46,6 +46,13 @@ obj-m := $(filter-out %/, $(obj-m))
>
> subdir-ym := $(sort $(subdir-y) $(subdir-m))
>
> +#
> +vpath-ym := $(vpath-y) $(vpath-m)
> +VPATH := $(KBUILD_VPATH)
> +VPATH += $(srctree)/$(src)
> +VPATH += $(obj)
> +VPATH += $(vpath-ym)
> +
> # if $(foo-objs) exists, foo.o is a composite object
> multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
> multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
> @@ -167,7 +174,7 @@ ifdef REGENERATE_PARSERS
> quiet_cmd_gperf = GPERF $@
> cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
>
> -$(src)/%.hash.c_shipped: $(src)/%.gperf
> +$(src)/%.hash.c_shipped: %.gperf
> $(call cmd,gperf)
>
> # LEX
> @@ -177,7 +184,7 @@ LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
> quiet_cmd_flex = LEX $@
> cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
>
> -$(src)/%.lex.c_shipped: $(src)/%.l
> +$(src)/%.lex.c_shipped: %.l
> $(call cmd,flex)
>
> # YACC
> @@ -187,13 +194,13 @@ YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
> quiet_cmd_bison = YACC $@
> cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
>
> -$(src)/%.tab.c_shipped: $(src)/%.y
> +$(src)/%.tab.c_shipped: %.y
> $(call cmd,bison)
>
> quiet_cmd_bison_h = YACC $@
> cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
>
> -$(src)/%.tab.h_shipped: $(src)/%.y
> +$(src)/%.tab.h_shipped: %.y
> $(call cmd,bison_h)
>
> endif
> @@ -204,7 +211,7 @@ endif
> quiet_cmd_shipped = SHIPPED $@
> cmd_shipped = cat $< > $@
>
> -$(obj)/%: $(src)/%_shipped
> +$(obj)/%: %_shipped
> $(call cmd,shipped)
>
> # Commands useful for building a boot image
> --
> 1.7.6.153.g78432
>
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-08-30 0:31 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-08-30 0:31 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Fri, Aug 19, 2011 at 8:37 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
>
> Considering:
>
> arch/foo/lib:
> fancy.c
>
> We want to be able to build it with -DPANTS=32 in the kernel, but the
> bootloader requires -DPANTS_SIZE=30.
>
> Currently we would do, either:
>
> arch/foo/lib/Makefile
> LDFLAGS_fancy.o := -DPANTS=32
> obj-y += fancy.o
>
> and, either:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> ? ? ? ?$(call cmd,shipped)
>
> or
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> ? ? ? ?$(call cmd,cc_c_o)
>
> The former implies an extra copy of the source file, the latter expose Kbuild
> internal function.
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
>
Nicolas, I guess you were the one who was interested for a generic way
to do such code re-use, did you had any chance to test the quoted
patch ?
Thanks,
- Arnaud
> Comments welcome,
> ?- Arnaud
>
> Cc: linux-kernel at vger.kernel.org
> Cc: linux-arm-kernel at lists.infradead.org
>
> ---
> ?Makefile ? ? ? ? ? ? ? | ? ?5 +++--
> ?scripts/Makefile.build | ? 24 +++++++++++++++---------
> ?scripts/Makefile.lib ? | ? 17 ++++++++++++-----
> ?3 files changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index b4ca4e1..db7f7f5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -154,9 +154,10 @@ objtree ? ? ? ? ? ?:= $(CURDIR)
> ?src ? ? ? ? ? ?:= $(srctree)
> ?obj ? ? ? ? ? ?:= $(objtree)
>
> -VPATH ? ? ? ? ?:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
> +KBUILD_VPATH ? := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
> +VPATH ? ? ? ? ?:= $(KBUILD_VPATH)
>
> -export srctree objtree VPATH
> +export srctree objtree KBUILD_VPATH
>
>
> ?# SUBARCH tells the usermode build what the underlying arch is. ?That is set
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index a0fd502..ac539d7 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -18,6 +18,8 @@ always :=
> ?targets :=
> ?subdir-y :=
> ?subdir-m :=
> +vpath-y :=
> +vpath-m :=
> ?EXTRA_AFLAGS ? :=
> ?EXTRA_CFLAGS ? :=
> ?EXTRA_CPPFLAGS :=
> @@ -37,6 +39,7 @@ include scripts/Kbuild.include
>
> ?# For backward compatibility check that these variables do not change
> ?save-cflags := $(CFLAGS)
> +save-vpath := $(VPATH)
>
> ?# The filename Kbuild has precedence over Makefile
> ?kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
> @@ -48,6 +51,9 @@ ifeq ($(KBUILD_NOPEDANTIC),)
> ? ? ? ? ifneq ("$(save-cflags)","$(CFLAGS)")
> ? ? ? ? ? ? ? ? $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS)
> ? ? ? ? endif
> + ? ? ? ?ifneq ("$(save-vpath)","$(VPATH)")
> + ? ? ? ? ? ? ? ?$(error VPATH was changed in "$(kbuild-file)". Please uses vpath-y)
> + ? ? ? ?endif
> ?endif
>
> ?#
> @@ -198,13 +204,13 @@ $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
> ?quiet_cmd_cc_s_c = CC $(quiet_modtag) ?$@
> ?cmd_cc_s_c ? ? ? = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
>
> -$(obj)/%.s: $(src)/%.c FORCE
> +$(obj)/%.s: %.c FORCE
> ? ? ? ?$(call if_changed_dep,cc_s_c)
>
> ?quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
> ?cmd_cc_i_c ? ? ? = $(CPP) $(c_flags) ? -o $@ $<
>
> -$(obj)/%.i: $(src)/%.c FORCE
> +$(obj)/%.i: %.c FORCE
> ? ? ? ?$(call if_changed_dep,cc_i_c)
>
> ?cmd_gensymtypes = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> @@ -219,7 +225,7 @@ cmd_cc_symtypes_c = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> ? ? $(call cmd_gensymtypes,true,$@) >/dev/null; ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> ? ? test -s $@ || rm -f $@
>
> -$(obj)/%.symtypes : $(src)/%.c FORCE
> +$(obj)/%.symtypes : %.c FORCE
> ? ? ? ?$(call cmd,cc_symtypes_c)
>
> ?# C (.c) files
> @@ -301,13 +307,13 @@ define rule_cc_o_c
> ?endef
>
> ?# Built-in and composite module parts
> -$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
> +$(obj)/%.o: %.c $(recordmcount_source) FORCE
> ? ? ? ?$(call cmd,force_checksrc)
> ? ? ? ?$(call if_changed_rule,cc_o_c)
>
> ?# Single-part modules are special since we need to mark them in $(MODVERDIR)
>
> -$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
> +$(single-used-m): %.o: %.c $(recordmcount_source) FORCE
> ? ? ? ?$(call cmd,force_checksrc)
> ? ? ? ?$(call if_changed_rule,cc_o_c)
> ? ? ? ?@{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
> @@ -317,7 +323,7 @@ quiet_cmd_cc_lst_c = MKLST ? $@
> ? ? ? ? ? ? ? ? ? ? $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.map $(OBJDUMP) > $@
>
> -$(obj)/%.lst: $(src)/%.c FORCE
> +$(obj)/%.lst: %.c FORCE
> ? ? ? ?$(call if_changed_dep,cc_lst_c)
>
> ?# Compile assembler sources (.S)
> @@ -331,13 +337,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
> ?quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
> ?cmd_as_s_S ? ? ? = $(CPP) $(a_flags) ? -o $@ $<
>
> -$(obj)/%.s: $(src)/%.S FORCE
> +$(obj)/%.s: %.S FORCE
> ? ? ? ?$(call if_changed_dep,as_s_S)
>
> ?quiet_cmd_as_o_S = AS $(quiet_modtag) ?$@
> ?cmd_as_o_S ? ? ? = $(CC) $(a_flags) -c -o $@ $<
>
> -$(obj)/%.o: $(src)/%.S FORCE
> +$(obj)/%.o: %.S FORCE
> ? ? ? ?$(call if_changed_dep,as_o_S)
>
> ?targets += $(real-objs-y) $(real-objs-m) $(lib-y)
> @@ -349,7 +355,7 @@ quiet_cmd_cpp_lds_S = LDS ? ? $@
> ? ? ? cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
>
> -$(obj)/%.lds: $(src)/%.lds.S FORCE
> +$(obj)/%.lds: %.lds.S FORCE
> ? ? ? ?$(call if_changed_dep,cpp_lds_S)
>
> ?# Build the compiled-in targets
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index aeea84a..b57b621 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -46,6 +46,13 @@ obj-m ? ? ? ? ? ? ? ?:= $(filter-out %/, $(obj-m))
>
> ?subdir-ym ? ? ?:= $(sort $(subdir-y) $(subdir-m))
>
> +#
> +vpath-ym ? ? ? := $(vpath-y) $(vpath-m)
> +VPATH ? ? ? ? ?:= $(KBUILD_VPATH)
> +VPATH ? ? ? ? ?+= $(srctree)/$(src)
> +VPATH ? ? ? ? ?+= $(obj)
> +VPATH ? ? ? ? ?+= $(vpath-ym)
> +
> ?# if $(foo-objs) exists, foo.o is a composite object
> ?multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
> ?multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
> @@ -167,7 +174,7 @@ ifdef REGENERATE_PARSERS
> ?quiet_cmd_gperf = GPERF $@
> ? ? ? cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
>
> -$(src)/%.hash.c_shipped: $(src)/%.gperf
> +$(src)/%.hash.c_shipped: %.gperf
> ? ? ? ?$(call cmd,gperf)
>
> ?# LEX
> @@ -177,7 +184,7 @@ LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
> ?quiet_cmd_flex = LEX ? ? $@
> ? ? ? cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
>
> -$(src)/%.lex.c_shipped: $(src)/%.l
> +$(src)/%.lex.c_shipped: %.l
> ? ? ? ?$(call cmd,flex)
>
> ?# YACC
> @@ -187,13 +194,13 @@ YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
> ?quiet_cmd_bison = YACC ? ?$@
> ? ? ? cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
>
> -$(src)/%.tab.c_shipped: $(src)/%.y
> +$(src)/%.tab.c_shipped: %.y
> ? ? ? ?$(call cmd,bison)
>
> ?quiet_cmd_bison_h = YACC ? ?$@
> ? ? ? cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
>
> -$(src)/%.tab.h_shipped: $(src)/%.y
> +$(src)/%.tab.h_shipped: %.y
> ? ? ? ?$(call cmd,bison_h)
>
> ?endif
> @@ -204,7 +211,7 @@ endif
> ?quiet_cmd_shipped = SHIPPED $@
> ?cmd_shipped = cat $< > $@
>
> -$(obj)/%: $(src)/%_shipped
> +$(obj)/%: %_shipped
> ? ? ? ?$(call cmd,shipped)
>
> ?# Commands useful for building a boot image
> --
> 1.7.6.153.g78432
>
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-08-30 0:31 ` Arnaud Lacombe
@ 2011-08-30 4:32 ` Nicolas Pitre
-1 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-08-30 4:32 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: linux-kbuild, lkml, linux-arm-kernel
On Mon, 29 Aug 2011, Arnaud Lacombe wrote:
> On Fri, Aug 19, 2011 at 8:37 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> > With the attached patch, we would do:
> >
> > arch/foo/boot/Makefile:
> > LDFLAGS_fancy.o := -DPANTS=30
> > obj-y += fancy.o
> > vpath-y += $(srctree)/arch/foo/lib
> >
> > and let GNU make do the job.
> >
> Nicolas, I guess you were the one who was interested for a generic way
> to do such code re-use, did you had any chance to test the quoted
> patch ?
I actually missed the original post (I wasn't in CC) so I didn't test it.
Will try to do so ASAP.
Nicolas
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-08-30 4:32 ` Nicolas Pitre
0 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-08-30 4:32 UTC (permalink / raw)
To: linux-arm-kernel
On Mon, 29 Aug 2011, Arnaud Lacombe wrote:
> On Fri, Aug 19, 2011 at 8:37 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> > With the attached patch, we would do:
> >
> > arch/foo/boot/Makefile:
> > LDFLAGS_fancy.o := -DPANTS=30
> > obj-y += fancy.o
> > vpath-y += $(srctree)/arch/foo/lib
> >
> > and let GNU make do the job.
> >
> Nicolas, I guess you were the one who was interested for a generic way
> to do such code re-use, did you had any chance to test the quoted
> patch ?
I actually missed the original post (I wasn't in CC) so I didn't test it.
Will try to do so ASAP.
Nicolas
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-08-30 4:32 ` Nicolas Pitre
@ 2011-08-30 4:36 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-08-30 4:36 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: linux-kbuild, lkml, linux-arm-kernel
Hi,
On Tue, Aug 30, 2011 at 12:32 AM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Mon, 29 Aug 2011, Arnaud Lacombe wrote:
>
>> On Fri, Aug 19, 2011 at 8:37 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
>> > With the attached patch, we would do:
>> >
>> > arch/foo/boot/Makefile:
>> > LDFLAGS_fancy.o := -DPANTS=30
>> > obj-y += fancy.o
>> > vpath-y += $(srctree)/arch/foo/lib
>> >
>> > and let GNU make do the job.
>> >
>> Nicolas, I guess you were the one who was interested for a generic way
>> to do such code re-use, did you had any chance to test the quoted
>> patch ?
>
> I actually missed the original post (I wasn't in CC) so I didn't test it.
> Will try to do so ASAP.
>
Sorry for the miss, I thought linux-arm-kernel@ would catch enough people :)
- Arnaud
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-08-30 4:36 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-08-30 4:36 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Tue, Aug 30, 2011 at 12:32 AM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Mon, 29 Aug 2011, Arnaud Lacombe wrote:
>
>> On Fri, Aug 19, 2011 at 8:37 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
>> > With the attached patch, we would do:
>> >
>> > arch/foo/boot/Makefile:
>> > LDFLAGS_fancy.o := -DPANTS=30
>> > obj-y += fancy.o
>> > vpath-y += $(srctree)/arch/foo/lib
>> >
>> > and let GNU make do the job.
>> >
>> Nicolas, I guess you were the one who was interested for a generic way
>> to do such code re-use, did you had any chance to test the quoted
>> patch ?
>
> I actually missed the original post (I wasn't in CC) so I didn't test it.
> Will try to do so ASAP.
>
Sorry for the miss, I thought linux-arm-kernel@ would catch enough people :)
- Arnaud
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-08-20 0:37 ` Arnaud Lacombe
@ 2011-09-07 19:07 ` Nicolas Pitre
-1 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-09-07 19:07 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: linux-kbuild, linux-arm-kernel, lkml
On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
>
> Considering:
>
> arch/foo/lib:
> fancy.c
>
> We want to be able to build it with -DPANTS=32 in the kernel, but the
> bootloader requires -DPANTS_SIZE=30.
>
> Currently we would do, either:
>
> arch/foo/lib/Makefile
> LDFLAGS_fancy.o := -DPANTS=32
> obj-y += fancy.o
>
> and, either:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,shipped)
>
> or
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,cc_c_o)
>
> The former implies an extra copy of the source file, the latter expose Kbuild
> internal function.
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
>
> Comments welcome,
It doesn't work. Whatever I do to arch/arm/boot/compressed/Makefile
(which admittedly looks a bit hairy and could benefit from a shave) in
order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
end up with:
make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. Stop.
Obviously, restoring the explicit dependency with a $(call cmd,as_o_S)
does make it work, but this is rather against the point of your patch.
Do you have an example of how arch/arm/boot/compressed/Makefile should
be changed to benefit from your patch?
Nicolas
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-07 19:07 ` Nicolas Pitre
0 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-09-07 19:07 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
>
> Considering:
>
> arch/foo/lib:
> fancy.c
>
> We want to be able to build it with -DPANTS=32 in the kernel, but the
> bootloader requires -DPANTS_SIZE=30.
>
> Currently we would do, either:
>
> arch/foo/lib/Makefile
> LDFLAGS_fancy.o := -DPANTS=32
> obj-y += fancy.o
>
> and, either:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,shipped)
>
> or
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,cc_c_o)
>
> The former implies an extra copy of the source file, the latter expose Kbuild
> internal function.
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
>
> Comments welcome,
It doesn't work. Whatever I do to arch/arm/boot/compressed/Makefile
(which admittedly looks a bit hairy and could benefit from a shave) in
order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
end up with:
make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. Stop.
Obviously, restoring the explicit dependency with a $(call cmd,as_o_S)
does make it work, but this is rather against the point of your patch.
Do you have an example of how arch/arm/boot/compressed/Makefile should
be changed to benefit from your patch?
Nicolas
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-07 19:07 ` Nicolas Pitre
@ 2011-09-07 19:34 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-07 19:34 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: linux-kbuild, linux-arm-kernel, lkml
Hi,
On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
>
>> Hi folks,
>>
>> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> directory without having to go through a copy. Technically, it changes Kbuild to
>> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> to change it indirectly.
>>
>> Considering:
>>
>> arch/foo/lib:
>> fancy.c
>>
>> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> bootloader requires -DPANTS_SIZE=30.
>>
>> Currently we would do, either:
>>
>> arch/foo/lib/Makefile
>> LDFLAGS_fancy.o := -DPANTS=32
>> obj-y += fancy.o
>>
>> and, either:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> $(call cmd,shipped)
>>
>> or
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> $(call cmd,cc_c_o)
>>
>> The former implies an extra copy of the source file, the latter expose Kbuild
>> internal function.
>>
>> With the attached patch, we would do:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> vpath-y += $(srctree)/arch/foo/lib
>>
>> and let GNU make do the job.
>>
>> Comments welcome,
>
> It doesn't work. Whatever I do to arch/arm/boot/compressed/Makefile
> (which admittedly looks a bit hairy and could benefit from a shave) in
> order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
> end up with:
>
> make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. Stop.
>
What was the exact change you made which triggered this ?
Thanks,
- Arnaud
> Obviously, restoring the explicit dependency with a $(call cmd,as_o_S)
> does make it work, but this is rather against the point of your patch.
>
> Do you have an example of how arch/arm/boot/compressed/Makefile should
> be changed to benefit from your patch?
>
>
> Nicolas
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-07 19:34 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-07 19:34 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
>
>> Hi folks,
>>
>> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> directory without having to go through a copy. Technically, it changes Kbuild to
>> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> to change it indirectly.
>>
>> Considering:
>>
>> arch/foo/lib:
>> fancy.c
>>
>> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> bootloader requires -DPANTS_SIZE=30.
>>
>> Currently we would do, either:
>>
>> arch/foo/lib/Makefile
>> LDFLAGS_fancy.o := -DPANTS=32
>> obj-y += fancy.o
>>
>> and, either:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> ? ? ? $(call cmd,shipped)
>>
>> or
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> ? ? ? $(call cmd,cc_c_o)
>>
>> The former implies an extra copy of the source file, the latter expose Kbuild
>> internal function.
>>
>> With the attached patch, we would do:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> vpath-y += $(srctree)/arch/foo/lib
>>
>> and let GNU make do the job.
>>
>> Comments welcome,
>
> It doesn't work. ?Whatever I do to arch/arm/boot/compressed/Makefile
> (which admittedly looks a bit hairy and could benefit from a shave) in
> order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
> end up with:
>
> make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. ?Stop.
>
What was the exact change you made which triggered this ?
Thanks,
- Arnaud
> Obviously, restoring the explicit dependency with a $(call cmd,as_o_S)
> does make it work, but this is rather against the point of your patch.
>
> Do you have an example of how arch/arm/boot/compressed/Makefile should
> be changed to benefit from your patch?
>
>
> Nicolas
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-07 19:34 ` Arnaud Lacombe
@ 2011-09-07 19:59 ` Nicolas Pitre
-1 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-09-07 19:59 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: linux-kbuild, linux-arm-kernel, lkml
[-- Attachment #1: Type: TEXT/PLAIN, Size: 3060 bytes --]
On Wed, 7 Sep 2011, Arnaud Lacombe wrote:
> Hi,
>
> On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> > On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
> >
> >> Hi folks,
> >>
> >> The attached patch modify Kbuild to allow to directly re-use code in multiple
> >> directory without having to go through a copy. Technically, it changes Kbuild to
> >> use by default the VPATH feature of GNU make and provides accessors for Makefile
> >> to change it indirectly.
> >>
> >> Considering:
> >>
> >> arch/foo/lib:
> >> fancy.c
> >>
> >> We want to be able to build it with -DPANTS=32 in the kernel, but the
> >> bootloader requires -DPANTS_SIZE=30.
> >>
> >> Currently we would do, either:
> >>
> >> arch/foo/lib/Makefile
> >> LDFLAGS_fancy.o := -DPANTS=32
> >> obj-y += fancy.o
> >>
> >> and, either:
> >>
> >> arch/foo/boot/Makefile:
> >> LDFLAGS_fancy.o := -DPANTS=30
> >> obj-y += fancy.o
> >> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> >> $(call cmd,shipped)
> >>
> >> or
> >>
> >> arch/foo/boot/Makefile:
> >> LDFLAGS_fancy.o := -DPANTS=30
> >> obj-y += fancy.o
> >> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> >> $(call cmd,cc_c_o)
> >>
> >> The former implies an extra copy of the source file, the latter expose Kbuild
> >> internal function.
> >>
> >> With the attached patch, we would do:
> >>
> >> arch/foo/boot/Makefile:
> >> LDFLAGS_fancy.o := -DPANTS=30
> >> obj-y += fancy.o
> >> vpath-y += $(srctree)/arch/foo/lib
> >>
> >> and let GNU make do the job.
> >>
> >> Comments welcome,
> >
> > It doesn't work. Whatever I do to arch/arm/boot/compressed/Makefile
> > (which admittedly looks a bit hairy and could benefit from a shave) in
> > order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
> > end up with:
> >
> > make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. Stop.
> >
> What was the exact change you made which triggered this ?
In its simplest expression (not caring about the now undefined lib1funcs
variable):
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 0c74a6fab9..b34ed80977 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -70,6 +70,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
OBJS += head-shmobile.o
endif
+# For __aeabi_uidivmod
+OBJS += lib1funcs.o
+vpath-y += $(srctree)/arch/arm/lib
+
#
# We now have a PIC decompressor implementation. Decompressors running
# from RAM should not define ZTEXTADDR. Decompressors running directly
@@ -120,12 +124,6 @@ LDFLAGS_vmlinux += -X
# Next argument is a linker script
LDFLAGS_vmlinux += -T
-# For __aeabi_uidivmod
-lib1funcs = $(obj)/lib1funcs.o
-
-$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
- $(call cmd,shipped)
-
# We need to prevent any GOTOFF relocs being used with references
# to symbols in the .bss section since we cannot relocate them
# independently from the rest at run time. This can be achieved by
Nicolas
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-07 19:59 ` Nicolas Pitre
0 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-09-07 19:59 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, 7 Sep 2011, Arnaud Lacombe wrote:
> Hi,
>
> On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> > On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
> >
> >> Hi folks,
> >>
> >> The attached patch modify Kbuild to allow to directly re-use code in multiple
> >> directory without having to go through a copy. Technically, it changes Kbuild to
> >> use by default the VPATH feature of GNU make and provides accessors for Makefile
> >> to change it indirectly.
> >>
> >> Considering:
> >>
> >> arch/foo/lib:
> >> fancy.c
> >>
> >> We want to be able to build it with -DPANTS=32 in the kernel, but the
> >> bootloader requires -DPANTS_SIZE=30.
> >>
> >> Currently we would do, either:
> >>
> >> arch/foo/lib/Makefile
> >> LDFLAGS_fancy.o := -DPANTS=32
> >> obj-y += fancy.o
> >>
> >> and, either:
> >>
> >> arch/foo/boot/Makefile:
> >> LDFLAGS_fancy.o := -DPANTS=30
> >> obj-y += fancy.o
> >> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> >> ? ? ? $(call cmd,shipped)
> >>
> >> or
> >>
> >> arch/foo/boot/Makefile:
> >> LDFLAGS_fancy.o := -DPANTS=30
> >> obj-y += fancy.o
> >> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> >> ? ? ? $(call cmd,cc_c_o)
> >>
> >> The former implies an extra copy of the source file, the latter expose Kbuild
> >> internal function.
> >>
> >> With the attached patch, we would do:
> >>
> >> arch/foo/boot/Makefile:
> >> LDFLAGS_fancy.o := -DPANTS=30
> >> obj-y += fancy.o
> >> vpath-y += $(srctree)/arch/foo/lib
> >>
> >> and let GNU make do the job.
> >>
> >> Comments welcome,
> >
> > It doesn't work. ?Whatever I do to arch/arm/boot/compressed/Makefile
> > (which admittedly looks a bit hairy and could benefit from a shave) in
> > order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
> > end up with:
> >
> > make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. ?Stop.
> >
> What was the exact change you made which triggered this ?
In its simplest expression (not caring about the now undefined lib1funcs
variable):
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 0c74a6fab9..b34ed80977 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -70,6 +70,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
OBJS += head-shmobile.o
endif
+# For __aeabi_uidivmod
+OBJS += lib1funcs.o
+vpath-y += $(srctree)/arch/arm/lib
+
#
# We now have a PIC decompressor implementation. Decompressors running
# from RAM should not define ZTEXTADDR. Decompressors running directly
@@ -120,12 +124,6 @@ LDFLAGS_vmlinux += -X
# Next argument is a linker script
LDFLAGS_vmlinux += -T
-# For __aeabi_uidivmod
-lib1funcs = $(obj)/lib1funcs.o
-
-$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
- $(call cmd,shipped)
-
# We need to prevent any GOTOFF relocs being used with references
# to symbols in the .bss section since we cannot relocate them
# independently from the rest at run time. This can be achieved by
Nicolas
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-07 19:59 ` Nicolas Pitre
@ 2011-09-07 20:52 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-07 20:52 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: linux-kbuild, linux-arm-kernel, lkml
Hi,
On Wed, Sep 7, 2011 at 3:59 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Wed, 7 Sep 2011, Arnaud Lacombe wrote:
>
>> Hi,
>>
>> On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>> > On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
>> >
>> >> Hi folks,
>> >>
>> >> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> >> directory without having to go through a copy. Technically, it changes Kbuild to
>> >> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> >> to change it indirectly.
>> >>
>> >> Considering:
>> >>
>> >> arch/foo/lib:
>> >> fancy.c
>> >>
>> >> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> >> bootloader requires -DPANTS_SIZE=30.
>> >>
>> >> Currently we would do, either:
>> >>
>> >> arch/foo/lib/Makefile
>> >> LDFLAGS_fancy.o := -DPANTS=32
>> >> obj-y += fancy.o
>> >>
>> >> and, either:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> >> $(call cmd,shipped)
>> >>
>> >> or
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> >> $(call cmd,cc_c_o)
>> >>
>> >> The former implies an extra copy of the source file, the latter expose Kbuild
>> >> internal function.
>> >>
>> >> With the attached patch, we would do:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> vpath-y += $(srctree)/arch/foo/lib
>> >>
>> >> and let GNU make do the job.
>> >>
>> >> Comments welcome,
>> >
>> > It doesn't work. Whatever I do to arch/arm/boot/compressed/Makefile
>> > (which admittedly looks a bit hairy and could benefit from a shave) in
>> > order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
>> > end up with:
>> >
>> > make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. Stop.
>> >
>> What was the exact change you made which triggered this ?
>
> In its simplest expression (not caring about the now undefined lib1funcs
> variable):
>
> diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
> index 0c74a6fab9..b34ed80977 100644
> --- a/arch/arm/boot/compressed/Makefile
> +++ b/arch/arm/boot/compressed/Makefile
> @@ -70,6 +70,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
> OBJS += head-shmobile.o
> endif
>
> +# For __aeabi_uidivmod
> +OBJS += lib1funcs.o
> +vpath-y += $(srctree)/arch/arm/lib
> +
> #
> # We now have a PIC decompressor implementation. Decompressors running
> # from RAM should not define ZTEXTADDR. Decompressors running directly
> @@ -120,12 +124,6 @@ LDFLAGS_vmlinux += -X
> # Next argument is a linker script
> LDFLAGS_vmlinux += -T
>
> -# For __aeabi_uidivmod
> -lib1funcs = $(obj)/lib1funcs.o
> -
> -$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
> - $(call cmd,shipped)
> -
> # We need to prevent any GOTOFF relocs being used with references
> # to symbols in the .bss section since we cannot relocate them
> # independently from the rest at run time. This can be achieved by
>
that look correct to me, however, the error you get:
make[2]: *** No rule to make target
`arch/arm/boot/compressed/lib1funcs.S', needed by
`arch/arm/boot/compressed/lib1funcs.o'. Stop.
seem odd to me.
I just re-tried on x86 with:
diff --git a/arch/x86/boot/compressed/Makefile
b/arch/x86/boot/compressed/Makefile
index 09664ef..65c89f7 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -23,7 +23,9 @@ LDFLAGS_vmlinux := -T
hostprogs-y := mkpiggy
-$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head_$(BITS).o
$(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o
$(obj)/early_serial_console.o $(obj)/piggy.o FORCE
+vpath-y += $(srctree)/arch/x86/lib
+
+$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/checksum_32.o
$(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o
$(obj)/early_serial_console.o $(obj)/piggy.o FORCE
$(call if_changed,ld)
@:
and `checksum_32.o' gets built just fine from
`$(srctree)/arch/x86/lib/checksum_32.S'. I guess I'll ends up building
an arm toolchain tonight and see closer.
- Arnaud
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-07 20:52 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-07 20:52 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Wed, Sep 7, 2011 at 3:59 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Wed, 7 Sep 2011, Arnaud Lacombe wrote:
>
>> Hi,
>>
>> On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>> > On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
>> >
>> >> Hi folks,
>> >>
>> >> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> >> directory without having to go through a copy. Technically, it changes Kbuild to
>> >> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> >> to change it indirectly.
>> >>
>> >> Considering:
>> >>
>> >> arch/foo/lib:
>> >> fancy.c
>> >>
>> >> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> >> bootloader requires -DPANTS_SIZE=30.
>> >>
>> >> Currently we would do, either:
>> >>
>> >> arch/foo/lib/Makefile
>> >> LDFLAGS_fancy.o := -DPANTS=32
>> >> obj-y += fancy.o
>> >>
>> >> and, either:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> >> ? ? ? $(call cmd,shipped)
>> >>
>> >> or
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> >> ? ? ? $(call cmd,cc_c_o)
>> >>
>> >> The former implies an extra copy of the source file, the latter expose Kbuild
>> >> internal function.
>> >>
>> >> With the attached patch, we would do:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> vpath-y += $(srctree)/arch/foo/lib
>> >>
>> >> and let GNU make do the job.
>> >>
>> >> Comments welcome,
>> >
>> > It doesn't work. ?Whatever I do to arch/arm/boot/compressed/Makefile
>> > (which admittedly looks a bit hairy and could benefit from a shave) in
>> > order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
>> > end up with:
>> >
>> > make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. ?Stop.
>> >
>> What was the exact change you made which triggered this ?
>
> In its simplest expression (not caring about the now undefined lib1funcs
> variable):
>
> diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
> index 0c74a6fab9..b34ed80977 100644
> --- a/arch/arm/boot/compressed/Makefile
> +++ b/arch/arm/boot/compressed/Makefile
> @@ -70,6 +70,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
> ?OBJS ? ? ? ? ? += head-shmobile.o
> ?endif
>
> +# For __aeabi_uidivmod
> +OBJS ? ? ? ? ? += lib1funcs.o
> +vpath-y ? ? ? ? ? ? ? ?+= $(srctree)/arch/arm/lib
> +
> ?#
> ?# We now have a PIC decompressor implementation. ?Decompressors running
> ?# from RAM should not define ZTEXTADDR. ?Decompressors running directly
> @@ -120,12 +124,6 @@ LDFLAGS_vmlinux += -X
> ?# Next argument is a linker script
> ?LDFLAGS_vmlinux += -T
>
> -# For __aeabi_uidivmod
> -lib1funcs = $(obj)/lib1funcs.o
> -
> -$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
> - ? ? ? $(call cmd,shipped)
> -
> ?# We need to prevent any GOTOFF relocs being used with references
> ?# to symbols in the .bss section since we cannot relocate them
> ?# independently from the rest at run time. ?This can be achieved by
>
that look correct to me, however, the error you get:
make[2]: *** No rule to make target
`arch/arm/boot/compressed/lib1funcs.S', needed by
`arch/arm/boot/compressed/lib1funcs.o'. Stop.
seem odd to me.
I just re-tried on x86 with:
diff --git a/arch/x86/boot/compressed/Makefile
b/arch/x86/boot/compressed/Makefile
index 09664ef..65c89f7 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -23,7 +23,9 @@ LDFLAGS_vmlinux := -T
hostprogs-y := mkpiggy
-$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head_$(BITS).o
$(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o
$(obj)/early_serial_console.o $(obj)/piggy.o FORCE
+vpath-y += $(srctree)/arch/x86/lib
+
+$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/checksum_32.o
$(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/string.o $(obj)/cmdline.o
$(obj)/early_serial_console.o $(obj)/piggy.o FORCE
$(call if_changed,ld)
@:
and `checksum_32.o' gets built just fine from
`$(srctree)/arch/x86/lib/checksum_32.S'. I guess I'll ends up building
an arm toolchain tonight and see closer.
- Arnaud
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-07 19:59 ` Nicolas Pitre
@ 2011-09-08 4:50 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-08 4:50 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: linux-kbuild, linux-arm-kernel, lkml
Hi,
On Wed, Sep 7, 2011 at 3:59 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Wed, 7 Sep 2011, Arnaud Lacombe wrote:
>
>> Hi,
>>
>> On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>> > On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
>> >
>> >> Hi folks,
>> >>
>> >> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> >> directory without having to go through a copy. Technically, it changes Kbuild to
>> >> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> >> to change it indirectly.
>> >>
>> >> Considering:
>> >>
>> >> arch/foo/lib:
>> >> fancy.c
>> >>
>> >> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> >> bootloader requires -DPANTS_SIZE=30.
>> >>
>> >> Currently we would do, either:
>> >>
>> >> arch/foo/lib/Makefile
>> >> LDFLAGS_fancy.o := -DPANTS=32
>> >> obj-y += fancy.o
>> >>
>> >> and, either:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> >> $(call cmd,shipped)
>> >>
>> >> or
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> >> $(call cmd,cc_c_o)
>> >>
>> >> The former implies an extra copy of the source file, the latter expose Kbuild
>> >> internal function.
>> >>
>> >> With the attached patch, we would do:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> vpath-y += $(srctree)/arch/foo/lib
>> >>
>> >> and let GNU make do the job.
>> >>
>> >> Comments welcome,
>> >
>> > It doesn't work. Whatever I do to arch/arm/boot/compressed/Makefile
>> > (which admittedly looks a bit hairy and could benefit from a shave) in
>> > order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
>> > end up with:
>> >
>> > make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. Stop.
>> >
>> What was the exact change you made which triggered this ?
>
> In its simplest expression (not caring about the now undefined lib1funcs
> variable):
>
> diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
> index 0c74a6fab9..b34ed80977 100644
> --- a/arch/arm/boot/compressed/Makefile
> +++ b/arch/arm/boot/compressed/Makefile
> @@ -70,6 +70,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
> OBJS += head-shmobile.o
> endif
>
> +# For __aeabi_uidivmod
> +OBJS += lib1funcs.o
> +vpath-y += $(srctree)/arch/arm/lib
> +
> #
> # We now have a PIC decompressor implementation. Decompressors running
> # from RAM should not define ZTEXTADDR. Decompressors running directly
> @@ -120,12 +124,6 @@ LDFLAGS_vmlinux += -X
> # Next argument is a linker script
> LDFLAGS_vmlinux += -T
>
> -# For __aeabi_uidivmod
> -lib1funcs = $(obj)/lib1funcs.o
> -
> -$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
> - $(call cmd,shipped)
> -
> # We need to prevent any GOTOFF relocs being used with references
> # to symbols in the .bss section since we cannot relocate them
> # independently from the rest at run time. This can be achieved by
>
you missed:
# Make sure files are removed during clean
-extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
+extra-y += piggy.gzip piggy.lzo piggy.lzma
This confused make.
before:
% rm -rf /linux/obj/vpath-arm/arch/arm/boot/compressed/
% make ARCH=arm V=2 \
CROSS_COMPILE=arm-none-linux-gnueabi- \
O=/linux/obj/vpath-arm
[...]
CC arch/arm/boot/compressed/decompress.o - due to target missing
make[3]: *** No rule to make target
`arch/arm/boot/compressed/lib1funcs.S', needed by
`arch/arm/boot/compressed/lib1funcs.o'. Stop.
make[2]: *** [arch/arm/boot/compressed/vmlinux] Error 2
make[1]: *** [zImage] Error 2
make: *** [sub-make] Error 2
after:
% rm -rf /linux/obj/vpath-arm/arch/arm/boot/compressed/
% make ARCH=arm V=2 \
CROSS_COMPILE=arm-none-linux-gnueabi- \
O=/linux/obj/vpath-arm
[...]
CC arch/arm/boot/compressed/decompress.o - due to target missing
AS arch/arm/boot/compressed/lib1funcs.o - due to target missing
LD arch/arm/boot/compressed/vmlinux - due to target missing
OBJCOPY arch/arm/boot/zImage - due to: arch/arm/boot/compressed/vmlinux
Kernel: arch/arm/boot/zImage is ready
Building modules, stage 2.
MODPOST 33 modules - due to target is PHONY
- Arnaud
>
> Nicolas
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-08 4:50 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-08 4:50 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Wed, Sep 7, 2011 at 3:59 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Wed, 7 Sep 2011, Arnaud Lacombe wrote:
>
>> Hi,
>>
>> On Wed, Sep 7, 2011 at 3:07 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>> > On Fri, 19 Aug 2011, Arnaud Lacombe wrote:
>> >
>> >> Hi folks,
>> >>
>> >> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> >> directory without having to go through a copy. Technically, it changes Kbuild to
>> >> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> >> to change it indirectly.
>> >>
>> >> Considering:
>> >>
>> >> arch/foo/lib:
>> >> fancy.c
>> >>
>> >> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> >> bootloader requires -DPANTS_SIZE=30.
>> >>
>> >> Currently we would do, either:
>> >>
>> >> arch/foo/lib/Makefile
>> >> LDFLAGS_fancy.o := -DPANTS=32
>> >> obj-y += fancy.o
>> >>
>> >> and, either:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> >> ? ? ? $(call cmd,shipped)
>> >>
>> >> or
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> >> ? ? ? $(call cmd,cc_c_o)
>> >>
>> >> The former implies an extra copy of the source file, the latter expose Kbuild
>> >> internal function.
>> >>
>> >> With the attached patch, we would do:
>> >>
>> >> arch/foo/boot/Makefile:
>> >> LDFLAGS_fancy.o := -DPANTS=30
>> >> obj-y += fancy.o
>> >> vpath-y += $(srctree)/arch/foo/lib
>> >>
>> >> and let GNU make do the job.
>> >>
>> >> Comments welcome,
>> >
>> > It doesn't work. ?Whatever I do to arch/arm/boot/compressed/Makefile
>> > (which admittedly looks a bit hairy and could benefit from a shave) in
>> > order to remove the $(call cmd,shipped) used with lib1funcs.S, I always
>> > end up with:
>> >
>> > make[2]: *** No rule to make target `arch/arm/boot/compressed/lib1funcs.S', needed by `arch/arm/boot/compressed/lib1funcs.o'. ?Stop.
>> >
>> What was the exact change you made which triggered this ?
>
> In its simplest expression (not caring about the now undefined lib1funcs
> variable):
>
> diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
> index 0c74a6fab9..b34ed80977 100644
> --- a/arch/arm/boot/compressed/Makefile
> +++ b/arch/arm/boot/compressed/Makefile
> @@ -70,6 +70,10 @@ ifeq ($(CONFIG_ARCH_SHMOBILE),y)
> ?OBJS ? ? ? ? ? += head-shmobile.o
> ?endif
>
> +# For __aeabi_uidivmod
> +OBJS ? ? ? ? ? += lib1funcs.o
> +vpath-y ? ? ? ? ? ? ? ?+= $(srctree)/arch/arm/lib
> +
> ?#
> ?# We now have a PIC decompressor implementation. ?Decompressors running
> ?# from RAM should not define ZTEXTADDR. ?Decompressors running directly
> @@ -120,12 +124,6 @@ LDFLAGS_vmlinux += -X
> ?# Next argument is a linker script
> ?LDFLAGS_vmlinux += -T
>
> -# For __aeabi_uidivmod
> -lib1funcs = $(obj)/lib1funcs.o
> -
> -$(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
> - ? ? ? $(call cmd,shipped)
> -
> ?# We need to prevent any GOTOFF relocs being used with references
> ?# to symbols in the .bss section since we cannot relocate them
> ?# independently from the rest at run time. ?This can be achieved by
>
you missed:
# Make sure files are removed during clean
-extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
+extra-y += piggy.gzip piggy.lzo piggy.lzma
This confused make.
before:
% rm -rf /linux/obj/vpath-arm/arch/arm/boot/compressed/
% make ARCH=arm V=2 \
CROSS_COMPILE=arm-none-linux-gnueabi- \
O=/linux/obj/vpath-arm
[...]
CC arch/arm/boot/compressed/decompress.o - due to target missing
make[3]: *** No rule to make target
`arch/arm/boot/compressed/lib1funcs.S', needed by
`arch/arm/boot/compressed/lib1funcs.o'. Stop.
make[2]: *** [arch/arm/boot/compressed/vmlinux] Error 2
make[1]: *** [zImage] Error 2
make: *** [sub-make] Error 2
after:
% rm -rf /linux/obj/vpath-arm/arch/arm/boot/compressed/
% make ARCH=arm V=2 \
CROSS_COMPILE=arm-none-linux-gnueabi- \
O=/linux/obj/vpath-arm
[...]
CC arch/arm/boot/compressed/decompress.o - due to target missing
AS arch/arm/boot/compressed/lib1funcs.o - due to target missing
LD arch/arm/boot/compressed/vmlinux - due to target missing
OBJCOPY arch/arm/boot/zImage - due to: arch/arm/boot/compressed/vmlinux
Kernel: arch/arm/boot/zImage is ready
Building modules, stage 2.
MODPOST 33 modules - due to target is PHONY
- Arnaud
>
> Nicolas
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
2011-08-20 0:37 ` Arnaud Lacombe
` (3 preceding siblings ...)
(?)
@ 2011-09-08 18:24 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-08 18:24 UTC (permalink / raw)
To: linux-arm-kernel
Hi Michal,
On Fri, Aug 19, 2011 at 8:37 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
>
> Considering:
>
> arch/foo/lib:
> fancy.c
>
> We want to be able to build it with -DPANTS=32 in the kernel, but the
> bootloader requires -DPANTS_SIZE=30.
>
> Currently we would do, either:
>
> arch/foo/lib/Makefile
> LDFLAGS_fancy.o := -DPANTS=32
> obj-y += fancy.o
>
> and, either:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> ? ? ? ?$(call cmd,shipped)
>
> or
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> ? ? ? ?$(call cmd,cc_c_o)
>
> The former implies an extra copy of the source file, the latter expose Kbuild
> internal function.
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
>
> Comments welcome,
> ?- Arnaud
>
> Cc: linux-kernel at vger.kernel.org
> Cc: linux-arm-kernel at lists.infradead.org
>
can you tell me you're point of view on the aim of the patch, and the
patch itself ? It's no use anyone start using it if you ends up
NACK'ing it.
Thanks,
- Arnaud
> ---
> ?Makefile ? ? ? ? ? ? ? | ? ?5 +++--
> ?scripts/Makefile.build | ? 24 +++++++++++++++---------
> ?scripts/Makefile.lib ? | ? 17 ++++++++++++-----
> ?3 files changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index b4ca4e1..db7f7f5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -154,9 +154,10 @@ objtree ? ? ? ? ? ?:= $(CURDIR)
> ?src ? ? ? ? ? ?:= $(srctree)
> ?obj ? ? ? ? ? ?:= $(objtree)
>
> -VPATH ? ? ? ? ?:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
> +KBUILD_VPATH ? := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
> +VPATH ? ? ? ? ?:= $(KBUILD_VPATH)
>
> -export srctree objtree VPATH
> +export srctree objtree KBUILD_VPATH
>
>
> ?# SUBARCH tells the usermode build what the underlying arch is. ?That is set
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index a0fd502..ac539d7 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -18,6 +18,8 @@ always :=
> ?targets :=
> ?subdir-y :=
> ?subdir-m :=
> +vpath-y :=
> +vpath-m :=
> ?EXTRA_AFLAGS ? :=
> ?EXTRA_CFLAGS ? :=
> ?EXTRA_CPPFLAGS :=
> @@ -37,6 +39,7 @@ include scripts/Kbuild.include
>
> ?# For backward compatibility check that these variables do not change
> ?save-cflags := $(CFLAGS)
> +save-vpath := $(VPATH)
>
> ?# The filename Kbuild has precedence over Makefile
> ?kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
> @@ -48,6 +51,9 @@ ifeq ($(KBUILD_NOPEDANTIC),)
> ? ? ? ? ifneq ("$(save-cflags)","$(CFLAGS)")
> ? ? ? ? ? ? ? ? $(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS)
> ? ? ? ? endif
> + ? ? ? ?ifneq ("$(save-vpath)","$(VPATH)")
> + ? ? ? ? ? ? ? ?$(error VPATH was changed in "$(kbuild-file)". Please uses vpath-y)
> + ? ? ? ?endif
> ?endif
>
> ?#
> @@ -198,13 +204,13 @@ $(multi-objs-y:.o=.lst) : modname = $(modname-multi)
> ?quiet_cmd_cc_s_c = CC $(quiet_modtag) ?$@
> ?cmd_cc_s_c ? ? ? = $(CC) $(c_flags) -fverbose-asm -S -o $@ $<
>
> -$(obj)/%.s: $(src)/%.c FORCE
> +$(obj)/%.s: %.c FORCE
> ? ? ? ?$(call if_changed_dep,cc_s_c)
>
> ?quiet_cmd_cc_i_c = CPP $(quiet_modtag) $@
> ?cmd_cc_i_c ? ? ? = $(CPP) $(c_flags) ? -o $@ $<
>
> -$(obj)/%.i: $(src)/%.c FORCE
> +$(obj)/%.i: %.c FORCE
> ? ? ? ?$(call if_changed_dep,cc_i_c)
>
> ?cmd_gensymtypes = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> @@ -219,7 +225,7 @@ cmd_cc_symtypes_c = ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> ? ? $(call cmd_gensymtypes,true,$@) >/dev/null; ? ? ? ? ? ? ? ? ? ? ? ? ? ? \
> ? ? test -s $@ || rm -f $@
>
> -$(obj)/%.symtypes : $(src)/%.c FORCE
> +$(obj)/%.symtypes : %.c FORCE
> ? ? ? ?$(call cmd,cc_symtypes_c)
>
> ?# C (.c) files
> @@ -301,13 +307,13 @@ define rule_cc_o_c
> ?endef
>
> ?# Built-in and composite module parts
> -$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
> +$(obj)/%.o: %.c $(recordmcount_source) FORCE
> ? ? ? ?$(call cmd,force_checksrc)
> ? ? ? ?$(call if_changed_rule,cc_o_c)
>
> ?# Single-part modules are special since we need to mark them in $(MODVERDIR)
>
> -$(single-used-m): $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
> +$(single-used-m): %.o: %.c $(recordmcount_source) FORCE
> ? ? ? ?$(call cmd,force_checksrc)
> ? ? ? ?$(call if_changed_rule,cc_o_c)
> ? ? ? ?@{ echo $(@:.o=.ko); echo $@; } > $(MODVERDIR)/$(@F:.o=.mod)
> @@ -317,7 +323,7 @@ quiet_cmd_cc_lst_c = MKLST ? $@
> ? ? ? ? ? ? ? ? ? ? $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.map $(OBJDUMP) > $@
>
> -$(obj)/%.lst: $(src)/%.c FORCE
> +$(obj)/%.lst: %.c FORCE
> ? ? ? ?$(call if_changed_dep,cc_lst_c)
>
> ?# Compile assembler sources (.S)
> @@ -331,13 +337,13 @@ $(real-objs-m:.o=.s): modkern_aflags := $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE)
> ?quiet_cmd_as_s_S = CPP $(quiet_modtag) $@
> ?cmd_as_s_S ? ? ? = $(CPP) $(a_flags) ? -o $@ $<
>
> -$(obj)/%.s: $(src)/%.S FORCE
> +$(obj)/%.s: %.S FORCE
> ? ? ? ?$(call if_changed_dep,as_s_S)
>
> ?quiet_cmd_as_o_S = AS $(quiet_modtag) ?$@
> ?cmd_as_o_S ? ? ? = $(CC) $(a_flags) -c -o $@ $<
>
> -$(obj)/%.o: $(src)/%.S FORCE
> +$(obj)/%.o: %.S FORCE
> ? ? ? ?$(call if_changed_dep,as_o_S)
>
> ?targets += $(real-objs-y) $(real-objs-m) $(lib-y)
> @@ -349,7 +355,7 @@ quiet_cmd_cpp_lds_S = LDS ? ? $@
> ? ? ? cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -C -U$(ARCH) \
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $<
>
> -$(obj)/%.lds: $(src)/%.lds.S FORCE
> +$(obj)/%.lds: %.lds.S FORCE
> ? ? ? ?$(call if_changed_dep,cpp_lds_S)
>
> ?# Build the compiled-in targets
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index aeea84a..b57b621 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -46,6 +46,13 @@ obj-m ? ? ? ? ? ? ? ?:= $(filter-out %/, $(obj-m))
>
> ?subdir-ym ? ? ?:= $(sort $(subdir-y) $(subdir-m))
>
> +#
> +vpath-ym ? ? ? := $(vpath-y) $(vpath-m)
> +VPATH ? ? ? ? ?:= $(KBUILD_VPATH)
> +VPATH ? ? ? ? ?+= $(srctree)/$(src)
> +VPATH ? ? ? ? ?+= $(obj)
> +VPATH ? ? ? ? ?+= $(vpath-ym)
> +
> ?# if $(foo-objs) exists, foo.o is a composite object
> ?multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
> ?multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
> @@ -167,7 +174,7 @@ ifdef REGENERATE_PARSERS
> ?quiet_cmd_gperf = GPERF $@
> ? ? ? cmd_gperf = gperf -t --output-file $@ -a -C -E -g -k 1,3,$$ -p -t $<
>
> -$(src)/%.hash.c_shipped: $(src)/%.gperf
> +$(src)/%.hash.c_shipped: %.gperf
> ? ? ? ?$(call cmd,gperf)
>
> ?# LEX
> @@ -177,7 +184,7 @@ LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
> ?quiet_cmd_flex = LEX ? ? $@
> ? ? ? cmd_flex = flex -o$@ -L -P $(LEX_PREFIX) $<
>
> -$(src)/%.lex.c_shipped: $(src)/%.l
> +$(src)/%.lex.c_shipped: %.l
> ? ? ? ?$(call cmd,flex)
>
> ?# YACC
> @@ -187,13 +194,13 @@ YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy)
> ?quiet_cmd_bison = YACC ? ?$@
> ? ? ? cmd_bison = bison -o$@ -t -l -p $(YACC_PREFIX) $<
>
> -$(src)/%.tab.c_shipped: $(src)/%.y
> +$(src)/%.tab.c_shipped: %.y
> ? ? ? ?$(call cmd,bison)
>
> ?quiet_cmd_bison_h = YACC ? ?$@
> ? ? ? cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
>
> -$(src)/%.tab.h_shipped: $(src)/%.y
> +$(src)/%.tab.h_shipped: %.y
> ? ? ? ?$(call cmd,bison_h)
>
> ?endif
> @@ -204,7 +211,7 @@ endif
> ?quiet_cmd_shipped = SHIPPED $@
> ?cmd_shipped = cat $< > $@
>
> -$(obj)/%: $(src)/%_shipped
> +$(obj)/%: %_shipped
> ? ? ? ?$(call cmd,shipped)
>
> ?# Commands useful for building a boot image
> --
> 1.7.6.153.g78432
>
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-08 4:50 ` Arnaud Lacombe
@ 2011-09-08 20:33 ` Nicolas Pitre
-1 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-09-08 20:33 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: linux-kbuild, linux-arm-kernel, lkml
On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
> you missed:
>
> # Make sure files are removed during clean
> -extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
> +extra-y += piggy.gzip piggy.lzo piggy.lzma
>
> This confused make.
Well... that was suttle.
So yes, your patch may certainly be useful to a couple cases, and it
works fine for this lib1func.S.
It doesn't help me much in the following situation though. What I
actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. I
still haven't found a way to convince gcc to do that.
Nicolas
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-08 20:33 ` Nicolas Pitre
0 siblings, 0 replies; 35+ messages in thread
From: Nicolas Pitre @ 2011-09-08 20:33 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
> you missed:
>
> # Make sure files are removed during clean
> -extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
> +extra-y += piggy.gzip piggy.lzo piggy.lzma
>
> This confused make.
Well... that was suttle.
So yes, your patch may certainly be useful to a couple cases, and it
works fine for this lib1func.S.
It doesn't help me much in the following situation though. What I
actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. I
still haven't found a way to convince gcc to do that.
Nicolas
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-08 20:33 ` Nicolas Pitre
@ 2011-09-09 1:22 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-09 1:22 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: linux-kbuild, linux-arm-kernel, lkml
Hi,
On Thu, Sep 8, 2011 at 4:33 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
>
>> you missed:
>>
>> # Make sure files are removed during clean
>> -extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
>> +extra-y += piggy.gzip piggy.lzo piggy.lzma
>>
>> This confused make.
>
> Well... that was suttle.
>
he, welcome to make(1) world :)
> So yes, your patch may certainly be useful to a couple cases, and it
> works fine for this lib1func.S.
>
> It doesn't help me much in the following situation though. What I
> actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
> from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
> version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. I
> still haven't found a way to convince gcc to do that.
>
The only choice you have in gcc, is to use -I-, to construct:
$(CROSS_COMPILE)gcc -I$(srctree)/arch/arm/boot/compressed -I- [...]
however, it's been marked as deprecated, but still usable as of today
snapshot of 4.7.0. Its replacement, -iquote, do not provide this
functionnality, that is to override the source file origin directory
as search directory for #include "...".
- Arnaud
> Nicolas
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-09 1:22 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-09 1:22 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Thu, Sep 8, 2011 at 4:33 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
> On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
>
>> you missed:
>>
>> ?# Make sure files are removed during clean
>> -extra-y ? ? ? += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
>> +extra-y ? ? ? += piggy.gzip piggy.lzo piggy.lzma
>>
>> This confused make.
>
> Well... that was suttle.
>
he, welcome to make(1) world :)
> So yes, your patch may certainly be useful to a couple cases, and it
> works fine for this lib1func.S.
>
> It doesn't help me much in the following situation though. ?What I
> actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
> from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
> version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. ?I
> still haven't found a way to convince gcc to do that.
>
The only choice you have in gcc, is to use -I-, to construct:
$(CROSS_COMPILE)gcc -I$(srctree)/arch/arm/boot/compressed -I- [...]
however, it's been marked as deprecated, but still usable as of today
snapshot of 4.7.0. Its replacement, -iquote, do not provide this
functionnality, that is to override the source file origin directory
as search directory for #include "...".
- Arnaud
> Nicolas
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-08-20 0:37 ` Arnaud Lacombe
@ 2011-09-09 12:30 ` Michal Marek
-1 siblings, 0 replies; 35+ messages in thread
From: Michal Marek @ 2011-09-09 12:30 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: linux-kbuild, linux-kernel, linux-arm-kernel
On 20.8.2011 02:37, Arnaud Lacombe wrote:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
>
> Considering:
>
> arch/foo/lib:
> fancy.c
>
> We want to be able to build it with -DPANTS=32 in the kernel, but the
> bootloader requires -DPANTS_SIZE=30.
>
> Currently we would do, either:
>
> arch/foo/lib/Makefile
> LDFLAGS_fancy.o := -DPANTS=32
> obj-y += fancy.o
>
> and, either:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,shipped)
>
> or
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,cc_c_o)
>
> The former implies an extra copy of the source file, the latter expose Kbuild
> internal function.
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
I like this. The only issue I can think of right now, is that if you add
a large directory to vpath-y, then it would be easy to accidentally
reuse more files from that directory than intended. But that could be
easily prevented by isolating those reusable source files.
Michal
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-09 12:30 ` Michal Marek
0 siblings, 0 replies; 35+ messages in thread
From: Michal Marek @ 2011-09-09 12:30 UTC (permalink / raw)
To: linux-arm-kernel
On 20.8.2011 02:37, Arnaud Lacombe wrote:
> Hi folks,
>
> The attached patch modify Kbuild to allow to directly re-use code in multiple
> directory without having to go through a copy. Technically, it changes Kbuild to
> use by default the VPATH feature of GNU make and provides accessors for Makefile
> to change it indirectly.
>
> Considering:
>
> arch/foo/lib:
> fancy.c
>
> We want to be able to build it with -DPANTS=32 in the kernel, but the
> bootloader requires -DPANTS_SIZE=30.
>
> Currently we would do, either:
>
> arch/foo/lib/Makefile
> LDFLAGS_fancy.o := -DPANTS=32
> obj-y += fancy.o
>
> and, either:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,shipped)
>
> or
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
> $(call cmd,cc_c_o)
>
> The former implies an extra copy of the source file, the latter expose Kbuild
> internal function.
>
> With the attached patch, we would do:
>
> arch/foo/boot/Makefile:
> LDFLAGS_fancy.o := -DPANTS=30
> obj-y += fancy.o
> vpath-y += $(srctree)/arch/foo/lib
>
> and let GNU make do the job.
I like this. The only issue I can think of right now, is that if you add
a large directory to vpath-y, then it would be easy to accidentally
reuse more files from that directory than intended. But that could be
easily prevented by isolating those reusable source files.
Michal
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-09 1:22 ` Arnaud Lacombe
@ 2011-09-09 12:32 ` Michal Marek
-1 siblings, 0 replies; 35+ messages in thread
From: Michal Marek @ 2011-09-09 12:32 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: Nicolas Pitre, linux-kbuild, linux-arm-kernel, lkml
On 9.9.2011 03:22, Arnaud Lacombe wrote:
> Hi,
>
> On Thu, Sep 8, 2011 at 4:33 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>> On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
>>
>>> you missed:
>>>
>>> # Make sure files are removed during clean
>>> -extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
>>> +extra-y += piggy.gzip piggy.lzo piggy.lzma
>>>
>>> This confused make.
>>
>> Well... that was suttle.
>>
> he, welcome to make(1) world :)
>
>> So yes, your patch may certainly be useful to a couple cases, and it
>> works fine for this lib1func.S.
>>
>> It doesn't help me much in the following situation though. What I
>> actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
>> from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
>> version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. I
>> still haven't found a way to convince gcc to do that.
>>
> The only choice you have in gcc, is to use -I-, to construct:
>
> $(CROSS_COMPILE)gcc -I$(srctree)/arch/arm/boot/compressed -I- [...]
>
> however, it's been marked as deprecated, but still usable as of today
> snapshot of 4.7.0. Its replacement, -iquote, do not provide this
> functionnality, that is to override the source file origin directory
> as search directory for #include "...".
Or you modify libfdt to support -DLIBFDT_ENV=libfdt_arm.h or similar.
Michal
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-09 12:32 ` Michal Marek
0 siblings, 0 replies; 35+ messages in thread
From: Michal Marek @ 2011-09-09 12:32 UTC (permalink / raw)
To: linux-arm-kernel
On 9.9.2011 03:22, Arnaud Lacombe wrote:
> Hi,
>
> On Thu, Sep 8, 2011 at 4:33 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>> On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
>>
>>> you missed:
>>>
>>> # Make sure files are removed during clean
>>> -extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
>>> +extra-y += piggy.gzip piggy.lzo piggy.lzma
>>>
>>> This confused make.
>>
>> Well... that was suttle.
>>
> he, welcome to make(1) world :)
>
>> So yes, your patch may certainly be useful to a couple cases, and it
>> works fine for this lib1func.S.
>>
>> It doesn't help me much in the following situation though. What I
>> actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
>> from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
>> version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. I
>> still haven't found a way to convince gcc to do that.
>>
> The only choice you have in gcc, is to use -I-, to construct:
>
> $(CROSS_COMPILE)gcc -I$(srctree)/arch/arm/boot/compressed -I- [...]
>
> however, it's been marked as deprecated, but still usable as of today
> snapshot of 4.7.0. Its replacement, -iquote, do not provide this
> functionnality, that is to override the source file origin directory
> as search directory for #include "...".
Or you modify libfdt to support -DLIBFDT_ENV=libfdt_arm.h or similar.
Michal
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-09 12:32 ` Michal Marek
@ 2011-09-09 16:16 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-09 16:16 UTC (permalink / raw)
To: Michal Marek; +Cc: Nicolas Pitre, linux-kbuild, linux-arm-kernel, lkml
Hi,
On Fri, Sep 9, 2011 at 8:32 AM, Michal Marek <mmarek@suse.cz> wrote:
> On 9.9.2011 03:22, Arnaud Lacombe wrote:
>> Hi,
>>
>> On Thu, Sep 8, 2011 at 4:33 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>>> On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
>>>
>>>> you missed:
>>>>
>>>> # Make sure files are removed during clean
>>>> -extra-y += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
>>>> +extra-y += piggy.gzip piggy.lzo piggy.lzma
>>>>
>>>> This confused make.
>>>
>>> Well... that was suttle.
>>>
>> he, welcome to make(1) world :)
>>
>>> So yes, your patch may certainly be useful to a couple cases, and it
>>> works fine for this lib1func.S.
>>>
>>> It doesn't help me much in the following situation though. What I
>>> actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
>>> from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
>>> version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. I
>>> still haven't found a way to convince gcc to do that.
>>>
>> The only choice you have in gcc, is to use -I-, to construct:
>>
>> $(CROSS_COMPILE)gcc -I$(srctree)/arch/arm/boot/compressed -I- [...]
>>
>> however, it's been marked as deprecated, but still usable as of today
>> snapshot of 4.7.0. Its replacement, -iquote, do not provide this
>> functionnality, that is to override the source file origin directory
>> as search directory for #include "...".
>
> Or you modify libfdt to support -DLIBFDT_ENV=libfdt_arm.h or similar.
>
If dtc has to be modified, let's just get rid of that #include "..."
in favor of #include <...>. We will gain full control of search path,
and it will be cleaner than this awful LIBFTD_ENV construct.
- Arnaud
> Michal
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-09 16:16 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-09 16:16 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
On Fri, Sep 9, 2011 at 8:32 AM, Michal Marek <mmarek@suse.cz> wrote:
> On 9.9.2011 03:22, Arnaud Lacombe wrote:
>> Hi,
>>
>> On Thu, Sep 8, 2011 at 4:33 PM, Nicolas Pitre <nico@fluxnic.net> wrote:
>>> On Thu, 8 Sep 2011, Arnaud Lacombe wrote:
>>>
>>>> you missed:
>>>>
>>>> ?# Make sure files are removed during clean
>>>> -extra-y ? ? ? += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S
>>>> +extra-y ? ? ? += piggy.gzip piggy.lzo piggy.lzma
>>>>
>>>> This confused make.
>>>
>>> Well... that was suttle.
>>>
>> he, welcome to make(1) world :)
>>
>>> So yes, your patch may certainly be useful to a couple cases, and it
>>> works fine for this lib1func.S.
>>>
>>> It doesn't help me much in the following situation though. ?What I
>>> actually want to achieve is to compile arch/arm/boot/compressed/fdt_rw.o
>>> from scripts/dtc/libfdt/fdt_rw.c, however I want it to include my local
>>> version of libfdt_env.h rather than scripts/dtc/libfdt/libfdt_env.h. ?I
>>> still haven't found a way to convince gcc to do that.
>>>
>> The only choice you have in gcc, is to use -I-, to construct:
>>
>> ?$(CROSS_COMPILE)gcc -I$(srctree)/arch/arm/boot/compressed -I- [...]
>>
>> however, it's been marked as deprecated, but still usable as of today
>> snapshot of 4.7.0. Its replacement, -iquote, do not provide this
>> functionnality, that is to override the source file origin directory
>> as search directory for #include "...".
>
> Or you modify libfdt to support -DLIBFDT_ENV=libfdt_arm.h or similar.
>
If dtc has to be modified, let's just get rid of that #include "..."
in favor of #include <...>. We will gain full control of search path,
and it will be cleaner than this awful LIBFTD_ENV construct.
- Arnaud
> Michal
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-09 12:30 ` Michal Marek
@ 2011-09-13 21:13 ` Arnaud Lacombe
-1 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-13 21:13 UTC (permalink / raw)
To: Michal Marek; +Cc: linux-kbuild, linux-kernel, linux-arm-kernel
Hi,
2011/9/9 Michal Marek <mmarek@suse.cz>:
> On 20.8.2011 02:37, Arnaud Lacombe wrote:
>> Hi folks,
>>
>> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> directory without having to go through a copy. Technically, it changes Kbuild to
>> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> to change it indirectly.
>>
>> Considering:
>>
>> arch/foo/lib:
>> fancy.c
>>
>> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> bootloader requires -DPANTS_SIZE=30.
>>
>> Currently we would do, either:
>>
>> arch/foo/lib/Makefile
>> LDFLAGS_fancy.o := -DPANTS=32
>> obj-y += fancy.o
>>
>> and, either:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> $(call cmd,shipped)
>>
>> or
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> $(call cmd,cc_c_o)
>>
>> The former implies an extra copy of the source file, the latter expose Kbuild
>> internal function.
>>
>> With the attached patch, we would do:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> vpath-y += $(srctree)/arch/foo/lib
>>
>> and let GNU make do the job.
>
> I like this. The only issue I can think of right now, is that if you add
> a large directory to vpath-y, then it would be easy to accidentally
> reuse more files from that directory than intended. But that could be
> easily prevented by isolating those reusable source files.
>
I do not think it is that dangerous. We enforce unique access to VPATH
and we still prioritize $(src) over any other specified path.
That said, what would you want to pull the patch into -next, beside
kernel.org being up ?
Thanks,
- Arnaud
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-13 21:13 ` Arnaud Lacombe
0 siblings, 0 replies; 35+ messages in thread
From: Arnaud Lacombe @ 2011-09-13 21:13 UTC (permalink / raw)
To: linux-arm-kernel
Hi,
2011/9/9 Michal Marek <mmarek@suse.cz>:
> On 20.8.2011 02:37, Arnaud Lacombe wrote:
>> Hi folks,
>>
>> The attached patch modify Kbuild to allow to directly re-use code in multiple
>> directory without having to go through a copy. Technically, it changes Kbuild to
>> use by default the VPATH feature of GNU make and provides accessors for Makefile
>> to change it indirectly.
>>
>> Considering:
>>
>> arch/foo/lib:
>> fancy.c
>>
>> We want to be able to build it with -DPANTS=32 in the kernel, but the
>> bootloader requires -DPANTS_SIZE=30.
>>
>> Currently we would do, either:
>>
>> arch/foo/lib/Makefile
>> LDFLAGS_fancy.o := -DPANTS=32
>> obj-y += fancy.o
>>
>> and, either:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.c: $(srctree)/arch/foo/lib/fancy.c
>> ? ? ? $(call cmd,shipped)
>>
>> or
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> $(obj)/fancy.o: $(srctree)/arch/foo/lib/fancy.c
>> ? ? ? $(call cmd,cc_c_o)
>>
>> The former implies an extra copy of the source file, the latter expose Kbuild
>> internal function.
>>
>> With the attached patch, we would do:
>>
>> arch/foo/boot/Makefile:
>> LDFLAGS_fancy.o := -DPANTS=30
>> obj-y += fancy.o
>> vpath-y += $(srctree)/arch/foo/lib
>>
>> and let GNU make do the job.
>
> I like this. The only issue I can think of right now, is that if you add
> a large directory to vpath-y, then it would be easy to accidentally
> reuse more files from that directory than intended. But that could be
> easily prevented by isolating those reusable source files.
>
I do not think it is that dangerous. We enforce unique access to VPATH
and we still prioritize $(src) over any other specified path.
That said, what would you want to pull the patch into -next, beside
kernel.org being up ?
Thanks,
- Arnaud
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [RFC] Kbuild: allow code re-use across different directories
2011-09-13 21:13 ` Arnaud Lacombe
@ 2011-09-14 1:48 ` Michal Marek
-1 siblings, 0 replies; 35+ messages in thread
From: Michal Marek @ 2011-09-14 1:48 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: linux-kbuild, linux-kernel, linux-arm-kernel
Dne 13.9.2011 23:13, Arnaud Lacombe napsal(a):
> 2011/9/9 Michal Marek <mmarek@suse.cz>:
>> On 20.8.2011 02:37, Arnaud Lacombe wrote:
>>> With the attached patch, we would do:
>>>
>>> arch/foo/boot/Makefile:
>>> LDFLAGS_fancy.o := -DPANTS=30
>>> obj-y += fancy.o
>>> vpath-y += $(srctree)/arch/foo/lib
>>>
>>> and let GNU make do the job.
>>
>> I like this. The only issue I can think of right now, is that if you add
>> a large directory to vpath-y, then it would be easy to accidentally
>> reuse more files from that directory than intended. But that could be
>> easily prevented by isolating those reusable source files.
>>
> I do not think it is that dangerous. We enforce unique access to VPATH
> and we still prioritize $(src) over any other specified path.
>
> That said, what would you want to pull the patch into -next, beside
> kernel.org being up ?
Just post it with a proper signoff. But there won't be any linux-next
until kernel.org is back again.
Michal
^ permalink raw reply [flat|nested] 35+ messages in thread
* [RFC] Kbuild: allow code re-use across different directories
@ 2011-09-14 1:48 ` Michal Marek
0 siblings, 0 replies; 35+ messages in thread
From: Michal Marek @ 2011-09-14 1:48 UTC (permalink / raw)
To: linux-arm-kernel
Dne 13.9.2011 23:13, Arnaud Lacombe napsal(a):
> 2011/9/9 Michal Marek <mmarek@suse.cz>:
>> On 20.8.2011 02:37, Arnaud Lacombe wrote:
>>> With the attached patch, we would do:
>>>
>>> arch/foo/boot/Makefile:
>>> LDFLAGS_fancy.o := -DPANTS=30
>>> obj-y += fancy.o
>>> vpath-y += $(srctree)/arch/foo/lib
>>>
>>> and let GNU make do the job.
>>
>> I like this. The only issue I can think of right now, is that if you add
>> a large directory to vpath-y, then it would be easy to accidentally
>> reuse more files from that directory than intended. But that could be
>> easily prevented by isolating those reusable source files.
>>
> I do not think it is that dangerous. We enforce unique access to VPATH
> and we still prioritize $(src) over any other specified path.
>
> That said, what would you want to pull the patch into -next, beside
> kernel.org being up ?
Just post it with a proper signoff. But there won't be any linux-next
until kernel.org is back again.
Michal
^ permalink raw reply [flat|nested] 35+ messages in thread
end of thread, other threads:[~2011-09-14 1:48 UTC | newest]
Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-20 0:37 [RFC] Kbuild: allow code re-use across different directories Arnaud Lacombe
2011-08-20 0:37 ` Arnaud Lacombe
2011-08-22 8:42 ` Cong Wang
2011-08-22 8:42 ` Cong Wang
2011-08-30 0:31 ` Arnaud Lacombe
2011-08-30 0:31 ` Arnaud Lacombe
2011-08-30 4:32 ` Nicolas Pitre
2011-08-30 4:32 ` Nicolas Pitre
2011-08-30 4:36 ` Arnaud Lacombe
2011-08-30 4:36 ` Arnaud Lacombe
2011-09-07 19:07 ` Nicolas Pitre
2011-09-07 19:07 ` Nicolas Pitre
2011-09-07 19:34 ` Arnaud Lacombe
2011-09-07 19:34 ` Arnaud Lacombe
2011-09-07 19:59 ` Nicolas Pitre
2011-09-07 19:59 ` Nicolas Pitre
2011-09-07 20:52 ` Arnaud Lacombe
2011-09-07 20:52 ` Arnaud Lacombe
2011-09-08 4:50 ` Arnaud Lacombe
2011-09-08 4:50 ` Arnaud Lacombe
2011-09-08 20:33 ` Nicolas Pitre
2011-09-08 20:33 ` Nicolas Pitre
2011-09-09 1:22 ` Arnaud Lacombe
2011-09-09 1:22 ` Arnaud Lacombe
2011-09-09 12:32 ` Michal Marek
2011-09-09 12:32 ` Michal Marek
2011-09-09 16:16 ` Arnaud Lacombe
2011-09-09 16:16 ` Arnaud Lacombe
2011-09-08 18:24 ` Arnaud Lacombe
2011-09-09 12:30 ` Michal Marek
2011-09-09 12:30 ` Michal Marek
2011-09-13 21:13 ` Arnaud Lacombe
2011-09-13 21:13 ` Arnaud Lacombe
2011-09-14 1:48 ` Michal Marek
2011-09-14 1:48 ` Michal Marek
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.