1SHELL = bash
2
3# It can happen that a makefile calls us, which contains an 'export' directive
4# or the '.EXPORT_ALL_VARIABLES:' special target. In this case, all the make
5# variables are added to the environment for each line of the recipes, so that
6# any sub-makefile can use them.
7# We have observed this can cause issues such as 'Argument list too long'
8# errors as the shell runs out of memory.
9# Since this Makefile won't call any sub-makefiles, and since the commands do
10# not expect to implicitely obtain any make variable from the environment, we
11# can safely cancel this export mechanism. Unfortunately, it can't be done
12# globally, only by name. Let's unexport MAKEFILE_LIST which is by far the
13# biggest one due to our way of tracking dependencies and compile flags
14# (we include many *.cmd and *.d files).
15unexport MAKEFILE_LIST
16
17# Automatically delete corrupt targets (file updated but recipe exits with a
18# nonzero status). Useful since a few recipes use shell redirection.
19.DELETE_ON_ERROR:
20
21include mk/checkconf.mk
22
23.PHONY: all
24all:
25
26.PHONY: mem_usage
27mem_usage:
28
29# log and load eventual tee config file
30# path is absolute or relative to current source root directory.
31ifdef CFG_OPTEE_CONFIG
32$(info Loading OPTEE configuration file $(CFG_OPTEE_CONFIG))
33include $(CFG_OPTEE_CONFIG)
34endif
35
36# If $(PLATFORM) is defined and contains a hyphen, parse it as
37# $(PLATFORM)-$(PLATFORM_FLAVOR) for convenience
38ifneq (,$(findstring -,$(PLATFORM)))
39ops := $(join PLATFORM PLATFORM_FLAVOR,$(addprefix =,$(subst -, ,$(PLATFORM))))
40$(foreach op,$(ops),$(eval override $(op)))
41endif
42
43# Make these default for now
44$(call force,ARCH,arm)
45PLATFORM        ?= vexpress
46# Default value for PLATFORM_FLAVOR is set in plat-$(PLATFORM)/conf.mk
47ifeq ($O,)
48O               := out
49out-dir         := $(O)/$(ARCH)-plat-$(PLATFORM)
50else
51out-dir         := $(O)
52endif
53
54arch_$(ARCH)	:= y
55
56ifneq ($V,1)
57q := @
58cmd-echo := true
59cmd-echo-silent := echo
60else
61q :=
62cmd-echo := echo
63cmd-echo-silent := true
64endif
65
66ifneq ($(filter 4.%,$(MAKE_VERSION)),)  # make-4
67ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
68cmd-echo-silent := true
69endif
70else                                    # make-3.8x
71ifneq ($(findstring s, $(MAKEFLAGS)),)
72cmd-echo-silent := true
73endif
74endif
75
76SCRIPTS_DIR := scripts
77
78include core/core.mk
79
80# Platform/arch config is supposed to assign the targets
81ta-targets ?= invalid
82default-user-ta-target ?= $(firstword $(ta-targets))
83
84ifeq ($(CFG_WITH_USER_TA),y)
85include ldelf/ldelf.mk
86define build-ta-target
87ta-target := $(1)
88include ta/ta.mk
89endef
90$(foreach t, $(ta-targets), $(eval $(call build-ta-target, $(t))))
91
92# Build user TAs included in this git
93define build-user-ta
94ta-mk-file := $(1)
95include ta/mk/build-user-ta.mk
96endef
97$(foreach t, $(sort $(wildcard ta/*/user_ta.mk)), $(eval $(call build-user-ta,$(t))))
98endif
99
100include mk/cleandirs.mk
101
102.PHONY: clean
103clean:
104	@$(cmd-echo-silent) '  CLEAN   $(out-dir)'
105	$(call do-rm-f, $(cleanfiles))
106	${q}dirs="$(call cleandirs-for-rmdir)"; if [ "$$dirs" ]; then $(RMDIR) $$dirs; fi
107	@if [ "$(out-dir)" != "$(O)" ]; then $(cmd-echo-silent) '  CLEAN   $(O)'; fi
108	${q}if [ -d "$(O)" ]; then $(RMDIR) $(O); fi
109
110.PHONY: cscope
111cscope:
112	@echo '  CSCOPE  .'
113	${q}rm -f cscope.*
114	${q}find $(PWD) -name "*.[chSs]" | grep -v export-ta_ > cscope.files
115	${q}cscope -b -q -k
116
117.PHONY: checkpatch checkpatch-staging checkpatch-working
118checkpatch: checkpatch-staging checkpatch-working
119
120checkpatch-working:
121	${q}./scripts/checkpatch.sh
122
123checkpatch-staging:
124	${q}./scripts/checkpatch.sh --cached
125