]> granicus.if.org Git - fortune-mod/commitdiff
Propagate the VERSION number to ./fortune.
authorShlomi Fish <shlomif@shlomifish.org>
Thu, 30 Nov 2017 09:33:39 +0000 (11:33 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Thu, 30 Nov 2017 09:33:39 +0000 (11:33 +0200)
See https://github.com/shlomif/fortune-mod/issues/16 .

fortune-mod/CMakeLists.txt
fortune-mod/config.h.in [new file with mode: 0644]
fortune-mod/fortune/fortune.c
fortune-mod/util/strfile.c
fortune-mod/util/strfile.h

index 643e18307e5e2b5d4fc443d1e07a9d6e0b798001..9ca8e54530c93509ae3bd9cca52a1289bf74e157 100644 (file)
@@ -101,6 +101,9 @@ IF (NOT "${HAVE_RECODE_H}")
     MESSAGE(FATAL_ERROR "Cannot find recode.h anywhere - please install lib recode")
 ENDIF ()
 
+# So it can find config.h
+INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_BINARY_DIR}")
+
 MACRO(my_exe exe c_file dir)
     ADD_EXECUTABLE("${exe}" "${c_file}")
     INSTALL(TARGETS "${exe}" RUNTIME DESTINATION "${dir}")
@@ -251,4 +254,20 @@ ADD_CUSTOM_TARGET(
     "perl" "${CMAKE_SOURCE_DIR}/run-tests.pl" "--src-dir" "${CMAKE_SOURCE_DIR}" "--cookies" "${COOKIES_STR}"
 )
 
+# Rebuild config.h if ver.txt has changed.
+ADD_CUSTOM_COMMAND(
+    OUTPUT "config.h.in"
+    DEPENDS "ver.txt"
+    COMMAND "touch"
+    ARGS "config.h.in"
+)
+
+SET(AUTOGENERATED_CONFIG_H "config.h was auto-generated from config.h.in . Do not modify directly")
+
+CONFIGURE_FILE(
+    ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
+    ${CMAKE_CURRENT_BINARY_DIR}/config.h
+    )
+
+
 INCLUDE(CPack)
diff --git a/fortune-mod/config.h.in b/fortune-mod/config.h.in
new file mode 100644 (file)
index 0000000..4609bba
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * config.h - Configuration file fortune-mod
+ *
+ * ${AUTOGENERATED_CONFIG_H}
+*/
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Version number of package */
+#define VERSION "${VERSION}"
+
+#ifdef __cplusplus
+}
+#endif
index 9acd54c79453e92bfb3a1a3406ff148cb0d7475d..d5d30fce8b7b9e62dc9929d998dfe1acc430d8f4 100644 (file)
@@ -97,7 +97,6 @@ static char rcsid[] = "$NetBSD: fortune.c,v 1.8 1995/03/23 08:28:40 cgd Exp $";
 #endif /* killing warnings */
 
 #define         PROGRAM_NAME            "fortune-mod"
-#define         PROGRAM_VERSION         "1.99.4"
 
 #include <stdbool.h>
 
@@ -137,6 +136,7 @@ static char rcsid[] = "$NetBSD: fortune.c,v 1.8 1995/03/23 08:28:40 cgd Exp $";
 #include        <rx.h>
 #endif
 
+#include        "config.h"
 #include        "strfile.h"
 
 #define TRUE    1
@@ -240,7 +240,7 @@ int add_dir(register FILEDESC *);
 static char *program_version(void)
 {
     static char buf[BUFSIZ];
-    (void) sprintf(buf, "%s version %s", PROGRAM_NAME, PROGRAM_VERSION);
+    (void) sprintf(buf, "%s version %s", PROGRAM_NAME, VERSION);
     return buf;
 }
 
index e8b4d411f44168e3a7807938f30fb80ed570ab62..054c0fde4985b85a24f26a2d563eaac4b8e5e005 100644 (file)
@@ -437,7 +437,7 @@ int main(int ac, char **av)
     Tbl.str_longlen = 0;
     Tbl.str_shortlen = (unsigned int) 0xffffffff;
     Tbl.str_delim = (uint8_t)Delimch;
-    Tbl.str_version = VERSION;
+    Tbl.str_version = STRFILE_VERSION;
     first = Oflag;
     add_offset(outf, (int32_t)ftell(inf));
     last_off = 0;
index 517e11579d3a9af5b8cc96d44411fca4319ef64b..4829889395de13f0d8888008ee252266821741a1 100644 (file)
@@ -42,7 +42,7 @@
     ((line)[0] == (tbl).str_delim && (line)[1] == '\n')
 
 typedef struct {                /* information table */
-#define VERSION     2
+#define STRFILE_VERSION     2
     uint32_t   str_version;        /* version number */
     uint32_t   str_numstr;     /* # of strings in the file */
     uint32_t   str_longlen;        /* length of longest string */