Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 1 | # Input |
| 2 | # |
| 3 | # subdirs tells the subdirectories to descend |
| 4 | # |
| 5 | # Output |
| 6 | # |
Jens Wiklander | 13301e1 | 2017-04-06 09:07:08 +0200 | [diff] [blame] | 7 | # set srcs gen-srcs |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 8 | # set cflags-$(oname) cflags-remove-$(oname) |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 9 | # cxxflags-$(oname) cxxflags-remove-$(oname) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 10 | # aflags-$(oname) aflags-remove-$(oname) |
| 11 | # cppflags-$(oname) cppflags-remove-$(oname) |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 12 | # incdirs-$(oname) |
Jerome Forissier | 606f378 | 2016-10-13 14:26:54 +0200 | [diff] [blame] | 13 | # incdirs-lib$(libname)-$(sm) [if libname is defined] |
| 14 | # cppflags-lib$(libname)-$(sm) [if libname is defined] |
| 15 | # cflags-lib$(libname)-$(sm) [if libname is defined] |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 16 | # cxxflags-lib$(libname)-$(sm) [if libname is defined] |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 17 | # for each file found, oname is the name of the object file for corresponding |
| 18 | # source file |
| 19 | |
| 20 | srcs := |
Jens Wiklander | 13301e1 | 2017-04-06 09:07:08 +0200 | [diff] [blame] | 21 | gen-srcs := |
Jerome Forissier | 070168e | 2018-03-12 14:45:16 +0100 | [diff] [blame] | 22 | asm-defines-files := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 23 | |
| 24 | define process-subdir-srcs-y |
| 25 | ifeq ($$(sub-dir),.) |
Pascal Brand | 565e42f | 2014-08-07 13:42:57 +0200 | [diff] [blame] | 26 | srcs += $1 |
Jerome Forissier | 4334e8d | 2014-09-08 10:53:42 +0200 | [diff] [blame] | 27 | oname := $(out-dir)/$(base-prefix)$(basename $1).o |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 28 | else |
Pascal Brand | 565e42f | 2014-08-07 13:42:57 +0200 | [diff] [blame] | 29 | ifneq ($(filter /%,$(1)),) |
| 30 | # $1 is an absolute path - start with "/" |
| 31 | srcs += $1 |
Jerome Forissier | 4334e8d | 2014-09-08 10:53:42 +0200 | [diff] [blame] | 32 | oname := $(out-dir)/$(base-prefix)$(basename $1).o |
Pascal Brand | 565e42f | 2014-08-07 13:42:57 +0200 | [diff] [blame] | 33 | else |
| 34 | srcs += $(sub-dir)/$1 |
Jerome Forissier | 4334e8d | 2014-09-08 10:53:42 +0200 | [diff] [blame] | 35 | oname := $(out-dir)/$(base-prefix)$(basename $$(sub-dir)/$1).o |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 36 | endif |
Pascal Brand | 565e42f | 2014-08-07 13:42:57 +0200 | [diff] [blame] | 37 | endif |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 38 | cflags-$$(oname) := $$(cflags-y) $$(cflags-$(1)-y) |
| 39 | cflags-remove-$$(oname) := $$(cflags-remove-y) \ |
| 40 | $$(cflags-remove-$(1)-y) |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 41 | cxxflags-$$(oname) := $$(cxxflags-y) $$(cxxflags-$(1)-y) |
| 42 | cxxflags-remove-$$(oname) := $$(cxxflags-remove-y) \ |
| 43 | $$(cxxflags-remove-$(1)-y) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 44 | cppflags-$$(oname) := $$(cppflags-y) $$(cppflags-$(1)-y) |
| 45 | cppflags-remove-$$(oname) := $$(cppflags-remove-y) \ |
| 46 | $$(cppflags-remove-$(1)-y) |
| 47 | aflags-$$(oname) := $$(aflags-y) $$(aflags-$(1)-y) |
| 48 | aflags-remove-$$(oname) := $$(aflags-remove-y) \ |
| 49 | $$(aflags-remove-$(1)-y) |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 50 | incdirs-$$(oname) := $$(thissubdir-incdirs) $$(addprefix $(sub-dir)/,$$(incdirs-$(1)-y)) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 51 | # Clear local filename specific variables to avoid accidental reuse |
| 52 | # in another subdirectory |
| 53 | cflags-$(1)-y := |
| 54 | cflags-remove-$(1)-y := |
Jerome Forissier | 3d34e12 | 2014-10-30 17:37:42 +0100 | [diff] [blame] | 55 | cflags-lib-y := |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 56 | cxxflags-$(1)-y := |
| 57 | cxxflags-remove-$(1)-y := |
| 58 | cxxflags-lib-y := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 59 | cppflags-$(1)-y := |
| 60 | cppflags-remove-$(1)-y := |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 61 | cppflags-lib-y := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 62 | aflags-$(1)-y := |
| 63 | aflags-remove-$(1)-y := |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 64 | incdirs-$(1)-y := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 65 | fname := |
| 66 | oname := |
| 67 | endef #process-subdir-srcs-y |
| 68 | |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 69 | define process-subdir-gensrcs-helper |
| 70 | # $1 gensrc-y element |
| 71 | # $2 full path and name of generated source file |
| 72 | # $3 full path and name of object file compiled from source file |
| 73 | # $4 full path to out directory |
Jerome Forissier | cba8ca1 | 2019-09-13 18:01:48 +0200 | [diff] [blame] | 74 | # $5 y if $2 must be generated before $(sm) starts building (e.g., .h file) |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 75 | |
Jens Wiklander | c95ce41 | 2016-05-30 16:06:35 +0200 | [diff] [blame] | 76 | gen-srcs += $2 |
Jerome Forissier | 27fd7c7 | 2019-10-23 17:59:07 +0200 | [diff] [blame] | 77 | cleanfiles += $2 |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 78 | oname := $3 |
| 79 | |
Jerome Forissier | cba8ca1 | 2019-09-13 18:01:48 +0200 | [diff] [blame] | 80 | FORCE-GENSRC$(sm): $(if $(filter y,$5),$2,) |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 81 | |
| 82 | $$(addprefix $4,$$(produce-additional-$1)): $2 |
| 83 | |
| 84 | subdir-$2 := $$(sub-dir) |
| 85 | recipe-$2 := $$(recipe-$1) |
| 86 | $2: $$(depends-$1) |
| 87 | @$(cmd-echo-silent) ' GEN $2' |
| 88 | $(q)mkdir -p $4 |
| 89 | $(q)$$(recipe-$2) |
| 90 | |
| 91 | cflags-$$(oname) := $$(cflags-y) $$(cflags-$(1)-y) |
| 92 | cflags-remove-$$(oname) := $$(cflags-remove-y) \ |
| 93 | $$(cflags-remove-$(1)-y) |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 94 | cxxflags-$$(oname) := $$(cxxflags-y) $$(cxxflags-$(1)-y) |
| 95 | cxxflags-remove-$$(oname) := $$(cxxflags-remove-y) \ |
| 96 | $$(cxxflags-remove-$(1)-y) |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 97 | cppflags-$$(oname) := $$(cppflags-y) $$(cppflags-$(1)-y) |
| 98 | cppflags-remove-$$(oname) := $$(cppflags-remove-y) \ |
| 99 | $$(cppflags-remove-$(1)-y) |
| 100 | aflags-$$(oname) := $$(aflags-y) $$(aflags-$(1)-y) |
| 101 | aflags-remove-$$(oname) := $$(aflags-remove-y) \ |
| 102 | $$(aflags-remove-$(1)-y) |
| 103 | incdirs-$$(oname) := $$(thissubdir-incdirs) $$(addprefix $(sub-dir)/,$$(incdirs-$(1)-y)) |
| 104 | # Clear local filename specific variables to avoid accidental reuse |
| 105 | # in another subdirectory |
| 106 | cflags-$(1)-y := |
| 107 | cflags-remove-$(1)-y := |
| 108 | cflags-lib-y := |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 109 | cxxflags-$(1)-y := |
| 110 | cxxflags-remove-$(1)-y := |
| 111 | cxxflags-lib-y := |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 112 | cppflags-$(1)-y := |
| 113 | cppflags-remove-$(1)-y := |
| 114 | cppflags-lib-y := |
| 115 | aflags-$(1)-y := |
| 116 | aflags-remove-$(1)-y := |
| 117 | incdirs-$(1)-y := |
| 118 | fname := |
| 119 | oname := |
| 120 | |
| 121 | endef #process-subdir-gensrcs-helper |
| 122 | |
| 123 | define process-subdir-gensrcs-y |
Jerome Forissier | cba8ca1 | 2019-09-13 18:01:48 +0200 | [diff] [blame] | 124 | $$(eval $$(call process-subdir-gensrcs-helper,$1,$(sub-dir-out)/$$(produce-$1),$(sub-dir-out)/$(basename $(produce-$1)).o,$(sub-dir-out),$(force-gensrc-$1))) |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 125 | endef #process-subdir-gensrcs-y |
| 126 | |
Jerome Forissier | 070168e | 2018-03-12 14:45:16 +0100 | [diff] [blame] | 127 | define process-subdir-asm-defines-y |
| 128 | asm-defines-files += $(sub-dir)/$1 |
| 129 | endef #process-subdir-asm-defines-y |
| 130 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 131 | define process-subdir |
| 132 | sub-dir := $1 |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 133 | ifeq ($1,.) |
Jerome Forissier | 3e3182a | 2020-05-13 13:16:02 +0200 | [diff] [blame] | 134 | sub-dir-out := $(patsubst %/,%,$(out-dir)/$(base-prefix)) |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 135 | else |
| 136 | sub-dir-out := $(out-dir)/$(base-prefix)$1 |
| 137 | endif |
| 138 | |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 139 | include $1/sub.mk |
| 140 | sub-subdirs := $$(addprefix $1/,$$(subdirs-y)) |
| 141 | incdirs$(sm) := $(incdirs$(sm)) $$(addprefix $1/,$$(global-incdirs-y)) |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 142 | thissubdir-incdirs := $(out-dir)/$(base-prefix)$1 $$(addprefix $1/,$$(incdirs-y)) |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 143 | ifneq ($$(libname),) |
Jerome Forissier | 606f378 | 2016-10-13 14:26:54 +0200 | [diff] [blame] | 144 | incdirs-lib$$(libname)-$$(sm) := $$(incdirs-lib$$(libname)-$$(sm)) $$(addprefix $1/,$$(incdirs-lib-y)) |
| 145 | cflags-lib$$(libname)-$$(sm) := $$(cflags-lib$$(libname)-$$(sm)) $$(cflags-lib-y) |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 146 | cxxflags-lib$$(libname)-$$(sm) := $$(cxxflags-lib$$(libname)-$$(sm)) $$(cxxflags-lib-y) |
Jerome Forissier | 606f378 | 2016-10-13 14:26:54 +0200 | [diff] [blame] | 147 | cppflags-lib$$(libname)-$$(sm) := $$(cppflags-lib$$(libname)-$$(sm)) $$(cppflags-lib-y) |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 148 | endif |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 149 | |
| 150 | # Process files in current directory |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 151 | $$(foreach g, $$(gensrcs-y), $$(eval $$(call process-subdir-gensrcs-y,$$(g)))) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 152 | $$(foreach s, $$(srcs-y), $$(eval $$(call process-subdir-srcs-y,$$(s)))) |
Jerome Forissier | 070168e | 2018-03-12 14:45:16 +0100 | [diff] [blame] | 153 | $$(foreach a, $$(asm-defines-y), $$(eval $$(call process-subdir-asm-defines-y,$$(a)))) |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 154 | # Clear flags used when processing current directory |
| 155 | srcs-y := |
| 156 | cflags-y := |
Jerome Forissier | 3d34e12 | 2014-10-30 17:37:42 +0100 | [diff] [blame] | 157 | cflags-lib-y := |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 158 | cxxflags-y := |
| 159 | cxxflags-lib-y := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 160 | cppflags-y := |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 161 | cppflags-lib-y := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 162 | aflags-y := |
| 163 | cflags-remove-y := |
Jerome Forissier | 4010618 | 2020-08-14 09:53:03 +0200 | [diff] [blame] | 164 | cxxflags-remove-y := |
Jens Wiklander | 098883e | 2020-07-17 09:32:45 +0200 | [diff] [blame] | 165 | aflags-remove-y := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 166 | subdirs-y := |
| 167 | global-incdirs-y := |
Jerome Forissier | 73dc728 | 2014-09-25 16:04:03 +0200 | [diff] [blame] | 168 | incdirs-lib-y := |
| 169 | incdirs-y := |
Jens Wiklander | 36a0605 | 2016-06-02 13:52:12 +0200 | [diff] [blame] | 170 | gensrcs-y := |
| 171 | this-out-dir := |
Jerome Forissier | 070168e | 2018-03-12 14:45:16 +0100 | [diff] [blame] | 172 | asm-defines-y := |
Pascal Brand | b010477 | 2014-06-12 15:56:20 +0200 | [diff] [blame] | 173 | |
| 174 | # Process subdirectories in current directory |
| 175 | $$(foreach sd, $$(sub-subdirs), $$(eval $$(call process-subdir,$$(sd)))) |
| 176 | endef #process-subdir |
| 177 | |
| 178 | # Top subdirectories |
| 179 | $(foreach sd, $(subdirs), $(eval $(call process-subdir,$(sd)))) |