From 5f19ef4a62da76ce986abf9cfc625d4ed37d3ef4 Mon Sep 17 00:00:00 2001 From: pedro-bento Date: Thu, 22 Oct 2026 20:39:02 +0100 Subject: [PATCH] Add raylib --- .forgejo/scripts/freebsd-build.sh | 4 +- .forgejo/workflows/release.yml | 44 +++++++--- .gitignore | 6 +- Makefile | 129 +++++++++++++++--------------- README.md | 84 +++++++++---------- build.bat | 14 ++-- gen-hate-no-d.lua | 25 +++--- 7 files changed, 168 insertions(+), 138 deletions(-) diff --git a/.forgejo/scripts/freebsd-build.sh b/.forgejo/scripts/freebsd-build.sh index 92ec772..518a40b 100644 --- a/.forgejo/scripts/freebsd-build.sh +++ b/.forgejo/scripts/freebsd-build.sh @@ -109,8 +109,8 @@ done log "guest up after ~$((i * 2))s: $(ssh_vm 'uname -sr')" # --- build ------------------------------------------------------------------- -log "installing gmake in guest" -ssh_vm 'set -e; env ASSUME_ALWAYS_YES=yes pkg install -y gmake luajit >/dev/null 2>&1; gmake --version | head -1' +log "installing gmake, luajit and the X11/GL prerequisites in guest" +ssh_vm 'set -e; env ASSUME_ALWAYS_YES=yes pkg install -y gmake luajit libX11 libXrandr libXinerama libXi libXcursor mesa-libs >/dev/null; gmake --version | head -1' log "transferring source" tar czf "$WORK/src.tar.gz" -C "$SRC" \ diff --git a/.forgejo/workflows/release.yml b/.forgejo/workflows/release.yml index 1f1e369..0e3149c 100644 --- a/.forgejo/workflows/release.yml +++ b/.forgejo/workflows/release.yml @@ -48,18 +48,21 @@ jobs: - arch: x86_64 machine: X86-64 make_args: '' - packages: '' + multiarch: '' + packages: 'libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgl-dev' # 32-bit target: leaving HOST_CC unset keeps minilua/buildvm 32-bit # too. Host and target pointer sizes must match -- do not use HOST_CC=gcc. - arch: i686 machine: 'Intel 80386' make_args: 'CC="gcc -m32"' - packages: 'gcc-multilib libc6-dev-i386' + multiarch: 'i386' + packages: 'gcc-multilib libc6-dev-i386 libx11-dev:i386 libxrandr-dev:i386 libxinerama-dev:i386 libxcursor-dev:i386 libxi-dev:i386 libgl-dev:i386' # 64-bit host -> 64-bit target, so host tools stay native. - arch: aarch64 machine: AArch64 make_args: 'CC=aarch64-linux-gnu-gcc HOST_CC=gcc' - packages: 'gcc-aarch64-linux-gnu libc6-dev-arm64-cross qemu-user-static' + multiarch: 'arm64' + packages: 'gcc-aarch64-linux-gnu libc6-dev-arm64-cross qemu-user-static libx11-dev:arm64 libxrandr-dev:arm64 libxinerama-dev:arm64 libxcursor-dev:arm64 libxi-dev:arm64 libgl-dev:arm64' # 32-bit target, so the host tools must be 32-bit too. gcc-multilib # cannot be installed (gcc-12-arm-linux-gnueabihf conflicts with it); # lib32gcc-12-dev + libc6-dev-i386 replace it, and linux-libc-dev:i386 @@ -67,8 +70,8 @@ jobs: - arch: armv7 machine: ARM make_args: 'CC=arm-linux-gnueabihf-gcc HOST_CC="gcc -m32"' - packages: 'gcc-arm-linux-gnueabihf libc6-dev-armhf-cross lib32gcc-12-dev libc6-dev-i386 linux-libc-dev:i386 qemu-user-static' - multiarch_i386: true + multiarch: 'armhf i386' + packages: 'gcc-arm-linux-gnueabihf libc6-dev-armhf-cross lib32gcc-12-dev libc6-dev-i386 linux-libc-dev:i386 qemu-user-static libx11-dev:armhf libxrandr-dev:armhf libxinerama-dev:armhf libxcursor-dev:armhf libxi-dev:armhf libgl-dev:armhf' steps: - name: Checkout uses: https://data.forgejo.org/actions/checkout@v4 @@ -81,9 +84,16 @@ jobs: - name: Install toolchain run: | set -eu - # Only armv7: linux-libc-dev:i386 provides its 32-bit asm/ headers. - if [ '${{ matrix.multiarch_i386 }}' = 'true' ]; then - dpkg --add-architecture i386 + # raylib's GLFW backend needs the X11/GL headers even when only a + # static archive is produced, and the final link needs the target's + # libX11/libGL stubs. Cross jobs therefore install the *foreign* arch + # dev packages; only the native job installs the host's. + # armv7 additionally needs linux-libc-dev:i386 for its 32-bit host + # tools (gcc -m32), hence two foreign arches there. + if [ -n '${{ matrix.multiarch }}' ]; then + for arch in ${{ matrix.multiarch }}; do + dpkg --add-architecture "$arch" + done fi apt-get update -qq apt-get install -y --no-install-recommends \ @@ -99,6 +109,12 @@ jobs: readelf -h ./hate-no-d | grep -F 'Machine:' | grep -F '${{ matrix.machine }}' echo "architecture ok: ${{ matrix.machine }}" + # The parser tables are generated into build/api from the pinned raylib + # headers, so assert they still reproduce the shipped binding byte for + # byte before it goes into a release archive. + - name: Verify bindings + run: make check-bindings + - name: Package run: sh .forgejo/scripts/make-archive.sh "hate-no-d-linux-${{ matrix.arch }}" tar.gz ./hate-no-d ./hate-no-d.lua @@ -270,8 +286,18 @@ jobs: file "./$bin" | grep -q 'for MS Windows' deps=$(${{ matrix.arch }}-w64-mingw32-objdump -p "./$bin" | awk '/DLL Name/{print $3}') echo "$deps" - bad=$(printf '%s\n' "$deps" | grep -v -E '^(KERNEL32|msvcrt)\.dll$' || true) + # raylib imports the Win32 system DLLs (gdi32/user32/shell32/winmm) + # plus what the mingw link records (advapi32/ole32/...); anything + # outside that set is a toolchain DLL leaking into a release. Names + # are case-insensitive: mingw writes WINMM.dll, not winmm.dll. + # (opengl32 is in the list for the MSVC path, where it does appear.) + bad=$(printf '%s\n' "$deps" | grep -viE '^(kernel32|gdi32|user32|shell32|winmm|opengl32|advapi32|ole32|oleaut32|uuid|msvcrt|api-ms-win-[a-z0-9-]+)\.dll$' || true) [ -z "$bad" ] || { echo "unexpected runtime DLL dependency: $bad" >&2; exit 1; } + # raylib loads GL through the driver at runtime, so there is no + # opengl32 import to assert; what must hold is that ffi.C can resolve + # raylib through the exe's export table (PE has no --export-dynamic). + ${{ matrix.arch }}-w64-mingw32-objdump -p "./$bin" | grep -qw InitWindow \ + || { echo "hate-no-d.exe does not export raylib symbols" >&2; exit 1; } - name: Package run: | diff --git a/.gitignore b/.gitignore index 298f7e7..17f2f14 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,10 @@ hate-no-d-*/ hate-no-d-*.tar.gz hate-no-d-*.zip -# Build artifacts. +# Build artifacts: objects, the host rlparser, generated parser tables, and +# build.bat's CMake trees. The CLI and hate-no-d.lua stay in the root. +/build/ + +# Stray objects from an out-of-tree compile. *.o *.obj diff --git a/Makefile b/Makefile index ea470b5..67981b7 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,19 @@ # hate-no-d # -# Native platforms are auto-detected from uname. Cross targets are selected explicitly: +# Native platforms are auto-detected from uname. Cross targets are explicit: # make -# make PLATFORM=Android ANDROID_NDK=/opt/android-ndk -# make PLATFORM=Android ANDROID_NDK=... ANDROID_ABI=armeabi-v7a ANDROID_API=21 +# make PLATFORM=Android ANDROID_NDK=/opt/android-ndk [ANDROID_ABI=... ANDROID_API=...] # make PLATFORM=Windows WIN_ARCH=x86_64 (cross build with mingw-w64) # # Targets: # make the CLI (hate-no-d or hate-no-d.exe) # make help every target and option # -# raylib is linked into the CLI. +# raylib is linked into the CLI. Objects, rlparser and its generated API tables +# go to build/; only the CLI and hate-no-d.lua land in the repository root. +# raylib and LuaJIT build in their own trees (both gitignore their output). -# luajit requires GNU Make (use `gmake` on FreeBSD/OpenBSD/NetBSD). -# The guard below only runs under GNU make; BSD make fails earlier. +# luajit requires GNU Make. BSD make fails on .FEATURES before this guard. ifndef .FEATURES $(error This build requires GNU Make -- on BSD use 'gmake') endif @@ -26,14 +26,19 @@ LUAJIT_AR := $(LUAJIT_SRC)/libluajit.a RAYLIB_DIR := submodules/raylib RAYLIB_SRC := $(RAYLIB_DIR)/src RAYLIB_AR := $(RAYLIB_SRC)/libraylib.a -RAYLIB_API := $(RAYLIB_DIR)/tools/rlparser/output/raylib_api.lua RLPARSER_DIR := $(RAYLIB_DIR)/tools/rlparser -RLPARSER := $(RLPARSER_DIR)/rlparser -API_DIR := $(RLPARSER_DIR)/output -BINDING := hate-no-d.lua -OBJ := hate-no-d.o +BUILD_DIR := build +API_DIR := $(BUILD_DIR)/api +RLPARSER := $(BUILD_DIR)/rlparser +RAYLIB_API := $(API_DIR)/raylib_api.lua +BINDING := hate-no-d.lua +OBJ := $(BUILD_DIR)/hate-no-d.o BIN := hate-no-d +GEN_FLAGS := --raylib=$(API_DIR)/raylib_api.lua \ + --rlgl=$(API_DIR)/rlgl_api.lua \ + --raymath=$(API_DIR)/raymath_api.lua + # Archiver passed to raylib's build. Cross toolchains ship their own. AR ?= ar @@ -89,13 +94,9 @@ ifeq ($(OS_KIND),bsd) LINK_TARGET := $(BIN) endif -# Windows (PE, cross-compiled from a POSIX host with mingw-w64) -# -# Native builds use build.bat. -# -# 64-bit targets build on any 64-bit host. i686 also needs a 32-bit host -# compiler, because LuaJIT's buildvm runs natively and its pointer size must -# match the target: +# Windows (PE, cross-compiled from a POSIX host with mingw-w64; native builds use +# build.bat). i686 needs a 32-bit host compiler, since LuaJIT's buildvm runs +# natively and must match the target pointer size: # make PLATFORM=Windows WIN_ARCH=i686 HOST_CC="gcc -m32" ifeq ($(OS_KIND),windows) WIN_ARCH ?= x86_64 @@ -117,17 +118,14 @@ ifeq ($(OS_KIND),windows) # Export the exe's symbols so ffi.C can resolve raylib on Windows. EXPORT_LDFLAGS := -Wl,--export-all-symbols - # LuaJIT derives HOST_CC from CC, so label both to the sub-make: otherwise - # the host tools (minilua, buildvm) are compiled with the cross compiler. + # LuaJIT derives HOST_CC from CC: label both, or the host tools are built with + # the cross compiler. LUAJIT_EXTRA := "CC=$(CC)" "HOST_CC=$(HOST_CC)" TARGET_SYS=Windows endif -# macOS (Mach-O) -# -# ld64 exports main-executable globals by default; -export_dynamic only stops -# -dead_strip / LTO from discarding the Lua API. GC64 is mandatory on arm64. -# JIT under the hardened runtime needs MAP_JIT, which is compiled in only when -# the deployment target is >= 11.0. +# macOS (Mach-O). ld64 exports main-executable globals by default; +# -export_dynamic keeps -dead_strip/LTO from discarding the Lua API. JIT under +# the hardened runtime needs MAP_JIT, so the deployment target must be >= 11.0. ifeq ($(OS_KIND),macos) ifeq ($(origin CC),default) CC := clang @@ -143,8 +141,7 @@ ifeq ($(OS_KIND),macos) # ld64 has no --whole-archive. RAYLIB_LINK := -Wl,-force_load,$(RAYLIB_AR) - # MAP_JIT path: needed for the hardened runtime (and therefore notarization). - # Requires MACOSX_DEPLOYMENT_TARGET >= 11.0 or LuaJIT compiles it back out. + # MAP_JIT path, needed for the hardened runtime (and thus notarization). MACOSX_HRT ?= 1 ifeq ($(MACOSX_HRT),1) LUAJIT_XCFLAGS += -DLUAJIT_ENABLE_OSX_HRT @@ -219,15 +216,12 @@ ifndef LINK_TARGET $(error Unsupported platform '$(PLATFORM)' -- supported: Linux, Android, Darwin, Windows, BSD) endif -# Host compiler for build-time tools (rlparser). The Windows branch above -# already pins gcc; everywhere else 'cc' is the native compiler. +# Host compiler for build-time tools (rlparser); the Windows branch pins gcc. HOST_CC ?= cc LUAJIT ?= luajit -# raylib's RELEASE desktop build appends -O1. -O2 is a large win for CPU-bound -# code (measured 0.83s -> 0.47s on image generation here); -O3 adds nothing. -# Override with RAYLIB_OPT=..., then run `make clean` (objects are not -# flag-aware, so raylib will not rebuild by itself). +# 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. RAYLIB_OPT ?= -O2 RAYLIB_MAKE_ARGS += CUSTOM_CFLAGS="$(RAYLIB_OPT)" @@ -241,8 +235,7 @@ LUAJIT_MAKE_ARGS := BUILDMODE=static XCFLAGS="$(LUAJIT_XCFLAGS)" $(LUAJIT_EXTRA) $(LUAJIT_AR): $(MAKE) -C $(LUAJIT_SRC) $(LUAJIT_MAKE_ARGS) "LJCORE_O=ljamalg.o" libluajit.a -# raylib: static archive only; CC/AR are pinned because its Makefile defaults to -# native gcc/ar. +# raylib: static archive only; CC/AR are pinned, its Makefile defaults to host gcc/ar. $(RAYLIB_AR): $(MAKE) -C $(RAYLIB_SRC) $(RAYLIB_MAKE_ARGS) CC="$(CC)" AR="$(AR)" @@ -255,7 +248,7 @@ help: @echo " make bindings regenerate hate-no-d.lua only" @echo " make check-bindings verify hate-no-d.lua is reproducible and loads" @echo " make print-config resolved configuration for the current target" - @echo " make clean remove build artifacts, submodules included" + @echo " make clean remove build/ and submodule build artifacts" @echo " make help this text" @echo "" @echo "Options (pass as VAR=value):" @@ -277,11 +270,17 @@ help: all: $(LINK_TARGET) $(BINDING) -$(OBJ): hate-no-d.c +$(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 must be pulled in whole: nothing references it, so the linker would -# otherwise drop it and ffi.C would have nothing to resolve. +# 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) @@ -289,44 +288,41 @@ $(BIN): $(OBJ) $(LUAJIT_AR) $(RAYLIB_AR) # --------------------------------------------------------------------------- # Lua bindings (hate-no-d.lua) # -# rlparser emits plain Lua tables; gen-hate-no-d.lua turns raylib.h + rlgl.h + -# raymath.h into one ffi.cdef block, constants, wrappers and LuaCATS comments. -# The tables live in raylib's own tools output directory, next to the committed -# raylib_api.lua; there is no second copy of the parser in this repo. +# 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. # -# rlparser is built for the host with HOST_CC, never with the target CC: cross -# builds still have to execute it while generating the platform-independent -# hate-no-d.lua. +# 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. # --------------------------------------------------------------------------- -# raylib gitignores this binary; its own Makefile builds it in place when a -# fresh checkout does not have one yet. CFLAGS is pinned so a cross/target -# build's command-line flags never leak into the host tool. -$(RLPARSER): $(RLPARSER_DIR)/rlparser.c - $(MAKE) -C $(RLPARSER_DIR) CC="$(HOST_CC)" CFLAGS="-O2 -Wall -std=c99" rlparser +$(RLPARSER): $(RLPARSER_DIR)/rlparser.c | $(BUILD_DIR) + $(HOST_CC) -O2 -Wall -std=c99 -o $@ $(RLPARSER_DIR)/rlparser.c -$(API_DIR)/rlgl_api.lua: $(RLPARSER) $(RAYLIB_SRC)/rlgl.h +$(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)/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=$@ + $(LUAJIT) gen-hate-no-d.lua --out=$@ $(GEN_FLAGS) bindings: $(BINDING) -# Fail if regeneration is not byte-identical or the module does not load; also -# checks the three API families are present. +# Fail if regeneration is not byte-identical or the module does not load. check-bindings: $(BINDING) - $(LUAJIT) gen-hate-no-d.lua --out=hate-no-d.lua.tmp - cmp $(BINDING) hate-no-d.lua.tmp - rm -f hate-no-d.lua.tmp + $(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")' -# Show the resolved configuration for the current (or selected) platform. -# Useful for checking a cross build before committing to it. +# Resolved configuration for the current target; useful before a cross build. print-config: @echo "PLATFORM = $(PLATFORM)" @echo "OS_KIND = $(OS_KIND)" @@ -340,7 +336,9 @@ print-config: @echo "OBJ = $(OBJ)" @echo "HOST_CC = $(HOST_CC)" @echo "LUAJIT = $(LUAJIT)" + @echo "BUILD_DIR = $(BUILD_DIR)" @echo "API_DIR = $(API_DIR)" + @echo "RLPARSER = $(RLPARSER)" @echo "BINDING = $(BINDING)" @echo "LUAJIT_MAKE_ARGS = $(LUAJIT_MAKE_ARGS)" @echo "RAYLIB_AR = $(RAYLIB_AR)" @@ -352,8 +350,9 @@ print-config: clean: @if [ -f $(LUAJIT_DIR)/Makefile ]; then $(MAKE) -C $(LUAJIT_DIR) clean; fi @if [ -f $(RAYLIB_SRC)/Makefile ]; then $(MAKE) -C $(RAYLIB_SRC) clean; fi - rm -f $(BIN) hate-no-d.exe $(OBJ) libhate-no-d.a libhate-no-d.a.mri $(LUAJIT_AR) $(RAYLIB_AR) - rm -f $(BINDING) hate-no-d.lua.tmp - rm -f $(API_DIR)/rlgl_api.lua $(API_DIR)/raymath_api.lua + 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 $(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 diff --git a/README.md b/README.md index 0156764..51dc7e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A [Love2D](https://www.love2d.org/) antagonist. -A glorified [Makefile](./Makefile), plus a small `build.bat` for MSVC. +A glorified [Makefile](./Makefile). Should work on: @@ -14,56 +14,52 @@ Should work on: ## Quick Start -Once you have the binary, save this as `quick-start.lua`: +Save this as `quick-start.lua`: ```lua local hnd = require("hate-no-d") hnd.InitWindow(1280, 720, "hate-no-d") +hnd.SetTargetFPS(60) local text = "Your first hate-no-d application!" local fontSize = 48 -local spacing = fontSize / hnd.GetFontDefault().baseSize -local textSize = hnd.MeasureTextEx(hnd.GetFontDefault(), text, fontSize, spacing) - -local posX = (hnd.GetRenderWidth() / 2) - (textSize.x / 2) -local posY = (hnd.GetRenderHeight() / 2) - (textSize.y / 2) - while not hnd.WindowShouldClose() do + hnd.BeginDrawing() hnd.ClearBackground(hnd.SKYBLUE) - hnd.BeginDrawing() - hnd.DrawText(text, posX, posY, fontSize, hnd.DARKBLUE) + local width = hnd.MeasureText(text, fontSize) + hnd.DrawText(text, (hnd.GetScreenWidth() - width)/2, (hnd.GetScreenHeight() - fontSize)/2, fontSize, hnd.DARKBLUE) + hnd.EndDrawing() end hnd.CloseWindow() ``` -Then run it: +Run it: ```sh ./hate-no-d quick-start.lua ``` -`hate-no-d.lua` is the generated raylib/rlgl/raymath binding module. Release -archives include it next to the binary; when building from source, `make` -generates it automatically. - -On Windows, use `cmd` or PowerShell: +On Windows: ```bat hate-no-d.exe quick-start.lua ``` +`hate-no-d.lua` is the generated raylib/rlgl/raymath binding; release archives +ship it next to the binary. + ## Building -You can download precompiled builds from the [releases page](https://git.pbento.pt/pedro-bento/hate-no-d/releases). +Precompiled builds can be found on the [releases page](https://git.pbento.pt/pedro-bento/hate-no-d/releases). ### Linux prerequisites -Install a C toolchain, `git` and the OpenGL/X11 development headers: +Install a C toolchain, `git`, LuaJIT and the OpenGL/X11 headers. Debian/Ubuntu: @@ -97,46 +93,44 @@ sudo emerge --ask sys-devel/gcc dev-build/make dev-vcs/git dev-lang/luajit media ### macOS prerequisites -Install the Xcode Command Line Tools: - ```sh xcode-select --install -``` - -`make` and `clang` come with them. Install the host LuaJIT used by the binding -generator: - -```sh brew install luajit ``` +The Command Line Tools provide `make` and `clang`; LuaJIT runs the binding +generator. + ### BSD prerequisites -Install GNU Make and the X11 development headers. FreeBSD: +FreeBSD: ```sh -sudo pkg install gmake luajit libX11 libXrandr libXinerama libXi libXcursor +sudo pkg install gmake luajit libX11 libXrandr libXinerama libXi libXcursor mesa-libs ``` -On OpenBSD, NetBSD and DragonFly, install `gmake` and `luajit` with the system -package manager (`pkg_add gmake luajit`, `pkgin install gmake luajit` or -`pkg install gmake luajit`); X11 headers are usually in the base X sets, but -install the X11 libraries if they are missing. Use `gmake` instead of `make`. +On OpenBSD, NetBSD and DragonFly install `gmake`, `luajit` (`pkg_add`, `pkgin` +or `pkg`) and the X11/GL libraries if they are missing. Use `gmake` instead of +`make`. ### Android prerequisites -Android builds cross-compile from Linux or macOS. Install the Android NDK and -pass its path with `ANDROID_NDK`, or set `ANDROID_NDK_HOME`. +Cross-compile from Linux or macOS with the Android NDK, passed as `ANDROID_NDK` +or exported as `ANDROID_NDK_HOME`. ### Windows prerequisites -For MSVC, install Visual Studio 2022 with the "Desktop development with C++" workload. `build.bat` locates it automatically and uses the bundled CMake when available; raylib requires CMake 3.22 or newer, so install CMake if your VS2022 copy bundles an older version. +MSVC: install Visual Studio 2022 with the "Desktop development with C++" +workload. `build.bat` finds it. raylib needs CMake 3.22+, so install CMake if the +bundled copy is older. -For MinGW, use MSYS2 with the mingw-w64 toolchain and `make`. A native MSYS2 build is auto-detected; when cross-compiling from another host, pass `PLATFORM=Windows` (and `WIN_ARCH=i686` for 32-bit). +MinGW: use MSYS2 with the mingw-w64 toolchain and `make`. A native MSYS2 shell is +detected automatically; cross-compiling from elsewhere needs `PLATFORM=Windows` +(and `WIN_ARCH=i686` for 32-bit). ### Building from source -To build manually on Linux, macOS or a BSD, run: +Linux, macOS and the BSDs: ```sh git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git @@ -144,14 +138,10 @@ cd hate-no-d make ``` -`make` builds the CLI and regenerates `hate-no-d.lua`; the generator needs a -host `luajit` in `PATH` (override with `make LUAJIT=/path/to/luajit`). On the -BSDs, use `gmake` instead of `make`. +`make` builds the CLI and regenerates `hate-no-d.lua`, which needs a host `luajit` +in `PATH` (override with `make LUAJIT=/path/to/luajit`). On the BSDs use `gmake`. -On Windows with MinGW (MSYS2), run `make` in the MSYS2 MINGW shell. To cross-compile -from another host, run `make PLATFORM=Windows` (add `WIN_ARCH=i686` for 32-bit). - -On Windows with MSVC: +Windows with MSVC: ```bat git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git @@ -159,10 +149,12 @@ cd hate-no-d build.bat ``` -To build for Android from Linux or macOS, pass your NDK path (or set `ANDROID_NDK_HOME`): +Android from Linux or macOS: ```sh make PLATFORM=Android ANDROID_NDK=/path/to/ndk ``` -`ANDROID_ABI` defaults to `arm64-v8a` and `ANDROID_API` to `21`; see `make help` for the other ABIs. Building `armeabi-v7a` on a 64-bit host also needs `HOST_CC="gcc -m32"`. +`ANDROID_ABI` defaults to `arm64-v8a` and `ANDROID_API` to `21`; `make help` lists +the other ABIs. Building `armeabi-v7a` on a 64-bit host also needs +`HOST_CC="gcc -m32"`. diff --git a/build.bat b/build.bat index 3831531..51ef00b 100644 --- a/build.bat +++ b/build.bat @@ -106,12 +106,13 @@ if not exist "%RAYLIB_BUILD%\lib\raylib.lib" ( ) echo === Building hate-no-d.exe === -if exist hate-no-d.obj del /q hate-no-d.obj +if not exist "build" mkdir "build" +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 ^ - /I "submodules\luajit\src" /Fo"hate-no-d.obj" hate-no-d.c + /I "submodules\luajit\src" /Fo"build\hate-no-d.obj" hate-no-d.c if errorlevel 1 goto :fail -link /nologo /OUT:hate-no-d.exe hate-no-d.obj ^ +link /nologo /OUT:hate-no-d.exe "build\hate-no-d.obj" ^ "/WHOLEARCHIVE:%CD%\%RAYLIB_BUILD%\lib\raylib.lib" ^ "submodules\luajit\src\lua51.lib" ^ opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib advapi32.lib @@ -124,7 +125,7 @@ if errorlevel 1 ( goto :fail ) -del /q hate-no-d.obj +del /q "build\hate-no-d.obj" echo. echo === Built %CD%\hate-no-d.exe === @@ -134,7 +135,10 @@ exit /b 0 :clean echo === Cleaning === -for %%f in (hate-no-d.exe hate-no-d.obj) do if exist "%%f" del /q "%%f" +rem Every build product lives under build\ or in the submodules' own trees; +rem only hate-no-d.exe is left at the root by a build. +if exist "hate-no-d.exe" del /q "hate-no-d.exe" +if exist "hate-no-d.obj" del /q "hate-no-d.obj" if exist "submodules\luajit\src" ( pushd "submodules\luajit\src" >nul for %%f in (lua51.lib lua51.dll luajit.exe minilua.exe buildvm.exe) do if exist "%%f" del /q "%%f" diff --git a/gen-hate-no-d.lua b/gen-hate-no-d.lua index 566cd39..acf304b 100644 --- a/gen-hate-no-d.lua +++ b/gen-hate-no-d.lua @@ -10,11 +10,16 @@ The generated file contains: asset structs (Image*, Mesh*, ...) and callback pinning * complete LuaCATS annotations (---@class / @field / @param / @return) -Inputs are plain Lua tables produced by raylib's tools/rlparser: +Inputs are plain Lua tables produced by raylib's tools/rlparser. The Makefile +generates them into build/api (the parser itself into build/rlparser), so a +build never writes into raylib's tools/ tree: - rlparser -i raylib.h -o submodules/raylib/tools/rlparser/output/raylib_api.lua -f LUA - rlparser -i rlgl.h -o submodules/raylib/tools/rlparser/output/rlgl_api.lua -f LUA -d RLAPI -t "RLGL IMPLEMENTATION" - rlparser -i raymath.h -o submodules/raylib/tools/rlparser/output/raymath_api.lua -f LUA -d RMAPI + build/rlparser -i submodules/raylib/src/raylib.h \ + -o build/api/raylib_api.lua -f LUA -d RLAPI + build/rlparser -i submodules/raylib/src/rlgl.h \ + -o build/api/rlgl_api.lua -f LUA -d RLAPI -t "RLGL IMPLEMENTATION" + build/rlparser -i submodules/raylib/src/raymath.h \ + -o build/api/raymath_api.lua -f LUA -d RMAPI Usage: luajit gen-hate-no-d.lua [--out=hate-no-d.lua] [--no-rlgl] [--no-raymath] @@ -27,9 +32,9 @@ with --whole-archive exposes them to ffi.C. ]] local CFG = { - raylib = "submodules/raylib/tools/rlparser/output/raylib_api.lua", - rlgl = "submodules/raylib/tools/rlparser/output/rlgl_api.lua", - raymath = "submodules/raylib/tools/rlparser/output/raymath_api.lua", + raylib = "build/api/raylib_api.lua", + rlgl = "build/api/rlgl_api.lua", + raymath = "build/api/raymath_api.lua", out = "hate-no-d.lua", use_rlgl = true, use_raymath = true, @@ -39,9 +44,9 @@ 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: submodules/.../raylib_api.lua) - --rlgl=PATH rlgl parser table (default: submodules/.../rlgl_api.lua) - --raymath=PATH raymath parser table(default: submodules/.../raymath_api.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