import subprocess import os Import('env') env = env.Clone() host = os.environ.get('HOST', 'arm-none-eabi-') d = { 'CC': 'gcc', 'LD': 'ld', 'AR': 'ar', 'RANLIB': 'ranlib', 'OBJCOPY': 'objcopy', } for k, v in d.items(): env[k] = host + v env.Append(CCFLAGS = [ '-mcpu=cortex-m0plus', '-mthumb', '-ffunction-sections', '-fdata-sections', '-Os', ]) env.Append(LINKFLAGS = [ '-mcpu=cortex-m0plus', '-mthumb', '-specs=nano.specs', '-specs=nosys.specs', '-nostdlib', '-nostartfiles', ]) libgcc_path = \ subprocess.check_output('{} -print-libgcc-file-name'.format(env['CC']), shell=True).strip() env.Append(RUSTCFLAGS = [ '-C', 'opt-level=s', '-C', 'link-arg={}'.format(libgcc_path), '--target=thumbv6m-none-eabi', '-L', '$LIBPATH', '-l', 'common', ]) env.Append(LINKFLAGS = [ '-Wl,--gc-sections' ]) SConscript('SConscript.libcommon', exports='env', duplicate=0) bootloader_source_files = [ 'src/bootloader/main.rs', # Must be listed first (see below). 'src/bootloader/bootloader.rs', 'src/bootloader/flash.rs', ] for s in ['intermediate', 'final']: bootloader_env = env.Clone() bootloader_env.Append(RUSTCFLAGS = [ '-C', 'link-arg=-Tsrc/bootloader/bootloader-{}.ld'.format(s), '--cfg', 'bootloader_type=\\"{}\\"'.format(s) ]) bootloader_elf = \ bootloader_env.Rustc('gps-watch-bootloader-{}.elf'.format(s), bootloader_source_files[0]) for f in bootloader_source_files: Depends(bootloader_elf, f) Depends(bootloader_elf, 'libcommon.rlib') Depends(bootloader_elf, 'libcommon.a') bootloader_bin = bootloader_env.Objcopy(bootloader_elf) Default(bootloader_bin) application_source_files = [ 'src/application/main.rs', # Must be listed first (see below). 'src/application/uart0.rs', ] application_env = env.Clone() application_env.Append(RUSTCFLAGS = [ '-C', 'link-arg=-Tsrc/application/application.ld', ]) application_elf = application_env.Rustc('gps-watch-application.elf', application_source_files[0]) for f in application_source_files: Depends(application_elf, f) Depends(application_elf, 'libcommon.rlib') Depends(application_elf, 'libcommon.a') application_bin = application_env.Objcopy(application_elf) Default(application_bin)