18c2ecf20Sopenharmony_ci### 28c2ecf20Sopenharmony_ci# build: Generic definitions 38c2ecf20Sopenharmony_ci# 48c2ecf20Sopenharmony_ci# Lots of this code have been borrowed or heavily inspired from parts 58c2ecf20Sopenharmony_ci# of kbuild code, which is not credited, but mostly developed by: 68c2ecf20Sopenharmony_ci# 78c2ecf20Sopenharmony_ci# Copyright (C) Sam Ravnborg <sam@mars.ravnborg.org>, 2015 88c2ecf20Sopenharmony_ci# Copyright (C) Linus Torvalds <torvalds@linux-foundation.org>, 2015 98c2ecf20Sopenharmony_ci# 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci### 128c2ecf20Sopenharmony_ci# Convenient variables 138c2ecf20Sopenharmony_cicomma := , 148c2ecf20Sopenharmony_cisquote := ' 158c2ecf20Sopenharmony_cipound := \# 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci### 188c2ecf20Sopenharmony_ci# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o 198c2ecf20Sopenharmony_cidot-target = $(dir $@).$(notdir $@) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci### 228c2ecf20Sopenharmony_ci# filename of target with directory and extension stripped 238c2ecf20Sopenharmony_cibasetarget = $(basename $(notdir $@)) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci### 268c2ecf20Sopenharmony_ci# The temporary file to save gcc -MD generated dependencies must not 278c2ecf20Sopenharmony_ci# contain a comma 288c2ecf20Sopenharmony_cidepfile = $(subst $(comma),_,$(dot-target).d) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci### 318c2ecf20Sopenharmony_ci# Check if both arguments has same arguments. Result is empty string if equal. 328c2ecf20Sopenharmony_ciarg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ 338c2ecf20Sopenharmony_ci $(filter-out $(cmd_$@), $(cmd_$(1))) ) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci### 368c2ecf20Sopenharmony_ci# Escape single quote for use in echo statements 378c2ecf20Sopenharmony_ciescsq = $(subst $(squote),'\$(squote)',$1) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci# Echo command 408c2ecf20Sopenharmony_ci# Short version is used, if $(quiet) equals `quiet_', otherwise full one. 418c2ecf20Sopenharmony_ciecho-cmd = $(if $($(quiet)cmd_$(1)),\ 428c2ecf20Sopenharmony_ci echo ' $(call escsq,$($(quiet)cmd_$(1)))';) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci### 458c2ecf20Sopenharmony_ci# Replace >$< with >$$< to preserve $ when reloading the .cmd file 468c2ecf20Sopenharmony_ci# (needed for make) 478c2ecf20Sopenharmony_ci# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file 488c2ecf20Sopenharmony_ci# (needed for make) 498c2ecf20Sopenharmony_ci# Replace >'< with >'\''< to be able to enclose the whole string in '...' 508c2ecf20Sopenharmony_ci# (needed for the shell) 518c2ecf20Sopenharmony_cimake-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1))))) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci### 548c2ecf20Sopenharmony_ci# Find any prerequisites that is newer than target or that does not exist. 558c2ecf20Sopenharmony_ci# PHONY targets skipped in both cases. 568c2ecf20Sopenharmony_ciany-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci### 598c2ecf20Sopenharmony_ci# Copy dependency data into .cmd file 608c2ecf20Sopenharmony_ci# - gcc -M dependency info 618c2ecf20Sopenharmony_ci# - command line to create object 'cmd_object :=' 628c2ecf20Sopenharmony_cidep-cmd = $(if $(wildcard $(fixdep)), \ 638c2ecf20Sopenharmony_ci $(fixdep) $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp; \ 648c2ecf20Sopenharmony_ci rm -f $(depfile); \ 658c2ecf20Sopenharmony_ci mv -f $(dot-target).tmp $(dot-target).cmd, \ 668c2ecf20Sopenharmony_ci printf '$(pound) cannot find fixdep (%s)\n' $(fixdep) > $(dot-target).cmd; \ 678c2ecf20Sopenharmony_ci printf '$(pound) using basic dep data\n\n' >> $(dot-target).cmd; \ 688c2ecf20Sopenharmony_ci cat $(depfile) >> $(dot-target).cmd; \ 698c2ecf20Sopenharmony_ci printf '\n%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci### 728c2ecf20Sopenharmony_ci# if_changed_dep - execute command if any prerequisite is newer than 738c2ecf20Sopenharmony_ci# target, or command line has changed and update 748c2ecf20Sopenharmony_ci# dependencies in the cmd file 758c2ecf20Sopenharmony_ciif_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \ 768c2ecf20Sopenharmony_ci @set -e; \ 778c2ecf20Sopenharmony_ci $(echo-cmd) $(cmd_$(1)); \ 788c2ecf20Sopenharmony_ci $(dep-cmd)) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci# if_changed - execute command if any prerequisite is newer than 818c2ecf20Sopenharmony_ci# target, or command line has changed 828c2ecf20Sopenharmony_ciif_changed = $(if $(strip $(any-prereq) $(arg-check)), \ 838c2ecf20Sopenharmony_ci @set -e; \ 848c2ecf20Sopenharmony_ci $(echo-cmd) $(cmd_$(1)); \ 858c2ecf20Sopenharmony_ci printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci### 888c2ecf20Sopenharmony_ci# C flags to be used in rule definitions, includes: 898c2ecf20Sopenharmony_ci# - depfile generation 908c2ecf20Sopenharmony_ci# - global $(CFLAGS) 918c2ecf20Sopenharmony_ci# - per target C flags 928c2ecf20Sopenharmony_ci# - per object C flags 938c2ecf20Sopenharmony_ci# - BUILD_STR macro to allow '-D"$(variable)"' constructs 948c2ecf20Sopenharmony_cic_flags_1 = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj)) 958c2ecf20Sopenharmony_cic_flags_2 = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(c_flags_1)) 968c2ecf20Sopenharmony_cic_flags = $(filter-out $(CFLAGS_REMOVE_$(obj)), $(c_flags_2)) 978c2ecf20Sopenharmony_cicxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj)) 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci### 1008c2ecf20Sopenharmony_ci## HOSTCC C flags 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cihost_c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(KBUILD_HOSTCFLAGS) -D"BUILD_STR(s)=\#s" $(HOSTCFLAGS_$(basetarget).o) $(HOSTCFLAGS_$(obj)) 103