Add raygui (#13)
All checks were successful
release / linux/aarch64 (push) Successful in 2m2s
release / linux/i686 (push) Successful in 2m4s
release / freebsd/x86_64 (push) Successful in 4m54s
release / windows/i686 (push) Successful in 2m9s
release / windows/x86_64 (push) Successful in 2m13s
release / linux/armv7 (push) Successful in 2m19s
release / linux/x86_64 (push) Successful in 2m5s
release / android (push) Successful in 2m57s
All checks were successful
release / linux/aarch64 (push) Successful in 2m2s
release / linux/i686 (push) Successful in 2m4s
release / freebsd/x86_64 (push) Successful in 4m54s
release / windows/i686 (push) Successful in 2m9s
release / windows/x86_64 (push) Successful in 2m13s
release / linux/armv7 (push) Successful in 2m19s
release / linux/x86_64 (push) Successful in 2m5s
release / android (push) Successful in 2m57s
Reviewed-on: #13 Co-authored-by: pedro-bento <mail@pbento.pt> Co-committed-by: pedro-bento <mail@pbento.pt>
This commit is contained in:
parent
3b9bbd529a
commit
b48fbc4266
7 changed files with 2006 additions and 219 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -4,3 +4,6 @@
|
||||||
[submodule "submodules/raylib"]
|
[submodule "submodules/raylib"]
|
||||||
path = submodules/raylib
|
path = submodules/raylib
|
||||||
url = https://github.com/raysan5/raylib.git
|
url = https://github.com/raysan5/raylib.git
|
||||||
|
[submodule "submodules/raygui"]
|
||||||
|
path = submodules/raygui
|
||||||
|
url = https://github.com/raysan5/raygui.git
|
||||||
|
|
|
||||||
216
Makefile
216
Makefile
|
|
@ -1,17 +1,14 @@
|
||||||
# hate-no-d
|
# hate-no-d
|
||||||
#
|
#
|
||||||
# Native platforms are auto-detected from uname. Cross targets are explicit:
|
# Platforms are auto-detected from uname; cross targets are explicit:
|
||||||
# make
|
# make
|
||||||
# make PLATFORM=Android ANDROID_NDK=/opt/android-ndk [ANDROID_ABI=... ANDROID_API=...]
|
|
||||||
# make PLATFORM=Windows WIN_ARCH=x86_64 (cross build with mingw-w64)
|
# make PLATFORM=Windows WIN_ARCH=x86_64 (cross build with mingw-w64)
|
||||||
#
|
# make PLATFORM=Android ANDROID_NDK=/opt/ndk [ANDROID_ABI=... ANDROID_API=...]
|
||||||
# Targets:
|
|
||||||
# make the CLI (hate-no-d or hate-no-d.exe)
|
|
||||||
# make help every target and option
|
# make help every target and option
|
||||||
#
|
#
|
||||||
# raylib is linked into the CLI. Objects, rlparser and its generated API tables
|
# LuaJIT and raylib build inside their own submodule trees. Objects, rlparser
|
||||||
# go to build/; only the CLI and hate-no-d.lua land in the repository root.
|
# and its API tables go to build/; only the CLI and the generated hate-no-d.lua
|
||||||
# raylib and LuaJIT build in their own trees (both gitignore their output).
|
# land in the repository root.
|
||||||
|
|
||||||
# luajit requires GNU Make. BSD make fails on .FEATURES before this guard.
|
# luajit requires GNU Make. BSD make fails on .FEATURES before this guard.
|
||||||
ifndef .FEATURES
|
ifndef .FEATURES
|
||||||
|
|
@ -20,33 +17,46 @@ endif
|
||||||
|
|
||||||
.DEFAULT_GOAL := all
|
.DEFAULT_GOAL := all
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Paths and outputs
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
LUAJIT_DIR := submodules/luajit
|
LUAJIT_DIR := submodules/luajit
|
||||||
LUAJIT_SRC := $(LUAJIT_DIR)/src
|
LUAJIT_SRC := $(LUAJIT_DIR)/src
|
||||||
LUAJIT_AR := $(LUAJIT_SRC)/libluajit.a
|
LUAJIT_AR := $(LUAJIT_SRC)/libluajit.a
|
||||||
|
|
||||||
RAYLIB_DIR := submodules/raylib
|
RAYLIB_DIR := submodules/raylib
|
||||||
RAYLIB_SRC := $(RAYLIB_DIR)/src
|
RAYLIB_SRC := $(RAYLIB_DIR)/src
|
||||||
RAYLIB_AR := $(RAYLIB_SRC)/libraylib.a
|
RAYLIB_AR := $(RAYLIB_SRC)/libraylib.a
|
||||||
RLPARSER_DIR := $(RAYLIB_DIR)/tools/rlparser
|
RLPARSER_DIR := $(RAYLIB_DIR)/tools/rlparser
|
||||||
|
|
||||||
|
RAYGUI_DIR := submodules/raygui
|
||||||
|
RAYGUI_SRC := $(RAYGUI_DIR)/src
|
||||||
|
|
||||||
BUILD_DIR := build
|
BUILD_DIR := build
|
||||||
API_DIR := $(BUILD_DIR)/api
|
API_DIR := $(BUILD_DIR)/api
|
||||||
RLPARSER := $(BUILD_DIR)/rlparser
|
RLPARSER := $(BUILD_DIR)/rlparser
|
||||||
RAYLIB_API := $(API_DIR)/raylib_api.lua
|
|
||||||
BINDING := hate-no-d.lua
|
|
||||||
OBJ := $(BUILD_DIR)/hate-no-d.o
|
OBJ := $(BUILD_DIR)/hate-no-d.o
|
||||||
|
|
||||||
|
RAYLIB_API := $(API_DIR)/raylib_api.lua
|
||||||
|
RLGL_API := $(API_DIR)/rlgl_api.lua
|
||||||
|
RAYMATH_API := $(API_DIR)/raymath_api.lua
|
||||||
|
RAYGUI_API := $(API_DIR)/raygui_api.lua
|
||||||
|
|
||||||
|
BINDING := hate-no-d.lua
|
||||||
BIN := hate-no-d
|
BIN := hate-no-d
|
||||||
|
|
||||||
GEN_FLAGS := --raylib=$(API_DIR)/raylib_api.lua \
|
# ---------------------------------------------------------------------------
|
||||||
--rlgl=$(API_DIR)/rlgl_api.lua \
|
# Platform detection
|
||||||
--raymath=$(API_DIR)/raymath_api.lua
|
# ---------------------------------------------------------------------------
|
||||||
|
# PLATFORM= always wins over uname.
|
||||||
# Archiver passed to raylib's build. Cross toolchains ship their own.
|
PLATFORM ?= $(shell uname -s)
|
||||||
AR ?= ar
|
|
||||||
|
|
||||||
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
|
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
|
||||||
LUAJIT_EXTRA :=
|
LUAJIT_EXTRA :=
|
||||||
|
|
||||||
# Platform detection. PLATFORM= always wins over uname.
|
# raylib build args; per-platform blocks below override them.
|
||||||
PLATFORM ?= $(shell uname -s)
|
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC
|
||||||
|
RAYLIB_LINK := -Wl,--whole-archive $(RAYLIB_AR) -Wl,--no-whole-archive
|
||||||
|
|
||||||
ifeq ($(PLATFORM),Linux)
|
ifeq ($(PLATFORM),Linux)
|
||||||
OS_KIND := linux
|
OS_KIND := linux
|
||||||
|
|
@ -72,10 +82,6 @@ else ifneq (,$(filter $(PLATFORM),FreeBSD OpenBSD NetBSD DragonFly))
|
||||||
OS_KIND := bsd
|
OS_KIND := bsd
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# raylib build args; per-platform overrides follow.
|
|
||||||
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC
|
|
||||||
RAYLIB_LINK := -Wl,--whole-archive $(RAYLIB_AR) -Wl,--no-whole-archive
|
|
||||||
|
|
||||||
# Linux (ELF)
|
# Linux (ELF)
|
||||||
ifeq ($(OS_KIND),linux)
|
ifeq ($(OS_KIND),linux)
|
||||||
EXPORT_LDFLAGS := -Wl,-E
|
EXPORT_LDFLAGS := -Wl,-E
|
||||||
|
|
@ -83,15 +89,12 @@ ifeq ($(OS_KIND),linux)
|
||||||
LINK_TARGET := $(BIN)
|
LINK_TARGET := $(BIN)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# BSD (ELF, dlopen lives in libc)
|
# BSD (ELF, dlopen lives in libc). ld searches /usr/lib only, while pkg(8)
|
||||||
|
# installs into /usr/local, pkgsrc into /usr/pkg and base X11 into /usr/X11R6
|
||||||
|
# or /usr/X11R7, so every -l below needs an explicit -L. raylib's own BSD link
|
||||||
|
# list also omits the X11 set.
|
||||||
ifeq ($(OS_KIND),bsd)
|
ifeq ($(OS_KIND),bsd)
|
||||||
EXPORT_LDFLAGS := -Wl,-E
|
EXPORT_LDFLAGS := -Wl,-E
|
||||||
# ld searches /usr/lib only. pkg(8) installs into /usr/local (FreeBSD,
|
|
||||||
# DragonFly), pkgsrc into /usr/pkg (NetBSD), and base X11 lives in
|
|
||||||
# /usr/X11R6 (OpenBSD) or /usr/X11R7 (NetBSD), so every -l below needs an
|
|
||||||
# explicit -L. raylib's own BSD link list omits the X11 set and these paths,
|
|
||||||
# which is why its examples only link on a system with the libs on the
|
|
||||||
# default search path.
|
|
||||||
BSD_LIBDIRS := -L/usr/local/lib
|
BSD_LIBDIRS := -L/usr/local/lib
|
||||||
ifneq (,$(filter OpenBSD NetBSD,$(PLATFORM)))
|
ifneq (,$(filter OpenBSD NetBSD,$(PLATFORM)))
|
||||||
BSD_LIBDIRS += -L/usr/pkg/lib -L/usr/X11R6/lib -L/usr/X11R7/lib
|
BSD_LIBDIRS += -L/usr/pkg/lib -L/usr/X11R6/lib -L/usr/X11R7/lib
|
||||||
|
|
@ -104,8 +107,8 @@ ifeq ($(OS_KIND),bsd)
|
||||||
LINK_TARGET := $(BIN)
|
LINK_TARGET := $(BIN)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Windows (PE, cross-compiled from a POSIX host with mingw-w64; native builds use
|
# Windows (PE), cross-compiled from a POSIX host with mingw-w64; native builds
|
||||||
# build.bat). i686 needs a 32-bit host compiler, since LuaJIT's buildvm runs
|
# use build.bat. i686 needs a 32-bit host compiler, since LuaJIT's buildvm runs
|
||||||
# natively and must match the target pointer size:
|
# natively and must match the target pointer size:
|
||||||
# make PLATFORM=Windows WIN_ARCH=i686 HOST_CC="gcc -m32"
|
# make PLATFORM=Windows WIN_ARCH=i686 HOST_CC="gcc -m32"
|
||||||
ifeq ($(OS_KIND),windows)
|
ifeq ($(OS_KIND),windows)
|
||||||
|
|
@ -158,10 +161,9 @@ ifeq ($(OS_KIND),macos)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Android (ELF, cross-compiled with the NDK)
|
# Android (ELF), cross-compiled with the NDK. 64-bit ABIs build on any 64-bit
|
||||||
#
|
# host; armeabi-v7a also needs a 32-bit host compiler:
|
||||||
# 64-bit ABIs build on any 64-bit host. armeabi-v7a additionally needs a
|
# make PLATFORM=Android ANDROID_NDK=... HOST_CC="gcc -m32"
|
||||||
# 32-bit host compiler: make ... HOST_CC="gcc -m32"
|
|
||||||
ifeq ($(OS_KIND),android)
|
ifeq ($(OS_KIND),android)
|
||||||
ANDROID_NDK ?= $(ANDROID_NDK_HOME)
|
ANDROID_NDK ?= $(ANDROID_NDK_HOME)
|
||||||
ANDROID_API ?= 21
|
ANDROID_API ?= 21
|
||||||
|
|
@ -226,30 +228,107 @@ ifndef LINK_TARGET
|
||||||
$(error Unsupported platform '$(PLATFORM)' -- supported: Linux, Android, Darwin, Windows, BSD)
|
$(error Unsupported platform '$(PLATFORM)' -- supported: Linux, Android, Darwin, Windows, BSD)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Host compiler for build-time tools (rlparser); the Windows branch pins gcc.
|
# ---------------------------------------------------------------------------
|
||||||
|
# Tools and flags
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Host compiler for build-time tools (rlparser, LuaJIT's minilua/buildvm).
|
||||||
HOST_CC ?= cc
|
HOST_CC ?= cc
|
||||||
|
# Host LuaJIT that runs the binding generator.
|
||||||
LUAJIT ?= luajit
|
LUAJIT ?= luajit
|
||||||
|
# Archiver passed to raylib's build. Cross toolchains ship their own.
|
||||||
|
AR ?= ar
|
||||||
|
|
||||||
# raylib's RELEASE build appends -O1; -O2 is a big win for CPU-bound code.
|
# raylib's RELEASE build appends -O1; -O2 is a big win for CPU-bound code.
|
||||||
# Changing it needs `make clean` -- objects are not flag-aware.
|
# Changing it needs `make clean` -- objects are not flag-aware.
|
||||||
RAYLIB_OPT ?= -O2
|
RAYLIB_OPT ?= -O2
|
||||||
RAYLIB_MAKE_ARGS += CUSTOM_CFLAGS="$(RAYLIB_OPT)"
|
RAYLIB_MAKE_ARGS += CUSTOM_CFLAGS="$(RAYLIB_OPT)"
|
||||||
|
|
||||||
# Compiler / linker flags
|
|
||||||
CFLAGS ?= -O2 -Wall
|
CFLAGS ?= -O2 -Wall
|
||||||
CPPFLAGS += -I$(LUAJIT_SRC)
|
|
||||||
|
|
||||||
# LuaJIT: static archive only, built through the upstream GNU Makefile.
|
# raygui.h includes raylib.h, hence both include paths. raymath needs no header
|
||||||
|
# here: rcore.c already compiled it into libraylib.a. raygui has no such owner,
|
||||||
|
# so its implementation is force-included into the CLI's translation unit.
|
||||||
|
CPPFLAGS += -I$(LUAJIT_SRC) -I$(RAYLIB_SRC) -I$(RAYGUI_SRC) \
|
||||||
|
-DRAYGUI_IMPLEMENTATION -include $(RAYGUI_SRC)/raygui.h
|
||||||
|
|
||||||
LUAJIT_MAKE_ARGS := BUILDMODE=static XCFLAGS="$(LUAJIT_XCFLAGS)" $(LUAJIT_EXTRA)
|
LUAJIT_MAKE_ARGS := BUILDMODE=static XCFLAGS="$(LUAJIT_XCFLAGS)" $(LUAJIT_EXTRA)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Submodules (static archives only)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
$(LUAJIT_AR):
|
$(LUAJIT_AR):
|
||||||
$(MAKE) -C $(LUAJIT_SRC) $(LUAJIT_MAKE_ARGS) "LJCORE_O=ljamalg.o" libluajit.a
|
$(MAKE) -C $(LUAJIT_SRC) $(LUAJIT_MAKE_ARGS) "LJCORE_O=ljamalg.o" libluajit.a
|
||||||
|
|
||||||
# raylib: static archive only; CC/AR are pinned, its Makefile defaults to host gcc/ar.
|
# CC/AR are pinned: raylib's Makefile would otherwise pick host defaults.
|
||||||
$(RAYLIB_AR):
|
$(RAYLIB_AR):
|
||||||
$(MAKE) -C $(RAYLIB_SRC) $(RAYLIB_MAKE_ARGS) CC="$(CC)" AR="$(AR)"
|
$(MAKE) -C $(RAYLIB_SRC) $(RAYLIB_MAKE_ARGS) CC="$(CC)" AR="$(AR)"
|
||||||
|
|
||||||
# Targets
|
# ---------------------------------------------------------------------------
|
||||||
|
# CLI
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
all: $(LINK_TARGET) $(BINDING)
|
||||||
|
|
||||||
|
$(BUILD_DIR):
|
||||||
|
@mkdir -p $@
|
||||||
|
|
||||||
|
$(API_DIR): | $(BUILD_DIR)
|
||||||
|
@mkdir -p $@
|
||||||
|
|
||||||
|
$(OBJ): hate-no-d.c | $(BUILD_DIR)
|
||||||
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ hate-no-d.c
|
||||||
|
|
||||||
|
# raylib is pulled in whole: nothing references it, so the linker would drop it
|
||||||
|
# and ffi.C would have nothing to resolve.
|
||||||
|
$(BIN): $(OBJ) $(LUAJIT_AR) $(RAYLIB_AR)
|
||||||
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(OBJ) \
|
||||||
|
$(RAYLIB_LINK) $(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Lua bindings (hate-no-d.lua)
|
||||||
|
#
|
||||||
|
# gen-hate-no-d.lua turns the rlparser tables for raylib.h, rlgl.h, raymath.h
|
||||||
|
# and raygui.h into one ffi.cdef block plus constants, wrappers and LuaCATS
|
||||||
|
# comments.
|
||||||
|
#
|
||||||
|
# The tables are generated into build/api from the pinned submodule headers, so
|
||||||
|
# raylib's tools/rlparser/output (where raylib_api.lua is tracked) stays clean.
|
||||||
|
# rlparser runs on HOST_CC, never the target CC: cross builds still produce the
|
||||||
|
# same platform-independent binding. The script has these paths baked in
|
||||||
|
# (build/api/*.lua in, hate-no-d.lua out), so BINDING must match OUT.
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
$(RLPARSER): $(RLPARSER_DIR)/rlparser.c | $(BUILD_DIR)
|
||||||
|
$(HOST_CC) -O2 -Wall -std=c99 -o $@ $(RLPARSER_DIR)/rlparser.c
|
||||||
|
|
||||||
|
$(RAYLIB_API): $(RLPARSER) $(RAYLIB_SRC)/raylib.h | $(API_DIR)
|
||||||
|
$(RLPARSER) -i $(RAYLIB_SRC)/raylib.h -o $@ -f LUA -d RLAPI
|
||||||
|
|
||||||
|
$(RLGL_API): $(RLPARSER) $(RAYLIB_SRC)/rlgl.h | $(API_DIR)
|
||||||
|
$(RLPARSER) -i $(RAYLIB_SRC)/rlgl.h -o $@ -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
|
||||||
|
|
||||||
|
$(RAYMATH_API): $(RLPARSER) $(RAYLIB_SRC)/raymath.h | $(API_DIR)
|
||||||
|
$(RLPARSER) -i $(RAYLIB_SRC)/raymath.h -o $@ -f LUA -d RMAPI
|
||||||
|
|
||||||
|
$(RAYGUI_API): $(RLPARSER) $(RAYGUI_SRC)/raygui.h | $(API_DIR)
|
||||||
|
$(RLPARSER) -i $(RAYGUI_SRC)/raygui.h -o $@ -f LUA -d RAYGUIAPI
|
||||||
|
|
||||||
|
$(BINDING): gen-hate-no-d.lua $(RLGL_API) $(RAYMATH_API) $(RAYLIB_API) $(RAYGUI_API)
|
||||||
|
@command -v $(LUAJIT) >/dev/null 2>&1 || { \
|
||||||
|
echo "hate-no-d: cannot run '$(LUAJIT)' -- install LuaJIT or set LUAJIT=..." >&2; exit 1; }
|
||||||
|
$(LUAJIT) gen-hate-no-d.lua
|
||||||
|
|
||||||
|
bindings: $(BINDING)
|
||||||
|
|
||||||
|
# Fail if regeneration is not byte-identical or the module does not load.
|
||||||
|
check-bindings: $(BINDING)
|
||||||
|
@before=$$(cksum $(BINDING)); \
|
||||||
|
$(LUAJIT) gen-hate-no-d.lua; \
|
||||||
|
[ "$$before" = "$$(cksum $(BINDING))" ] || { \
|
||||||
|
echo "hate-no-d.lua: regeneration is not byte-identical" >&2; exit 1; }
|
||||||
|
$(LUAJIT) -e 'local M = dofile("$(BINDING)"); assert(type(M) == "table"); assert(type(M.GetMousePosition) == "function", "raylib"); assert(type(M.rlLoadIdentity) == "function", "rlgl"); assert(type(M.Vector2Add) == "function", "raymath"); assert(type(M.GuiButton) == "function", "raygui"); print("bindings ok")'
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Info and maintenance
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
help:
|
help:
|
||||||
@echo "hate-no-d -- LuaJIT-based Lua runtime"
|
@echo "hate-no-d -- LuaJIT-based Lua runtime"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
@ -278,60 +357,6 @@ help:
|
||||||
@echo " LDFLAGS= extra linker flags"
|
@echo " LDFLAGS= extra linker flags"
|
||||||
@echo " AR= archiver for raylib's build"
|
@echo " AR= archiver for raylib's build"
|
||||||
|
|
||||||
all: $(LINK_TARGET) $(BINDING)
|
|
||||||
|
|
||||||
$(BUILD_DIR):
|
|
||||||
@mkdir -p $@
|
|
||||||
|
|
||||||
$(API_DIR): | $(BUILD_DIR)
|
|
||||||
@mkdir -p $@
|
|
||||||
|
|
||||||
$(OBJ): hate-no-d.c | $(BUILD_DIR)
|
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ hate-no-d.c
|
|
||||||
|
|
||||||
# raylib is pulled in whole: nothing references it, so the linker would drop it
|
|
||||||
# and ffi.C would have nothing to resolve.
|
|
||||||
$(BIN): $(OBJ) $(LUAJIT_AR) $(RAYLIB_AR)
|
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(OBJ) \
|
|
||||||
$(RAYLIB_LINK) $(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Lua bindings (hate-no-d.lua)
|
|
||||||
#
|
|
||||||
# gen-hate-no-d.lua turns the rlparser tables for raylib.h, rlgl.h and raymath.h
|
|
||||||
# into one ffi.cdef block plus constants, wrappers and LuaCATS comments.
|
|
||||||
#
|
|
||||||
# The tables are generated into build/api from the pinned submodule headers, so
|
|
||||||
# raylib's tools/rlparser/output (where raylib_api.lua is tracked) stays clean.
|
|
||||||
# rlparser itself is built with HOST_CC, never the target CC: cross builds still
|
|
||||||
# run it to produce the platform-independent binding.
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
$(RLPARSER): $(RLPARSER_DIR)/rlparser.c | $(BUILD_DIR)
|
|
||||||
$(HOST_CC) -O2 -Wall -std=c99 -o $@ $(RLPARSER_DIR)/rlparser.c
|
|
||||||
|
|
||||||
$(RAYLIB_API): $(RLPARSER) $(RAYLIB_SRC)/raylib.h | $(API_DIR)
|
|
||||||
$(RLPARSER) -i $(RAYLIB_SRC)/raylib.h -o $@ -f LUA -d RLAPI
|
|
||||||
|
|
||||||
$(API_DIR)/rlgl_api.lua: $(RLPARSER) $(RAYLIB_SRC)/rlgl.h | $(API_DIR)
|
|
||||||
$(RLPARSER) -i $(RAYLIB_SRC)/rlgl.h -o $@ -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
|
|
||||||
|
|
||||||
$(API_DIR)/raymath_api.lua: $(RLPARSER) $(RAYLIB_SRC)/raymath.h | $(API_DIR)
|
|
||||||
$(RLPARSER) -i $(RAYLIB_SRC)/raymath.h -o $@ -f LUA -d RMAPI
|
|
||||||
|
|
||||||
$(BINDING): gen-hate-no-d.lua $(API_DIR)/rlgl_api.lua $(API_DIR)/raymath_api.lua $(RAYLIB_API)
|
|
||||||
@command -v $(LUAJIT) >/dev/null 2>&1 || { \
|
|
||||||
echo "hate-no-d: cannot run '$(LUAJIT)' -- install LuaJIT or set LUAJIT=..." >&2; exit 1; }
|
|
||||||
$(LUAJIT) gen-hate-no-d.lua --out=$@ $(GEN_FLAGS)
|
|
||||||
|
|
||||||
bindings: $(BINDING)
|
|
||||||
|
|
||||||
# Fail if regeneration is not byte-identical or the module does not load.
|
|
||||||
check-bindings: $(BINDING)
|
|
||||||
$(LUAJIT) gen-hate-no-d.lua --out=$(BUILD_DIR)/hate-no-d.lua.tmp $(GEN_FLAGS)
|
|
||||||
cmp $(BINDING) $(BUILD_DIR)/hate-no-d.lua.tmp
|
|
||||||
rm -f $(BUILD_DIR)/hate-no-d.lua.tmp
|
|
||||||
$(LUAJIT) -e 'local M = dofile("$(BINDING)"); assert(type(M) == "table"); assert(type(M.GetMousePosition) == "function", "raylib"); assert(type(M.rlLoadIdentity) == "function", "rlgl"); assert(type(M.Vector2Add) == "function", "raymath"); print("bindings ok")'
|
|
||||||
|
|
||||||
# Resolved configuration for the current target; useful before a cross build.
|
# Resolved configuration for the current target; useful before a cross build.
|
||||||
print-config:
|
print-config:
|
||||||
@echo "PLATFORM = $(PLATFORM)"
|
@echo "PLATFORM = $(PLATFORM)"
|
||||||
|
|
@ -364,6 +389,5 @@ clean:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
rm -f $(BIN) hate-no-d.exe libhate-no-d.a libhate-no-d.a.mri $(LUAJIT_AR) $(RAYLIB_AR)
|
rm -f $(BIN) hate-no-d.exe libhate-no-d.a libhate-no-d.a.mri $(LUAJIT_AR) $(RAYLIB_AR)
|
||||||
rm -f $(BINDING)
|
rm -f $(BINDING)
|
||||||
rm -f hate-no-d.o # object from builds that predate the move into build/
|
|
||||||
|
|
||||||
.PHONY: all clean print-config help bindings check-bindings
|
.PHONY: all clean print-config help bindings check-bindings
|
||||||
|
|
|
||||||
11
build.bat
11
build.bat
|
|
@ -109,7 +109,10 @@ echo === Building hate-no-d.exe ===
|
||||||
if not exist "build" mkdir "build"
|
if not exist "build" mkdir "build"
|
||||||
if exist "build\hate-no-d.obj" del /q "build\hate-no-d.obj"
|
if exist "build\hate-no-d.obj" del /q "build\hate-no-d.obj"
|
||||||
cl /nologo /c /O2 /W4 /MT /D_CRT_SECURE_NO_WARNINGS ^
|
cl /nologo /c /O2 /W4 /MT /D_CRT_SECURE_NO_WARNINGS ^
|
||||||
/I "submodules\luajit\src" /Fo"build\hate-no-d.obj" hate-no-d.c
|
/I "submodules\luajit\src" /I "submodules\raylib\src" /I "submodules\raygui\src" ^
|
||||||
|
/DRAYGUI_IMPLEMENTATION /FI"submodules\raygui\src\raygui.h" ^
|
||||||
|
/D"RAYGUIAPI=__declspec(dllexport)" ^
|
||||||
|
/Fo"build\hate-no-d.obj" hate-no-d.c
|
||||||
if errorlevel 1 goto :fail
|
if errorlevel 1 goto :fail
|
||||||
|
|
||||||
link /nologo /OUT:hate-no-d.exe "build\hate-no-d.obj" ^
|
link /nologo /OUT:hate-no-d.exe "build\hate-no-d.obj" ^
|
||||||
|
|
@ -118,10 +121,10 @@ link /nologo /OUT:hate-no-d.exe "build\hate-no-d.obj" ^
|
||||||
opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib advapi32.lib
|
opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib advapi32.lib
|
||||||
if errorlevel 1 goto :fail
|
if errorlevel 1 goto :fail
|
||||||
|
|
||||||
@rem ffi.C reads the exe's export table, so verify raylib really got exported.
|
@rem ffi.C reads the exe's export table, so verify raylib and raygui really got exported.
|
||||||
dumpbin /nologo /exports hate-no-d.exe | findstr /C:"InitWindow" >nul
|
dumpbin /nologo /exports hate-no-d.exe | findstr /C:"InitWindow" /C:"GuiButton" >nul
|
||||||
if errorlevel 1 (
|
if errorlevel 1 (
|
||||||
echo build.bat: hate-no-d.exe does not export raylib - ffi.C would not find it.
|
echo build.bat: hate-no-d.exe does not export raylib/raygui - ffi.C would not find it.
|
||||||
goto :fail
|
goto :fail
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,5 @@
|
||||||
-I./submodules/luajit/src
|
-I./submodules/luajit/src
|
||||||
|
-I./submodules/raylib/src
|
||||||
|
-I./submodules/raygui/src
|
||||||
|
-DRAYGUI_IMPLEMENTATION
|
||||||
|
-include ./submodules/raygui/src/raygui.h
|
||||||
|
|
|
||||||
|
|
@ -20,85 +20,41 @@ build never writes into raylib's tools/ tree:
|
||||||
-o build/api/rlgl_api.lua -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
|
-o build/api/rlgl_api.lua -f LUA -d RLAPI -t "RLGL IMPLEMENTATION"
|
||||||
build/rlparser -i submodules/raylib/src/raymath.h \
|
build/rlparser -i submodules/raylib/src/raymath.h \
|
||||||
-o build/api/raymath_api.lua -f LUA -d RMAPI
|
-o build/api/raymath_api.lua -f LUA -d RMAPI
|
||||||
|
build/rlparser -i submodules/raygui/src/raygui.h \
|
||||||
|
-o build/api/raygui_api.lua -f LUA -d RAYGUIAPI
|
||||||
|
|
||||||
Usage:
|
Run from the repository root; every table above is required and the result is
|
||||||
luajit gen-hate-no-d.lua [--out=hate-no-d.lua] [--no-rlgl] [--no-raymath]
|
always written to hate-no-d.lua.
|
||||||
[--raylib=path] [--rlgl=path] [--raymath=path]
|
|
||||||
|
|
||||||
raymath needs no extra translation unit: raylib's own rcore.c defines
|
raymath needs no extra translation unit: raylib's own rcore.c defines
|
||||||
RAYMATH_IMPLEMENTATION before including raymath.h, so libraylib.a already
|
RAYMATH_IMPLEMENTATION before including raymath.h, so libraylib.a already
|
||||||
contains all 146 raymath symbols (verified with nm). Linking the library
|
contains all 146 raymath symbols (verified with nm). Linking the library
|
||||||
with --whole-archive exposes them to ffi.C.
|
with --whole-archive exposes them to ffi.C.
|
||||||
|
|
||||||
|
raygui is header-only, its implementation is force-included into the CLI's
|
||||||
|
translation unit (-DRAYGUI_IMPLEMENTATION -include .../raygui.h), so its
|
||||||
|
symbols land in the executable and --whole-archive is not involved.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local CFG = {
|
local RAYLIB_API = "build/api/raylib_api.lua"
|
||||||
raylib = "build/api/raylib_api.lua",
|
local RLGL_API = "build/api/rlgl_api.lua"
|
||||||
rlgl = "build/api/rlgl_api.lua",
|
local RAYMATH_API = "build/api/raymath_api.lua"
|
||||||
raymath = "build/api/raymath_api.lua",
|
local RAYGUI_API = "build/api/raygui_api.lua"
|
||||||
out = "hate-no-d.lua",
|
local OUT = "hate-no-d.lua"
|
||||||
use_rlgl = true,
|
|
||||||
use_raymath = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
local USAGE = [[
|
|
||||||
usage: luajit gen-hate-no-d.lua [options]
|
|
||||||
|
|
||||||
--out=PATH output file (default: hate-no-d.lua)
|
|
||||||
--raylib=PATH raylib parser table (default: build/api/raylib_api.lua)
|
|
||||||
--rlgl=PATH rlgl parser table (default: build/api/rlgl_api.lua)
|
|
||||||
--raymath=PATH raymath parser table(default: build/api/raymath_api.lua)
|
|
||||||
--no-rlgl skip rlgl
|
|
||||||
--no-raymath skip raymath
|
|
||||||
-h, --help this text
|
|
||||||
]]
|
|
||||||
|
|
||||||
local function die(fmt, ...)
|
local function die(fmt, ...)
|
||||||
io.stderr:write("gen-hate-no-d: " .. string.format(fmt, ...) .. "\n")
|
io.stderr:write("gen-hate-no-d: " .. string.format(fmt, ...) .. "\n")
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function warn(fmt, ...)
|
|
||||||
io.stderr:write("gen-hate-no-d: warning: " .. string.format(fmt, ...) .. "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, #arg do
|
|
||||||
local a = arg[i]
|
|
||||||
local key, value = a:match("^%-%-([%w]+)=(.*)$")
|
|
||||||
if key == "out" then
|
|
||||||
CFG.out = value
|
|
||||||
elseif key == "raylib" then
|
|
||||||
CFG.raylib = value
|
|
||||||
elseif key == "rlgl" then
|
|
||||||
CFG.rlgl = value
|
|
||||||
elseif key == "raymath" then
|
|
||||||
CFG.raymath = value
|
|
||||||
elseif key then
|
|
||||||
die("unknown option --%s", key)
|
|
||||||
elseif a == "--no-rlgl" then
|
|
||||||
CFG.use_rlgl = false
|
|
||||||
elseif a == "--no-raymath" then
|
|
||||||
CFG.use_raymath = false
|
|
||||||
elseif a == "-h" or a == "--help" then
|
|
||||||
io.write(USAGE)
|
|
||||||
os.exit(0)
|
|
||||||
else
|
|
||||||
die("unknown argument %s", a)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
-- loading
|
-- loading
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
local function load_api(path, optional)
|
local function load_api(path)
|
||||||
local chunk, err = loadfile(path)
|
local chunk, err = loadfile(path)
|
||||||
if not chunk then
|
if not chunk then
|
||||||
if optional then
|
|
||||||
warn("skipping %s (%s)", path, err)
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
die("cannot load %s: %s", path, err)
|
die("cannot load %s: %s", path, err)
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
local ok, data = pcall(chunk)
|
local ok, data = pcall(chunk)
|
||||||
if not ok then
|
if not ok then
|
||||||
|
|
@ -110,28 +66,17 @@ local function load_api(path, optional)
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
local apis = {}
|
local raylib_api = load_api(RAYLIB_API)
|
||||||
|
local raygui_api = load_api(RAYGUI_API)
|
||||||
|
|
||||||
local raylib_api = load_api(CFG.raylib)
|
-- Merge order matters: raylib defines the base types (Texture, ...) that raygui
|
||||||
apis[#apis + 1] = { tag = "raylib", data = raylib_api }
|
-- redeclares in its standalone fallback, so raylib always goes first.
|
||||||
|
local apis = {
|
||||||
if CFG.use_rlgl then
|
raylib_api,
|
||||||
local data = load_api(CFG.rlgl, false)
|
load_api(RLGL_API),
|
||||||
if data then
|
load_api(RAYMATH_API),
|
||||||
apis[#apis + 1] = { tag = "rlgl", data = data }
|
raygui_api,
|
||||||
else
|
}
|
||||||
warn("rlgl API table missing, building raylib.h only")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if CFG.use_raymath then
|
|
||||||
local data = load_api(CFG.raymath, false)
|
|
||||||
if data then
|
|
||||||
apis[#apis + 1] = { tag = "raymath", data = data }
|
|
||||||
else
|
|
||||||
warn("raymath API table missing, building without raymath")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
-- type model
|
-- type model
|
||||||
|
|
@ -206,18 +151,7 @@ local function sanitize_fields(fields)
|
||||||
return clean
|
return clean
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_api(tag)
|
local function add_api(data)
|
||||||
local data
|
|
||||||
for _, item in ipairs(apis) do
|
|
||||||
if item.tag == tag then
|
|
||||||
data = item.data
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not data then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, s in ipairs(data.structs or {}) do
|
for _, s in ipairs(data.structs or {}) do
|
||||||
if not STRUCTS[s.name] and not ALIASES[s.name] then
|
if not STRUCTS[s.name] and not ALIASES[s.name] then
|
||||||
STRUCTS[s.name] = {
|
STRUCTS[s.name] = {
|
||||||
|
|
@ -250,13 +184,12 @@ local function add_api(tag)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, f in ipairs(data.functions or {}) do
|
for _, f in ipairs(data.functions or {}) do
|
||||||
f._tag = tag
|
|
||||||
FUNCS[#FUNCS + 1] = f
|
FUNCS[#FUNCS + 1] = f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, item in ipairs(apis) do
|
for _, data in ipairs(apis) do
|
||||||
add_api(item.tag)
|
add_api(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TraceLogCallback carries va_list, which LuaJIT cannot pass to a Lua
|
-- TraceLogCallback carries va_list, which LuaJIT cannot pass to a Lua
|
||||||
|
|
@ -677,14 +610,16 @@ local function find_define(data, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
version = tostring(find_define(raylib_api, "RAYLIB_VERSION") or "unknown")
|
version = tostring(find_define(raylib_api, "RAYLIB_VERSION") or "unknown")
|
||||||
|
local raygui_version = tostring(find_define(raygui_api, "RAYGUI_VERSION") or "unknown")
|
||||||
|
|
||||||
w("--[[")
|
w("--[[")
|
||||||
w(" hate-no-d.lua - generated by gen-hate-no-d.lua, do not edit.")
|
w(" hate-no-d.lua - generated by gen-hate-no-d.lua, do not edit.")
|
||||||
w("")
|
w("")
|
||||||
w(" raylib " .. version .. " / rlgl / raymath")
|
w(" raylib " .. version .. " / rlgl / raymath / raygui " .. raygui_version)
|
||||||
w(" Functions: " .. tostring(#FUNCS))
|
w(" Functions: " .. tostring(#FUNCS))
|
||||||
w("")
|
w("")
|
||||||
w(" raymath symbols come from rcore.o (RAYMATH_IMPLEMENTATION) in libraylib.a.")
|
w(" raymath symbols come from rcore.o (RAYMATH_IMPLEMENTATION) in libraylib.a.")
|
||||||
|
w(" raygui symbols come from a forced -include of raygui.h (RAYGUI_IMPLEMENTATION).")
|
||||||
w("]]")
|
w("]]")
|
||||||
w("")
|
w("")
|
||||||
w('local ffi = require("ffi")')
|
w('local ffi = require("ffi")')
|
||||||
|
|
@ -803,8 +738,8 @@ w("")
|
||||||
local enum_constants = {}
|
local enum_constants = {}
|
||||||
local seen_const = {}
|
local seen_const = {}
|
||||||
|
|
||||||
for _, item in ipairs(apis) do
|
for _, data in ipairs(apis) do
|
||||||
for _, enum in ipairs(item.data.enums or {}) do
|
for _, enum in ipairs(data.enums or {}) do
|
||||||
w("---@enum raylib." .. enum.name)
|
w("---@enum raylib." .. enum.name)
|
||||||
w("M." .. enum.name .. " = {")
|
w("M." .. enum.name .. " = {")
|
||||||
for _, v in ipairs(enum.values or {}) do
|
for _, v in ipairs(enum.values or {}) do
|
||||||
|
|
@ -825,8 +760,8 @@ for _, item in ipairs(apis) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, item in ipairs(apis) do
|
for _, data in ipairs(apis) do
|
||||||
for _, enum in ipairs(item.data.enums or {}) do
|
for _, enum in ipairs(data.enums or {}) do
|
||||||
for _, v in ipairs(enum.values or {}) do
|
for _, v in ipairs(enum.values or {}) do
|
||||||
w("---@type raylib." .. enum.name)
|
w("---@type raylib." .. enum.name)
|
||||||
w("M." .. v.name .. " = M." .. enum.name .. "." .. v.name)
|
w("M." .. v.name .. " = M." .. enum.name .. "." .. v.name)
|
||||||
|
|
@ -852,8 +787,8 @@ local function eval_float_math(expr)
|
||||||
return value
|
return value
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, item in ipairs(apis) do
|
for _, data in ipairs(apis) do
|
||||||
for _, d in ipairs(item.data.defines or {}) do
|
for _, d in ipairs(data.defines or {}) do
|
||||||
if not seen_const[d.name] then
|
if not seen_const[d.name] then
|
||||||
local dtype = d.type
|
local dtype = d.type
|
||||||
local emitted = false
|
local emitted = false
|
||||||
|
|
@ -1166,10 +1101,9 @@ w("return M")
|
||||||
----------------------------------------------------------------------------
|
----------------------------------------------------------------------------
|
||||||
|
|
||||||
local text = table.concat(out, "\n") .. "\n"
|
local text = table.concat(out, "\n") .. "\n"
|
||||||
local file, err = io.open(CFG.out, "wb")
|
local file, err = io.open(OUT, "wb")
|
||||||
if not file then
|
if not file then
|
||||||
die("cannot write %s: %s", CFG.out, err)
|
die("cannot write %s: %s", OUT, err)
|
||||||
return
|
|
||||||
end
|
end
|
||||||
file:write(text)
|
file:write(text)
|
||||||
file:close()
|
file:close()
|
||||||
|
|
@ -1187,4 +1121,4 @@ for _ in pairs(CALLBACKS) do
|
||||||
end
|
end
|
||||||
io.stderr:write(string.format(
|
io.stderr:write(string.format(
|
||||||
"gen-hate-no-d: wrote %s (%d functions, %d structs, %d aliases, %d callbacks, %d lines)\n",
|
"gen-hate-no-d: wrote %s (%d functions, %d structs, %d aliases, %d callbacks, %d lines)\n",
|
||||||
CFG.out, emitted_wrappers, n_struct, n_alias, n_cb, #out))
|
OUT, emitted_wrappers, n_struct, n_alias, n_cb, #out))
|
||||||
|
|
|
||||||
1822
hate-no-d.lua
1822
hate-no-d.lua
File diff suppressed because it is too large
Load diff
1
submodules/raygui
Submodule
1
submodules/raygui
Submodule
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 1abccb3a5303d041dc14404b7dd874fa665dd4af
|
||||||
Loading…
Reference in a new issue