Add raylib #3
12 changed files with 12807 additions and 226 deletions
|
|
@ -1,11 +1,8 @@
|
|||
#!/bin/sh
|
||||
# Build hate-no-d inside a FreeBSD VM and copy the binary and the static
|
||||
# library back.
|
||||
# Build hate-no-d inside a FreeBSD VM and copy the binary back.
|
||||
#
|
||||
# freebsd-build.sh <output-file> [source-dir]
|
||||
#
|
||||
# The archive lands next to <output-file> as libhate-no-d.a.
|
||||
#
|
||||
# Needs qemu-system-x86, cloud-image-utils, openssh-client, xz and curl, plus
|
||||
# /dev/kvm (act_runner: options: "--device /dev/kvm"); under TCG the boot takes
|
||||
# many minutes. The guest runs with -snapshot, so nothing persists.
|
||||
|
|
@ -21,12 +18,13 @@ if [ $# -lt 1 ]; then
|
|||
echo "usage: $0 <output-file> [source-dir]" >&2
|
||||
exit 2
|
||||
fi
|
||||
# Both paths are resolved before the cd into $WORK below: a relative output
|
||||
# directory would otherwise be created under the work dir, and the artifact
|
||||
# copy would look for it there.
|
||||
OUT_DIR=$(dirname "$1")
|
||||
mkdir -p "$OUT_DIR"
|
||||
OUT=$(cd "$OUT_DIR" && pwd)/$(basename "$1")
|
||||
# Absolute: the script cd's into $WORK below, so a relative path would land there
|
||||
# instead of next to $OUT.
|
||||
LIB_OUT=$(dirname "$OUT")/libhate-no-d.a
|
||||
OUT_DIR=$(cd "$OUT_DIR" && pwd)
|
||||
OUT="$OUT_DIR/$(basename "$1")"
|
||||
SRC=$(cd "${2:-.}" && pwd)
|
||||
|
||||
WORK="${FBSD_WORK:-${TMPDIR:-/tmp}/fbsd-ci}"
|
||||
|
|
@ -115,13 +113,16 @@ 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 >/dev/null 2>&1; gmake --version | head -1'
|
||||
log "installing gmake, luajit and the X11/GL prerequisites in guest"
|
||||
# libglvnd, not mesa-libs: raylib's GL 3.3 path uses its bundled GLAD loader, so
|
||||
# only libGL.so is needed for the link. mesa-libs pulls llvm19 (~1 GB) and fills
|
||||
# the cloud image's root filesystem.
|
||||
ssh_vm 'set -e; env ASSUME_ALWAYS_YES=yes pkg install -y gmake luajit libX11 libXrandr libXinerama libXi libXcursor libglvnd >/dev/null; gmake --version | head -1'
|
||||
|
||||
log "transferring source"
|
||||
tar czf "$WORK/src.tar.gz" -C "$SRC" \
|
||||
--exclude=.git --exclude=.build --exclude=hate-no-d \
|
||||
--exclude='*.o' --exclude='*.a' --exclude='*.so' .
|
||||
--exclude=.git --exclude=.build --exclude=build --exclude=hate-no-d \
|
||||
--exclude=hate-no-d.lua --exclude='*.o' --exclude='*.a' --exclude='*.so' .
|
||||
scp $SCP_OPTS "$WORK/src.tar.gz" "root@127.0.0.1:/root/src.tar.gz"
|
||||
|
||||
# FreeBSD has no gcc: CC must be on the command line to reach the sub-make.
|
||||
|
|
@ -131,11 +132,10 @@ ssh_vm 'set -e
|
|||
tar xzf /root/src.tar.gz -C /root/src
|
||||
cd /root/src
|
||||
gmake CC=cc clean >/dev/null 2>&1 || true
|
||||
gmake CC=cc all lib'
|
||||
gmake CC=cc all'
|
||||
|
||||
log "fetching artifacts"
|
||||
log "fetching artifact"
|
||||
scp $SCP_OPTS "root@127.0.0.1:/root/src/hate-no-d" "$OUT"
|
||||
scp $SCP_OPTS "root@127.0.0.1:/root/src/libhate-no-d.a" "$LIB_OUT"
|
||||
scp $SCP_OPTS "root@127.0.0.1:/root/src/hate-no-d.lua" "$OUT_DIR/hate-no-d.lua"
|
||||
|
||||
log "built $OUT ($(wc -c < "$OUT") bytes)"
|
||||
log "built $LIB_OUT ($(wc -c < "$LIB_OUT") bytes)"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Apple targets (macOS + iOS), kept out of release.yml: they need a `macos`
|
||||
# runner. Gating them there with `if: vars.*` does not work -- Forgejo does not
|
||||
# evaluate `vars` in `if:`, so the jobs queued forever and the run never
|
||||
# finished. Manual dispatch only, until a Mac runner exists.
|
||||
# macOS, kept out of release.yml: it needs a `macos` runner. Gating it there
|
||||
# with `if: vars.*` does not work -- Forgejo does not evaluate `vars` in `if:`,
|
||||
# so the job queued forever and the run never finished. Manual dispatch only,
|
||||
# until a Mac runner exists.
|
||||
name: apple
|
||||
|
||||
on:
|
||||
|
|
@ -40,12 +40,15 @@ jobs:
|
|||
- name: Fetch submodules
|
||||
run: git submodule update --init --recursive
|
||||
|
||||
- name: Install LuaJIT
|
||||
run: brew install luajit
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
make \
|
||||
CFLAGS="-O2 -Wall -arch ${{ matrix.arch }}" \
|
||||
LUAJIT_EXTRA="TARGET_FLAGS=-arch ${{ matrix.arch }}" \
|
||||
all lib
|
||||
all
|
||||
|
||||
- name: Verify architecture
|
||||
run: |
|
||||
|
|
@ -56,42 +59,8 @@ jobs:
|
|||
- name: Package
|
||||
run: |
|
||||
sh .forgejo/scripts/make-archive.sh "hate-no-d-macos-${{ matrix.arch }}" tar.gz \
|
||||
./hate-no-d ./libhate-no-d.a
|
||||
./hate-no-d ./hate-no-d.lua
|
||||
|
||||
- name: Attach to release
|
||||
if: github.event.inputs.tag != ''
|
||||
run: sh .forgejo/scripts/release-asset.sh "./hate-no-d-macos-${{ matrix.arch }}.tar.gz"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# iOS. Builds only the archive (JIT compiled out) for an Xcode app target.
|
||||
# ---------------------------------------------------------------------------
|
||||
ios:
|
||||
name: ios/arm64
|
||||
runs-on: macos
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://data.forgejo.org/actions/checkout@v4
|
||||
with:
|
||||
submodules: false
|
||||
|
||||
- name: Fetch submodules
|
||||
run: git submodule update --init --recursive
|
||||
|
||||
- name: Build static library
|
||||
run: make PLATFORM=iOS IOS_ARCH=arm64 all lib
|
||||
|
||||
- name: Verify archive
|
||||
run: |
|
||||
set -eu
|
||||
# libhate-no-d.a is what ships; it must be single-arch arm64 Mach-O.
|
||||
lipo -info ./libhate-no-d.a
|
||||
lipo -info ./libhate-no-d.a | grep -q arm64
|
||||
|
||||
- name: Package
|
||||
# Only a static archive ships here: iOS forbids JIT, so libhate-no-d.a is
|
||||
# the deliverable to link into an Xcode target. There is no binary.
|
||||
run: sh .forgejo/scripts/make-archive.sh hate-no-d-ios-arm64 tar.gz ./libhate-no-d.a
|
||||
|
||||
- name: Attach to release
|
||||
if: github.event.inputs.tag != ''
|
||||
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d-ios-arm64.tar.gz
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
# Windows), each unpacking to a directory of the same name holding the binary
|
||||
# plus LICENSE and README.md. Release attachments are a flat list with no
|
||||
# folders, so the archive is what groups a target's files together.
|
||||
# macOS/iOS live in apple.yml; everything here builds on the Linux runner.
|
||||
# macOS lives in apple.yml; everything here builds on the Linux runner.
|
||||
name: release
|
||||
|
||||
on:
|
||||
|
|
@ -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,16 +84,23 @@ 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 \
|
||||
make gcc libc6-dev binutils jq curl ca-certificates ${{ matrix.packages }}
|
||||
make gcc libc6-dev binutils jq curl ca-certificates luajit ${{ matrix.packages }}
|
||||
|
||||
- name: Build
|
||||
run: make ${{ matrix.make_args }} all lib
|
||||
run: make ${{ matrix.make_args }} all
|
||||
|
||||
# A mis-set CC silently yields a host binary, so check the ELF machine.
|
||||
- name: Verify architecture
|
||||
|
|
@ -99,8 +109,14 @@ 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 ./libhate-no-d.a
|
||||
run: sh .forgejo/scripts/make-archive.sh "hate-no-d-linux-${{ matrix.arch }}" tar.gz ./hate-no-d ./hate-no-d.lua
|
||||
|
||||
- name: Attach to release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
|
|
@ -134,7 +150,7 @@ jobs:
|
|||
set -eu
|
||||
apt-get update -qq
|
||||
apt-get install -y --no-install-recommends \
|
||||
make gcc libc6-dev binutils jq curl ca-certificates unzip \
|
||||
make gcc libc6-dev binutils jq curl ca-certificates unzip luajit \
|
||||
gcc-multilib libc6-dev-i386
|
||||
|
||||
- name: Install NDK r27c
|
||||
|
|
@ -155,15 +171,14 @@ jobs:
|
|||
make clean >/dev/null 2>&1 || true
|
||||
if [ "$abi" = armeabi-v7a ]; then
|
||||
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
||||
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all lib
|
||||
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all
|
||||
else
|
||||
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
||||
ANDROID_ABI="$abi" HOST_CC=gcc all lib
|
||||
ANDROID_ABI="$abi" HOST_CC=gcc all
|
||||
fi
|
||||
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -E 'AArch64|ARM|X86-64'
|
||||
mkdir -p "dist/$abi"
|
||||
cp ./hate-no-d "dist/$abi/hate-no-d"
|
||||
cp ./libhate-no-d.a "dist/$abi/libhate-no-d.a"
|
||||
done
|
||||
|
||||
- name: Package
|
||||
|
|
@ -171,7 +186,7 @@ jobs:
|
|||
set -eu
|
||||
for abi in arm64-v8a armeabi-v7a x86_64; do
|
||||
sh .forgejo/scripts/make-archive.sh "hate-no-d-android-$abi" tar.gz \
|
||||
"dist/$abi/hate-no-d" "dist/$abi/libhate-no-d.a"
|
||||
"dist/$abi/hate-no-d" ./hate-no-d.lua
|
||||
done
|
||||
|
||||
- name: Attach to release
|
||||
|
|
@ -215,10 +230,12 @@ jobs:
|
|||
mkdir -p dist
|
||||
sh .forgejo/scripts/freebsd-build.sh dist/hate-no-d .
|
||||
|
||||
# Both artifacts come back from the guest (the VM builds its own
|
||||
# hate-no-d.lua), so package dist/, not the checked-out copy.
|
||||
- name: Package
|
||||
run: |
|
||||
sh .forgejo/scripts/make-archive.sh hate-no-d-freebsd-x86_64 tar.gz \
|
||||
dist/hate-no-d dist/libhate-no-d.a
|
||||
dist/hate-no-d dist/hate-no-d.lua
|
||||
|
||||
- name: Attach to release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
|
|
@ -259,10 +276,10 @@ jobs:
|
|||
set -eu
|
||||
apt-get update -qq
|
||||
apt-get install -y --no-install-recommends \
|
||||
make gcc libc6-dev gcc-multilib mingw-w64 jq zip
|
||||
make gcc libc6-dev gcc-multilib mingw-w64 jq zip luajit
|
||||
|
||||
- name: Build
|
||||
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all lib
|
||||
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all
|
||||
|
||||
- name: Verify executable
|
||||
run: |
|
||||
|
|
@ -271,13 +288,23 @@ 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: |
|
||||
sh .forgejo/scripts/make-archive.sh "hate-no-d-windows-${{ matrix.arch }}" zip \
|
||||
./hate-no-d.exe ./libhate-no-d.a
|
||||
./hate-no-d.exe ./hate-no-d.lua
|
||||
|
||||
- name: Attach to release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
|
|
|
|||
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -7,7 +7,10 @@ hate-no-d-*/
|
|||
hate-no-d-*.tar.gz
|
||||
hate-no-d-*.zip
|
||||
|
||||
# Build artifacts (make lib).
|
||||
# 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
|
||||
*.mri
|
||||
libhate-no-d.a
|
||||
*.obj
|
||||
|
|
|
|||
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +1,6 @@
|
|||
[submodule "submodules/luajit"]
|
||||
path = submodules/luajit
|
||||
url = https://luajit.org/git/luajit.git
|
||||
[submodule "submodules/raylib"]
|
||||
path = submodules/raylib
|
||||
url = https://github.com/raysan5/raylib.git
|
||||
|
|
|
|||
6
.luarc.json
Normal file
6
.luarc.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
|
||||
"runtime.version": "LuaJIT",
|
||||
"workspace.checkThirdParty": false,
|
||||
"workspace.library": ["./hate-no-d.lua"]
|
||||
}
|
||||
317
Makefile
317
Makefile
|
|
@ -1,18 +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=iOS IOS_ARCH=arm64 IOS_MIN=12.0
|
||||
# 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 / libluajit.a on iOS)
|
||||
# make lib libhate-no-d.a, for embedding into another program
|
||||
# make the CLI (hate-no-d or hate-no-d.exe)
|
||||
# make help every target and option
|
||||
#
|
||||
# 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).
|
||||
# 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
|
||||
|
|
@ -22,21 +23,23 @@ endif
|
|||
LUAJIT_DIR := submodules/luajit
|
||||
LUAJIT_SRC := $(LUAJIT_DIR)/src
|
||||
LUAJIT_AR := $(LUAJIT_SRC)/libluajit.a
|
||||
OBJ := hate-no-d.o
|
||||
RAYLIB_DIR := submodules/raylib
|
||||
RAYLIB_SRC := $(RAYLIB_DIR)/src
|
||||
RAYLIB_AR := $(RAYLIB_SRC)/libraylib.a
|
||||
RLPARSER_DIR := $(RAYLIB_DIR)/tools/rlparser
|
||||
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
|
||||
LIB := libhate-no-d.a
|
||||
|
||||
# Everything that goes into $(LIB) besides LuaJIT itself. Empty today: the only
|
||||
# C in the tree is the CLI driver, and its main() belongs to the executable an
|
||||
# embedder already has, not to a library (a -all_load/--whole-archive link would
|
||||
# collide). Runtime modules added later get listed here, e.g.
|
||||
# LIB_OBJS += hnod.o
|
||||
# and are merged into the archive automatically -- that is why the archive has
|
||||
# a name of its own instead of just being LuaJIT's.
|
||||
LIB_OBJS :=
|
||||
GEN_FLAGS := --raylib=$(API_DIR)/raylib_api.lua \
|
||||
--rlgl=$(API_DIR)/rlgl_api.lua \
|
||||
--raymath=$(API_DIR)/raymath_api.lua
|
||||
|
||||
# Archiver used to merge $(LIB). Cross toolchains ship their own; Apple has no
|
||||
# `ar -M`, so those targets use libtool instead (see the $(LIB) rule).
|
||||
# Archiver passed to raylib's build. Cross toolchains ship their own.
|
||||
AR ?= ar
|
||||
|
||||
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
|
||||
|
|
@ -51,49 +54,60 @@ else ifeq ($(PLATFORM),Android)
|
|||
OS_KIND := android
|
||||
else ifeq ($(PLATFORM),Darwin)
|
||||
OS_KIND := macos
|
||||
else ifeq ($(PLATFORM),iOS)
|
||||
OS_KIND := ios
|
||||
else ifeq ($(PLATFORM),Windows)
|
||||
OS_KIND := windows
|
||||
else ifneq (,$(filter $(PLATFORM),FreeBSD OpenBSD NetBSD DragonFly GNU/kFreeBSD))
|
||||
OS_KIND := bsd
|
||||
else ifneq (,$(filter MINGW% MSYS% CYGWIN%,$(PLATFORM)))
|
||||
# Native MinGW/MSYS2/Cygwin shell: uname reports e.g. MINGW64_NT-10.0.
|
||||
OS_KIND := windows
|
||||
PLATFORM := Windows
|
||||
MINGW_ARCH := $(shell uname -m)
|
||||
ifeq ($(MINGW_ARCH),amd64)
|
||||
WIN_ARCH ?= x86_64
|
||||
else ifeq ($(MINGW_ARCH),x86)
|
||||
WIN_ARCH ?= i686
|
||||
else
|
||||
OS_KIND := posix
|
||||
WIN_ARCH ?= $(MINGW_ARCH)
|
||||
endif
|
||||
else ifneq (,$(filter $(PLATFORM),FreeBSD OpenBSD NetBSD DragonFly))
|
||||
OS_KIND := bsd
|
||||
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)
|
||||
ifeq ($(OS_KIND),linux)
|
||||
EXPORT_LDFLAGS := -Wl,-E
|
||||
PLAT_LIBS := -lm -ldl
|
||||
PLAT_LIBS := -lm -ldl -lGL -lX11 -lpthread -lrt
|
||||
LINK_TARGET := $(BIN)
|
||||
endif
|
||||
|
||||
# BSD (ELF or Mach-O, dlopen lives in libc)
|
||||
# BSD (ELF, dlopen lives in libc)
|
||||
ifeq ($(OS_KIND),bsd)
|
||||
EXPORT_LDFLAGS := -Wl,-E
|
||||
PLAT_LIBS := -lm
|
||||
# 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
|
||||
ifneq (,$(filter OpenBSD NetBSD,$(PLATFORM)))
|
||||
BSD_LIBDIRS += -L/usr/pkg/lib -L/usr/X11R6/lib -L/usr/X11R7/lib
|
||||
endif
|
||||
PLAT_LIBS := $(BSD_LIBDIRS) -lm -lGL -lpthread \
|
||||
-lX11 -lXrandr -lXinerama -lXi -lXcursor
|
||||
ifneq (,$(filter $(PLATFORM),OpenBSD NetBSD))
|
||||
PLAT_LIBS += -lossaudio
|
||||
endif
|
||||
LINK_TARGET := $(BIN)
|
||||
endif
|
||||
|
||||
# Generic POSIX fallback (Solaris/illumos, AIX, Haiku, ...).
|
||||
# Note: Solaris ld's -E is NOT --export-dynamic, so it is deliberately off.
|
||||
ifeq ($(OS_KIND),posix)
|
||||
EXPORT_LDFLAGS :=
|
||||
PLAT_LIBS := -lm
|
||||
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"
|
||||
#
|
||||
# No export table: ffi.C resolves through msvcrt/kernel32 handles on Windows,
|
||||
# unlike ELF where the Lua API has to be exported with -Wl,-E.
|
||||
ifeq ($(OS_KIND),windows)
|
||||
WIN_ARCH ?= x86_64
|
||||
|
||||
|
|
@ -104,21 +118,24 @@ ifeq ($(OS_KIND),windows)
|
|||
CC := $(WIN_ARCH)-w64-mingw32-gcc
|
||||
AR := $(WIN_ARCH)-w64-mingw32-ar
|
||||
HOST_CC ?= gcc
|
||||
PLAT_LIBS := -lm
|
||||
PLAT_LIBS := -lm -lopengl32 -lgdi32 -lwinmm
|
||||
BIN := $(BIN).exe
|
||||
LINK_TARGET := $(BIN)
|
||||
|
||||
# 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.
|
||||
# raylib detects the host's OS, so pin the target for cross builds.
|
||||
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC PLATFORM_OS=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: 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
|
||||
|
|
@ -127,11 +144,14 @@ ifeq ($(OS_KIND),macos)
|
|||
export MACOSX_DEPLOYMENT_TARGET
|
||||
|
||||
EXPORT_LDFLAGS := -Wl,-export_dynamic
|
||||
PLAT_LIBS := -lm
|
||||
PLAT_LIBS := -lm -framework OpenGL -framework Cocoa -framework IOKit \
|
||||
-framework CoreAudio -framework CoreVideo -framework QuartzCore
|
||||
LINK_TARGET := $(BIN)
|
||||
|
||||
# MAP_JIT path: needed for the hardened runtime (and therefore notarization).
|
||||
# Requires MACOSX_DEPLOYMENT_TARGET >= 11.0 or LuaJIT compiles it back out.
|
||||
# ld64 has no --whole-archive.
|
||||
RAYLIB_LINK := -Wl,-force_load,$(RAYLIB_AR)
|
||||
|
||||
# MAP_JIT path, needed for the hardened runtime (and thus notarization).
|
||||
MACOSX_HRT ?= 1
|
||||
ifeq ($(MACOSX_HRT),1)
|
||||
LUAJIT_XCFLAGS += -DLUAJIT_ENABLE_OSX_HRT
|
||||
|
|
@ -151,6 +171,10 @@ ifeq ($(OS_KIND),android)
|
|||
$(error PLATFORM=Android requires ANDROID_NDK (or ANDROID_NDK_HOME) to be set)
|
||||
endif
|
||||
|
||||
ifneq (,$(filter MINGW% MSYS% CYGWIN%,$(shell uname -s)))
|
||||
$(error PLATFORM=Android must be built from a Linux or macOS host)
|
||||
endif
|
||||
|
||||
ifeq ($(ANDROID_ABI),arm64-v8a)
|
||||
ANDROID_TRIPLET := aarch64-linux-android
|
||||
else ifeq ($(ANDROID_ABI),armeabi-v7a)
|
||||
|
|
@ -172,46 +196,45 @@ ifeq ($(OS_KIND),android)
|
|||
ANDROID_BIN := $(ANDROID_NDK)/toolchains/llvm/prebuilt/$(ANDROID_HOST_TAG)/bin
|
||||
ANDROID_CC := $(ANDROID_BIN)/$(ANDROID_TRIPLET)$(ANDROID_API)-clang
|
||||
|
||||
ifeq ($(ANDROID_ABI),arm64-v8a)
|
||||
RAYLIB_ANDROID_ARCH := arm64
|
||||
else ifeq ($(ANDROID_ABI),armeabi-v7a)
|
||||
RAYLIB_ANDROID_ARCH := arm
|
||||
else ifeq ($(ANDROID_ABI),x86_64)
|
||||
RAYLIB_ANDROID_ARCH := x86_64
|
||||
else
|
||||
RAYLIB_ANDROID_ARCH := x86
|
||||
endif
|
||||
RAYLIB_MAKE_ARGS := PLATFORM=PLATFORM_ANDROID RAYLIB_LIBTYPE=STATIC \
|
||||
ANDROID_NDK=$(ANDROID_NDK) ANDROID_ARCH=$(RAYLIB_ANDROID_ARCH) \
|
||||
ANDROID_API_VERSION=$(ANDROID_API)
|
||||
|
||||
CC := $(ANDROID_CC)
|
||||
AR := $(ANDROID_BIN)/llvm-ar
|
||||
EXPORT_LDFLAGS := -Wl,-E
|
||||
PLAT_LIBS := -lm
|
||||
# -Wl,--wrap=fopen is raylib's APK asset hook.
|
||||
PLAT_LIBS := -lm -llog -landroid -lEGL -lGLESv2 -lOpenSLES -ldl -Wl,--wrap=fopen
|
||||
LINK_TARGET := $(BIN)
|
||||
|
||||
LUAJIT_EXTRA := CROSS=$(ANDROID_BIN)/$(ANDROID_TRIPLET)- STATIC_CC=$(ANDROID_CC) TARGET_LD=$(ANDROID_CC) "TARGET_AR=$(ANDROID_BIN)/llvm-ar rcus" TARGET_STRIP=$(ANDROID_BIN)/llvm-strip
|
||||
endif
|
||||
|
||||
# iOS (Mach-O, ARM64 only)
|
||||
#
|
||||
# There is no runnable binary: link libluajit.a into your Xcode app target.
|
||||
# The JIT is compiled out by LuaJIT itself (no runtime code generation is
|
||||
# allowed on iOS), so you get the fast interpreter only.
|
||||
ifeq ($(OS_KIND),ios)
|
||||
IOS_SDK ?= $(shell xcrun --sdk iphoneos --show-sdk-path 2>/dev/null)
|
||||
IOS_CC ?= $(shell xcrun --sdk iphoneos --find clang 2>/dev/null)
|
||||
IOS_ARCH ?= arm64
|
||||
IOS_MIN ?= 12.0
|
||||
|
||||
ifeq ($(strip $(IOS_SDK)),)
|
||||
$(error PLATFORM=iOS requires Xcode/xcrun on the build host)
|
||||
endif
|
||||
|
||||
IOS_FLAGS := -arch $(IOS_ARCH) -isysroot $(IOS_SDK) -mios-version-min=$(IOS_MIN)
|
||||
|
||||
CC := $(IOS_CC)
|
||||
EXPORT_LDFLAGS :=
|
||||
PLAT_LIBS :=
|
||||
LINK_TARGET := $(LUAJIT_AR)
|
||||
|
||||
# DEFAULT_CC keeps the host toolchain (minilua/buildvm) native; CROSS
|
||||
# switches only the target objects to the iOS SDK.
|
||||
LUAJIT_EXTRA := DEFAULT_CC=clang CROSS=$(dir $(IOS_CC)) TARGET_SYS=iOS "TARGET_FLAGS=$(IOS_FLAGS)"
|
||||
LUAJIT_EXTRA := CROSS=$(ANDROID_BIN)/$(ANDROID_TRIPLET)- \
|
||||
STATIC_CC=$(ANDROID_CC) TARGET_LD=$(ANDROID_CC) \
|
||||
"TARGET_AR=$(ANDROID_BIN)/llvm-ar rcus" \
|
||||
TARGET_STRIP=$(ANDROID_BIN)/llvm-strip TARGET_SYS=Linux
|
||||
endif
|
||||
|
||||
ifndef LINK_TARGET
|
||||
$(error Unsupported platform '$(PLATFORM)')
|
||||
$(error Unsupported platform '$(PLATFORM)' -- supported: Linux, Android, Darwin, Windows, BSD)
|
||||
endif
|
||||
|
||||
# Host compiler for build-time tools (rlparser); the Windows branch pins gcc.
|
||||
HOST_CC ?= cc
|
||||
LUAJIT ?= luajit
|
||||
|
||||
# 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)"
|
||||
|
||||
# Compiler / linker flags
|
||||
CFLAGS ?= -O2 -Wall
|
||||
CPPFLAGS += -I$(LUAJIT_SRC)
|
||||
|
|
@ -222,93 +245,125 @@ 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, its Makefile defaults to host gcc/ar.
|
||||
$(RAYLIB_AR):
|
||||
$(MAKE) -C $(RAYLIB_SRC) $(RAYLIB_MAKE_ARGS) CC="$(CC)" AR="$(AR)"
|
||||
|
||||
# Targets
|
||||
help:
|
||||
@echo "hate-no-d -- LuaJIT-based Lua runtime"
|
||||
@echo ""
|
||||
@echo "Targets:"
|
||||
@echo " make [all] CLI for the auto-detected platform (hate-no-d,"
|
||||
@echo " hate-no-d.exe, or libluajit.a on iOS)"
|
||||
@echo " make lib libhate-no-d.a: LuaJIT plus LIB_OBJS, for embedding"
|
||||
@echo " make luajit LuaJIT static archive only"
|
||||
@echo " make [all] CLI for the current platform + hate-no-d.lua"
|
||||
@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, LuaJIT's included"
|
||||
@echo " make clean remove build/ and submodule build artifacts"
|
||||
@echo " make help this text"
|
||||
@echo ""
|
||||
@echo "Options (pass as VAR=value):"
|
||||
@echo " PLATFORM= Linux | Android | Darwin | iOS | Windows | a BSD"
|
||||
@echo " PLATFORM= Linux | Android | Darwin | Windows | a BSD"
|
||||
@echo " (default: uname -s)"
|
||||
@echo " WIN_ARCH= x86_64 | i686 [Windows]"
|
||||
@echo " ANDROID_NDK= NDK root, or export ANDROID_NDK_HOME [Android]"
|
||||
@echo " ANDROID_ABI= arm64-v8a | armeabi-v7a | x86_64 | x86 [Android]"
|
||||
@echo " ANDROID_API= target API level, default 21 [Android]"
|
||||
@echo " IOS_ARCH= IOS_MIN= arm64 / 12.0 [iOS]"
|
||||
@echo " IOS_SDK= IOS_CC= Xcode paths, default from xcrun [iOS]"
|
||||
@echo " MACOSX_HRT= hardened-runtime JIT, default 1 [macOS]"
|
||||
@echo " MACOSX_DEPLOYMENT_TARGET= default 11.0 [macOS]"
|
||||
@echo " HOST_CC= host compiler for minilua/buildvm; needed"
|
||||
@echo " when the target is 32-bit and the host is not"
|
||||
@echo " LUAJIT= host LuaJIT for the generator, default luajit"
|
||||
@echo " CFLAGS= default -O2 -Wall"
|
||||
@echo " RAYLIB_OPT= raylib optimization flags, default -O2"
|
||||
@echo " LDFLAGS= extra linker flags"
|
||||
@echo " LIB_OBJS= extra objects merged into libhate-no-d.a"
|
||||
@echo " AR= archiver used to merge libhate-no-d.a"
|
||||
@echo " AR= archiver for raylib's build"
|
||||
|
||||
all: $(LINK_TARGET)
|
||||
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
|
||||
|
||||
$(BIN): $(OBJ) $(LUAJIT_AR)
|
||||
# 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) \
|
||||
$(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
||||
$(RAYLIB_LINK) $(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
||||
|
||||
luajit: $(LUAJIT_AR)
|
||||
# ---------------------------------------------------------------------------
|
||||
# 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
|
||||
|
||||
# Static library for embedding: $(LIB_OBJS) plus LuaJIT, merged into one archive
|
||||
# so a host program links a single file, and modules added to $(LIB_OBJS) later
|
||||
# join it without the host's link line changing.
|
||||
lib: $(LIB)
|
||||
$(RAYLIB_API): $(RLPARSER) $(RAYLIB_SRC)/raylib.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/raylib.h -o $@ -f LUA -d RLAPI
|
||||
|
||||
# Apple's ar (cctools) has no MRI script mode, so archives are merged with
|
||||
# libtool there. Everywhere else GNU ar, binutils ar and llvm-ar all parse MRI
|
||||
# scripts (ADDMOD for objects, ADDLIB for another archive).
|
||||
APPLE := $(filter macos ios,$(OS_KIND))
|
||||
$(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"
|
||||
|
||||
$(LIB): $(LIB_OBJS) $(LUAJIT_AR)
|
||||
ifeq ($(APPLE),)
|
||||
@rm -f $@ $@.mri
|
||||
@{ echo "CREATE $@"; \
|
||||
for o in $(LIB_OBJS); do echo "ADDMOD $$o"; done; \
|
||||
echo "ADDLIB $(LUAJIT_AR)"; \
|
||||
echo "SAVE"; echo "END"; } > $@.mri
|
||||
$(AR) -M < $@.mri
|
||||
@rm -f $@.mri
|
||||
else
|
||||
@rm -f $@
|
||||
libtool -static -o $@ $(LIB_OBJS) $(LUAJIT_AR)
|
||||
endif
|
||||
@echo "lib: built $@ ($$($(AR) t $@ | wc -l | tr -d ' ') members)"
|
||||
$(API_DIR)/raymath_api.lua: $(RLPARSER) $(RAYLIB_SRC)/raymath.h | $(API_DIR)
|
||||
$(RLPARSER) -i $(RAYLIB_SRC)/raymath.h -o $@ -f LUA -d RMAPI
|
||||
|
||||
# Show the resolved configuration for the current (or selected) platform.
|
||||
# Useful for checking a cross build before committing to it.
|
||||
$(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.
|
||||
print-config:
|
||||
@echo "PLATFORM = $(PLATFORM)"
|
||||
@echo "OS_KIND = $(OS_KIND)"
|
||||
@echo "CC / AR = $(CC) / $(AR)"
|
||||
@echo "CFLAGS = $(CFLAGS)"
|
||||
@echo "RAYLIB_OPT = $(RAYLIB_OPT)"
|
||||
@echo "CPPFLAGS = $(CPPFLAGS)"
|
||||
@echo "EXPORT_LDFLAGS = $(EXPORT_LDFLAGS)"
|
||||
@echo "PLAT_LIBS = $(PLAT_LIBS)"
|
||||
@echo "BSD_LIBDIRS = $(BSD_LIBDIRS)"
|
||||
@echo "LINK_TARGET = $(LINK_TARGET)"
|
||||
@echo "OBJ / LIB = $(OBJ) / $(LIB) [$(LIB_OBJS)]"
|
||||
@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)"
|
||||
@echo "RAYLIB_MAKE_ARGS = $(RAYLIB_MAKE_ARGS)"
|
||||
@echo "MACOSX_DEPLOYMENT_TARGET = $(MACOSX_DEPLOYMENT_TARGET) (HRT=$(MACOSX_HRT))"
|
||||
@echo "ANDROID_ABI / API = $(ANDROID_ABI) / $(ANDROID_API)"
|
||||
@echo "IOS_ARCH / MIN = $(IOS_ARCH) / $(IOS_MIN)"
|
||||
@echo "WIN_ARCH = $(WIN_ARCH) (HOST_CC=$(HOST_CC))"
|
||||
|
||||
clean:
|
||||
$(MAKE) -C $(LUAJIT_DIR) clean
|
||||
rm -f $(BIN) $(OBJ) $(LIB) $(LIB).mri
|
||||
@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 -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 luajit print-config lib help
|
||||
.PHONY: all clean print-config help bindings check-bindings
|
||||
|
|
|
|||
137
README.md
137
README.md
|
|
@ -2,25 +2,135 @@
|
|||
|
||||
A [Love2D](https://www.love2d.org/) antagonist.
|
||||
|
||||
A glorified [Makefile](./Makefile).
|
||||
|
||||
Should work on:
|
||||
|
||||
- Linux (x86, x86_64, ARM, ARM64)
|
||||
- Android (armeabi-v7a, arm64-v8a, x86, x86_64)
|
||||
- macOS (x86_64, ARM64)
|
||||
- Windows (x86, x86_64 via MinGW; ARM64 via MSVC)
|
||||
- FreeBSD, OpenBSD, NetBSD (x86, x86_64) or DragonFly BSD (x86_64)
|
||||
|
||||
## Quick Start
|
||||
|
||||
### On Linux, macOS, BSD, POSIX or Windows-MinGW
|
||||
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
|
||||
|
||||
while not hnd.WindowShouldClose() do
|
||||
hnd.BeginDrawing()
|
||||
hnd.ClearBackground(hnd.SKYBLUE)
|
||||
|
||||
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()
|
||||
```
|
||||
|
||||
Run it:
|
||||
|
||||
```sh
|
||||
echo -e 'print("Hey! I am hate-no-d!")' > quick-start.lua
|
||||
./hate-no-d quick-start.lua
|
||||
```
|
||||
|
||||
### On Windows MSVC
|
||||
On Windows:
|
||||
|
||||
```bat
|
||||
echo print("Hey! I am hate-no-d!") > quick-start.lua
|
||||
hate-no-d.exe quick-start.lua
|
||||
```
|
||||
|
||||
## Build
|
||||
`hate-no-d.lua` is the generated raylib/rlgl/raymath binding; release archives
|
||||
ship it next to the binary.
|
||||
|
||||
### On Linux, macOS, BSD, POSIX or Windows-MinGW
|
||||
## Building
|
||||
|
||||
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`, LuaJIT and the OpenGL/X11 headers.
|
||||
|
||||
Debian/Ubuntu:
|
||||
|
||||
```sh
|
||||
sudo apt install build-essential git luajit libgl1-mesa-dev libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
|
||||
```
|
||||
|
||||
Fedora:
|
||||
|
||||
```sh
|
||||
sudo dnf install gcc make git luajit mesa-libGL-devel libX11-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel
|
||||
```
|
||||
|
||||
Arch:
|
||||
|
||||
```sh
|
||||
sudo pacman -S --needed base-devel git luajit mesa libx11 libxrandr libxinerama libxcursor libxi
|
||||
```
|
||||
|
||||
Void:
|
||||
|
||||
```sh
|
||||
sudo xbps-install -S base-devel git luajit MesaLib-devel libX11-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel
|
||||
```
|
||||
|
||||
Gentoo:
|
||||
|
||||
```sh
|
||||
sudo emerge --ask sys-devel/gcc dev-build/make dev-vcs/git dev-lang/luajit media-libs/mesa x11-libs/libX11 x11-libs/libXrandr x11-libs/libXinerama x11-libs/libXcursor x11-libs/libXi
|
||||
```
|
||||
|
||||
### macOS prerequisites
|
||||
|
||||
```sh
|
||||
xcode-select --install
|
||||
brew install luajit
|
||||
```
|
||||
|
||||
The Command Line Tools provide `make` and `clang`; LuaJIT runs the binding
|
||||
generator.
|
||||
|
||||
### BSD prerequisites
|
||||
|
||||
FreeBSD:
|
||||
|
||||
```sh
|
||||
sudo pkg install gmake luajit libX11 libXrandr libXinerama libXi libXcursor libglvnd
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
Cross-compile from Linux or macOS with the Android NDK, passed as `ANDROID_NDK`
|
||||
or exported as `ANDROID_NDK_HOME`.
|
||||
|
||||
### Windows prerequisites
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
Linux, macOS and the BSDs:
|
||||
|
||||
```sh
|
||||
git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git
|
||||
|
|
@ -28,10 +138,23 @@ cd hate-no-d
|
|||
make
|
||||
```
|
||||
|
||||
### On Windows MSVC
|
||||
`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`.
|
||||
|
||||
Windows with MSVC:
|
||||
|
||||
```bat
|
||||
git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git
|
||||
cd hate-no-d
|
||||
build.bat
|
||||
```
|
||||
|
||||
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`; `make help` lists
|
||||
the other ABIs. Building `armeabi-v7a` on a 64-bit host also needs
|
||||
`HOST_CC="gcc -m32"`.
|
||||
|
|
|
|||
78
build.bat
78
build.bat
|
|
@ -7,7 +7,8 @@
|
|||
@rem
|
||||
@rem Works from a plain cmd.exe (locates Visual Studio itself) or from an
|
||||
@rem existing Developer Command Prompt. Produces hate-no-d.exe in this
|
||||
@rem directory, statically linked against LuaJIT.
|
||||
@rem directory, statically linked against LuaJIT and raylib. raylib is built
|
||||
@rem with CMake (shipped with Visual Studio) and linked in whole.
|
||||
@echo off
|
||||
setlocal EnableExtensions
|
||||
|
||||
|
|
@ -41,12 +42,18 @@ if not exist "submodules\luajit\src\msvcbuild.bat" (
|
|||
|
||||
@rem msvcbuild.bat only ever appends options in a fixed order and deletes its
|
||||
@rem own .obj files at the end, so every run is a full rebuild anyway.
|
||||
@rem Pin /MT through the CL environment so LuaJIT's static CRT matches raylib's
|
||||
@rem below; the static branch of msvcbuild.bat does not choose a runtime itself.
|
||||
echo === Building LuaJIT (static, lua52compat) for Windows/%ARCH% ===
|
||||
if exist "submodules\luajit\src\lua51.lib" del /q "submodules\luajit\src\lua51.lib"
|
||||
|
||||
set "HNOD_CL=%CL%"
|
||||
set "CL=/MT"
|
||||
pushd "submodules\luajit\src" >nul
|
||||
call msvcbuild.bat lua52compat static
|
||||
popd >nul
|
||||
set "CL=%HNOD_CL%"
|
||||
set "HNOD_CL="
|
||||
|
||||
@rem msvcbuild.bat does not set errorlevel when it fails, so the artifact is
|
||||
@rem the only trustworthy signal.
|
||||
|
|
@ -56,16 +63,69 @@ if not exist "submodules\luajit\src\lua51.lib" (
|
|||
goto :fail
|
||||
)
|
||||
|
||||
@rem raylib is built through CMake, which ships with Visual Studio.
|
||||
@rem It uses the static CRT to match LuaJIT's default msvcbuild output, and
|
||||
@rem defines BUILD_LIBTYPE_SHARED so its RLAPI functions carry dllexport and
|
||||
@rem land in the exe's export table -- MSVC has no --export-dynamic, and ffi.C
|
||||
@rem resolves C symbols through that table at runtime.
|
||||
if not exist "submodules\raylib\CMakeLists.txt" (
|
||||
echo build.bat: submodules\raylib is missing.
|
||||
echo Fetch it with: git submodule update --init submodules/raylib
|
||||
goto :fail
|
||||
)
|
||||
|
||||
where cmake >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo build.bat: cmake not found - install CMake 3.22+ or use a Developer Command Prompt.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
if /I "%ARCH%"=="x64" set "CMAKE_ARCH=x64"
|
||||
if /I "%ARCH%"=="x86" set "CMAKE_ARCH=Win32"
|
||||
if /I "%ARCH%"=="arm64" set "CMAKE_ARCH=ARM64"
|
||||
|
||||
@rem One build tree per arch: CMake refuses to reuse a cache configured for
|
||||
@rem another -A platform, so `build.bat x86` after x64 must not share it.
|
||||
set "RAYLIB_BUILD=build\raylib-%ARCH%"
|
||||
|
||||
echo === Building raylib (static) for Windows/%ARCH% ===
|
||||
cmake -S "submodules\raylib" -B "%RAYLIB_BUILD%" -A %CMAKE_ARCH% ^
|
||||
-DBUILD_SHARED_LIBS=OFF ^
|
||||
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ^
|
||||
-DCMAKE_C_FLAGS_RELEASE="/O2 /Ob2 /DNDEBUG /DBUILD_LIBTYPE_SHARED" ^
|
||||
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE="%CD%\%RAYLIB_BUILD%\lib" ^
|
||||
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG="%CD%\%RAYLIB_BUILD%\lib"
|
||||
if errorlevel 1 goto :fail
|
||||
|
||||
cmake --build "%RAYLIB_BUILD%" --config Release --target raylib
|
||||
if errorlevel 1 goto :fail
|
||||
|
||||
if not exist "%RAYLIB_BUILD%\lib\raylib.lib" (
|
||||
echo build.bat: raylib.lib was not produced.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
echo === Building hate-no-d.exe ===
|
||||
if exist hate-no-d.obj del /q hate-no-d.obj
|
||||
cl /nologo /c /O2 /W4 /D_CRT_SECURE_NO_WARNINGS ^
|
||||
/I "submodules\luajit\src" /Fo"hate-no-d.obj" hate-no-d.c
|
||||
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"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 "submodules\luajit\src\lua51.lib"
|
||||
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
|
||||
if errorlevel 1 goto :fail
|
||||
|
||||
del /q hate-no-d.obj
|
||||
@rem ffi.C reads the exe's export table, so verify raylib really got exported.
|
||||
dumpbin /nologo /exports hate-no-d.exe | findstr /C:"InitWindow" >nul
|
||||
if errorlevel 1 (
|
||||
echo build.bat: hate-no-d.exe does not export raylib - ffi.C would not find it.
|
||||
goto :fail
|
||||
)
|
||||
|
||||
del /q "build\hate-no-d.obj"
|
||||
|
||||
echo.
|
||||
echo === Built %CD%\hate-no-d.exe ===
|
||||
|
|
@ -75,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"
|
||||
|
|
@ -84,6 +147,7 @@ if exist "submodules\luajit\src" (
|
|||
del /q *.obj host\*.obj *.manifest >nul 2>&1
|
||||
popd >nul
|
||||
)
|
||||
if exist "build" rmdir /s /q "build"
|
||||
popd >nul
|
||||
endlocal
|
||||
exit /b 0
|
||||
|
|
|
|||
1190
gen-hate-no-d.lua
Normal file
1190
gen-hate-no-d.lua
Normal file
File diff suppressed because it is too large
Load diff
11140
hate-no-d.lua
Normal file
11140
hate-no-d.lua
Normal file
File diff suppressed because it is too large
Load diff
1
submodules/raylib
Submodule
1
submodules/raylib
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit ad124dd7f5864fcdd9cc8868d5baae61041a7d3c
|
||||
Loading…
Reference in a new issue