]> source.dussan.org Git - rspamd.git/commitdiff
Use perl instead of bloody cmake for string manipulation
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Dec 2015 14:36:12 +0000 (14:36 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Dec 2015 14:36:12 +0000 (14:36 +0000)
CMakeLists.txt
src/rspamadm/CMakeLists.txt
src/rspamadm/lua_preprocess.cmake [deleted file]
src/rspamadm/lua_preprocess.pl [new file with mode: 0644]

index 67ff501cdaa9a879e9401afb5be7d206069361bf..add82c1523bacf5f3547158495c0dc44b1866b3d 100644 (file)
@@ -157,9 +157,7 @@ INCLUDE(CheckCCompilerFlag)
 INCLUDE(CMakeParseArguments)
 
 FIND_PACKAGE(PkgConfig REQUIRED)
-IF (ENABLE_SNOWBALL MATCHES "ON")
-       FIND_PACKAGE(Perl REQUIRED)
-ENDIF()
+FIND_PACKAGE(Perl REQUIRED)
 
 ############################# MACRO SECTION #############################################
 
index 80a253c20e523318f6b069997d3c141197684bcb..c69bf0cbe179a6f636ccdb57528da5d25489f311 100644 (file)
@@ -17,9 +17,11 @@ SET(RSPAMADMSRC rspamadm.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})
+        ${PERL_EXECUTABLE}
+            "${CMAKE_CURRENT_SOURCE_DIR}/lua_preprocess.pl"
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            "${CMAKE_CURRENT_BINARY_DIR}"
+        SOURCES ${RSPAMADMLUASRC} ${CMAKE_CURRENT_SOURCE_DIR}/lua_preprocess.pl)
 IF (ENABLE_HYPERSCAN MATCHES "ON")
     LIST(APPEND RSPAMADMSRC "${CMAKE_SOURCE_DIR}/src/hs_helper.c")
 ENDIF()
diff --git a/src/rspamadm/lua_preprocess.cmake b/src/rspamadm/lua_preprocess.cmake
deleted file mode 100644 (file)
index 13a2348..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-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()
diff --git a/src/rspamadm/lua_preprocess.pl b/src/rspamadm/lua_preprocess.pl
new file mode 100644 (file)
index 0000000..6384df2
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use warnings FATAL => 'all';
+use strict;
+
+my ($in_dir, $out_dir) = @ARGV;
+my @files = <$in_dir/*.lua>;
+
+foreach my $file (@files) {
+    $file =~ /([^\/.]+)(.lua)$/;
+    my $fname = "$1$2";
+    my $varname = "rspamadm_script_$1";
+    my $definename = uc $varname;
+
+    open(IN, "< $file") or die "input missing";
+    open(OUT, "> $out_dir/$fname.h") or die "output missing";
+
+    print OUT <<EOD;
+#ifndef ${definename}_GUARD_H
+#define ${definename}_GUARD_H
+
+static const char ${varname}\[\] = ""
+EOD
+
+    while (<IN>) {
+        $_ =~ s/^(.*)$/"$1\\n"/;
+        print OUT $_;
+    }
+    print OUT <<EOD;
+"";
+#endif
+EOD
+    close IN;
+    close OUT;
+}