[PATCH v2 5/6] build: Allow enabled-by in ldflags for link_cc and link_cxx

Alex White alex.white at oarcorp.com
Wed Aug 30 02:05:28 UTC 2023


This allows for conditionally setting 'ldflags' in scripts that use
`link_cc` and `link_cxx`. The immediate use case is allowing a linker
flag to be used only for MicroBlaze builds of certain tests.
---
 wscript | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/wscript b/wscript
index 280c3929cd..03c6ac1035 100755
--- a/wscript
+++ b/wscript
@@ -353,10 +353,10 @@ class Item(object):
 
         class link(Task):
 
-            def __init__(self, item, bic, cmd, env):
+            def __init__(self, item, bic, cmd, env, ldflags):
                 super(link, self).__init__(self, env=env)
                 self.cmd = cmd
-                self.ldflags = bic.ldflags + item.data["ldflags"]
+                self.ldflags = bic.ldflags + ldflags
                 self.stlib = item.data["stlib"]
                 self.use = (item.data["use-before"] + bic.use +
                             item.data["use-after"])
@@ -382,7 +382,14 @@ class Item(object):
                     [],
                 )
 
-        tsk = link(self, bic, cmd, bld.env)
+        ldflags = []
+        for ldflag in self.data["ldflags"]:
+            if isinstance(ldflag, dict):
+                if _is_enabled(bld.env.ENABLE, ldflag["enabled-by"]):
+                    ldflags.append(ldflag["value"])
+            else:
+                ldflags.append(ldflag)
+        tsk = link(self, bic, cmd, bld.env, ldflags)
         tsk.set_inputs([bld.bldnode.make_node(s) for s in source])
         tsk.set_outputs(bld.bldnode.make_node(target))
         bld.add_to_group(tsk)
-- 
2.34.1



More information about the devel mailing list