forked from KOMA-Elektronik/FieldKitFX
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextra_script.py
More file actions
20 lines (17 loc) · 1.05 KB
/
extra_script.py
File metadata and controls
20 lines (17 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from os import makedirs
from os.path import isdir, join
Import('env')
# bugfix for Weak symbols (https://github.com/platformio/platformio-core/issues/2070)
# Surround the library archives with linker --whole-archive/--no-whole-archive pair
libString = env.subst("$_LIBFLAGS") # something like "-Wl,--start-group .pioenvs/foo/libFrameworkArduinoVariant.a .pioenvs/foo/libFrameworkArduino.a -larm_cortexM7l_math -lc -lm -lgcc -lstdc++ -lc -Wl,--end-group"
libString += ' -O3 -mfloat-abi=hard -mfpu=fpv4-sp-d16'
# -flto -fuse-linker-plugin'
tokens = libString.lstrip(' ').rstrip(' ').split()
archives = [t for t in tokens if t.endswith(".a")] # find the archives
tokens = [t for t in tokens if t not in archives] # remove the archives from the orignal set
#rebuild a new string with --whole-archive option pair surrounding the archives
newLibString = ' '.join([tokens[0] , "-Wl,--whole-archive"] + archives + ["-Wl,--no-whole-archive"] +tokens[1:])
env.Replace(
_LIBFLAGS=newLibString,
LINKCOM='$LINK -o $TARGET $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
)