Moving to a ninja-based build system

This commit is contained in:
Justin C. Miller
2019-02-02 02:59:45 -08:00
parent 523d0b3b8c
commit 0f8efdb55e
24 changed files with 604 additions and 507 deletions

View File

@@ -0,0 +1,54 @@
builddir = {{ buildroot }}
srcroot = {{ srcroot }}
ccflags = $
-I${srcroot}/src/include $
-I${srcroot}/src/include/x86_64 $
-DVERSION_MAJOR={{ version.major }} $
-DVERSION_MINOR={{ version.minor }} $
-DVERSION_PATCH={{ version.patch }} $
-DVERSION_GITSHA=\"{{ version.sha }}\" $
-DGIT_VERSION=\"{{ version.major }}.{{ version.minor }}.{{ version.patch }}-{{ version.sha }}\"
asflags = $
-DVERSION_MAJOR={{ version.major }} $
-DVERSION_MINOR={{ version.minor }} $
-DVERSION_PATCH={{ version.patch }} $
-DVERSION_GITSHA=\"{{ version.sha }}\"
cflags = -std=c11
cxxflags = -std=c++14
libs =
rule cc
deps = gcc
depfile = $out.d
description = Compiling $name
command = $cc -MMD -MF $out.d $ccflags $cflags -o $out -c $in
rule cxx
deps = gcc
depfile = $out.d
description = Compiling $name
command = $cxx -MMD -MF $out.d $cxxflags $ccflags -o $out -c $in
rule nasm
deps = gcc
depfile = $out.d
description = Assembling $name
command = $nasm -o $out -felf64 -MD $out.d $asflags $in
rule exe
description = Linking $name
command = $ld -o $out $in $libs
rule lib
description = Archiving $name
command = $ar qcs $out $in
{% for target in targets %}
subninja {{ target }}/target.ninja
{% endfor %}
# vim: et ts=4 sts=4 sw=4

View File

@@ -0,0 +1 @@
{% extends "module.base.ninja.j2" %}

View File

@@ -0,0 +1,26 @@
moddir = ${builddir}/{{ name }}.dir
{% block variables %}
ccflags = $ccflags $
{%- for dep in module.deps %}
-I${srcroot}/src/libraries/{{ dep }}/include $
{%- endfor %}
-I${srcroot}/{{ module.path }} $
-I${srcroot}/{{ module.path }}/include
{% endblock %}
{% for source in sources %}
build ${moddir}/{{ source.output }} : {{ source.action }} {{ source.input }}
name = {{ source.name }}
{% endfor %}
build {% block artifact %} ${builddir}/lib{{ name }}.a : lib {% endblock %} $
{%- block extrasources %}{% endblock -%}
{%- for source in sources %}
${moddir}/{{ source.output }}{% if not loop.last %} ${% endif %}
{%- endfor -%}
{%- if module.deps %}| {% for dep in module.deps %} ${builddir}/lib{{ dep }}.a {% endfor %}{% endif %}
name = {{ name }}
# End

View File

@@ -0,0 +1,18 @@
{% extends "program.default.ninja.j2" %}
{% block variables %}
{{ super() }}
cflags = $cflags $
-DKERNEL_FILENAME=L\"popcorn.elf\" $
-DGNU_EFI_USE_MS_ABI $
-DHAVE_USE_MS_ABI $
-DEFI_DEBUG=0 $
-DEFI_DEBUG_CLEAR_MEMORY=0 $
-fPIC $
-fshort-wchar
ldflags = $ldflags $
-shared $
-T ${srcroot}/src/arch/x86_64/boot.ld
{% endblock %}

View File

@@ -0,0 +1,13 @@
{% extends "module.base.ninja.j2" %}
{% block variables %}
{{ super() }}
libs = $
-L${builddir} $
{%- for dep in module.deps %}
-l{{dep}} $
{%- endfor %}
$libs
{% endblock %}
{% block artifact %}{{ module.output }} : exe{% endblock %}

View File

@@ -0,0 +1,8 @@
{% extends "program.default.ninja.j2" %}
{% block variables %}
{{ super() }}
asflags = $asflags -I${srcroot}/src/kernel/
libs = $libs -lc
{% endblock %}

View File

@@ -0,0 +1,16 @@
builddir = $builddir/{{ target }}
{% block variables %}
{% endblock %}
{% block binaries %}
cc = clang
cxx = clang++
ld = clang++
ar = ar
nasm = nasm
{% endblock %}
{% for module in modules %}
subninja {{ module }}.ninja
{% endfor %}

View File

@@ -0,0 +1,39 @@
{% extends "target.default.ninja.j2" %}
{% block binaries %}
cc = ${srcroot}/sysroot/bin/clang
cxx = ${srcroot}/sysroot/bin/clang++
ld = ${srcroot}/sysroot/bin/x86_64-elf-ld
ar = ${srcroot}/sysroot/bin/x86_64-elf-ar
nasm = ${srcroot}/sysroot/bin/nasm
{% endblock %}
{% block variables %}
ccflags = $ccflags $
-D__ELF__ $
-nodefaultlibs $
-nostdinc $
-nostdlib $
-ffreestanding $
-mno-sse $
-fno-omit-frame-pointer $
-mno-red-zone $
-mcmodel=large $
-isystem${srcroot}/sysroot/include $
--sysroot="${srcroot}/sysroot"
cxxflags = $cxxflags $
-nostdlibinc $
-isystem${srcroot}/sysroot/include/c++/v1 $
-fno-exceptions $
-fno-rtti
ldflags = $ldflags $
-g $
-nostdlib $
-nostartfiles $
-znocombreloc $
-Bsymbolic $
-nostartfiles
{% endblock %}

View File

@@ -0,0 +1 @@
{% extends "target.default.ninja.j2" %}