Import('env')
local = env.Clone()



firmware_env = local.Clone()
firmware_env.Append(SKROCFLAGS=['--no-std-libs'])
firmware_h = firmware_env.OccamBytecodeHeader('firmware.h', 'firmware.occ')


tvm_env  = local.Clone()
tvm_conf = tvm_env.Configure(config_h = 'config.h', help=False)

headers  = Split('''
        stdlib.h stdio.h stdarg.h string.h
        dlfcn.h errno.h inttypes.h limits.h math.h
        search.h signal.h termios.h time.h unistd.h
        sys/ioctl.h sys/time.h sys/timeb.h sys/types.h
        ''')
for h in headers:
    tvm_conf.CheckCHeader(h)

functions = Split('ftime gettimeofday nanosleep setitimer Sleep')    
for f in functions:
    tvm_conf.CheckFunc(f)

tvm_conf.Define('VERSION', '"1.0.0"', 'The version of the package')
tvm_env = tvm_conf.Finish()        
tvm_env.Append(CCFLAGS = '-DHAVE_CONFIG_H')

tvm_src = Split('''
        main.c
        sffi.c
        unix_io.c
        ''')

tvm = tvm_env.Program('tvm', tvm_src, LIBS='$TVM_LIB')
tvm_env.Depends(tvm, firmware_h)
tvm_env.Depends(tvm, '$TVM_LIB')
tvm_env.Append(CPPPATH='../../runtime/libtvm')
