# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.

# SPDX-License-Identifier: MIT

aml_add_library()

if(CONFIG_EXCEPTION_SVC)
target_compile_options(${CURRENT_LIBRARY} PUBLIC -DGUEST)
endif()

aml_library_sources(
	list.c
	queue.c
	tasks.c
	event_groups.c
	timers.c
	stream_buffer.c
	croutine.c
)

add_subdirectory(portable/${CONFIG_KERNEL_COMPILER_DIR}/${CONFIG_KERNEL_ARCH_DIR})

if(CONFIG_KERNEL_HEAP_TYPE_4_COMM)
aml_library_sources(
	portable/MemMang/heap_4_comm.c
)
elseif(CONFIG_KERNEL_HEAP_TYPE_5)
aml_library_sources(
	portable/MemMang/heap_5.c
)
elseif(CONFIG_KERNEL_HEAP_TYPE_4)
aml_library_sources(
	portable/MemMang/heap_4.c
)
elseif(CONFIG_KERNEL_HEAP_TYPE_3)
aml_library_sources(
	portable/MemMang/heap_3.c
)
elseif(CONFIG_KERNEL_HEAP_TYPE_2)
aml_library_sources(
	portable/MemMang/heap_2.c
)
else()
aml_library_sources(
	portable/MemMang/heap_1.c
)
endif()

#XTENSA toolchain not support Wno-builtin-macro-redefined
if(CONFIG_ARM OR CONFIG_ARM64 OR CONFIG_RISCV)
redefine_file_macro()
target_compile_options(
    ${CURRENT_LIBRARY}
    PRIVATE
    -Wno-builtin-macro-redefined
)
endif()

aml_library_include_directories(
	include
	aml_extend
)

aml_library_link_libraries(arch__${ARCH})
aml_library_link_libraries(drivers)

if(CONFIG_BACKTRACE)
aml_library_link_libraries(lib__backtrace)
endif()
if(CONFIG_BARECTF)
aml_library_link_libraries(utilities__barectf)
endif()

aml_link_libraries()
