Ninja-based system now builds the disk images

This commit is contained in:
Justin C. Miller
2019-02-02 13:30:43 -08:00
parent 7e1933d79b
commit 73df20d195
11 changed files with 121 additions and 26 deletions

Binary file not shown.

View File

@@ -10,14 +10,14 @@
[[files]] [[files]]
dest = "screenfont.psf" dest = "screenfont.psf"
source = "assets/fonts/tamsyn8x16r.psf" source = "../assets/fonts/tamsyn8x16r.psf"
[[files]] [[files]]
dest = "nulldrv1" dest = "nulldrv1"
source = "build/kernel/src/drivers/nulldrv/nulldrv" source = "host/nulldrv"
executable = true executable = true
[[files]] [[files]]
dest = "nulldrv2" dest = "nulldrv2"
source = "build/kernel/src/drivers/nulldrv/nulldrv" source = "host/nulldrv"
executable = true executable = true

View File

@@ -13,6 +13,9 @@ MODULES = {
"kutil": library('src/libraries/kutil', []), "kutil": library('src/libraries/kutil', []),
"makerd": program('src/tools/makerd', ["initrd", "kutil"], "makerd", ["native"]), "makerd": program('src/tools/makerd', ["initrd", "kutil"], "makerd", ["native"]),
"nulldrv": program('src/drivers/nulldrv', [], "nulldrv", ["host"]),
"boot": program('src/boot', ["elf"], "boot.elf", ["host"]), "boot": program('src/boot', ["elf"], "boot.elf", ["host"]),
"kernel": program('src/kernel', ["elf", "initrd", "kutil"], "popcorn.elf", ["host"]), "kernel": program('src/kernel', ["elf", "initrd", "kutil"], "popcorn.elf", ["host"]),
} }
@@ -26,9 +29,9 @@ def get_template(env, typename, name):
return env.get_template("{}.default.ninja.j2".format(typename)) return env.get_template("{}.default.ninja.j2".format(typename))
def get_sources(path): def get_sources(path, srcroot):
import os import os
from os.path import abspath, join, splitext from os.path import abspath, join, relpath, splitext
actions = {'.c': 'cc', '.cpp': 'cxx', '.s': 'nasm'} actions = {'.c': 'cc', '.cpp': 'cxx', '.s': 'nasm'}
@@ -40,7 +43,7 @@ def get_sources(path):
name = join(root, f) name = join(root, f)
sources.append( sources.append(
source( source(
name, relpath(name, srcroot),
abspath(name), abspath(name),
f + ".o", f + ".o",
actions[ext])) actions[ext]))
@@ -68,8 +71,12 @@ def main(buildroot):
import os import os
from os.path import abspath, dirname, isdir, join from os.path import abspath, dirname, isdir, join
buildroot = abspath(buildroot) generator = abspath(__file__)
srcroot = dirname(abspath(__file__)) srcroot = dirname(generator)
if buildroot is None:
buildroot = join(srcroot, "build")
if not isdir(buildroot): if not isdir(buildroot):
os.mkdir(buildroot) os.mkdir(buildroot)
@@ -96,7 +103,7 @@ def main(buildroot):
open_list.extend(dep.deps) open_list.extend(dep.deps)
targets[target].add(depname) targets[target].add(depname)
sources = get_sources(join(srcroot, mod.path)) sources = get_sources(join(srcroot, mod.path), join(srcroot, "src"))
buildfile = join(buildroot, name + ".ninja") buildfile = join(buildroot, name + ".ninja")
buildfiles.append(buildfile) buildfiles.append(buildfile)
with open(buildfile, 'w') as out: with open(buildfile, 'w') as out:
@@ -141,12 +148,12 @@ def main(buildroot):
buildfile=buildfile, buildfile=buildfile,
buildfiles=buildfiles, buildfiles=buildfiles,
templates=[abspath(f) for f in templates], templates=[abspath(f) for f in templates],
generator=abspath(__file__), generator=generator,
version=git_version)) version=git_version))
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
buildroot = "build" buildroot = None
if len(sys.argv) > 1: if len(sys.argv) > 1:
buildroot = sys.argv[1] buildroot = sys.argv[1]
main(buildroot) main(buildroot)

