Skip to content

Commit

Permalink
kbuild: use $(obj)/ instead of $(src)/ for common pattern rules
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Masahiro Yamada committed May 9, 2024
1 parent 9dcb47a commit 9a0ebe5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ endif
quiet_cmd_cc_s_c = CC $(quiet_modtag) $@
cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $<

$(obj)/%.s: $(src)/%.c FORCE
$(obj)/%.s: $(obj)/%.c FORCE
$(call if_changed_dep,cc_s_c)

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

$(obj)/%.i: $(src)/%.c FORCE
$(obj)/%.i: $(obj)/%.c FORCE
$(call if_changed_dep,cpp_i_c)

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

$(obj)/%.symtypes : $(src)/%.c FORCE
$(obj)/%.symtypes : $(obj)/%.c FORCE
$(call cmd,cc_symtypes_c)

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

$(obj)/%.ll: $(src)/%.c FORCE
$(obj)/%.ll: $(obj)/%.c FORCE
$(call if_changed_dep,cc_ll_c)

# C (.c) files
Expand Down Expand Up @@ -240,7 +240,7 @@ define rule_as_o_S
endef

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

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

$(obj)/%.lst: $(src)/%.c FORCE
$(obj)/%.lst: $(obj)/%.c FORCE
$(call if_changed_dep,cc_lst_c)

# Compile Rust sources (.rs)
Expand Down Expand Up @@ -290,27 +290,27 @@ rust_common_cmd = \
quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $<

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

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

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

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

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

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

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

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

$(obj)/%.symtypes : $(src)/%.S FORCE
$(obj)/%.symtypes : $(obj)/%.S FORCE
$(call cmd,cc_symtypes_S)


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

$(obj)/%.s: $(src)/%.S FORCE
$(obj)/%.s: $(obj)/%.S FORCE
$(call if_changed_dep,cpp_s_S)

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

endif

$(obj)/%.o: $(src)/%.S FORCE
$(obj)/%.o: $(obj)/%.S FORCE
$(call if_changed_rule,as_o_S)

targets += $(filter-out $(subdir-builtin), $(real-obj-y))
Expand Down
4 changes: 2 additions & 2 deletions scripts/Makefile.host
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ endif
quiet_cmd_host-csingle = HOSTCC $@
cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
$(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
$(host-csingle): $(obj)/%: $(src)/%.c FORCE
$(host-csingle): $(obj)/%: $(obj)/%.c FORCE
$(call if_changed_dep,host-csingle)

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

# Link an executable based on list of .o files, a mixture of .c and .cc
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.lib
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ quiet_cmd_dtb = $(quiet_cmd_dtc)
cmd_dtb = $(cmd_dtc)
endif

$(obj)/%.dtb: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
$(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
$(call if_changed_dep,dtb)

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

0 comments on commit 9a0ebe5

Please sign in to comment.