Exemplo n.º 1
0
def write_ninja_for_tools(ninja: ninja_syntax.Writer):
    ninja.rule("cc_tool",
        description="cc_tool $in",
        command=f"cc -w $in -O3 -o $out",
    )

    ninja.build(YAY0_COMPRESS_TOOL, "cc_tool", f"{BUILD_TOOLS}/yay0/Yay0compress.c")
    ninja.build(CRC_TOOL, "cc_tool", f"{BUILD_TOOLS}/rom/n64crc.c")
Exemplo n.º 2
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)
Exemplo n.º 3
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))
Exemplo n.º 4
0
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")

    n.rule("synthesize", "(cd $builddir; xst -ifn xst_script)")
    n.rule("build", "(cd $builddir; ngdbuild -uc $const design.ngc design.ngd)")
    n.rule("map", "(cd $builddir; map -global_opt $global_opt -logic_opt on " +
                  "-mt on -timing -w design.ngd -o design.ncd design.pcf)")
    n.rule("par", "(cd $builddir; par -w design.ncd finished/design.ncd " +
                  "design.pcf)")
    n.rule("bitgen", "(cd $builddir; bitgen -w finished/design.ncd " +
                     "design.bit design.pcf)")

    for f in sources + [constraint_file]:
Exemplo n.º 5
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")
Exemplo n.º 6
0
                ('destdir', '$builddir/%s' % prj),
                ('workdir', '$intdir/%s' % prj),
            ]))
    n.build([prj], 'phony', target)
    return target


