From b6228f442d68cbf89b5f1cd098f153a5700d25be Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Tue, 29 Apr 2014 16:11:27 +0200 Subject: [PATCH] Replacing autotools with CMake --- .gitignore | 32 ++++------ CMakeLists.txt | 85 +++++++++++++++++++++++++++ INSTALL | 56 ++++++++++++++++++ Makefile.am | 60 ------------------- cmake/FindLua.cmake | 118 +++++++++++++++++++++++++++++++++++++ config.h.in | 6 ++ configure.ac | 140 -------------------------------------------- inotify.c | 4 -- lsyncd.c | 22 +++---- lsyncd.h | 16 ++--- 10 files changed, 287 insertions(+), 252 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 INSTALL delete mode 100644 Makefile.am create mode 100644 cmake/FindLua.cmake create mode 100644 config.h.in delete mode 100644 configure.ac diff --git a/.gitignore b/.gitignore index 463e171..0426677 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,26 @@ -#~~~~~ -# Compiled output +# +# compiled stuff # *.o *.out lsyncd -#~~~~~ -# Autoconf/Automake # -aclocal.m4 +# cmake +# +AdditionalInfo.txt config.h -config.h.in -config.log -config.status -configure -install-sh Makefile -depcomp -Makefile.in -missing -stamp-h1 +build/ -.deps/ -autom4te.cache/ - -#~~~~~ -# Manpages +# +# manpages # doc/lsyncd.1.xml doc/lsyncd.1 -##### -# Generated C code +# +# generated C code # defaults.c runner.c - diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2fc6bd6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,85 @@ +# preamble +project( Lsyncd ) +cmake_minimum_required( VERSION 2.8 ) +set( LSYNCD_VERSION 2.1.5 ) +set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/" ) + + +# finding Lua +find_package(Lua REQUIRED) +include_directories ( ${LUA_INCLUDE_DIR} ) + + +# setting Lsyncd sources +set( LSYNCD_SRC lsyncd.c runner.c defaults.c ) + + +# selecting the file notification mechanisms to compile against +option( WITH_INOTIFY "Compile with inotify file notifications (Linux)" ON ) +option( WITH_FSEVENTS "Compile with inotify file notifications (OSX)" OFF ) + +if( WITH_INOTIFY ) + set( LSYNCD_SRC ${LSYNCD_SRC} inotify.c ) +endif( WITH_INOTIFY ) + +if( WITH_FSEVENTS ) + set( LSYNCD_SRC ${LSYNCD_SRC} fsevents.c ) + + option( XNU_DIR "Path to the xnu sources" ) + +# if( NOT XNU_DIR/bsd/sys/fsevents.h ) +# message( SEND_ERROR "Cannot find bsd/sys/fsevents.h in XNU_DIR" ) +# endif( ) + + include_directories( ${XNU_DIR} ) +endif( WITH_FSEVENTS ) + + +# generating the config.h file +configure_file ( + "${PROJECT_SOURCE_DIR}/config.h.in" + "${PROJECT_BINARY_DIR}/config.h" +) +include_directories("${PROJECT_BINARY_DIR}") + + +# building and compiling the part of lsyncd written in Lua +# also called "runner" +add_custom_command( OUTPUT runner.c + COMMAND ${CMAKE_COMMAND} -E echo "Generating built-in runner linkable" + COMMAND ${LUA_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin2carray.lua runner.out runner runner.c + DEPENDS runner.out +) + +# this supposes the Lua compiler 'luac' is sitting right next to the Lua interpreter 'lua' +add_custom_command( OUTPUT runner.out + COMMAND ${CMAKE_COMMAND} -E echo "Compiling built-in runner" + COMMAND ${LUA_EXECUTABLE}c -o runner.out ${PROJECT_SOURCE_DIR}/lsyncd.lua + DEPENDS ${PROJECT_SOURCE_DIR}/lsyncd.lua +) + +# building and compiling the built-in default configs: +# rsync rysnc-ssh and direct +add_custom_command( OUTPUT defaults.c + COMMAND ${CMAKE_COMMAND} -E echo "Generating built-in default configs" + COMMAND ${LUA_EXECUTABLE} ${PROJECT_SOURCE_DIR}/bin2carray.lua defaults.out defaults defaults.c + DEPENDS defaults.out +) + +set( DEFAULT_CONFIGS + ${PROJECT_SOURCE_DIR}/default.lua + ${PROJECT_SOURCE_DIR}/default-rsync.lua + ${PROJECT_SOURCE_DIR}/default-rsyncssh.lua + ${PROJECT_SOURCE_DIR}/default-direct.lua +) + +add_custom_command( OUTPUT defaults.out + COMMAND ${CMAKE_COMMAND} -E echo "Compiling built-in default configs" + COMMAND ${LUA_EXECUTABLE}c -o defaults.out ${DEFAULT_CONFIGS} + DEPENDS ${DEFAULT_CONFIGS} +) + + +# compiling and linking it all together +add_executable( lsyncd ${LSYNCD_SRC} ) +target_link_libraries( lsyncd ${LUA_LIBRARIES} ) diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..f42a093 --- /dev/null +++ b/INSTALL @@ -0,0 +1,56 @@ +INSTALLING +========== + +Prerequisites +------------- + + CMake + + Lsyncd now uses CMake as configuration tool + + Common compiler stuff + + The C compiler, make, binutils, etc. + + Lua + + For building Lsyncd the Lua interpreter 'lua' + and the Lua compiler 'luac' are needed. + They aren't needed in the deployed binary tough. + + Use Lua 5.1 or Lua 5.2 at your choice. + + Liblua + + The lua library. + + Note that you likely need the package "liblua-dev" + or something like that. + + Use Lua 5.1 or Lua 5.2 at your choice. + + Note, this has to be exactly the same Version as the + lua compiler used above! + + +Building +-------- + + Building with a seperate build directory: + + mkdir build + cd build + cmake .. + make + sudo make install + + Building intree: + cmake . + make + + On OSX you yet need to get the xnu sources. + For example: + cmake -DWITH_INOTIFY=OFF -DWITH_FSEVENTS=ON -DXNU_DIR=/path/to/xnu-VERSION + make + +FIXME make install not yet done diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 107b852..0000000 --- a/Makefile.am +++ /dev/null @@ -1,60 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 - -CFLAGS += -Wall $(LUA_CFLAGS) -bin_PROGRAMS = lsyncd -lsyncd_SOURCES = lsyncd.h lsyncd.c lsyncd.lua default-rsync.lua - -if INOTIFY -lsyncd_SOURCES += inotify.c -endif - -if FSEVENTS -lsyncd_SOURCES += fsevents.c -endif - -lsyncd_LDADD = $(LUA_LIBS) -exampledir = $(docdir)/ -dist_example_DATA = \ - examples/lbash.lua \ - examples/lecho.lua \ - examples/lgforce.lua \ - examples/limagemagic.lua \ - examples/lpostcmd.lua \ - examples/lrsync.lua \ - examples/lrsyncssh.lua -TESTS = \ - tests/churn-rsync.lua \ - tests/churn-rsyncssh.lua \ - tests/churn-direct.lua \ - tests/exclude-rsync.lua \ - tests/exclude-rsyncssh.lua \ - tests/schedule.lua \ - tests/l4rsyncdata.lua - -dist_man1_MANS = doc/lsyncd.1 -EXTRA_DIST = doc/lsyncd.1.txt inotify.c fsevents.c bin2carray.lua \ - default.lua default-rsync.lua default-rsyncssh.lua default-direct.lua - -doc/lsyncd.1: doc/lsyncd.1.txt - a2x --format=manpage $< - -CLEANFILES = runner.out defaults.out runner.c defaults.c - -# compiles the runner and the defaults into the binary -lsyncd_LDADD += runner.o defaults.o - -runner.o: runner.c -defaults.o: defaults.c - -runner.c: runner.out bin2carray.lua - $(LUA) ./bin2carray.lua $< runner $@ - -defaults.c: defaults.out bin2carray.lua - $(LUA) ./bin2carray.lua $< defaults $@ - -runner.out: lsyncd.lua - $(LUAC) -o $@ $< - -defaults.out: default.lua default-rsync.lua default-rsyncssh.lua default-direct.lua - $(LUAC) -o $@ $^ - diff --git a/cmake/FindLua.cmake b/cmake/FindLua.cmake new file mode 100644 index 0000000..7fb7ca3 --- /dev/null +++ b/cmake/FindLua.cmake @@ -0,0 +1,118 @@ +# Locate Lua library +# This module defines +# LUA_EXECUTABLE, if found +# LUA_FOUND, if false, do not try to link to Lua +# LUA_LIBRARIES +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) +# +# Note that the expected include convention is +# #include "lua.h" +# and not +# #include +# This is because, the lua location is not standardized and may exist +# in locations other than lua/ + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# Modified to support Lua 5.2 by LuaDist 2012 +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) +# +# The required version of Lua can be specified using the +# standard syntax, e.g. FIND_PACKAGE(Lua 5.1) +# Otherwise the module will search for any available Lua implementation + +# Always search for non-versioned lua first (recommended) +SET(_POSSIBLE_LUA_INCLUDE include include/lua) +SET(_POSSIBLE_LUA_EXECUTABLE lua) +SET(_POSSIBLE_LUA_LIBRARY lua) + +# Determine possible naming suffixes (there is no standard for this) +IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}") +ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1") +ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR) + +# Set up possible search names and locations +FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES}) + LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}") + LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}") + LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}") +ENDFOREACH(_SUFFIX) + +# Find the lua executable +FIND_PROGRAM(LUA_EXECUTABLE + NAMES ${_POSSIBLE_LUA_EXECUTABLE} +) + +# Find the lua header +FIND_PATH(LUA_INCLUDE_DIR lua.h + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE} + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +# Find the lua library +FIND_LIBRARY(LUA_LIBRARY + NAMES ${_POSSIBLE_LUA_LIBRARY} + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + +IF(LUA_LIBRARY) + # include the math library for Unix + IF(UNIX AND NOT APPLE) + FIND_LIBRARY(LUA_MATH_LIBRARY m) + SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + ELSE(UNIX AND NOT APPLE) + SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + ENDIF(UNIX AND NOT APPLE) +ENDIF(LUA_LIBRARY) + +# Determine Lua version +IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + UNSET(lua_version_str) +ENDIF() + +INCLUDE(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE) + diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..df5dae8 --- /dev/null +++ b/config.h.in @@ -0,0 +1,6 @@ +/* Lsyncd Version */ +#define PACKAGE_VERSION "@LSYNCD_VERSION@" + +/* File event notification mechanims available */ +#cmakedefine WITH_INOTIFY 1 +#cmakedefine WITH_FSEVENTS 1 diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 56d1bd8..0000000 --- a/configure.ac +++ /dev/null @@ -1,140 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -#AC_PREREQ(2.60) -AC_INIT(lsyncd, 2.1.5, axkibe@gmail.com) -AM_INIT_AUTOMAKE([foreign]) - -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_SRCDIR([lsyncd.c]) -AC_CONFIG_HEADER([config.h]) -AC_USE_SYSTEM_EXTENSIONS - -### -# Checks for programs. -AC_PROG_CC -AC_PROG_INSTALL -AC_PROG_MAKE_SET - -#AC_PATH_PROG([A2X], [a2x], [no]) -#if test x${A2X} = xno ; then -# AC_MSG_ERROR([Program 'a2x' (package asciidoc) is required]) -#fi - -### -# Checks for Lua - -# Try versioned Lua 5.2 first -PKG_CHECK_MODULES([LUA52], [lua5.2],,[ - PKG_CHECK_MODULES([LUA52], [lua52],,[ - PKG_CHECK_MODULES([LUA52], [lua-5.2],,[:]) - ]) -]) -AC_PATH_PROGS([LUA52], [lua5.2 lua52], [no]) -AC_PATH_PROGS([LUAC52], [luac5.2 luac52], [no]) - -if test -z "${LUA52_PKG_ERRORS}" -a "${LUA52}" != no -a "${LUAC52}" != no ; then - LUA_VERSION="5.2" - LUA_CFLAGS="${LUA52_CFLAGS}" - LUA_LIBS="${LUA52_LIBS}" - LUA="${LUA52}" - LUAC="${LUAC52}" -else - # Fall back to versioned Lua 5.1 - PKG_CHECK_MODULES([LUA51], [lua5.1 >= 5.1.3],,[ - PKG_CHECK_MODULES([LUA51], [lua51 >= 5.1.3],,[ - PKG_CHECK_MODULES([LUA51], [lua-5.1 >= 5.1.3],,[:]) - ]) - ]) - AC_PATH_PROGS([LUA51], [lua5.1 lua51], [no]) - AC_PATH_PROGS([LUAC51], [luac5.1 luac51], [no]) - - if test -z "${LUA51_PKG_ERRORS}" -a "${LUA51}" != no -a "${LUAC51}" != no ; then - LUA_VERSION="5.1" - LUA_CFLAGS="${LUA51_CFLAGS}" - LUA_LIBS="${LUA51_LIBS}" - LUA="${LUA51}" - LUAC="${LUAC51}" - else - # Try any Lua now - PKG_CHECK_MODULES([LUA], [lua >= 5.1.3],,[:]) - AC_PATH_PROG([LUA], [lua], [no]) - AC_PATH_PROG([LUAC], [luac], [no]) - - if test -z "${LUA_PKG_ERRORS}" -a "${LUA}" != no -a "${LUAC}" != no ; then - LUA_VERSION="(unknown version)" - else - AC_MSG_ERROR([Need a Lua toolchain with matching versions ('lua' library and 'lua' and 'luac' programs)]) - fi - fi -fi - -_LIBS="${LIBS}" -_CFLAGS="${CFLAGS}" -_CPPFLAGS="${CPPFLAGS}" -LIBS="-lm ${LIBS} ${LUA_LIBS}" -CFLAGS="${CFLAGS} ${LUA_CFLAGS}" -CPPFLAGS="${CPPFLAGS} ${LUA_CFLAGS}" - -AC_MSG_CHECKING([whether Lua library was compiled with compat support]) -AC_LINK_IFELSE( - [AC_LANG_PROGRAM([ - #define LUA_COMPAT_ALL - #include - ],[luaL_register(0,0,0);])], - [lua_compat_support=yes], - [lua_compat_support=no] -) -AC_MSG_RESULT([${lua_compat_support}]) - -if test "x${lua_compat_support}" = xno ; then - AC_MSG_ERROR([Lua library needs to be compiled with compat support]) -fi - -LIBS="${_LIBS}" -CFLAGS="${_CFLAGS}" -CPPFLAGS="${_CPPFLAGS}" -unset _LIBS _CFLAGS _CPPFLAGS - -AX_SUBST_L([LUA_CFLAGS], [LUA_LIBS], [LUA], [LUAC]) - - -### -# Checks for header files. -AC_CHECK_HEADERS([sys/inotify.h]) - -### -# --without-inotify option -AC_ARG_WITH([inotify], -[ --without-inotify Do not use Linux inotify event interface. On by default.], -[],[with_inotify=yes]) -if test "x${with_inotify}" == xyes; then - echo "compiling with inotify" - AC_DEFINE(LSYNCD_WITH_INOTIFY,,"descr") -else - echo "compiling without inotify" -fi -AM_CONDITIONAL([INOTIFY], [test x${with_inotify} != xno]) - -### -# --with-fsevents -# disabled per default, experimental, works only with OS X 10.5/10.6 -AC_ARG_WITH([fsevents], -[ --with-fsevents Uses MacOS (10.5) /dev/fsevents. EXPERIMENTAL! - Off by default.]) -if test "x${with_fsevents}" == xyes; then - echo "compiling with fsevents. WARNING experimental!" - AC_DEFINE(LSYNCD_WITH_FSEVENTS,,"descr") -fi -AM_CONDITIONAL([FSEVENTS], - [test x${with_fsevents} != x -a xno${with_fsevents} != xno]) - -# Checks for typedefs, structures, and compiler characteristics. -# Checks for library functions. -AC_CONFIG_FILES([Makefile]) -AC_OUTPUT - -AC_MSG_NOTICE([ -Summary: - Using Lua ${LUA_VERSION} -]) diff --git a/inotify.c b/inotify.c index 875e364..54322ad 100644 --- a/inotify.c +++ b/inotify.c @@ -12,10 +12,6 @@ #include "lsyncd.h" -#ifndef HAVE_SYS_INOTIFY_H -# error Missing ; supply kernel-headers and rerun configure. -#endif - #include #include #include diff --git a/lsyncd.c b/lsyncd.c index 676b9ec..baaed77 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -58,11 +58,9 @@ extern size_t defaults_size; /* | Makes sure there is one file system monitor. */ -#ifndef LSYNCD_WITH_INOTIFY -#ifndef LSYNCD_WITH_FANOTIFY -#ifndef LSYNCD_WITH_FSEVENTS -# error "need at least one notifcation system. please rerun ./configure" -#endif +#ifndef WITH_INOTIFY +#ifndef WITH_FSEVENTS +# error "needing at least one notification system. please rerun cmake" #endif #endif @@ -71,15 +69,11 @@ extern size_t defaults_size; */ static char *monitors[] = { -#ifdef LSYNCD_WITH_INOTIFY +#ifdef WITH_INOTIFY "inotify", #endif -#ifdef LSYNCD_WITH_FANOTIFY - "fanotify", -#endif - -#ifdef LSYNCD_WITH_FSEVENTS +#ifdef WITH_FSEVENTS "fsevents", #endif @@ -1925,7 +1919,7 @@ register_lsyncd( lua_State *L ) lua_pop( L, 1 ); // pop(mt) -#ifdef LSYNCD_WITH_INOTIFY +#ifdef WITH_INOTIFY lua_getglobal( L, LSYNCD_LIBNAME ); register_inotify( L ); @@ -2722,13 +2716,13 @@ main1( int argc, char *argv[] ) } } -#ifdef LSYNCD_WITH_INOTIFY +#ifdef WITH_INOTIFY open_inotify( L ); #endif -#ifdef LSYNCD_WITH_FSEVENTS +#ifdef WITH_FSEVENTS open_fsevents( L ); diff --git a/lsyncd.h b/lsyncd.h index fa598a7..073b3b4 100644 --- a/lsyncd.h +++ b/lsyncd.h @@ -141,26 +141,18 @@ extern void observe_fd( // stops the core to observe a file descriptor extern void nonobserve_fd(int fd); -/** +/* * inotify */ -#ifdef LSYNCD_WITH_INOTIFY +#ifdef WITH_INOTIFY extern void register_inotify(lua_State *L); extern void open_inotify(lua_State *L); #endif -/** - * fanotify - */ -#ifdef LSYNCD_WITH_FANOTIFY -extern void register_fanotify(lua_State *L); -extern void open_fanotify(lua_State *L); -#endif - -/** +/* * /dev/fsevents */ -#ifdef LSYNCD_WITH_FSEVENTS +#ifdef WITH_FSEVENTS extern void open_fsevents(lua_State *L); #endif