1# SPDX-License-Identifier: GPL-2.0 2# ========================================================================== 3# Building 4# ========================================================================== 5 6src := $(if $(VPATH),$(VPATH)/)$(obj) 7 8PHONY := $(obj)/ 9$(obj)/: 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 := 29rustflags-y := 30cppflags-y := 31ldflags-y := 32 33subdir-asflags-y := 34subdir-ccflags-y := 35 36# Read auto.conf if it exists, otherwise ignore 37-include $(objtree)/include/config/auto.conf 38 39include $(srctree)/scripts/Kbuild.include 40include $(srctree)/scripts/Makefile.compiler 41include $(kbuild-file) 42include $(srctree)/scripts/Makefile.lib 43 44ifndef obj 45$(warning kbuild: Makefile.build is included improperly) 46endif 47 48ifeq ($(need-modorder),) 49ifneq ($(obj-m),) 50$(warning $(patsubst %.o,'%.ko',$(obj-m)) will not be built even though obj-m is specified.) 51$(warning You cannot use subdir-y/m to visit a module Makefile. Use obj-y/m instead.) 52endif 53endif 54 55# =========================================================================== 56 57# subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...) 58subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y))) 59subdir-modorder := $(sort $(filter %/modules.order, $(obj-m))) 60 61targets-for-builtin := $(extra-y) 62 63ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),) 64targets-for-builtin += $(obj)/lib.a 65endif 66 67ifdef need-builtin 68targets-for-builtin += $(obj)/built-in.a 69endif 70 71targets-for-modules := $(foreach x, o mod, \ 72 $(patsubst %.o, %.$x, $(filter %.o, $(obj-m)))) 73 74ifdef need-modorder 75targets-for-modules += $(obj)/modules.order 76endif 77 78targets += $(targets-for-builtin) $(targets-for-modules) 79 80# Linus' kernel sanity checking tool 81ifeq ($(KBUILD_CHECKSRC),1) 82 quiet_cmd_checksrc = CHECK $< 83 cmd_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< 84else ifeq ($(KBUILD_CHECKSRC),2) 85 quiet_cmd_force_checksrc = CHECK $< 86 cmd_force_checksrc = $(CHECK) $(CHECKFLAGS) $(c_flags) $< 87endif 88 89ifneq ($(KBUILD_EXTRA_WARN),) 90 cmd_checkdoc = $(srctree)/scripts/kernel-doc -none $(KDOCFLAGS) \ 91 $(if $(findstring 2, $(KBUILD_EXTRA_WARN)), -Wall) \ 92 $< 93endif 94 95# Compile C sources (.c) 96# --------------------------------------------------------------------------- 97 98quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ 99 cmd_cc_s_c = $(CC) $(filter-out $(DEBUG_CFLAGS) $(CC_FLAGS_LTO), $(c_flags)) -fverbose-asm -S -o $@ $< 100 101$(obj)/%.s: $(obj)/%.c FORCE 102 $(call if_changed_dep,cc_s_c) 103 104quiet_cmd_cpp_i_c = CPP $(quiet_modtag) $@ 105cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $< 106 107$(obj)/%.i: $(obj)/%.c FORCE 108 $(call if_changed_dep,cpp_i_c) 109 110getexportsymbols = $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/$(1)/p' 111 112gendwarfksyms = $(objtree)/scripts/gendwarfksyms/gendwarfksyms \ 113 $(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes)) \ 114 $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable) 115 116genksyms = $(objtree)/scripts/genksyms/genksyms \ 117 $(if $(1), -T $(2)) \ 118 $(if $(KBUILD_PRESERVE), -p) \ 119 -r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null) 120 121# These mirror gensymtypes_S and co below, keep them in synch. 122ifdef CONFIG_GENDWARFKSYMS 123cmd_gensymtypes_c = $(if $(skip_gendwarfksyms),, \ 124 $(call getexportsymbols,\1) | $(gendwarfksyms) $@) 125else 126cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms) 127endif # CONFIG_GENDWARFKSYMS 128 129quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 130 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 135# LLVM assembly 136# Generate .ll files from .c 137quiet_cmd_cc_ll_c = CC $(quiet_modtag) $@ 138 cmd_cc_ll_c = $(CC) $(c_flags) -emit-llvm -S -fno-discard-value-names -o $@ $< 139 140$(obj)/%.ll: $(obj)/%.c FORCE 141 $(call if_changed_dep,cc_ll_c) 142 143# C (.c) files 144# The C file is compiled and updated dependency information is generated. 145# (See cmd_cc_o_c + relevant part of rule_cc_o_c) 146 147is-single-obj-m = $(and $(part-of-module),$(filter $@, $(obj-m)),y) 148 149# When a module consists of a single object, there is no reason to keep LLVM IR. 150# Make $(LD) covert LLVM IR to ELF here. 151ifdef CONFIG_LTO_CLANG 152cmd_ld_single_m = $(if $(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@) 153endif 154 155quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ 156 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \ 157 $(cmd_ld_single_m) \ 158 $(cmd_objtool) 159 160ifdef CONFIG_MODVERSIONS 161# When module versioning is enabled the following steps are executed: 162# o compile a <file>.o from <file>.c 163# o if <file>.o doesn't contain a __export_symbol_*, i.e. does 164# not export symbols, it's done. 165# o otherwise, we calculate symbol versions using the good old 166# genksyms on the preprocessed source and dump them into the .cmd file. 167# o modpost will extract versions from that file and create *.c files that will 168# be compiled and linked to the kernel and/or modules. 169 170gen_symversions = \ 171 if $(NM) $@ 2>/dev/null | grep -q ' __export_symbol_'; then \ 172 $(call cmd_gensymtypes_$(1),$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 173 >> $(dot-target).cmd; \ 174 fi 175 176cmd_gen_symversions_c = $(call gen_symversions,c) 177 178endif 179 180ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 181# compiler will not generate __mcount_loc use recordmcount or recordmcount.pl 182ifdef BUILD_C_RECORDMCOUNT 183ifeq ("$(origin RECORDMCOUNT_WARN)", "command line") 184 RECORDMCOUNT_FLAGS = -w 185endif 186# Due to recursion, we must skip empty.o. 187# The empty.o file is created in the make process in order to determine 188# the target endianness and word size. It is made before all other C 189# files, including recordmcount. 190sub_cmd_record_mcount = \ 191 if [ $(@) != "scripts/mod/empty.o" ]; then \ 192 $(objtree)/scripts/recordmcount $(RECORDMCOUNT_FLAGS) "$(@)"; \ 193 fi; 194recordmcount_source := $(srctree)/scripts/recordmcount.c \ 195 $(srctree)/scripts/recordmcount.h 196else 197sub_cmd_record_mcount = perl $(srctree)/scripts/recordmcount.pl "$(ARCH)" \ 198 "$(if $(CONFIG_CPU_BIG_ENDIAN),big,little)" \ 199 "$(if $(CONFIG_64BIT),64,32)" \ 200 "$(OBJDUMP)" "$(OBJCOPY)" "$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)" \ 201 "$(LD) $(KBUILD_LDFLAGS)" "$(NM)" "$(RM)" "$(MV)" \ 202 "$(if $(part-of-module),1,0)" "$(@)"; 203recordmcount_source := $(srctree)/scripts/recordmcount.pl 204endif # BUILD_C_RECORDMCOUNT 205cmd_record_mcount = $(if $(findstring $(strip $(CC_FLAGS_FTRACE)),$(_c_flags)), \ 206 $(sub_cmd_record_mcount)) 207endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 208 209# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory 210# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file 211# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file 212 213is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),$(is-kernel-object)) 214 215$(obj)/%.o: private objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y)) 216 217ifneq ($(findstring 1, $(KBUILD_EXTRA_WARN)),) 218cmd_warn_shared_object = $(if $(word 2, $(modname-multi)),$(warning $(kbuild-file): $*.o is added to multiple modules: $(modname-multi))) 219endif 220 221define rule_cc_o_c 222 $(call cmd_and_fixdep,cc_o_c) 223 $(call cmd,checksrc) 224 $(call cmd,checkdoc) 225 $(call cmd,gen_objtooldep) 226 $(call cmd,gen_symversions_c) 227 $(call cmd,record_mcount) 228 $(call cmd,warn_shared_object) 229endef 230 231define rule_as_o_S 232 $(call cmd_and_fixdep,as_o_S) 233 $(call cmd,gen_objtooldep) 234 $(call cmd,gen_symversions_S) 235 $(call cmd,warn_shared_object) 236endef 237 238# Built-in and composite module parts 239$(obj)/%.o: $(obj)/%.c $(recordmcount_source) FORCE 240 $(call if_changed_rule,cc_o_c) 241 $(call cmd,force_checksrc) 242 243# To make this rule robust against "Argument list too long" error, 244# ensure to add $(obj)/ prefix by a shell command. 245cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \ 246 $(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@ 247 248$(obj)/%.mod: FORCE 249 $(call if_changed,mod) 250 251quiet_cmd_cc_lst_c = MKLST $@ 252 cmd_cc_lst_c = $(CC) $(c_flags) -g -c -o $*.o $< && \ 253 $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ 254 System.map $(OBJDUMP) > $@ 255 256$(obj)/%.lst: $(obj)/%.c FORCE 257 $(call if_changed_dep,cc_lst_c) 258 259# Compile Rust sources (.rs) 260# --------------------------------------------------------------------------- 261 262rust_allowed_features := arbitrary_self_types,asm_const,asm_goto,lint_reasons,used_with_arg 263 264# `--out-dir` is required to avoid temporaries being created by `rustc` in the 265# current working directory, which may be not accessible in the out-of-tree 266# modules case. 267rust_common_cmd = \ 268 OBJTREE=$(abspath $(objtree)) \ 269 RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \ 270 -Zallow-features=$(rust_allowed_features) \ 271 -Zcrate-attr=no_std \ 272 -Zcrate-attr='feature($(rust_allowed_features))' \ 273 -Zunstable-options --extern kernel \ 274 --crate-type rlib -L $(objtree)/rust/ \ 275 --crate-name $(basename $(notdir $@)) \ 276 --sysroot=/dev/null \ 277 --out-dir $(dir $@) --emit=dep-info=$(depfile) 278 279# `--emit=obj`, `--emit=asm` and `--emit=llvm-ir` imply a single codegen unit 280# will be used. We explicitly request `-Ccodegen-units=1` in any case, and 281# the compiler shows a warning if it is not 1. However, if we ever stop 282# requesting it explicitly and we start using some other `--emit` that does not 283# imply it (and for which codegen is performed), then we would be out of sync, 284# i.e. the outputs we would get for the different single targets (e.g. `.ll`) 285# would not match each other. 286 287quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 288 cmd_rustc_o_rs = $(rust_common_cmd) --emit=obj=$@ $< $(cmd_objtool) 289 290define rule_rustc_o_rs 291 $(call cmd_and_fixdep,rustc_o_rs) 292 $(call cmd,gen_objtooldep) 293endef 294 295$(obj)/%.o: $(obj)/%.rs FORCE 296 +$(call if_changed_rule,rustc_o_rs) 297 298quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 299 cmd_rustc_rsi_rs = \ 300 $(rust_common_cmd) -Zunpretty=expanded $< >$@; \ 301 command -v $(RUSTFMT) >/dev/null && $(RUSTFMT) $@ 302 303$(obj)/%.rsi: $(obj)/%.rs FORCE 304 +$(call if_changed_dep,rustc_rsi_rs) 305 306quiet_cmd_rustc_s_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 307 cmd_rustc_s_rs = $(rust_common_cmd) --emit=asm=$@ $< 308 309$(obj)/%.s: $(obj)/%.rs FORCE 310 +$(call if_changed_dep,rustc_s_rs) 311 312quiet_cmd_rustc_ll_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@ 313 cmd_rustc_ll_rs = $(rust_common_cmd) --emit=llvm-ir=$@ $< 314 315$(obj)/%.ll: $(obj)/%.rs FORCE 316 +$(call if_changed_dep,rustc_ll_rs) 317 318quiet_cmd_rustc_rs_rs_S = RSCPP $(quiet_modtag) $@ 319 cmd_rustc_rs_rs_S = $(CPP) $(c_flags) -xc -C -P $< | sed '1,/^\/\/ Cut here.$$/d' >$@ 320 321$(obj)/%.rs: $(obj)/%.rs.S FORCE 322 +$(call if_changed_dep,rustc_rs_rs_S) 323 324# Compile assembler sources (.S) 325# --------------------------------------------------------------------------- 326 327# .S file exports must have their C prototypes defined in asm/asm-prototypes.h 328# or a file that it includes, in order to get versioned symbols. We build a 329# dummy C file that includes asm-prototypes and the EXPORT_SYMBOL lines from 330# the .S file (with trailing ';'), and run genksyms on that, to extract vers. 331# 332# This is convoluted. The .S file must first be preprocessed to run guards and 333# expand names, then the resulting exports must be constructed into plain 334# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed 335# to make the genksyms input or compiled into an object for gendwarfksyms. 336# 337# These mirror gensymtypes_c and co above, keep them in synch. 338getasmexports = \ 339 { echo "\#include <linux/kernel.h>" ; \ 340 echo "\#include <linux/string.h>" ; \ 341 echo "\#include <asm/asm-prototypes.h>" ; \ 342 $(call getexportsymbols,EXPORT_SYMBOL(\1);) ; } 343 344ifdef CONFIG_GENDWARFKSYMS 345cmd_gensymtypes_S = \ 346 $(getasmexports) | \ 347 $(CC) $(c_flags) -c -o $(@:.o=.gendwarfksyms.o) -xc -; \ 348 $(call getexportsymbols,\1) | \ 349 $(gendwarfksyms) $(@:.o=.gendwarfksyms.o) 350else 351cmd_gensymtypes_S = \ 352 $(getasmexports) | \ 353 $(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms) 354endif # CONFIG_GENDWARFKSYMS 355 356quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@ 357 cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null 358 359$(obj)/%.symtypes : $(obj)/%.S FORCE 360 $(call cmd,cc_symtypes_S) 361 362 363quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@ 364cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $< 365 366$(obj)/%.s: $(obj)/%.S FORCE 367 $(call if_changed_dep,cpp_s_S) 368 369quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 370 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool) 371 372ifdef CONFIG_ASM_MODVERSIONS 373 374# versioning matches the C process described above, with difference that 375# we parse asm-prototypes.h C header to get function definitions. 376 377cmd_gen_symversions_S = $(call gen_symversions,S) 378 379endif 380 381$(obj)/%.o: $(obj)/%.S FORCE 382 $(call if_changed_rule,as_o_S) 383 384targets += $(filter-out $(subdir-builtin), $(real-obj-y)) 385targets += $(filter-out $(subdir-modorder), $(real-obj-m)) 386targets += $(lib-y) $(always-y) 387 388# Linker scripts preprocessor (.lds.S -> .lds) 389# --------------------------------------------------------------------------- 390quiet_cmd_cpp_lds_S = LDS $@ 391 cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -U$(ARCH) \ 392 -D__ASSEMBLY__ -DLINKER_SCRIPT -o $@ $< 393 394$(obj)/%.lds: $(src)/%.lds.S FORCE 395 $(call if_changed_dep,cpp_lds_S) 396 397# ASN.1 grammar 398# --------------------------------------------------------------------------- 399quiet_cmd_asn1_compiler = ASN.1 $(basename $@).[ch] 400 cmd_asn1_compiler = $(objtree)/scripts/asn1_compiler $< \ 401 $(basename $@).c $(basename $@).h 402 403$(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler 404 $(call cmd,asn1_compiler) 405 406# Build the compiled-in targets 407# --------------------------------------------------------------------------- 408 409# To build objects in subdirs, we need to descend into the directories 410$(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ; 411$(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ; 412 413# 414# Rule to compile a set of .o files into one .a file (without symbol table) 415# 416# To make this rule robust against "Argument list too long" error, 417# remove $(obj)/ prefix, and restore it by a shell command. 418 419quiet_cmd_ar_builtin = AR $@ 420 cmd_ar_builtin = rm -f $@; \ 421 $(if $(real-prereqs), printf "$(obj)/%s " $(patsubst $(obj)/%,%,$(real-prereqs)) | xargs) \ 422 $(AR) cDPrST $@ 423 424$(obj)/built-in.a: $(real-obj-y) FORCE 425 $(call if_changed,ar_builtin) 426 427# This is a list of build artifacts from the current Makefile and its 428# sub-directories. The timestamp should be updated when any of the member files. 429 430cmd_gen_order = { $(foreach m, $(real-prereqs), \ 431 $(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \ 432 > $@ 433 434$(obj)/modules.order: $(obj-m) FORCE 435 $(call if_changed,gen_order) 436 437# 438# Rule to compile a set of .o files into one .a file (with symbol table) 439# 440 441$(obj)/lib.a: $(lib-y) FORCE 442 $(call if_changed,ar) 443 444quiet_cmd_ld_multi_m = LD [M] $@ 445 cmd_ld_multi_m = $(LD) $(ld_flags) -r -o $@ @$< $(cmd_objtool) 446 447define rule_ld_multi_m 448 $(call cmd_and_savecmd,ld_multi_m) 449 $(call cmd,gen_objtooldep) 450endef 451 452$(multi-obj-m): private objtool-enabled := $(delay-objtool) 453$(multi-obj-m): private part-of-module := y 454$(multi-obj-m): %.o: %.mod FORCE 455 $(call if_changed_rule,ld_multi_m) 456$(call multi_depend, $(multi-obj-m), .o, -objs -y -m) 457 458# Add intermediate targets: 459# When building objects with specific suffix patterns, add intermediate 460# targets that the final targets are derived from. 461intermediate_targets = $(foreach sfx, $(2), \ 462 $(patsubst %$(strip $(1)),%$(sfx), \ 463 $(filter %$(strip $(1)), $(targets)))) 464# %.asn1.o <- %.asn1.[ch] <- %.asn1 465targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) 466 467# Include additional build rules when necessary 468# --------------------------------------------------------------------------- 469 470# $(sort ...) is used here to remove duplicated words and excessive spaces. 471hostprogs := $(sort $(hostprogs)) 472ifneq ($(hostprogs),) 473include $(srctree)/scripts/Makefile.host 474endif 475 476# $(sort ...) is used here to remove duplicated words and excessive spaces. 477userprogs := $(sort $(userprogs)) 478ifneq ($(userprogs),) 479include $(srctree)/scripts/Makefile.userprogs 480endif 481 482ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),) 483include $(srctree)/scripts/Makefile.dtbs 484endif 485 486# Build 487# --------------------------------------------------------------------------- 488 489$(obj)/: $(if $(KBUILD_BUILTIN), $(targets-for-builtin)) \ 490 $(if $(KBUILD_MODULES), $(targets-for-modules)) \ 491 $(subdir-ym) $(always-y) 492 @: 493 494# Single targets 495# --------------------------------------------------------------------------- 496 497single-subdirs := $(foreach d, $(subdir-ym), $(if $(filter $d/%, $(MAKECMDGOALS)), $d)) 498single-subdir-goals := $(filter $(addsuffix /%, $(single-subdirs)), $(MAKECMDGOALS)) 499 500$(single-subdir-goals): $(single-subdirs) 501 @: 502 503# Descending 504# --------------------------------------------------------------------------- 505 506PHONY += $(subdir-ym) 507$(subdir-ym): 508 $(Q)$(MAKE) $(build)=$@ \ 509 need-builtin=$(if $(filter $@/built-in.a, $(subdir-builtin)),1) \ 510 need-modorder=$(if $(filter $@/modules.order, $(subdir-modorder)),1) \ 511 $(filter $@/%, $(single-subdir-goals)) 512 513# Add FORCE to the prerequisites of a target to force it to be always rebuilt. 514# --------------------------------------------------------------------------- 515 516PHONY += FORCE 517 518FORCE: 519 520targets += $(filter-out $(single-subdir-goals), $(MAKECMDGOALS)) 521targets := $(filter-out $(PHONY), $(targets)) 522 523# Read all saved command lines and dependencies for the $(targets) we 524# may be building above, using $(if_changed{,_dep}). As an 525# optimization, we don't need to read them if the target does not 526# exist, we will rebuild anyway in that case. 527 528existing-targets := $(wildcard $(sort $(targets))) 529 530-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 531 532# Create directories for object files if they do not exist 533obj-dirs := $(sort $(patsubst %/,%, $(dir $(targets)))) 534# If targets exist, their directories apparently exist. Skip mkdir. 535existing-dirs := $(sort $(patsubst %/,%, $(dir $(existing-targets)))) 536obj-dirs := $(strip $(filter-out $(existing-dirs), $(obj-dirs))) 537ifneq ($(obj-dirs),) 538$(shell mkdir -p $(obj-dirs)) 539endif 540 541.PHONY: $(PHONY) 542