Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 1 | # Input |
| 2 | # |
| 3 | # The output from mk/sub.mk |
| 4 | # base-prefix |
Jerome Forissier | fe52b1f | 2014-11-06 17:54:51 +0100 | [diff] [blame] | 5 | # conf-file [optional] if set, all objects will depend on $(conf-file) |
Jerome Forissier | cf903a6 | 2018-08-10 14:24:33 +0200 | [diff] [blame] | 6 | # additional-compile-deps [optional] additional dependencies |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 7 | # |
| 8 | # Output |
| 9 | # |
| 10 | # set objs |
| 11 | # update cleanfiles |
| 12 | # |
| 13 | # Generates explicit rules for all objs |
| 14 | |
| 15 | objs := |
| 16 | |
| 17 | # Disable all builtin rules |
| 18 | .SUFFIXES: |
| 19 | |
Etienne Carriere | 1dc8870 | 2022-11-23 14:27:39 +0100 | [diff] [blame] | 20 | comp-cflags$(sm) = -std=gnu11 |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 21 | comp-aflags$(sm) = |
| 22 | comp-cppflags$(sm) = |
| 23 | |
Jerome Forissier | beb065d | 2018-06-26 10:04:49 +0200 | [diff] [blame] | 24 | ifeq ($(CFG_WERROR),y) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 25 | comp-cflags$(sm) += -Werror |
| 26 | endif |
| 27 | comp-cflags$(sm) += -fdiagnostics-show-option |
| 28 | |
| 29 | comp-cflags-warns-high = \ |
| 30 | -Wall -Wcast-align \ |
| 31 | -Werror-implicit-function-declaration -Wextra -Wfloat-equal \ |
| 32 | -Wformat-nonliteral -Wformat-security -Wformat=2 -Winit-self \ |
| 33 | -Wmissing-declarations -Wmissing-format-attribute \ |
| 34 | -Wmissing-include-dirs -Wmissing-noreturn \ |
| 35 | -Wmissing-prototypes -Wnested-externs -Wpointer-arith \ |
| 36 | -Wshadow -Wstrict-prototypes -Wswitch-default \ |
| 37 | -Wwrite-strings \ |
Jens Wiklander | 4516e38 | 2022-02-14 22:06:49 +0100 | [diff] [blame] | 38 | -Wno-missing-field-initializers -Wno-format-zero-length \ |
| 39 | -Wno-c2x-extensions |
Jens Wiklander | a748f9e | 2021-11-24 12:13:33 +0100 | [diff] [blame] | 40 | ifeq ($(CFG_WARN_DECL_AFTER_STATEMENT),y) |
| 41 | comp-cflags-warns-high += $(call cc-option,-Wdeclaration-after-statement) |
| 42 | endif |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 43 | comp-cflags-warns-medium = \ |
Jens Wiklander | 821dd79 | 2020-11-06 17:01:23 +0100 | [diff] [blame] | 44 | -Wredundant-decls |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 45 | comp-cflags-warns-low = \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 46 | -Wold-style-definition -Wstrict-aliasing=2 \ |
Etienne Carriere | 3303500 | 2019-04-04 09:11:41 +0200 | [diff] [blame] | 47 | -Wundef |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 48 | |
| 49 | comp-cflags-warns-1:= $(comp-cflags-warns-high) |
| 50 | comp-cflags-warns-2:= $(comp-cflags-warns-1) $(comp-cflags-warns-medium) |
| 51 | comp-cflags-warns-3:= $(comp-cflags-warns-2) $(comp-cflags-warns-low) |
| 52 | |
| 53 | WARNS ?= 3 |
| 54 | |
Jerome Forissier | 98d863a | 2019-07-05 14:34:22 +0200 | [diff] [blame] | 55 | comp-cflags$(sm) += $(comp-cflags-warns-$(WARNS)) \ |
| 56 | $(comp-cflags-warns-$(COMPILER_$(sm))) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 57 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 58 | CHECK ?= sparse |
| 59 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 60 | .PHONY: FORCE |
Jens Wiklander | 94cd76c | 2018-07-17 15:47:46 +0200 | [diff] [blame] | 61 | .PHONY: FORCE-GENSRC$(sm) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 62 | FORCE: |
Jens Wiklander | 94cd76c | 2018-07-17 15:47:46 +0200 | [diff] [blame] | 63 | FORCE-GENSRC$(sm): |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 64 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 65 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 66 | define process_srcs |
| 67 | objs += $2 |
| 68 | comp-dep-$2 := $$(dir $2).$$(notdir $2).d |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 69 | comp-cmd-file-$2:= $$(dir $2).$$(notdir $2).cmd |
| 70 | comp-sm-$2 := $(sm) |
Jerome Forissier | 606f378 | 2016-10-13 14:26:54 +0200 | [diff] [blame] | 71 | comp-lib-$2 := $(libname)-$(sm) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 72 | |
| 73 | cleanfiles := $$(cleanfiles) $$(comp-dep-$2) $$(comp-cmd-file-$2) $2 |
| 74 | |
| 75 | ifeq ($$(filter %.c,$1),$1) |
Jerome Forissier | be3bc46 | 2020-07-21 10:55:15 +0200 | [diff] [blame] | 76 | comp-q-$2 := CC # one trailing space |
| 77 | comp-compiler-$2 := $$(CC$(sm)) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 78 | comp-flags-$2 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \ |
Jerome Forissier | 0259891 | 2016-02-26 09:59:55 +0100 | [diff] [blame] | 79 | $$(cflags-remove-$$(comp-sm-$2)) \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 80 | $$(cflags-remove-$2), \ |
Jerome Forissier | b09cddc | 2016-02-24 13:01:45 +0100 | [diff] [blame] | 81 | $$(CFLAGS$$(arch-bits-$$(comp-sm-$2))) $$(CFLAGS_WARNS) \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 82 | $$(comp-cflags$$(comp-sm-$2)) $$(cflags$$(comp-sm-$2)) \ |
Jerome Forissier | 3d34e12 | 2014-10-30 17:37:42 +0100 | [diff] [blame] | 83 | $$(cflags-lib$$(comp-lib-$2)) $$(cflags-$2)) |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 84 | ifeq ($C,1) |
| 85 | check-cmd-$2 = $(CHECK) $$(comp-cppflags-$2) $$< |
| 86 | echo-check-$2 := $(cmd-echo-silent) |
| 87 | echo-check-cmd-$2 = $(cmd-echo) $$(subst \",\\\",$$(check-cmd-$2)) |
| 88 | endif |
| 89 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 90 | else ifeq ($$(filter %.S,$1),$1) |
Jerome Forissier | be3bc46 | 2020-07-21 10:55:15 +0200 | [diff] [blame] | 91 | comp-q-$2 := AS # one trailing space |
| 92 | comp-compiler-$2 := $$(CC$(sm)) |
Jens Wiklander | df7712b | 2019-08-21 11:28:37 +0200 | [diff] [blame] | 93 | comp-flags-$2 = $$(filter-out $$(AFLAGS_REMOVE) $$(aflags-remove) \ |
| 94 | $$(aflags-remove-$$(comp-sm-$2)) \ |
| 95 | $$(aflags-remove-$2), \ |
| 96 | $$(AFLAGS) $$(comp-aflags$$(comp-sm-$2)) \ |
| 97 | $$(aflags$$(comp-sm-$2)) $$(aflags-$2)) |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 98 | |
Jerome Forissier | be3bc46 | 2020-07-21 10:55:15 +0200 | [diff] [blame] | 99 | else ifeq ($$(filter %.cpp,$1),$1) |
| 100 | comp-q-$2 := CXX |
| 101 | comp-compiler-$2 := $$(CXX$(sm)) |
| 102 | comp-flags-$2 = $$(filter-out $$(CXXFLAGS_REMOVE) $$(cxxflags-remove) \ |
| 103 | $$(cxxflags-remove-$$(comp-sm-$2)) \ |
| 104 | $$(cxxflags-remove-$2), \ |
| 105 | $$(CXXFLAGS) $$(comp-cxxflags$$(comp-sm-$2)) \ |
| 106 | $$(cxxflags$$(comp-sm-$2)) $$(cxxflags-$2)) |
| 107 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 108 | else |
| 109 | $$(error "Don't know what to do with $1") |
| 110 | endif |
| 111 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 112 | comp-cppflags-$2 = $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \ |
Jerome Forissier | 0259891 | 2016-02-26 09:59:55 +0100 | [diff] [blame] | 113 | $$(cppflags-remove-$$(comp-sm-$2)) \ |
| 114 | $$(cppflags-remove-$2), \ |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 115 | $$(nostdinc$$(comp-sm-$2)) $$(CPPFLAGS) \ |
| 116 | $$(addprefix -I,$$(incdirs$$(comp-sm-$2))) \ |
| 117 | $$(addprefix -I,$$(incdirs-lib$$(comp-lib-$2))) \ |
| 118 | $$(addprefix -I,$$(incdirs-$2)) \ |
| 119 | $$(cppflags$$(comp-sm-$2)) \ |
Jens Wiklander | d3353b4 | 2018-11-22 22:09:14 +0100 | [diff] [blame] | 120 | $$(cppflags-lib$$(comp-lib-$2)) $$(cppflags-$2)) \ |
| 121 | -D__FILE_ID__=$$(subst -,_,$$(subst /,_,$$(subst .,_,$1))) |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 122 | |
| 123 | comp-flags-$2 += -MD -MF $$(comp-dep-$2) -MT $$@ |
| 124 | comp-flags-$2 += $$(comp-cppflags-$2) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 125 | |
Jerome Forissier | be3bc46 | 2020-07-21 10:55:15 +0200 | [diff] [blame] | 126 | comp-cmd-$2 = $$(comp-compiler-$2) $$(comp-flags-$2) -c $$< -o $$@ |
Jens Wiklander | 1b4eb4f | 2015-02-02 09:19:18 +0100 | [diff] [blame] | 127 | comp-objcpy-cmd-$2 = $$(OBJCOPY$(sm)) \ |
Jens Wiklander | 6d6ea54 | 2014-12-02 11:06:01 +0100 | [diff] [blame] | 128 | --rename-section .rodata=.rodata.$1 \ |
| 129 | --rename-section .rodata.str1.1=.rodata.str1.1.$1 \ |
| 130 | $2 |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 131 | |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 132 | # Assign defaults if unassigned |
| 133 | echo-check-$2 ?= true |
| 134 | echo-check-cmd-$2 ?= true |
| 135 | check-cmd-$2 ?= true |
| 136 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 137 | -include $$(comp-cmd-file-$2) |
| 138 | -include $$(comp-dep-$2) |
| 139 | |
| 140 | |
Jens Wiklander | 94cd76c | 2018-07-17 15:47:46 +0200 | [diff] [blame] | 141 | $2: $1 FORCE-GENSRC$(sm) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 142 | # Check if any prerequisites are newer than the target and |
| 143 | # check if command line has changed |
Jens Wiklander | 94cd76c | 2018-07-17 15:47:46 +0200 | [diff] [blame] | 144 | $$(if $$(strip $$(filter-out FORCE-GENSRC$(sm), $$?) \ |
Jerome Forissier | 313ead4 | 2015-01-22 18:17:54 +0100 | [diff] [blame] | 145 | $$(filter-out $$(comp-cmd-$2), $$(old-cmd-$2)) \ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 146 | $$(filter-out $$(old-cmd-$2), $$(comp-cmd-$2))), \ |
| 147 | @set -e ;\ |
| 148 | mkdir -p $$(dir $2) ;\ |
Jens Wiklander | fbecf4e | 2015-04-16 17:00:22 +0200 | [diff] [blame] | 149 | $$(echo-check-$2) ' CHECK $$<' ;\ |
| 150 | $$(echo-check-cmd-$2) ;\ |
| 151 | $$(check-cmd-$2) ;\ |
Jerome Forissier | be3bc46 | 2020-07-21 10:55:15 +0200 | [diff] [blame] | 152 | $(cmd-echo-silent) ' $$(comp-q-$2) $$@' ;\ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 153 | $(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$2)) ;\ |
| 154 | $$(comp-cmd-$2) ;\ |
Jens Wiklander | 6d6ea54 | 2014-12-02 11:06:01 +0100 | [diff] [blame] | 155 | $(cmd-echo) $$(comp-objcpy-cmd-$2) ;\ |
| 156 | $$(comp-objcpy-cmd-$2) ;\ |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 157 | echo "old-cmd-$2 := $$(subst \",\\\",$$(comp-cmd-$2))" > \ |
| 158 | $$(comp-cmd-file-$2) ;\ |
| 159 | ) |
| 160 | |
| 161 | endef |
| 162 | |
| 163 | $(foreach f, $(srcs), $(eval $(call \ |
Jerome Forissier | 4334e8d | 2014-09-08 10:53:42 +0200 | [diff] [blame] | 164 | process_srcs,$(f),$(out-dir)/$(base-prefix)$$(basename $f).o))) |
Jerome Forissier | fe52b1f | 2014-11-06 17:54:51 +0100 | [diff] [blame] | 165 | |
Jens Wiklander | bc42074 | 2015-05-05 14:59:15 +0200 | [diff] [blame] | 166 | # Handle generated source files, that is, files that are compiled from out-dir |
Jens Wiklander | c95ce41 | 2016-05-30 16:06:35 +0200 | [diff] [blame] | 167 | $(foreach f, $(gen-srcs), $(eval $(call process_srcs,$(f),$$(basename $f).o))) |
Jens Wiklander | bc42074 | 2015-05-05 14:59:15 +0200 | [diff] [blame] | 168 | |
Jens Wiklander | cfa34d9 | 2018-07-17 15:47:46 +0200 | [diff] [blame] | 169 | # Handle specified source files, that is, files that have a specified path |
| 170 | # but where the object file should go into a specified out directory |
| 171 | $(foreach f, $(spec-srcs), $(eval $(call \ |
| 172 | process_srcs,$(f),$(spec-out-dir)/$$(notdir $$(basename $f)).o))) |
| 173 | |
Jerome Forissier | cf903a6 | 2018-08-10 14:24:33 +0200 | [diff] [blame] | 174 | $(objs): $(conf-file) $(additional-compile-deps) |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 175 | |
| 176 | define _gen-asm-defines-file |
| 177 | # c-filename in $1 |
| 178 | # h-filename in $2 |
| 179 | # s-filename in $3 |
Jerome Forissier | 8826a6a | 2021-02-12 17:58:08 +0100 | [diff] [blame] | 180 | # Dependencies in $4 |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 181 | |
Jens Wiklander | 94cd76c | 2018-07-17 15:47:46 +0200 | [diff] [blame] | 182 | FORCE-GENSRC$(sm): $(2) |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 183 | |
| 184 | comp-dep-$3 := $$(dir $3)$$(notdir $3).d |
| 185 | comp-cmd-file-$3:= $$(dir $3)$$(notdir $3).cmd |
| 186 | comp-sm-$3 := $(sm) |
| 187 | |
| 188 | cleanfiles := $$(cleanfiles) $$(comp-dep-$3) $$(comp-cmd-file-$3) $3 $2 |
| 189 | |
| 190 | comp-flags-$3 = $$(filter-out $$(CFLAGS_REMOVE) $$(cflags-remove) \ |
Jerome Forissier | 0259891 | 2016-02-26 09:59:55 +0100 | [diff] [blame] | 191 | $$(cflags-remove-$$(comp-sm-$3)) \ |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 192 | $$(cflags-remove-$3), \ |
| 193 | $$(CFLAGS) $$(CFLAGS_WARNS) \ |
| 194 | $$(comp-cflags$$(comp-sm-$3)) $$(cflags$$(comp-sm-$3)) \ |
| 195 | $$(cflags-lib$$(comp-lib-$3)) $$(cflags-$3)) |
| 196 | |
| 197 | comp-cppflags-$3 = $$(filter-out $$(CPPFLAGS_REMOVE) $$(cppflags-remove) \ |
Jerome Forissier | 0259891 | 2016-02-26 09:59:55 +0100 | [diff] [blame] | 198 | $$(cppflags-remove-$$(comp-sm-$3)) \ |
| 199 | $$(cppflags-remove-$3), \ |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 200 | $$(nostdinc$$(comp-sm-$3)) $$(CPPFLAGS) \ |
| 201 | $$(addprefix -I,$$(incdirs$$(comp-sm-$3))) \ |
| 202 | $$(addprefix -I,$$(incdirs-lib$$(comp-lib-$3))) \ |
| 203 | $$(addprefix -I,$$(incdirs-$3)) \ |
| 204 | $$(cppflags$$(comp-sm-$3)) \ |
| 205 | $$(cppflags-lib$$(comp-lib-$3)) $$(cppflags-$3)) |
| 206 | |
| 207 | comp-flags-$3 += -MD -MF $$(comp-dep-$3) -MT $$@ |
| 208 | comp-flags-$3 += $$(comp-cppflags-$3) |
| 209 | |
| 210 | comp-cmd-$3 = $$(CC$(sm)) $$(comp-flags-$3) -fverbose-asm -S $$< -o $$@ |
| 211 | |
| 212 | |
| 213 | -include $$(comp-cmd-file-$3) |
| 214 | -include $$(comp-dep-$3) |
| 215 | |
Jerome Forissier | 8826a6a | 2021-02-12 17:58:08 +0100 | [diff] [blame] | 216 | $3: $1 $(conf-file) $(4) FORCE |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 217 | # Check if any prerequisites are newer than the target and |
| 218 | # check if command line has changed |
| 219 | $$(if $$(strip $$(filter-out FORCE, $$?) \ |
| 220 | $$(filter-out $$(comp-cmd-$3), $$(old-cmd-$3)) \ |
| 221 | $$(filter-out $$(old-cmd-$3), $$(comp-cmd-$3))), \ |
| 222 | @set -e ;\ |
Jens Wiklander | c02f9fb | 2016-01-12 10:14:50 +0100 | [diff] [blame] | 223 | mkdir -p $$(dir $2) $$(dir $3) ;\ |
Jerome Forissier | 3ee4416 | 2019-03-22 14:25:26 +0100 | [diff] [blame] | 224 | $(cmd-echo-silent) ' CC $$@'; \ |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 225 | $(cmd-echo) $$(subst \",\\\",$$(comp-cmd-$3)) ;\ |
| 226 | $$(comp-cmd-$3) ;\ |
| 227 | echo "old-cmd-$3 := $$(subst \",\\\",$$(comp-cmd-$3))" > \ |
| 228 | $$(comp-cmd-file-$3) ;\ |
| 229 | ) |
| 230 | |
Vesa Jääskeläinen | 6754fa7 | 2020-12-27 10:28:54 +0200 | [diff] [blame] | 231 | guard-$2 := $$(subst -,_,$$(subst .,_,$$(subst /,_,$$(subst +,_,$2)))) |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 232 | |
| 233 | $(2): $(3) |
| 234 | $(q)set -e; \ |
| 235 | $(cmd-echo-silent) ' CHK $$@'; \ |
| 236 | mkdir -p $$(dir $$@); \ |
| 237 | echo "#ifndef $$(guard-$2)" >$$@.tmp; \ |
| 238 | echo "#define $$(guard-$2)" >>$$@.tmp; \ |
Jerome Forissier | ec295ea | 2019-03-22 17:06:08 +0100 | [diff] [blame] | 239 | sed -ne 's|^.*==>\([^ ]*\) [\$$$$#]*\([-0-9]*\) \([^@/]*\).*|#define \1\t\2\t/* \3*/|p' \ |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 240 | < $$< >>$$@.tmp; \ |
| 241 | echo "#endif" >>$$@.tmp; \ |
| 242 | $$(call mv-if-changed,$$@.tmp,$$@) |
| 243 | |
| 244 | endef |
| 245 | |
| 246 | define gen-asm-defines-file |
Jerome Forissier | 8826a6a | 2021-02-12 17:58:08 +0100 | [diff] [blame] | 247 | $(call _gen-asm-defines-file,$1,$2,$(dir $2).$(notdir $(2:.h=.s)),$(asm-defines-$(notdir $(1))-deps)) |
Jens Wiklander | d5a887c | 2016-01-12 15:19:16 +0100 | [diff] [blame] | 248 | endef |
| 249 | |
Jerome Forissier | 070168e | 2018-03-12 14:45:16 +0100 | [diff] [blame] | 250 | $(foreach f,$(asm-defines-files),$(eval $(call gen-asm-defines-file,$(f),$(out-dir)/$(sm)/include/generated/$(basename $(notdir $(f))).h))) |
Jerome Forissier | cf903a6 | 2018-08-10 14:24:33 +0200 | [diff] [blame] | 251 | |
Etienne Carriere | c828ece | 2018-11-23 18:03:52 +0100 | [diff] [blame] | 252 | # Device tree source file compilation |
| 253 | DTC := dtc |
| 254 | DTC_FLAGS += -I dts -O dtb |
| 255 | DTC_FLAGS += -Wno-unit_address_vs_reg |
| 256 | |
| 257 | define gen-dtb-file |
| 258 | # dts file path/name in $1 |
| 259 | # dtb file path/name in $2 |
| 260 | |
| 261 | dtb-basename-$2 := $$(basename $$(notdir $2)) |
| 262 | dtb-predts-$2 := $$(dir $2)$$(dtb-basename-$2).pre.dts |
| 263 | dtb-predep-$2 := $$(dir $2).$$(dtb-basename-$2).pre.dts.d |
| 264 | dtb-dep-$2 := $$(dir $2).$$(notdir $2).d |
| 265 | dtb-cmd-file-$2 := $$(dir $2).$$(notdir $2).cmd |
| 266 | |
| 267 | cleanfiles := $$(cleanfiles) $2 \ |
| 268 | $$(dtb-predts-$2) $$(dtb-predep-$2) \ |
| 269 | $$(dtb-dep-$2) $$(dtb-cmd-file-$2) |
| 270 | |
lei zhou | 61b2d6e | 2023-01-25 18:27:41 +0000 | [diff] [blame] | 271 | dtb-cppflags-$2 := -Icore/include/ -x assembler-with-cpp -Ulinux -Uunix \ |
Etienne Carriere | c828ece | 2018-11-23 18:03:52 +0100 | [diff] [blame] | 272 | -E -ffreestanding $$(CPPFLAGS) \ |
| 273 | -MD -MF $$(dtb-predep-$2) -MT $2 |
| 274 | |
| 275 | dtb-dtcflags-$2 := $$(DTC_FLAGS) -d $$(dtb-dep-$2) |
| 276 | |
| 277 | -include $$(dtb-dep-$2) |
| 278 | -include $$(dtb-predep-$2) |
| 279 | -include $$(dtb-cmd-file-$2) |
| 280 | |
| 281 | dtb-precmd-$2 = $$(CPP$(sm)) $$(dtb-cppflags-$2) -o $$(dtb-predts-$2) $$< |
| 282 | dtb-cmd-$2 = $$(DTC) $$(dtb-dtcflags-$2) -o $$@ $$(dtb-predts-$2) |
| 283 | |
| 284 | $2: $1 FORCE |
| 285 | # Check if any prerequisites are newer than the target and |
| 286 | # check if command line has changed |
| 287 | $$(if $$(strip $$(filter-out FORCE, $$?) \ |
| 288 | $$(filter-out $$(dtb-precmd-$2), $$(dtb-old-precmd-$2)) \ |
| 289 | $$(filter-out $$(dtb-old-precmd-$2), $$(dtb-precmd-$2)) \ |
| 290 | $$(filter-out $$(dtb-cmd-$2), $$(dtb-old-cmd-$2)) \ |
| 291 | $$(filter-out $$(dtb-old-cmd-$2), $$(dtb-cmd-$2))), \ |
| 292 | @set -e; \ |
| 293 | mkdir -p $$(dir $2); \ |
| 294 | $(cmd-echo-silent) ' CPP $$(dtb-predts-$2)'; \ |
| 295 | $$(dtb-precmd-$2); \ |
| 296 | $(cmd-echo-silent) ' DTC $$@'; \ |
| 297 | $$(dtb-cmd-$2); \ |
| 298 | echo "dtb-old-precmd-$2 := $$(subst \",\\\",$$(dtb-precmd-$2))" > \ |
| 299 | $$(dtb-cmd-file-$2) ;\ |
| 300 | echo "dtb-old-cmd-$2 := $$(subst \",\\\",$$(dtb-cmd-$2))" >> \ |
| 301 | $$(dtb-cmd-file-$2) ;\ |
| 302 | ) |
| 303 | |
| 304 | endef |
| 305 | |
Jerome Forissier | cf903a6 | 2018-08-10 14:24:33 +0200 | [diff] [blame] | 306 | additional-compile-deps := |