summaryrefslogtreecommitdiffstats
path: root/tools/mkembedconfig
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mkembedconfig')
-rw-r--r--tools/mkembedconfig/CMakeLists.txt24
-rw-r--r--tools/mkembedconfig/mkembedconfig.c51
2 files changed, 75 insertions, 0 deletions
diff --git a/tools/mkembedconfig/CMakeLists.txt b/tools/mkembedconfig/CMakeLists.txt
new file mode 100644
index 0000000..90fe0ce
--- /dev/null
+++ b/tools/mkembedconfig/CMakeLists.txt
@@ -0,0 +1,24 @@
+# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
+
+set(mkembedconfig_SOURCES
+ mkembedconfig.c
+)
+
+add_executable(mkembedconfig ${mkembedconfig_SOURCES})
+
+set_target_properties (
+ mkembedconfig PROPERTIES
+ FOLDER Bin
+)
+
+macro(MKEMBEDCONFIG_TARGET EmbedInput EmbedOutput)
+ add_custom_command(
+ OUTPUT ${EmbedOutput}
+ COMMAND mkembedconfig
+ ARGS ${EmbedInput} ${CMAKE_CURRENT_BINARY_DIR}/${EmbedOutput}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS mkembedconfig ${EmbedInput}
+ )
+ set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${EmbedOutput} PROPERTY EXCLUDE_UNITY_BUILD TRUE)
+endmacro()
+
diff --git a/tools/mkembedconfig/mkembedconfig.c b/tools/mkembedconfig/mkembedconfig.c
new file mode 100644
index 0000000..ae23087
--- /dev/null
+++ b/tools/mkembedconfig/mkembedconfig.c
@@ -0,0 +1,51 @@
+/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ FILE *infp, *outfp;
+
+ if (argc < 3) {
+ fprintf(stderr, "Syntax: %s <in-file> <out-file>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ infp = fopen(argv[1], "r");
+
+ if (!infp) {
+ perror("fopen");
+ return EXIT_FAILURE;
+ }
+
+ outfp = fopen(argv[2], "w");
+
+ if (!outfp) {
+ fclose(infp);
+ perror("fopen");
+ return EXIT_FAILURE;
+ }
+
+ fprintf(outfp, "/* This file has been automatically generated\n"
+ " from the input file \"%s\". */\n\n", argv[1]);
+ fputs("#include \"config/configfragment.hpp\"\n\nnamespace {\n\nconst char *fragment = R\"CONFIG_FRAGMENT(", outfp);
+
+ while (!feof(infp)) {
+ char buf[1024];
+ size_t rc = fread(buf, 1, sizeof(buf), infp);
+
+ if (rc == 0)
+ break;
+
+ fwrite(buf, rc, 1, outfp);
+ }
+
+ fprintf(outfp, ")CONFIG_FRAGMENT\";\n\nREGISTER_CONFIG_FRAGMENT(\"%s\", fragment);\n\n}", argv[1]);
+
+ fclose(outfp);
+ fclose(infp);
+
+ return EXIT_SUCCESS;
+}