From 09c24256c31202f036331bdb8592d72dce7a8f31 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 30 Nov 2017 11:33:39 +0200 Subject: [PATCH] Propagate the VERSION number to ./fortune. See https://github.com/shlomif/fortune-mod/issues/16 . --- fortune-mod/CMakeLists.txt | 19 +++++++++++++++++++ fortune-mod/config.h.in | 17 +++++++++++++++++ fortune-mod/fortune/fortune.c | 4 ++-- fortune-mod/util/strfile.c | 2 +- fortune-mod/util/strfile.h | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 fortune-mod/config.h.in diff --git a/fortune-mod/CMakeLists.txt b/fortune-mod/CMakeLists.txt index 643e183..9ca8e54 100644 --- a/fortune-mod/CMakeLists.txt +++ b/fortune-mod/CMakeLists.txt @@ -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 index 0000000..4609bba --- /dev/null +++ b/fortune-mod/config.h.in @@ -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 diff --git a/fortune-mod/fortune/fortune.c b/fortune-mod/fortune/fortune.c index 9acd54c..d5d30fc 100644 --- a/fortune-mod/fortune/fortune.c +++ b/fortune-mod/fortune/fortune.c @@ -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 @@ -137,6 +136,7 @@ static char rcsid[] = "$NetBSD: fortune.c,v 1.8 1995/03/23 08:28:40 cgd Exp $"; #include #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; } diff --git a/fortune-mod/util/strfile.c b/fortune-mod/util/strfile.c index e8b4d41..054c0fd 100644 --- a/fortune-mod/util/strfile.c +++ b/fortune-mod/util/strfile.c @@ -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; diff --git a/fortune-mod/util/strfile.h b/fortune-mod/util/strfile.h index 517e115..4829889 100644 --- a/fortune-mod/util/strfile.h +++ b/fortune-mod/util/strfile.h @@ -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 */ -- 2.40.0