all repos — mgba @ 572eb40d420984f477269200dd7988eba09552bd

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/input.h"
17#include "gba/renderers/tile-cache.h"
18#include "lr35902/lr35902.h"
19#include "gb/gb.h"
20#include "gb/renderers/tile-cache.h"
21#include "util/png-io.h"
22#include "util/vfs.h"
23
24struct VFile* VFileFromPython(void* fileobj);
25
26struct VFilePy {
27    struct VFile d;
28    void* fileobj;
29};
30
31struct mLogger* mLoggerPythonCreate(void* pyobj);
32
33struct mLoggerPy {
34    struct mLogger d;
35    void* pyobj;
36};
37""", include_dirs=[src],
38     extra_compile_args=sys.argv[1:],
39     libraries=["mgba"],
40     library_dirs=[os.path.join(os.getcwd(), "..")],
41     sources=[os.path.join(os.path.dirname(__file__), path) for path in ["vfs-py.c", "log.c"]])
42
43with open(os.path.join(os.getcwd(), "_builder.h")) as core:
44    lines = []
45    for line in core:
46        line = line.strip()
47        if line.startswith('#'):
48            continue
49        lines.append(line)
50    ffi.cdef('\n'.join(lines))
51
52ffi.compile()