1# Settings for Xtensa toolchain for the hifimini kernels.
2# REQUIRED:
3#  Environment variables:
4#   - XTENSA_BASE  must be set to location of
5#     the Xtensa developer tools installation directory.
6#  Command line arguments:
7#   - XTENSA_TOOLS_VERSION: For example: RI-2019.2-linux
8#   - XTENSA_CORE: The name of the Xtensa core to use
9#      For example: hifimini
10
11TARGET_ARCH :=
12XTENSA_USE_LIBC :=
13
14ifndef XTENSA_BASE
15  $(error XTENSA_BASE is undefined)
16endif
17
18ifndef XTENSA_TOOLS_VERSION
19  $(error XTENSA_TOOLS_VERSION is undefined)
20endif
21
22ifndef XTENSA_CORE
23  $(error XTENSA_CORE is undefined)
24endif
25
26ifeq ($(TARGET_ARCH), )
27  $(error TARGET_ARCH must be specified on the command line)
28endif
29
30# Create a cflag based on the specified TARGET_ARCH. For example:
31#   TARGET_ARCH=hifi4 --> -DHIFI4
32TARGET_ARCH_DEFINES := -D$(shell echo $(TARGET_ARCH) | tr [a-z] [A-Z])
33
34PLATFORM_FLAGS = \
35  -DTF_LITE_MCU_DEBUG_LOG \
36  -DTF_LITE_USE_CTIME \
37  --xtensa-core=$(XTENSA_CORE) \
38  -mcoproc \
39  -DMAX_RFFT_PWR=9 \
40  -DMIN_RFFT_PWR=MAX_RFFT_PWR \
41  $(TARGET_ARCH_DEFINES) \
42  -mlongcalls
43
44ifeq ($(BUILD_TYPE), release)
45  PLATFORM_FLAGS += -Wno-unused-private-field
46endif
47
48export PATH := $(XTENSA_BASE)/tools/$(XTENSA_TOOLS_VERSION)/XtensaTools/bin:$(PATH)
49TARGET_TOOLCHAIN_PREFIX := xt-
50CXX_TOOL := clang++
51CC_TOOL := clang
52
53# Unused exception related symbols make their way into a binary that links
54# against TFLM as described in https://github.com/tensorflow/tensorflow/issues/47575.
55# We have two options to avoid this. The first involves using -stdlib=libc++ and
56# the second involves stubbing out and modifying some of the files in the Xtensa
57# toolchain to prevent inclusion of the exception handling code
58# (http://b/182209217#comment3). This Makefile supports building TFLM in a way
59# that is compatible with either of the two approaches.
60ifeq ($(XTENSA_USE_LIBC), true)
61  PLATFORM_FLAGS += -stdlib=libc++
62else
63  # TODO(b/150240249): Do not filter-out -fno-rtti once that works for the
64  # Xtensa toolchain.
65  CXXFLAGS := $(filter-out -fno-rtti, $(CXXFLAGS))
66endif
67
68CXXFLAGS += $(PLATFORM_FLAGS)
69CCFLAGS += $(PLATFORM_FLAGS)
70
71TEST_SCRIPT := tensorflow/lite/micro/testing/test_xtensa_binary.sh
72
73# TODO(b/158651472): Fix the memory_arena_threshold_test
74# TODO(b/174707181): Fix the micro_interpreter_test
75EXCLUDED_TESTS := \
76  tensorflow/lite/micro/micro_interpreter_test.cc \
77  tensorflow/lite/micro/memory_arena_threshold_test.cc
78MICROLITE_TEST_SRCS := $(filter-out $(EXCLUDED_TESTS), $(MICROLITE_TEST_SRCS))
79
80# TODO(b/156962140): This manually maintained list of excluded examples is
81# quite error prone.
82EXCLUDED_EXAMPLE_TESTS := \
83  tensorflow/lite/micro/examples/hello_world/Makefile.inc \
84  tensorflow/lite/micro/examples/image_recognition_experimental/Makefile.inc \
85  tensorflow/lite/micro/examples/magic_wand/Makefile.inc \
86  tensorflow/lite/micro/examples/network_tester/Makefile.inc
87MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TESTS))
88