5ba4641
diff --git a/Makefile.am b/Makefile.am
5ba4641
new file mode 100644
5ba4641
index 0000000..8d968c4
5ba4641
--- /dev/null
5ba4641
+++ b/Makefile.am
5ba4641
@@ -0,0 +1,3 @@
5ba4641
+SUBDIRS = src doc
5ba4641
+
5ba4641
+EXTRA_DIST = README
5ba4641
diff --git a/configure.ac b/configure.ac
5ba4641
new file mode 100644
5ba4641
index 0000000..3af6625
5ba4641
--- /dev/null
5ba4641
+++ b/configure.ac
5ba4641
@@ -0,0 +1,69 @@
5ba4641
+AC_PREREQ(2.59)
5ba4641
+AC_INIT([lua], [5.2.3], [https://bugzilla.redhat.com/], [lua-at], [http://www.lua.org])
5ba4641
+AC_SUBST([MAJOR_VERSION], [5.2])
5ba4641
+
5ba4641
+AC_CONFIG_HEADERS([config.h])
5ba4641
+AC_CONFIG_SRCDIR([src/lapi.c])
5ba4641
+
5ba4641
+AM_INIT_AUTOMAKE([1.9 foreign])
5ba4641
+
5ba4641
+AC_PROG_CC
5ba4641
+AC_PROG_LIBTOOL
5ba4641
+
5ba4641
+AC_ARG_WITH(
5ba4641
+  [readline],
5ba4641
+  [AC_HELP_STRING([--with-readline], [Use readline for interpreter input [default=yes]])],
5ba4641
+  [use_readline=$withval],
5ba4641
+  [use_readline=yes]
5ba4641
+)
5ba4641
+
5ba4641
+LUA_LIBS="-lm"
5ba4641
+
5ba4641
+# Check for readline
5ba4641
+READLINE_DEFS="#undef LUA_USE_READLINE"
5ba4641
+if test "x$use_readline" == "xyes"; then
5ba4641
+  AC_CHECK_LIB([readline], [readline], [:], [use_readline=no], [-lncurses])
5ba4641
+  AC_CHECK_HEADERS([readline/readline.h readline/history.h], [], [use_readline=no])
5ba4641
+  if test "x$use_readline" == "xno"; then
5ba4641
+    AC_MSG_WARN([readline headers could not be found, disabling readline support])
5ba4641
+  else
5ba4641
+    READLINE_DEFS="#define LUA_USE_READLINE"
5ba4641
+    READLINE_LIBS="-lreadline -lncurses"
5ba4641
+  fi
5ba4641
+fi
5ba4641
+AC_SUBST(READLINE_DEFS)
5ba4641
+AC_SUBST(READLINE_LIBS)
5ba4641
+
5ba4641
+case "$host" in
5ba4641
+  *-mingw*)  use_os=win32  ;;
5ba4641
+  *-darwin*) use_os=macosx ;;
5ba4641
+  *)         use_os=posix  ;;
5ba4641
+esac
5ba4641
+
5ba4641
+POSIX_DEFS="#undef LUA_USE_POSIX"
5ba4641
+LUA_DL_DEFS="#undef LUA_USE_DLOPEN"
5ba4641
+LUA_BUILD_AS_DLL_DEFS="#undef LUA_BUILD_AS_DLL"
5ba4641
+
5ba4641
+if test "x$use_os" == "xwin32"; then
5ba4641
+  LUA_BUILD_AS_DLL_DEFS="#define LUA_BUILD_AS_DLL"
5ba4641
+elif test "x$use_os" == "xmacosx"; then
5ba4641
+  POSIX_DEFS="#define LUA_USE_POSIX"
5ba4641
+  LUA_DL_DEFS="#define LUA_DL_DYLD"
5ba4641
+elif test "x$use_os" == "xposix"; then
5ba4641
+  POSIX_DEFS="#define LUA_USE_POSIX"
5ba4641
+  LUA_DL_DEFS="#define LUA_DL_DLOPEN"
5ba4641
+  LUA_LIBS="$LUA_LIBS -ldl"
5ba4641
+fi
5ba4641
+AC_SUBST(POSIX_DEFS)
5ba4641
+AC_SUBST(LUA_DL_DEFS)
5ba4641
+AC_SUBST(LUA_BUILD_AS_DLL_DEFS)
5ba4641
+
5ba4641
+AC_SUBST(LUA_LIBS)
5ba4641
+
5ba4641
+AC_CONFIG_FILES([Makefile
5ba4641
+                 src/Makefile
5ba4641
+                 src/lua.pc
5ba4641
+                 src/luaconf.h.template
5ba4641
+                 doc/Makefile
5ba4641
+])
5ba4641
+AC_OUTPUT
5ba4641
diff --git a/doc/Makefile.am b/doc/Makefile.am
5ba4641
new file mode 100644
5ba4641
index 0000000..3705696
5ba4641
--- /dev/null
5ba4641
+++ b/doc/Makefile.am
5ba4641
@@ -0,0 +1,4 @@
5ba4641
+man1_MANS = lua.1 luac.1
5ba4641
+
5ba4641
+EXTRA_DIST = \
5ba4641
+	contents.html logo.gif lua.1 luac.1 lua.css manual.css manual.html osi-certified-72x60.png readme.html
5ba4641
diff --git a/src/.gitignore b/src/.gitignore
5ba4641
new file mode 100644
5ba4641
index 0000000..0abd9dd
5ba4641
--- /dev/null
5ba4641
+++ b/src/.gitignore
5ba4641
@@ -0,0 +1,5 @@
5ba4641
+lua
5ba4641
+lua.pc
5ba4641
+luac
5ba4641
+luaconf.h
5ba4641
+luaconf.h.template
5ba4641
diff --git a/src/Makefile.am b/src/Makefile.am
5ba4641
new file mode 100644
5ba4641
index 0000000..6c7c79f
5ba4641
--- /dev/null
5ba4641
+++ b/src/Makefile.am
5ba4641
@@ -0,0 +1,46 @@
5ba4641
+AM_CFLAGS = -Wall
5ba4641
+
5ba4641
+include_HEADERS = lua.h lualib.h lauxlib.h lua.hpp
5ba4641
+
5ba4641
+nodist_include_HEADERS = luaconf.h
5ba4641
+
5ba4641
+lib_LTLIBRARIES = liblua.la
5ba4641
+liblua_la_LDFLAGS = -release @MAJOR_VERSION@
5ba4641
+liblua_la_SOURCES = \
5ba4641
+	lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c lcorolib.c lctype.c ldblib.c \
5ba4641
+	ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c \
5ba4641
+	loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c \
5ba4641
+	ltable.c ltablib.c ltm.c lundump.c lvm.c lzio.c \
5ba4641
+	lapi.h lcode.h lctype.h ldebug.h ldo.h lfunc.h lgc.h llex.h llimits.h \
5ba4641
+	lmem.h lobject.h lopcodes.h lparser.h lstate.h lstring.h ltable.h ltm.h \
5ba4641
+	lundump.h lvm.h lzio.h
5ba4641
+
5ba4641
+pkgconfigdir = $(libdir)/pkgconfig
5ba4641
+pkgconfig_DATA = lua.pc
5ba4641
+
5ba4641
+bin_PROGRAMS = lua luac
5ba4641
+
5ba4641
+lua_SOURCES = lua.c
5ba4641
+lua_LDADD = liblua.la @LUA_LIBS@ @READLINE_LIBS@
5ba4641
+lua_DEPENDENCIES = liblua.la
5ba4641
+
5ba4641
+luac_SOURCES = luac.c
5ba4641
+# Statically link liblua against luac since luac uses symbols not exported in liblua
5ba4641
+luac_LDADD = .libs/liblua.a @LUA_LIBS@
5ba4641
+luac_DEPENDENCIES = liblua.la
5ba4641
+
5ba4641
+EXTRA_DIST = luaconf.h.template
5ba4641
+BUILT_SOURCES = luaconf.h
5ba4641
+CLEANFILES = luaconf.h luaconf.h.template
5ba4641
+
5ba4641
+readline_defs = @READLINE_DEFS@
5ba4641
+
5ba4641
+edit = 	sed \
5ba4641
+	  -e 's,%prefix%,$(prefix),g' \
5ba4641
+	  -e 's,%lua_datadir%,$(datadir),g' \
5ba4641
+	  -e 's,%lua_libdir%,$(libdir),g'
5ba4641
+
5ba4641
+luaconf.h : luaconf.h.template
5ba4641
+	rm -f $@ $@.tmp
5ba4641
+	$(edit) $< >$@.tmp
5ba4641
+	mv $@.tmp $@
5ba4641
diff --git a/src/lua.pc.in b/src/lua.pc.in
5ba4641
new file mode 100644
5ba4641
index 0000000..25faa8d
5ba4641
--- /dev/null
5ba4641
+++ b/src/lua.pc.in
5ba4641
@@ -0,0 +1,13 @@
5ba4641
+V= @MAJOR_VERSION@
5ba4641
+R= @VERSION@
5ba4641
+prefix= @prefix@
5ba4641
+exec_prefix=${prefix}
5ba4641
+libdir= @libdir@
5ba4641
+includedir=${prefix}/include
5ba4641
+
5ba4641
+Name: Lua
5ba4641
+Description: An Extensible Extension Language
5ba4641
+Version: ${R}
5ba4641
+Requires:
5ba4641
+Libs: -llua @LUA_LIBS@
5ba4641
+Cflags: -I${includedir}
5ba4641
diff --git a/src/luaconf.h b/src/luaconf.h.template.in
5ba4641
--- a/src/luaconf.h.template.in
5ba4641
+++ b/src/luaconf.h.template.in
5ba4641
@@ -11,6 +11,11 @@
5ba4641
 #include <limits.h>
5ba4641
 #include <stddef.h>
5ba4641
 
5ba4641
+@POSIX_DEFS@
5ba4641
+@LUA_DL_DEFS@
5ba4641
+@LUA_BUILD_AS_DLL_DEFS@
5ba4641
+@READLINE_DEFS@
5ba4641
+
5ba4641
 
5ba4641
 /*
5ba4641
 ** ==================================================================
5ba4641
@@ -100,9 +105,9 @@
5ba4641
 #else			/* }{ */
5ba4641
 
5ba4641
 #define LUA_VDIR	LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
5ba4641
-#define LUA_ROOT	"/usr/local/"
5ba4641
-#define LUA_LDIR	LUA_ROOT "share/lua/" LUA_VDIR
5ba4641
-#define LUA_CDIR	LUA_ROOT "lib/lua/" LUA_VDIR
5ba4641
+#define LUA_ROOT	"@prefix@/"
5ba4641
+#define LUA_LDIR	"@pkgdatadir@/lua/" LUA_VDIR
5ba4641
+#define LUA_CDIR	"@libdir@/lua/" LUA_VDIR
5ba4641
 #define LUA_PATH_DEFAULT  \
5ba4641
 		LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
5ba4641
 		LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua;" "./?.lua"