70 lines
2 KiB
Python
70 lines
2 KiB
Python
# SConscript
|
|
# vim: set ft=python:
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
import os
|
|
import os.path
|
|
import shlex
|
|
import subprocess
|
|
|
|
files = [
|
|
'boot.s',
|
|
'Main.cc',
|
|
'Console.cc',
|
|
'Descriptors.cc',
|
|
'Interrupts.cc',
|
|
'Kernel.cc',
|
|
'Multiboot.cc',
|
|
'StartupInformation.cc',
|
|
'PIC.cc',
|
|
'cxa.cc',
|
|
'isr.S',
|
|
|
|
'kstd/CString.cc',
|
|
'kstd/Memory.cc',
|
|
'kstd/PrintFormat.cc',
|
|
|
|
'memory/FrameAllocator.cc',
|
|
'memory/Memory.cc',
|
|
]
|
|
|
|
toolchain_bin = Dir(os.environ['POLKA_TOOLCHAIN']).Dir('bin')
|
|
toolchain_gcc_lib = Dir(os.environ['POLKA_TOOLCHAIN']).Dir('lib/gcc/i686-elf/5.3.0')
|
|
linker_script = File('linker.ld')
|
|
|
|
env.Replace(AS=toolchain_bin.File('i686-elf-as'),
|
|
CC=toolchain_bin.File('i686-elf-gcc'),
|
|
CXX=toolchain_bin.File('i686-elf-g++'),
|
|
LINK=toolchain_bin.File('i686-elf-ld'))
|
|
env.Append(CCFLAGS='-ffreestanding',
|
|
CPPDEFINES='__polka',
|
|
CXXFLAGS='-fno-exceptions -fno-rtti',
|
|
LIBPATH=[toolchain_gcc_lib],
|
|
LINKFLAGS='-nostdlib -T{}'.format(linker_script.path))
|
|
|
|
# Global constructor files. These must be linked IN THIS ORDER.
|
|
def crtfile_path(name):
|
|
cmd = shlex.split(env.subst('$CC $CCFLAGS $CFLAGS -print-file-name={}'.format(name)))
|
|
return subprocess.check_output(cmd).strip()
|
|
|
|
crtbegin_file = Command('crtbegin.o', [], Copy('$TARGET', crtfile_path('crtbegin.o')))
|
|
crtend_file = Command('crtend.o', [], Copy('$TARGET', crtfile_path('crtend.o')))
|
|
crtinit_files = ['crti.s', crtbegin_file]
|
|
crtfini_files = [crtend_file, 'crtn.s']
|
|
|
|
kernel = Program('polka.bin', crtinit_files + files + crtfini_files, LIBS=['gcc'])
|
|
Depends(kernel, linker_script)
|
|
Alias('kernel', kernel)
|
|
|
|
img_dir = Dir('img')
|
|
grub_cfg = File('grub.cfg')
|
|
image_dir = Command(img_dir, kernel, [
|
|
Mkdir(img_dir.Dir('boot/grub')),
|
|
Copy(os.path.join(img_dir.Dir('boot').path, '${SOURCE.file}'), '$SOURCE'),
|
|
Copy(img_dir.Dir('boot/grub'), grub_cfg.srcnode())
|
|
])
|
|
Clean(image_dir, img_dir)
|
|
image = Command('polka.img', image_dir, [
|
|
'grub-mkrescue -o $TARGET $SOURCE',
|
|
])
|
|
Alias('image', image)
|