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 *

# Prepare environment.
PrepareEnv()

################################## change rtconfig.xxx to customize build ########################################

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

# 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,
    CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
    AR = rtconfig.AR, ARFLAGS = '-rc',
    LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
   
# Prepare building environment
objs = PrepareBuilding(env)

# Build application.
DoBuilding(TARGET, objs)

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

# Generate download .bat script
GenDownloadScript(env)
