This commit is contained in:
Justin C. Miller
2018-09-24 11:13:18 -07:00
parent dffdcc095d
commit 591ca7c83c
25 changed files with 87 additions and 61 deletions

View File

@@ -7,8 +7,10 @@ def build(bld):
bld.stlib( bld.stlib(
source = sources, source = sources,
includes = 'include',
name = 'elf', name = 'elf',
target = 'elf', target = 'elf',
use = 'KUTIL',
) )
# vim: ft=python et # vim: ft=python et

View File

@@ -1,7 +1,7 @@
#include "initrd/headers.h"
#include "initrd/initrd.h" #include "initrd/initrd.h"
#include "kutil/assert.h" #include "kutil/assert.h"
#include "kutil/enum_bitfields.h" #include "kutil/enum_bitfields.h"
#include "headers.h"
namespace initrd { namespace initrd {

View File

@@ -7,8 +7,10 @@ def build(bld):
bld.stlib( bld.stlib(
source = sources, source = sources,
includes = 'include',
name = 'initrd', name = 'initrd',
target = 'initrd', target = 'initrd',
use = 'KUTIL',
) )
# vim: ft=python et # vim: ft=python et

View File

@@ -1,4 +1,4 @@
#include "assert.h" #include "kutil/assert.h"
namespace kutil { namespace kutil {

View File

@@ -1,6 +1,6 @@
#include "memory.h" #include "kutil/memory.h"
#include "memory_manager.h" #include "kutil/memory_manager.h"
#include "type_macros.h" #include "kutil/type_macros.h"
__weak void * operator new (size_t, void *p) noexcept { return p; } __weak void * operator new (size_t, void *p) noexcept { return p; }
__weak void * operator new (size_t n) { return kutil::malloc(n); } __weak void * operator new (size_t n) { return kutil::malloc(n); }

View File

@@ -1,7 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include "assert.h" #include "kutil/assert.h"
#include "memory.h" #include "kutil/memory.h"
#include "memory_manager.h" #include "kutil/memory_manager.h"
namespace kutil { namespace kutil {

View File

@@ -7,6 +7,7 @@ def build(bld):
bld.stlib( bld.stlib(
source = sources, source = sources,
includes = 'include',
name = 'kutil', name = 'kutil',
target = 'kutil', target = 'kutil',
) )

View File

@@ -9,7 +9,7 @@ def build(bld):
source = sources, source = sources,
name = 'makerd', name = 'makerd',
target = 'makerd', target = 'makerd',
use = 'initrd', use = 'INITRD KUTIL',
) )
# vim: ft=python et # vim: ft=python et

125
wscript
View File

@@ -27,7 +27,7 @@ def options(opt):
help='Compile in debugging mode') help='Compile in debugging mode')
def common_configure(ctx): def common_configure(ctx, phase):
from os import listdir from os import listdir
from os.path import join, exists from os.path import join, exists
from subprocess import check_output from subprocess import check_output
@@ -47,38 +47,45 @@ def common_configure(ctx):
ctx.env.ARCH_D = join(str(ctx.path), "src", "arch", ctx.env.ARCH_D = join(str(ctx.path), "src", "arch",
ctx.env.POPCORN_ARCH) ctx.env.POPCORN_ARCH)
ctx.env.append_value('INCLUDES', [
join(ctx.path.abspath(), "src", "include"),
join(ctx.path.abspath(), "src", "include", ctx.env.POPCORN_ARCH),
join(ctx.path.abspath(), "src", "libraries"),
join(ctx.path.abspath(), "src", "drivers"),
])
libraries = [] libraries = []
mod_root = join("src", "libraries") lib_root = join("src", "libraries")
for module in listdir(mod_root): for lib in listdir(lib_root):
mod_path = join(mod_root, module) name = lib.upper()
if exists(join(mod_path, "wscript")): lib_path = join(lib_root, lib)
libraries.append(mod_path) out_path = join(
ctx.path.get_bld().abspath(),
phase,
lib_path)
ctx.env.append_value('INCLUDES_{}'.format(name), [
join(ctx.path.abspath(), lib_path, "include"),
])
if exists(join(lib_path, "wscript")):
ctx.env.append_value('LIB_{}'.format(name), [lib])
ctx.env.append_value('LIBPATH_{}'.format(name), [out_path])
libraries.append(lib_path)
ctx.env.LIBRARIES = libraries ctx.env.LIBRARIES = libraries
tools = [] tools = []
mod_root = join("src", "tools") tool_root = join("src", "tools")
for module in listdir(mod_root): for tool in listdir(tool_root):
mod_path = join(mod_root, module) tool_path = join(tool_root, tool)
if exists(join(mod_path, "wscript")): if exists(join(tool_path, "wscript")):
tools.append(mod_path) tools.append(tool_path)
ctx.env.TOOLS = tools ctx.env.TOOLS = tools
drivers = [] drivers = []
mod_root = join("src", "drivers") drv_root = join("src", "drivers")
for module in listdir(mod_root): for drv in listdir(drv_root):
mod_path = join(mod_root, module) drv_path = join(drv_root, drv)
if exists(join(mod_path, "wscript")): if exists(join(drv_path, "wscript")):
drivers.append(mod_path) drivers.append(drv_path)
ctx.env.DRIVERS = drivers ctx.env.DRIVERS = drivers
ctx.env.append_value('DEFINES', [ ctx.env.append_value('DEFINES', [
'POPCORN_BUILD_PHASE="{}"'.format(phase),
'GIT_VERSION="{}"'.format(version), 'GIT_VERSION="{}"'.format(version),
'GIT_VERSION_WIDE=L"{}"'.format(version), 'GIT_VERSION_WIDE=L"{}"'.format(version),
"VERSION_MAJOR={}".format(major), "VERSION_MAJOR={}".format(major),
@@ -121,15 +128,25 @@ def configure(ctx):
ctx.env.LINKFLAGS_cstlib = ['-Bstatic'] ctx.env.LINKFLAGS_cstlib = ['-Bstatic']
baseflags = [ baseflags = [
'-nostdlib',
'-ffreestanding',
'-nodefaultlibs', '-nodefaultlibs',
'-nostdinc',
'-nostdlib',
'-nostdlibinc',
'-ffreestanding',
'-nostdinc',
'-fno-builtin', '-fno-builtin',
'-mno-sse', '-mno-sse',
'-fno-omit-frame-pointer', '-fno-omit-frame-pointer',
'-mno-red-zone', '-mno-red-zone',
] ]
baseflags += ["-isystem{}".format(i) for i in [
join(ctx.path.abspath(), "external", "include", "c++", "v1"),
join(ctx.path.abspath(), "src", "include", ctx.options.arch),
join(ctx.path.abspath(), "src", "include"),
]]
warnflags = ['-W{}'.format(opt) for opt in [ warnflags = ['-W{}'.format(opt) for opt in [
'format=2', 'format=2',
'init-self', 'init-self',
@@ -157,7 +174,10 @@ def configure(ctx):
ctx.env.append_value('CFLAGS', baseflags) ctx.env.append_value('CFLAGS', baseflags)
ctx.env.append_value('CFLAGS', warnflags) ctx.env.append_value('CFLAGS', warnflags)
ctx.env.append_value('CFLAGS', ['-ggdb', '-std=c11']) ctx.env.append_value('CFLAGS', [
'-nolibc',
'-ggdb',
'-std=c11'])
ctx.env.append_value('CXXFLAGS', baseflags) ctx.env.append_value('CXXFLAGS', baseflags)
ctx.env.append_value('CXXFLAGS', warnflags) ctx.env.append_value('CXXFLAGS', warnflags)
@@ -171,12 +191,13 @@ def configure(ctx):
ctx.env.append_value('LINKFLAGS', [ ctx.env.append_value('LINKFLAGS', [
'-g', '-g',
'-nostdlib', '-nostdlib',
'-nostartfiles',
'-znocombreloc', '-znocombreloc',
'-Bsymbolic', '-Bsymbolic',
'-nostartfiles', '-nostartfiles',
]) ])
common_configure(ctx) common_configure(ctx, 'kernel')
base_bare = ctx.env base_bare = ctx.env
ctx.setenv('boot', env=base_bare) ctx.setenv('boot', env=base_bare)
ctx.recurse(join("src", "boot")) ctx.recurse(join("src", "boot"))
@@ -189,11 +210,11 @@ def configure(ctx):
'-fno-rtti', '-fno-rtti',
]) ])
for mod_path in ctx.env.LIBRARIES: for lib_path in ctx.env.LIBRARIES:
ctx.recurse(mod_path) ctx.recurse(lib_path)
for mod_path in ctx.env.DRIVERS: for drv_path in ctx.env.DRIVERS:
ctx.recurse(mod_path) ctx.recurse(drv_path)
ctx.recurse(join("src", "kernel")) ctx.recurse(join("src", "kernel"))
@@ -204,36 +225,36 @@ def configure(ctx):
ctx.load('clang++') ctx.load('clang++')
ctx.find_program("mcopy", var="mcopy") ctx.find_program("mcopy", var="mcopy")
ctx.find_program("dd", var="dd") ctx.find_program("dd", var="dd")
common_configure(ctx) common_configure(ctx, 'tools')
ctx.env.CXXFLAGS = ['-g', '-std=c++14'] ctx.env.CXXFLAGS = ['-g', '-std=c++14']
ctx.env.LINKFLAGS = ['-g'] ctx.env.LINKFLAGS = ['-g']
for mod_path in ctx.env.LIBRARIES: for lib_path in ctx.env.LIBRARIES:
ctx.recurse(mod_path) ctx.recurse(lib_path)
for mod_path in ctx.env.TOOLS: for drv_path in ctx.env.TOOLS:
ctx.recurse(mod_path) ctx.recurse(drv_path)
## Image configuration ## Image configuration
## ##
ctx.setenv('image', env=ConfigSet()) ctx.setenv('image', env=ConfigSet())
ctx.find_program("mcopy", var="mcopy") ctx.find_program("mcopy", var="mcopy")
ctx.find_program("dd", var="dd") ctx.find_program("dd", var="dd")
common_configure(ctx) common_configure(ctx, 'image')
## Testing configuration ## Testing configuration
## ##
from waflib.ConfigSet import ConfigSet from waflib.ConfigSet import ConfigSet
ctx.setenv('tests', env=ConfigSet()) ctx.setenv('tests', env=ConfigSet())
ctx.load('clang++') ctx.load('clang++')
common_configure(ctx) common_configure(ctx, 'tests')
ctx.env.CXXFLAGS = ['-g', '-std=c++14', '-fno-rtti'] ctx.env.CXXFLAGS = ['-g', '-std=c++14', '-fno-rtti']
ctx.env.LINKFLAGS = ['-g'] ctx.env.LINKFLAGS = ['-g']
for mod_path in ctx.env.LIBRARIES: for lib_path in ctx.env.LIBRARIES:
ctx.recurse(mod_path) ctx.recurse(lib_path)
ctx.recurse(join("src", "tests")) ctx.recurse(join("src", "tests"))
@@ -303,18 +324,18 @@ def build(bld):
## Tools ## Tools
# #
elif bld.variant == 'tools': elif bld.variant == 'tools':
for mod_path in bld.env.LIBRARIES: for lib_path in bld.env.LIBRARIES:
bld.recurse(mod_path) bld.recurse(lib_path)
for mod_path in bld.env.TOOLS: for tool_path in bld.env.TOOLS:
bld.recurse(mod_path) bld.recurse(tool_path)
## Kernel ## Kernel
# #
elif bld.variant == 'kernel': elif bld.variant == 'kernel':
for mod_path in bld.env.LIBRARIES: for lib_path in bld.env.LIBRARIES:
bld.recurse(mod_path) bld.recurse(lib_path)
for mod_path in bld.env.DRIVERS: for drv_path in bld.env.DRIVERS:
bld.recurse(mod_path) bld.recurse(drv_path)
bld.recurse(join("src", "kernel")) bld.recurse(join("src", "kernel"))
@@ -371,15 +392,15 @@ def build(bld):
## Tests ## Tests
# #
elif bld.variant == 'tests': elif bld.variant == 'tests':
for mod_path in bld.env.LIBRARIES: for lib_path in bld.env.LIBRARIES:
bld.recurse(mod_path) bld.recurse(lib_path)
bld.recurse(join("src", "tests")) bld.recurse(join("src", "tests"))
def test(bld): def test(bld):
from os.path import join from os.path import join
for mod_path in bld.env.LIBRARIES: for lib_path in bld.env.LIBRARIES:
bld.recurse(mod_path) bld.recurse(lib_path)
bld.recurse(join("src", "tests")) bld.recurse(join("src", "tests"))