24
24
import subprocess
25
25
import time
26
26
27
- ffibuilder = FFI ()
27
+
28
+
28
29
29
30
def check_raylib_installed ():
30
31
return subprocess .run (['pkg-config' , '--exists' , 'raylib' ], text = True , stdout = subprocess .PIPE ).returncode == 0
31
32
33
+
32
34
def get_the_include_path ():
33
- return subprocess .run (['pkg-config' , '--variable=includedir' , 'raylib' ], text = True , stdout = subprocess .PIPE ).stdout .strip ()
35
+ return subprocess .run (['pkg-config' , '--variable=includedir' , 'raylib' ], text = True ,
36
+ stdout = subprocess .PIPE ).stdout .strip ()
34
37
35
38
36
39
def get_the_lib_path ():
37
- return subprocess .run (['pkg-config' , '--variable=libdir' , 'raylib' ], text = True , stdout = subprocess .PIPE ).stdout .strip ()
40
+ return subprocess .run (['pkg-config' , '--variable=libdir' , 'raylib' ], text = True ,
41
+ stdout = subprocess .PIPE ).stdout .strip ()
38
42
39
43
40
44
def pre_process_header (filename ):
41
- print ("Pre-processing " + filename )
45
+ print ("Pre-processing " + filename )
42
46
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=' ,
47
+ filetext = "" .join ([line for line in file if '#include' not in line ])
48
+ command = ['gcc' , '-CC' , '-P' , '-undef' , '-nostdinc' , '-DRLAPI=' , '-DPHYSACDEF=' , '-DRAYGUIDEF=' ,
45
49
'-dDI' , '-E' , '-' ]
46
50
filetext2 = subprocess .run (command , text = True , input = filetext , stdout = subprocess .PIPE ).stdout
47
51
filetext3 = filetext2 .replace ("va_list" , "void *" )
48
- filetext4 = "\n " .join ([ line for line in filetext3 .splitlines () if not line .startswith ("#" )])
49
- #print(r)
52
+ filetext4 = "\n " .join ([line for line in filetext3 .splitlines () if not line .startswith ("#" )])
53
+ # print(r)
50
54
return filetext4
51
55
56
+
52
57
def check_header_exists (file ):
53
58
if not os .path .isfile (file ):
54
59
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 " )
60
+ print (
61
+ 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
62
print ("**************************************\n \n " )
57
63
time .sleep (1 )
58
64
return False
59
65
return True
60
66
67
+
61
68
def mangle (string ):
62
69
return string
63
70
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
71
69
- if not os .path .isfile (raylib_h ):
70
- raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib." )
72
+ def build_unix ():
73
+ if not check_raylib_installed ():
74
+ raise Exception ("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib." )
71
75
76
+ raylib_h = get_the_include_path () + "/raylib.h"
72
77
78
+ if not os .path .isfile (raylib_h ):
79
+ raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib." )
73
80
74
-
75
- ffi_includes = """
76
- #include "raylib.h"
77
- """
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"
81
+ ffi_includes = """
82
+ #include "raylib.h"
93
83
"""
94
84
85
+ raygui_h = get_the_include_path () + "/raygui.h"
86
+ if check_header_exists (raygui_h ):
87
+ ffi_includes += """
88
+ #define RAYGUI_IMPLEMENTATION
89
+ #define RAYGUI_SUPPORT_RICONS
90
+ #include "raygui.h"
91
+ """
92
+
93
+ physac_h = get_the_include_path () + "/physac.h"
94
+ if check_header_exists (physac_h ):
95
+ ffi_includes += """
96
+ #define PHYSAC_IMPLEMENTATION
97
+ #include "physac.h"
98
+ """
95
99
96
-
97
-
98
-
99
-
100
-
101
- def build_linux ():
102
- print ("BUILDING FOR LINUX" )
103
100
ffibuilder .cdef (pre_process_header (raylib_h ))
104
101
if os .path .isfile (raygui_h ):
105
102
ffibuilder .cdef (pre_process_header (raygui_h ))
106
103
if os .path .isfile (physac_h ):
107
104
ffibuilder .cdef (pre_process_header (physac_h ))
108
- ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
109
- extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-lm' , '-lpthread' , '-lGLU' , '-lGL' ,
110
- '-lrt' ,
111
- '-lm' , '-ldl' , '-lX11' , '-lpthread' ],
112
- libraries = ['GL' , 'm' , 'pthread' , 'dl' , 'rt' , 'X11' ],
113
- include_dirs = ['raylib' ]
114
- )
115
- if __name__ == "__main__" :
116
- ffibuilder .compile (verbose = True )
105
+
106
+ if platform .system () == "Darwin" :
107
+ print ("BUILDING FOR MAC" )
108
+ extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-framework' , 'OpenGL' , '-framework' , 'Cocoa' ,
109
+ '-framework' , 'IOKit' , '-framework' , 'CoreFoundation' , '-framework' ,
110
+ 'CoreVideo' ]
111
+ libraries = []
112
+ elif platform .system () == "Linux" :
113
+ if "x86" in platform .machine ():
114
+ print ("BUILDING FOR LINUX" )
115
+ extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-lm' , '-lpthread' , '-lGLU' , '-lGL' ,
116
+ '-lrt' , '-lm' , '-ldl' , '-lX11' , '-lpthread' ]
117
+ libraries = ['GL' , 'm' , 'pthread' , 'dl' , 'rt' , 'X11' ]
118
+ elif "arm" in platform .machine ():
119
+ print ("BUILDING FOR RASPBERRY PI" )
120
+ extra_link_args = [get_the_lib_path () + '/libraylib.a' ,
121
+ '/opt/vc/lib/libEGL_static.a' , '/opt/vc/lib/libGLESv2_static.a' ,
122
+ '-L/opt/vc/lib' , '-lvcos' , '-lbcm_host' , '-lbrcmEGL' , '-lbrcmGLESv2' ,
123
+ '-lm' , '-lpthread' , '-lrt' ]
124
+ libraries = []
125
+
126
+ ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes , extra_link_args = extra_link_args ,
127
+ libraries = libraries ,
128
+ include_dirs = ['raylib' ])
117
129
118
130
119
131
def build_windows ():
120
132
print ("BUILDING FOR WINDOWS" )
121
133
ffibuilder .cdef (mangle ("raylib/raylib.h" ))
122
134
ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
123
135
ffibuilder .cdef (open ("raylib/physac_modified.h" ).read ().replace ('PHYSACDEF ' , '' ))
124
- ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
136
+ ffibuilder .set_source ("raylib._raylib_cffi" , """
137
+ #include "raylib.h"
138
+ #define RAYGUI_IMPLEMENTATION
139
+ #define RAYGUI_SUPPORT_RICONS
140
+ #include "raygui.h"
141
+ #define PHYSAC_IMPLEMENTATION
142
+ #include "physac.h"
143
+ """ ,
125
144
extra_link_args = ['/NODEFAULTLIB:MSVCRTD' ],
126
145
libraries = ['raylib' , 'gdi32' , 'shell32' , 'user32' , 'OpenGL32' , 'winmm' ],
127
146
include_dirs = ['raylib' ],
128
147
)
129
- if __name__ == "__main__" :
130
- ffibuilder .compile (verbose = True )
131
-
132
-
133
- def build_mac ():
134
- print ("BUILDING FOR MAC" )
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 ))
140
- ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
141
- extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-framework' , 'OpenGL' , '-framework' , 'Cocoa' ,
142
- '-framework' , 'IOKit' , '-framework' , 'CoreFoundation' , '-framework' ,
143
- 'CoreVideo' ],
144
- include_dirs = ['raylib' ],
145
- )
146
-
147
- if __name__ == "__main__" :
148
- ffibuilder .compile (verbose = True )
149
148
150
149
151
- def build_rpi_nox ():
152
- print ("BUILDING FOR RASPBERRY PI" )
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 ))
158
- ffibuilder .set_source ("raylib._raylib_cffi" , ffi_includes ,
159
- extra_link_args = [get_the_lib_path () + '/libraylib.a' ,
160
- '/opt/vc/lib/libEGL_static.a' , '/opt/vc/lib/libGLESv2_static.a' ,
161
- '-L/opt/vc/lib' , '-lvcos' , '-lbcm_host' , '-lbrcmEGL' , '-lbrcmGLESv2' ,
162
- '-lm' , '-lpthread' , '-lrt' ],
163
- include_dirs = ['raylib' ],
164
- )
165
-
166
- if __name__ == "__main__" :
167
- ffibuilder .compile (verbose = True )
168
-
150
+ ffibuilder = FFI ()
169
151
170
- if platform .system () == "Darwin" :
171
- build_mac ()
172
- elif platform .system () == "Linux" :
173
- if "x86" in platform .machine ():
174
- build_linux ()
175
- elif "arm" in platform .machine ():
176
- build_rpi_nox ()
177
- elif platform .system () == "Windows" :
152
+ if platform .system () == "Windows" :
178
153
build_windows ()
179
154
else :
180
- print ("WARNING: UKKNOWN PLATFORM - trying Linux build" )
181
- build_linux ()
155
+ print ("not windows, trying Unix build" )
156
+ build_unix ()
157
+
158
+
159
+ if __name__ == "__main__" :
160
+ ffibuilder .compile (verbose = True )
0 commit comments