Compiling Lua on z/OS
Lua is small scripting language, that is mostly known for its use as an extension or configuration language, enabled by its C API. Another benefit of Lua is the highly portable source code written in C, which allows us to compile it for z/OS without changes to the source code. The biggest hurdles will turn out to be EBCDIC and the non-standard C compiler.
Obtaining the source code
Because gzip is not available on the test system, i downloaded and decompressed the Lua source on Linux. The decompressed tar file is transferred to z/OS for extraction.
# Linux
curl -R -O <http://www.lua.org/ftp/lua-5.4.4.tar.gz>
gzip -d lua-5.4.4.tar.gz
scp -r lua-5.4.4.tar <user>@<host>:
# z/OS
tar xf lua-5.4.4.tar
cd lua-5.4.4
Compiling
make and a working C compiler (IBM XL C/C++) are needed for this step. Because no make target for z/OS exists, one is added. Additionally it is necessary to correctly convert and tag all files in preparation.
# convert the source files to EBCDIC
mkdir tmpsrc
for f in src/*c src/*h; do iconv -f UTF8 -t IBM1047 "$f" > tmp"$f"; done
mv tmpsrc/* src
rm -r tmpsrc
# tag the files
chtag -t -c IBM1047 src/*
chtag -t -c UTF8 Makefile src/Makefile
# required for cc to work
export STEPLIB="CBC.SCCNCMP"
# add zOS make target
printf '\nzOS:\n\t$(MAKE) $(ALL) CC="cc" CFLAGS="-O2 -DLUA_USE_C89 -DLUA_USE_POSIX"\n' >> src/Makefile
printf '1,$s/PLATS=/PLATS= zOS\nwq\n' | ed -W filecodeset=UTF8 Makefile
# compile
make zOS
make zOS # because ranlib doesn't exist, make fails to complete the first time
Installing
To install Lua system wide, use:
make install INSTALL_EXEC="cp -p" INSTALL_DATA="cp -p" INSTALL_TOP=""
Running
Running lua starts a REPL, lua file.lua runs file.lua. Making use of the C API is left as an exercise to the reader. It should be noted that Lua scripts need to be encoded in, and tagged as EBCDIC, which unfortunately limits the portability of the scripts.