blob: 497735d6c7383526be7b7c11155bcdd21175caf6 [file] [log] [blame]
Pascal Brandb0104772014-06-12 15:56:20 +02001# Input
2#
3# subdirs tells the subdirectories to descend
4#
5# Output
6#
Jens Wiklander13301e12017-04-06 09:07:08 +02007# set srcs gen-srcs
Pascal Brandb0104772014-06-12 15:56:20 +02008# set cflags-$(oname) cflags-remove-$(oname)
9# aflags-$(oname) aflags-remove-$(oname)
10# cppflags-$(oname) cppflags-remove-$(oname)
Jerome Forissier73dc7282014-09-25 16:04:03 +020011# incdirs-$(oname)
Jerome Forissier606f3782016-10-13 14:26:54 +020012# incdirs-lib$(libname)-$(sm) [if libname is defined]
13# cppflags-lib$(libname)-$(sm) [if libname is defined]
14# cflags-lib$(libname)-$(sm) [if libname is defined]
Pascal Brandb0104772014-06-12 15:56:20 +020015# for each file found, oname is the name of the object file for corresponding
16# source file
17
18srcs :=
Jens Wiklander13301e12017-04-06 09:07:08 +020019gen-srcs :=
Jerome Forissier070168e2018-03-12 14:45:16 +010020asm-defines-files :=
Pascal Brandb0104772014-06-12 15:56:20 +020021
22define process-subdir-srcs-y
23ifeq ($$(sub-dir),.)
Pascal Brand565e42f2014-08-07 13:42:57 +020024srcs += $1
Jerome Forissier4334e8d2014-09-08 10:53:42 +020025oname := $(out-dir)/$(base-prefix)$(basename $1).o
Pascal Brandb0104772014-06-12 15:56:20 +020026else
Pascal Brand565e42f2014-08-07 13:42:57 +020027ifneq ($(filter /%,$(1)),)
28# $1 is an absolute path - start with "/"
29srcs += $1
Jerome Forissier4334e8d2014-09-08 10:53:42 +020030oname := $(out-dir)/$(base-prefix)$(basename $1).o
Pascal Brand565e42f2014-08-07 13:42:57 +020031else
32srcs += $(sub-dir)/$1
Jerome Forissier4334e8d2014-09-08 10:53:42 +020033oname := $(out-dir)/$(base-prefix)$(basename $$(sub-dir)/$1).o
Pascal Brandb0104772014-06-12 15:56:20 +020034endif
Pascal Brand565e42f2014-08-07 13:42:57 +020035endif
Pascal Brandb0104772014-06-12 15:56:20 +020036cflags-$$(oname) := $$(cflags-y) $$(cflags-$(1)-y)
37cflags-remove-$$(oname) := $$(cflags-remove-y) \
38 $$(cflags-remove-$(1)-y)
39cppflags-$$(oname) := $$(cppflags-y) $$(cppflags-$(1)-y)
40cppflags-remove-$$(oname) := $$(cppflags-remove-y) \
41 $$(cppflags-remove-$(1)-y)
42aflags-$$(oname) := $$(aflags-y) $$(aflags-$(1)-y)
43aflags-remove-$$(oname) := $$(aflags-remove-y) \
44 $$(aflags-remove-$(1)-y)
Jerome Forissier73dc7282014-09-25 16:04:03 +020045incdirs-$$(oname) := $$(thissubdir-incdirs) $$(addprefix $(sub-dir)/,$$(incdirs-$(1)-y))
Pascal Brandb0104772014-06-12 15:56:20 +020046# Clear local filename specific variables to avoid accidental reuse
47# in another subdirectory
48cflags-$(1)-y :=
49cflags-remove-$(1)-y :=
Jerome Forissier3d34e122014-10-30 17:37:42 +010050cflags-lib-y :=
Pascal Brandb0104772014-06-12 15:56:20 +020051cppflags-$(1)-y :=
52cppflags-remove-$(1)-y :=
Jerome Forissier73dc7282014-09-25 16:04:03 +020053cppflags-lib-y :=
Pascal Brandb0104772014-06-12 15:56:20 +020054aflags-$(1)-y :=
55aflags-remove-$(1)-y :=
Jerome Forissier73dc7282014-09-25 16:04:03 +020056incdirs-$(1)-y :=
Pascal Brandb0104772014-06-12 15:56:20 +020057fname :=
58oname :=
59endef #process-subdir-srcs-y
60
Jens Wiklander36a06052016-06-02 13:52:12 +020061define process-subdir-gensrcs-helper
62# $1 gensrc-y element
63# $2 full path and name of generated source file
64# $3 full path and name of object file compiled from source file
65# $4 full path to out directory
66
Jens Wiklanderc95ce412016-05-30 16:06:35 +020067gen-srcs += $2
Jens Wiklander36a06052016-06-02 13:52:12 +020068oname := $3
69
Jens Wiklander94cd76c2018-07-17 15:47:46 +020070FORCE-GENSRC$(sm): $2
Jens Wiklander36a06052016-06-02 13:52:12 +020071
72$$(addprefix $4,$$(produce-additional-$1)): $2
73
74subdir-$2 := $$(sub-dir)
75recipe-$2 := $$(recipe-$1)
76$2: $$(depends-$1)
77 @$(cmd-echo-silent) ' GEN $2'
78 $(q)mkdir -p $4
79 $(q)$$(recipe-$2)
80
81cflags-$$(oname) := $$(cflags-y) $$(cflags-$(1)-y)
82cflags-remove-$$(oname) := $$(cflags-remove-y) \
83 $$(cflags-remove-$(1)-y)
84cppflags-$$(oname) := $$(cppflags-y) $$(cppflags-$(1)-y)
85cppflags-remove-$$(oname) := $$(cppflags-remove-y) \
86 $$(cppflags-remove-$(1)-y)
87aflags-$$(oname) := $$(aflags-y) $$(aflags-$(1)-y)
88aflags-remove-$$(oname) := $$(aflags-remove-y) \
89 $$(aflags-remove-$(1)-y)
90incdirs-$$(oname) := $$(thissubdir-incdirs) $$(addprefix $(sub-dir)/,$$(incdirs-$(1)-y))
91# Clear local filename specific variables to avoid accidental reuse
92# in another subdirectory
93cflags-$(1)-y :=
94cflags-remove-$(1)-y :=
95cflags-lib-y :=
96cppflags-$(1)-y :=
97cppflags-remove-$(1)-y :=
98cppflags-lib-y :=
99aflags-$(1)-y :=
100aflags-remove-$(1)-y :=
101incdirs-$(1)-y :=
102fname :=
103oname :=
104
105endef #process-subdir-gensrcs-helper
106
107define process-subdir-gensrcs-y
108$$(eval $$(call process-subdir-gensrcs-helper,$1,$(sub-dir-out)/$$(produce-$1),$(sub-dir-out)/$(basename $(produce-$1)).o,$(sub-dir-out)))
109endef #process-subdir-gensrcs-y
110
Jerome Forissier070168e2018-03-12 14:45:16 +0100111define process-subdir-asm-defines-y
112asm-defines-files += $(sub-dir)/$1
113endef #process-subdir-asm-defines-y
114
Pascal Brandb0104772014-06-12 15:56:20 +0200115define process-subdir
116sub-dir := $1
Jens Wiklander36a06052016-06-02 13:52:12 +0200117ifeq ($1,.)
118sub-dir-out := $(out-dir)/$(base-prefix)
119else
120sub-dir-out := $(out-dir)/$(base-prefix)$1
121endif
122
Pascal Brandb0104772014-06-12 15:56:20 +0200123include $1/sub.mk
124sub-subdirs := $$(addprefix $1/,$$(subdirs-y))
125incdirs$(sm) := $(incdirs$(sm)) $$(addprefix $1/,$$(global-incdirs-y))
Jens Wiklander36a06052016-06-02 13:52:12 +0200126thissubdir-incdirs := $(out-dir)/$(base-prefix)$1 $$(addprefix $1/,$$(incdirs-y))
Jerome Forissier73dc7282014-09-25 16:04:03 +0200127ifneq ($$(libname),)
Jerome Forissier606f3782016-10-13 14:26:54 +0200128incdirs-lib$$(libname)-$$(sm) := $$(incdirs-lib$$(libname)-$$(sm)) $$(addprefix $1/,$$(incdirs-lib-y))
129cflags-lib$$(libname)-$$(sm) := $$(cflags-lib$$(libname)-$$(sm)) $$(cflags-lib-y)
130cppflags-lib$$(libname)-$$(sm) := $$(cppflags-lib$$(libname)-$$(sm)) $$(cppflags-lib-y)
Jerome Forissier73dc7282014-09-25 16:04:03 +0200131endif
Pascal Brandb0104772014-06-12 15:56:20 +0200132
133# Process files in current directory
Jens Wiklander36a06052016-06-02 13:52:12 +0200134$$(foreach g, $$(gensrcs-y), $$(eval $$(call process-subdir-gensrcs-y,$$(g))))
Pascal Brandb0104772014-06-12 15:56:20 +0200135$$(foreach s, $$(srcs-y), $$(eval $$(call process-subdir-srcs-y,$$(s))))
Jerome Forissier070168e2018-03-12 14:45:16 +0100136$$(foreach a, $$(asm-defines-y), $$(eval $$(call process-subdir-asm-defines-y,$$(a))))
Pascal Brandb0104772014-06-12 15:56:20 +0200137# Clear flags used when processing current directory
138srcs-y :=
139cflags-y :=
Jerome Forissier3d34e122014-10-30 17:37:42 +0100140cflags-lib-y :=
Pascal Brandb0104772014-06-12 15:56:20 +0200141cppflags-y :=
Jerome Forissier73dc7282014-09-25 16:04:03 +0200142cppflags-lib-y :=
Pascal Brandb0104772014-06-12 15:56:20 +0200143aflags-y :=
144cflags-remove-y :=
145subdirs-y :=
146global-incdirs-y :=
Jerome Forissier73dc7282014-09-25 16:04:03 +0200147incdirs-lib-y :=
148incdirs-y :=
Jens Wiklander36a06052016-06-02 13:52:12 +0200149gensrcs-y :=
150this-out-dir :=
Jerome Forissier070168e2018-03-12 14:45:16 +0100151asm-defines-y :=
Pascal Brandb0104772014-06-12 15:56:20 +0200152
153# Process subdirectories in current directory
154$$(foreach sd, $$(sub-subdirs), $$(eval $$(call process-subdir,$$(sd))))
155endef #process-subdir
156
157# Top subdirectories
158$(foreach sd, $(subdirs), $(eval $(call process-subdir,$(sd))))