# -*- 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 scripts.config.projpaths import *
from scripts.config.configuration import *

config = configuration_retrieve()
arch = config.arch

env = Environment(CC = config.toolchain_userspace + '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', '-nostdlib', '-ffreestanding', '-std=gnu99',
                             '-Wall', '-Werror'],
		          LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds",
                               LIBC_LIBPATH, LIBL4_LIBPATH, LIBMEM_LIBPATH],
    	          ASFLAGS = ['-D__ASSEMBLY__'],
		          PROGSUFFIX = '.elf',	# The suffix to use for final executable
		          ENV = {'PATH' : os.environ['PATH']},	# Inherit shell path
		          LIBS = ['gcc', 'libl4', 'libc', 'libmm', 'libmc'],
                  CPPPATH = ["#include", LIBC_INCLUDE, KERNEL_HEADERS, LIBL4_INCLUDE],
		          CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h \
                              -D__KERNEL__')



def create_symlinks(arch):
	arch_path = "include/arch"
	arch_path2 ="src/arch"
	if os.path.exists(arch_path):
		os.system("rm %s" % (arch_path))
	os.system("ln -s %s %s" % ("arch-" + arch, arch_path))
	if os.path.exists(arch_path2):
		os.system("rm %s" % (arch_path2))
	os.system("ln -s %s %s" % ("arch-" + arch, arch_path2))

src = Glob(['*.c', 'src/*.c', 'src/lib/*.c', 'src/lib/elf/*.c', 'src/arch/*.c'])

objects = []
mm0_elf = env.Program('mm0.elf', objects)