with open('build.ninja', 'w') as buildfile:
    n = Writer(buildfile, width=20)
    n.comment('generated by %s' % sys.argv[0])
    n.include('build.vars.ninja')

    n.rule(
        'download',
        description='Downloading $url...',
        pool='console',
        command=
        'curl -o $out $url && test "$sha256" = `shasum -a256 $out | cut -f1 -d" "`'
    )

    targets = []

    n.build(
        ['tarballs/%s' % GETTEXT_TARBALL],
        'download',
        variables={
            'url': 'https://ftp.gnu.org/pub/gnu/gettext/%s' % GETTEXT_TARBALL,
            'sha256': GETTEXT_SHA256,
        })

    targets.append(
Exemplo n.º 7
0
            name = 'hlp.png'
        elif path.endswith('.out.js'):
            name = path[:-7] + '.js'

        stream.write('  <file alias="%s">%s</file>\n' % (name, os.path.abspath(path)))

    stream.write('</qresource>\n')
    stream.write('</RCC>')

info('Writing build.ninja...\n')

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

    n.comment('Transformers')
    n.rule('uic', py_script('tools/common/uic.py', ['$in', '$out'] + pyuic), 'UIC $out')
    n.rule('rcc', cmd2str([rcc, '-binary', '$in', '-o', '$out']), 'RCC $out')
    n.rule('js_lupdate', py_script('tools/common/js_lupdate.py', ['-o', '$out', '$in']), 'JS-LUPDATE $out')
    n.rule('pylupdate', cmd2str(pylupdate + ['$in', '-ts', '$out']), 'PY-LUPDATE $out')
    n.rule('lupdate', cmd2str([lupdate, '$in', '-ts', '$out']), 'LUPDATE $out')
    n.rule('webpack', cmdenv([node, 'node_modules/webpack/bin/webpack.js'], {'USE_WEBKIT': webkit}), 'WEBPACK $out')

    if sys.platform.startswith('linux'):
        n.rule('cat', 'cat $in > $out', 'CAT $out')

    n.comment('Files')
    ui_targets = build_targets(n, UI_FILES, 'uic', new_ext='py', new_path='knossos/ui')
    n.build('knossos/data/resources.rcc', 'rcc', 'knossos/data/resources.qrc', implicit=RCC_FILES)
    n.build('html/js/translations.js', 'js_lupdate', ['html/js/main.js'])
    n.build('locale/_py.ts', 'pylupdate', SRC_FILES)
    n.build('locale/_ui.ts', 'lupdate', ['locale/_py.ts', 'html/js/translations.js'] + UI_FILES)
Exemplo n.º 8
0
    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")

    n.rule("cdb_e",
           command=
           "cat cc_preexp.json | ./expand_compdb.py > compile_commands.json")

    n.rule(
        "cscf",
Exemplo n.º 9
0
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("ldscript_dev_path", "/usr/msp430/lib/ldscripts/" + MCU)
        n.variable("ldscript_path", "/usr/msp430/lib/ldscripts")
        n.variable("tc_path", "/usr/bin")
        n.variable("cflags", cflags)
        n.variable("cxxflags", cxxflags)
        n.variable("lflags", lflags)

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

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

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

        n.rule("oc", command="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 | egrep -v \"msp430[a-zA-Z0-9]*\\.h$$\" > $out; echo "
            + "/usr/msp430/include/" + MCU + ".h" + " > $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")
Exemplo n.º 10
0
    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
    ############################################################################

    if sys.platform == 'win32':
        n.rule('compile',
               command='$cc /showIncludes $cflags -c $in -Fo$out',
               deps='msvc')
    else:
        n.rule('compile',
               command='$cc $cflags -c $in -o $out -MMD -MF $out.d',
               depfile='$out.d')

    if sys.platform == 'win32':
        n.rule('link', command='link $in /OUT:$out')
    else:
        n.rule('link', command='$cc $in -o $bin_dir/$out')

    n.rule('clean_all', command='rm -rf $build_dir $bin_dir $project_name')
    if sys.platform == 'win32':
        n.rule('make_dirs',
               command='cmd /c if not exist $build_dir mkdir $build_dir')
Exemplo n.º 11
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")
Exemplo n.º 12
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()
Exemplo n.º 13
0
import glob
import os
from ninja_syntax import Writer

gxc_dirs = glob.glob('./examples/**/', recursive=True)

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

    n.rule("grc",
           command="cmd /c cd ${cwd} && grc ${in_name}",
           description="grc ${in_name}")
    n.rule("gxc",
           command="cmd /c cd ${cwd} && gxc ${in_name}",
           description="gxc ${in_name}")

    for dir in gxc_dirs:
        gxc_files = glob.glob(dir + '*.gxc')
        if gxc_files:
            grc_files = glob.glob(dir + '*.grc')
            gxc_implicit_inputs = []
            for grc_file in grc_files:
                #def build(self, outputs, rule, inputs=None, implicit=None, order_only=None,
                #variables=None, implicit_outputs=None):
                grc_file_name_part = os.path.split(grc_file)[1].split('.')[0]
                gr_file = os.path.join(dir, grc_file_name_part + '.gr')
                grh_file = os.path.join(dir, grc_file_name_part + '.grh')
                gxc_implicit_inputs.append(gr_file)
                gxc_implicit_inputs.append(grh_file)
                n.build(gr_file,
                        'grc',
Exemplo n.º 14
0
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)"
    )
    n.rule(
        "par",
        "(cd $builddir; arachne-pnr -d $device -P $package -o hardware.asc -p $const hardware.blif)"
    )
    n.rule(
        "timing",
        "(cd $builddir; icetime -d $device_type -c $clock_constraint_mhz -mtr hardware.rpt hardware.asc)"
    )
    n.rule("bitgen", "(cd $builddir; icepack hardware.asc hardware.bin)")
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
n.comment("build rules")
n.rule(
    "XZ_CC",
    command="$CC -Wall -Os -I $XZ_ROOT -MMD -MT $out -MF $out.d -o $out -c $in",
    description="XZ_CC $out",
    depfile="$out.d")
n.newline()

for gme_type in GME_TYPES:
    n.rule(
        "GME_" + gme_type + "_CXX",
        command=
        "$CXX -Wall -Os -I $GME_ROOT -DHAVE_CONFIG_H -I $GME_ROOT/config-headers/"
        + gme_type + " -MMD -MT $out -MF $out.d -o $out -c $in",
        description="GME_CXX $out",
        depfile="$out.d")
    n.newline()

n.rule(
Exemplo n.º 16
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"
""")
Exemplo n.º 17
0
if __name__ == '__main__':
    # 引数処理
    parser = argparse.ArgumentParser()
    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()

        # configファイルのインクルード
        writer.include('config.ninja')
        writer.newline()

        # ルール定義

        writer.rule(
            name='text_converter',
            command='python $text_converter $in $out --setting $setting_file',
            description='<キャラ名>を置換するコンバート')
        writer.newline()

        writer.rule(name='text_merger',
                    command='python $text_merger $in $out --depfile $out.d',
                    deps='gcc',
                    depfile='$out.d',
                    description='includeを展開するコンバート')
        writer.newline()
Exemplo n.º 18
0
    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",
           command = "$tc_path/arm-none-eabi-gcc $lflags $in -o $out")

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

    n.rule("cdb",
           command = "ninja -t compdb cc cxx > compile_commands.json")
Exemplo n.º 19
0
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')
    w.rule('bin2c', command=['python', 'bin2c.py', '$varname', '$in', '$out'])
    objs = []
    for src in cpp_sources:
        stem = strip_suffix(src)
        obj = '$builddir/' + stem + '.o'
        objs.append(obj)
        w.build(obj, rule='cpp', inputs=src)