all repos — mgba @ 5e0641cb0e9b6b71c19954da443a8f7b5813c507

mGBA Game Boy Advance Emulator

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

 1import cffi
 2import os.path
 3import subprocess
 4import sys
 5
 6ffi = cffi.FFI()
 7src = os.path.join(os.path.dirname(__file__), "..", "..")
 8
 9ffi.set_source("mgba._pylib", """
10#include "util/common.h"
11#include "core/core.h"
12#include "core/log.h"
13#include "core/tile-cache.h"
14#include "arm/arm.h"
15#include "gba/gba.h"
16#include "gba/renderers/tile-cache.h"
17#include "lr35902/lr35902.h"
18#include "gb/gb.h"
19#include "gb/renderers/tile-cache.h"
20#include "util/png-io.h"
21#include "util/vfs.h"
22
23struct VFile* VFileFromPython(void* fileobj);
24
25struct VFilePy {
26    struct VFile d;
27    void* fileobj;
28};
29
30struct mLogger* mLoggerPythonCreate(void* pyobj);
31
32struct mLoggerPy {
33    struct mLogger d;
34    void* pyobj;
35};
36""", include_dirs=[src],
37     extra_compile_args=sys.argv[1:],
38     libraries=["mgba"],
39     library_dirs=[os.path.join(os.getcwd(), "..")],
40     sources=[os.path.join(os.path.dirname(__file__), path) for path in ["vfs-py.c", "log.c"]])
41
42with open(os.path.join(os.getcwd(), "_builder.h")) as core:
43    lines = []
44    for line in core:
45        line = line.strip()
46        if line.startswith('#'):
47            continue
48        lines.append(line)
49    ffi.cdef('\n'.join(lines))
50
51ffi.compile()