Add README.
[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 bootloader_bins = []
63
64 for s in ['intermediate', 'final']:
65     bootloader_env = env.Clone()
66
67     bootloader_env.Append(RUSTCFLAGS = [
68         '-C', 'link-arg=-Tsrc/bootloader/bootloader-{}.ld'.format(s),
69         '--cfg',
70         'bootloader_type=\\"{}\\"'.format(s)
71     ])
72
73     bootloader_elf = \
74         bootloader_env.Rustc('gps-watch-bootloader-{}.elf'.format(s),
75                              bootloader_source_files[0])
76
77     for f in bootloader_source_files:
78         Depends(bootloader_elf, f)
79
80     Depends(bootloader_elf, 'libcommon.rlib')
81     Depends(bootloader_elf, 'libcommon.a')
82
83     bootloader_bin = bootloader_env.Objcopy(bootloader_elf)
84
85     Default(bootloader_bin)
86
87     bootloader_bins.append(bootloader_bin)
88
89 bootloader_intermediate_frm = \
90     bootloader_env.Frm(bootloader_bins[0])
91
92 Default(bootloader_intermediate_frm)
93
94 application_source_files = [
95     'src/application/main.rs', # Must be listed first (see below).
96     'src/application/button.rs',
97     'src/application/model.rs',
98     'src/application/views.rs',
99     'src/application/uart0.rs',
100 ]
101
102 application_env = env.Clone()
103
104 application_env.Append(RUSTCFLAGS = [
105     '-C', 'link-arg=-Tsrc/application/application.ld',
106 ])
107
108 application_elf = application_env.Rustc('gps-watch-application.elf',
109                                         application_source_files[0])
110
111 for f in application_source_files:
112     Depends(application_elf, f)
113
114 Depends(application_elf, 'libcommon.rlib')
115 Depends(application_elf, 'libcommon.a')
116
117 application_bin = application_env.Objcopy(application_elf)
118
119 Default(application_bin)