application: Use the Button struct to handle the play button.
[gps-watch.git] / SConscript.target
1 import subprocess
2 import os
3
4 Import('env')
5 env = env.Clone()
6
7 host = os.environ.get('HOST', 'arm-none-eabi-')
8
9 d = {
10     'CC': 'gcc',
11     'LD': 'ld',
12     'AR': 'ar',
13     'RANLIB': 'ranlib',
14     'OBJCOPY': 'objcopy',
15 }
16
17 for k, v in d.items():
18     env[k] = host + v
19
20 env.Append(CCFLAGS = [
21     '-mcpu=cortex-m0plus',
22     '-mthumb',
23     '-ffunction-sections',
24     '-fdata-sections',
25     '-Os',
26 ])
27
28 env.Append(LINKFLAGS = [
29     '-mcpu=cortex-m0plus',
30     '-mthumb',
31     '-specs=nano.specs',
32     '-specs=nosys.specs',
33     '-nostdlib',
34     '-nostartfiles',
35 ])
36
37 libgcc_path = \
38     subprocess.check_output('{} -print-libgcc-file-name'.format(env['CC']),
39                             shell=True).strip().decode('utf-8')
40
41 env.Append(RUSTCFLAGS = [
42     '-C', 'opt-level=s',
43     '-C', 'link-arg={}'.format(libgcc_path),
44     '--target=thumbv6m-none-eabi',
45     '-L', '$LIBPATH',
46     '-l', 'common',
47 ])
48
49 env.Append(LINKFLAGS = [
50     '-Wl,--gc-sections'
51 ])
52
53 SConscript('SConscript.libcommon.c', exports='env', duplicate=0)
54 SConscript('SConscript.libcommon.rs', exports='env', duplicate=0)
55
56 bootloader_source_files = [
57     'src/bootloader/main.rs', # Must be listed first (see below).
58     'src/bootloader/bootloader.rs',
59     'src/bootloader/flash.rs',
60 ]
61
62 for s in ['intermediate', 'final']:
63     bootloader_env = env.Clone()
64
65     bootloader_env.Append(RUSTCFLAGS = [
66         '-C', 'link-arg=-Tsrc/bootloader/bootloader-{}.ld'.format(s),
67         '--cfg',
68         'bootloader_type=\\"{}\\"'.format(s)
69     ])
70
71     bootloader_elf = \
72         bootloader_env.Rustc('gps-watch-bootloader-{}.elf'.format(s),
73                              bootloader_source_files[0])
74
75     for f in bootloader_source_files:
76         Depends(bootloader_elf, f)
77
78     Depends(bootloader_elf, 'libcommon.rlib')
79     Depends(bootloader_elf, 'libcommon.a')
80
81     bootloader_bin = bootloader_env.Objcopy(bootloader_elf)
82
83     Default(bootloader_bin)
84
85 application_source_files = [
86     'src/application/main.rs', # Must be listed first (see below).
87     'src/application/button.rs',
88     'src/application/uart0.rs',
89 ]
90
91 application_env = env.Clone()
92
93 application_env.Append(RUSTCFLAGS = [
94     '-C', 'link-arg=-Tsrc/application/application.ld',
95 ])
96
97 application_elf = application_env.Rustc('gps-watch-application.elf',
98                                         application_source_files[0])
99
100 for f in application_source_files:
101     Depends(application_elf, f)
102
103 Depends(application_elf, 'libcommon.rlib')
104 Depends(application_elf, 'libcommon.a')
105
106 application_bin = application_env.Objcopy(application_elf)
107
108 Default(application_bin)