Skip to content

Commit 5332bc5

Browse files
author
Herton R. Krzesinski
committed
kbuild: use $(obj)/ instead of $(src)/ for common pattern rules
JIRA: https://issues.redhat.com/browse/RHEL-107194 commit 9a0ebe5 Author: Masahiro Yamada <masahiroy@kernel.org> Date: Sat Apr 27 23:55:01 2024 +0900 kbuild: use $(obj)/ instead of $(src)/ for common pattern rules Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for checked-in source files. It is merely a convention without any functional difference. In fact, $(obj) and $(src) are exactly the same, as defined in scripts/Makefile.build: src := $(obj) Before changing the semantics of $(src) in the next commit, this commit replaces $(obj)/ with $(src)/ in pattern rules where the prerequisite might be a generated file. C, assembly, Rust, and DTS files are sometimes generated by tools, so they could be either generated files or real sources. The $(obj)/ prefix works for both cases with the help of VPATH. As mentioned above, $(obj) and $(src) are the same at this point, hence this commit has no functional change. I did not modify scripts/Makefile.userprogs because there is no use case where userspace C files are generated. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu> Conflicts: - scripts/Makefile.lib: since RHEL 9 does not have "dt-bindings: kbuild: Use DTB files for validation", we patch the yaml target instead. - At scripts/Makefile.build: * Adjusted $(obj)/%.symversions patching due previously applied RHEL only commit "kbuild: expose explicit .symversions targets" and which now needs to also be update with this change * Dropped patching of some targets (eg. with %.rs) since RHEL 9 does not have "Kbuild: add Rust support" Assisted-by: Patchpal AI Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
1 parent 8fb0adb commit 5332bc5

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

scripts/Makefile.build

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ endif
109109
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
110110
cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $<
111111

112-
$(obj)/%.s: $(src)/%.c FORCE
112+
$(obj)/%.s: $(obj)/%.c FORCE
113113
$(call if_changed_dep,cc_s_c)
114114

115115
quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
116116
cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
117117

118-
$(obj)/%.i: $(src)/%.c FORCE
118+
$(obj)/%.i: $(obj)/%.c FORCE
119119
$(call if_changed_dep,cpp_i_c)
120120

121121
genksyms = scripts/genksyms/genksyms \
@@ -128,22 +128,23 @@ cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
128128

129129
quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
130130
cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@) >/dev/null
131+
132+
$(obj)/%.symtypes : $(obj)/%.c FORCE
133+
$(call cmd,cc_symtypes_c)
134+
131135
cmd_cc_symversions_c = \
132136
$(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) > $@; \
133137
test -s $@ || rm -f $@
134138

135-
$(obj)/%.symtypes : $(src)/%.c FORCE
136-
$(call cmd,cc_symtypes_c)
137-
138-
$(obj)/%.symversions : $(src)/%.c FORCE
139+
$(obj)/%.symversions : $(obj)/%.c FORCE
139140
$(call cmd,cc_symversions_c)
140141

141142
# LLVM assembly
142143
# Generate .ll files from .c
143144
quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
144145
cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $<
145146

146-
$(obj)/%.ll: $(src)/%.c FORCE
147+
$(obj)/%.ll: $(obj)/%.c FORCE
147148
$(call if_changed_dep,cc_ll_c)
148149

149150
# C (.c) files
@@ -245,7 +246,7 @@ define rule_as_o_S
245246
endef
246247

247248
# Built-in and composite module parts
248-
$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
249+
$(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE
249250
$(call if_changed_rule,cc_o_c)
250251
$(call cmd,force_checksrc)
251252

@@ -268,7 +269,7 @@ quiet_cmd_cc_lst_c = MKLST $@
268269
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
269270
System.map $(OBJDUMP) > $@
270271

271-
$(obj)/%.lst: $(src)/%.c FORCE
272+
$(obj)/%.lst: $(obj)/%.c FORCE
272273
$(call if_changed_dep,cc_lst_c)
273274

274275
# Compile assembler sources (.S)
@@ -305,20 +306,21 @@ cmd_gensymversions_S = \
305306

306307
quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
307308
cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null
309+
310+
$(obj)/%.symtypes : $(obj)/%.S FORCE
311+
$(call cmd,cc_symtypes_S)
312+
308313
cmd_cc_symversions_S = \
309314
$(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) > $@; \
310315
test -s $@ || rm -f $@
311316

312-
$(obj)/%.symtypes : $(src)/%.S FORCE
313-
$(call cmd,cc_symtypes_S)
314-
315-
$(obj)/%.symversions : $(src)/%.S FORCE
317+
$(obj)/%.symversions : $(obj)/%.S FORCE
316318
$(call cmd,cc_symversions_S)
317319

318320
quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
319321
cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
320322

321-
$(obj)/%.s: $(src)/%.S FORCE
323+
$(obj)/%.s: $(obj)/%.S FORCE
322324
$(call if_changed_dep,cpp_s_S)
323325

324326
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
@@ -333,7 +335,7 @@ cmd_gen_symversions_S = $(call gen_symversions,S)
333335

334336
endif
335337

336-
$(obj)/%.o: $(src)/%.S FORCE
338+
$(obj)/%.o: $(obj)/%.S FORCE
337339
$(call if_changed_rule,as_o_S)
338340

339341
targets += $(filter-out $(subdir-builtin), $(real-obj-y))

scripts/Makefile.host

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags)
9191
quiet_cmd_host-csingle = HOSTCC $@
9292
cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
9393
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
94-
$(host-csingle): $(obj)/%: $(src)/%.c FORCE
94+
$(host-csingle): $(obj)/%: $(obj)/%.c FORCE
9595
$(call if_changed_dep,host-csingle)
9696

9797
# Link an executable based on list of .o files, all plain c
@@ -108,7 +108,7 @@ $(call multi_depend, $(host-cmulti), , -objs)
108108
# host-cobjs -> .o
109109
quiet_cmd_host-cobjs = HOSTCC $@
110110
cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
111-
$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
111+
$(host-cobjs): $(obj)/%.o: $(obj)/%.c FORCE
112112
$(call if_changed_dep,host-cobjs)
113113

114114
# Link an executable based on list of .o files, a mixture of .c and .cc

scripts/Makefile.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ define rule_dtc
429429
$(call cmd,dtb_check)
430430
endef
431431

432-
$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
432+
$(obj)/%.dt.yaml: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
433433
$(call if_changed_rule,dtc)
434434

435435
$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE

0 commit comments

Comments
 (0)