From a4caaed0a2699936cc40b4f260a49033ae2ea807 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 26 Jan 2011 21:37:48 +0300 Subject: [PATCH] * Add ability to build FreeBSD package from rspamd sources --- CMakeLists.txt | 136 +++++++++++++++++++++------------- freebsd/cmake/PkgCreate.cmake | 56 ++++++++++++++ freebsd/rspamd.plist | 29 ++++++++ 3 files changed, 169 insertions(+), 52 deletions(-) create mode 100644 freebsd/cmake/PkgCreate.cmake create mode 100644 freebsd/rspamd.plist diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ad2d777a..17dd4d738 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,15 +55,21 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") IF(ENABLE_REDIRECTOR MATCHES "ON") CONFIGURE_FILE(freebsd/redirector.sh.in freebsd/redirector.sh @ONLY) ENDIF(ENABLE_REDIRECTOR MATCHES "ON") - IF(NOT ETC_PREFIX) - SET(ETC_PREFIX /usr/local/etc) - ENDIF(NOT ETC_PREFIX) - IF(NOT MAN_PREFIX) - SET(MAN_PREFIX /usr/local/man) - ENDIF(NOT MAN_PREFIX) - IF(NOT PREFIX) - SET(PREFIX /usr/local) - ENDIF(NOT PREFIX) + IF(CMAKE_INSTALL_PREFIX) + SET(ETC_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(MAN_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(PREFIX "${CMAKE_INSTALL_PREFIX}") + ELSE(CMAKE_INSTALL_PREFIX) + IF(NOT ETC_PREFIX) + SET(ETC_PREFIX /usr/local/etc) + ENDIF(NOT ETC_PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/local/man) + ENDIF(NOT MAN_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /usr/local) + ENDIF(NOT PREFIX) + ENDIF(CMAKE_INSTALL_PREFIX) FIND_LIBRARY(LIBINTL_LIBRARY NAMES intl PATHS /lib /opt/lib /usr/lib @@ -76,16 +82,22 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -DDARWIN") - - IF(NOT ETC_PREFIX) - SET(ETC_PREFIX /usr/local/etc) - ENDIF(NOT ETC_PREFIX) - IF(NOT MAN_PREFIX) - SET(MAN_PREFIX /usr/local/man) - ENDIF(NOT MAN_PREFIX) - IF(NOT PREFIX) - SET(PREFIX /usr/local) - ENDIF(NOT PREFIX) + + IF(CMAKE_INSTALL_PREFIX) + SET(ETC_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(MAN_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(PREFIX "${CMAKE_INSTALL_PREFIX}") + ELSE(CMAKE_INSTALL_PREFIX) + IF(NOT ETC_PREFIX) + SET(ETC_PREFIX /usr/local/etc) + ENDIF(NOT ETC_PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/local/man) + ENDIF(NOT MAN_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /usr/local) + ENDIF(NOT PREFIX) + ENDIF(CMAKE_INSTALL_PREFIX) FIND_LIBRARY(LIBINTL_LIBRARY NAMES intl PATHS /lib /opt/lib @@ -99,15 +111,22 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Darwin") IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DLINUX") - IF(NOT ETC_PREFIX) - SET(ETC_PREFIX /etc) - ENDIF(NOT ETC_PREFIX) - IF(NOT PREFIX) - SET(PREFIX /usr) - ENDIF(NOT PREFIX) - IF(NOT MAN_PREFIX) - SET(MAN_PREFIX /usr/share/man) - ENDIF(NOT MAN_PREFIX) + IF(CMAKE_INSTALL_PREFIX) + SET(ETC_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(MAN_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(PREFIX "${CMAKE_INSTALL_PREFIX}") + ELSE(CMAKE_INSTALL_PREFIX) + IF(NOT ETC_PREFIX) + SET(ETC_PREFIX /etc) + ENDIF(NOT ETC_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /usr) + ENDIF(NOT PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/share/man) + ENDIF(NOT MAN_PREFIX) + ENDIF(CMAKE_INSTALL_PREFIX) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl) MESSAGE(STATUS "Configuring for Linux") @@ -115,16 +134,22 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DSOLARIS") - IF(NOT ETC_PREFIX) - SET(ETC_PREFIX /etc) - ENDIF(NOT ETC_PREFIX) - IF(NOT PREFIX) - SET(PREFIX /opt/rspamd) - ENDIF(NOT PREFIX) - IF(NOT MAN_PREFIX) - SET(MAN_PREFIX /usr/share/man) - ENDIF(NOT MAN_PREFIX) - + IF(CMAKE_INSTALL_PREFIX) + SET(ETC_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(MAN_PREFIX "${CMAKE_INSTALL_PREFIX}/etc") + SET(PREFIX "${CMAKE_INSTALL_PREFIX}") + ELSE(CMAKE_INSTALL_PREFIX) + IF(NOT ETC_PREFIX) + SET(ETC_PREFIX /etc) + ENDIF(NOT ETC_PREFIX) + IF(NOT PREFIX) + SET(PREFIX /opt/rspamd) + ENDIF(NOT PREFIX) + IF(NOT MAN_PREFIX) + SET(MAN_PREFIX /usr/share/man) + ENDIF(NOT MAN_PREFIX) + ENDIF(CMAKE_INSTALL_PREFIX) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES rt) LIST(APPEND CMAKE_REQUIRED_LIBRARIES dl) LIST(APPEND CMAKE_REQUIRED_LIBRARIES resolv) @@ -626,15 +651,15 @@ ADD_CUSTOM_COMMAND(OUTPUT src/modules.c WORKING_DIRECTORY src) IF(PERL_EXECUTABLE) - ADD_CUSTOM_COMMAND(OUTPUT perl/Makefile - DEPENDS perl/Makefile.PL + ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_SOURCE_DIR}/perl/Makefile + DEPENDS ${CMAKE_SOURCE_DIR}/perl/Makefile.PL COMMAND ${PERL_EXECUTABLE} ./Makefile.PL DESTDIR=${DESTDIR} PREFIX=${PREFIX} INSTALLMAN3DIR=${MAN_PREFIX}/man3 - WORKING_DIRECTORY perl) + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/perl) CONFIGURE_FILE(perl/Makefile.PL.in perl/Makefile.PL) ADD_CUSTOM_TARGET(perlmodule - COMMAND make - DEPENDS perl/Makefile - WORKING_DIRECTORY perl + COMMAND ${CMAKE_MAKE_PROGRAM} DESTDIR=${DESTDIR} + DEPENDS ${CMAKE_SOURCE_DIR}/perl/Makefile + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/perl VERBATIM) ENDIF(PERL_EXECUTABLE) @@ -746,12 +771,12 @@ IF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd) INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${DESTDIR}/${ETC_PREFIX}/rspamd)") ENDIF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd) -INSTALL(FILES conf/2tld.inc RENAME 2tld.inc.orig DESTINATION ${ETC_PREFIX}/rspamd) +INSTALL(FILES conf/2tld.inc RENAME 2tld.inc.orig DESTINATION etc/rspamd) IF(NOT EXISTS ${ETC_PREFIX}/rspamd/2tld.inc) - INSTALL(FILES conf/2tld.inc DESTINATION ${ETC_PREFIX}/rspamd) + INSTALL(FILES conf/2tld.inc DESTINATION etc/rspamd) ENDIF(NOT EXISTS ${ETC_PREFIX}/rspamd/2tld.inc) -INSTALL(FILES conf/rspamd.xml.sample DESTINATION ${ETC_PREFIX}/) +INSTALL(FILES conf/rspamd.xml.sample DESTINATION etc/) # Lua plugins IF(NOT IS_DIRECTORY ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/lua) @@ -765,7 +790,7 @@ FOREACH(LUA_PLUGIN ${LUA_PLUGINS}) INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/lua/${_rp})") ENDIF(NOT IS_DIRECTORY ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/lua/${_rp}) IF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/${_rp}/${LUA_PLUGIN}) - INSTALL(FILES "src/plugins/lua/${LUA_PLUGIN}" DESTINATION ${ETC_PREFIX}/rspamd/plugins/lua/${_rp}) + INSTALL(FILES "src/plugins/lua/${LUA_PLUGIN}" DESTINATION etc/rspamd/plugins/lua/${_rp}) ENDIF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/plugins/${_rp}/${LUA_PLUGIN}) ENDFOREACH(LUA_PLUGIN) @@ -780,7 +805,7 @@ FOREACH(LUA_CONF ${LUA_CONFIGS}) INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp})") ENDIF(NOT IS_DIRECTORY ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp}) IF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp}/${LUA_CONF}) - INSTALL(FILES "conf/lua/${LUA_CONF}" DESTINATION ${ETC_PREFIX}/rspamd/lua/${_rp}) + INSTALL(FILES "conf/lua/${LUA_CONF}" DESTINATION etc/rspamd/lua/${_rp}) ENDIF(NOT EXISTS ${DESTDIR}/${ETC_PREFIX}/rspamd/lua/${_rp}/${LUA_CONF}) ENDFOREACH(LUA_CONF) @@ -804,7 +829,7 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT BUILD_PORT) INSTALL(CODE "EXECUTE_PROCESS(COMMAND chown ${RSPAMD_USER}:${RSPAMD_GROUP} ${DESTDIR}/var/run/rspamd/)") ENDIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT BUILD_PORT) IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") - INSTALL(PROGRAMS linux/rspamd DESTINATION ${ETC_PREFIX}/init.d) + INSTALL(PROGRAMS linux/rspamd DESTINATION etc/init.d) INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${DESTDIR}/var/run/rspamd/)") INSTALL(CODE "EXECUTE_PROCESS(COMMAND chown ${RSPAMD_USER}:${RSPAMD_GROUP} ${DESTDIR}/var/run/rspamd/)") ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") @@ -824,6 +849,10 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") INCLUDE("linux/cmake/UseRPMTools.cmake") ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") +IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + INCLUDE("freebsd/cmake/PkgCreate.cmake") +ENDIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + SET(RPMNAME "rspamd") SET(PACKAGE_NAME "rspamd") SET(PACKAGE_RELEASE "1") @@ -840,7 +869,7 @@ ELSE(GMIME24) SET(PACKAGE_DEPENDS "libc6, libevent-1.4-2, libgmime-2.0-2, libxml-parser-perl, libterm-readkey-perl, libglib2.0-0") ENDIF(GMIME24) -SET(PACKAGE_VERSION "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}") +SET(PACKAGE_VERSION "${RSPAMD_VERSION_MAJOR}.${RSPAMD_VERSION_MINOR}.${RSPAMD_VERSION_PATCH}_${ID}") IF(RPMTools_FOUND) @@ -896,4 +925,7 @@ ENDIF(RPMTools_FOUND) IF(DPKG_FOUND STREQUAL "YES") ADD_DEBIAN_PACKAGE("rspamd") -ENDIF(DPKG_FOUND STREQUAL "YES") \ No newline at end of file +ENDIF(DPKG_FOUND STREQUAL "YES") +IF(PKGCREATE_FOUND STREQUAL "YES") + ADD_FREEBSD_PACKAGE("rspamd" "freebsd/rspamd.plist") +ENDIF(PKGCREATE_FOUND STREQUAL "YES") \ No newline at end of file diff --git a/freebsd/cmake/PkgCreate.cmake b/freebsd/cmake/PkgCreate.cmake new file mode 100644 index 000000000..547e8c967 --- /dev/null +++ b/freebsd/cmake/PkgCreate.cmake @@ -0,0 +1,56 @@ +# PkgCreate creates FreeBSD package for cmake +# USAGE : ADD_FREEBSD_PACKAGE ( PKG_TARGET_NAME [DESCRIPTION] ) + +FIND_PROGRAM(PKGCREATE + NAMES pkg_create + PATHS "/usr/sbin") + +IF ( PKGCREATE ) + GET_FILENAME_COMPONENT(PKGCREATE_PATH ${PKGCREATE} ABSOLUTE) + MESSAGE(STATUS "Found pkg_create : ${PKGCREATE_PATH}") + SET(PKGCREATE_FOUND "YES") +ELSE ( PKGCREATE ) + MESSAGE(STATUS "pkg_create NOT found. package generation will not be available") + SET(PKGCREATE_FOUND "NO") +ENDIF ( PKGCREATE ) + +MACRO(ADD_FREEBSD_PACKAGE PKGNAME PLIST_FILE) + # let's create a directory to call 'make install DESTDIR=...' into: + SET ( FREEBSD_DIR ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}-${PACKAGE_RELEASE} ) + FILE ( REMOVE ${FREEBSD_DIR} ) + FILE ( MAKE_DIRECTORY ${FREEBSD_DIR} ) + FILE ( MAKE_DIRECTORY ${FREEBSD_DIR}/pkg ) + # Calling "make install DESTDIR=${FREEBSD_DIR}" + ADD_CUSTOM_TARGET(pkg_destdir_install + COMMAND ${CMAKE_MAKE_PROGRAM} install CMAKE_INSTALL_PREFIX=/ DESTDIR=${FREEBSD_DIR} + DEPENDS ${CMAKE_BINARY_DIR}/cmake_install.cmake + COMMENT "Installing with DESTDIR = ${FREEBSD_DIR}" + ) + ADD_DEPENDENCIES(pkg_destdir_install pkg_destdir_preinstall) + ADD_CUSTOM_TARGET(pkg_destdir_preinstall + COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=/ -DDESTDIR=${FREEBSD_DIR} . + DEPENDS ${CMAKE_BINARY_DIR}/cmake_install.cmake + COMMENT "Configuring with DESTDIR = ${FREEBSD_DIR}" + ) + ADD_DEPENDENCIES(pkg_destdir_preinstall all preinstall) + + + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}-${PACKAGE_RELEASE}.tbz + COMMAND ${PKGCREATE_PATH} -c -"${PACKAGE_DESCRIPTION_SUMMARY}" + -d -"${PACKAGE_DESCRIPTION}" + -f ${PLIST_FILE} + -p ${FREEBSD_DIR} + ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}-${PACKAGE_RELEASE}.tbz + # removing control, so its (re)generated each time we need to build the package + DEPENDS ${PLIST_FILE} + COMMENT "Generating freebsd package" + ) + + # the final target: + ADD_CUSTOM_TARGET(${PKGNAME}_pkg + DEPENDS ${CMAKE_BINARY_DIR}/${PACKAGE_NAME}_${PACKAGE_VERSION}-${PACKAGE_RELEASE}.tbz + ) + + ADD_DEPENDENCIES(${PKGNAME}_pkg pkg_destdir_install) +ENDMACRO(ADD_FREEBSD_PACKAGE PKGNAME) \ No newline at end of file diff --git a/freebsd/rspamd.plist b/freebsd/rspamd.plist new file mode 100644 index 000000000..9aa563522 --- /dev/null +++ b/freebsd/rspamd.plist @@ -0,0 +1,29 @@ +etc/rspamd/plugins/lua/maillist.lua +etc/rspamd/plugins/lua/trie.lua +etc/rspamd/plugins/lua/received_rbl.lua +etc/rspamd/plugins/lua/multimap.lua +etc/rspamd/plugins/lua/phishing.lua +etc/rspamd/plugins/lua/once_received.lua +etc/rspamd/plugins/lua/whitelist.lua +etc/rspamd/plugins/lua/forged_recipients.lua +etc/rspamd/2tld.inc.orig +etc/rspamd/lua/rspamd.lua +etc/rspamd/lua/regexp/lotto.lua +etc/rspamd/lua/regexp/headers.lua +etc/rspamd/lua/regexp/drugs.lua +etc/rspamd/lua/regexp/fraud.lua +@unexec if cmp -s %D/etc/rspamd.xml.sample %D/etc/rspamd.xml; then rm -f %D/etc/rspamd.xml; fi +etc/rspamd.xml.sample +bin/rspamc +bin/rspamd +lib/librspamd_ipmark.so +lib/librspamd_regmark.so +@dirrm etc/rspamd/plugins/lua +@dirrm etc/rspamd/plugins +@dirrm etc/rspamd/lua/regexp +@dirrm etc/rspamd/lua +@dirrm etc/rspamd + +@unexec rmdir %D/etc/rspamd 2>/dev/null || true +@unexec rmdir /var/run/rspamd 2>/dev/null || true +@unexec %D/etc/rc.d/rspamd.sh forcestop 2>/dev/null || true -- 2.39.5