def configure(conf):
    if conf.is_silk():
        conf.env.append_unique('DEFINES', 'STM32F412xG')
    elif conf.env.MICRO_FAMILY == 'STM32F4':
        conf.env.append_unique('DEFINES', 'STM32F429_439xx')
    elif conf.env.MICRO_FAMILY == 'STM32F7':
        conf.env.append_unique('DEFINES', 'STM32F779xx')
    conf.recurse('FreeRTOS')
    if conf.capability('HAS_JAVASCRIPT'):
        conf.recurse('jerryscript')

def build(bld):
    bld.recurse('tinymt32')
    bld.recurse('FreeRTOS')
    bld.recurse('nanopb')

    if bld.env.MICRO_FAMILY == 'STM32F4':
        if bld.is_silk():
            excludes = ['**/stm32f4xx_fmc.c']
        else:
            excludes = ['**/stm32f4xx_fsmc.c']

        stm32_sources = bld.path.ant_glob('STM32F4xx_StdPeriph_Driver/src/*.c',
                                          excl=excludes)

        stm32_includes = ['CMSIS/Include',
                          'CMSIS/Device/ST/STM32F4xx/Include',
                          'STM32F4xx_StdPeriph_Driver/inc']

    elif bld.env.MICRO_FAMILY == 'STM32F2':
        stm32_sources = bld.path.ant_glob('STM32F2xx_StdPeriph_Driver/src/*.c')

        stm32_includes = ['CMSIS/Include',
                          'CMSIS/Device/ST/STM32F2xx/Include',
                          'STM32F2xx_StdPeriph_Driver/inc']

    elif bld.env.MICRO_FAMILY == 'STM32F7':
        stm32_sources = bld.path.ant_glob('stm32f7haxx_stdperiph/*.c')

        stm32_includes = ['CMSIS/Include',
                          'CMSIS/Device/ST/STM32F7xx/Include',
                          'stm32f7haxx_stdperiph']
    else:
        bld.fatal("No microcontroller family set for this build")

    bld.stlib(source=stm32_sources,
              target='stm32_stdlib',
              use='pblibc',
              # Parent dir is included for stm32fxxx_conf.h
              includes=stm32_includes + ['..'],
              export_includes=stm32_includes)

# vim:filetype=python
