21
21
import os
22
22
import platform
23
23
import sys
24
+ import subprocess
24
25
25
26
ffibuilder = FFI ()
26
27
27
28
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
+
28
49
def mangle (file ):
29
50
result = ""
30
51
skip = False
@@ -39,8 +60,6 @@ def mangle(file):
39
60
continue
40
61
if line .startswith ("#endif // RAYGUI_H" ):
41
62
break
42
- if line .__contains__ ("GetTouchEvent" ):
43
- continue
44
63
if line .startswith ("#" ):
45
64
continue
46
65
if line .startswith ("RLAPI" ):
@@ -56,19 +75,12 @@ def mangle(file):
56
75
57
76
def build_linux ():
58
77
print ("BUILDING FOR LINUX" )
59
- ffibuilder .cdef (mangle ("/usr/local/include /raylib.h" ))
78
+ ffibuilder .cdef (mangle (get_the_include_path () + " /raylib.h" ))
60
79
ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
61
80
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' ,
72
84
'-lm' , '-ldl' , '-lX11' , '-lpthread' ],
73
85
libraries = ['GL' , 'm' , 'pthread' , 'dl' , 'rt' , 'X11' ],
74
86
include_dirs = ['raylib' ]
@@ -82,15 +94,7 @@ def build_windows():
82
94
ffibuilder .cdef (mangle ("raylib/raylib.h" ))
83
95
ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ).replace ('bool' , 'int' ))
84
96
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 ,
94
98
extra_link_args = ['/NODEFAULTLIB:MSVCRTD' ],
95
99
libraries = ['raylib' , 'gdi32' , 'shell32' , 'user32' , 'OpenGL32' , 'winmm' ],
96
100
include_dirs = ['raylib' ],
@@ -101,19 +105,11 @@ def build_windows():
101
105
102
106
def build_mac ():
103
107
print ("BUILDING FOR MAC" )
104
- ffibuilder .cdef (mangle ("/usr/local/include /raylib.h" ))
108
+ ffibuilder .cdef (mangle (get_the_include_path () + " /raylib.h" ))
105
109
ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
106
110
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' ,
117
113
'-framework' , 'IOKit' , '-framework' , 'CoreFoundation' , '-framework' ,
118
114
'CoreVideo' ],
119
115
include_dirs = ['raylib' ],
@@ -125,19 +121,11 @@ def build_mac():
125
121
126
122
def build_rpi_nox ():
127
123
print ("BUILDING FOR RASPBERRY PI" )
128
- ffibuilder .cdef (mangle ("/usr/local/include /raylib.h" ))
124
+ ffibuilder .cdef (mangle (get_the_include_path () + " /raylib.h" ))
129
125
ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
130
126
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' ,
141
129
'/opt/vc/lib/libEGL_static.a' , '/opt/vc/lib/libGLESv2_static.a' ,
142
130
'-L/opt/vc/lib' , '-lvcos' , '-lbcm_host' , '-lbrcmEGL' , '-lbrcmGLESv2' ,
143
131
'-lm' , '-lpthread' , '-lrt' ],
0 commit comments