Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 5c05caf

Browse files
committed
Merge bc6df81 ("fixdep: parse Makefile more correctly to handle comments etc.") into android-mainline
Steps on the way to 6.3-rc1 Change-Id: If13e9c1a1549a6129c23f71f75c61e737c43851f Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2 parents e7c6f62 + bc6df81 commit 5c05caf

File tree

10 files changed

+195
-118
lines changed

10 files changed

+195
-118
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,12 @@ rust-analyzer:
19071907
# Misc
19081908
# ---------------------------------------------------------------------------
19091909

1910+
PHONY += misc-check
1911+
misc-check:
1912+
$(Q)$(srctree)/scripts/misc-check
1913+
1914+
all: misc-check
1915+
19101916
PHONY += scripts_gdb
19111917
scripts_gdb: prepare0
19121918
$(Q)$(MAKE) $(build)=scripts/gdb

rust/Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,9 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
332332
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
333333
cmd_rustc_procmacro = \
334334
$(RUSTC_OR_CLIPPY) $(rust_common_flags) \
335-
--emit=dep-info,link --extern proc_macro \
336-
--crate-type proc-macro --out-dir $(objtree)/$(obj) \
335+
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
336+
--crate-type proc-macro \
337337
--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \
338-
mv $(objtree)/$(obj)/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \
339338
sed -i '/^\#/d' $(depfile)
340339

341340
# Procedural macros can only be used with the `rustc` that compiled it.
@@ -349,10 +348,10 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
349348
OBJTREE=$(abspath $(objtree)) \
350349
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
351350
$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
352-
--emit=dep-info,obj,metadata --crate-type rlib \
353-
--out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \
351+
--emit=dep-info=$(depfile) --emit=obj=$@ \
352+
--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
353+
--crate-type rlib -L$(objtree)/$(obj) \
354354
--crate-name $(patsubst %.o,%,$(notdir $@)) $<; \
355-
mv $(objtree)/$(obj)/$(patsubst %.o,%,$(notdir $@)).d $(depfile); \
356355
sed -i '/^\#/d' $(depfile) \
357356
$(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
358357

scripts/Kbuild.include

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,14 @@ cmd = @$(if $(cmd_$(1)),set -e; $($(quiet)log_print) $(delete-on-interrupt) $(cm
170170
ifneq ($(KBUILD_NOCMDDEP),1)
171171
# Check if both commands are the same including their order. Result is empty
172172
# string if equal. User may override this check using make KBUILD_NOCMDDEP=1
173-
cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \
173+
# If the target does not exist, the *.cmd file should not be included so
174+
# $(savedcmd_$@) gets empty. Then, target will be built even if $(newer-prereqs)
175+
# happens to become empty.
176+
cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(savedcmd_$@))), \
174177
$(subst $(space),$(space_escape),$(strip $(cmd_$1))))
175178
else
176-
cmd-check = $(if $(strip $(cmd_$@)),,1)
179+
# We still need to detect missing targets.
180+
cmd-check = $(if $(strip $(savedcmd_$@)),,1)
177181
endif
178182

179183
# Replace >$< with >$$< to preserve $ when reloading the .cmd file
@@ -186,6 +190,8 @@ make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1))))
186190

187191
# Find any prerequisites that are newer than target or that do not exist.
188192
# PHONY targets skipped in both cases.
193+
# If there is no prerequisite other than phony targets, $(newer-prereqs) becomes
194+
# empty even if the target does not exist. cmd-check saves this corner case.
189195
newer-prereqs = $(filter-out $(PHONY),$?)
190196

191197
# It is a typical mistake to forget the FORCE prerequisite. Check it here so
@@ -199,7 +205,7 @@ if_changed = $(if $(if-changed-cond),$(cmd_and_savecmd),@:)
199205

200206
cmd_and_savecmd = \
201207
$(cmd); \
202-
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd
208+
printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd
203209

