diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-08-30 00:34:01 -0400 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-09-04 10:12:50 -0400 |
commit | 54b8ae66ae1a3454a7645d159a482c31cd89ab33 (patch) | |
tree | 483a7a19399eb352de2eeb49984417d2757bde00 /scripts | |
parent | 6f02bdfc995f098bde87216c122ade2b46f971b5 (diff) |
kbuild: change *FLAGS_<basetarget>.o to take the path relative to $(obj)
Kbuild provides per-file compiler flag addition/removal:
CFLAGS_<basetarget>.o
CFLAGS_REMOVE_<basetarget>.o
AFLAGS_<basetarget>.o
AFLAGS_REMOVE_<basetarget>.o
CPPFLAGS_<basetarget>.lds
HOSTCFLAGS_<basetarget>.o
HOSTCXXFLAGS_<basetarget>.o
The <basetarget> is the filename of the target with its directory and
suffix stripped.
This syntax comes into a trouble when two files with the same basename
appear in one Makefile, for example:
obj-y += foo.o
obj-y += dir/foo.o
CFLAGS_foo.o := <some-flags>
Here, the <some-flags> applies to both foo.o and dir/foo.o
The real world problem is:
scripts/kconfig/util.c
scripts/kconfig/lxdialog/util.c
Both files are compiled into scripts/kconfig/mconf, but only the
latter should be given with the ncurses flags.
It is more sensible to use the relative path to the Makefile, like this:
obj-y += foo.o
CFLAGS_foo.o := <some-flags>
obj-y += dir/foo.o
CFLAGS_dir/foo.o := <other-flags>
At first, I attempted to replace $(basetarget) with $*. The $* variable
is replaced with the stem ('%') part in a pattern rule. This works with
most of cases, but does not for explicit rules.
For example, arch/ia64/lib/Makefile reuses rule_as_o_S in its own
explicit rules, so $* will be empty, resulting in ignoring the per-file
AFLAGS.
I introduced a new variable, target-stem, which can be used also from
explicit rules.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.host | 22 | ||||
-rw-r--r-- | scripts/Makefile.lib | 13 | ||||
-rw-r--r-- | scripts/kconfig/Makefile | 8 |
3 files changed, 23 insertions, 20 deletions
diff --git a/scripts/Makefile.host b/scripts/Makefile.host index b402c619147d..4c51c95d40f4 100644 --- a/scripts/Makefile.host +++ b/scripts/Makefile.host | |||
@@ -80,9 +80,9 @@ host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs)) | |||
80 | # Handle options to gcc. Support building with separate output directory | 80 | # Handle options to gcc. Support building with separate output directory |
81 | 81 | ||
82 | _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ | 82 | _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ |
83 | $(HOSTCFLAGS_$(basetarget).o) | 83 | $(HOSTCFLAGS_$(target-stem).o) |
84 | _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ | 84 | _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ |
85 | $(HOSTCXXFLAGS_$(basetarget).o) | 85 | $(HOSTCXXFLAGS_$(target-stem).o) |
86 | 86 | ||
87 | # $(objtree)/$(obj) for including generated headers from checkin source files | 87 | # $(objtree)/$(obj) for including generated headers from checkin source files |
88 | ifeq ($(KBUILD_EXTMOD),) | 88 | ifeq ($(KBUILD_EXTMOD),) |
@@ -102,7 +102,7 @@ hostcxx_flags = -Wp,-MD,$(depfile) $(_hostcxx_flags) | |||
102 | # host-csingle -> Executable | 102 | # host-csingle -> Executable |
103 | quiet_cmd_host-csingle = HOSTCC $@ | 103 | quiet_cmd_host-csingle = HOSTCC $@ |
104 | cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \ | 104 | cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \ |
105 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) | 105 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem)) |
106 | $(host-csingle): $(obj)/%: $(src)/%.c FORCE | 106 | $(host-csingle): $(obj)/%: $(src)/%.c FORCE |
107 | $(call if_changed_dep,host-csingle) | 107 | $(call if_changed_dep,host-csingle) |
108 | 108 | ||
@@ -110,8 +110,8 @@ $(host-csingle): $(obj)/%: $(src)/%.c FORCE | |||
110 | # host-cmulti -> executable | 110 | # host-cmulti -> executable |
111 | quiet_cmd_host-cmulti = HOSTLD $@ | 111 | quiet_cmd_host-cmulti = HOSTLD $@ |
112 | cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \ | 112 | cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \ |
113 | $(addprefix $(obj)/,$($(@F)-objs)) \ | 113 | $(addprefix $(obj)/, $($(target-stem)-objs)) \ |
114 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) | 114 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem)) |
115 | $(host-cmulti): FORCE | 115 | $(host-cmulti): FORCE |
116 | $(call if_changed,host-cmulti) | 116 | $(call if_changed,host-cmulti) |
117 | $(call multi_depend, $(host-cmulti), , -objs) | 117 | $(call multi_depend, $(host-cmulti), , -objs) |
@@ -128,8 +128,8 @@ $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE | |||
128 | quiet_cmd_host-cxxmulti = HOSTLD $@ | 128 | quiet_cmd_host-cxxmulti = HOSTLD $@ |
129 | cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \ | 129 | cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \ |
130 | $(foreach o,objs cxxobjs,\ | 130 | $(foreach o,objs cxxobjs,\ |
131 | $(addprefix $(obj)/,$($(@F)-$(o)))) \ | 131 | $(addprefix $(obj)/, $($(target-stem)-$(o)))) \ |
132 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) | 132 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem)) |
133 | $(host-cxxmulti): FORCE | 133 | $(host-cxxmulti): FORCE |
134 | $(call if_changed,host-cxxmulti) | 134 | $(call if_changed,host-cxxmulti) |
135 | $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs) | 135 | $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs) |
@@ -161,8 +161,8 @@ $(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE | |||
161 | # *.o -> .so shared library (host-cshlib) | 161 | # *.o -> .so shared library (host-cshlib) |
162 | quiet_cmd_host-cshlib = HOSTLLD -shared $@ | 162 | quiet_cmd_host-cshlib = HOSTLLD -shared $@ |
163 | cmd_host-cshlib = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \ | 163 | cmd_host-cshlib = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \ |
164 | $(addprefix $(obj)/,$($(@F:.so=-objs))) \ | 164 | $(addprefix $(obj)/, $($(target-stem)-objs)) \ |
165 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) | 165 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem).so) |
166 | $(host-cshlib): FORCE | 166 | $(host-cshlib): FORCE |
167 | $(call if_changed,host-cshlib) | 167 | $(call if_changed,host-cshlib) |
168 | $(call multi_depend, $(host-cshlib), .so, -objs) | 168 | $(call multi_depend, $(host-cshlib), .so, -objs) |
@@ -171,8 +171,8 @@ $(call multi_depend, $(host-cshlib), .so, -objs) | |||
171 | # *.o -> .so shared library (host-cxxshlib) | 171 | # *.o -> .so shared library (host-cxxshlib) |
172 | quiet_cmd_host-cxxshlib = HOSTLLD -shared $@ | 172 | quiet_cmd_host-cxxshlib = HOSTLLD -shared $@ |
173 | cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \ | 173 | cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \ |
174 | $(addprefix $(obj)/,$($(@F:.so=-objs))) \ | 174 | $(addprefix $(obj)/, $($(target-stem)-objs)) \ |
175 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) | 175 | $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem).so) |
176 | $(host-cxxshlib): FORCE | 176 | $(host-cxxshlib): FORCE |
177 | $(call if_changed,host-cxxshlib) | 177 | $(call if_changed,host-cxxshlib) |
178 | $(call multi_depend, $(host-cxxshlib), .so, -objs) | 178 | $(call multi_depend, $(host-cxxshlib), .so, -objs) |
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 7ab17712ab24..380a7d11a573 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib | |||
@@ -101,6 +101,9 @@ modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\ | |||
101 | 101 | ||
102 | modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) | 102 | modname = $(if $(modname-multi),$(modname-multi),$(basetarget)) |
103 | 103 | ||
104 | # target with $(obj)/ and its suffix stripped | ||
105 | target-stem = $(basename $(patsubst $(obj)/%,%,$@)) | ||
106 | |||
104 | # These flags are needed for modversions and compiling, so we define them here | 107 | # These flags are needed for modversions and compiling, so we define them here |
105 | # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will | 108 | # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will |
106 | # end up in (or would, if it gets compiled in) | 109 | # end up in (or would, if it gets compiled in) |
@@ -109,12 +112,12 @@ basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) | |||
109 | modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) | 112 | modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) |
110 | 113 | ||
111 | orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ | 114 | orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ |
112 | $(ccflags-y) $(CFLAGS_$(basetarget).o) | 115 | $(ccflags-y) $(CFLAGS_$(target-stem).o) |
113 | _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) | 116 | _c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags)) |
114 | orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \ | 117 | orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \ |
115 | $(asflags-y) $(AFLAGS_$(basetarget).o) | 118 | $(asflags-y) $(AFLAGS_$(target-stem).o) |
116 | _a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags)) | 119 | _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags)) |
117 | _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) | 120 | _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) |
118 | 121 | ||
119 | # | 122 | # |
120 | # Enable gcov profiling flags for a file, directory or for all files depending | 123 | # Enable gcov profiling flags for a file, directory or for all files depending |
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile index bed7a5a2fbe9..ef2f2336c469 100644 --- a/scripts/kconfig/Makefile +++ b/scripts/kconfig/Makefile | |||
@@ -166,15 +166,15 @@ $(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg | |||
166 | 166 | ||
167 | # mconf: Used for the menuconfig target based on lxdialog | 167 | # mconf: Used for the menuconfig target based on lxdialog |
168 | hostprogs-y += mconf | 168 | hostprogs-y += mconf |
169 | lxdialog := checklist.o inputbox.o menubox.o textbox.o util.o yesno.o | 169 | lxdialog := $(addprefix lxdialog/, \ |
170 | mconf-objs := mconf.o $(addprefix lxdialog/, $(lxdialog)) $(common-objs) | 170 | checklist.o inputbox.o menubox.o textbox.o util.o yesno.o) |
171 | mconf-objs := mconf.o $(lxdialog) $(common-objs) | ||
171 | 172 | ||
172 | HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs) | 173 | HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs) |
173 | $(foreach f, mconf.o $(lxdialog), \ | 174 | $(foreach f, mconf.o $(lxdialog), \ |
174 | $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags))) | 175 | $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags))) |
175 | 176 | ||
176 | $(obj)/mconf.o: $(obj)/mconf-cfg | 177 | $(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg |
177 | $(addprefix $(obj)/lxdialog/, $(lxdialog)): $(obj)/mconf-cfg | ||
178 | 178 | ||
179 | # qconf: Used for the xconfig target based on Qt | 179 | # qconf: Used for the xconfig target based on Qt |
180 | hostprogs-y += qconf | 180 | hostprogs-y += qconf |