def _generate_ninja_file(cpp_compiler_path, c_compiler_path, archiver_path, target_scheme, build_dir, lib_path):

	with open(os.path.join(build_dir, "Application.ninja"), "w") as build_file:
		ninja_file = Writer(build_file)

		ninja_file.variable(key="builddir", value=build_dir)

		cpp_compiler_flags = COMPILER_FLAGS_DEFAULT_CPP + " " + COMPILER_FLAGS_TARGET_MAP[target_scheme] + " " + INCLUDE_PATHS
		c_compiler_flags = COMPILER_FLAGS_DEFAULT_C + " " + COMPILER_FLAGS_TARGET_MAP[target_scheme] + " " + INCLUDE_PATHS

		# Write the compiler rule for c, cpp and cc
		ninja_file.rule("compile_cpp", command="{} {} -o $out $in".format(cpp_compiler_path, cpp_compiler_flags), description="Compiling C++ source: $in", depfile="$out.o.d", deps="gcc")
		ninja_file.rule("compile_c", command="{} {} -o $out $in".format(c_compiler_path, c_compiler_flags), description="Compiling C source: $in", depfile="$out.o.d", deps="gcc")

		# Write the rule that generates the dependencies
		ninja_file.rule("dependencies_cpp", command="{} {} -MM -MG -MF $out $in".format(cpp_compiler_path, cpp_compiler_flags), description="Generating C++ dependency: $in")
		ninja_file.rule("dependencies_c", command="{} {} -MM -MG -MF $out $in".format(c_compiler_path, c_compiler_flags), description="Generating C dependency: $in")

		# Write the rule to build the static library. Note we use response files as on Windows the command is too long for CreateProcess
		ninja_file.rule("archive", command="{} rcs $out @$out.rsp".format(archiver_path), description="Building static library: $out", rspfile="$out.rsp", rspfile_content="$in")

		# Write the compile command for all source files.
		output_files = _write_build_command(ninja_file, SOURCE_PATHS, 'cpp', 'compile_cpp', 'dependencies_cpp', build_dir)
		output_files += _write_build_command(ninja_file, SOURCE_PATHS, 'c,cc', 'compile_c', 'dependencies_c', build_dir)

		# Write the command to generate the static library for ChilliSource and the application
		ninja_file.build(rule="archive", inputs=output_files, outputs=lib_path)
Example #2
0
def _generate_ninja_file(app_name,
	compiler_path, linker_path, archiver_path, 
	compiler_flags, linker_flags,
	app_source_dirs,
	project_root, build_dir, output_dir, lib_cs_path, lib_app_path):

	with open(os.path.join(build_dir, "Application.ninja"), "w") as build_file:
		ninja_file = Writer(build_file)

		ninja_file.variable(key="builddir", value=build_dir)

		# Write the compiler rule for c, cpp and cc
		ninja_file.rule("compile", command="{} {} -o $out $in".format(compiler_path, compiler_flags), description="Compiling source: $in", depfile="$out.o.d", deps="gcc")

		# Write the rule that generates the dependencies
		ninja_file.rule("dependencies", command="{} {} -MM -MG -MF $out $in".format(compiler_path, compiler_flags), description="Generating dependency: $in")

		# Write the rule to build the static library. Note we use response files as on Windows the command is too long for CreateProcess
		ninja_file.rule("archive", command="{} rcs $out @$out.rsp".format(archiver_path), description="Building static library: $out", rspfile="$out.rsp", rspfile_content="$in")

		# Write the rule to link. Note we use response files as on Windows the command is too long for CreateProcess
		ninja_file.rule("link", command="{} @$out.rsp {} -o $out".format(linker_path, linker_flags), description="Linking: $out", rspfile="$out.rsp", rspfile_content="$in")

		# Write the compile command for all source files.
		cs_source_dirs = [os.path.normpath('{}/ChilliSource/Source/ChilliSource'.format(project_root)), os.path.normpath('{}/ChilliSource/Source/CSBackend/Platform/RPi/'.format(project_root)), os.path.normpath('{}/ChilliSource/Source/CSBackend/Rendering/OpenGL/'.format(project_root))]
		cs_output_files = _write_build_command(ninja_file, cs_source_dirs, 'c,cpp,cc', 'compile', 'dependencies', project_root, build_dir)
		app_output_files = _write_build_command(ninja_file, app_source_dirs, 'c,cpp,cc', 'compile', 'dependencies', project_root, build_dir)
		all_output_files = cs_output_files + app_output_files

		# Write the command to generate the static library for ChilliSource and the application
		ninja_file.build(rule="archive", inputs=cs_output_files, outputs=lib_cs_path)
		ninja_file.build(rule="archive", inputs=app_output_files, outputs=lib_app_path)

		# Write the rule to link the libraries into the executable
		ninja_file.build(rule="link", inputs=all_output_files, outputs=os.path.join(output_dir, app_name))
