1515# Assumes raylib, GL, etc are all already installed as system libraries. We dont distribute them.
1616# Raylib must be installed and compiled with: cmake -DWITH_PIC=ON -DSHARED=ON -DSTATIC=ON ..
1717
18- # We use /usr/local/lib/libraylib.a to ensure we link to static version
19- import re
2018
19+ import re
2120from cffi import FFI
2221import os
2322import platform
24- import sys
2523import subprocess
2624import time
2725
26+ # Environment variables you can set before build
27+ #
28+ # RAYLIB_PLATFORM: Any one of: Desktop, SDL, DRM, PLATFORM_COMMA
29+ # RAYLIB_LINK_ARGS: Arguments to pass to the linker rather than getting them from pkg-config.
30+ # e.g.: -L/usr/local/lib -lraylib
31+ # RAYLIB_INCLUDE_PATH: Directory to find raylib.h rather than getting from pkg-config.
32+ # e.g.: /usr/local/include
33+ # RAYGUI_INCLUDE_PATH: Directory to find raygui.h
34+ # e.g.: /usr/local/include
35+ # GLFW_INCLUDE_PATH: Directory to find glfw3.h
36+ # e.g.: /usr/local/include/GLFW
37+ # PHYSAC_INCLUDE_PATH: Directory to find physac.h
38+ # e.g.: /usr/local/include
39+
2840RAYLIB_PLATFORM = os .getenv ("RAYLIB_PLATFORM" , "Desktop" )
2941
30- def check_raylib_installed ():
42+ def check_raylib_pkgconfig_installed ():
3143 return subprocess .run (['pkg-config' , '--exists' , 'raylib' ], text = True , stdout = subprocess .PIPE ).returncode == 0
3244
33- def check_SDL_installed ():
45+ def check_sdl_pkgconfig_installed ():
3446 return subprocess .run (['pkg-config' , '--exists' , 'sdl2' ], text = True , stdout = subprocess .PIPE ).returncode == 0
3547
36- def get_the_include_path ():
48+ def get_the_include_path_from_pkgconfig ():
3749 return subprocess .run (['pkg-config' , '--variable=includedir' , 'raylib' ], text = True ,
3850 stdout = subprocess .PIPE ).stdout .strip ()
3951
4052
41- def get_the_lib_path ():
53+ def get_the_lib_path_from_pkgconfig ():
4254 return subprocess .run (['pkg-config' , '--variable=libdir' , 'raylib' ], text = True ,
4355 stdout = subprocess .PIPE ).stdout .strip ()
4456
45- def get_lib_flags ():
57+ def get_lib_flags_from_pkgconfig ():
4658 return subprocess .run (['pkg-config' , '--libs' , 'raylib' ], text = True ,
47- stdout = subprocess .PIPE ).stdout .strip (). split ()
59+ stdout = subprocess .PIPE ).stdout .strip ()
4860
4961def pre_process_header (filename , remove_function_bodies = False ):
5062 print ("Pre-processing " + filename )
@@ -104,46 +116,60 @@ def check_header_exists(file):
104116
105117
106118def build_unix ():
107- if not check_raylib_installed ():
108- raise Exception ("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib." )
119+ if os .getenv ("RAYLIB_LINK_ARGS" ) is None and not check_raylib_pkgconfig_installed ():
120+ raise Exception ("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib"
121+ "or else set RAYLIB_LINK_ARGS env variable." )
109122
110- if RAYLIB_PLATFORM == "SDL" and not check_SDL_installed ():
111- raise Exception ("ERROR: SDL2 not found by pkg-config. Please install pkg-config and SDL2." )
123+ if RAYLIB_PLATFORM == "SDL" and os .getenv ("RAYLIB_LINK_ARGS" ) is None and not check_sdl_pkgconfig_installed ():
124+ raise Exception ("ERROR: SDL2 not found by pkg-config. Please install pkg-config and SDL2."
125+ "or else set RAYLIB_LINK_ARGS env variable." )
112126
113- raylib_h = get_the_include_path () + "/raylib.h"
114- rlgl_h = get_the_include_path () + "/rlgl.h"
115- raymath_h = get_the_include_path () + "/raymath.h"
127+ raylib_include_path = os .getenv ("RAYLIB_INCLUDE_PATH" )
128+ if raylib_include_path is None :
129+ raylib_include_path = get_the_include_path_from_pkgconfig ()
130+ raylib_h = raylib_include_path + "/raylib.h"
131+ rlgl_h = raylib_include_path + "/rlgl.h"
132+ raymath_h = raylib_include_path + "/raymath.h"
116133
117134 if not os .path .isfile (raylib_h ):
118- raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib." )
135+ raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib or set RAYLIB_INCLUDE_PATH ." )
119136
120137 if not os .path .isfile (rlgl_h ):
121- raise Exception ("ERROR: " + rlgl_h + " not found. Please install Raylib." )
138+ raise Exception ("ERROR: " + rlgl_h + " not found. Please install Raylib or set RAYLIB_INCLUDE_PATH ." )
122139
123140 if not os .path .isfile (raymath_h ):
124- raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib." )
141+ raise Exception ("ERROR: " + raylib_h + " not found. Please install Raylib or set RAYLIB_INCLUDE_PATH ." )
125142
126143 ffi_includes = """
127144 #include "raylib.h"
128145 #include "rlgl.h"
129146 #include "raymath.h"
130147 """
131148
132- glfw3_h = get_the_include_path () + "/GLFW/glfw3.h"
149+ glfw_include_path = os .getenv ("GLFW_INCLUDE_PATH" )
150+ if glfw_include_path is None :
151+ glfw_include_path = get_the_include_path_from_pkgconfig ()
152+ glfw3_h = glfw_include_path + "/GLFW/glfw3.h"
133153 if RAYLIB_PLATFORM == "Desktop" and check_header_exists (glfw3_h ):
134154 ffi_includes += """
135155 #include "GLFW/glfw3.h"
136156 """
137157
138- raygui_h = get_the_include_path () + "/raygui.h"
158+ raygui_include_path = os .getenv ("RAYGUI_INCLUDE_PATH" )
159+ if raygui_include_path is None :
160+ raygui_include_path = get_the_include_path_from_pkgconfig ()
161+ raygui_h = raygui_include_path + "/raygui.h"
139162 if check_header_exists (raygui_h ):
140163 ffi_includes += """
141164 #define RAYGUI_IMPLEMENTATION
142165 #define RAYGUI_SUPPORT_RICONS
143166 #include "raygui.h"
144167 """
145168
146- physac_h = get_the_include_path () + "/physac.h"
169+ physac_include_path = os .getenv ("PHYSAC_INCLUDE_PATH" )
170+ if physac_include_path is None :
171+ physac_include_path = get_the_include_path_from_pkgconfig ()
172+ physac_h = physac_include_path + "/physac.h"
147173 if check_header_exists (physac_h ):
148174 ffi_includes += """
149175 #define PHYSAC_IMPLEMENTATION
@@ -164,7 +190,11 @@ def build_unix():
164190
165191 if platform .system () == "Darwin" :
166192 print ("BUILDING FOR MAC" )
167- extra_link_args = [get_the_lib_path () + '/libraylib.a' , '-framework' , 'OpenGL' , '-framework' , 'Cocoa' ,
193+ flags = os .getenv ("RAYLIB_LINK_ARGS" )
194+ if flags is None :
195+ flags = get_the_lib_path_from_pkgconfig () + '/libraylib.a'
196+ # We use /usr/local/lib/libraylib.a to ensure we link to static version
197+ extra_link_args = flags .split () + ['-framework' , 'OpenGL' , '-framework' , 'Cocoa' ,
168198 '-framework' , 'IOKit' , '-framework' , 'CoreFoundation' , '-framework' ,
169199 'CoreVideo' ]
170200 if RAYLIB_PLATFORM == "SDL" :
@@ -174,12 +204,18 @@ def build_unix():
174204 extra_compile_args = ["-Wno-error=incompatible-function-pointer-types" , "-D_CFFI_NO_LIMITED_API" ]
175205 else : #platform.system() == "Linux":
176206 print ("BUILDING FOR LINUX" )
177- extra_link_args = get_lib_flags () + [ '-lm' , '-lpthread' , '-lGL' ,
207+ flags = os .getenv ("RAYLIB_LINK_ARGS" )
208+ if flags is None :
209+ flags = get_lib_flags_from_pkgconfig ()
210+ extra_link_args = flags .split () + [ '-lm' , '-lpthread' , '-lGL' ,
178211 '-lrt' , '-lm' , '-ldl' , '-lpthread' , '-latomic' ]
179212 if RAYLIB_PLATFORM == "SDL" :
180213 extra_link_args += ['-lX11' ,'-lSDL2' ]
181214 elif RAYLIB_PLATFORM == "DRM" :
182215 extra_link_args += ['-lEGL' , '-lgbm' ]
216+ elif RAYLIB_PLATFORM == "PLATFORM_COMMA" :
217+ extra_link_args .remove ('-lGL' )
218+ extra_link_args += ['-lGLESv2' , '-lEGL' , '-lwayland-client' , '-lwayland-egl' ]
183219 else :
184220 extra_link_args += ['-lX11' ]
185221 extra_compile_args = ["-Wno-incompatible-pointer-types" , "-D_CFFI_NO_LIMITED_API" ]
@@ -192,7 +228,7 @@ def build_unix():
192228 ffibuilder .set_source ("raylib._raylib_cffi" ,
193229 ffi_includes ,
194230 py_limited_api = False ,
195- include_dirs = [get_the_include_path ()],
231+ include_dirs = [get_the_include_path_from_pkgconfig ()],
196232 extra_link_args = extra_link_args ,
197233 extra_compile_args = extra_compile_args ,
198234 libraries = libraries )
0 commit comments