View File

@@ -2,6 +2,29 @@ ninja_required_version = 1.3
builddir = {{ buildroot }} builddir = {{ buildroot }}
srcroot = {{ srcroot }} srcroot = {{ srcroot }}
warnflags = $
-Wformat=2 $
-Winit-self $
-Wfloat-equal $
-Winline $
-Wmissing-format-attribute $
-Wmissing-include-dirs $
-Wswitch $
-Wundef $
-Wdisabled-optimization $
-Wpointer-arith $
-Wno-attributes $
-Wno-sign-compare $
-Wno-multichar $
-Wno-div-by-zero $
-Wno-endif-labels $
-Wno-pragmas $
-Wno-format-extra-args $
-Wno-unused-result $
-Wno-deprecated-declarations $
-Wno-unused-function $
-Werror
ccflags = $ ccflags = $
-I${srcroot}/src/include $ -I${srcroot}/src/include $
-I${srcroot}/src/include/x86_64 $ -I${srcroot}/src/include/x86_64 $
@@ -9,7 +32,8 @@ ccflags = $
-DVERSION_MINOR={{ version.minor }} $ -DVERSION_MINOR={{ version.minor }} $
-DVERSION_PATCH={{ version.patch }} $ -DVERSION_PATCH={{ version.patch }} $
-DVERSION_GITSHA=\"{{ version.sha }}\" $ -DVERSION_GITSHA=\"{{ version.sha }}\" $
-DGIT_VERSION=\"{{ version.major }}.{{ version.minor }}.{{ version.patch }}-{{ version.sha }}\" -DGIT_VERSION=\"{{ version.major }}.{{ version.minor }}.{{ version.patch }}-{{ version.sha }}\" $
$warnflags
asflags = $ asflags = $
-DVERSION_MAJOR={{ version.major }} $ -DVERSION_MAJOR={{ version.major }} $
@@ -50,7 +74,35 @@ rule lib
rule regen rule regen
generator = true generator = true
description = Regenrating build files description = Regenrating build files
command = {{ generator }} ${builddir} command = {{ generator }} $builddir
rule cp
description = Copying $name
command = cp $in $out
rule makerd
description = Making init ramdisk
command = $builddir/native/makerd $in $out
rule makeefi
description = Converting $name
command = objcopy $
-j .text $
-j .sdata $
-j .data $
-j .dynamic $
-j .dynsym $
-j .rel $
-j .rela $
-j .reloc $
--target=efi-app-x86_64 $
$in $out
rule makefat
description = Creating $name
command = $
cp $srcroot/assets/diskbase.img $out; $
mcopy -s -D o -i $out@@1024K $builddir/fatroot/* ::/
{% for target in targets %} {% for target in targets %}
subninja {{ target }}/target.ninja subninja {{ target }}/target.ninja
@@ -66,5 +118,27 @@ build $
{%- endfor %} {%- endfor %}
{{ generator }} {{ generator }}
build $builddir/flash.img : cp $srcroot/assets/ovmf/x64/OVMF.fd
name = flash.img
build $builddir/popcorn.fat : cp $srcroot/assets/ovmf/x64/OVMF.fd
name = flash.img
build $builddir/fatroot/popcorn.elf : cp $builddir/host/popcorn.elf
name = kernel to FAT image
build $builddir/fatroot/efi/boot/bootx64.efi : cp $builddir/host/boot.efi
name = bootloader to FAT image
build $builddir/fatroot/initrd.img : makerd ${srcroot}/assets/initrd.toml | $
${builddir}/native/makerd $
${builddir}/host/nulldrv
build $builddir/popcorn.img : makefat | $
$builddir/fatroot/initrd.img $
$builddir/fatroot/popcorn.elf $
$builddir/fatroot/efi/boot/bootx64.efi
name = popcorn.img
# vim: et ts=4 sts=4 sw=4 # vim: et ts=4 sts=4 sw=4

View File

@@ -22,5 +22,8 @@ build {% block artifact %} ${builddir}/lib{{ name }}.a : lib {% endblock %} $
{%- if module.deps %}| {% for dep in module.deps %} ${builddir}/lib{{ dep }}.a {% endfor %}{% endif %} {%- if module.deps %}| {% for dep in module.deps %} ${builddir}/lib{{ dep }}.a {% endfor %}{% endif %}
name = {{ name }} name = {{ name }}
# End {% block extra %}
{% endblock %}
# vim: ft=ninja et ts=4 sts=4 sw=4

View File

@@ -3,16 +3,23 @@
{{ super() }} {{ super() }}
cflags = $cflags $ cflags = $cflags $
-DKERNEL_FILENAME=L\"popcorn.elf\" $ -DKERNEL_FILENAME=L\"popcorn.elf\" $
-DGNU_EFI_USE_MS_ABI $ -DGNU_EFI_USE_MS_ABI $
-DHAVE_USE_MS_ABI $ -DHAVE_USE_MS_ABI $
-DEFI_DEBUG=0 $ -DEFI_DEBUG=0 $
-DEFI_DEBUG_CLEAR_MEMORY=0 $ -DEFI_DEBUG_CLEAR_MEMORY=0 $
-fPIC $ -fPIC $
-fshort-wchar -fshort-wchar
ldflags = $ldflags $ ldflags = $ldflags $
-shared $ -shared $
-T ${srcroot}/src/arch/x86_64/boot.ld -T ${srcroot}/src/arch/x86_64/boot.ld
{% endblock %}
{% block extra %}
build $builddir/boot.efi : makeefi ${builddir}/{{ module.output }}
name = boot.efi
{% endblock %} {% endblock %}

View File

@@ -3,11 +3,11 @@
{{ super() }} {{ super() }}
libs = $ libs = $
-L${builddir} $ -L${builddir} $
{%- for dep in module.deps %} {%- for dep in module.deps %}
-l{{dep}} $ -l{{dep}} $
{%- endfor %} {%- endfor %}
$libs $libs
{% endblock %} {% endblock %}
{% block artifact %}{{ module.output }} : exe{% endblock %} {% block artifact %}${builddir}/{{ module.output }} : exe{% endblock %}

View File

@@ -4,5 +4,6 @@
asflags = $asflags -I${srcroot}/src/kernel/ asflags = $asflags -I${srcroot}/src/kernel/
libs = $libs -lc libs = $libs -lc
ldflags = $ldflags -T ${srcroot}/src/arch/x86_64/kernel.ld
{% endblock %} {% endblock %}

View File

@@ -9,6 +9,7 @@ cxx = clang++
ld = clang++ ld = clang++
ar = ar ar = ar
nasm = nasm nasm = nasm
objcopy = objcopy
{% endblock %} {% endblock %}
{% for module in modules %} {% for module in modules %}

View File

@@ -5,12 +5,14 @@ cxx = ${srcroot}/sysroot/bin/clang++
ld = ${srcroot}/sysroot/bin/x86_64-elf-ld ld = ${srcroot}/sysroot/bin/x86_64-elf-ld
ar = ${srcroot}/sysroot/bin/x86_64-elf-ar ar = ${srcroot}/sysroot/bin/x86_64-elf-ar
nasm = ${srcroot}/sysroot/bin/nasm nasm = ${srcroot}/sysroot/bin/nasm
objcopy = ${srcroot}/sysroot/bin/x86_64-elf-objcopy
{% endblock %} {% endblock %}
{% block variables %} {% block variables %}
ccflags = $ccflags $ ccflags = $ccflags $
-D__ELF__ $ -D__ELF__ $
-D__POPCORN__ $
-nodefaultlibs $ -nodefaultlibs $
-nostdinc $ -nostdinc $
-nostdlib $ -nostdlib $