]> source.dussan.org Git - rspamd.git/commitdiff
Add lua preprocessing code
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Dec 2015 00:19:56 +0000 (00:19 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Dec 2015 00:19:56 +0000 (00:19 +0000)
src/rspamadm/CMakeLists.txt
src/rspamadm/lua_preprocess.cmake [new file with mode: 0644]

index 44da69156ab0d734848d95fd13be323779916f6e..80a253c20e523318f6b069997d3c141197684bcb 100644 (file)
@@ -1,4 +1,11 @@
-SET(RSPAMADMSRC rspamadm.c commands.c pw.c keypair.c configtest.c
+SET(RSPAMADMSRC rspamadm.c
+        commands.c
+        pw.c
+        keypair.c
+        configtest.c
+        fuzzy_merge.c
+        configdump.c
+        control.c
         ${CMAKE_BINARY_DIR}/src/workers.c
         ${CMAKE_BINARY_DIR}/src/modules.c
         ${CMAKE_SOURCE_DIR}/src/controller.c
@@ -6,11 +13,18 @@ SET(RSPAMADMSRC rspamadm.c commands.c pw.c keypair.c configtest.c
         ${CMAKE_SOURCE_DIR}/src/lua_worker.c
         ${CMAKE_SOURCE_DIR}/src/smtp_proxy.c
         ${CMAKE_SOURCE_DIR}/src/worker.c
-        ${CMAKE_SOURCE_DIR}/src/http_proxy.c fuzzy_merge.c configdump.c control.c)
+        ${CMAKE_SOURCE_DIR}/src/http_proxy.c)
+SET(RSPAMADMLUASRC ${CMAKE_CURRENT_SOURCE_DIR}/fuzzy_stat.lua)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+ADD_CUSTOM_TARGET(rspamadm_lua_preprocess
+        ${CMAKE_COMMAND} -DRSPAMADMLUASRC=${RSPAMADMLUASRC}
+            -P ${CMAKE_CURRENT_SOURCE_DIR}/lua_preprocess.cmake
+        SOURCES ${RSPAMADMLUASRC})
 IF (ENABLE_HYPERSCAN MATCHES "ON")
     LIST(APPEND RSPAMADMSRC "${CMAKE_SOURCE_DIR}/src/hs_helper.c")
 ENDIF()
 ADD_EXECUTABLE(rspamadm ${RSPAMADMSRC})
+ADD_DEPENDENCIES(rspamadm rspamadm_lua_preprocess)
 TARGET_LINK_LIBRARIES(rspamadm rspamd-server)
 TARGET_LINK_LIBRARIES(rspamadm ${RSPAMD_REQUIRED_LIBRARIES})
 
diff --git a/src/rspamadm/lua_preprocess.cmake b/src/rspamadm/lua_preprocess.cmake
new file mode 100644 (file)
index 0000000..13a2348
--- /dev/null
@@ -0,0 +1,22 @@
+FOREACH(_LUA_SRC ${RSPAMADMLUASRC})
+    GET_FILENAME_COMPONENT(_LUA_BASE ${_LUA_SRC} NAME_WE)
+    FILE(READ ${_LUA_SRC} _FILE_DATA)
+    STRING(REPLACE \" \\\" _OUT1 ${_FILE_DATA})
+    # Convert into cmake list
+    STRING(REGEX REPLACE ";" "\\\\;" _OUT2 "${_OUT1}")
+    STRING(REPLACE "\n" ";" _OUT3 "${_OUT2}")
+    FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_LUA_BASE}.lua.h" "
+#ifndef ${_LUA_BASE}_H
+#define ${_LUA_BASE}_H
+
+static const char rspamadm_script_${_LUA_BASE}[] = \"\"
+")
+    FOREACH(_LINE ${_OUT3})
+        STRING(REGEX REPLACE "^(.+)$" "\"\\1\\\\n\"\n" _OUT4 "${_LINE}")
+        FILE(APPEND "${CMAKE_CURRENT_BINARY_DIR}/${_LUA_BASE}.lua.h" ${_OUT4})
+    ENDFOREACH()
+
+    FILE(APPEND "${CMAKE_CURRENT_BINARY_DIR}/${_LUA_BASE}.lua.h" "\"\";
+#endif
+")
+ENDFOREACH()