Import("*")
import os
import glob

libs = ["gcc"]

arch = 'arm'

# C library information
clibvariant = "baremetal"
clibroot = os.getcwd() + '/../c'
clibpath = os.getcwd() + clibroot + '/build/' + clibvariant
cincpath = [clibroot + '/include', clibroot + '/include/arch/%s' % arch]

env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
		  CCFLAGS = ['-g', '-nostdinc', '-nostdlib', '-ffreestanding'],
		  LINKFLAGS = ['-nostdlib'],
		  ENV = {'PATH' : os.environ['PATH']},
		  LIBS = ['gcc','c-' + clibvariant],
		  LIBPATH = clibpath,
		  CPPPATH = ['#include'] + cincpath)


def src_glob(search):
    """Src glob is used to find source files easily e.g: src_glob("src/*.c"),
    the reason we can't just use glob is due to the way SCons handles out
    of directory builds."""
    dir = os.path.dirname(search)
    if dir != "":
        dir = dir + os.sep
    src_path = Dir('.').srcnode().abspath
    files = glob.glob(src_path + os.sep + search)
    files = map(os.path.basename, files)
    ret_files = []
    for file in files:
        ret_files.append(dir + file)
    return ret_files

src = src_glob("src/*.c")

libelf = env.StaticLibrary('elf', src)

