# -*- mode: python; coding: utf-8; -*-
#
#  Codezero -- Virtualization microkernel for embedded systems.
#
#  Copyright © 2009  B Labs Ltd
#
import os, shelve, sys
from os.path import *

PROJRELROOT = '../../'

sys.path.append(PROJRELROOT)

from config.projpaths import *
from config.configuration import *
from config.lib import *

config = configuration_retrieve()
arch = config.arch


LIBL4_RELDIR = 'conts/libl4'
KERNEL_INCLUDE = join(PROJROOT, 'include')
LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR)
LIBL4_INCLUDE = join(LIBL4_DIR, 'include')
LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR)

# Locally important paths are here
LIBC_RELDIR = 'conts/libc'
LIBC_DIR = join(PROJROOT, LIBC_RELDIR)
LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR)
LIBC_INCLUDE = [join(LIBC_DIR, 'include'), \
                join(LIBC_DIR, 'include/arch' + '/' + arch)]


env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
                  # We don't use -nostdinc because sometimes we need standard headers,
                  # such as stdarg.h e.g. for variable args, as in printk().
                  CCFLAGS = ['-g', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
                             '-std=gnu99', '-Wall', '-Werror'],
                  LINKFLAGS = ['-nostdlib'],
                  ASFLAGS = ['-D__ASSEMBLY__'],
                  PROGSUFFIX = '.elf', # The suffix to use for final executable
                  ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
                  LIBS = ['gcc', 'libl4', 'c-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
                  CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBC_INCLUDE],
                  LIBPATH = [LIBL4_LIBPATH, LIBC_LIBPATH],
                  CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')


contid = ARGUMENTS.get('cont', '0')

SConscript('SConscript', \
     exports = { 'config' : config,  'env' : env, 'contid' : contid }, duplicate = 0, \
     variant_dir = join(BUILDDIR, 'cont' + str(contid) + '/test'))

