$NetBSD: patch-config,v 1.1 2019/05/28 20:43:04 maya Exp $

Fix default directory locations
Try to find lua libs from pkgconfig, so we get RPATH specified.
(This eliminates the need to separately add -lm)

--- config.orig	2017-09-15 23:07:33.000000000 +0000
+++ config
@@ -1,22 +1,28 @@
 # Installation directories
 
 # Default installation prefix
-PREFIX=/usr/local
+PREFIX?=/usr/local
 
 # System's libraries directory (where binary libraries are installed)
-LUA_LIBDIR= $(PREFIX)/lib/lua/5.1
+LUA_LIBS= $(pkg-config --libs lua-$(LUA_VERS))
+LUA_LIBDIR= $(DESTDIR)$(PREFIX)/$(LUA_CDIR)
 
 # Lua includes directory
 LUA_INC= $(PREFIX)/include
 
 # OS dependent
-LIB_OPTION= -shared #for Linux
-#LIB_OPTION= -bundle -undefined dynamic_lookup #for MacOS X
+ifeq ($(shell uname -s 2>/dev/null), Darwin)
+# for macOS
+LIB_OPTION+= -L$(PREFIX)/lib $(LUA_LIBS) -shared -install_name $(PREFIX)/$(LUA_CDIR)/$(notdir $@)
+else
+# for Linux & other unix
+LIB_OPTION+= -L$(PREFIX)/lib $(LUA_LIBS) -shared
+endif
 
 LIBNAME= $T.so.$V
 
 # Compilation directives
-WARN= -O2 -Wall -fPIC -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings -pedantic
+WARN= -O2 -fPIC 
 INCS= -I$(LUA_INC)
 CFLAGS= $(WARN) $(INCS)
 CC= gcc