def write_buildfile():
    with open("build.ninja", "w") as buildfile:
        n = Writer(buildfile)

        # Variable declarations
        n.variable("lib_path",
                   "/usr/msp430/lib")  #"/usr/lib/gcc/msp430/4.6.3")
        n.variable("tc_path", "/usr/bin")
        n.variable("cflags", cflags)
        n.variable("cxxflags", cxxflags)
        n.variable("lflags", lflags)

        # Rule declarations
        n.rule("cxx", command="$tc_path/msp430-g++ $cxxflags -c $in -o $out")

        n.rule("cc", command="$tc_path/msp430-gcc $cflags -c $in -o $out")

        n.rule("cl",
               command="$tc_path/msp430-gcc $lflags $in -o $out -lm -lgcc -lc")

        n.rule("oc", command="$tc_path/msp430-objcopy -O binary $in $out")

        n.rule("cdb", command="ninja -t compdb cc cxx > compile_commands.json")

        n.rule("cscf",
               command="find " + " ".join(set(source_dirs + include_dirs)) +
               " -regex \".*\\(\\.c\\|\\.h\\|.cpp\\|.hpp\\)$$\" -and " +
               "-not -type d > $out")

        n.rule("cscdb", command="cscope -bq")

        # Build rules
        n.build("compile_commands.json", "cdb")
        n.build("cscope.files", "cscf")
        n.build(["cscope.in.out", "cscope.po.out", "cscope.out"], "cscdb",
                "cscope.files")

        objects = []

        def cc(name):
            ofile = subst_ext(name, ".o")
            n.build(ofile, "cc", name)
            objects.append(ofile)

        def cxx(name):
            ofile = subst_ext(name, ".o")
            n.build(ofile, "cxx", name)
            objects.append(ofile)

        def cl(oname, ofiles):
            n.build(oname, "cl", ofiles)

        sources = get_sources()
        map(cc, filter(lambda x: x.endswith(".c"), sources))
        map(cxx, filter(lambda x: x.endswith(".cpp"), sources))

        cl("main.elf", objects)

        n.build("main.bin", "oc", "main.elf")
Example #4
0
def ninjafy(project):
    file = open("build.ninja", "w+")
    ninja = Writer(file)
    for v in project.variables:
        ninja.variable(v.key, v.value)
    for r in project.rules:
        ninja.rule(r.name, r.command)
    for b in project.builds:
        ninja.build(b.outputs, b.rule, b.inputs)
Example #5
0
def _generate_ninja_file(cpp_compiler_path, c_compiler_path, archiver_path,
                         target_scheme, build_dir, lib_path):

    with open(os.path.join(build_dir, "Application.ninja"), "w") as build_file:
        ninja_file = Writer(build_file)

        ninja_file.variable(key="builddir", value=build_dir)

        cpp_compiler_flags = COMPILER_FLAGS_DEFAULT_CPP + " " + COMPILER_FLAGS_TARGET_MAP[
            target_scheme] + " " + INCLUDE_PATHS
        c_compiler_flags = COMPILER_FLAGS_DEFAULT_C + " " + COMPILER_FLAGS_TARGET_MAP[
            target_scheme] + " " + INCLUDE_PATHS

        # Write the compiler rule for c, cpp and cc
        ninja_file.rule("compile_cpp",
                        command="{} {} -o $out $in".format(
                            cpp_compiler_path, cpp_compiler_flags),
                        description="Compiling C++ source: $in",
                        depfile="$out.o.d",
                        deps="gcc")
        ninja_file.rule("compile_c",
                        command="{} {} -o $out $in".format(
                            c_compiler_path, c_compiler_flags),
                        description="Compiling C source: $in",
                        depfile="$out.o.d",
                        deps="gcc")

        # Write the rule that generates the dependencies
        ninja_file.rule("dependencies_cpp",
                        command="{} {} -MM -MG -MF $out $in".format(
                            cpp_compiler_path, cpp_compiler_flags),
                        description="Generating C++ dependency: $in")
        ninja_file.rule("dependencies_c",
                        command="{} {} -MM -MG -MF $out $in".format(
                            c_compiler_path, c_compiler_flags),
                        description="Generating C dependency: $in")

        # Write the rule to build the static library. Note we use response files as on Windows the command is too long for CreateProcess
        ninja_file.rule("archive",
                        command="{} rcs $out @$out.rsp".format(archiver_path),
                        description="Building static library: $out",
                        rspfile="$out.rsp",
                        rspfile_content="$in")

        # Write the compile command for all source files.
        output_files = _write_build_command(ninja_file, SOURCE_PATHS, 'cpp',
                                            'compile_cpp', 'dependencies_cpp',
                                            build_dir)
        output_files += _write_build_command(ninja_file, SOURCE_PATHS, 'c,cc',
                                             'compile_c', 'dependencies_c',
                                             build_dir)

        # Write the command to generate the static library for ChilliSource and the application
        ninja_file.build(rule="archive", inputs=output_files, outputs=lib_path)
