# for module compiling
from building import *
import rtconfig
import os
Import('RTT_ROOT')
Import('BOARD_FILES')
Import('BOARD_HEADER')
Import('BOARD_DEFINES')
Import('START_UP_FILE')

cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
path=[cwd]
for p in BOARD_HEADER:
    path = path + [cwd+'/'+p]
path += [cwd+'/../../mcu_lib/st_driver/CMSIS/Include']

# add teeny usb sources
src = []
src += ['teeny_usb_desc.c']

for p in Split(BOARD_FILES):
    src += [cwd+'/'+p]
if START_UP_FILE[rtconfig.CROSS_TOOL]:
    src += [cwd+'/'+START_UP_FILE[rtconfig.CROSS_TOOL]]

objs = objs + DefineGroup('Board', src, depend = [''], CPPPATH = path, CPPDEFINES = BOARD_DEFINES)

TUSB_DFEFINES=['USE_RTTHREAD']
# TUSB_DFEFINES+=['NO_HOST']
# TUSB_DFEFINES+=['NO_DEVICE']
path = []
path += [cwd+'/../../usb_stack/inc']
path += [cwd+'/../../usb_stack/class']
path += [cwd+'/../../usb_stack/class/host']

src = []
src += Glob(cwd+'/../../usb_stack/src/*.c')
src += Glob(cwd+'/../../usb_stack/class/*.c')
src += Glob(cwd+'/../../usb_stack/class/host/*.c')

objs = objs + DefineGroup('TeenyUSB', src, depend = [''], CPPPATH = path, CPPDEFINES = TUSB_DFEFINES)

for d in list:
    path = os.path.join(cwd, d)
    if os.path.isfile(os.path.join(path, 'SConscript')):
        objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')
