From 5cff9a858388ae2d1cbcfe8a6af6150428fe83da Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Tue, 26 Oct 2010 20:29:12 +0000 Subject: [PATCH] --- Makefile.am | 17 ++++++++++++++++- configure.ac | 11 ++++++++++- lsyncd.c | 30 ++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index 17b64a5..cee1c6f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,20 @@ AUTOMAKE_OPTIONS = foreign CFLAGS = -Wall $(LIBLUA_CFLAGS) bin_PROGRAMS = lsyncd -lsyncd_SOURCES = lsyncd.c +lsyncd_SOURCES = lsyncd.c lsyncd_LDADD = $(LIBLUA_LIBS) + +if RUNNER +else +lsyncd: luac.o $(lsyncd_LDADD) + +architecture: | lsyncd.o + objdump -f $< | grep architecture | sed -e "s/,.*$$//" -e "s/[^ ]* \(.*\)/\1/" > $@ || rm architecture + +luac.o: luac.out architecture + objcopy --input-target=binary --output-target=`gcc -dumpmachine` --binary-architecture=`cat architecture` $< $@ + +luac.out: lsyncd.lua + luac $< +endif + diff --git a/configure.ac b/configure.ac index 43717ae..e79658f 100644 --- a/configure.ac +++ b/configure.ac @@ -12,8 +12,17 @@ AC_PROG_MAKE_SET # Checks for libraries. PKG_CHECK_MODULES(LIBLUA, lua5.1) # Checks for header files. +AC_CHECK_HEADERS([sys/inotify.h]) + +AC_ARG_WITH([runner], +[ --with-runner= Specify place where lsyncds part written in Lua will be placed. + If missing it will be compiled into the binary)]) +if test "x${with_runner}" != x; then +AC_DEFINE_UNQUOTED(LSYNCD_DEFAULT_RUNNER_FILE, "${with_runner}", "descr") +fi +AM_CONDITIONAL([RUNNER], [test x${with_runner} != x]) + # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. -AC_CHECK_HEADERS([sys/inotify.h]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/lsyncd.c b/lsyncd.c index 587871e..a98774a 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -71,7 +71,10 @@ enum event_type { /** * The Lua part of lsyncd. */ -#define LSYNCD_DEFAULT_RUNNER_FILE "lsyncd.lua" +//#define LSYNCD_DEFAULT_RUNNER_FILE "lsyncd.lua" +extern char _binary_luac_out_start; +extern char _binary_luac_out_end; + static char * lsyncd_runner_file = NULL; static char * lsyncd_config_file = NULL; @@ -1017,6 +1020,7 @@ main(int argc, char *argv[]) lua_pushinteger(L, ERROR); lua_setglobal(L, "ERROR"); /* TODO parse runner */ +#ifdef LSYNCD_DEFAULT_RUNNER_FILE if (!strcmp(argv[argp], "--runner")) { if (argc < 3) { fprintf(stderr, "Lsyncd Lua-runner file missing after --runner.\n"); @@ -1033,28 +1037,46 @@ main(int argc, char *argv[]) } else { lsyncd_runner_file = LSYNCD_DEFAULT_RUNNER_FILE; } +#else + if (!strcmp(argv[argp], "--runner")) { + fprintf(stderr, "This lsyncd binary has its lua runner staticly compiled.\n"); + fprintf(stderr, "Configure and compile with --with-runner=FILE to use the lsyncd.lua file.\n"); + return -1; // ERRNO + } +#endif lsyncd_config_file = argv[argp++]; { struct stat st; +#ifdef LSYNCD_DEFAULT_RUNNER_FILE if (stat(lsyncd_runner_file, &st)) { - fprintf(stderr, "Cannot find Lsyncd Lua-runner at %s.\n", lsyncd_runner_file); + fprintf(stderr, "Cannot find Lsyncd Lua-runner at '%s'.\n", lsyncd_runner_file); fprintf(stderr, "Maybe specify another place? %s --runner RUNNER_FILE CONFIG_FILE\n", argv[0]); return -1; // ERRNO } +#endif if (stat(lsyncd_config_file, &st)) { - fprintf(stderr, "Cannot find config file at %s.\n", lsyncd_config_file); + fprintf(stderr, "Cannot find config file at '%s'.\n", lsyncd_config_file); return -1; // ERRNO } } +#ifdef LSYNCD_DEFAULT_RUNNER_FILE if (luaL_loadfile(L, lsyncd_runner_file)) { fprintf(stderr, "error loading '%s': %s\n", lsyncd_runner_file, lua_tostring(L, -1)); return -1; // ERRNO } +#else + if (luaL_loadbuffer(L, &_binary_luac_out_start, + &_binary_luac_out_end - &_binary_luac_out_start, "lsyncd.lua")) { + fprintf(stderr, "error loading precompiled lsyncd.lua runner: %s\n", + lua_tostring(L, -1)); + return -1; // ERRNO + } +#endif if (lua_pcall(L, 0, LUA_MULTRET, 0)) { fprintf(stderr, "error preparing '%s': %s\n", - lsyncd_runner_file, lua_tostring(L, -1)); + lsyncd_runner_file, lua_tostring(L, -1)); return -1; // ERRNO }