15
15
# Assumes raylib, GL, etc are all already installed as system libraries. We dont distribute them.
16
16
# Raylib must be installed and compiled with: cmake -DWITH_PIC=ON -DSHARED=ON -DSTATIC=ON ..
17
17
18
- # We use /usr/local/lib/libraylib.a to ensure we link to static version
19
- import re
20
18
19
+ import re
21
20
from cffi import FFI
22
21
import os
23
22
import platform
24
- import sys
25
23
import subprocess
26
24
import time
27
25
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
+
28
40
RAYLIB_PLATFORM = os .getenv ("RAYLIB_PLATFORM" , "Desktop" )
29
41
30
- def check_raylib_installed ():
42
+ def check_raylib_pkgconfig_installed ():
31
43
return subprocess .run (['pkg-config' , '--exists' , 'raylib' ], text = True , stdout = subprocess .PIPE ).returncode == 0
32
44
33
- def check_SDL_installed ():
45
+ def check_sdl_pkgconfig_installed ():
34
46
return subprocess .run (['pkg-config' , '--exists' , 'sdl2' ], text = True , stdout = subprocess .PIPE ).returncode == 0
35
47
36
- def get_the_include_path ():
48
+ def get_the_include_path_from_pkgconfig ():
37
49
return subprocess .run (['pkg-config' , '--variable=includedir' , 'raylib' ], text = True ,
38
50
stdout = subprocess .PIPE ).stdout .strip ()
39
51
40
52
41
- def get_the_lib_path ():
53
+ def get_the_lib_path_from_pkgconfig ():
42
54
return subprocess .run (['pkg-config' , '--variable=libdir' , 'raylib' ], text = True ,
43
55
stdout = subprocess .PIPE ).stdout .strip ()
44
56
45
- def get_lib_flags ():
57
+ def get_lib_flags_from_pkgconfig ():
46
58
return subprocess .run (['pkg-config' , '--libs' , 'raylib' ], text = True ,
47
- stdout = subprocess .PIPE ).stdout .strip (). split ()
59
+ stdout = subprocess .PIPE ).stdout .strip ()
48
60
49
61
def pre_process_header (filename , remove_function_bodies = False ):
50
62
print ("Pre-processing " + filename )
@@ -104,46 +116,60 @@ def check_header_exists(file):
104
116
105
117
106
118
def 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." )
109
122
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." )
112
126
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"
116
133
117
134
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 ." )
119
136
120
137
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 ." )
122
139
123
140
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 ." )
125
142
126
143
ffi_includes = """
127
144
#include "raylib.h"
128
145
#include "rlgl.h"
129
146
#include "raymath.h"
130
147
"""
131
148
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"
133
153
if RAYLIB_PLATFORM == "Desktop" and check_header_exists (glfw3_h ):
134
154
ffi_includes += """
135
155
#include "GLFW/glfw3.h"
136
156
"""
137
157
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"
139
162
if check_header_exists (raygui_h ):
140
163
ffi_includes += """
141
164
#define RAYGUI_IMPLEMENTATION
142
165
#define RAYGUI_SUPPORT_RICONS
143
166
#include "raygui.h"
144
167
"""
145
168
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"
147
173
if check_header_exists (physac_h ):
148
174
ffi_includes += """
149
175
#define PHYSAC_IMPLEMENTATION
@@ -164,7 +190,11 @@ def build_unix():
164
190
165
191
if platform .system () == "Darwin" :
166
192
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' ,
168
198
'-framework' , 'IOKit' , '-framework' , 'CoreFoundation' , '-framework' ,
169
199
'CoreVideo' ]
170
200
if RAYLIB_PLATFORM == "SDL" :
@@ -174,12 +204,18 @@ def build_unix():
174
204
extra_compile_args = ["-Wno-error=incompatible-function-pointer-types" , "-D_CFFI_NO_LIMITED_API" ]
175
205
else : #platform.system() == "Linux":
176
206
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' ,
178
211
'-lrt' , '-lm' , '-ldl' , '-lpthread' , '-latomic' ]
179
212
if RAYLIB_PLATFORM == "SDL" :
180
213
extra_link_args += ['-lX11' ,'-lSDL2' ]
181
214
elif RAYLIB_PLATFORM == "DRM" :
182
215
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' ]
183
219
else :
184
220
extra_link_args += ['-lX11' ]
185
221
extra_compile_args = ["-Wno-incompatible-pointer-types" , "-D_CFFI_NO_LIMITED_API" ]
@@ -192,7 +228,7 @@ def build_unix():
192
228
ffibuilder .set_source ("raylib._raylib_cffi" ,
193
229
ffi_includes ,
194
230
py_limited_api = False ,
195
- include_dirs = [get_the_include_path ()],
231
+ include_dirs = [get_the_include_path_from_pkgconfig ()],
196
232
extra_link_args = extra_link_args ,
197
233
extra_compile_args = extra_compile_args ,
198
234
libraries = libraries )
0 commit comments