standardize_release_workflow #2
6 changed files with 233 additions and 32 deletions
|
|
@ -1,8 +1,11 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Build hate-no-d inside a FreeBSD VM and copy the binary back.
|
# Build hate-no-d inside a FreeBSD VM and copy the binary and the static
|
||||||
|
# library back.
|
||||||
#
|
#
|
||||||
# freebsd-build.sh <output-file> [source-dir]
|
# 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
|
# 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
|
# /dev/kvm (act_runner: options: "--device /dev/kvm"); under TCG the boot takes
|
||||||
# many minutes. The guest runs with -snapshot, so nothing persists.
|
# many minutes. The guest runs with -snapshot, so nothing persists.
|
||||||
|
|
@ -21,6 +24,9 @@ fi
|
||||||
OUT_DIR=$(dirname "$1")
|
OUT_DIR=$(dirname "$1")
|
||||||
mkdir -p "$OUT_DIR"
|
mkdir -p "$OUT_DIR"
|
||||||
OUT=$(cd "$OUT_DIR" && pwd)/$(basename "$1")
|
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
|
||||||
SRC=$(cd "${2:-.}" && pwd)
|
SRC=$(cd "${2:-.}" && pwd)
|
||||||
|
|
||||||
WORK="${FBSD_WORK:-${TMPDIR:-/tmp}/fbsd-ci}"
|
WORK="${FBSD_WORK:-${TMPDIR:-/tmp}/fbsd-ci}"
|
||||||
|
|
@ -125,10 +131,11 @@ ssh_vm 'set -e
|
||||||
tar xzf /root/src.tar.gz -C /root/src
|
tar xzf /root/src.tar.gz -C /root/src
|
||||||
cd /root/src
|
cd /root/src
|
||||||
gmake CC=cc clean >/dev/null 2>&1 || true
|
gmake CC=cc clean >/dev/null 2>&1 || true
|
||||||
gmake CC=cc all'
|
gmake CC=cc all lib'
|
||||||
|
|
||||||
log "fetching binary"
|
log "fetching artifacts"
|
||||||
mkdir -p "$(dirname "$OUT")"
|
|
||||||
scp $SCP_OPTS "root@127.0.0.1:/root/src/hate-no-d" "$OUT"
|
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"
|
||||||
|
|
||||||
log "built $OUT ($(wc -c < "$OUT") bytes)"
|
log "built $OUT ($(wc -c < "$OUT") bytes)"
|
||||||
|
log "built $LIB_OUT ($(wc -c < "$LIB_OUT") bytes)"
|
||||||
|
|
|
||||||
66
.forgejo/scripts/make-archive.sh
Executable file
66
.forgejo/scripts/make-archive.sh
Executable file
|
|
@ -0,0 +1,66 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Stage one release asset into a directory and pack it, so every download is a
|
||||||
|
# self-contained "folder" instead of a bare binary.
|
||||||
|
#
|
||||||
|
# make-archive.sh <asset-name> <tar.gz|zip> <payload>...
|
||||||
|
#
|
||||||
|
# asset-name e.g. hate-no-d-linux-x86_64; also the directory inside the
|
||||||
|
# archive, so unpacking never scatters files
|
||||||
|
# format tar.gz for Unix payloads (keeps the executable bit), zip for
|
||||||
|
# Windows ones
|
||||||
|
# payload files to pack, each keeping its basename
|
||||||
|
#
|
||||||
|
# LICENSE and README.md are added from the working directory when present.
|
||||||
|
# Writes ./<asset-name>.<format> and leaves the staging directory behind.
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ $# -lt 3 ]; then
|
||||||
|
echo "usage: $0 <asset-name> <tar.gz|zip> <payload>..." >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
name=$1
|
||||||
|
format=$2
|
||||||
|
shift 2
|
||||||
|
|
||||||
|
# Guard the rm -rf below.
|
||||||
|
case "$name" in
|
||||||
|
'' | */*) echo "make-archive: bad asset name: '$name'" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$format" in
|
||||||
|
tar.gz | zip) ;;
|
||||||
|
*) echo "make-archive: unknown format: '$format'" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
for f in "$@"; do
|
||||||
|
[ -f "$f" ] || { echo "make-archive: no such file: $f" >&2; exit 1; }
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -rf "$name"
|
||||||
|
mkdir -p "$name"
|
||||||
|
|
||||||
|
# The first payload is the binary: make its mode deterministic instead of
|
||||||
|
# trusting whatever the build/copy path produced.
|
||||||
|
first=1
|
||||||
|
for f in "$@"; do
|
||||||
|
cp "$f" "$name/$(basename "$f")"
|
||||||
|
if [ "$first" = 1 ]; then
|
||||||
|
chmod 755 "$name/$(basename "$f")"
|
||||||
|
first=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for f in LICENSE README.md; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
cp "$f" "$name/"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
case "$format" in
|
||||||
|
tar.gz) tar -czf "$name.tar.gz" "$name" ;;
|
||||||
|
zip) zip -qr -X "$name.zip" "$name" >/dev/null ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "make-archive: wrote $name.$format"
|
||||||
|
ls -l "$name" | sed 's/^/make-archive: /'
|
||||||
|
|
@ -45,7 +45,7 @@ jobs:
|
||||||
make \
|
make \
|
||||||
CFLAGS="-O2 -Wall -arch ${{ matrix.arch }}" \
|
CFLAGS="-O2 -Wall -arch ${{ matrix.arch }}" \
|
||||||
LUAJIT_EXTRA="TARGET_FLAGS=-arch ${{ matrix.arch }}" \
|
LUAJIT_EXTRA="TARGET_FLAGS=-arch ${{ matrix.arch }}" \
|
||||||
all
|
all lib
|
||||||
|
|
||||||
- name: Verify architecture
|
- name: Verify architecture
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -53,9 +53,14 @@ jobs:
|
||||||
file ./hate-no-d
|
file ./hate-no-d
|
||||||
file ./hate-no-d | grep -q '${{ matrix.arch }}'
|
file ./hate-no-d | grep -q '${{ matrix.arch }}'
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
run: |
|
||||||
|
sh .forgejo/scripts/make-archive.sh "hate-no-d-macos-${{ matrix.arch }}" tar.gz \
|
||||||
|
./hate-no-d ./libhate-no-d.a
|
||||||
|
|
||||||
- name: Attach to release
|
- name: Attach to release
|
||||||
if: github.event.inputs.tag != ''
|
if: github.event.inputs.tag != ''
|
||||||
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d "hate-no-d-macos-${{ matrix.arch }}"
|
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. Builds only the archive (JIT compiled out) for an Xcode app target.
|
||||||
|
|
@ -72,15 +77,21 @@ jobs:
|
||||||
- name: Fetch submodules
|
- name: Fetch submodules
|
||||||
run: git submodule update --init --recursive
|
run: git submodule update --init --recursive
|
||||||
|
|
||||||
- name: Build libluajit.a
|
- name: Build static library
|
||||||
run: make PLATFORM=iOS IOS_ARCH=arm64 all
|
run: make PLATFORM=iOS IOS_ARCH=arm64 all lib
|
||||||
|
|
||||||
- name: Verify archive
|
- name: Verify archive
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
lipo -info submodules/luajit/src/libluajit.a
|
# libhate-no-d.a is what ships; it must be single-arch arm64 Mach-O.
|
||||||
lipo -info submodules/luajit/src/libluajit.a | grep -q arm64
|
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
|
- name: Attach to release
|
||||||
if: github.event.inputs.tag != ''
|
if: github.event.inputs.tag != ''
|
||||||
run: sh .forgejo/scripts/release-asset.sh submodules/luajit/src/libluajit.a hate-no-d-ios-arm64-luajit.a
|
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d-ios-arm64.tar.gz
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,10 @@
|
||||||
# push / pull_request -> build only
|
# push / pull_request -> build only
|
||||||
# tag 'v*' -> build + release assets
|
# tag 'v*' -> build + release assets
|
||||||
#
|
#
|
||||||
# Assets: hate-no-d-linux-*, -android-*, -windows_mingw_w64-*.exe, -freebsd-x86_64.
|
# Assets: one archive per target, named hate-no-d-<os>-<arch>.tar.gz (zip on
|
||||||
|
# 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/iOS live in apple.yml; everything here builds on the Linux runner.
|
||||||
name: release
|
name: release
|
||||||
|
|
||||||
|
|
@ -87,7 +90,7 @@ jobs:
|
||||||
make gcc libc6-dev binutils jq curl ca-certificates ${{ matrix.packages }}
|
make gcc libc6-dev binutils jq curl ca-certificates ${{ matrix.packages }}
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make ${{ matrix.make_args }} all
|
run: make ${{ matrix.make_args }} all lib
|
||||||
|
|
||||||
# A mis-set CC silently yields a host binary, so check the ELF machine.
|
# A mis-set CC silently yields a host binary, so check the ELF machine.
|
||||||
- name: Verify architecture
|
- name: Verify architecture
|
||||||
|
|
@ -96,9 +99,12 @@ jobs:
|
||||||
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -F '${{ matrix.machine }}'
|
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -F '${{ matrix.machine }}'
|
||||||
echo "architecture ok: ${{ matrix.machine }}"
|
echo "architecture ok: ${{ matrix.machine }}"
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
run: sh .forgejo/scripts/make-archive.sh "hate-no-d-linux-${{ matrix.arch }}" tar.gz ./hate-no-d ./libhate-no-d.a
|
||||||
|
|
||||||
- name: Attach to release
|
- name: Attach to release
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d "hate-no-d-linux-${{ matrix.arch }}"
|
run: sh .forgejo/scripts/release-asset.sh "./hate-no-d-linux-${{ matrix.arch }}.tar.gz"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Android. One job for all ABIs so the ~630 MB NDK is downloaded once. The
|
# Android. One job for all ABIs so the ~630 MB NDK is downloaded once. The
|
||||||
|
|
@ -149,13 +155,23 @@ jobs:
|
||||||
make clean >/dev/null 2>&1 || true
|
make clean >/dev/null 2>&1 || true
|
||||||
if [ "$abi" = armeabi-v7a ]; then
|
if [ "$abi" = armeabi-v7a ]; then
|
||||||
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
||||||
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all
|
ANDROID_ABI="$abi" HOST_CC="gcc -m32" all lib
|
||||||
else
|
else
|
||||||
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
make PLATFORM=Android ANDROID_NDK="$ANDROID_NDK" ANDROID_API="$ANDROID_API" \
|
||||||
ANDROID_ABI="$abi" HOST_CC=gcc all
|
ANDROID_ABI="$abi" HOST_CC=gcc all lib
|
||||||
fi
|
fi
|
||||||
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -E 'AArch64|ARM|X86-64'
|
readelf -h ./hate-no-d | grep -F 'Machine:' | grep -E 'AArch64|ARM|X86-64'
|
||||||
cp ./hate-no-d "dist/hate-no-d-android-$abi"
|
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
|
||||||
|
run: |
|
||||||
|
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"
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Attach to release
|
- name: Attach to release
|
||||||
|
|
@ -163,7 +179,7 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
for abi in arm64-v8a armeabi-v7a x86_64; do
|
for abi in arm64-v8a armeabi-v7a x86_64; do
|
||||||
sh .forgejo/scripts/release-asset.sh "dist/hate-no-d-android-$abi" "hate-no-d-android-$abi"
|
sh .forgejo/scripts/release-asset.sh "hate-no-d-android-$abi.tar.gz"
|
||||||
done
|
done
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
@ -197,16 +213,22 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
sh .forgejo/scripts/freebsd-build.sh dist/hate-no-d-freebsd-x86_64 .
|
sh .forgejo/scripts/freebsd-build.sh dist/hate-no-d .
|
||||||
|
|
||||||
|
- 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
|
||||||
|
|
||||||
- name: Attach to release
|
- name: Attach to release
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: sh .forgejo/scripts/release-asset.sh dist/hate-no-d-freebsd-x86_64 hate-no-d-freebsd-x86_64
|
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d-freebsd-x86_64.tar.gz
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Windows. Cross-compiled with mingw-w64; no Windows machine or MSVC involved.
|
# Windows. Cross-compiled with mingw-w64; no Windows machine or MSVC involved.
|
||||||
# i686 needs a 32-bit host compiler for the native buildvm. The build stays
|
# i686 needs a 32-bit host compiler for the native buildvm. The asset is a zip
|
||||||
# hate-no-d.exe -- only the release asset name carries the toolchain.
|
# (Windows convention) holding hate-no-d.exe; the toolchain is not part of the
|
||||||
|
# name because it is not a compatibility axis for anyone downloading it.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
windows:
|
windows:
|
||||||
name: windows/${{ matrix.arch }}
|
name: windows/${{ matrix.arch }}
|
||||||
|
|
@ -218,10 +240,8 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- arch: x86_64
|
- arch: x86_64
|
||||||
tag: windows_mingw_w64-x64
|
|
||||||
host_cc: gcc
|
host_cc: gcc
|
||||||
- arch: i686
|
- arch: i686
|
||||||
tag: windows_mingw_w64-x86
|
|
||||||
host_cc: gcc -m32
|
host_cc: gcc -m32
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|
@ -233,15 +253,16 @@ jobs:
|
||||||
run: git submodule update --init --recursive
|
run: git submodule update --init --recursive
|
||||||
|
|
||||||
# --no-install-recommends omits libc6-dev, and minilua needs limits.h.
|
# --no-install-recommends omits libc6-dev, and minilua needs limits.h.
|
||||||
|
# zip: the release asset is a .zip, matching the Windows convention.
|
||||||
- name: Install toolchain
|
- name: Install toolchain
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
apt-get install -y --no-install-recommends \
|
apt-get install -y --no-install-recommends \
|
||||||
make gcc libc6-dev gcc-multilib mingw-w64 jq
|
make gcc libc6-dev gcc-multilib mingw-w64 jq zip
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all
|
run: make PLATFORM=Windows WIN_ARCH=${{ matrix.arch }} HOST_CC="${{ matrix.host_cc }}" all lib
|
||||||
|
|
||||||
- name: Verify executable
|
- name: Verify executable
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -253,6 +274,11 @@ jobs:
|
||||||
bad=$(printf '%s\n' "$deps" | grep -v -E '^(KERNEL32|msvcrt)\.dll$' || true)
|
bad=$(printf '%s\n' "$deps" | grep -v -E '^(KERNEL32|msvcrt)\.dll$' || true)
|
||||||
[ -z "$bad" ] || { echo "unexpected runtime DLL dependency: $bad" >&2; exit 1; }
|
[ -z "$bad" ] || { echo "unexpected runtime DLL dependency: $bad" >&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
|
||||||
|
|
||||||
- name: Attach to release
|
- name: Attach to release
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: sh .forgejo/scripts/release-asset.sh ./hate-no-d.exe hate-no-d-${{ matrix.tag }}.exe
|
run: sh .forgejo/scripts/release-asset.sh "./hate-no-d-windows-${{ matrix.arch }}.zip"
|
||||||
|
|
|
||||||
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -1,3 +1,13 @@
|
||||||
hate-no-d
|
hate-no-d
|
||||||
hate-no-d.exe
|
hate-no-d.exe
|
||||||
quick-start.lua
|
quick-start.lua
|
||||||
|
|
||||||
|
# Release staging dirs and archives (.forgejo/scripts/make-archive.sh).
|
||||||
|
hate-no-d-*/
|
||||||
|
hate-no-d-*.tar.gz
|
||||||
|
hate-no-d-*.zip
|
||||||
|
|
||||||
|
# Build artifacts (make lib).
|
||||||
|
*.o
|
||||||
|
*.mri
|
||||||
|
libhate-no-d.a
|
||||||
|
|
|
||||||
91
Makefile
91
Makefile
|
|
@ -6,6 +6,11 @@
|
||||||
# make PLATFORM=Android ANDROID_NDK=... ANDROID_ABI=armeabi-v7a ANDROID_API=21
|
# make PLATFORM=Android ANDROID_NDK=... ANDROID_ABI=armeabi-v7a ANDROID_API=21
|
||||||
# make PLATFORM=iOS IOS_ARCH=arm64 IOS_MIN=12.0
|
# make PLATFORM=iOS IOS_ARCH=arm64 IOS_MIN=12.0
|
||||||
# make PLATFORM=Windows WIN_ARCH=x86_64 (cross build with mingw-w64)
|
# 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 help every target and option
|
||||||
|
|
||||||
# luajit requires GNU Make (use `gmake` on FreeBSD/OpenBSD/NetBSD).
|
# luajit requires GNU Make (use `gmake` on FreeBSD/OpenBSD/NetBSD).
|
||||||
ifndef .FEATURES
|
ifndef .FEATURES
|
||||||
|
|
@ -17,7 +22,22 @@ endif
|
||||||
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
|
||||||
|
OBJ := hate-no-d.o
|
||||||
BIN := hate-no-d
|
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 :=
|
||||||
|
|
||||||
|
# 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).
|
||||||
|
AR ?= ar
|
||||||
|
|
||||||
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
|
LUAJIT_XCFLAGS := -DLUAJIT_ENABLE_LUA52COMPAT
|
||||||
LUAJIT_EXTRA :=
|
LUAJIT_EXTRA :=
|
||||||
|
|
@ -82,6 +102,7 @@ ifeq ($(OS_KIND),windows)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CC := $(WIN_ARCH)-w64-mingw32-gcc
|
CC := $(WIN_ARCH)-w64-mingw32-gcc
|
||||||
|
AR := $(WIN_ARCH)-w64-mingw32-ar
|
||||||
HOST_CC ?= gcc
|
HOST_CC ?= gcc
|
||||||
PLAT_LIBS := -lm
|
PLAT_LIBS := -lm
|
||||||
BIN := $(BIN).exe
|
BIN := $(BIN).exe
|
||||||
|
|
@ -152,6 +173,7 @@ ifeq ($(OS_KIND),android)
|
||||||
ANDROID_CC := $(ANDROID_BIN)/$(ANDROID_TRIPLET)$(ANDROID_API)-clang
|
ANDROID_CC := $(ANDROID_BIN)/$(ANDROID_TRIPLET)$(ANDROID_API)-clang
|
||||||
|
|
||||||
CC := $(ANDROID_CC)
|
CC := $(ANDROID_CC)
|
||||||
|
AR := $(ANDROID_BIN)/llvm-ar
|
||||||
EXPORT_LDFLAGS := -Wl,-E
|
EXPORT_LDFLAGS := -Wl,-E
|
||||||
PLAT_LIBS := -lm
|
PLAT_LIBS := -lm
|
||||||
LINK_TARGET := $(BIN)
|
LINK_TARGET := $(BIN)
|
||||||
|
|
@ -201,25 +223,84 @@ $(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
|
||||||
|
|
||||||
# Targets
|
# 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 print-config resolved configuration for the current target"
|
||||||
|
@echo " make clean remove build artifacts, LuaJIT's included"
|
||||||
|
@echo " make help this text"
|
||||||
|
@echo ""
|
||||||
|
@echo "Options (pass as VAR=value):"
|
||||||
|
@echo " PLATFORM= Linux | Android | Darwin | iOS | 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 " CFLAGS= default -O2 -Wall"
|
||||||
|
@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"
|
||||||
|
|
||||||
all: $(LINK_TARGET)
|
all: $(LINK_TARGET)
|
||||||
|
|
||||||
$(BIN): hate-no-d.c $(LUAJIT_AR)
|
$(OBJ): hate-no-d.c
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ hate-no-d.c \
|
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ hate-no-d.c
|
||||||
|
|
||||||
|
$(BIN): $(OBJ) $(LUAJIT_AR)
|
||||||
|
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $(OBJ) \
|
||||||
$(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
$(LUAJIT_AR) $(EXPORT_LDFLAGS) $(LDFLAGS) $(PLAT_LIBS)
|
||||||
|
|
||||||
luajit: $(LUAJIT_AR)
|
luajit: $(LUAJIT_AR)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
|
||||||
|
$(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)"
|
||||||
|
|
||||||
# Show the resolved configuration for the current (or selected) platform.
|
# Show the resolved configuration for the current (or selected) platform.
|
||||||
# Useful for checking a cross build before committing to it.
|
# Useful for checking a cross build before committing to it.
|
||||||
print-config:
|
print-config:
|
||||||
@echo "PLATFORM = $(PLATFORM)"
|
@echo "PLATFORM = $(PLATFORM)"
|
||||||
@echo "OS_KIND = $(OS_KIND)"
|
@echo "OS_KIND = $(OS_KIND)"
|
||||||
@echo "CC = $(CC)"
|
@echo "CC / AR = $(CC) / $(AR)"
|
||||||
@echo "CFLAGS = $(CFLAGS)"
|
@echo "CFLAGS = $(CFLAGS)"
|
||||||
@echo "CPPFLAGS = $(CPPFLAGS)"
|
@echo "CPPFLAGS = $(CPPFLAGS)"
|
||||||
@echo "EXPORT_LDFLAGS = $(EXPORT_LDFLAGS)"
|
@echo "EXPORT_LDFLAGS = $(EXPORT_LDFLAGS)"
|
||||||
@echo "PLAT_LIBS = $(PLAT_LIBS)"
|
@echo "PLAT_LIBS = $(PLAT_LIBS)"
|
||||||
@echo "LINK_TARGET = $(LINK_TARGET)"
|
@echo "LINK_TARGET = $(LINK_TARGET)"
|
||||||
|
@echo "OBJ / LIB = $(OBJ) / $(LIB) [$(LIB_OBJS)]"
|
||||||
@echo "LUAJIT_MAKE_ARGS = $(LUAJIT_MAKE_ARGS)"
|
@echo "LUAJIT_MAKE_ARGS = $(LUAJIT_MAKE_ARGS)"
|
||||||
@echo "MACOSX_DEPLOYMENT_TARGET = $(MACOSX_DEPLOYMENT_TARGET) (HRT=$(MACOSX_HRT))"
|
@echo "MACOSX_DEPLOYMENT_TARGET = $(MACOSX_DEPLOYMENT_TARGET) (HRT=$(MACOSX_HRT))"
|
||||||
@echo "ANDROID_ABI / API = $(ANDROID_ABI) / $(ANDROID_API)"
|
@echo "ANDROID_ABI / API = $(ANDROID_ABI) / $(ANDROID_API)"
|
||||||
|
|
@ -228,6 +309,6 @@ print-config:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C $(LUAJIT_DIR) clean
|
$(MAKE) -C $(LUAJIT_DIR) clean
|
||||||
rm -f $(BIN)
|
rm -f $(BIN) $(OBJ) $(LIB) $(LIB).mri
|
||||||
|
|
||||||
.PHONY: all clean luajit print-config
|
.PHONY: all clean luajit print-config lib help
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue