build: Link libgcc from the command line instead of the linker script.
[gps-watch.git] / SConscript.target
index b42eecef5f6166c51d73698c4abfe52e89e679db..1e5f40299db24dddac0bd645cf7ae25436c96fab 100644 (file)
@@ -1,3 +1,4 @@
+import subprocess
 import os
 
 Import('env')
@@ -33,6 +34,10 @@ env.Append(LINKFLAGS = [
     '-nostartfiles',
 ])
 
+libgcc_path = \
+    subprocess.check_output('{} -print-libgcc-file-name'.format(env['CC']),
+                            shell=True).strip()
+
 env.Append(RUSTCFLAGS = [
     '-C', 'opt-level=s',
     '--target=thumbv6m-none-eabi',
@@ -76,9 +81,15 @@ for s in ['intermediate', 'final']:
         '-Tsrc/bootloader/bootloader-{}.ld'.format(s),
     ])
 
+    bootloader_libs = [
+        'bootloader-{}'.format(s),
+        'common',
+        File(libgcc_path),
+    ]
+
     bootloader_elf = \
         bootloader_env.Program('gps-watch-bootloader-{}.elf'.format(s),
-                               start_o, LIBS = ['bootloader-{}'.format(s), 'common'])
+                               start_o, LIBS = bootloader_libs)
 
     bootloader_bin = bootloader_env.Objcopy(bootloader_elf)
 
@@ -104,9 +115,14 @@ application_env.Append(LINKFLAGS = [
     '-Tsrc/application/application.ld'
 ])
 
+application_libs = [
+    'application',
+    'common',
+    File(libgcc_path),
+]
+
 application_elf = application_env.Program('gps-watch-application.elf',
-                                          start_o,
-                                          LIBS = ['application', 'common'])
+                                          start_o, LIBS = application_libs)
 
 application_bin = application_env.Objcopy(application_elf)