|
root / base / lua / build.sh
build.sh Bash 77 lines 3.4 KB
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
# Build script for Lua 5.4 (plain uname-keyed Makefile - NOT autotools).
#
# Lua's src/Makefile only has a "guess"/named-platform target dispatch (no
# dedicated Hammerhead/illumos entry) and its "posix"/"solaris" targets only
# ever produce a STATIC liblua.a - there is no shared-library target at all
# upstream, on any platform. So this build.sh does two passes:
#   1. `gmake posix` - the generic POSIX target (illumos has no dedicated
#      target; "solaris"/"SunOS" exists but drags in Solaris-specific
#      readline assumptions we don't want) - gives us liblua.a + lua/luac
#      binaries, and validates the objects build cleanly.
#   2. Manually recompile the library objects -fPIC and link them into a
#      real liblua.so.5.4 - conky/neovim need a *shared* liblua, which
#      upstream never ships, so this has to be done by hand.
# Finally we write a lua.pc by hand (upstream Lua ships NO pkg-config file
# at all) so consumers (conky, neovim) can find it via pkg-config.
set -e
cd "$SRCDIR/src"

export CC=gcc

# --- Pass 1: static build (also produces the lua/luac binaries) ---
gmake MYCFLAGS="-D__EXTENSIONS__ -DLUA_USE_POSIX -DLUA_USE_DLOPEN -fPIC" \
      MYLIBS="-ldl" \
      CC="$CC" \
      posix

# --- Pass 2: shared liblua.so.5.4 ---
# CORE_O/LIB_O objects were already compiled -fPIC above (MYCFLAGS carried
# -fPIC into SYSCFLAGS via MYCFLAGS), so relink into a shared object rather
# than recompiling. lua.o/luac.o are excluded (those are the standalone
# interpreter/compiler mains, not part of the library).
# NOTE: coral invokes build.sh via `zsh script.sh` (not `sh script.sh`), so
# the shebang is not honored and zsh's default (no word-splitting on
# unquoted variable expansion) applies - an "$CORE_O $LIB_O" variable
# reference collapses to a single argument and breaks the link. Inline the
# object list literally (plain script tokens, not a variable) to sidestep
# the shell-dependent splitting behavior entirely.
gcc -shared -Wl,-soname,liblua.so.5 -o liblua.so.5.4 \
    lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \
    lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \
    ltm.o lundump.o lvm.o lzio.o \
    lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o \
    loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o \
    -lm -ldl
ln -sf liblua.so.5.4 liblua.so.5
ln -sf liblua.so.5   liblua.so

# --- Install (static lib + binaries + headers via upstream install target) ---
cd "$SRCDIR"
gmake install INSTALL_TOP="$PKGDIR$PREFIX"

# --- Stage the shared lib alongside the static one ---
# NOTE: illumos cp(1) has no GNU/BSD-style -P (no-dereference) flag - copy
# only the real regular file, then recreate the two symlinks in place with
# ln -sf so they land as symlinks (not dereferenced copies).
mkdir -p "$PKGDIR$PREFIX/lib"
cp -f src/liblua.so.5.4 "$PKGDIR$PREFIX/lib/"
( cd "$PKGDIR$PREFIX/lib" && ln -sf liblua.so.5.4 liblua.so.5 && ln -sf liblua.so.5 liblua.so )

# --- Write lua.pc (upstream ships none) ---
mkdir -p "$PKGDIR$PREFIX/lib/pkgconfig"
cat > "$PKGDIR$PREFIX/lib/pkgconfig/lua.pc" <<EOF
prefix=$PREFIX
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include

Name: lua
Description: Lua embeddable scripting language
Version: 5.4.8
Libs: -L\${libdir} -llua -lm -ldl
Cflags: -I\${includedir}
EOF
# Also provide the lua5.4 alias name some consumers probe for.
ln -sf lua.pc "$PKGDIR$PREFIX/lib/pkgconfig/lua5.4.pc"