xref: /dragonfly/contrib/gcc-8.0/gcc/gcov-iov.c (revision 38fd1498)
1*38fd1498Szrj /* Generate gcov version string from version.c. See gcov-io.h for
2*38fd1498Szrj    description of how the version string is generated.
3*38fd1498Szrj    Copyright (C) 2002-2018 Free Software Foundation, Inc.
4*38fd1498Szrj    Contributed by Nathan Sidwell <nathan@codesourcery.com>
5*38fd1498Szrj 
6*38fd1498Szrj This file is part of GCC.
7*38fd1498Szrj 
8*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
9*38fd1498Szrj the terms of the GNU General Public License as published by the Free
10*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
11*38fd1498Szrj version.
12*38fd1498Szrj 
13*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16*38fd1498Szrj for more details.
17*38fd1498Szrj 
18*38fd1498Szrj You should have received a copy of the GNU General Public License
19*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
20*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
21*38fd1498Szrj 
22*38fd1498Szrj #include "bconfig.h"
23*38fd1498Szrj #include "system.h"
24*38fd1498Szrj 
25*38fd1498Szrj /* Command line arguments are the base GCC version and the development
26*38fd1498Szrj    phase (the latter may be an empty string).  */
27*38fd1498Szrj 
28*38fd1498Szrj int
main(int argc,char ** argv)29*38fd1498Szrj main (int argc, char **argv)
30*38fd1498Szrj {
31*38fd1498Szrj   unsigned int version = 0;
32*38fd1498Szrj   unsigned char v[4];
33*38fd1498Szrj   unsigned int ix;
34*38fd1498Szrj   unsigned long major;
35*38fd1498Szrj   unsigned long minor = 0;
36*38fd1498Szrj   char phase = 0;
37*38fd1498Szrj   char *ptr;
38*38fd1498Szrj 
39*38fd1498Szrj   if (argc != 3)
40*38fd1498Szrj     {
41*38fd1498Szrj       fprintf (stderr, "usage: %s 'version' 'phase'\n", argv[0]);
42*38fd1498Szrj       return 1;
43*38fd1498Szrj     }
44*38fd1498Szrj 
45*38fd1498Szrj   ptr = argv[1];
46*38fd1498Szrj   major = strtoul (ptr, &ptr, 10);
47*38fd1498Szrj 
48*38fd1498Szrj   if (*ptr == '.')
49*38fd1498Szrj     minor = strtoul (ptr + 1, 0, 10);
50*38fd1498Szrj 
51*38fd1498Szrj   /* For releases the development phase is an empty string, for
52*38fd1498Szrj      prerelease versions on a release branch it is "prerelease".
53*38fd1498Szrj      Consider both equal as patch-level releases do not change
54*38fd1498Szrj      the GCOV version either.
55*38fd1498Szrj      On the trunk the development phase is "experimental".  */
56*38fd1498Szrj   phase = argv[2][0];
57*38fd1498Szrj   if (phase == '\0'
58*38fd1498Szrj       || strcmp (argv[2], "prerelease") == 0)
59*38fd1498Szrj     phase = '*';
60*38fd1498Szrj 
61*38fd1498Szrj   v[0] = (major / 10) + 'A';
62*38fd1498Szrj   v[1] = (major % 10) + '0';
63*38fd1498Szrj   v[2] = minor + '0';
64*38fd1498Szrj   v[3] = phase;
65*38fd1498Szrj 
66*38fd1498Szrj   for (ix = 0; ix != 4; ix++)
67*38fd1498Szrj     version = (version << 8) | v[ix];
68*38fd1498Szrj 
69*38fd1498Szrj   printf ("/* Generated automatically by the program `%s'\n", argv[0]);
70*38fd1498Szrj   printf ("   from `%s (%lu %lu) and %s (%c)'.  */\n",
71*38fd1498Szrj 	  argv[1], major, minor, argv[2], phase);
72*38fd1498Szrj   printf ("\n");
73*38fd1498Szrj   printf ("#define GCOV_VERSION ((gcov_unsigned_t)0x%08x)  /* %.4s */\n",
74*38fd1498Szrj 	  version, v);
75*38fd1498Szrj 
76*38fd1498Szrj   return 0;
77*38fd1498Szrj }
78