22
22
import platform
23
23
import sys
24
24
import subprocess
25
+ import time
25
26
26
27
ffibuilder = FFI ()
27
28
29
+ def check_raylib_installed ():
30
+ return subprocess .run (['pkg-config' , '--exists' , 'raylib' ], text = True , stdout = subprocess .PIPE ).returncode == 0
28
31
29
32
def get_the_include_path ():
30
- return subprocess .run (['pkg-config' , '--variable=includedir' , 'raylib' ], stdout = subprocess .PIPE ).stdout .decode (
31
- 'utf-8' ).strip ()
33
+ return subprocess .run (['pkg-config' , '--variable=includedir' , 'raylib' ], text = True , stdout = subprocess .PIPE ).stdout .strip ()
32
34
33
35
34
36
def get_the_lib_path ():
35
- return subprocess .run (['pkg-config' , '--variable=libdir' , 'raylib' ], stdout = subprocess .PIPE ).stdout .decode (
36
- 'utf-8' ).strip ()
37
+ return subprocess .run (['pkg-config' , '--variable=libdir' , 'raylib' ], text = True , stdout = subprocess .PIPE ).stdout .strip ()
38
+
39
+
40
+ def pre_process_header (filename ):
41
+ print ("Pre-processing " + filename )
42
+ file = open (filename , "r" )
43
+ filetext = "" .join ([ line for line in file if '#include' not in line ])
44
+ command = ['gcc' , '-CC' , '-P' ,'-undef' , '-nostdinc' , '-DRLAPI=' , '-DPHYSACDEF=' , '-DRAYGUIDEF=' ,
45
+ '-dDI' , '-E' , '-' ]
46
+ filetext2 = subprocess .run (command , text = True , input = filetext , stdout = subprocess .PIPE ).stdout
47
+ filetext3 = filetext2 .replace ("va_list" , "void *" )
48
+ filetext4 = "\n " .join ([ line for line in filetext3 .splitlines () if not line .startswith ("#" )])
49
+ #print(r)
50
+ return filetext4
51
+
52
+ def check_header_exists (file ):
53
+ if not os .path .isfile (file ):
54
+ print ("\n \n *************** WARNING ***************\n \n " )
55
+ print (file + " not found. Build will not contain these extra functions.\n \n Please copy file from src/extras to " + file + " if you want them.\n \n " )
56
+ print ("**************************************\n \n " )
57
+ time .sleep (1 )
58
+ return False
59
+ return True
60
+
61
+ def mangle (string ):
62
+ return string
63
+
64
+ if not check_raylib_installed ():
65
+ raise Exception ("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib." )
66
+
67
+ raylib_h = get_the_include_path () + "/raylib.h"
68
+
69
+ if not os .path .isfile (raylib_h ):
70
+ raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib." )
71
+
72
+
37
73
38
74
39
75
ffi_includes = """
40
76
#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
77
"""
47
78
79
+ raygui_h = get_the_include_path () + "/raygui.h"
80
+ if check_header_exists (raygui_h ):
81
+ ffi_includes += """
82
+ #define RAYGUI_IMPLEMENTATION
83
+ #define RAYGUI_SUPPORT_RICONS
84
+ #include "raygui.h"
85
+ """
86
+
87
+
88
+ physac_h = get_the_include_path () + "/physac.h"
89
+ if check_header_exists (physac_h ):
90
+ ffi_includes += """
91
+ #define PHYSAC_IMPLEMENTATION
92
+ #include "physac.h"
93
+ """
94
+
95
+
96
+
97
+
48
98
49
- def mangle (file ):
50
- result = ""
51
- skip = False
52
- for line in open (file ):
53
- line = line .strip ().replace ("va_list" , "void *" ) + "\n "
54
- if skip :
55
- if line .startswith ("#endif" ):
56
- skip = False
57
- continue
58
- if line .startswith ("#if defined(__cplusplus)" ):
59
- skip = True
60
- continue
61
- if line .startswith ("#endif // RAYGUI_H" ):
62
- break
63
- if line .startswith ("#" ):
64
- continue
65
- if line .startswith ("RLAPI" ):
66
- line = line .replace ('RLAPI ' , '' )
67
- if line .startswith ("RAYGUIDEF" ):
68
- line = line .replace ('RAYGUIDEF ' , '' )
69
- if line .startswith ("PHYSACDEF" ):
70
- line = line .replace ('PHYSACDEF ' , '' )
71
- result += line
72
- # print(line)
73
- return result
74
99
75
100
76
101
def build_linux ():
77
102
print ("BUILDING FOR LINUX" )
78
- ffibuilder .cdef (mangle (get_the_include_path () + "/raylib.h" ))
79
- ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
80
- ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
103
+ ffibuilder .cdef (pre_process_header (raylib_h ))
104
+ if os .path .isfile (raygui_h ):
105
+ ffibuilder .cdef (pre_process_header (raygui_h ))
106
+ if os .path .isfile (physac_h ):
107
+ ffibuilder .cdef (pre_process_header (physac_h ))
81
108
ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
82
109
extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-lm' , '-lpthread' , '-lGLU' , '-lGL' ,
83
110
'-lrt' ,
@@ -92,8 +119,8 @@ def build_linux():
92
119
def build_windows ():
93
120
print ("BUILDING FOR WINDOWS" )
94
121
ffibuilder .cdef (mangle ("raylib/raylib.h" ))
95
- ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ). replace ( 'bool' , 'int' ) )
96
- ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ). replace ( 'bool' , 'int' ) )
122
+ ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
123
+ ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
97
124
ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
98
125
extra_link_args = ['/NODEFAULTLIB:MSVCRTD' ],
99
126
libraries = ['raylib' , 'gdi32' , 'shell32' , 'user32' , 'OpenGL32' , 'winmm' ],
@@ -105,9 +132,11 @@ def build_windows():
105
132
106
133
def build_mac ():
107
134
print ("BUILDING FOR MAC" )
108
- ffibuilder .cdef (mangle (get_the_include_path () + "/raylib.h" ))
109
- ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
110
- ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
135
+ ffibuilder .cdef (pre_process_header (raylib_h ))
136
+ if os .path .isfile (raygui_h ):
137
+ ffibuilder .cdef (pre_process_header (raygui_h ))
138
+ if os .path .isfile (physac_h ):
139
+ ffibuilder .cdef (pre_process_header (physac_h ))
111
140
ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
112
141
extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-framework' , 'OpenGL' , '-framework' , 'Cocoa' ,
113
142
'-framework' , 'IOKit' , '-framework' , 'CoreFoundation' , '-framework' ,
@@ -121,9 +150,11 @@ def build_mac():
121
150
122
151
def build_rpi_nox ():
123
152
print ("BUILDING FOR RASPBERRY PI" )
124
- ffibuilder .cdef (mangle (get_the_include_path () + "/raylib.h" ))
125
- ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
126
- ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
153
+ ffibuilder .cdef (pre_process_header (raylib_h ))
154
+ if os .path .isfile (raygui_h ):
155
+ ffibuilder .cdef (pre_process_header (raygui_h ))
156
+ if os .path .isfile (physac_h ):
157
+ ffibuilder .cdef (pre_process_header (physac_h ))
127
158
ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
128
159
extra_link_args = [get_the_lib_path () + '/libraylib.a' ,
129
160
'/opt/vc/lib/libEGL_static.a' , '/opt/vc/lib/libGLESv2_static.a' ,
0 commit comments