From ea8e2e2b6f07f69ea35e7e76c64b6880438fa987 Mon Sep 17 00:00:00 2001
From: Peng Fan <Peng.Fan@freescale.com>
Date: Sun, 27 Jul 2014 21:34:18 +0800
Subject: [PATCH] Fix multiple same options in rtems_linkflags problem

When assign same options such as '--lib m --lib rtemscpu --lib rtemsbsp',
waf only keeps one '--lib' in the final executed command, and rtems-ld
will complain 'can not open rtemscpu'. This is because waf use python set
to process USELIB_VARS and call 'append_unique' to append flags to env.
This patch fixes this problem.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
---
 rtems.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/rtems.py b/rtems.py
index 84cd193..469c513 100644
--- a/rtems.py
+++ b/rtems.py
@@ -511,9 +511,26 @@ def _log_header(conf):
     conf.to_log('-----------------------------------------')
 
 from waflib import TaskGen
-from waflib.Tools.ccroot import link_task, USELIB_VARS
+from waflib.Tools.ccroot import link_task, USELIB_VARS, feature, before_method
 USELIB_VARS['rap'] = set(['RTEMS_LINKFLAGS'])
 USELIB_VARS['ra'] = set(['RTEMS_RAFLAGS'])
+
+@feature('rap')
+@before_method('apply_link')
+def reassign_rtems_linkflags(self):
+    env = self.env
+    _rtems_linkflags =  env._get_list_value_for_modification('RTEMS_LINKFLAGS')
+    if _rtems_linkflags == False:
+        return
+
+    env.table['RTEMS_LINKFLAGS'] = []
+    _vars = self.get_uselib_vars()
+
+    for x in _vars:
+        y = x.lower()
+        if y == 'rtems_linkflags':
+            env.append_value(x, self.to_list(getattr(self, y, [])))
+
 @TaskGen.extension('.c')
 class rap(link_task):
         "Link object files into a RTEMS applicatoin"
-- 
1.8.4.5

