[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: configuration path in 5.1
- From: JSaw <j4y54w@...>
- Date: Wed, 29 Jun 2005 01:00:07 +0200
Hi all.
I already asked on IRC if it would be possible to add a configure script
to lua - and of course, the auto* generated files would be way bigger
than the lua source code itself. But what's about a simple configure
script that does no checks but takes a subset of usual options (like
"--prefix", "--enable-shared", "--enable-readline") and then only
adjusts Makefiles and src/luaconf.h accordingly? (see attached "configure").
Second, getting the library and script installation paths out of lua is
a bit strange. Why isn't this simply stored in the package table? (see
attached "package-dirs.diff")
George
#!/bin/sh
# simple lua configure script
# Juergen "George" Sawinski
# see copyright notice in COPYRIGHT
MYCFLAGS=
MYLDFLAGS=
MYLIBS=
luaconf_h_sedscript=
Makefile_sedscript=
#sedscript_add variable-name regex transform
sedscript_add() {
local regex="$2" trans="$3"
eval "$1=\"\$$1 s%$regex%$trans%;\""
}
#variable_add variable-name seperator text
variable_add() {
eval "$1=\"\$$1$2$3\""
}
# luaconf_h_define define-name content
luaconf_h_define() {
sedscript_add luaconf_h_sedscript "^\\(#define[ \t]*$1[ \t]*\\).*" "\\1$2"
}
#Makefile_sed regex replace
Makefile_sed() {
sedscript_add Makefile_sedscript "^\($1[ \t]*=[ \t]*\).*" "\1$2"
}
usage() {
cat <<EOF
configure [options]
Simple configuration for lua (no checks are performed).
Options:
--prefix=path Adjust installation root.
--enable-shared Enable loading of dynamic libraries.
--enable-readline Enable readline for command line interface.
CFLAGS="options" Additional compiler options.
LDFLAGS="options" Additional linker options.
EOF
}
# parse arguments
while [ "$1" ]; do
case "$1" in
-h|--help)
usage
exit ;;
CFLAGS=*)
cflags="`expr "$1" : "[^=]*=\(.*\)"`"
variable_add MYCFLAGS ' ' "$cflags"
shift ;;
LDFLAGS=*)
ldflags="`expr "$1" : "[^=]*=\(.*\)"`"
variable_add MYLDFLAGS ' ' "$ldflags"
shift ;;
--prefix=*)
prefix="`expr "$1" : "[^=]*=\(.*\)"`"
luaconf_h_define LUA_ROOT "\\\"$prefix\\\""
Makefile_sed INSTALL_TOP "$prefix"
shift ;;
--enable-shared)
variable_add MYCFLAGS ' ' "-DLUA_USE_DLOPEN"
variable_add MYLDFLAGS ' ' "-Wl,-E"
variable_add MYLIBS ' ' "-ldl"
shift ;;
--enable-readline)
variable_add MYCFLAGS ' ' "-DLUA_USE_READLINE"
variable_add MYLIBS ' ' "-lreadline -lhistory -lncurses"
shift ;;
esac
done
Makefile_sed MYCFLAGS "$MYCFLAGS"
Makefile_sed MYLIBS "$MYLIBS"
Makefile_sed MYLDFLAGS "$MYLDFLAGS"
# execute sed scripts
if [ "$luaconf_h_sedscript" ]; then
cp src/luaconf.h src/luaconf.h.cfg
eval "sed '$luaconf_h_sedscript' < src/luaconf.h.cfg > src/luaconf.h"
rm -f src/luaconf.h.cfg
fi
if [ "$Makefile_sedscript" ]; then
cp Makefile Makefile.cfg
eval "sed '$Makefile_sedscript' < Makefile.cfg > Makefile"
rm -f Makefile.cfg
cp src/Makefile src/Makefile.cfg
eval "sed '$Makefile_sedscript' < src/Makefile.cfg > src/Makefile"
rm -f src/Makefile.cfg
fi
Index: lua/src/loadlib.c
===================================================================
--- lua/src/loadlib.c (revision 255)
+++ lua/src/loadlib.c (revision 259)
@@ -495,6 +495,13 @@
if (path == NULL) path = LUA_PATH_DEFAULT;
lua_pushstring(L, path);
lua_setfield(L, -2, "path");
+ /* set fields `root', `cdir', `ldir' */
+ lua_pushstring(L, LUA_ROOT);
+ lua_setfield(L, -2, "root");
+ lua_pushstring(L, LUA_CDIR);
+ lua_setfield(L, -2, "cdir");
+ lua_pushstring(L, LUA_LDIR);
+ lua_setfield(L, -2, "ldir");
/* set field `cpath' */
path = getenv(LUA_CPATH);
if (path == NULL) path = LUA_CPATH_DEFAULT;