def write_buildfile():
    with open("build.ninja", "w") as buildfile:
        n = Writer(buildfile)

        # Variable declarations
        n.variable("lib_path", "/usr/arm-none-eabi/lib")
        n.variable("cflags", cflags)
        n.variable("cxxflags", cxxflags)
        n.variable("lflags", lflags)

        # Rule declarations
        n.rule("cxx",
               command = "arm-none-eabi-g++ $cxxflags -c $in -o $out")

        n.rule("cc",
               command = "arm-none-eabi-gcc $cflags -c $in -o $out")

        n.rule("cl",
               command = "arm-none-eabi-gcc $lflags $in -o $out")

        n.rule("oc",
               command = "arm-none-eabi-objcopy -O binary $in $out")

        n.rule("cdb",
              command = "ninja -t compdb cc cxx > compile_commands.json")

        n.rule("cscf",
              command = "find " + " ".join(set(source_dirs + include_dirs)) +
                        " -regex \".*\\(\\.c\\|\\.h\\|.cpp\\|.hpp\\)$$\" -and " +
                        "-not -type d > $out")

        n.rule("cscdb",
              command = "cscope -bq")

        # Build rules
        n.build("compile_commands.json", "cdb")
        n.build("cscope.files", "cscf")
        n.build(["cscope.in.out", "cscope.po.out", "cscope.out"], "cscdb",
                "cscope.files")

        objects = []

        def cc(name):
            ofile = subst_ext(name, ".o")
            n.build(ofile, "cc", name)
            objects.append(ofile)
        def cxx(name):
            ofile = subst_ext(name, ".o")
            n.build(ofile, "cxx", name)
            objects.append(ofile)
        def cl(oname, ofiles):
            n.build(oname, "cl", ofiles)

        sources = get_sources()
        map(cc, filter(lambda x : x.endswith(".c") or x.endswith(".S"), sources))
        map(cxx, filter(lambda x : x.endswith(".cpp"), sources))

        cl("main.elf", objects)

        n.build("main.bin", "oc", "main.elf")
Example #7
0
    return " ".join(map(lambda x: "-I" + x, source_dirs + include_dirs))


def get_libs():
    return " ".join(libraries)


def get_defines():
    return " ".join(map(lambda x: "-D" + x, defines))


with open("build.ninja", "w") as buildfile:
    n = Writer(buildfile)

    # Variable declarations
    n.variable("cxxflags",
               "-g -Wall -std=c++14 " + get_includes() + " " + get_defines())
    n.variable("cflags",
               "-g -Wall -std=c99 " + get_includes() + " " + get_defines())
    n.variable("lflags", " -lm -lstdc++ -lc")
    n.variable("libs", get_libs())

    # Rule declarations
    n.rule("cxx", command="g++ $cxxflags -c $in -o $out")

    n.rule("cc", command="gcc $cflags -c $in -o $out")

    n.rule("cl", command="gcc -o $out $in $libs $lflags")

    n.rule("ocb", command="objcopy -O binary $in $out")

    n.rule("cdb", command="ninja -t compdb cc cxx > cc_preexp.json")
