#
# Copyright (C) 2015 Niek Linnenbank
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

Import('build_env')

env = build_env.Clone()

for item in env['LINKUSER']:
    env['LINKFLAGS'].remove(item)

env.Append(LINKFLAGS = env['LINKKERN'])
env.Append(CPPFLAGS = '-D__KERNEL__')

env.UseLibraries(['liballoc', 'libstd', 'libarch', 'libipc', 'libfs'])
env.UseServers(['serial'])
env.TargetProgram('kernel', [ Glob('*.cpp'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/*.cpp'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/intel/*.cpp'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/intel/*.S'),
                              Glob('#' + env['BUILDROOT'] + '/kernel/API/*.cpp'),
                              '#' + env['BUILDROOT'] + '/server/serial/SerialDevice.o',
                              '#' + env['BUILDROOT'] + '/server/serial/i8250.o' ]
                            , env['boot'])

#
# Boot ISO (LiveCD)
#
cd = env.ISO('#${BUILDROOT}/boot.iso',
           [ '#${BUILDROOT}/kernel/intel/pc/kernel',
             '#${BUILDROOT}/boot.img' ])

# Shortcut to build the ISO.
Alias('iso', cd)

# First part of the Qemu command arguments
qemu_args = build_env['QEMUCMD'] + ' -cdrom ' + build_env['BUILDROOT'] + '/boot.iso ' + \
            '-chardev socket,id=charmonitor,path=monitor.dev,server,nowait -monitor chardev:charmonitor '

#
# Qemu targets
#
env.Targets(qemu        = qemu_args + '-nographic')
env.Targets(qemu_sdl    = qemu_args + '-sdl')
env.Targets(qemu_curses = qemu_args + '-curses')
env.Targets(qemu_debug  = qemu_args + '-nographic -s -S')

#
# Autotester in Qemu
#
env.AutoTester(qemu_test = qemu_args + '-nographic')
env.AutoTesterLoop(qemu_loop = qemu_args + '-nographic')
