all repos — mgba @ 34964495171d71264e34874e001046c471b2df74

mGBA Game Boy Advance Emulator

src/platform/python/_builder.py (view raw)

 1import cffi
 2import os, os.path
 3import shlex
 4import subprocess
 5import sys
 6
 7ffi = cffi.FFI()
 8pydir = os.path.dirname(os.path.abspath(__file__))
 9srcdir = os.path.join(pydir, "..", "..")
10bindir = os.environ.get("BINDIR", os.path.join(os.getcwd(), ".."))
11
12cpp = shlex.split(os.environ.get("CPP", "cc -E"))
13cppflags = shlex.split(os.environ.get("CPPFLAGS", ""))
14if __name__ == "__main__":
15    cppflags.extend(sys.argv[1:])
16cppflags.extend(["-I" + srcdir, "-I" + bindir])
17
18ffi.set_source("mgba._pylib", """
19#include "flags.h"
20#include "util/common.h"
21#include "core/core.h"
22#include "core/log.h"
23#include "core/tile-cache.h"
24#include "arm/arm.h"
25#include "gba/gba.h"
26#include "gba/input.h"
27#include "gba/renderers/tile-cache.h"
28#include "lr35902/lr35902.h"
29#include "gb/gb.h"
30#include "gb/renderers/tile-cache.h"
31#include "util/png-io.h"
32#include "util/vfs.h"
33
34struct VFile* VFileFromPython(void* fileobj);
35
36struct VFilePy {
37    struct VFile d;
38    void* fileobj;
39};
40
41struct mLogger* mLoggerPythonCreate(void* pyobj);
42
43struct mLoggerPy {
44    struct mLogger d;
45    void* pyobj;
46};
47""", include_dirs=[srcdir],
48     extra_compile_args=cppflags,
49     libraries=["mgba"],
50     library_dirs=[bindir],
51     sources=[os.path.join(pydir, path) for path in ["vfs-py.c", "log.c"]])
52
53preprocessed = subprocess.check_output(cpp + ["-fno-inline", "-P"] + cppflags + [os.path.join(pydir, "_builder.h")], universal_newlines=True)
54
55lines = []
56for line in preprocessed.splitlines():
57    line = line.strip()
58    if line.startswith('#'):
59        continue
60    lines.append(line)
61ffi.cdef('\n'.join(lines))
62
63if __name__ == "__main__":
64    ffi.compile()