xref: /optee_os/mk/subdir.mk (revision b01047730e77127c23a36591643eeb8bb0487d68)
1# Input
2#
3# subdirs	tells the subdirectories to descend
4#
5# Output
6#
7# set srcs
8# set     cflags-$(oname) cflags-remove-$(oname)
9#         aflags-$(oname) aflags-remove-$(oname)
10#         cppflags-$(oname) cppflags-remove-$(oname)
11# for each file found, oname is the name of the object file for corresponding
12# source file
13
14srcs :=
15
16define process-subdir-srcs-y
17ifeq ($$(sub-dir),.)
18fname				:= $1
19oname				:= $(out-dir)$(base-prefix)$(basename $1).o
20else
21fname				:= $(sub-dir)/$1
22oname				:= $(out-dir)$(base-prefix)$(basename $$(sub-dir)/$1).o
23endif
24srcs 				+= $$(fname)
25cflags-$$(oname) 		:= $$(cflags-y) $$(cflags-$(1)-y)
26cflags-remove-$$(oname) 	:= $$(cflags-remove-y) \
27					$$(cflags-remove-$(1)-y)
28cppflags-$$(oname) 		:= $$(cppflags-y) $$(cppflags-$(1)-y)
29cppflags-remove-$$(oname) 	:= $$(cppflags-remove-y) \
30					$$(cppflags-remove-$(1)-y)
31aflags-$$(oname) 		:= $$(aflags-y) $$(aflags-$(1)-y)
32aflags-remove-$$(oname) 	:= $$(aflags-remove-y) \
33					$$(aflags-remove-$(1)-y)
34# Clear local filename specific variables to avoid accidental reuse
35# in another subdirectory
36cflags-$(1)-y 			:=
37cflags-remove-$(1)-y		:=
38cppflags-$(1)-y			:=
39cppflags-remove-$(1)-y		:=
40aflags-$(1)-y 			:=
41aflags-remove-$(1)-y		:=
42fname				:=
43oname				:=
44endef #process-subdir-srcs-y
45
46define process-subdir
47sub-dir := $1
48include $1/sub.mk
49sub-subdirs := $$(addprefix $1/,$$(subdirs-y))
50incdirs$(sm) := $(incdirs$(sm)) $$(addprefix $1/,$$(global-incdirs-y))
51
52# Process files in current directory
53$$(foreach s, $$(srcs-y), $$(eval $$(call process-subdir-srcs-y,$$(s))))
54# Clear flags used when processing current directory
55srcs-y :=
56cflags-y :=
57cppflags-y :=
58aflags-y :=
59cflags-remove-y :=
60subdirs-y :=
61global-incdirs-y :=
62
63# Process subdirectories in current directory
64$$(foreach sd, $$(sub-subdirs), $$(eval $$(call process-subdir,$$(sd))))
65endef #process-subdir
66
67# Top subdirectories
68$(foreach sd, $(subdirs), $(eval $(call process-subdir,$(sd))))
69