import os
import rtconfig

# Check SDK 
SIFLI_SDK = os.getenv('SIFLI_SDK')
if not SIFLI_SDK:
    print("Please run set_env.bat in root folder of SIFLI SDK to set environment.")
    exit()
from building import *

PrepareEnv()

################################## change rtconfig.xxx to customize build ########################################
# print (rtconfig.OUTPUT_DIR)

# Add bootloader project
AddBootLoader(SIFLI_SDK,rtconfig.CHIP)

# Add LCPU project
AddLCPU(SIFLI_SDK,rtconfig.CHIP,"../src/lcpu_img.c")

# Set default compile options
SifliEnv()


TARGET = rtconfig.OUTPUT_DIR + rtconfig.TARGET_NAME + '.' + rtconfig.TARGET_EXT
env = Environment(tools = ['mingw'],
    AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
    CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
    AR = rtconfig.AR, ARFLAGS = '-rc',
    LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
   
# prepare building environment
objs = PrepareBuilding(env)

# make a building
DoBuilding(TARGET, objs)

# Add flash table
AddFTAB(SIFLI_SDK,rtconfig.CHIP)

GenDownloadScript(env)
