1# SPDX-License-Identifier: GPL-2.0 2# ========================================================================== 3# Building 4# ========================================================================== 5 6src := $(obj) 7 8PHONY := __build 9__build: 10 11# Init all relevant variables used in kbuild files so 12# 1) they have correct type 13# 2) they do not inherit any value from the environment 14obj-y := 15obj-m := 16lib-y := 17lib-m := 18always-y := 19always-m := 20targets := 21subdir-y := 22subdir-m := 23EXTRA_AFLAGS := 24EXTRA_CFLAGS := 25EXTRA_CPPFLAGS := 26EXTRA_LDFLAGS := 27asflags-y := 28ccflags-y := 29cppflags-y := 30ldflags-y := 31 32subdir-asflags-y := 33subdir-ccflags-y := 34 35# Read auto.conf if it exists, otherwise ignore 36-include include/config/auto.conf 37 38include $(srctree)/scripts/Kbuild.include 39include $(srctree)/scripts/Makefile.compiler 40 41# The filename Kbuild has precedence over Makefile 42kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) 43include $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile) 44 45include $(srctree)/scripts/Makefile.lib 46 47# Do not include hostprogs rules unless needed. 48# $(sort ...) is used here to remove duplicated words and excessive spaces. 49hostprogs := $(sort $(hostprogs)) 50ifneq ($(hostprogs),) 51include $(srctree)/scripts/Makefile.host 52endif 53 54# Do not include userprogs rules unless needed. 55# $(sort ...) is used here to remove duplicated words and excessive spaces. 56userprogs := $(sort $(userprogs)) 57ifneq ($(userprogs),) 58include $(srctree)/scripts/Makefile.userprogs 59endif 60 61ifndef obj 62$(warning kbuild: Makefile.build is included improperly) 63endif 64 65ifeq ($(need-modorder),) 66ifneq ($(obj-m),) 67$(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.) 68$(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.) 69endif 70endif 71 72# =========================================================================== 73 74# subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...) 75subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y))) 76subdir-modorder := $(sort $(filter %/modules.order, $(obj-m))) 77 78targets-for-builtin := $(extra-y) 79 80ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) 81targets-for-builtin += $(obj)/lib.a 82endif 83 84ifdef need-builtin 85targets-for-builtin += $(obj)/built-in.a 86endif 87 88targets-for-modules := $(foreach x, o mod $(if $(CONFIG_TRIM_UNUSED_KSYMS), usyms), \ 89 $(patsubst %.o, %.$x, $(filter %.o, $(obj-m)))) 90 91ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 92targets-for-modules += $(patsubst %.o, %.prelink.o, $(filter %.o, $(obj-m))) 93endif 94 95ifdef need-modorder 96targets-for-modules += $(obj)/modules.order 97endif 98 99targets += $(targets-for-builtin) $(targets-for-modules) 100 101# Linus' kernel sanity checking tool 102ifeq ($(KBUILD_CHECKSRC),1) 103 quiet_cmd_checksrc = CHECK $< 104 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< 105else ifeq ($(KBUILD_CHECKSRC),2) 106 quiet_cmd_force_checksrc = CHECK $< 107 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< 108endif 109 110ifneq ($(KBUILD_EXTRA_WARN),) 111 cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $< 112endif 113 114# Compile C sources (.c) 115# --------------------------------------------------------------------------- 116 117quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ 118 cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $< 119 120$(obj)/%.s: $(src)/%.c FORCE 121 $(call if_changed_dep,cc_s_c) 122 123quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@ 124cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< 125 126$(obj)/%.i: $(src)/%.c FORCE 127 $(call if_changed_dep,cpp_i_c) 128 129genksyms = scripts/genksyms/genksyms \ 130 $(if $(1), -T $(2)) \ 131 $(if $(CONFIG_MODULE_REL_CRCS), -R) \ 132 $(if $(KBUILD_PRESERVE), -p) \ 133 -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null) 134 135# These mirror gensymtypes_S and co below, keep them in synch. 136cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms) 137 138quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 139 cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@) >/dev/null 140 141$(obj)/%.symtypes : $(src)/%.c FORCE 142 $(call cmd,cc_symtypes_c) 143 144# LLVM assembly 145# Generate .ll files from .c 146quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@ 147 cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -o $@ $< 148 149$(obj)/%.ll: $(src)/%.c FORCE 150 $(call if_changed_dep,cc_ll_c) 151 152# C (.c) files 153# The C file is compiled and updated dependency information is generated. 154# (See cmd_cc_o_c + relevant part of rule_cc_o_c) 155 156quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ 157 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< $(cmd_objtool) 158 159ifdef CONFIG_MODVERSIONS 160# When module versioning is enabled the following steps are executed: 161# o compile a <file>.o from <file>.c 162# o if <file>.o doesn't contain a __ksymtab version, i.e. does 163# not export symbols, it's done. 164# o otherwise, we calculate symbol versions using the good old 165# genksyms on the preprocessed source and postprocess them in a way 166# that they are usable as a linker script 167# o generate .tmp_<file>.o from <file>.o using the linker to 168# replace the unresolved symbols __crc_exported_symbol with 169# the actual value of the checksum generated by genksyms 170# o remove .tmp_<file>.o to <file>.o 171 172# Generate .o.symversions files for each .o with exported symbols, and link these 173# to the kernel and/or modules at the end. 174gen_symversions = \ 175 if $(NM) $@ 2>/dev/null | grep -q __ksymtab; then \ 176 $(call cmd_gensymtypes_$(1),$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 177 > $@.symversions; \ 178 else \ 179 rm -f $@.symversions; \ 180 fi 181 182cmd_gen_symversions_c = $(call gen_symversions,c) 183 184cmd_modversions = \ 185 if [ -r $@.symversions ]; then \ 186 $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ 187 -T $@.symversions; \ 188 mv -f $(@D)/.tmp_$(@F) $@; \ 189 fi 190endif 191 192ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 193# compiler will not generate __mcount_loc use recordmcount or recordmcount.pl 194ifdef BUILD_C_RECORDMCOUNT 195ifeq ("$(origin RECORDMCOUNT_WARN)", "command line") 196 RECORDMCOUNT_FLAGS = -w 197endif 198# Due to recursion, we must skip empty.o. 199# The empty.o file is created in the make process in order to determine 200# the target endianness and word size. It is made before all other C 201# files, including recordmcount. 202sub_cmd_record_mcount = \ 203 if [ $(@) != "scripts/mod/empty.o" ]; then \ 204 $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ 205 fi; 206recordmcount_source := $(srctree)/scripts/recordmcount.c \ 207 $(srctree)/scripts/recordmcount.h 208else 209sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ 210 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ 211 "$(if $(CONFIG_64BIT),64,32)" \ 212 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \ 213 "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ 214 "$(if $(part-of-module),1,0)" "$(@)"; 215recordmcount_source := $(srctree)/scripts/recordmcount.pl 216endif # BUILD_C_RECORDMCOUNT 217cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \ 218 $(sub_cmd_record_mcount)) 219endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 220 221ifdef CONFIG_STACK_VALIDATION 222 223objtool := $(objtree)/tools/objtool/objtool 224 225objtool_args = \ 226 $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \ 227 $(if $(part-of-module), --module) \ 228 $(if $(CONFIG_X86_KERNEL_IBT), --lto --ibt) \ 229 $(if $(CONFIG_FRAME_POINTER),, --no-fp) \ 230 $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\ 231 $(if $(CONFIG_RETPOLINE), --retpoline) \ 232 $(if $(CONFIG_X86_SMAP), --uaccess) \ 233 $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ 234 $(if $(CONFIG_SLS), --sls) 235 236cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) 237cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) 238 239endif # CONFIG_STACK_VALIDATION 240 241ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 242 243# Skip objtool for LLVM bitcode 244$(obj)/%.o: objtool-enabled := 245 246else 247 248# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory 249# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file 250# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file 251 252$(obj)/%.o: objtool-enabled = $(if $(filter-out y%, \ 253 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y) 254 255endif 256 257ifdef CONFIG_TRIM_UNUSED_KSYMS 258cmd_gen_ksymdeps = \ 259 $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd 260endif 261 262define rule_cc_o_c 263 $(call cmd_and_fixdep,cc_o_c) 264 $(call cmd,gen_ksymdeps) 265 $(call cmd,checksrc) 266 $(call cmd,checkdoc) 267 $(call cmd,gen_objtooldep) 268 $(call cmd,gen_symversions_c) 269 $(if $(CONFIG_LTO_CLANG),,$(call cmd,modversions)) 270 $(call cmd,record_mcount) 271endef 272 273define rule_as_o_S 274 $(call cmd_and_fixdep,as_o_S) 275 $(call cmd,gen_ksymdeps) 276 $(call cmd,gen_objtooldep) 277 $(call cmd,gen_symversions_S) 278 $(call cmd,modversions) 279endef 280 281# Built-in and composite module parts 282$(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE 283 $(call if_changed_rule,cc_o_c) 284 $(call cmd,force_checksrc) 285 286ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 287# Module .o files may contain LLVM bitcode, compile them into native code 288# before ELF processing 289quiet_cmd_cc_prelink_modules = LD [M] $@ 290 cmd_cc_prelink_modules = \ 291 $(LD) $(ld_flags) -r -o $@ \ 292 $(shell [ -s $(@:.prelink.o=.o.symversions) ] && \ 293 echo -T $(@:.prelink.o=.o.symversions)) \ 294 --whole-archive $(filter-out FORCE,$^) \ 295 $(cmd_objtool) 296 297# objtool was skipped for LLVM bitcode, run it now that we have compiled 298# modules into native code 299$(obj)/%.prelink.o: objtool-enabled = y 300$(obj)/%.prelink.o: part-of-module := y 301 302$(obj)/%.prelink.o: $(obj)/%.o FORCE 303 $(call if_changed,cc_prelink_modules) 304endif 305 306cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \ 307 $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@ 308 309$(obj)/%.mod: FORCE 310 $(call if_changed,mod) 311 312# List module undefined symbols 313cmd_undefined_syms = $(NM) $< | sed -n 's/^ *U //p' > $@ 314 315$(obj)/%.usyms: $(obj)/%$(mod-prelink-ext).o FORCE 316 $(call if_changed,undefined_syms) 317 318quiet_cmd_cc_lst_c = MKLST $@ 319 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ 320 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ 321 System.map $(OBJDUMP) > $@ 322 323$(obj)/%.lst: $(src)/%.c FORCE 324 $(call if_changed_dep,cc_lst_c) 325 326# Compile assembler sources (.S) 327# --------------------------------------------------------------------------- 328 329# .S file exports must have their C prototypes defined in asm/asm-prototypes.h 330# or a file that it includes, in order to get versioned symbols. We build a 331# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from 332# the .S file (with trailing ';'), and run genksyms on that, to extract vers. 333# 334# This is convoluted. The .S file must first be preprocessed to run guards and 335# expand names, then the resulting exports must be constructed into plain 336# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed 337# to make the genksyms input. 338# 339# These mirror gensymtypes_c and co above, keep them in synch. 340cmd_gensymtypes_S = \ 341 { echo "\#include <linux/kernel.h>" ; \ 342 echo "\#include <asm/asm-prototypes.h>" ; \ 343 $(CPP) $(a_flags) $< | \ 344 grep "\<___EXPORT_SYMBOL\>" | \ 345 sed 's/.*___EXPORT_SYMBOL[[:space:]]*\([a-zA-Z0-9_]*\)[[:space:]]*,.*/EXPORT_SYMBOL(\1);/' ; } | \ 346 $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) 347 348quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@ 349 cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null 350 351$(obj)/%.symtypes : $(src)/%.S FORCE 352 $(call cmd,cc_symtypes_S) 353 354 355quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@ 356cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $< 357 358$(obj)/%.s: $(src)/%.S FORCE 359 $(call if_changed_dep,cpp_s_S) 360 361quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 362 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool) 363 364ifdef CONFIG_ASM_MODVERSIONS 365 366# versioning matches the C process described above, with difference that 367# we parse asm-prototypes.h C header to get function definitions. 368 369cmd_gen_symversions_S = $(call gen_symversions,S) 370 371endif 372 373$(obj)/%.o: $(src)/%.S FORCE 374 $(call if_changed_rule,as_o_S) 375 376targets += $(filter-out $(subdir-builtin), $(real-obj-y)) 377targets += $(filter-out $(subdir-modorder), $(real-obj-m)) 378targets += $(real-dtb-y) $(lib-y) $(always-y) $(MAKECMDGOALS) 379 380# Linker scripts preprocessor (.lds.S -> .lds) 381# --------------------------------------------------------------------------- 382quiet_cmd_cpp_lds_S = LDS $@ 383 cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \ 384 -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< 385 386$(obj)/%.lds: $(src)/%.lds.S FORCE 387 $(call if_changed_dep,cpp_lds_S) 388 389# ASN.1 grammar 390# --------------------------------------------------------------------------- 391quiet_cmd_asn1_compiler = ASN.1 $(basename $@).[ch] 392 cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \ 393 $(basename $@).c $(basename $@).h 394 395$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler 396 $(call cmd,asn1_compiler) 397 398# Build the compiled-in targets 399# --------------------------------------------------------------------------- 400 401# To build objects in subdirs, we need to descend into the directories 402$(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ; 403$(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ; 404 405# combine symversions for later processing 406ifeq ($(CONFIG_LTO_CLANG) $(CONFIG_MODVERSIONS),y y) 407 cmd_update_lto_symversions = \ 408 rm -f $@.symversions \ 409 $(foreach n, $(filter-out FORCE,$^), \ 410 $(if $(shell test -s $(n).symversions && echo y), \ 411 ; cat $(n).symversions >> $@.symversions)) 412else 413 cmd_update_lto_symversions = echo >/dev/null 414endif 415 416# 417# Rule to compile a set of .o files into one .a file (without symbol table) 418# 419 420quiet_cmd_ar_builtin = AR $@ 421 cmd_ar_builtin = rm -f $@; $(AR) cDPrST $@ $(real-prereqs) 422 423quiet_cmd_ar_and_symver = AR $@ 424 cmd_ar_and_symver = $(cmd_update_lto_symversions); $(cmd_ar_builtin) 425 426$(obj)/built-in.a: $(real-obj-y) FORCE 427 $(call if_changed,ar_and_symver) 428 429# 430# Rule to create modules.order file 431# 432# Create commands to either record .ko file or cat modules.order from 433# a subdirectory 434# Add $(obj-m) as the prerequisite to avoid updating the timestamp of 435# modules.order unless contained modules are updated. 436 437cmd_modules_order = { $(foreach m, $(real-prereqs), \ 438 $(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \ 439 | $(AWK) '!x[$$0]++' - > $@ 440 441$(obj)/modules.order: $(obj-m) FORCE 442 $(call if_changed,modules_order) 443 444# 445# Rule to compile a set of .o files into one .a file (with symbol table) 446# 447quiet_cmd_ar_lib = AR $@ 448 cmd_ar_lib = $(cmd_update_lto_symversions); $(cmd_ar) 449 450$(obj)/lib.a: $(lib-y) FORCE 451 $(call if_changed,ar_lib) 452 453ifneq ($(CONFIG_LTO_CLANG)$(CONFIG_X86_KERNEL_IBT),) 454quiet_cmd_link_multi-m = AR [M] $@ 455cmd_link_multi-m = \ 456 $(cmd_update_lto_symversions); \ 457 rm -f $@; \ 458 $(AR) cDPrsT $@ @$(patsubst %.o,%.mod,$@) 459else 460quiet_cmd_link_multi-m = LD [M] $@ 461 cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ @$(patsubst %.o,%.mod,$@) 462endif 463 464$(multi-obj-m): %.o: %.mod FORCE 465 $(call if_changed,link_multi-m) 466$(call multi_depend, $(multi-obj-m), .o, -objs -y -m) 467 468targets := $(filter-out $(PHONY), $(targets)) 469 470# Add intermediate targets: 471# When building objects with specific suffix patterns, add intermediate 472# targets that the final targets are derived from. 473intermediate_targets = $(foreach sfx, $(2), \ 474 $(patsubst %$(strip $(1)),%$(sfx), \ 475 $(filter %$(strip $(1)), $(targets)))) 476# %.asn1.o <- %.asn1.[ch] <- %.asn1 477# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts 478# %.lex.o <- %.lex.c <- %.l 479# %.tab.o <- %.tab.[ch] <- %.y 480targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \ 481 $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \ 482 $(call intermediate_targets, .lex.o, .lex.c) \ 483 $(call intermediate_targets, .tab.o, .tab.c .tab.h) 484 485# Build 486# --------------------------------------------------------------------------- 487 488ifdef single-build 489 490KBUILD_SINGLE_TARGETS := $(filter $(obj)/%, $(KBUILD_SINGLE_TARGETS)) 491 492curdir-single := $(sort $(foreach x, $(KBUILD_SINGLE_TARGETS), \ 493 $(if $(filter $(x) $(basename $(x)).o, $(targets)), $(x)))) 494 495# Handle single targets without any rule: show "Nothing to be done for ..." or 496# "No rule to make target ..." depending on whether the target exists. 497unknown-single := $(filter-out $(addsuffix /%, $(subdir-ym)), \ 498 $(filter-out $(curdir-single), $(KBUILD_SINGLE_TARGETS))) 499 500single-subdirs := $(foreach d, $(subdir-ym), \ 501 $(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d))) 502 503__build: $(curdir-single) $(single-subdirs) 504ifneq ($(unknown-single),) 505 $(Q)$(MAKE) -f /dev/null $(unknown-single) 506endif 507 @: 508 509ifeq ($(curdir-single),) 510# Nothing to do in this directory. Do not include any .*.cmd file for speed-up 511targets := 512else 513targets += $(curdir-single) 514endif 515 516else 517 518__build: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ 519 $(if $(KBUILD_MODULES), $(targets-for-modules)) \ 520 $(subdir-ym) $(always-y) 521 @: 522 523endif 524 525# Descending 526# --------------------------------------------------------------------------- 527 528PHONY += $(subdir-ym) 529$(subdir-ym): 530 $(Q)$(MAKE) $(build)=$@ \ 531 $(if $(filter $@/, $(KBUILD_SINGLE_TARGETS)),single-build=) \ 532 need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \ 533 need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1) 534 535# Add FORCE to the prequisites of a target to force it to be always rebuilt. 536# --------------------------------------------------------------------------- 537 538PHONY += FORCE 539 540FORCE: 541 542# Read all saved command lines and dependencies for the $(targets) we 543# may be building above, using $(if_changed{,_dep}). As an 544# optimization, we don't need to read them if the target does not 545# exist, we will rebuild anyway in that case. 546 547existing-targets := $(wildcard $(sort $(targets))) 548 549-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 550 551# Create directories for object files if they do not exist 552obj-dirs := $(sort $(patsubst %/,%, $(dir $(targets)))) 553# If targets exist, their directories apparently exist. Skip mkdir. 554existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets)))) 555obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs))) 556ifneq ($(obj-dirs),) 557$(shell mkdir -p $(obj-dirs)) 558endif 559 560.PHONY: $(PHONY) 561