You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.9 KiB

  1. From: James McCoy <jamessan@jamessan.com>
  2. Date: Thu, 28 Jan 2016 10:55:11 -0500
  3. Subject: Support defining compilation date in $SOURCE_DATE_EPOCH
  4. There is an ongoing effort[0] to make FOSS software reproducibly
  5. buildable. In order to make Vim build reproducibly, it is necessary to
  6. allow defining the date/time that is part of VIM_VERSION_LONG as part of
  7. the build process.
  8. This commit enables that by adding support for the SOURCE_DATE_EPOCH
  9. spec[1]. When the $SOURCE_DATE_EPOCH environment variable is defined,
  10. it will be used to populate the BUILD_DATE preprocessor define.
  11. If BUILD_DATE is not defined, the existing behavior of relying on the
  12. preprocessor's __DATE__/__TIME__ symbols will be used.
  13. [0]: https://reproducible-builds.org/
  14. [1]: https://reproducible-builds.org/specs/source-date-epoch/
  15. ---
  16. src/config.h.in | 3 +++
  17. src/configure.ac | 10 ++++++++++
  18. src/version.c | 6 ++++++
  19. 3 files changed, 19 insertions(+)
  20. diff --git a/src/config.h.in b/src/config.h.in
  21. index e692d40..d3aa1a2 100644
  22. --- a/src/config.h.in
  23. +++ b/src/config.h.in
  24. @@ -30,6 +30,9 @@
  25. /* Define when __DATE__ " " __TIME__ can be used */
  26. #undef HAVE_DATE_TIME
  27. +/* Defined as the date of last modification */
  28. +#undef BUILD_DATE
  29. +
  30. /* Define when __attribute__((unused)) can be used */
  31. #undef HAVE_ATTRIBUTE_UNUSED
  32. diff --git a/src/configure.ac b/src/configure.ac
  33. index e287124..5a16797 100644
  34. --- a/src/configure.ac
  35. +++ b/src/configure.ac
  36. @@ -29,6 +29,16 @@ dnl in autoconf needs it, where it uses STDC_HEADERS.
  37. AC_HEADER_STDC
  38. AC_HEADER_SYS_WAIT
  39. +dnl If $SOURCE_DATE_EPOCH is present in the environment, use that as the
  40. +dnl "compiled" timestamp in :version's output. Attempt to get the formatted
  41. +dnl date using GNU date syntax, BSD date syntax, and finally falling back to
  42. +dnl just using the current time.
  43. +if test -n "$SOURCE_DATE_EPOCH"; then
  44. + DATE_FMT="%b %d %Y %H:%M:%S"
  45. + BUILD_DATE=$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" "+$DATE_FMT" 2>/dev/null || LC_ALL=C date -u -r "$SOURCE_DATE_EPOCH" "+$DATE_FMT" 2>/dev/null || LC_ALL=C date -u "+$DATE_FMT")
  46. + AC_DEFINE_UNQUOTED(BUILD_DATE, ["$BUILD_DATE"])
  47. +fi
  48. +
  49. dnl Check that the C99 features that Vim uses are supported:
  50. if test x"$ac_cv_prog_cc_c99" != xno; then
  51. dnl If the compiler doesn't explicitly support C99, then check
  52. diff --git a/src/version.c b/src/version.c
  53. index 65f5a4b..9422657 100644
  54. --- a/src/version.c
  55. +++ b/src/version.c
  56. @@ -44,11 +44,17 @@ make_version(void)
  57. * VAX C can't catenate strings in the preprocessor.
  58. */
  59. strcpy(longVersion, VIM_VERSION_LONG_DATE);
  60. +#ifdef BUILD_DATE
  61. + strcat(longVersion, BUILD_DATE);
  62. +#else
  63. strcat(longVersion, __DATE__);
  64. strcat(longVersion, " ");
  65. strcat(longVersion, __TIME__);
  66. +#endif
  67. strcat(longVersion, ")");
  68. }
  69. +# elif defined(BUILD_DATE)
  70. +char *longVersion = VIM_VERSION_LONG_DATE BUILD_DATE ")";
  71. # else
  72. char *longVersion = VIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")";
  73. # endif