2121import os
2222import platform
2323import sys
24+ import subprocess
2425
2526ffibuilder = FFI ()
2627
2728
29+ def get_the_include_path ():
30+ return subprocess .run (['pkg-config' , '--variable=includedir' , 'raylib' ], stdout = subprocess .PIPE ).stdout .decode (
31+ 'utf-8' ).strip ()
32+
33+
34+ def get_the_lib_path ():
35+ return subprocess .run (['pkg-config' , '--variable=libdir' , 'raylib' ], stdout = subprocess .PIPE ).stdout .decode (
36+ 'utf-8' ).strip ()
37+
38+
39+ ffi_includes = """
40+ #include "raylib.h"
41+ #define RAYGUI_IMPLEMENTATION
42+ #define RAYGUI_SUPPORT_RICONS
43+ #include "raygui.h"
44+ #define PHYSAC_IMPLEMENTATION
45+ #include "physac.h"
46+ """
47+
48+
2849def mangle (file ):
2950 result = ""
3051 skip = False
@@ -39,8 +60,6 @@ def mangle(file):
3960 continue
4061 if line .startswith ("#endif // RAYGUI_H" ):
4162 break
42- if line .__contains__ ("GetTouchEvent" ):
43- continue
4463 if line .startswith ("#" ):
4564 continue
4665 if line .startswith ("RLAPI" ):
@@ -56,19 +75,12 @@ def mangle(file):
5675
5776def build_linux ():
5877 print ("BUILDING FOR LINUX" )
59- ffibuilder .cdef (mangle ("/usr/local/include /raylib.h" ))
78+ ffibuilder .cdef (mangle (get_the_include_path () + " /raylib.h" ))
6079 ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
6180 ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
62- ffibuilder .set_source ("raylib._raylib_cffi" ,
63- """
64- #include "raylib.h"
65- #define RAYGUI_IMPLEMENTATION
66- #define RAYGUI_SUPPORT_RICONS
67- #include "raygui.h"
68- #define PHYSAC_IMPLEMENTATION
69- #include "physac.h"
70- """ ,
71- extra_link_args = ['/usr/local/lib/libraylib.a' , '-lm' , '-lpthread' , '-lGLU' , '-lGL' , '-lrt' ,
81+ ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
82+ extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-lm' , '-lpthread' , '-lGLU' , '-lGL' ,
83+ '-lrt' ,
7284 '-lm' , '-ldl' , '-lX11' , '-lpthread' ],
7385 libraries = ['GL' , 'm' , 'pthread' , 'dl' , 'rt' , 'X11' ],
7486 include_dirs = ['raylib' ]
@@ -82,15 +94,7 @@ def build_windows():
8294 ffibuilder .cdef (mangle ("raylib/raylib.h" ))
8395 ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ).replace ('bool' , 'int' ))
8496 ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ).replace ('bool' , 'int' ))
85- ffibuilder .set_source ("raylib._raylib_cffi" ,
86- """
87- #include "raylib.h"
88- #define RAYGUI_IMPLEMENTATION
89- #define RAYGUI_SUPPORT_RICONS
90- #include "raygui.h"
91- #define PHYSAC_IMPLEMENTATION
92- #include "physac.h"
93- """ ,
97+ ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
9498 extra_link_args = ['/NODEFAULTLIB:MSVCRTD' ],
9599 libraries = ['raylib' , 'gdi32' , 'shell32' , 'user32' , 'OpenGL32' , 'winmm' ],
96100 include_dirs = ['raylib' ],
@@ -101,19 +105,11 @@ def build_windows():
101105
102106def build_mac ():
103107 print ("BUILDING FOR MAC" )
104- ffibuilder .cdef (mangle ("/usr/local/include /raylib.h" ))
108+ ffibuilder .cdef (mangle (get_the_include_path () + " /raylib.h" ))
105109 ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
106110 ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
107- ffibuilder .set_source ("raylib._raylib_cffi" ,
108- """
109- #include "raylib.h"
110- #define RAYGUI_IMPLEMENTATION
111- #define RAYGUI_SUPPORT_RICONS
112- #include "raygui.h"
113- #define PHYSAC_IMPLEMENTATION
114- #include "physac.h"
115- """ ,
116- extra_link_args = ['/usr/local/lib/libraylib.a' , '-framework' , 'OpenGL' , '-framework' , 'Cocoa' ,
111+ ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
112+ extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-framework' , 'OpenGL' , '-framework' , 'Cocoa' ,
117113 '-framework' , 'IOKit' , '-framework' , 'CoreFoundation' , '-framework' ,
118114 'CoreVideo' ],
119115 include_dirs = ['raylib' ],
@@ -125,19 +121,11 @@ def build_mac():
125121
126122def build_rpi_nox ():
127123 print ("BUILDING FOR RASPBERRY PI" )
128- ffibuilder .cdef (mangle ("/usr/local/include /raylib.h" ))
124+ ffibuilder .cdef (mangle (get_the_include_path () + " /raylib.h" ))
129125 ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
130126 ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
131- ffibuilder .set_source ("raylib._raylib_cffi" ,
132- """
133- #include "raylib.h"
134- #define RAYGUI_IMPLEMENTATION
135- #define RAYGUI_SUPPORT_RICONS
136- #include "raygui.h"
137- #define PHYSAC_IMPLEMENTATION
138- #include "physac.h"
139- """ ,
140- extra_link_args = ['/usr/local/lib/libraylib.a' ,
127+ ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
128+ extra_link_args = [get_the_lib_path () + '/libraylib.a' ,
141129 '/opt/vc/lib/libEGL_static.a' , '/opt/vc/lib/libGLESv2_static.a' ,
142130 '-L/opt/vc/lib' , '-lvcos' , '-lbcm_host' , '-lbrcmEGL' , '-lbrcmGLESv2' ,
143131 '-lm' , '-lpthread' , '-lrt' ],
0 commit comments