1132718Skan/* Generate gcov version string from version.c. See gcov-io.h for
2132718Skan   description of how the version string is generated.
3169689Skan   Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
4132718Skan   Contributed by Nathan Sidwell <nathan@codesourcery.com>
5132718Skan
6132718SkanThis file is part of GCC.
7132718Skan
8132718SkanGCC is free software; you can redistribute it and/or modify it under
9132718Skanthe terms of the GNU General Public License as published by the Free
10132718SkanSoftware Foundation; either version 2, or (at your option) any later
11132718Skanversion.
12132718Skan
13132718SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY
14132718SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or
15132718SkanFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16132718Skanfor more details.
17132718Skan
18132718SkanYou should have received a copy of the GNU General Public License
19132718Skanalong with GCC; see the file COPYING.  If not, write to the Free
20169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21169689Skan02110-1301, USA.  */
22132718Skan
23169689Skan#include <stdio.h>
24169689Skan#include <stdlib.h>
25132718Skan
26169689Skan/* Command line arguments are the base GCC version and the development
27169689Skan   phase (the latter may be an empty string).  */
28132718Skan
29132718Skanint
30169689Skanmain (int argc, char **argv)
31132718Skan{
32169689Skan  unsigned int version = 0;
33132718Skan  unsigned char v[4];
34169689Skan  unsigned int ix;
35169689Skan  unsigned long major;
36169689Skan  unsigned long minor = 0;
37169689Skan  char phase = 0;
38169689Skan  char *ptr;
39132718Skan
40169689Skan  if (argc != 3)
41169689Skan    {
42169689Skan      fprintf (stderr, "usage: %s 'version' 'phase'\n", argv[0]);
43169689Skan      return 1;
44169689Skan    }
45132718Skan
46169689Skan  ptr = argv[1];
47169689Skan  major = strtoul (ptr, &ptr, 10);
48169689Skan
49169689Skan  if (*ptr == '.')
50169689Skan    minor = strtoul (ptr + 1, 0, 10);
51169689Skan
52169689Skan  phase = argv[2][0];
53169689Skan  if (phase == '\0')
54169689Skan    phase = '*';
55169689Skan
56132718Skan  v[0] = (major < 10 ? '0' : 'A' - 10) + major;
57132718Skan  v[1] = (minor / 10) + '0';
58132718Skan  v[2] = (minor % 10) + '0';
59169689Skan  v[3] = phase;
60132718Skan
61132718Skan  for (ix = 0; ix != 4; ix++)
62132718Skan    version = (version << 8) | v[ix];
63132718Skan
64132718Skan  printf ("/* Generated automatically by the program `%s'\n", argv[0]);
65169689Skan  printf ("   from `%s (%lu %lu) and %s (%c)'.  */\n",
66169689Skan	  argv[1], major, minor, argv[2], phase);
67132718Skan  printf ("\n");
68132718Skan  printf ("#define GCOV_VERSION ((gcov_unsigned_t)%#08x)  /* %.4s */\n",
69132718Skan	  version, v);
70132718Skan
71132718Skan  return 0;
72132718Skan}
73