2424import subprocess
2525import time
2626
27- ffibuilder = FFI ()
27+
28+
2829
2930def check_raylib_installed ():
3031 return subprocess .run (['pkg-config' , '--exists' , 'raylib' ], text = True , stdout = subprocess .PIPE ).returncode == 0
3132
33+
3234def 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 ()
3437
3538
3639def 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 ()
3842
3943
4044def pre_process_header (filename ):
41- print ("Pre-processing " + filename )
45+ print ("Pre-processing " + filename )
4246 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=' ,
4549 '-dDI' , '-E' , '-' ]
4650 filetext2 = subprocess .run (command , text = True , input = filetext , stdout = subprocess .PIPE ).stdout
4751 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)
5054 return filetext4
5155
56+
5257def check_header_exists (file ):
5358 if not os .path .isfile (file ):
5459 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 " )
5662 print ("**************************************\n \n " )
5763 time .sleep (1 )
5864 return False
5965 return True
6066
67+
6168def mangle (string ):
6269 return string
6370
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"
6871
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." )
7175
76+ raylib_h = get_the_include_path () + "/raylib.h"
7277
78+ if not os .path .isfile (raylib_h ):
79+ raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib." )
7380
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"
9383 """
9484
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+ """
9599
96-
97-
98-
99-
100-
101- def build_linux ():
102- print ("BUILDING FOR LINUX" )
103100 ffibuilder .cdef (pre_process_header (raylib_h ))
104101 if os .path .isfile (raygui_h ):
105102 ffibuilder .cdef (pre_process_header (raygui_h ))
106103 if os .path .isfile (physac_h ):
107104 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' ])
117129
118130
119131def build_windows ():
120132 print ("BUILDING FOR WINDOWS" )
121133 ffibuilder .cdef (mangle ("raylib/raylib.h" ))
122134 ffibuilder .cdef (open ("raylib/raygui_modified.h" ).read ().replace ('RAYGUIDEF ' , '' ))
123135 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+ """ ,
125144 extra_link_args = ['/NODEFAULTLIB:MSVCRTD' ],
126145 libraries = ['raylib' , 'gdi32' , 'shell32' , 'user32' , 'OpenGL32' , 'winmm' ],
127146 include_dirs = ['raylib' ],
128147 )
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 )
149148
150149
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 ()
169151
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" :
178153 build_windows ()
179154else :
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