Lua53 revision 3
Needs ReviewPublic

Authored by on Dec 30 2017, 7:09 AM.




The logic behind this revision is:

  • Review old notes and assumptions and clean up things unrequired
  • Apply some logic to the way the port is built
  • Prepare for possible inclusion of luarocks in base lua package
  • [Possible integration of ports between lua revisions]

I will put comments inline about the changes, but the overall consideration is to patch the source and makefile as to be correct for the platform, then build it using the standard lua build target of "freebsd". I would like to eliminate the MAKEARGS in the middle and instead rename the files during install, or a preinstall step to copy the files. This further modification leaves the port output in a vanilla state and the executables can be used for other things.

Test Plan

I have none at this point and am looking for input. A search of freshports for things dependent on lua53 brings up 5 items. Suggestions ways to test these items would be appreciated. (Is it simply good enough if they build in my ports tree?)

I will be testing this on Arm as soon as I can get one of my boards spun up again. Famous last words: "I see no reason it shouldn't work".

Diff Detail

rP FreeBSD ports repository
Lint Skipped
Unit Tests Skipped

This is simply handled in the code patch to lua.c. As far as I can tell, editline is a standard package in FreeBSD 4.4?


These variable have been added to standardize with and hopefully other packages if I have time.


Unnecessary if the standard editline package is used.


As per an email with Jan Beich:

-pthread was inherited from
which was probably fixed by

How do I test this?


I would like to remove the renaming of the lua build output and postpone it until the install step, or a preinstall rename. Input appreciated.


Added to the base Makefile


The code that this patches is not reachable due to the USE_POSIX.

From lmathlib.c

#if !defined(l_rand) /* { */
#if defined(LUA_USE_POSIX)
#define l_rand() random()
#define l_srand(x) srandom(x)
#define L_RANDMAX 2147483647 /* (2^31 - 1), following POSIX */
#define l_rand() rand()
#define l_srand(x) srand(x)
#endif /* } */

from luaconf.h

#if defined(LUA_USE_LINUX)
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#define LUA_USE_READLINE /* needs some extra libraries */


luaconf.h contains no readline reference and I instead created a patch for lua.c. This makes the code changes in one place (patch files) and the changes required are easily visible (in the patch file).


This is the simplest way to patch the original make file to compile it on FreeBSD. I don't have my arm boards handy, but this is essentially what I do when I build lua manually. Again, the changes are applied to the base makefile so the lua sources are as vanilla as possible and the base make system works.


Eliminates all shared dependencies and the code is 100% portable on FreeBSD.


This is the standard make target for freebsd in lua. added inline comments.

As I pointed out in email, this change should be eliminated in favour of adding -I/usr/include/edit to cflags.

Note that the USES=libedit can be removed, since that pulls in the ports libedit. (Unless there's some reason to use the ports libedit...)


This removal isn't quite right because the point of editing luaconf.h here is not to deal with readline, but rather to fix LUA_ROOT to ensure it matches ${PREFIX}. By default these are both /usr/local, so it's not obvious if this step is missed, but if ${PREFIX} is set to something else it's important that LUA_ROOT in luaconf.h be updated to match.

Hi Andrew,

Once you're happy with the 5.4 patch i will back-port to 5.3 and add the missing Lua patches.