Example #8
0
def write_ninja_rules(ninja: ninja_syntax.Writer, cpp: str, cppflags: str, extra_cflags: str, use_ccache: bool,
                      non_matching: bool, debug: bool):
    # platform-specific
    if sys.platform  == "darwin":
        iconv = "tools/iconv.py UTF-8 SHIFT-JIS"
    elif sys.platform == "linux":
        iconv = "iconv --from UTF-8 --to SHIFT-JIS"
    else:
        raise Exception(f"unsupported platform {sys.platform}")

    ccache = ""

    if use_ccache:
        ccache = "ccache "
        try:
            subprocess.call(["ccache"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        except FileNotFoundError:
            ccache = ""

    cross = "mips-linux-gnu-"
    cc = f"{BUILD_TOOLS}/cc/gcc/gcc"
    cc_ido = f"{BUILD_TOOLS}/cc/ido5.3/cc"
    cc_272_dir = f"{BUILD_TOOLS}/cc/gcc2.7.2/"
    cc_272 = f"{cc_272_dir}/gcc"
    cxx = f"{BUILD_TOOLS}/cc/gcc/g++"

    CPPFLAGS_COMMON = "-Iver/$version/build/include -Iinclude -Isrc -Iassets/$version -D_LANGUAGE_C -D_FINALROM " \
               "-DVERSION=$version -DF3DEX_GBI_2 -D_MIPS_SZLONG=32"

    CPPFLAGS = "-w " + CPPFLAGS_COMMON + " -nostdinc"

    CPPFLAGS_272 = "-Iver/$version/build/include -Iinclude -Isrc -Iassets/$version -D_LANGUAGE_C -D_FINALROM " \
               "-DVERSION=$version -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 -nostdinc"

    cflags = f"-c -G0 -O2 -fno-common -B {BUILD_TOOLS}/cc/gcc/ {extra_cflags}"
    cflags_272 = f"-c -G0 -mgp32 -mfp32 -mips3 {extra_cflags}"
    cflags_272 = cflags_272.replace("-ggdb3","-g1")

    ninja.variable("python", sys.executable)

    ninja.rule("ld",
        description="link($version) $out",
        command=f"{cross}ld -T ver/$version/build/undefined_syms.txt -T ver/$version/undefined_syms_auto.txt -T ver/$version/undefined_funcs_auto.txt -Map $mapfile --no-check-sections -T $in -o $out",
    )

    objcopy_sections = ""
    if debug:
        ninja.rule("genobjcopy",
            description="generate $out",
            command=f"$python {BUILD_TOOLS}/genobjcopy.py $in $out",
        )
        objcopy_sections = "@ver/$version/build/objcopy_sections.txt "

    ninja.rule("z64",
        description="rom $out",
        command=f"{cross}objcopy {objcopy_sections} $in $out -O binary && {BUILD_TOOLS}/rom/n64crc $out",
    )

    ninja.rule("sha1sum",
        description="check $in",
        command="sha1sum -c $in && touch $out" if DO_SHA1_CHECK else "touch $out",
    )

    ninja.rule("cpp",
        description="cpp $in",
        command=f"{cpp} $in {cppflags} -P -o $out"
    )

    ninja.rule("cc",
        description="gcc $in",
        command=f"bash -o pipefail -c '{cpp} {CPPFLAGS} {cppflags} $cppflags -MD -MF $out.d $in -o - | {iconv} > $out.i && {ccache}{cc} {cflags} $cflags $out.i -o $out'",
        depfile="$out.d",
        deps="gcc",
    )

    ninja.rule("cc_ido",
        description="ido $in",
        command=f"{ccache}{cc_ido} -w {CPPFLAGS_COMMON} {cppflags} $cppflags -c -mips1 -O0 -G0 -non_shared -Xfullwarn -Xcpluscomm -o $out $in",
    )

    ninja.rule("cc_272",
        description="cc_272 $in",
        command=f"bash -o pipefail -c 'COMPILER_PATH={cc_272_dir} {cc_272} {CPPFLAGS_272} {cppflags} $cppflags {cflags_272} $cflags $in -o $out && mips-linux-gnu-objcopy -N $in $out'",
    )

    ninja.rule("cxx",
        description="cxx $in",
        command=f"bash -o pipefail -c '{cpp} {CPPFLAGS} {cppflags} $cppflags -MD -MF $out.d $in -o - | {iconv} > $out.i && {ccache}{cxx} {cflags} $cflags $out.i -o $out'",
        depfile="$out.d",
        deps="gcc",
    )

    ninja.rule("bin",
        description="bin $in",
        command=f"{cross}ld -r -b binary $in -o $out",
    )

    ninja.rule("as",
        description="as $in",
        command=f"{cross}as -EB -march=vr4300 -mtune=vr4300 -Iinclude $in -o $out",
    )

    ninja.rule("img",
        description="img($img_type) $in",
        command=f"$python {BUILD_TOOLS}/img/build.py $img_type $in $out $img_flags",
    )

    ninja.rule("img_header",
        description="img_header $in",
        command=f"$python {BUILD_TOOLS}/img/header.py $in $out $c_name",
    )

    ninja.rule("bin_inc_c",
        description="bin_inc_c $out",
        command=f"$python {BUILD_TOOLS}/bin_inc_c.py $in $out $c_name",
    )

    ninja.rule("yay0",
        description="yay0 $in",
        command=f"{BUILD_TOOLS}/yay0/Yay0compress $in $out",
    )

    ninja.rule("sprite",
        description="sprite $sprite_name",
        command=f"$python {BUILD_TOOLS}/sprites/sprite.py $out $sprite_dir",
    )

    ninja.rule("sprite_combine",
        description="sprite_combine $in",
        command=f"$python {BUILD_TOOLS}/sprites/combine.py $out $in",
    )

    ninja.rule("sprite_header",
        description="sprite_header $sprite_name",
        command=f"$python {BUILD_TOOLS}/sprites/header.py $out $sprite_dir $sprite_id",
    )

    ninja.rule("msg",
        description="msg $in",
        command=f"$python {BUILD_TOOLS}/msg/parse_compile.py $in $out",
    )

    ninja.rule("msg_combine",
        description="msg_combine $out",
        command=f"$python {BUILD_TOOLS}/msg/combine.py $out $in",
    )

    ninja.rule("mapfs",
        description="mapfs $out",
        command=f"$python {BUILD_TOOLS}/mapfs/combine.py $version $out $in",
    )

    ninja.rule("pack_title_data",
        description="pack_title_data $out",
        command=f"$python {BUILD_TOOLS}/mapfs/pack_title_data.py $out $in",
    )

    ninja.rule("map_header", command=f"$python {BUILD_TOOLS}/mapfs/map_header.py $in > $out")

    ninja.rule("pm_charset", command=f"$python {BUILD_TOOLS}/pm_charset.py $out $in")

    ninja.rule("pm_charset_palettes", command=f"$python {BUILD_TOOLS}/pm_charset_palettes.py $out $in")

    with Path("tools/permuter_settings.toml").open("w") as f:
        f.write(f"compiler_command = \"{cc} {CPPFLAGS.replace('$version', 'us')} {cflags} -DPERMUTER -fforce-addr\"\n")
        f.write(f"assembler_command = \"{cross}as -EB -march=vr4300 -mtune=vr4300 -Iinclude\"\n")
        f.write(
"""
[preserve_macros]
"gs?[DS]P.*" = "void"
OVERRIDE_FLAG_CHECK = "int"
OS_K0_TO_PHYSICAL = "int"
"G_.*" = "int"
"TEXEL.*" = "int"
PRIMITIVE = "int"

[decompme.compilers]
"tools/build/cc/gcc/gcc" = "gcc2.8.1"
""")
    parser.add_argument('output')
    args = parser.parse_args()

    with codecs.open(args.output, 'w', 'utf-8') as f:
        writer = Writer(f)

        writer.comment('ninjaの定数等を定義するファイル')
        writer.newline()

        # このリポジトリのルートディレクトリ
        root_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..'))

        writer.comment('テキストコンバーター')
        writer.variable(key='text_converter',
                        value=os.path.join(root_dir, 'scripts',
                                           'text_converter.py'))

        writer.comment('テキストマージャー')
        writer.variable(key='text_merger',
                        value=os.path.join(root_dir, 'scripts',
                                           'text_merger.py'))

        writer.comment('中間ディレクトリ')
        writer.variable(key='tmpdir',
                        value=os.path.join(root_dir, 'build', 'tmp'))

        writer.comment('出力ディレクトリ')
        writer.variable(key='outdir',
                        value=os.path.join(root_dir, 'build', 'out'))
Example #10
0
SRC_DIR = 'src'
BUILD_DIR = 'build'
BIN_DIR = 'bin'

with open('build.ninja', 'w') as build_file:
    n = Writer(build_file)

    n.comment('THIS FILE IS GENERATED BY configure.py')
    n.comment('EDITS WILL BE OVERWRITTEN')
    n.newline()

    ############################################################################
    # VARIABLES
    ############################################################################

    n.variable(key='ninja_required_version', value='1.9')

    if sys.platform == 'win32':
        n.variable(key='msvc_deps_prefix', value='Note: including file:')

    n.variable(key='cc', value=CC)
    n.variable(key='cflags', value=' '.join(CFLAGS))
    n.variable(key='project_name', value=PROJECT_NAME)
    n.variable(key='src_dir', value=SRC_DIR)
    n.variable(key='bin_dir', value=BIN_DIR)
    n.variable(key='build_dir', value=BUILD_DIR)

    n.newline()

    ############################################################################
    # RULES
Example #11
0
    for d in source_dirs:
        for f in os.listdir(d):
            fnames.append(os.path.join(d, f))
    return fnames


def get_includes():
    return " ".join(map(lambda x: "-I" + x, source_dirs))


with open("build.ninja", "w") as buildfile:
    n = Writer(buildfile)

    # Variable declarations
    n.variable(
        "cflags",
        "-c -Os -w -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -DF_CPU=80000000L -DPART_TM4C123GH6PM "
        + get_includes())
    n.variable(
        "lflags",
        "-Os -nostartfiles -nostdlib -Wl,--gc-sections -T lm4fcpp_blizzard.ld -Wl,--entry=ResetISR -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -lm -lc -lgcc"
    )

    # Rule declarations
    n.rule("cxx", command="arm-none-eabi-g++ $cxxflags -c $in -o $out")

    n.rule("cc", command="arm-none-eabi-gcc $cflags -c $in -o $out")

    n.rule("cca", command="arm-none-eabi-gcc $cflags -S -c $in -o $out")

    n.rule("cl", command="arm-none-eabi-gcc $lflags $in -o $out")
Example #12
0
def write_ninja_rules(ninja: ninja_syntax.Writer, cpp: str):
    # platform-specific
    if sys.platform == "darwin":
        os_dir = "mac"
        iconv = "tools/iconv.py UTF-8 SHIFT-JIS"
    elif sys.platform == "linux":
        from os import uname

        if uname()[4] == "aarch64":
            os_dir = "arm"
        else:
            os_dir = "linux"

        iconv = "iconv --from UTF-8 --to SHIFT-JIS"
    else:
        raise Exception(f"unsupported platform {sys.platform}")

    cross = "mips-linux-gnu-"

    ninja.variable("python", sys.executable)

    ninja.rule(
        "ld",
        description="link($version) $out",
        command=
        f"{cross}ld -T ver/$version/undefined_syms.txt -T ver/$version/undefined_syms_auto.txt -T ver/$version/undefined_funcs_auto.txt  -T ver/$version/dead_syms.txt -Map $mapfile --no-check-sections -T $in -o $out",
    )

    ninja.rule(
        "z64",
        description="rom $out",
        command=
        f"{cross}objcopy $in $out -O binary && {BUILD_TOOLS}/rom/n64crc $out",
    )

    if DO_SHA1_CHECK:
        ninja.rule(
            "sha1sum",
            description="check $in",
            command=f"sha1sum -c $in && touch $out",
        )
    else:
        ninja.rule(
            "sha1sum",
            description="check $in",
            command=f"touch $out",
        )

    ninja.rule(
        "cc",
        description="cc($version) $in",
        command=
        f"bash -o pipefail -c '{cpp} {CPPFLAGS} $in -o - | {iconv} | {BUILD_TOOLS}/{os_dir}/cc1 {CFLAGS} -o - | {BUILD_TOOLS}/{os_dir}/mips-nintendo-nu64-as -EB -G 0 - -o $out'",
        depfile="$out.d",
        deps="gcc",
    )

    ninja.rule(
        "cc_nusys",
        description="cc($version) $in",
        command=
        f"bash -o pipefail -c '{cpp} {CPPFLAGS} $in -o - | {iconv} | {BUILD_TOOLS}/{os_dir}/cc1 {CFLAGS_NUSYS} -o - | {BUILD_TOOLS}/{os_dir}/mips-nintendo-nu64-as -EB -G 0 - -o $out'",
        depfile="$out.d",
        deps="gcc",
    )

    ninja.rule(
        "cc_libultra",
        description="cc($version) $in",
        command=
        f"bash -o pipefail -c '{cpp} {CPPFLAGS} $in -o - | {iconv} | {BUILD_TOOLS}/{os_dir}/cc1 {CFLAGS_LIBULTRA} -o - | {BUILD_TOOLS}/{os_dir}/mips-nintendo-nu64-as -EB -G 0 - -o $out'",
        depfile="$out.d",
        deps="gcc",
    )

    ninja.rule(
        "cc_dsl",
        description="cc_dsl($version) $in",
        command=
        f"bash -o pipefail -c '{cpp} {CPPFLAGS} $in -o - | $python {BUILD_TOOLS}/cc_dsl/compile_script.py | {iconv} | {BUILD_TOOLS}/{os_dir}/cc1 {CFLAGS} -o - | {BUILD_TOOLS}/{os_dir}/mips-nintendo-nu64-as -EB -G 0 - -o $out'",
        depfile="$out.d",
        deps="gcc",
    )

    ninja.rule(
        "bin",
        description="bin $in",
        command=f"{cross}ld -r -b binary $in -o $out",
    )

    ninja.rule(
        "as",
        description="as $in",
        command=
        f"{cross}as -EB -march=vr4300 -mtune=vr4300 -Iinclude $in -o $out",
    )

    ninja.rule(
        "img",
        description="img($img_type) $in",
        command=
        f"$python {BUILD_TOOLS}/img/build.py $img_type $in $out $img_flags",
    )

    ninja.rule(
        "img_header",
        description="img_header $in",
        command=f"$python {BUILD_TOOLS}/img/header.py $in $out",
    )

    ninja.rule(
        "yay0",
        description="yay0 $in",
        command=f"{BUILD_TOOLS}/yay0/Yay0compress $in $out",
    )

    ninja.rule(
        "sprite",
        description="sprite $sprite_name",
        command=f"$python {BUILD_TOOLS}/sprites/sprite.py $out $sprite_dir",
    )

    ninja.rule(
        "sprite_combine",
        description="sprite_combine $in",
        command=f"$python {BUILD_TOOLS}/sprites/combine.py $out $in",
    )

    ninja.rule(
        "sprite_header",
        description="sprite_header $sprite_name",
        command=
        f"$python {BUILD_TOOLS}/sprites/header.py $out $sprite_dir $sprite_id",
    )

    ninja.rule(
        "msg",
        description="msg $in",
        command=f"$python {BUILD_TOOLS}/msg/parse_compile.py $in $out",
    )

    ninja.rule(
        "msg_combine",
        description="msg_combine $out",
        command=f"$python {BUILD_TOOLS}/msg/combine.py $out $in",
    )

    ninja.rule(
        "mapfs",
        description="mapfs $out",
        command=f"$python {BUILD_TOOLS}/mapfs/combine.py $out $in",
    )

    ninja.rule("map_header",
               command=f"$python {BUILD_TOOLS}/mapfs/map_header.py $in > $out")
Example #13
0
def ninjaCommonHeader(cursor: Writer, ag: Any) -> None:
    '''
    Writes a common header to the ninja file. ag is parsed arguments.
    '''
    cursor.comment('-- start common ninja header --')
    cursor.comment(f'Note, this ninja file was automatically generated by {__file__}')
    cursor.newline()
    cursor.comment('-- compiling tools --')
    cursor.newline()
    cursor.variable('CXX', 'g++')
    cursor.variable('PROTOC', '/usr/bin/protoc')
    cursor.variable('PROTO_TEXT', f'./proto_text')
    cursor.variable('SHOGUN_EXTRA', '') # used for adding specific flags for a specific target
    cursor.newline()
    cursor.comment('-- compiler flags --')
    cursor.newline()
    cursor.variable('CPPFLAGS', '-D_FORTIFY_SOURCE=2 ' + str(os.getenv('CPPFLAGS', '')))
    cursor.variable('CXXFLAGS', '-std=c++14 -O2 -pipe -fPIC -gsplit-dwarf -DNDEBUG'
        + ' -fstack-protector-strong -w ' + str(os.getenv('CXXFLAGS', '')))
    cursor.variable('LDFLAGS', '-Wl,-z,relro -Wl,-z,now ' + str(os.getenv('LDFLAGS', '')))
    cursor.variable('INCLUDES', '-I. -I./debian/embedded/eigen3 -I./third_party/eigen3/'
            + ' -I/usr/include/gemmlowp -I/usr/include/llvm-c-7'
            + ' -I/usr/include/llvm-7 -Ithird_party/toolchains/gpus/cuda/')
    cursor.variable('LIBS', '-lpthread -lprotobuf -lnsync -lnsync_cpp -ldouble-conversion'
	+ ' -ldl -lm -lz -lre2 -ljpeg -lpng -lsqlite3 -llmdb -lsnappy -lgif -lLLVM-7')
    cursor.newline()
    cursor.comment('-- compiling rules-- ')
    cursor.rule('rule_PROTOC', f'$PROTOC $in --cpp_out . $SHOGUN_EXTRA')
    cursor.rule('rule_PROTOC_GRPC', f'$PROTOC --grpc_out . --cpp_out . --plugin protoc-gen-grpc=/usr/bin/grpc_cpp_plugin $in')
    cursor.rule('rule_PROTO_TEXT', f'$PROTO_TEXT tensorflow/core tensorflow/core tensorflow/tools/proto_text/placeholder.txt $in')
    cursor.rule('rule_CXX_OBJ', f'$CXX $CPPFLAGS $CXXFLAGS $INCLUDES $SHOGUN_EXTRA -c $in -o $out')
    cursor.rule('rule_CXX_EXEC', f'$CXX $CPPFLAGS $CXXFLAGS $INCLUDES $LDFLAGS $LIBS $SHOGUN_EXTRA $in -o $out')
    cursor.rule('rule_CXX_SHLIB', f'$CXX -shared -fPIC $CPPFLAGS $CXXFLAGS $INCLUDES $LDFLAGS $LIBS $SHOGUN_EXTRA $in -o $out')
    cursor.rule('rule_CC_OP_GEN', f'LD_LIBRARY_PATH=. ./$in $out $cc_op_gen_internal tensorflow/core/api_def/base_api')
    cursor.rule('COPY', f'cp $in $out')
    cursor.newline()
    cursor.comment('-- end common ninja header --')
    cursor.newline()
Example #14
0
# Create working directories
mkdir_if_ne(build_dir)

## Collect the sources list
sources = reduce(lambda a, b: a + b, [
    filter(filter_source, os.listdir(source_dir)) for source_dir in source_dirs
])

## Identify toplevel design file
topfile = find_top(sources)

with open("build.ninja", "w") as buildfile:
    n = Writer(buildfile)

    n.variable("builddir", build_dir)
    n.variable("const", constraint_file)
    n.variable("device", device)
    n.variable("device_type", device_type)
    n.variable("package", package)
    n.variable("clock_constraint_mhz", clock_constraint_mhz)
    n.variable("topfile", topfile)
    n.variable("top_module", os.path.splitext(topfile)[0])
    n.variable("sources", ' '.join(sources))

    n.rule("cpbuild", "cp $in $out")

    n.rule(
        "synthesize",
        "(cd $builddir; yosys -ql hardware.log -p 'synth_ice40 -top $top_module -blif hardware.blif; write_verilog optimized.v' $sources)"
    )
Example #15
0
#!/usr/bin/env python3

from ninja_syntax import Writer

with open("build.ninja", "w") as buildfile:
    n = Writer(buildfile)

    n.variable("cc", "clang")
    n.variable("cflags", "-Weverything")

    n.rule("compile",
           command="$cc $cflags -c $in -o $out",
           description="Compiling object file $out")

    n.rule("link",
           command="$cc $in -o $out",
           description="Linking executable $out")
    n.build("hello.o", "compile hello.c")
    n.build("hello", "link hello.o")

    n.default("hello")
def get_includes():
    return " ".join(map(lambda x : "-I"+x, source_dirs + include_dirs))

def get_libs():
    return " ".join(libraries)
    #return "-Wl,-rpath," + (":".join(library_dirs))

def get_defines():
    return " ".join(map(lambda x : "-D"+x, defines))

with open("build.ninja", "w") as buildfile:
    n = Writer(buildfile)

    # Variable declarations
    n.variable("cflags", "-funsigned-char -funsigned-bitfields -DDEBUG -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=attiny84a -c -std=gnu99 " + get_includes() + " " +  get_defines())
    n.variable("lflags", " -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=attiny84a")
    n.variable("libs", get_libs())

    # Rule declarations
    n.rule("cxx",
           command = "avr-g++ $cxxflags -c $in -o $out")

    n.rule("cc",
           command = "avr-gcc $cflags -c $in -o $out")

    n.rule("cl",
           command = "avr-gcc -o $out $in $libs $lflags")

    n.rule("och",
           command = "avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $in $out")
Example #17
0
## Collect the sources list
sources = reduce(lambda a,b : a+b, [filter(lambda d : check_source_ext(d),
                                           os.listdir(source_dir)) for
                                    source_dir in source_dirs])

## Identify toplevel design file
topfile = find_top(sources)

open(bdir(project_file), "w").write(
    "\n".join(["%s %s %s" % (source_type(source), default_lib, source) for
    source in sources]) + "\n")

with open("build.ninja", "w") as buildfile:
    n = Writer(buildfile)

    n.variable("builddir", build_dir)
    n.variable("const", constraint_file)
    n.variable("device", device)
    n.variable("opt_level", "1")
    n.variable("opt_mode", "Speed")
    n.variable("global_opt", "speed")
    n.variable("package", package)
    n.variable("prjfile", project_file)
    n.variable("speed", speed)
    n.variable("topfile", os.path.splitext(topfile)[0])

    n.rule("cpbuild", "cp $in $out")
    n.rule("genscript", "echo \"run -ifn $prjfile -ifmt mixed -top $topfile " +
                         "-ofn design.ngc -ofmt NGC -p ${device}-${speed}-" +
                         "${package} -opt_mode $opt_mode -opt_level " +
                         "$opt_level\" > $out")
    "Hes_Apu.cpp", "Hes_Cpu.cpp", "Hes_Emu.cpp", "Kss_Cpu.cpp", "Kss_Emu.cpp",
    "Kss_Scc_Apu.cpp", "M3u_Playlist.cpp", "Multi_Buffer.cpp", "Music_Emu.cpp",
    "Nes_Apu.cpp", "Nes_Cpu.cpp", "Nes_Fme7_Apu.cpp", "Nes_Namco_Apu.cpp",
    "Nes_Oscs.cpp", "Nes_Vrc6_Apu.cpp", "Nsfe_Emu.cpp", "Nsf_Emu.cpp",
    "Sap_Apu.cpp", "Sap_Cpu.cpp", "Sap_Emu.cpp", "Sms_Apu.cpp", "Snes_Spc.cpp",
    "Spc_Cpu.cpp", "Spc_Dsp.cpp", "Spc_Emu.cpp", "Spc_Filter.cpp",
    "Vgm_Emu.cpp", "Vgm_Emu_Impl.cpp", "Ym2413_Emu.cpp", "Ym2612_Emu.cpp"
]

buildfile = open("build.ninja", "w")

n = Writer(buildfile)

# variable declarations
n.comment("variable declarations")
n.variable("CC", "emcc")
n.variable("CXX", "em++")
n.newline()
n.variable("ROOT", ".")
n.variable("XZ_ROOT", "$ROOT/xz-embedded")
n.variable("GME_ROOT", "$ROOT/gme-source-0.6.1")
n.variable("OBJECTS", "$ROOT/objects")
n.variable("FINAL_DIR", "$ROOT/final")
n.newline()
n.variable(
    "EXPORT_LIST",
    "\"['_crPlayerContextSize', '_crPlayerInitialize', '_crPlayerLoadFile', '_crPlayerSetTrack', '_crPlayerGenerateStereoFrames', '_crPlayerVoicesCanBeToggled', '_crPlayerGetVoiceCount', '_crPlayerGetVoiceName', '_crPlayerSetVoiceState', '_crPlayerCleanup', '_main']\""
)
n.newline()

# build rules
Example #19
0
def get_sources():
    fnames = []
    for d in source_dirs:
        for f in os.listdir(d):
            fnames.append(os.path.join(d, f))
    return fnames

def get_includes():
    return " ".join(map(lambda x : "-I"+x, source_dirs))

with open("build.ninja", "w") as buildfile:
    n = Writer(buildfile)

    # Variable declarations
    n.variable("tc_path", "/home/kbalke/Projects/Coding/energia-0101E0016/hardware/tools/lm4f/bin")
    n.variable("cflags", "-c -Os -w -g -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -DF_CPU=80000000L -DPART_TM4C123GH6PM " + get_includes())
    n.variable("cxxflags", "-c -Os -w -g -std=c++11 -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -DF_CPU=80000000L -DPART_TM4C123GH6PM " + get_includes())
    n.variable("lflags", "-Os -g -nostartfiles -nostdlib -Wl,--gc-sections -T lm4fcpp_blizzard.ld -Wl,--entry=ResetISR -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -lm -lc -lgcc -lstdc++")

    # Rule declarations
    n.rule("cxx",
           command = "$tc_path/arm-none-eabi-g++ $cxxflags -c $in -o $out")

    n.rule("cc",
           command = "$tc_path/arm-none-eabi-gcc $cflags -c $in -o $out")

    n.rule("cca",
           command = "$tc_path/arm-none-eabi-gcc $cflags -S -c $in -o $out")

    n.rule("cl",
Example #20
0
    'src/*.cc',
    'src/w/*.cc',
    'src/vfx/*.cc',
    'src/ops/*.cc',
)

c_sources = mglob(
    'src/*.c',
    'ext/*.c',
)

binary_data = {'DroidSansMonoTTF': 'fonts/DroidSansMono.ttf'}

with open('build.ninja', 'w') as f:
    w = Writer(f)
    w.variable('builddir', 'build')
    w.variable('cppflags', cppflags)
    w.variable('cflags', cflags)
    w.variable('ldflags', ldflags)
    w.rule('cpp',
           command=[
               cpp_compiler, '$cppflags', '-MMD', '-MF', '$out.d', '-c', '-o',
               '$out', '$in'
           ],
           depfile='$out.d')
    w.rule('cc',
           command=[
               c_compiler, '$cflags', '-MMD', '-MF', '$out.d', '-c', '-o',
               '$out', '$in'
           ],
           depfile='$out.d')