Skip to content

Commit 54b8ae6

Browse files
committed
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 <[email protected]> Acked-by: Marc Zyngier <[email protected]>
1 parent 6f02bdf commit 54b8ae6

File tree

10 files changed

+43
-42
lines changed

10 files changed

+43
-42
lines changed

arch/arm/kvm/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ ifeq ($(plus_virt),+virt)
88
plus_virt_def := -DREQUIRES_VIRT=1
99
endif
1010

11+
KVM := ../../../virt/kvm
12+
1113
ccflags-y += -I $(srctree)/$(src) -I $(srctree)/virt/kvm/arm/vgic
12-
CFLAGS_arm.o := $(plus_virt_def)
14+
CFLAGS_$(KVM)/arm/arm.o := $(plus_virt_def)
1315

1416
AFLAGS_init.o := -Wa,-march=armv7-a$(plus_virt)
1517
AFLAGS_interrupts.o := -Wa,-march=armv7-a$(plus_virt)
1618

17-
KVM := ../../../virt/kvm
1819
kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o $(KVM)/vfio.o
1920

2021
obj-$(CONFIG_KVM_ARM_HOST) += hyp/

arch/x86/entry/vdso/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ $(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS
8989
#
9090
CFLAGS_REMOVE_vdso-note.o = -pg
9191
CFLAGS_REMOVE_vclock_gettime.o = -pg
92+
CFLAGS_REMOVE_vdso32/vclock_gettime.o = -pg
9293
CFLAGS_REMOVE_vgetcpu.o = -pg
9394
CFLAGS_REMOVE_vvar.o = -pg
9495

@@ -128,7 +129,7 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE
128129
$(obj)/vdsox32.so.dbg: $(obj)/vdsox32.lds $(vobjx32s) FORCE
129130
$(call if_changed,vdso_and_check)
130131

131-
CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
132+
CPPFLAGS_vdso32/vdso32.lds = $(CPPFLAGS_vdso.lds)
132133
VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -soname linux-gate.so.1
133134

134135
targets += vdso32/vdso32.lds

drivers/gpu/drm/amd/display/dc/calcs/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ endif
3232

3333
calcs_ccflags := -mhard-float -msse $(cc_stack_align)
3434

35-
CFLAGS_dcn_calcs.o := $(calcs_ccflags)
36-
CFLAGS_dcn_calc_auto.o := $(calcs_ccflags)
37-
CFLAGS_dcn_calc_math.o := $(calcs_ccflags) -Wno-tautological-compare
35+
CFLAGS_$(AMDDALPATH)/dc/calcs/dcn_calcs.o := $(calcs_ccflags)
36+
CFLAGS_$(AMDDALPATH)/dc/calcs/dcn_calc_auto.o := $(calcs_ccflags)
37+
CFLAGS_$(AMDDALPATH)/dc/calcs/dcn_calc_math.o := $(calcs_ccflags) -Wno-tautological-compare
3838

3939
BW_CALCS = dce_calcs.o bw_fixed.o custom_float.o
4040

drivers/gpu/drm/amd/display/dc/dcn20/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ else ifneq ($(call cc-option, -mstack-alignment=16),)
1616
cc_stack_align := -mstack-alignment=16
1717
endif
1818

19-
CFLAGS_dcn20_resource.o := -mhard-float -msse $(cc_stack_align)
19+
CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o := -mhard-float -msse $(cc_stack_align)
2020

2121
AMD_DAL_DCN20 = $(addprefix $(AMDDALPATH)/dc/dcn20/,$(DCN20))
2222

drivers/gpu/drm/amd/display/dc/dml/Makefile

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@ endif
3232

3333
dml_ccflags := -mhard-float -msse $(cc_stack_align)
3434

35-
CFLAGS_display_mode_lib.o := $(dml_ccflags)
35+
CFLAGS_$(AMDDALPATH)/dc/dml/display_mode_lib.o := $(dml_ccflags)
3636

3737
ifdef CONFIG_DRM_AMD_DC_DCN2_0
38-
CFLAGS_display_mode_vba.o := $(dml_ccflags)
39-
CFLAGS_display_mode_vba_20.o := $(dml_ccflags)
40-
CFLAGS_display_rq_dlg_calc_20.o := $(dml_ccflags)
38+
CFLAGS_$(AMDDALPATH)/dc/dml/display_mode_vba.o := $(dml_ccflags)
39+
CFLAGS_$(AMDDALPATH)/dc/dml/dcn20/display_mode_vba_20.o := $(dml_ccflags)
40+
CFLAGS_$(AMDDALPATH)/dc/dml/dcn20/display_rq_dlg_calc_20.o := $(dml_ccflags)
4141
endif
42-
ifdef CONFIG_DRM_AMD_DCN3AG
43-
CFLAGS_display_mode_vba_3ag.o := $(dml_ccflags)
44-
endif
45-
CFLAGS_dml1_display_rq_dlg_calc.o := $(dml_ccflags)
46-
CFLAGS_display_rq_dlg_helpers.o := $(dml_ccflags)
47-
CFLAGS_dml_common_defs.o := $(dml_ccflags)
42+
CFLAGS_$(AMDDALPATH)/dc/dml/dml1_display_rq_dlg_calc.o := $(dml_ccflags)
43+
CFLAGS_$(AMDDALPATH)/dc/dml/display_rq_dlg_helpers.o := $(dml_ccflags)
44+
CFLAGS_$(AMDDALPATH)/dc/dml/dml_common_defs.o := $(dml_ccflags)
4845

4946
DML = display_mode_lib.o display_rq_dlg_helpers.o dml1_display_rq_dlg_calc.o \
5047
dml_common_defs.o

drivers/gpu/drm/amd/display/dc/dsc/Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ endif
99

1010
dsc_ccflags := -mhard-float -msse $(cc_stack_align)
1111

12-
CFLAGS_rc_calc.o := $(dsc_ccflags)
13-
CFLAGS_rc_calc_dpi.o := $(dsc_ccflags)
14-
CFLAGS_codec_main_amd.o := $(dsc_ccflags)
15-
CFLAGS_dc_dsc.o := $(dsc_ccflags)
12+
CFLAGS_$(AMDDALPATH)/dc/dsc/rc_calc.o := $(dsc_ccflags)
13+
CFLAGS_$(AMDDALPATH)/dc/dsc/rc_calc_dpi.o := $(dsc_ccflags)
14+
CFLAGS_$(AMDDALPATH)/dc/dsc/dc_dsc.o := $(dsc_ccflags)
1615

1716
DSC = dc_dsc.o rc_calc.o rc_calc_dpi.o
1817

drivers/gpu/drm/i915/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ subdir-ccflags-$(CONFIG_DRM_I915_WERROR) += -Werror
2626

2727
# Fine grained warnings disable
2828
CFLAGS_i915_pci.o = $(call cc-disable-warning, override-init)
29-
CFLAGS_intel_fbdev.o = $(call cc-disable-warning, override-init)
29+
CFLAGS_display/intel_fbdev.o = $(call cc-disable-warning, override-init)
3030

3131
subdir-ccflags-y += \
3232
$(call as-instr,movntdqa (%eax)$(comma)%xmm0,-DCONFIG_AS_MOVNTDQA)

scripts/Makefile.host

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
8080
# Handle options to gcc. Support building with separate output directory
8181

8282
_hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
83-
$(HOSTCFLAGS_$(basetarget).o)
83+
$(HOSTCFLAGS_$(target-stem).o)
8484
_hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
85-
$(HOSTCXXFLAGS_$(basetarget).o)
85+
$(HOSTCXXFLAGS_$(target-stem).o)
8686

8787
# $(objtree)/$(obj) for including generated headers from checkin source files
8888
ifeq ($(KBUILD_EXTMOD),)
@@ -102,16 +102,16 @@ hostcxx_flags = -Wp,-MD,$(depfile) $(_hostcxx_flags)
102102
# host-csingle -> Executable
103103
quiet_cmd_host-csingle = HOSTCC $@
104104
cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
105-
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
105+
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
106106
$(host-csingle): $(obj)/%: $(src)/%.c FORCE
107107
$(call if_changed_dep,host-csingle)
108108

109109
# Link an executable based on list of .o files, all plain c
110110
# host-cmulti -> executable
111111
quiet_cmd_host-cmulti = HOSTLD $@
112112
cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
113-
$(addprefix $(obj)/,$($(@F)-objs)) \
114-
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
113+
$(addprefix $(obj)/, $($(target-stem)-objs)) \
114+
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
115115
$(host-cmulti): FORCE
116116
$(call if_changed,host-cmulti)
117117
$(call multi_depend, $(host-cmulti), , -objs)
@@ -128,8 +128,8 @@ $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
128128
quiet_cmd_host-cxxmulti = HOSTLD $@
129129
cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
130130
$(foreach o,objs cxxobjs,\
131-
$(addprefix $(obj)/,$($(@F)-$(o)))) \
132-
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
131+
$(addprefix $(obj)/, $($(target-stem)-$(o)))) \
132+
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
133133
$(host-cxxmulti): FORCE
134134
$(call if_changed,host-cxxmulti)
135135
$(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
@@ -161,8 +161,8 @@ $(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
161161
# *.o -> .so shared library (host-cshlib)
162162
quiet_cmd_host-cshlib = HOSTLLD -shared $@
163163
cmd_host-cshlib = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
164-
$(addprefix $(obj)/,$($(@F:.so=-objs))) \
165-
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
164+
$(addprefix $(obj)/, $($(target-stem)-objs)) \
165+
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem).so)
166166
$(host-cshlib): FORCE
167167
$(call if_changed,host-cshlib)
168168
$(call multi_depend, $(host-cshlib), .so, -objs)
@@ -171,8 +171,8 @@ $(call multi_depend, $(host-cshlib), .so, -objs)
171171
# *.o -> .so shared library (host-cxxshlib)
172172
quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
173173
cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
174-
$(addprefix $(obj)/,$($(@F:.so=-objs))) \
175-
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
174+
$(addprefix $(obj)/, $($(target-stem)-objs)) \
175+
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem).so)
176176
$(host-cxxshlib): FORCE
177177
$(call if_changed,host-cxxshlib)
178178
$(call multi_depend, $(host-cxxshlib), .so, -objs)

