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