application: Factor out the configure_push_buttons() function.
[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()
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', exports='env', duplicate=0)
54
55 bootloader_source_files = [
56     'src/bootloader/main.rs', # Must be listed first (see below).
57     'src/bootloader/bootloader.rs',
58     'src/bootloader/flash.rs',
59 ]
60
61 for s in ['intermediate', 'final']:
62     bootloader_env = env.Clone()
63
64     bootloader_env.Append(RUSTCFLAGS = [
65         '-C', 'link-arg=-Tsrc/bootloader/bootloader-{}.ld'.format(s),
66         '--cfg',
67         'bootloader_type=\\"{}\\"'.format(s)
68     ])
69
70     bootloader_elf = \
71         bootloader_env.Rustc('gps-watch-bootloader-{}.elf'.format(s),
72                              bootloader_source_files[0])
73
74     for f in bootloader_source_files:
75         Depends(bootloader_elf, f)
76
77     Depends(bootloader_elf, 'libcommon.rlib')
78     Depends(bootloader_elf, 'libcommon.a')
79
80     bootloader_bin = bootloader_env.Objcopy(bootloader_elf)
81
82     Default(bootloader_bin)
83
84 application_source_files = [
85     'src/application/main.rs', # Must be listed first (see below).
86     'src/application/uart0.rs',
87 ]
88
89 application_env = env.Clone()
90
91 application_env.Append(RUSTCFLAGS = [
92     '-C', 'link-arg=-Tsrc/application/application.ld',
93 ])
94
95 application_elf = application_env.Rustc('gps-watch-application.elf',
96                                         application_source_files[0])
97
98 for f in application_source_files:
99     Depends(application_elf, f)
100
101 Depends(application_elf, 'libcommon.rlib')
102 Depends(application_elf, 'libcommon.a')
103
104 application_bin = application_env.Objcopy(application_elf)
105
106 Default(application_bin)