makefile: Invert check for lua vs lua5.1

Apparently ubuntu 13.x (?) installs lua5.1 by default for other packages
so checking for lua5.1 picks up the system installation by accident.

Instead now we check for lua first and then fall back to lua5.1 instead.
makefile: add -ldl as default linker option

Apparently now on Ubuntu 13.x (?) -ldl is required to compile.

This may be because it was automatically included previously with some
of gcc's default libs?