1ifeq ($O,)
2out-dir := $(CURDIR)/out
3else
4include scripts/common.mk
5out-dir := $(call strip-trailing-slashes-and-dots,$(O))
6ifeq ($(out-dir),)
7$(error invalid output directory (O=$(O)))
8endif
9endif
10
11bindir ?= /bin
12libdir ?= /lib
13
14-include $(TA_DEV_KIT_DIR)/host_include/conf.mk
15-include $(OPTEE_CLIENT_EXPORT)/include/optee_client_config.mk
16
17ifneq ($V,1)
18	q := @
19	echo := @echo
20else
21	q :=
22	echo := @:
23endif
24# export 'q', used by sub-makefiles.
25export q
26
27# If _HOST or _TA specific compilers are not specified, then use CROSS_COMPILE
28CROSS_COMPILE_HOST ?= $(CROSS_COMPILE)
29CROSS_COMPILE_TA ?= $(CROSS_COMPILE)
30
31.PHONY: all
32ifneq ($(wildcard $(TA_DEV_KIT_DIR)/host_include/conf.mk),)
33all: xtest ta test_plugin
34else
35all:
36	$(q)echo "TA_DEV_KIT_DIR is not correctly defined" && false
37endif
38
39.PHONY: xtest
40xtest:
41	$(q)$(MAKE) -C host/xtest CROSS_COMPILE="$(CROSS_COMPILE_HOST)" \
42			     --no-builtin-variables \
43			     O=$(out-dir) \
44			     $@
45
46.PHONY: ta
47ta:
48	$(q)$(MAKE) -C ta CROSS_COMPILE="$(CROSS_COMPILE_TA)" \
49			  O=$(out-dir) \
50			  $@
51
52.PHONY: test_plugin
53test_plugin:
54	$(q)$(MAKE) -C host/supp_plugin CROSS_COMPILE="$(CROSS_COMPILE_HOST)" \
55			     --no-builtin-variables \
56			     O=$(out-dir)
57
58.PHONY: clean
59ifneq ($(wildcard $(TA_DEV_KIT_DIR)/host_include/conf.mk),)
60clean:
61	$(q)$(MAKE) -C host/xtest O=$(out-dir) $@
62	$(q)$(MAKE) -C ta O=$(out-dir) $@
63	$(q)$(MAKE) -C host/supp_plugin O=$(out-dir) $@
64else
65clean:
66	$(q)echo "TA_DEV_KIT_DIR is not correctly defined"
67	$(q)echo "You can remove manually $(out-dir)"
68endif
69
70.PHONY: checkpatch checkpatch-staging checkpatch-working
71checkpatch: checkpatch-staging checkpatch-working
72
73checkpatch-working:
74	@./scripts/checkpatch.sh
75
76checkpatch-staging:
77	@./scripts/checkpatch.sh --cached
78
79install:
80	$(echo) '  INSTALL ${DESTDIR}${libdir}/optee_armtz'
81	$(q)mkdir -p ${DESTDIR}${libdir}/optee_armtz
82	$(q)find $(out-dir) -name \*.ta -exec cp {} ${DESTDIR}${libdir}/optee_armtz \;
83	$(echo) '  INSTALL ${DESTDIR}${bindir}'
84	$(q)mkdir -p ${DESTDIR}${bindir}
85	$(q)cp $(out-dir)/xtest/xtest ${DESTDIR}${bindir}
86	$(echo) '  INSTALL ${DESTDIR}/$(CFG_TEE_PLUGIN_LOAD_PATH)'
87	$(q)mkdir -p ${DESTDIR}/$(CFG_TEE_PLUGIN_LOAD_PATH)
88	$(q)cp $(out-dir)/supp_plugin/*.plugin ${DESTDIR}/$(CFG_TEE_PLUGIN_LOAD_PATH)
89
90.PHONY: cscope
91cscope:
92	$(echo) '  CSCOPE  .'
93	${q}rm -f cscope.*
94	${q}find $(PWD) -name "*.[ch]" -o -name "*.cpp" | grep -v /package/ > cscope.files
95	${q}cscope -b -q -k
96