Blame view
tools/build/Build.include
4.06 KB
c819e2cf2 tools build: Add ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
### # build: Generic definitions # # Lots of this code have been borrowed or heavily inspired from parts # of kbuild code, which is not credited, but mostly developed by: # # Copyright (C) Sam Ravnborg <sam@mars.ravnborg.org>, 2015 # Copyright (C) Linus Torvalds <torvalds@linux-foundation.org>, 2015 # ### # Convenient variables comma := , squote := ' |
9564a8cf4 Kbuild: fix # esc... |
15 |
pound := \# |
c819e2cf2 tools build: Add ... |
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o dot-target = $(dir $@).$(notdir $@) ### # filename of target with directory and extension stripped basetarget = $(basename $(notdir $@)) ### # The temporary file to save gcc -MD generated dependencies must not # contain a comma depfile = $(subst $(comma),_,$(dot-target).d) ### # Check if both arguments has same arguments. Result is empty string if equal. arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ $(filter-out $(cmd_$@), $(cmd_$(1))) ) ### # Escape single quote for use in echo statements escsq = $(subst $(squote),'\$(squote)',$1) # Echo command # Short version is used, if $(quiet) equals `quiet_', otherwise full one. echo-cmd = $(if $($(quiet)cmd_$(1)),\ echo ' $(call escsq,$($(quiet)cmd_$(1)))';) ### # Replace >$< with >$$< to preserve $ when reloading the .cmd file # (needed for make) |
9564a8cf4 Kbuild: fix # esc... |
47 |
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file |
c819e2cf2 tools build: Add ... |
48 49 50 |
# (needed for make) # Replace >'< with >'\''< to be able to enclose the whole string in '...' # (needed for the shell) |
9564a8cf4 Kbuild: fix # esc... |
51 |
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1))))) |
c819e2cf2 tools build: Add ... |
52 53 54 55 56 57 58 |
### # Find any prerequisites that is newer than target or that does not exist. # PHONY targets skipped in both cases. any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) ### |
275e2d955 tools build: Move... |
59 60 61 |
# Copy dependency data into .cmd file # - gcc -M dependency info # - command line to create object 'cmd_object :=' |
9fb81323e tools build: Make... |
62 63 64 65 |
dep-cmd = $(if $(wildcard $(fixdep)), \ $(fixdep) $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp; \ rm -f $(depfile); \ mv -f $(dot-target).tmp $(dot-target).cmd, \ |
9feeb638c tools build: fix ... |
66 67 68 69 70 |
printf '$(pound) cannot find fixdep (%s) ' $(fixdep) > $(dot-target).cmd; \ printf '$(pound) using basic dep data ' >> $(dot-target).cmd; \ |
9fb81323e tools build: Make... |
71 |
cat $(depfile) >> $(dot-target).cmd; \ |
a5ba0a1a5 tools build: Make... |
72 73 74 |
printf ' %s ' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd) |
275e2d955 tools build: Move... |
75 76 |
### |
c819e2cf2 tools build: Add ... |
77 78 79 80 |
# if_changed_dep - execute command if any prerequisite is newer than # target, or command line has changed and update # dependencies in the cmd file if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \ |
2fedf79b6 tools build: Move... |
81 |
@set -e; \ |
a278f3d81 tools, build: Pro... |
82 83 |
$(echo-cmd) $(cmd_$(1)); \ $(dep-cmd)) |
c819e2cf2 tools build: Add ... |
84 85 86 |
# if_changed - execute command if any prerequisite is newer than # target, or command line has changed |
2fedf79b6 tools build: Move... |
87 88 89 90 91 |
if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ @set -e; \ $(echo-cmd) $(cmd_$(1)); \ printf '%s ' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) |
c819e2cf2 tools build: Add ... |
92 93 94 95 96 97 98 99 |
### # C flags to be used in rule definitions, includes: # - depfile generation # - global $(CFLAGS) # - per target C flags # - per object C flags # - BUILD_STR macro to allow '-D"$(variable)"' constructs |
baa1973eb tools build: Fix ... |
100 |
c_flags_1 = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj)) |
2ec8107d8 tools build: Add ... |
101 102 |
c_flags_2 = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(c_flags_1)) c_flags = $(filter-out $(CFLAGS_REMOVE_$(obj)), $(c_flags_2)) |
baa1973eb tools build: Fix ... |
103 |
cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj)) |
0c3b7e426 tools build: Add ... |
104 105 106 |
### ## HOSTCC C flags |
96f14fe73 kbuild: Rename HO... |
107 |
host_c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(KBUILD_HOSTCFLAGS) -D"BUILD_STR(s)=\#s" $(HOSTCFLAGS_$(basetarget).o) $(HOSTCFLAGS_$(obj)) |