From b7d99e02188b7907b09fec3032fc1fd82fc2668a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 10 Aug 2016 16:33:20 +0200 Subject: [PATCH] doc: Get rid of version.texi * configure.ac (CC_FOR_BUILD): New. * doc/mkdefsinc.c: New. Taken from GnuPG and modified for gpgme. * doc/Makefile.am (EXTRA_DIST): Add defsincdate and mkdefsinc.c (BUILT_SOURCES): new. (gpgme.texi): New dependency. (mkdefsinc, defsincdate, defs.inc): New rules. (dist-hook): New. * doc/gpgme.texi: Include defs.inc. Remove version.texi. -- GnuPG-bug-id: 2352 That new system should also yield more approriate date infos for the manual. --- configure.ac | 16 +++ doc/Makefile.am | 28 ++++- doc/gpgme.texi | 3 +- doc/mkdefsinc.c | 310 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 354 insertions(+), 3 deletions(-) create mode 100644 doc/mkdefsinc.c diff --git a/configure.ac b/configure.ac index 105f80ef..9eb55bb1 100644 --- a/configure.ac +++ b/configure.ac @@ -127,6 +127,22 @@ VERSION_NUMBER=m4_esyscmd(printf "0x%02x%02x%02x" mym4_version_major \ mym4_version_minor mym4_version_micro) AC_SUBST(VERSION_NUMBER) +# We need to compile and run a program on the build machine. A +# comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in +# the AC archive is broken for autoconf 2.57. Given that there is no +# newer version of that macro, we assume that it is also broken for +# autoconf 2.61 and thus we use a simple but usually sufficient +# approach. +AC_MSG_CHECKING(for cc for build) +if test "$cross_compiling" = "yes"; then + CC_FOR_BUILD="${CC_FOR_BUILD-cc}" +else + CC_FOR_BUILD="${CC_FOR_BUILD-$CC}" +fi +AC_MSG_RESULT($CC_FOR_BUILD) +AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler]) + + # Don't default to build static libs. LT_PREREQ([2.2.6]) LT_INIT([win32-dll disable-static]) diff --git a/doc/Makefile.am b/doc/Makefile.am index 2df35b49..905f9534 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -20,12 +20,38 @@ ## Process this file with automake to produce Makefile.in DISTCLEANFILES = gpgme.tmp +CLEANFILES = mkdefsinc defs.inc + +EXTRA_DIST = module-overview.sk HACKING DCO ChangeLog-2011 \ + mkdefsinc.c defsincdate + +BUILT_SOURCES = defsincdate defs.inc -EXTRA_DIST = module-overview.sk HACKING DCO ChangeLog-2011 info_TEXINFOS = gpgme.texi gpgme_TEXINFOS = uiserver.texi lesser.texi gpl.texi +gpgme.texi : defs.inc + +mkdefsinc: mkdefsinc.c Makefile ../config.h + $(CC_FOR_BUILD) -I. -I.. -I$(srcdir) $(AM_CPPFLAGS) \ + -o $@ $(srcdir)/mkdefsinc.c + +dist-hook: defsincdate + +defsincdate: $(gpgme_TEXINFOS) + : >defsincdate ; \ + if test -e $(top_srcdir)/.git; then \ + (cd $(srcdir) && git log -1 --format='%ct' -- \ + $(info_TEXINFOS) $(gpgme_TEXINFOS) 2>/dev/null) >>defsincdate; \ + fi + +defs.inc: defsincdate Makefile mkdefsinc + incd="`test -f defsincdate || echo '$(srcdir)/'`defsincdate"; \ + ./mkdefsinc -C $(srcdir) --date "`cat $$incd 2>/dev/null`" \ + $(info_TEXINFOS) $(gpgme_TEXINFOS) >$@ + + online: gpgme.html gpgme.pdf set -e; \ echo "Uploading current manuals to www.gnupg.org ..."; \ diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 907099ad..2bbed285 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -1,6 +1,7 @@ \input texinfo @c -*- mode: texinfo; coding: utf-8; -*- @documentencoding UTF-8 @setfilename gpgme.info +@include defs.inc @settitle The `GnuPG Made Easy' Reference Manual @dircategory GNU Libraries @@ -30,8 +31,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @end copying -@include version.texi - @c Macros used by the description of the UI server protocol @macro clnt @sc{c:} @c diff --git a/doc/mkdefsinc.c b/doc/mkdefsinc.c new file mode 100644 index 00000000..0f30d933 --- /dev/null +++ b/doc/mkdefsinc.c @@ -0,0 +1,310 @@ +/* mkdefsinc.c - Tool to create defs.inc + * Copyright (C) 2015 g10 Code GmbH + * + * This file is free software; as a special exception the author gives + * unlimited permission to copy and/or distribute it, with or without + * modifications, as long as this notice is preserved. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* This tool needs to be build with command line supplied -D options + for the various directory variables. It is easier to do this in + build file than to use fragile make rules and a template file. */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#define PGM "mkdefsinc" + +/* We include config.h after all include files because the config.h + values are not valid for the build platform but we need some values + nevertheless. */ +#include "config.h" + + +static int verbose; + + +/* The usual free wrapper. */ +static void +xfree (void *a) +{ + if (a) + free (a); +} + + +static char * +xmalloc (size_t n) +{ + char *p; + + p = malloc (n); + if (!p) + { + fputs (PGM ": out of core\n", stderr); + exit (1); + } + return p; +} + + +static char * +xstrdup (const char *string) +{ + char *p; + + p = xmalloc (strlen (string)+1); + strcpy (p, string); + return p; +} + + +/* Return a malloced string with the last modification date of the + FILES. Returns NULL on error. */ +static char * +get_date_from_files (char **files) +{ + const char *file; + const char *usedfile = NULL; + struct stat sb; + struct tm *tp; + int errors = 0; + time_t stamp = 0; + char *result; + + for (; (file = *files); files++) + { + if (!*file || !strcmp (file, ".") || !strcmp (file, "..")) + continue; + if (stat (file, &sb)) + { + fprintf (stderr, PGM ": stat failed for '%s': %s\n", + file, strerror (errno)); + errors = 1; + continue; + } + if (sb.st_mtime > stamp) + { + stamp = sb.st_mtime; + usedfile = file; + } + } + if (errors) + exit (1); + + if (usedfile) + fprintf (stderr, PGM ": taking date from '%s'\n", usedfile); + + tp = gmtime (&stamp); + if (!tp) + return NULL; + result = xmalloc (4+1+2+1+2+1); + snprintf (result, 4+1+2+1+2+1, "%04d-%02d-%02d", + tp->tm_year + 1900, tp->tm_mon+1, tp->tm_mday); + return result; +} + + +/* We need to escape file names for Texinfo. */ +static void +print_filename (const char *prefix, const char *name) +{ + const char *s; + + fputs (prefix, stdout); + for (s=name; *s; s++) + switch (*s) + { + case '@': fputs ("@atchar{}", stdout); break; + case '{': fputs ("@lbracechar{}", stdout); break; + case '}': fputs ("@rbracechar{}", stdout); break; + case ',': fputs ("@comma{}", stdout); break; + case '\\':fputs ("@backslashchar{}", stdout); break; + case '#': fputs ("@hashchar{}", stdout); break; + default: putchar (*s); break; + } + putchar('\n'); +} + + +int +main (int argc, char **argv) +{ + int last_argc = -1; + char *opt_date = NULL; + int monthoff; + char *p, *pend; + size_t n; + + /* Option parsing. */ + if (argc) + { + argc--; argv++; + } + while (argc && last_argc != argc ) + { + last_argc = argc; + if (!strcmp (*argv, "--")) + { + argc--; argv++; + break; + } + else if (!strcmp (*argv, "--help")) + { + fputs ("Usage: " PGM " [OPTION] [FILES]\n" + "Create defs.inc file.\nOptions:\n" + " -C DIR Change to DIR before doing anything\n" + " --date STRING Take publication date from STRING\n" + " --verbose Enable extra informational output\n" + " --help Display this help and exit\n" + , stdout); + exit (0); + } + else if (!strcmp (*argv, "--verbose")) + { + verbose = 1; + argc--; argv++; + } + else if (!strcmp (*argv, "-C")) + { + argc--; argv++; + if (argc) + { + if (chdir (*argv)) + { + fprintf (stderr, PGM ": chdir to '%s' failed: %s\n", + *argv, strerror (errno)); + exit (1); + } + argc--; argv++; + } + } + else if (!strcmp (*argv, "--date")) + { + argc--; argv++; + if (argc) + { + opt_date = xstrdup (*argv); + argc--; argv++; + } + } + else if (!strncmp (*argv, "--", 2)) + { + fprintf (stderr, PGM ": unknown option '%s'\n", *argv); + exit (1); + } + } + + if (opt_date && *opt_date) + { + time_t stamp; + struct tm *tp; + + if (*opt_date == '2' && strlen (opt_date) >= 10 + && opt_date[4] == '-' && opt_date[7] == '-') + { + opt_date[10] = 0; + } + else if ((stamp = strtoul (opt_date, NULL, 10)) > 0 + && (tp = gmtime (&stamp))) + { + p = xmalloc (4+1+2+1+2+1); + snprintf (p, 4+1+2+1+2+1, "%04d-%02d-%02d", + tp->tm_year + 1900, tp->tm_mon+1, tp->tm_mday); + xfree (opt_date); + opt_date = p; + } + else + { + fprintf (stderr, PGM ": bad date '%s'\n", opt_date); + exit (1); + } + } + else + { + xfree (opt_date); + opt_date = argc? get_date_from_files (argv) : NULL; + } + if (!opt_date) + { + opt_date = xstrdup ("unknown"); + monthoff = 0; + } + else + { + const char *month = "?"; + + switch (atoi (opt_date+5)) + { + case 1: month = "January"; break; + case 2: month = "February"; break; + case 3: month = "March"; break; + case 4: month = "April"; break; + case 5: month = "May"; break; + case 6: month = "June"; break; + case 7: month = "July"; break; + case 8: month = "August"; break; + case 9: month = "September"; break; + case 10: month = "October"; break; + case 11: month = "November"; break; + case 12: month = "December"; break; + } + n = strlen (opt_date) + strlen (month) + 2 + 1; + p = xmalloc (n); + snprintf (p, n, "%d %n%s %d", + atoi (opt_date+8), &monthoff, month, atoi (opt_date)); + xfree (opt_date); + opt_date = p; + } + + + fputs ("@c defs.inc -*- texinfo -*-\n" + "@c Common and build specific constants for the manuals.\n" + "@c This file has been created by " PGM ".\n\n", stdout); + + fputs ("@ifclear defsincincluded\n" + "@set defsincincluded 1\n\n", stdout); + + + fputs ("\n@c Flags\n\n", stdout); + + fputs ("\n@c Directories\n\n", stdout); + + /* print_filename ("@set BINDIR ", GNUPG_BINDIR ); */ + + fputs ("\n@c Version information a la version.texi\n\n", stdout); + + printf ("@set UPDATED %s\n", opt_date); + printf ("@set UPDATED-MONTH %s\n", opt_date + monthoff); + printf ("@set EDITION %s\n", PACKAGE_VERSION); + printf ("@set VERSION %s\n", PACKAGE_VERSION); + + fputs ("\n@c Macros\n\n", stdout); + + /* Trailer. */ + fputs ("\n" + "@end ifclear\n" + "\n" + "@c Loc" "al Variables:\n" + "@c buffer-read-only: t\n" + "@c End:\n", stdout); + + if (ferror (stdout)) + { + fprintf (stderr, PGM ": error writing to stdout: %s\n", strerror (errno)); + return 1; + } + + return 0; +}