204210
# Execute the command and also postprocess generated .d dependencies file.
205211
if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
@@ -239,7 +245,7 @@ _why = \
239245
$(if $(wildcard $@), \
240246
$(if $(newer-prereqs),- due to: $(newer-prereqs), \
241247
$(if $(cmd-check), \
242-
$(if $(cmd_$@),- due to command line change, \
248+
$(if $(savedcmd_$@),- due to command line change, \
243249
$(if $(filter $@, $(targets)), \
244250
- due to missing .cmd file, \
245251
- due to $(notdir $@) not in $$(targets) \

scripts/Makefile.build

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,11 @@ rust_common_cmd = \
285285
-Zcrate-attr=no_std \
286286
-Zcrate-attr='feature($(rust_allowed_features))' \
287287
--extern alloc --extern kernel \
288-
--crate-type rlib --out-dir $(obj) -L $(objtree)/rust/ \
289-
--crate-name $(basename $(notdir $@))
288+
--crate-type rlib -L $(objtree)/rust/ \
289+
--crate-name $(basename $(notdir $@)) \
290+
--emit=dep-info=$(depfile)
290291

291292
rust_handle_depfile = \
292-
mv $(obj)/$(basename $(notdir $@)).d $(depfile); \
293293
sed -i '/^\#/d' $(depfile)
294294

295295
# `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit
@@ -302,15 +302,15 @@ rust_handle_depfile = \
302302

303303
quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
304304
cmd_rustc_o_rs = \
305-
$(rust_common_cmd) --emit=dep-info,obj $<; \
305+
$(rust_common_cmd) --emit=obj=$@ $<; \
306306
$(rust_handle_depfile)
307307

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

311311
quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
312312
cmd_rustc_rsi_rs = \
313-
$(rust_common_cmd) --emit=dep-info -Zunpretty=expanded $< >$@; \
313+
$(rust_common_cmd) -Zunpretty=expanded $< >$@; \
314314
command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@; \
315315
$(rust_handle_depfile)
316316

@@ -319,15 +319,15 @@ $(obj)/%.rsi: $(src)/%.rs FORCE
319319

320320
quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
321321
cmd_rustc_s_rs = \
322-
$(rust_common_cmd) --emit=dep-info,asm $<; \
322+
$(rust_common_cmd) --emit=asm=$@ $<; \
323323
$(rust_handle_depfile)
324324

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

328328
quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
329329
cmd_rustc_ll_rs = \
330-
$(rust_common_cmd) --emit=dep-info,llvm-ir $<; \
330+
$(rust_common_cmd) --emit=llvm-ir=$@ $<; \
331331
$(rust_handle_depfile)
332332

333333
$(obj)/%.ll: $(src)/%.rs FORCE

scripts/Makefile.host

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

83-
_hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
83+
hostc_flags = -Wp,-MMD,$(depfile) \
84+
$(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
8485
$(HOSTCFLAGS_$(target-stem).o)
85-
_hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
86+
hostcxx_flags = -Wp,-MMD,$(depfile) \
87+
$(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
8688
$(HOSTCXXFLAGS_$(target-stem).o)
87-
_hostrust_flags = $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
88-
$(HOSTRUSTFLAGS_$(target-stem))
89+
hostrust_flags = --emit=dep-info=$(depfile) \
90+
$(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \
91+
$(HOSTRUSTFLAGS_$(target-stem))
8992

9093
# $(objtree)/$(obj) for including generated headers from checkin source files
9194
ifeq ($(KBUILD_EXTMOD),)
9295
ifdef building_out_of_srctree
93-
_hostc_flags += -I $(objtree)/$(obj)
94-
_hostcxx_flags += -I $(objtree)/$(obj)
96+
hostc_flags += -I $(objtree)/$(obj)
97+
hostcxx_flags += -I $(objtree)/$(obj)
9598
endif
9699
endif
97100

98-
hostc_flags = -Wp,-MMD,$(depfile) $(_hostc_flags)
99-
hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags)
100-
hostrust_flags = $(_hostrust_flags)
101-
102101
#####
103102
# Compile programs on the host
104103

@@ -149,9 +148,7 @@ $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
149148
# host-rust -> Executable
150149
quiet_cmd_host-rust = HOSTRUSTC $@
151150
cmd_host-rust = \
152-
$(HOSTRUSTC) $(hostrust_flags) --emit=dep-info,link \
153-
--out-dir=$(obj)/ $<; \
154-
mv $(obj)/$(target-stem).d $(depfile); \
151+
$(HOSTRUSTC) $(hostrust_flags) --emit=link=$@ $<; \
155152
sed -i '/^\#/d' $(depfile)
156153
$(host-rust): $(obj)/%: $(src)/%.rs FORCE
157154
$(call if_changed_dep,host-rust)

scripts/Makefile.lib

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -370,40 +370,25 @@ DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
370370
DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
371371

372372
# Generate an assembly file to wrap the output of the device tree compiler
373-
quiet_cmd_dt_S_dtb= DTBS $@
374-
cmd_dt_S_dtb= \
375-
{ \
376-
echo '\#include <asm-generic/vmlinux.lds.h>'; \
377-
echo '.section .dtb.init.rodata,"a"'; \
378-
echo '.balign STRUCT_ALIGNMENT'; \
379-
echo '.global __dtb_$(subst -,_,$(*F))_begin'; \
380-
echo '__dtb_$(subst -,_,$(*F))_begin:'; \
381-
echo '.incbin "$<" '; \
382-
echo '__dtb_$(subst -,_,$(*F))_end:'; \
383-
echo '.global __dtb_$(subst -,_,$(*F))_end'; \
384-
echo '.balign STRUCT_ALIGNMENT'; \
385-
} > $@
373+
quiet_cmd_wrap_S_dtb = WRAP $@
374+
cmd_wrap_S_dtb = { \
375+
symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \
376+
echo '\#include <asm-generic/vmlinux.lds.h>'; \
377+
echo '.section .dtb.init.rodata,"a"'; \
378+
echo '.balign STRUCT_ALIGNMENT'; \
379+
echo ".global $${symbase}_begin"; \
380+
echo "$${symbase}_begin:"; \
381+
echo '.incbin "$<" '; \
382+
echo ".global $${symbase}_end"; \
383+
echo "$${symbase}_end:"; \
384+
echo '.balign STRUCT_ALIGNMENT'; \
385+
} > $@
386386

387387
$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
388-
$(call if_changed,dt_S_dtb)
389-
390-
# Generate an assembly file to wrap the output of the device tree compiler
391-
quiet_cmd_dt_S_dtbo= DTBOS $@
392-
cmd_dt_S_dtbo= \
393-
{ \
394-
echo '\#include <asm-generic/vmlinux.lds.h>'; \
395-
echo '.section .dtb.init.rodata,"a"'; \
396-
echo '.balign STRUCT_ALIGNMENT'; \
397-
echo '.global __dtbo_$(subst -,_,$(*F))_begin'; \
398-
echo '__dtbo_$(subst -,_,$(*F))_begin:'; \
399-
echo '.incbin "$<" '; \
400-
echo '__dtbo_$(subst -,_,$(*F))_end:'; \
401-
echo '.global __dtbo_$(subst -,_,$(*F))_end'; \
402-
echo '.balign STRUCT_ALIGNMENT'; \
403-
} > $@
388+
$(call if_changed,wrap_S_dtb)
404389

405390
$(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
406-
$(call if_changed,dt_S_dtbo)
391+
$(call if_changed,wrap_S_dtb)
407392

408393
quiet_cmd_dtc = DTC $@
409394
cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \

scripts/Makefile.modfinal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ newer_prereqs_except = $(filter-out $(PHONY) $(1),$?)
5656
# Same as if_changed, but allows to exclude specified extra dependencies
5757
if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \
5858
$(cmd); \
59-
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
59+
printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
6060

6161
# Re-generate module BTFs if either module's .ko or vmlinux changed
6262
%.ko: %.o %.mod.o scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(mixed-build-prefix)vmlinux) FORCE

0 commit comments

Comments
 (0)