use gcc to process header files instead of doing it ourselves
This commit is contained in:
parent
f6d0c6a912
commit
2ef7aba8a8
4 changed files with 77 additions and 192 deletions
111
raylib/build.py
111
raylib/build.py
|
@ -22,62 +22,89 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
ffibuilder = FFI()
|
ffibuilder = FFI()
|
||||||
|
|
||||||
|
def check_raylib_installed():
|
||||||
|
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'], stdout=subprocess.PIPE).stdout.decode(
|
return subprocess.run(['pkg-config', '--variable=includedir', 'raylib'], text=True, stdout=subprocess.PIPE).stdout.strip()
|
||||||
'utf-8').strip()
|
|
||||||
|
|
||||||
|
|
||||||
def get_the_lib_path():
|
def get_the_lib_path():
|
||||||
return subprocess.run(['pkg-config', '--variable=libdir', 'raylib'], stdout=subprocess.PIPE).stdout.decode(
|
return subprocess.run(['pkg-config', '--variable=libdir', 'raylib'], text=True, stdout=subprocess.PIPE).stdout.strip()
|
||||||
'utf-8').strip()
|
|
||||||
|
|
||||||
|
def pre_process_header(filename):
|
||||||
|
print("Pre-processing "+filename)
|
||||||
|
file = open(filename, "r")
|
||||||
|
filetext = "".join([ line for line in file if '#include' not in line])
|
||||||
|
command =['gcc', '-CC', '-P' ,'-undef', '-nostdinc', '-DRLAPI=', '-DPHYSACDEF=', '-DRAYGUIDEF=',
|
||||||
|
'-dDI', '-E', '-']
|
||||||
|
filetext2 = subprocess.run(command, text=True, input=filetext, stdout=subprocess.PIPE).stdout
|
||||||
|
filetext3 = filetext2.replace("va_list", "void *")
|
||||||
|
filetext4 = "\n".join([ line for line in filetext3.splitlines() if not line.startswith("#")])
|
||||||
|
#print(r)
|
||||||
|
return filetext4
|
||||||
|
|
||||||
|
def check_header_exists(file):
|
||||||
|
if not os.path.isfile(file):
|
||||||
|
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("**************************************\n\n")
|
||||||
|
time.sleep(1)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def mangle(string):
|
||||||
|
return string
|
||||||
|
|
||||||
|
if not check_raylib_installed():
|
||||||
|
raise Exception("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib.")
|
||||||
|
|
||||||
|
raylib_h = get_the_include_path() + "/raylib.h"
|
||||||
|
|
||||||
|
if not os.path.isfile(raylib_h):
|
||||||
|
raise Exception("ERROR: "+raylib_h+" not found. Please install Raylib.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ffi_includes = """
|
ffi_includes = """
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
"""
|
||||||
|
|
||||||
|
raygui_h = get_the_include_path() + "/raygui.h"
|
||||||
|
if check_header_exists(raygui_h):
|
||||||
|
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"
|
||||||
|
if check_header_exists(physac_h):
|
||||||
|
ffi_includes += """
|
||||||
#define PHYSAC_IMPLEMENTATION
|
#define PHYSAC_IMPLEMENTATION
|
||||||
#include "physac.h"
|
#include "physac.h"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def mangle(file):
|
|
||||||
result = ""
|
|
||||||
skip = False
|
|
||||||
for line in open(file):
|
|
||||||
line = line.strip().replace("va_list", "void *") + "\n"
|
|
||||||
if skip:
|
|
||||||
if line.startswith("#endif"):
|
|
||||||
skip = False
|
|
||||||
continue
|
|
||||||
if line.startswith("#if defined(__cplusplus)"):
|
|
||||||
skip = True
|
|
||||||
continue
|
|
||||||
if line.startswith("#endif // RAYGUI_H"):
|
|
||||||
break
|
|
||||||
if line.startswith("#"):
|
|
||||||
continue
|
|
||||||
if line.startswith("RLAPI"):
|
|
||||||
line = line.replace('RLAPI ', '')
|
|
||||||
if line.startswith("RAYGUIDEF"):
|
|
||||||
line = line.replace('RAYGUIDEF ', '')
|
|
||||||
if line.startswith("PHYSACDEF"):
|
|
||||||
line = line.replace('PHYSACDEF ', '')
|
|
||||||
result += line
|
|
||||||
# print(line)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def build_linux():
|
def build_linux():
|
||||||
print("BUILDING FOR LINUX")
|
print("BUILDING FOR LINUX")
|
||||||
ffibuilder.cdef(mangle(get_the_include_path() + "/raylib.h"))
|
ffibuilder.cdef(pre_process_header(raylib_h))
|
||||||
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
|
if os.path.isfile(raygui_h):
|
||||||
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
|
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,
|
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
||||||
extra_link_args=[get_the_lib_path() + '/libraylib.a', '-lm', '-lpthread', '-lGLU', '-lGL',
|
extra_link_args=[get_the_lib_path() + '/libraylib.a', '-lm', '-lpthread', '-lGLU', '-lGL',
|
||||||
'-lrt',
|
'-lrt',
|
||||||
|
@ -92,8 +119,8 @@ def build_linux():
|
||||||
def build_windows():
|
def build_windows():
|
||||||
print("BUILDING FOR WINDOWS")
|
print("BUILDING FOR WINDOWS")
|
||||||
ffibuilder.cdef(mangle("raylib/raylib.h"))
|
ffibuilder.cdef(mangle("raylib/raylib.h"))
|
||||||
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', '').replace('bool', 'int'))
|
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
|
||||||
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', '').replace('bool', 'int'))
|
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
|
||||||
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
||||||
extra_link_args=['/NODEFAULTLIB:MSVCRTD'],
|
extra_link_args=['/NODEFAULTLIB:MSVCRTD'],
|
||||||
libraries=['raylib', 'gdi32', 'shell32', 'user32', 'OpenGL32', 'winmm'],
|
libraries=['raylib', 'gdi32', 'shell32', 'user32', 'OpenGL32', 'winmm'],
|
||||||
|
@ -105,9 +132,11 @@ def build_windows():
|
||||||
|
|
||||||
def build_mac():
|
def build_mac():
|
||||||
print("BUILDING FOR MAC")
|
print("BUILDING FOR MAC")
|
||||||
ffibuilder.cdef(mangle(get_the_include_path() + "/raylib.h"))
|
ffibuilder.cdef(pre_process_header(raylib_h))
|
||||||
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
|
if os.path.isfile(raygui_h):
|
||||||
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
|
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,
|
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
||||||
extra_link_args=[get_the_lib_path() + '/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa',
|
extra_link_args=[get_the_lib_path() + '/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa',
|
||||||
'-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework',
|
'-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework',
|
||||||
|
@ -121,9 +150,11 @@ def build_mac():
|
||||||
|
|
||||||
def build_rpi_nox():
|
def build_rpi_nox():
|
||||||
print("BUILDING FOR RASPBERRY PI")
|
print("BUILDING FOR RASPBERRY PI")
|
||||||
ffibuilder.cdef(mangle(get_the_include_path() + "/raylib.h"))
|
ffibuilder.cdef(pre_process_header(raylib_h))
|
||||||
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
|
if os.path.isfile(raygui_h):
|
||||||
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
|
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,
|
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes,
|
||||||
extra_link_args=[get_the_lib_path() + '/libraylib.a',
|
extra_link_args=[get_the_lib_path() + '/libraylib.a',
|
||||||
'/opt/vc/lib/libEGL_static.a', '/opt/vc/lib/libGLESv2_static.a',
|
'/opt/vc/lib/libEGL_static.a', '/opt/vc/lib/libGLESv2_static.a',
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
from raylib import *
|
|
||||||
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
|
|
||||||
SetConfigFlags(FLAG_MSAA_4X_HINT)
|
|
||||||
InitWindow(screenWidth, screenHeight, b"[physac] Basic demo")
|
|
||||||
|
|
||||||
|
|
||||||
logoX = screenWidth - MeasureText(b"Physac", 30) - 10
|
|
||||||
logoY = 15
|
|
||||||
|
|
||||||
|
|
||||||
InitPhysics()
|
|
||||||
|
|
||||||
|
|
||||||
floor = CreatePhysicsBodyRectangle([screenWidth/2, screenHeight ], 500, 100, 10)
|
|
||||||
floor.enabled = False
|
|
||||||
|
|
||||||
|
|
||||||
circle = CreatePhysicsBodyCircle([screenWidth/2, screenHeight/2], 45, 10)
|
|
||||||
circle.enabled = False
|
|
||||||
|
|
||||||
SetTargetFPS(60)
|
|
||||||
|
|
||||||
while not WindowShouldClose():
|
|
||||||
|
|
||||||
UpdatePhysics();
|
|
||||||
|
|
||||||
if IsMouseButtonPressed(MOUSE_LEFT_BUTTON):
|
|
||||||
body = CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10)
|
|
||||||
|
|
||||||
elif IsMouseButtonPressed(MOUSE_RIGHT_BUTTON):
|
|
||||||
CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10)
|
|
||||||
|
|
||||||
|
|
||||||
bodiesCount = GetPhysicsBodiesCount()
|
|
||||||
for i in range(bodiesCount):
|
|
||||||
body = GetPhysicsBody(i)
|
|
||||||
if body and (body.position.y > screenHeight*2):
|
|
||||||
DestroyPhysicsBody(body)
|
|
||||||
|
|
||||||
|
|
||||||
BeginDrawing()
|
|
||||||
ClearBackground(BLACK)
|
|
||||||
DrawFPS(screenWidth - 90, screenHeight - 30)
|
|
||||||
|
|
||||||
|
|
||||||
bodiesCount = GetPhysicsBodiesCount()
|
|
||||||
for i in range(bodiesCount):
|
|
||||||
body = GetPhysicsBody(i)
|
|
||||||
if body:
|
|
||||||
vertexCount = GetPhysicsShapeVerticesCount(i)
|
|
||||||
for j in range(vertexCount):
|
|
||||||
vertexA = GetPhysicsShapeVertex(body, j)
|
|
||||||
jj = j + 1 if (j + 1) < vertexCount else 0
|
|
||||||
vertexB = GetPhysicsShapeVertex(body, jj)
|
|
||||||
DrawLineV(vertexA, vertexB, GREEN)
|
|
||||||
|
|
||||||
DrawText(b"Left mouse button to create a polygon", 10, 10, 10, WHITE)
|
|
||||||
DrawText(b"Right mouse button to create a circle", 10, 25, 10, WHITE)
|
|
||||||
|
|
||||||
DrawText(b"Physac", logoX, logoY, 30, WHITE)
|
|
||||||
DrawText(b"Powered by", logoX + 50, logoY - 7, 10, WHITE)
|
|
||||||
|
|
||||||
EndDrawing()
|
|
||||||
|
|
||||||
ClosePhysics()
|
|
||||||
|
|
||||||
CloseWindow()
|
|
|
@ -1,76 +0,0 @@
|
||||||
from raylib import *
|
|
||||||
|
|
||||||
VELOCITY = 0.5
|
|
||||||
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
|
|
||||||
SetConfigFlags(FLAG_MSAA_4X_HINT)
|
|
||||||
InitWindow(screenWidth, screenHeight, b"[physac] Basic demo")
|
|
||||||
logoX = screenWidth - MeasureText(b"Physac", 30) - 10
|
|
||||||
logoY = 15
|
|
||||||
|
|
||||||
|
|
||||||
InitPhysics()
|
|
||||||
|
|
||||||
floor = CreatePhysicsBodyRectangle([screenWidth/2, screenHeight ], screenWidth, 100, 10)
|
|
||||||
platformLeft = CreatePhysicsBodyRectangle([screenWidth*0.25, screenHeight*0.6 ], screenWidth*0.25, 10, 10)
|
|
||||||
platformRight = CreatePhysicsBodyRectangle([screenWidth*0.75, screenHeight*0.6 ], screenWidth*0.25, 10, 10)
|
|
||||||
wallLeft = CreatePhysicsBodyRectangle([-5, screenHeight/2 ], 10, screenHeight, 10)
|
|
||||||
wallRight = CreatePhysicsBodyRectangle([screenWidth + 5, screenHeight/2 ], 10, screenHeight, 10)
|
|
||||||
|
|
||||||
|
|
||||||
floor.enabled = False
|
|
||||||
platformLeft.enabled = False
|
|
||||||
platformRight.enabled = False
|
|
||||||
wallLeft.enabled = False
|
|
||||||
wallRight.enabled = False
|
|
||||||
|
|
||||||
|
|
||||||
body = CreatePhysicsBodyRectangle([screenWidth/2, screenHeight/2 ], 50, 50, 1)
|
|
||||||
body.freezeOrient = True
|
|
||||||
|
|
||||||
SetTargetFPS(60)
|
|
||||||
|
|
||||||
while not WindowShouldClose():
|
|
||||||
|
|
||||||
UpdatePhysics();
|
|
||||||
|
|
||||||
if IsKeyDown(KEY_RIGHT):
|
|
||||||
body.velocity.x = VELOCITY
|
|
||||||
elif IsKeyDown(KEY_LEFT):
|
|
||||||
body.velocity.x = -VELOCITY
|
|
||||||
|
|
||||||
|
|
||||||
if IsKeyDown(KEY_UP) and body.isGrounded:
|
|
||||||
body.velocity.y = -VELOCITY*4
|
|
||||||
|
|
||||||
BeginDrawing()
|
|
||||||
|
|
||||||
ClearBackground(BLACK)
|
|
||||||
|
|
||||||
DrawFPS(screenWidth - 90, screenHeight - 30)
|
|
||||||
|
|
||||||
|
|
||||||
bodiesCount = GetPhysicsBodiesCount()
|
|
||||||
for i in range(bodiesCount):
|
|
||||||
body = GetPhysicsBody(i)
|
|
||||||
vertexCount = GetPhysicsShapeVerticesCount(i)
|
|
||||||
for j in range(vertexCount):
|
|
||||||
vertexA = GetPhysicsShapeVertex(body, j)
|
|
||||||
|
|
||||||
jj = j + 1 if j + 1 < vertexCount else 0
|
|
||||||
vertexB = GetPhysicsShapeVertex(body, jj)
|
|
||||||
|
|
||||||
DrawLineV(vertexA, vertexB, GREEN)
|
|
||||||
|
|
||||||
DrawText(b"Use 'ARROWS' to move player", 10, 10, 10, WHITE)
|
|
||||||
|
|
||||||
DrawText(b"Physac", logoX, logoY, 30, WHITE)
|
|
||||||
DrawText(b"Powered by", logoX + 50, logoY - 7, 10, WHITE)
|
|
||||||
|
|
||||||
EndDrawing()
|
|
||||||
|
|
||||||
ClosePhysics()
|
|
||||||
|
|
||||||
CloseWindow()
|
|
|
@ -1 +1 @@
|
||||||
__version__ = "4.0a5"
|
__version__ = "4.0a6"
|
Reference in a new issue