separate win build from all unix platforms
This commit is contained in:
parent
cc9ba3e219
commit
9e0a28d5f6
1 changed files with 77 additions and 98 deletions
159
raylib/build.py
159
raylib/build.py
|
@ -24,96 +24,108 @@ import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
ffibuilder = FFI()
|
|
||||||
|
|
||||||
|
|
||||||
def check_raylib_installed():
|
def check_raylib_installed():
|
||||||
return subprocess.run(['pkg-config', '--exists', 'raylib'], text=True, stdout=subprocess.PIPE).returncode == 0
|
return subprocess.run(['pkg-config', '--exists', 'raylib'], text=True, stdout=subprocess.PIPE).returncode == 0
|
||||||
|
|
||||||
|
|
||||||
def get_the_include_path():
|
def get_the_include_path():
|
||||||
return subprocess.run(['pkg-config', '--variable=includedir', 'raylib'], text=True, stdout=subprocess.PIPE).stdout.strip()
|
return subprocess.run(['pkg-config', '--variable=includedir', 'raylib'], text=True,
|
||||||
|
stdout=subprocess.PIPE).stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
def get_the_lib_path():
|
def get_the_lib_path():
|
||||||
return subprocess.run(['pkg-config', '--variable=libdir', 'raylib'], text=True, stdout=subprocess.PIPE).stdout.strip()
|
return subprocess.run(['pkg-config', '--variable=libdir', 'raylib'], text=True,
|
||||||
|
stdout=subprocess.PIPE).stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
def pre_process_header(filename):
|
def pre_process_header(filename):
|
||||||
print("Pre-processing "+filename)
|
print("Pre-processing " + filename)
|
||||||
file = open(filename, "r")
|
file = open(filename, "r")
|
||||||
filetext = "".join([ line for line in file if '#include' not in line])
|
filetext = "".join([line for line in file if '#include' not in line])
|
||||||
command =['gcc', '-CC', '-P' ,'-undef', '-nostdinc', '-DRLAPI=', '-DPHYSACDEF=', '-DRAYGUIDEF=',
|
command = ['gcc', '-CC', '-P', '-undef', '-nostdinc', '-DRLAPI=', '-DPHYSACDEF=', '-DRAYGUIDEF=',
|
||||||
'-dDI', '-E', '-']
|
'-dDI', '-E', '-']
|
||||||
filetext2 = subprocess.run(command, text=True, input=filetext, stdout=subprocess.PIPE).stdout
|
filetext2 = subprocess.run(command, text=True, input=filetext, stdout=subprocess.PIPE).stdout
|
||||||
filetext3 = filetext2.replace("va_list", "void *")
|
filetext3 = filetext2.replace("va_list", "void *")
|
||||||
filetext4 = "\n".join([ line for line in filetext3.splitlines() if not line.startswith("#")])
|
filetext4 = "\n".join([line for line in filetext3.splitlines() if not line.startswith("#")])
|
||||||
#print(r)
|
# print(r)
|
||||||
return filetext4
|
return filetext4
|
||||||
|
|
||||||
|
|
||||||
def check_header_exists(file):
|
def check_header_exists(file):
|
||||||
if not os.path.isfile(file):
|
if not os.path.isfile(file):
|
||||||
print("\n\n*************** WARNING ***************\n\n")
|
print("\n\n*************** WARNING ***************\n\n")
|
||||||
print(file+" not found. Build will not contain these extra functions.\n\nPlease copy file from src/extras to "+file+" if you want them.\n\n")
|
print(
|
||||||
|
file + " not found. Build will not contain these extra functions.\n\nPlease copy file from src/extras to " + file + " if you want them.\n\n")
|
||||||
print("**************************************\n\n")
|
print("**************************************\n\n")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def mangle(string):
|
def mangle(string):
|
||||||
return string
|
return string
|
||||||
|
|
||||||
if not check_raylib_installed():
|
|
||||||
|
def build_unix():
|
||||||
|
if not check_raylib_installed():
|
||||||
raise Exception("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib.")
|
raise Exception("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib.")
|
||||||
|
|
||||||
raylib_h = get_the_include_path() + "/raylib.h"
|
raylib_h = get_the_include_path() + "/raylib.h"
|
||||||
|
|
||||||
if not os.path.isfile(raylib_h):
|
if not os.path.isfile(raylib_h):
|
||||||
raise Exception("ERROR: "+raylib_h+" not found. Please install Raylib.")
|
raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib.")
|
||||||
|
|
||||||
|
ffi_includes = """
|
||||||
|
#include "raylib.h"
|
||||||
|
"""
|
||||||
|
|
||||||
|
raygui_h = get_the_include_path() + "/raygui.h"
|
||||||
|
if check_header_exists(raygui_h):
|
||||||
ffi_includes = """
|
|
||||||
#include "raylib.h"
|
|
||||||
"""
|
|
||||||
|
|
||||||
raygui_h = get_the_include_path() + "/raygui.h"
|
|
||||||
if check_header_exists(raygui_h):
|
|
||||||
ffi_includes += """
|
ffi_includes += """
|
||||||
#define RAYGUI_IMPLEMENTATION
|
#define RAYGUI_IMPLEMENTATION
|
||||||
#define RAYGUI_SUPPORT_RICONS
|
#define RAYGUI_SUPPORT_RICONS
|
||||||
#include "raygui.h"
|
#include "raygui.h"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
physac_h = get_the_include_path() + "/physac.h"
|
||||||
physac_h = get_the_include_path() + "/physac.h"
|
if check_header_exists(physac_h):
|
||||||
if check_header_exists(physac_h):
|
|
||||||
ffi_includes += """
|
ffi_includes += """
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "physac.h"
|
#include "physac.h"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_linux():
|
|
||||||
print("BUILDING FOR LINUX")
|
|
||||||
ffibuilder.cdef(pre_process_header(raylib_h))
|
ffibuilder.cdef(pre_process_header(raylib_h))
|
||||||
if os.path.isfile(raygui_h):
|
if os.path.isfile(raygui_h):
|
||||||
ffibuilder.cdef(pre_process_header(raygui_h))
|
ffibuilder.cdef(pre_process_header(raygui_h))
|
||||||
if os.path.isfile(physac_h):
|
if os.path.isfile(physac_h):
|
||||||
ffibuilder.cdef(pre_process_header(physac_h))
|
ffibuilder.cdef(pre_process_header(physac_h))
|
||||||
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
|
||||||
extra_link_args=[get_the_lib_path() + '/libraylib.a', '-lm', '-lpthread', '-lGLU', '-lGL',
|
if platform.system() == "Darwin":
|
||||||
'-lrt',
|
print("BUILDING FOR MAC")
|
||||||
'-lm', '-ldl', '-lX11', '-lpthread'],
|
extra_link_args = [get_the_lib_path() + '/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa',
|
||||||
libraries=['GL', 'm', 'pthread', 'dl', 'rt', 'X11'],
|
'-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework',
|
||||||
include_dirs=['raylib']
|
'CoreVideo']
|
||||||
)
|
libraries = []
|
||||||
if __name__ == "__main__":
|
elif platform.system() == "Linux":
|
||||||
ffibuilder.compile(verbose=True)
|
if "x86" in platform.machine():
|
||||||
|
print("BUILDING FOR LINUX")
|
||||||
|
extra_link_args = [get_the_lib_path() + '/libraylib.a', '-lm', '-lpthread', '-lGLU', '-lGL',
|
||||||
|
'-lrt', '-lm', '-ldl', '-lX11', '-lpthread']
|
||||||
|
libraries = ['GL', 'm', 'pthread', 'dl', 'rt', 'X11']
|
||||||
|
elif "arm" in platform.machine():
|
||||||
|
print("BUILDING FOR RASPBERRY PI")
|
||||||
|
extra_link_args = [get_the_lib_path() + '/libraylib.a',
|
||||||
|
'/opt/vc/lib/libEGL_static.a', '/opt/vc/lib/libGLESv2_static.a',
|
||||||
|
'-L/opt/vc/lib', '-lvcos', '-lbcm_host', '-lbrcmEGL', '-lbrcmGLESv2',
|
||||||
|
'-lm', '-lpthread', '-lrt']
|
||||||
|
libraries = []
|
||||||
|
|
||||||
|
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes, extra_link_args=extra_link_args,
|
||||||
|
libraries=libraries,
|
||||||
|
include_dirs=['raylib'])
|
||||||
|
|
||||||
|
|
||||||
def build_windows():
|
def build_windows():
|
||||||
|
@ -121,61 +133,28 @@ def build_windows():
|
||||||
ffibuilder.cdef(mangle("raylib/raylib.h"))
|
ffibuilder.cdef(mangle("raylib/raylib.h"))
|
||||||
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
|
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
|
||||||
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
|
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
|
||||||
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
ffibuilder.set_source("raylib._raylib_cffi", """
|
||||||
|
#include "raylib.h"
|
||||||
|
#define RAYGUI_IMPLEMENTATION
|
||||||
|
#define RAYGUI_SUPPORT_RICONS
|
||||||
|
#include "raygui.h"
|
||||||
|
#define PHYSAC_IMPLEMENTATION
|
||||||
|
#include "physac.h"
|
||||||
|
""",
|
||||||
extra_link_args=['/NODEFAULTLIB:MSVCRTD'],
|
extra_link_args=['/NODEFAULTLIB:MSVCRTD'],
|
||||||
libraries=['raylib', 'gdi32', 'shell32', 'user32', 'OpenGL32', 'winmm'],
|
libraries=['raylib', 'gdi32', 'shell32', 'user32', 'OpenGL32', 'winmm'],
|
||||||
include_dirs=['raylib'],
|
include_dirs=['raylib'],
|
||||||
)
|
)
|
||||||
if __name__ == "__main__":
|
|
||||||
ffibuilder.compile(verbose=True)
|
|
||||||
|
|
||||||
|
|
||||||
def build_mac():
|
ffibuilder = FFI()
|
||||||
print("BUILDING FOR MAC")
|
|
||||||
ffibuilder.cdef(pre_process_header(raylib_h))
|
|
||||||
if os.path.isfile(raygui_h):
|
|
||||||
ffibuilder.cdef(pre_process_header(raygui_h))
|
|
||||||
if os.path.isfile(physac_h):
|
|
||||||
ffibuilder.cdef(pre_process_header(physac_h))
|
|
||||||
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
|
||||||
extra_link_args=[get_the_lib_path() + '/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa',
|
|
||||||
'-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework',
|
|
||||||
'CoreVideo'],
|
|
||||||
include_dirs=['raylib'],
|
|
||||||
)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if platform.system() == "Windows":
|
||||||
ffibuilder.compile(verbose=True)
|
|
||||||
|
|
||||||
|
|
||||||
def build_rpi_nox():
|
|
||||||
print("BUILDING FOR RASPBERRY PI")
|
|
||||||
ffibuilder.cdef(pre_process_header(raylib_h))
|
|
||||||
if os.path.isfile(raygui_h):
|
|
||||||
ffibuilder.cdef(pre_process_header(raygui_h))
|
|
||||||
if os.path.isfile(physac_h):
|
|
||||||
ffibuilder.cdef(pre_process_header(physac_h))
|
|
||||||
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
|
||||||
extra_link_args=[get_the_lib_path() + '/libraylib.a',
|
|
||||||
'/opt/vc/lib/libEGL_static.a', '/opt/vc/lib/libGLESv2_static.a',
|
|
||||||
'-L/opt/vc/lib', '-lvcos', '-lbcm_host', '-lbrcmEGL', '-lbrcmGLESv2',
|
|
||||||
'-lm', '-lpthread', '-lrt'],
|
|
||||||
include_dirs=['raylib'],
|
|
||||||
)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
ffibuilder.compile(verbose=True)
|
|
||||||
|
|
||||||
|
|
||||||
if platform.system() == "Darwin":
|
|
||||||
build_mac()
|
|
||||||
elif platform.system() == "Linux":
|
|
||||||
if "x86" in platform.machine():
|
|
||||||
build_linux()
|
|
||||||
elif "arm" in platform.machine():
|
|
||||||
build_rpi_nox()
|
|
||||||
elif platform.system() == "Windows":
|
|
||||||
build_windows()
|
build_windows()
|
||||||
else:
|
else:
|
||||||
print("WARNING: UKKNOWN PLATFORM - trying Linux build")
|
print("not windows, trying Unix build")
|
||||||
build_linux()
|
build_unix()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ffibuilder.compile(verbose=True)
|
Reference in a new issue