Skip to content

Commit 9a0ebe5

Browse files
committed
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 <[email protected]> Reviewed-by: Nicolas Schier <[email protected]>
1 parent 9dcb47a commit 9a0ebe5

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

scripts/Makefile.build

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ endif
113113
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
114114
cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $<
115115

116-
$(obj)/%.s: $(src)/%.c FORCE
116+
$(obj)/%.s: $(obj)/%.c FORCE
117117
$(call if_changed_dep,cc_s_c)
118118

119119
quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@
120120
cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
121121

122-
$(obj)/%.i: $(src)/%.c FORCE
122+
$(obj)/%.i: $(obj)/%.c FORCE
123123
$(call if_changed_dep,cpp_i_c)
124124

125125
genksyms = scripts/genksyms/genksyms \
@@ -133,15 +133,15 @@ cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
133133
quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
134134
cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@) >/dev/null
135135

136-
$(obj)/%.symtypes : $(src)/%.c FORCE
136+
$(obj)/%.symtypes : $(obj)/%.c FORCE
137137
$(call cmd,cc_symtypes_c)
138138

139139
# LLVM assembly
140140
# Generate .ll files from .c
141141
quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@
142142
cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -fno-discard-value-names -o $@ $<
143143

144-
$(obj)/%.ll: $(src)/%.c FORCE
144+
$(obj)/%.ll: $(obj)/%.c FORCE
145145
$(call if_changed_dep,cc_ll_c)
146146

147147
# C (.c) files
@@ -240,7 +240,7 @@ define rule_as_o_S
240240
endef
241241

242242
# Built-in and composite module parts
243-
$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
243+
$(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE
244244
$(call if_changed_rule,cc_o_c)
245245
$(call cmd,force_checksrc)
246246

@@ -257,7 +257,7 @@ quiet_cmd_cc_lst_c = MKLST $@
257257
$(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \
258258
System.map $(OBJDUMP) > $@
259259

260-
$(obj)/%.lst: $(src)/%.c FORCE
260+
$(obj)/%.lst: $(obj)/%.c FORCE
261261
$(call if_changed_dep,cc_lst_c)
262262

263263
# Compile Rust sources (.rs)
@@ -290,27 +290,27 @@ rust_common_cmd = \
290290
quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
291291
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $<
292292

293-
$(obj)/%.o: $(src)/%.rs FORCE
293+
$(obj)/%.o: $(obj)/%.rs FORCE
294294
+$(call if_changed_dep,rustc_o_rs)
295295

296296
quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
297297
cmd_rustc_rsi_rs = \
298298
$(rust_common_cmd) -Zunpretty=expanded $< >$@; \
299299
command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@
300300

301-
$(obj)/%.rsi: $(src)/%.rs FORCE
301+
$(obj)/%.rsi: $(obj)/%.rs FORCE
302302
+$(call if_changed_dep,rustc_rsi_rs)
303303

304304
quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
305305
cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $<
306306

307-
$(obj)/%.s: $(src)/%.rs FORCE
307+
$(obj)/%.s: $(obj)/%.rs FORCE
308308
+$(call if_changed_dep,rustc_s_rs)
309309

310310
quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
311311
cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $<
312312

313-
$(obj)/%.ll: $(src)/%.rs FORCE
313+
$(obj)/%.ll: $(obj)/%.rs FORCE
314314
+$(call if_changed_dep,rustc_ll_rs)
315315

316316
# Compile assembler sources (.S)
@@ -336,14 +336,14 @@ cmd_gensymtypes_S = \
336336
quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
337337
cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null
338338

339-
$(obj)/%.symtypes : $(src)/%.S FORCE
339+
$(obj)/%.symtypes : $(obj)/%.S FORCE
340340
$(call cmd,cc_symtypes_S)
341341

342342

343343
quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
344344
cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<
345345

346-
$(obj)/%.s: $(src)/%.S FORCE
346+
$(obj)/%.s: $(obj)/%.S FORCE
347347
$(call if_changed_dep,cpp_s_S)
348348

349349
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
@@ -358,7 +358,7 @@ cmd_gen_symversions_S = $(call gen_symversions,S)
358358

359359
endif
360360

361-
$(obj)/%.o: $(src)/%.S FORCE
361+
$(obj)/%.o: $(obj)/%.S FORCE
362362
$(call if_changed_rule,as_o_S)
363363

364364
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
@@ -112,7 +112,7 @@ endif
112112
quiet_cmd_host-csingle = HOSTCC $@
113113
cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
114114
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
115-
$(host-csingle): $(obj)/%: $(src)/%.c FORCE
115+
$(host-csingle): $(obj)/%: $(obj)/%.c FORCE
116116
$(call if_changed_dep,host-csingle)
117117

118118
# Link an executable based on list of .o files, all plain c
@@ -129,7 +129,7 @@ $(call multi_depend, $(host-cmulti), , -objs)
129129
# host-cobjs -> .o
130130
quiet_cmd_host-cobjs = HOSTCC $@
131131
cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
132-
$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
132+
$(host-cobjs): $(obj)/%.o: $(obj)/%.c FORCE
133133
$(call if_changed_dep,host-cobjs)
134134

135135
# 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
@@ -423,7 +423,7 @@ quiet_cmd_dtb = $(quiet_cmd_dtc)
423423
cmd_dtb = $(cmd_dtc)
424424
endif
425425

426-
$(obj)/%.dtb: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
426+
$(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
427427
$(call if_changed_dep,dtb)
428428

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

0 commit comments

Comments
 (0)