build: Use more overrideable system-autodetect.mk

With these changes, some commonly overrided values can be exported
from the environment to influence the build output (e.g. PREFIX, CFLAGS,
INSTALL, etc). You can also specify the lua version you'd like to use
with the following variable: "LUA_VERSION" (if not specified, it tries
to detect the highest lua version available (as seen by pkg-config)).