scripts/Makefile.lib

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\
101101

102102
modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
103103

104+
# target with $(obj)/ and its suffix stripped
105+
target-stem = $(basename $(patsubst $(obj)/%,%,$@))
106+
104107
# These flags are needed for modversions and compiling, so we define them here
105108
# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
106109
# end up in (or would, if it gets compiled in)
@@ -109,12 +112,12 @@ basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
109112
modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
110113

111114
orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
112-
$(ccflags-y) $(CFLAGS_$(basetarget).o)
113-
_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
115+
$(ccflags-y) $(CFLAGS_$(target-stem).o)
116+
_c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags))
114117
orig_a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
115-
$(asflags-y) $(AFLAGS_$(basetarget).o)
116-
_a_flags = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
117-
_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
118+
$(asflags-y) $(AFLAGS_$(target-stem).o)
119+
_a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags))
120+
_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
118121

119122
#
120123
# Enable gcov profiling flags for a file, directory or for all files depending

scripts/kconfig/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,15 @@ $(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
166166

167167
# mconf: Used for the menuconfig target based on lxdialog
168168
hostprogs-y += mconf
169-
lxdialog := checklist.o inputbox.o menubox.o textbox.o util.o yesno.o
170-
mconf-objs := mconf.o $(addprefix lxdialog/, $(lxdialog)) $(common-objs)
169+
lxdialog := $(addprefix lxdialog/, \
170+
checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
171+
mconf-objs := mconf.o $(lxdialog) $(common-objs)
171172

172173
HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
173174
$(foreach f, mconf.o $(lxdialog), \
174175
$(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
175176

176-
$(obj)/mconf.o: $(obj)/mconf-cfg
177-
$(addprefix $(obj)/lxdialog/, $(lxdialog)): $(obj)/mconf-cfg
177+
$(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
178178

179179
# qconf: Used for the xconfig target based on Qt
180180
hostprogs-y += qconf

0 commit comments

Comments
 (0)