Skip to content

Commit 708eff2

Browse files
committed
Put custom ldscript in front
1 parent 65f30dd commit 708eff2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

platformio/builder/tools/platformio.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,25 @@ def _append_pio_macros():
122122
if (env.get("LDSCRIPT_PATH")
123123
and not any("-Wl,-T" in f for f in env['LINKFLAGS'])):
124124
env.Prepend(LINKFLAGS=["-T", "$LDSCRIPT_PATH"])
125+
# or parse user-provided -Wl,-T... and prepend it before any other arguments
126+
else:
127+
flags = env["LINKFLAGS"]
128+
filtered = []
129+
ldscript = None
130+
131+
while len(flags):
132+
flag = flags.pop(0)
133+
if "-Wl,-T" in flag:
134+
ldscript = flag.replace("-Wl,", "")
135+
continue
136+
137+
filtered.append(flag)
138+
139+
filtered.insert(0, ldscript)
140+
env.Replace(LINKFLAGS=filtered)
141+
142+
# TODO removeme
143+
print(env["LINKFLAGS"])
125144

126145
# enable "cyclic reference" for linker
127146
if env.get("LIBS") and env.GetCompilerType() == "gcc":

0 commit comments

Comments
 (0)