@@ -33,6 +33,66 @@ function(add_soc_series_subdir ic_name)
3333 endif ()
3434endfunction ()
3535
36+ # Add either a blob library or a stub source for a driver.
37+ #
38+ # Behavior:
39+ # - If CONFIG_BUILD_ONLY_NO_BLOBS=y, always use the stub source.
40+ # - Otherwise, use the blob library when present.
41+ # - If the blob library is absent, fall back to the stub source.
42+ # - If the same blob library is requested multiple times, link it only once.
43+ #
44+ # Usage:
45+ # add_blob_or_stub(
46+ # ${ZEPHYR_CURRENT_LIBRARY}
47+ # adc
48+ # <blob library path>
49+ # <stub source path>
50+ # )
51+ function (add_blob_or_stub TARGET NAME BLOB_LIB_PATH STUB_FILE )
52+ string (TOUPPER "${NAME} " NAME_UPPER)
53+
54+ set (use_stubs FALSE )
55+
56+ if (CONFIG_BUILD_ONLY_NO_BLOBS)
57+ message (STATUS "CONFIG_BUILD_ONLY_NO_BLOBS=y, forcing ${NAME_UPPER} stubs" )
58+ set (use_stubs TRUE )
59+ elseif (EXISTS "${BLOB_LIB_PATH} " )
60+ get_property (linked_blobs GLOBAL PROPERTY REALTEK_BLOB_LIBS_LINKED)
61+ if (NOT linked_blobs)
62+ set (linked_blobs "" )
63+ endif ()
64+
65+ list (FIND linked_blobs "${BLOB_LIB_PATH} " blob_index)
66+ if (blob_index EQUAL -1)
67+ message (STATUS "Using ${NAME_UPPER} blob library: ${BLOB_LIB_PATH} " )
68+ target_link_libraries (${TARGET} PUBLIC ${BLOB_LIB_PATH} )
69+ set_property (GLOBAL APPEND PROPERTY REALTEK_BLOB_LIBS_LINKED "${BLOB_LIB_PATH} " )
70+ else ()
71+ message (STATUS
72+ "${NAME_UPPER} blob library already linked, skipping duplicate: "
73+ "${BLOB_LIB_PATH} "
74+ )
75+ endif ()
76+ else ()
77+ message (STATUS
78+ "${NAME_UPPER} blob library not found: ${BLOB_LIB_PATH} \n "
79+ "Falling back to ${NAME_UPPER} stubs"
80+ )
81+ set (use_stubs TRUE )
82+ endif ()
83+
84+ if (use_stubs)
85+ if (EXISTS "${STUB_FILE} " )
86+ message (STATUS "Using ${NAME_UPPER} stub source: ${STUB_FILE} " )
87+ zephyr_library_sources (${STUB_FILE} )
88+ else ()
89+ message (FATAL_ERROR
90+ "${NAME_UPPER} stub source not found: ${STUB_FILE} "
91+ )
92+ endif ()
93+ endif ()
94+ endfunction ()
95+
3696add_subdirectory (adc )
3797add_subdirectory_ifdef (CONFIG_REALTEK_BEE_BT bluetooth )
3898add_subdirectory (can )
0 commit comments