INCLUDE(CMakeParseArguments)
FIND_PACKAGE(PkgConfig REQUIRED)
-IF (ENABLE_SNOWBALL MATCHES "ON")
- FIND_PACKAGE(Perl REQUIRED)
-ENDIF()
+FIND_PACKAGE(Perl REQUIRED)
############################# MACRO SECTION #############################################
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()
+++ /dev/null
-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()
--- /dev/null
+#!/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;
+}