#
# Link OpenThread into the Thread builds (envs using [thread_flags]).
#
# The prebuilt link line of the framework does not know OpenThread. Insert it
# right before the 802.15.4 driver, so every library OpenThread depends on
# follows it on the link line. Only the firmware link carries that list; the
# ESP-IDF library pass of the hybrid compile is left alone.
#

Import("env")

libs = env.get("LIBS", [])
if "-lieee802154" in libs and "-lopenthread" not in libs:
    pos = libs.index("-lieee802154")
    env.Replace(LIBS=libs[:pos] + ["-lopenthread"] + libs[pos:])
