Skip to content

Instantly share code, notes, and snippets.

@mpeterv
Last active April 29, 2018 16:25
Show Gist options
  • Save mpeterv/93cf0c71a1ae4138141b0abadc43b525 to your computer and use it in GitHub Desktop.
Save mpeterv/93cf0c71a1ae4138141b0abadc43b525 to your computer and use it in GitHub Desktop.
Cross-compile luacheck.exe
#!/usr/bin/env bash
# TODO: write a program called `rock2bin` that does this all in
# one call (`rock2bin luacheck -l 5.3 -t windows`).
mkdir build
curl https://www.lua.org/ftp/lua-5.3.4.tar.gz | tar xz
luarocks unpack luafilesystem 1.6.3-2
luarocks unpack lanes 3.10.1-1
cd lua-5.3.4
make mingw CC=x86_64-w64-mingw32-gcc AR="x86_64-w64-mingw32-ar rcu"
mv src/liblua.a ../build
cd ..
cd luafilesystem-1.6.3-2/luafilesystem
x86_64-w64-mingw32-gcc -c -O2 src/lfs.c -I../../lua-5.3.4/src -o src/lfs.o
x86_64-w64-mingw32-ar rcs src/lfs.a src/lfs.o
mv src/lfs.a ../../build
cd ../..
cd lanes-3.10.1-1/lanes
x86_64-w64-mingw32-gcc -c -O2 src/compat.c -I../../lua-5.3.4/src -o src/compat.o
x86_64-w64-mingw32-gcc -c -O2 src/deep.c -I../../lua-5.3.4/src -o src/deep.o
x86_64-w64-mingw32-gcc -c -O2 src/lanes.c -I../../lua-5.3.4/src -o src/lanes.o
x86_64-w64-mingw32-gcc -c -O2 src/keeper.c -I../../lua-5.3.4/src -o src/keeper.o
x86_64-w64-mingw32-gcc -c -O2 src/tools.c -I../../lua-5.3.4/src -o src/tools.o
x86_64-w64-mingw32-gcc -c -O2 src/threading.c -I../../lua-5.3.4/src -o src/threading.o
x86_64-w64-mingw32-ar rcs src/lanes.a src/compat.o src/deep.o src/lanes.o src/keeper.o src/tools.o src/threading.o
mv src/lanes.a ../../build
cp src/lanes.lua ../..
cd ../..
cp -r ~/luacheck/src/luacheck .
cp ~/luacheck/bin/luacheck.lua build
CC="" luastatic build/luacheck.lua luacheck/*.lua lanes.lua build/liblua.a build/lfs.a build/lanes.a -Ilua-5.3.4/src
x86_64-w64-mingw32-gcc -Os build/luacheck.lua.c build/lfs.a build/lanes.a build/liblua.a -lm -o luacheck.exe -Ilua-5.3.4/src
strip luacheck.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment