public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/genversion)] Use genversion to generate version.h.
@ 2021-04-23 11:41 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2021-04-23 11:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bc15fba97b2230936026e1fd6b9fa4c831f40714

commit bc15fba97b2230936026e1fd6b9fa4c831f40714
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Apr 20 16:56:07 2021 +0200

    Use genversion to generate version.h.
    
    c++tools/ChangeLog:
    
            * Makefile.in: Include also ../gcc folder.
    
    gcc/ChangeLog:
    
            * Makefile.in: Rename gcov-iov to genversion and depend
            on version.h (instead of gcov-iov.h).
            * gcov-io.h: Include version.h instread of gcov-iov.h.
            * gengtype-state.c (read_state_version): Likewise.
            * gcov-iov.c: Moved to...
            * genversion.c: ...here.
            * lto-streamer.h (LTO_major_version): Define it with
            GCC_major_version.
            * version.c: Removed.
            * version.h: Removed.
    
    libgcc/ChangeLog:
    
            * libgcov-driver.c (gcov_version): Use different name that does
            not clash with newly introduced macro.

Diff:
---
 c++tools/Makefile.in             |  4 +--
 gcc/Makefile.in                  | 53 ++++++++++++++--------------------------
 gcc/gcov-io.h                    |  6 +----
 gcc/gengtype-state.c             |  6 ++---
 gcc/{gcov-iov.c => genversion.c} | 42 +++++++++++++++++++------------
 gcc/lto-streamer.h               |  3 ++-
 gcc/version.c                    | 35 --------------------------
 gcc/version.h                    |  6 -----
 libgcc/libgcov-driver.c          |  4 +--
 9 files changed, 55 insertions(+), 104 deletions(-)

diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
index 9700706206d..afc87d07ad9 100644
--- a/c++tools/Makefile.in
+++ b/c++tools/Makefile.in
@@ -89,9 +89,9 @@ all::g++-mapper-server$(exeext)
 
 MAPPER.O := server.o resolver.o
 CODYLIB = ../libcody/libcody.a
-CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I.
+CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. -I../gcc
 g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB)
-	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS)
+	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS)
 
 # copy to gcc dir so tests there can run
 all::../gcc/g++-mapper-server$(exeext)
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 8a5fb3fd99c..e5d07fb98b0 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -960,7 +960,7 @@ BASIC_BLOCK_H = basic-block.h $(PREDICT_H) $(VEC_H) $(FUNCTION_H) \
 GIMPLE_H = gimple.h gimple.def gsstruct.def $(VEC_H) \
 	$(GGC_H) $(BASIC_BLOCK_H) $(TREE_H) tree-ssa-operands.h \
 	tree-ssa-alias.h $(INTERNAL_FN_H) $(HASH_TABLE_H) is-a.h
-GCOV_IO_H = gcov-io.h gcov-iov.h auto-host.h gcov-counter.def
+GCOV_IO_H = gcov-io.h version.h auto-host.h gcov-counter.def
 RECOG_H = recog.h
 EMIT_RTL_H = emit-rtl.h
 FLAGS_H = flags.h flag-types.h $(OPTIONS_H)
@@ -1711,7 +1711,7 @@ OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \
 	edit-context.o \
 	pretty-print.o intl.o \
 	sbitmap.o \
-	vec.o input.o version.o hash-table.o ggc-none.o memory-block.o \
+	vec.o input.o hash-table.o ggc-none.o memory-block.o \
 	selftest.o selftest-diagnostic.o sort.o
 
 # Objects in libcommon-target.a, used by drivers and by the core
@@ -1763,7 +1763,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
  $(EXTRA_PROGRAMS) gcc-cross$(exeext) \
  $(SPECS) collect2$(exeext) gcc-ar$(exeext) gcc-nm$(exeext) \
  gcc-ranlib$(exeext) \
- gcov-iov$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
+ genversion$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
  gcov-tool$(exeect) \
  gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
  libcommon-target.a libcommon.a libgcc.mk perf.data
@@ -2144,7 +2144,7 @@ checksum-options:
 # Build libgcc.a.
 
 libgcc-support: libgcc.mvars stmp-int-hdrs $(TCONFIG_H) \
-	$(MACHMODE_H) gcov-iov.h
+	$(MACHMODE_H) version.h
 
 libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	: > tmp-libgcc.mvars
@@ -2333,12 +2333,6 @@ s-options-h: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \
 
 dumpvers: dumpvers.c
 
-CFLAGS-version.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s)
-version.o: $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-
 # lto-compress.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-lto-compress.o += $(ZLIBINC) $(ZSTD_INC)
 
@@ -2755,7 +2749,7 @@ generated_files = config.h tm.h $(TM_P_H) $(TM_D_H) $(TM_H) multilib.h \
        $(simple_generated_h) specs.h \
        tree-check.h genrtl.h insn-modes.h insn-modes-inline.h \
        tm-preds.h tm-constrs.h \
-       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h gcov-iov.h \
+       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h version.h \
        options.h target-hooks-def.h insn-opinit.h \
        common/common-target-hooks-def.h pass-instances.def \
        c-family/c-target-hooks-def.h d/d-target-hooks-def.h \
@@ -2769,16 +2763,6 @@ build/%.o :  # dependencies provided by explicit rule later
 	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
 		-o $@ $<
 
-## build/version.o is compiled by the $(COMPILER_FOR_BUILD) but needs
-## several C macro definitions, just like version.o
-build/version.o:  version.c version.h \
-                  $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
-	-DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s) -o $@ $<
-
 # Header dependencies for the programs that generate source code.
 # These are library modules...
 build/errors.o : errors.c $(BCONFIG_H) $(SYSTEM_H) errors.h
@@ -2957,10 +2941,10 @@ build/genmatch$(build_exeext) : $(BUILD_CPPLIB) \
 
 # These programs are not linked with the MD reader.
 build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o \
-              build/gengtype-state.o build/version.o build/errors.o
+              build/gengtype-state.o version.h build/errors.o
 
 gengtype$(exeext) : gengtype.o gengtype-lex.o gengtype-parse.o \
-              gengtype-state.o version.o errors.o $(LIBDEPS)
+              gengtype-state.o version.h errors.o $(LIBDEPS)
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
 	    $(filter-out ($LIBDEPS), $^) $(LIBS)
 
@@ -3039,20 +3023,19 @@ CFLAGS-cppdefault.o += $(PREPROCESSOR_DEFINES)
 # Note for the stamp targets, we run the program `true' instead of
 # having an empty command (nothing following the semicolon).
 
-# gcov-iov.c is run on the build machine to generate gcov-iov.h from version.c
-build/gcov-iov.o: gcov-iov.c $(BCONFIG_H) $(CORETYPES_H) $(GTM_H) \
-  $(SYSTEM_H) $(CORETYPES_H) $(TM_H)
+# genversion.c is run on the build machine to generate version.h
+CFLAGS-build/genversion.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
+	-DREVISION=$(REVISION_s) \
+	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
+	-DBUGURL=$(BUGURL_s)
 
-build/gcov-iov$(build_exeext): build/gcov-iov.o
-	+$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) \
-		build/gcov-iov.o -o $@
+build/genversion.o: genversion.c $(BCONFIG_H) $(SYSTEM_H)
 
-gcov-iov.h: s-iov; @true
-s-iov: build/gcov-iov$(build_exeext) $(BASEVER) $(DEVPHASE)
-	build/gcov-iov$(build_exeext) '$(BASEVER_c)' '$(DEVPHASE_c)' \
-	    > tmp-gcov-iov.h
-	$(SHELL) $(srcdir)/../move-if-change tmp-gcov-iov.h gcov-iov.h
-	$(STAMP) s-iov
+version.h: s-version; @true
+s-version: build/genversion$(build_exeext)
+	build/genversion$(build_exeext) > tmp-version.h
+	$(SHELL) $(srcdir)/../move-if-change tmp-version.h version.h
+	$(STAMP) s-version
 
 # gcov.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-gcov.o += $(ZLIBINC)
diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h
index 75f16a274c7..1f7f4d65a2d 100644
--- a/gcc/gcov-io.h
+++ b/gcc/gcov-io.h
@@ -225,11 +225,7 @@ typedef uint64_t gcov_type_unsigned;
 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */
 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */
 
-/* gcov-iov.h is automatically generated by the makefile from
-   version.c, it looks like
-   	#define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef)
-*/
-#include "gcov-iov.h"
+#include "version.h"
 
 /* Convert a magic or version number to a 4 character string.  */
 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE)	\
diff --git a/gcc/gengtype-state.c b/gcc/gengtype-state.c
index 891f2e18a61..5a95455352b 100644
--- a/gcc/gengtype-state.c
+++ b/gcc/gengtype-state.c
@@ -2150,7 +2150,7 @@ read_state_options (options_p *opt)
 
 /* Read a version, and check against the version of the gengtype.  */
 static void
-read_state_version (const char *version_string)
+read_state_version (const char *ver_string)
 {
   struct state_token_st *t0 = peek_state_token (0);
   struct state_token_st *t1 = peek_state_token (1);
@@ -2166,10 +2166,10 @@ read_state_version (const char *version_string)
 	{
 	  /* Check that the read version string is the same as current
 	     version.  */
-	  if (strcmp (version_string, t0->stok_un.stok_string))
+	  if (strcmp (ver_string, t0->stok_un.stok_string))
 	    fatal_reading_state_printf (t0,
 					"version string mismatch; expecting %s but got %s",
-					version_string,
+					ver_string,
 					t0->stok_un.stok_string);
 	  next_state_tokens (2);
 	}
diff --git a/gcc/gcov-iov.c b/gcc/genversion.c
similarity index 59%
rename from gcc/gcov-iov.c
rename to gcc/genversion.c
index 32bf8dedb7c..22d8e349de5 100644
--- a/gcc/gcov-iov.c
+++ b/gcc/genversion.c
@@ -1,4 +1,4 @@
-/* Generate gcov version string from version.c. See gcov-io.h for
+/* Generate version strings. See gcov-io.h for
    description of how the version string is generated.
    Copyright (C) 2002-2021 Free Software Foundation, Inc.
    Contributed by Nathan Sidwell <nathan@codesourcery.com>
@@ -26,7 +26,7 @@ along with GCC; see the file COPYING3.  If not see
    phase (the latter may be an empty string).  */
 
 int
-main (int argc, char **argv)
+main (void)
 {
   unsigned int version = 0;
   unsigned char v[4];
@@ -34,15 +34,9 @@ main (int argc, char **argv)
   unsigned long major;
   unsigned long minor = 0;
   char phase = 0;
-  char *ptr;
+  char basever[] = BASEVER;
+  char *ptr = basever;
 
-  if (argc != 3)
-    {
-      fprintf (stderr, "usage: %s 'version' 'phase'\n", argv[0]);
-      return 1;
-    }
-
-  ptr = argv[1];
   major = strtoul (ptr, &ptr, 10);
 
   if (*ptr == '.')
@@ -53,9 +47,9 @@ main (int argc, char **argv)
      Consider both equal as patch-level releases do not change
      the GCOV version either.
      On the trunk the development phase is "experimental".  */
-  phase = argv[2][0];
+  phase = DEVPHASE[0];
   if (phase == '\0'
-      || strcmp (argv[2], "prerelease") == 0)
+      || strcmp (DEVPHASE, "prerelease") == 0)
     phase = '*';
 
   v[0] = (major / 10) + 'A';
@@ -66,12 +60,30 @@ main (int argc, char **argv)
   for (ix = 0; ix != 4; ix++)
     version = (version << 8) | v[ix];
 
-  printf ("/* Generated automatically by the program `%s'\n", argv[0]);
-  printf ("   from `%s (%lu %lu) and %s (%c)'.  */\n",
-	  argv[1], major, minor, argv[2], phase);
+  printf ("#ifndef VERSION_H\n");
+  printf ("#define VERSION_H\n\n");
+  printf ("/* Generated automatically by genversion.  */\n");
   printf ("\n");
+  printf ("#define GCC_major_version %lu\n\n", major);
+
+  printf ("/* The complete version string, assembled from several pieces.\n"
+	  "BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the\n"
+	  "Makefile.  */\n\n");
+
+  printf ("#define version_string \"" BASEVER DATESTAMP DEVPHASE REVISION "\"\n");
+  printf ("#define pkgversion_string \"" PKGVERSION "\"\n\n");
+
+  printf ("/* This is the location of the online document giving instructions for\n"
+     "reporting bugs.  If you distribute a modified version of GCC,\n"
+     "please configure with --with-bugurl pointing to a document giving\n"
+     "instructions for reporting bugs to you, not us.  (You are of course\n"
+     "welcome to forward us bugs reported to you, if you determine that\n"
+     "they are not bugs in your modifications.)  */\n\n");
+  printf ("#define bug_report_url \"" BUGURL "\"\n\n");
+
   printf ("#define GCOV_VERSION ((gcov_unsigned_t)0x%08x)  /* %.4s */\n",
 	  version, v);
+  printf ("\n#endif /* VERSION_H */\n");
 
   return 0;
 }
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 5c7cd84d46f..5f0335eb76c 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "plugin-api.h"
 #include "gcov-io.h"
 #include "diagnostic.h"
+#include "version.h"
 
 /* The encoding for a function consists of the following sections:
 
@@ -120,7 +121,7 @@ along with GCC; see the file COPYING3.  If not see
      String are represented in the table as pairs, a length in ULEB128
      form followed by the data for the string.  */
 
-#define LTO_major_version 9
+#define LTO_major_version GCC_major_version
 #define LTO_minor_version 0
 
 typedef unsigned char	lto_decl_flags_t;
diff --git a/gcc/version.c b/gcc/version.c
deleted file mode 100644
index 9415bb692ec..00000000000
--- a/gcc/version.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1997-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING3.  If not see
-<http://www.gnu.org/licenses/>.  */
-
-#include "version.h"
-
-/* This is the location of the online document giving instructions for
-   reporting bugs.  If you distribute a modified version of GCC,
-   please configure with --with-bugurl pointing to a document giving
-   instructions for reporting bugs to you, not us.  (You are of course
-   welcome to forward us bugs reported to you, if you determine that
-   they are not bugs in your modifications.)  */
-
-const char bug_report_url[] = BUGURL;
-
-/* The complete version string, assembled from several pieces.
-   BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the
-   Makefile.  */
-
-const char version_string[] = BASEVER DATESTAMP DEVPHASE REVISION;
-const char pkgversion_string[] = PKGVERSION;
diff --git a/gcc/version.h b/gcc/version.h
deleted file mode 100644
index 88919039d96..00000000000
--- a/gcc/version.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef GCC_VERSION_H
-#define GCC_VERSION_H
-extern const char version_string[];
-extern const char pkgversion_string[];
-extern const char bug_report_url[];
-#endif /* ! GCC_VERSION_H */
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index a1338b6e525..2747deff2a8 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -196,7 +196,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
   if (version != GCOV_VERSION)
     {
       char v[4], e[4];
-      char version_string[128], expected_string[128];
+      char ver_string[128], expected_string[128];
 
       GCOV_UNSIGNED2STRING (v, version);
       GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
@@ -205,7 +205,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
 		  "got %s (%.4s)\n",
 		  filename? filename : ptr->filename,
 		  gcov_version_string (expected_string, e), e,
-		  gcov_version_string (version_string, v), v);
+		  gcov_version_string (ver_string, v), v);
       return 0;
     }
   return 1;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gcc(refs/users/marxin/heads/genversion)] Use genversion to generate version.h.
@ 2021-04-20 18:01 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2021-04-20 18:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:86d1946449de8aec5e71030f6c7c48010e83cd67

commit 86d1946449de8aec5e71030f6c7c48010e83cd67
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Apr 20 16:56:07 2021 +0200

    Use genversion to generate version.h.
    
    c++tools/ChangeLog:
    
            * Makefile.in: Include also ../gcc folder.
    
    gcc/ChangeLog:
    
            * Makefile.in: Rename gcov-iov to genversion and depend
            on version.h (instead of gcov-iov.h).
            * gcov-io.h: Include version.h instread of gcov-iov.h.
            * gengtype-state.c (read_state_version): Likewise.
            * gcov-iov.c: Moved to...
            * genversion.c: ...here.
            * lto-streamer.h (LTO_major_version): Define it with
            GCC_major_version.
            * version.c: Removed.
            * version.h: Removed.
    
    libgcc/ChangeLog:
    
            * libgcov-driver.c (gcov_version): Use different name that does
            not clash with newly introduced macro.

Diff:
---
 c++tools/Makefile.in             |  4 +--
 gcc/Makefile.in                  | 53 ++++++++++++++--------------------------
 gcc/gcov-io.h                    |  6 +----
 gcc/gengtype-state.c             |  6 ++---
 gcc/{gcov-iov.c => genversion.c} | 42 +++++++++++++++++++------------
 gcc/lto-streamer.h               |  3 ++-
 gcc/version.c                    | 35 --------------------------
 gcc/version.h                    |  6 -----
 libgcc/libgcov-driver.c          |  4 +--
 9 files changed, 55 insertions(+), 104 deletions(-)

diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
index 9700706206d..afc87d07ad9 100644
--- a/c++tools/Makefile.in
+++ b/c++tools/Makefile.in
@@ -89,9 +89,9 @@ all::g++-mapper-server$(exeext)
 
 MAPPER.O := server.o resolver.o
 CODYLIB = ../libcody/libcody.a
-CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I.
+CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. -I../gcc
 g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB)
-	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS)
+	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS)
 
 # copy to gcc dir so tests there can run
 all::../gcc/g++-mapper-server$(exeext)
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 8a5fb3fd99c..e5d07fb98b0 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -960,7 +960,7 @@ BASIC_BLOCK_H = basic-block.h $(PREDICT_H) $(VEC_H) $(FUNCTION_H) \
 GIMPLE_H = gimple.h gimple.def gsstruct.def $(VEC_H) \
 	$(GGC_H) $(BASIC_BLOCK_H) $(TREE_H) tree-ssa-operands.h \
 	tree-ssa-alias.h $(INTERNAL_FN_H) $(HASH_TABLE_H) is-a.h
-GCOV_IO_H = gcov-io.h gcov-iov.h auto-host.h gcov-counter.def
+GCOV_IO_H = gcov-io.h version.h auto-host.h gcov-counter.def
 RECOG_H = recog.h
 EMIT_RTL_H = emit-rtl.h
 FLAGS_H = flags.h flag-types.h $(OPTIONS_H)
@@ -1711,7 +1711,7 @@ OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \
 	edit-context.o \
 	pretty-print.o intl.o \
 	sbitmap.o \
-	vec.o input.o version.o hash-table.o ggc-none.o memory-block.o \
+	vec.o input.o hash-table.o ggc-none.o memory-block.o \
 	selftest.o selftest-diagnostic.o sort.o
 
 # Objects in libcommon-target.a, used by drivers and by the core
@@ -1763,7 +1763,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
  $(EXTRA_PROGRAMS) gcc-cross$(exeext) \
  $(SPECS) collect2$(exeext) gcc-ar$(exeext) gcc-nm$(exeext) \
  gcc-ranlib$(exeext) \
- gcov-iov$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
+ genversion$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
  gcov-tool$(exeect) \
  gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
  libcommon-target.a libcommon.a libgcc.mk perf.data
@@ -2144,7 +2144,7 @@ checksum-options:
 # Build libgcc.a.
 
 libgcc-support: libgcc.mvars stmp-int-hdrs $(TCONFIG_H) \
-	$(MACHMODE_H) gcov-iov.h
+	$(MACHMODE_H) version.h
 
 libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	: > tmp-libgcc.mvars
@@ -2333,12 +2333,6 @@ s-options-h: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \
 
 dumpvers: dumpvers.c
 
-CFLAGS-version.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s)
-version.o: $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-
 # lto-compress.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-lto-compress.o += $(ZLIBINC) $(ZSTD_INC)
 
@@ -2755,7 +2749,7 @@ generated_files = config.h tm.h $(TM_P_H) $(TM_D_H) $(TM_H) multilib.h \
        $(simple_generated_h) specs.h \
        tree-check.h genrtl.h insn-modes.h insn-modes-inline.h \
        tm-preds.h tm-constrs.h \
-       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h gcov-iov.h \
+       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h version.h \
        options.h target-hooks-def.h insn-opinit.h \
        common/common-target-hooks-def.h pass-instances.def \
        c-family/c-target-hooks-def.h d/d-target-hooks-def.h \
@@ -2769,16 +2763,6 @@ build/%.o :  # dependencies provided by explicit rule later
 	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
 		-o $@ $<
 
-## build/version.o is compiled by the $(COMPILER_FOR_BUILD) but needs
-## several C macro definitions, just like version.o
-build/version.o:  version.c version.h \
-                  $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
-	-DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s) -o $@ $<
-
 # Header dependencies for the programs that generate source code.
 # These are library modules...
 build/errors.o : errors.c $(BCONFIG_H) $(SYSTEM_H) errors.h
@@ -2957,10 +2941,10 @@ build/genmatch$(build_exeext) : $(BUILD_CPPLIB) \
 
 # These programs are not linked with the MD reader.
 build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o \
-              build/gengtype-state.o build/version.o build/errors.o
+              build/gengtype-state.o version.h build/errors.o
 
 gengtype$(exeext) : gengtype.o gengtype-lex.o gengtype-parse.o \
-              gengtype-state.o version.o errors.o $(LIBDEPS)
+              gengtype-state.o version.h errors.o $(LIBDEPS)
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
 	    $(filter-out ($LIBDEPS), $^) $(LIBS)
 
@@ -3039,20 +3023,19 @@ CFLAGS-cppdefault.o += $(PREPROCESSOR_DEFINES)
 # Note for the stamp targets, we run the program `true' instead of
 # having an empty command (nothing following the semicolon).
 
-# gcov-iov.c is run on the build machine to generate gcov-iov.h from version.c
-build/gcov-iov.o: gcov-iov.c $(BCONFIG_H) $(CORETYPES_H) $(GTM_H) \
-  $(SYSTEM_H) $(CORETYPES_H) $(TM_H)
+# genversion.c is run on the build machine to generate version.h
+CFLAGS-build/genversion.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
+	-DREVISION=$(REVISION_s) \
+	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
+	-DBUGURL=$(BUGURL_s)
 
-build/gcov-iov$(build_exeext): build/gcov-iov.o
-	+$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) \
-		build/gcov-iov.o -o $@
+build/genversion.o: genversion.c $(BCONFIG_H) $(SYSTEM_H)
 
-gcov-iov.h: s-iov; @true
-s-iov: build/gcov-iov$(build_exeext) $(BASEVER) $(DEVPHASE)
-	build/gcov-iov$(build_exeext) '$(BASEVER_c)' '$(DEVPHASE_c)' \
-	    > tmp-gcov-iov.h
-	$(SHELL) $(srcdir)/../move-if-change tmp-gcov-iov.h gcov-iov.h
-	$(STAMP) s-iov
+version.h: s-version; @true
+s-version: build/genversion$(build_exeext)
+	build/genversion$(build_exeext) > tmp-version.h
+	$(SHELL) $(srcdir)/../move-if-change tmp-version.h version.h
+	$(STAMP) s-version
 
 # gcov.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-gcov.o += $(ZLIBINC)
diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h
index 75f16a274c7..1f7f4d65a2d 100644
--- a/gcc/gcov-io.h
+++ b/gcc/gcov-io.h
@@ -225,11 +225,7 @@ typedef uint64_t gcov_type_unsigned;
 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */
 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */
 
-/* gcov-iov.h is automatically generated by the makefile from
-   version.c, it looks like
-   	#define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef)
-*/
-#include "gcov-iov.h"
+#include "version.h"
 
 /* Convert a magic or version number to a 4 character string.  */
 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE)	\
diff --git a/gcc/gengtype-state.c b/gcc/gengtype-state.c
index 891f2e18a61..5a95455352b 100644
--- a/gcc/gengtype-state.c
+++ b/gcc/gengtype-state.c
@@ -2150,7 +2150,7 @@ read_state_options (options_p *opt)
 
 /* Read a version, and check against the version of the gengtype.  */
 static void
-read_state_version (const char *version_string)
+read_state_version (const char *ver_string)
 {
   struct state_token_st *t0 = peek_state_token (0);
   struct state_token_st *t1 = peek_state_token (1);
@@ -2166,10 +2166,10 @@ read_state_version (const char *version_string)
 	{
 	  /* Check that the read version string is the same as current
 	     version.  */
-	  if (strcmp (version_string, t0->stok_un.stok_string))
+	  if (strcmp (ver_string, t0->stok_un.stok_string))
 	    fatal_reading_state_printf (t0,
 					"version string mismatch; expecting %s but got %s",
-					version_string,
+					ver_string,
 					t0->stok_un.stok_string);
 	  next_state_tokens (2);
 	}
diff --git a/gcc/gcov-iov.c b/gcc/genversion.c
similarity index 59%
rename from gcc/gcov-iov.c
rename to gcc/genversion.c
index 32bf8dedb7c..22d8e349de5 100644
--- a/gcc/gcov-iov.c
+++ b/gcc/genversion.c
@@ -1,4 +1,4 @@
-/* Generate gcov version string from version.c. See gcov-io.h for
+/* Generate version strings. See gcov-io.h for
    description of how the version string is generated.
    Copyright (C) 2002-2021 Free Software Foundation, Inc.
    Contributed by Nathan Sidwell <nathan@codesourcery.com>
@@ -26,7 +26,7 @@ along with GCC; see the file COPYING3.  If not see
    phase (the latter may be an empty string).  */
 
 int
-main (int argc, char **argv)
+main (void)
 {
   unsigned int version = 0;
   unsigned char v[4];
@@ -34,15 +34,9 @@ main (int argc, char **argv)
   unsigned long major;
   unsigned long minor = 0;
   char phase = 0;
-  char *ptr;
+  char basever[] = BASEVER;
+  char *ptr = basever;
 
-  if (argc != 3)
-    {
-      fprintf (stderr, "usage: %s 'version' 'phase'\n", argv[0]);
-      return 1;
-    }
-
-  ptr = argv[1];
   major = strtoul (ptr, &ptr, 10);
 
   if (*ptr == '.')
@@ -53,9 +47,9 @@ main (int argc, char **argv)
      Consider both equal as patch-level releases do not change
      the GCOV version either.
      On the trunk the development phase is "experimental".  */
-  phase = argv[2][0];
+  phase = DEVPHASE[0];
   if (phase == '\0'
-      || strcmp (argv[2], "prerelease") == 0)
+      || strcmp (DEVPHASE, "prerelease") == 0)
     phase = '*';
 
   v[0] = (major / 10) + 'A';
@@ -66,12 +60,30 @@ main (int argc, char **argv)
   for (ix = 0; ix != 4; ix++)
     version = (version << 8) | v[ix];
 
-  printf ("/* Generated automatically by the program `%s'\n", argv[0]);
-  printf ("   from `%s (%lu %lu) and %s (%c)'.  */\n",
-	  argv[1], major, minor, argv[2], phase);
+  printf ("#ifndef VERSION_H\n");
+  printf ("#define VERSION_H\n\n");
+  printf ("/* Generated automatically by genversion.  */\n");
   printf ("\n");
+  printf ("#define GCC_major_version %lu\n\n", major);
+
+  printf ("/* The complete version string, assembled from several pieces.\n"
+	  "BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the\n"
+	  "Makefile.  */\n\n");
+
+  printf ("#define version_string \"" BASEVER DATESTAMP DEVPHASE REVISION "\"\n");
+  printf ("#define pkgversion_string \"" PKGVERSION "\"\n\n");
+
+  printf ("/* This is the location of the online document giving instructions for\n"
+     "reporting bugs.  If you distribute a modified version of GCC,\n"
+     "please configure with --with-bugurl pointing to a document giving\n"
+     "instructions for reporting bugs to you, not us.  (You are of course\n"
+     "welcome to forward us bugs reported to you, if you determine that\n"
+     "they are not bugs in your modifications.)  */\n\n");
+  printf ("#define bug_report_url \"" BUGURL "\"\n\n");
+
   printf ("#define GCOV_VERSION ((gcov_unsigned_t)0x%08x)  /* %.4s */\n",
 	  version, v);
+  printf ("\n#endif /* VERSION_H */\n");
 
   return 0;
 }
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 5c7cd84d46f..5f0335eb76c 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "plugin-api.h"
 #include "gcov-io.h"
 #include "diagnostic.h"
+#include "version.h"
 
 /* The encoding for a function consists of the following sections:
 
@@ -120,7 +121,7 @@ along with GCC; see the file COPYING3.  If not see
      String are represented in the table as pairs, a length in ULEB128
      form followed by the data for the string.  */
 
-#define LTO_major_version 9
+#define LTO_major_version GCC_major_version
 #define LTO_minor_version 0
 
 typedef unsigned char	lto_decl_flags_t;
diff --git a/gcc/version.c b/gcc/version.c
deleted file mode 100644
index 9415bb692ec..00000000000
--- a/gcc/version.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1997-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING3.  If not see
-<http://www.gnu.org/licenses/>.  */
-
-#include "version.h"
-
-/* This is the location of the online document giving instructions for
-   reporting bugs.  If you distribute a modified version of GCC,
-   please configure with --with-bugurl pointing to a document giving
-   instructions for reporting bugs to you, not us.  (You are of course
-   welcome to forward us bugs reported to you, if you determine that
-   they are not bugs in your modifications.)  */
-
-const char bug_report_url[] = BUGURL;
-
-/* The complete version string, assembled from several pieces.
-   BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the
-   Makefile.  */
-
-const char version_string[] = BASEVER DATESTAMP DEVPHASE REVISION;
-const char pkgversion_string[] = PKGVERSION;
diff --git a/gcc/version.h b/gcc/version.h
deleted file mode 100644
index 88919039d96..00000000000
--- a/gcc/version.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef GCC_VERSION_H
-#define GCC_VERSION_H
-extern const char version_string[];
-extern const char pkgversion_string[];
-extern const char bug_report_url[];
-#endif /* ! GCC_VERSION_H */
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index a1338b6e525..2747deff2a8 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -196,7 +196,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
   if (version != GCOV_VERSION)
     {
       char v[4], e[4];
-      char version_string[128], expected_string[128];
+      char ver_string[128], expected_string[128];
 
       GCOV_UNSIGNED2STRING (v, version);
       GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
@@ -205,7 +205,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
 		  "got %s (%.4s)\n",
 		  filename? filename : ptr->filename,
 		  gcov_version_string (expected_string, e), e,
-		  gcov_version_string (version_string, v), v);
+		  gcov_version_string (ver_string, v), v);
       return 0;
     }
   return 1;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gcc(refs/users/marxin/heads/genversion)] Use genversion to generate version.h.
@ 2021-04-20 17:46 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2021-04-20 17:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5002eed4646881f8e8fb4a8ebdda7ca005034664

commit 5002eed4646881f8e8fb4a8ebdda7ca005034664
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Apr 20 16:56:07 2021 +0200

    Use genversion to generate version.h.

Diff:
---
 c++tools/Makefile.in             |  4 +--
 gcc/Makefile.in                  | 53 ++++++++++++++--------------------------
 gcc/gcov-io.h                    |  6 +----
 gcc/gengtype-state.c             |  6 ++---
 gcc/{gcov-iov.c => genversion.c} | 42 +++++++++++++++++++------------
 gcc/lto-streamer.h               |  3 ++-
 gcc/version.c                    | 35 --------------------------
 gcc/version.h                    |  6 -----
 libgcc/libgcov-driver.c          |  4 +--
 9 files changed, 55 insertions(+), 104 deletions(-)

diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
index 9700706206d..afc87d07ad9 100644
--- a/c++tools/Makefile.in
+++ b/c++tools/Makefile.in
@@ -89,9 +89,9 @@ all::g++-mapper-server$(exeext)
 
 MAPPER.O := server.o resolver.o
 CODYLIB = ../libcody/libcody.a
-CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I.
+CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. -I../gcc
 g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB)
-	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS)
+	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS)
 
 # copy to gcc dir so tests there can run
 all::../gcc/g++-mapper-server$(exeext)
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 8a5fb3fd99c..e5d07fb98b0 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -960,7 +960,7 @@ BASIC_BLOCK_H = basic-block.h $(PREDICT_H) $(VEC_H) $(FUNCTION_H) \
 GIMPLE_H = gimple.h gimple.def gsstruct.def $(VEC_H) \
 	$(GGC_H) $(BASIC_BLOCK_H) $(TREE_H) tree-ssa-operands.h \
 	tree-ssa-alias.h $(INTERNAL_FN_H) $(HASH_TABLE_H) is-a.h
-GCOV_IO_H = gcov-io.h gcov-iov.h auto-host.h gcov-counter.def
+GCOV_IO_H = gcov-io.h version.h auto-host.h gcov-counter.def
 RECOG_H = recog.h
 EMIT_RTL_H = emit-rtl.h
 FLAGS_H = flags.h flag-types.h $(OPTIONS_H)
@@ -1711,7 +1711,7 @@ OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \
 	edit-context.o \
 	pretty-print.o intl.o \
 	sbitmap.o \
-	vec.o input.o version.o hash-table.o ggc-none.o memory-block.o \
+	vec.o input.o hash-table.o ggc-none.o memory-block.o \
 	selftest.o selftest-diagnostic.o sort.o
 
 # Objects in libcommon-target.a, used by drivers and by the core
@@ -1763,7 +1763,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
  $(EXTRA_PROGRAMS) gcc-cross$(exeext) \
  $(SPECS) collect2$(exeext) gcc-ar$(exeext) gcc-nm$(exeext) \
  gcc-ranlib$(exeext) \
- gcov-iov$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
+ genversion$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
  gcov-tool$(exeect) \
  gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
  libcommon-target.a libcommon.a libgcc.mk perf.data
@@ -2144,7 +2144,7 @@ checksum-options:
 # Build libgcc.a.
 
 libgcc-support: libgcc.mvars stmp-int-hdrs $(TCONFIG_H) \
-	$(MACHMODE_H) gcov-iov.h
+	$(MACHMODE_H) version.h
 
 libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	: > tmp-libgcc.mvars
@@ -2333,12 +2333,6 @@ s-options-h: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \
 
 dumpvers: dumpvers.c
 
-CFLAGS-version.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s)
-version.o: $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-
 # lto-compress.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-lto-compress.o += $(ZLIBINC) $(ZSTD_INC)
 
@@ -2755,7 +2749,7 @@ generated_files = config.h tm.h $(TM_P_H) $(TM_D_H) $(TM_H) multilib.h \
        $(simple_generated_h) specs.h \
        tree-check.h genrtl.h insn-modes.h insn-modes-inline.h \
        tm-preds.h tm-constrs.h \
-       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h gcov-iov.h \
+       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h version.h \
        options.h target-hooks-def.h insn-opinit.h \
        common/common-target-hooks-def.h pass-instances.def \
        c-family/c-target-hooks-def.h d/d-target-hooks-def.h \
@@ -2769,16 +2763,6 @@ build/%.o :  # dependencies provided by explicit rule later
 	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
 		-o $@ $<
 
-## build/version.o is compiled by the $(COMPILER_FOR_BUILD) but needs
-## several C macro definitions, just like version.o
-build/version.o:  version.c version.h \
-                  $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
-	-DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s) -o $@ $<
-
 # Header dependencies for the programs that generate source code.
 # These are library modules...
 build/errors.o : errors.c $(BCONFIG_H) $(SYSTEM_H) errors.h
@@ -2957,10 +2941,10 @@ build/genmatch$(build_exeext) : $(BUILD_CPPLIB) \
 
 # These programs are not linked with the MD reader.
 build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o \
-              build/gengtype-state.o build/version.o build/errors.o
+              build/gengtype-state.o version.h build/errors.o
 
 gengtype$(exeext) : gengtype.o gengtype-lex.o gengtype-parse.o \
-              gengtype-state.o version.o errors.o $(LIBDEPS)
+              gengtype-state.o version.h errors.o $(LIBDEPS)
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
 	    $(filter-out ($LIBDEPS), $^) $(LIBS)
 
@@ -3039,20 +3023,19 @@ CFLAGS-cppdefault.o += $(PREPROCESSOR_DEFINES)
 # Note for the stamp targets, we run the program `true' instead of
 # having an empty command (nothing following the semicolon).
 
-# gcov-iov.c is run on the build machine to generate gcov-iov.h from version.c
-build/gcov-iov.o: gcov-iov.c $(BCONFIG_H) $(CORETYPES_H) $(GTM_H) \
-  $(SYSTEM_H) $(CORETYPES_H) $(TM_H)
+# genversion.c is run on the build machine to generate version.h
+CFLAGS-build/genversion.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
+	-DREVISION=$(REVISION_s) \
+	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
+	-DBUGURL=$(BUGURL_s)
 
-build/gcov-iov$(build_exeext): build/gcov-iov.o
-	+$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) \
-		build/gcov-iov.o -o $@
+build/genversion.o: genversion.c $(BCONFIG_H) $(SYSTEM_H)
 
-gcov-iov.h: s-iov; @true
-s-iov: build/gcov-iov$(build_exeext) $(BASEVER) $(DEVPHASE)
-	build/gcov-iov$(build_exeext) '$(BASEVER_c)' '$(DEVPHASE_c)' \
-	    > tmp-gcov-iov.h
-	$(SHELL) $(srcdir)/../move-if-change tmp-gcov-iov.h gcov-iov.h
-	$(STAMP) s-iov
+version.h: s-version; @true
+s-version: build/genversion$(build_exeext)
+	build/genversion$(build_exeext) > tmp-version.h
+	$(SHELL) $(srcdir)/../move-if-change tmp-version.h version.h
+	$(STAMP) s-version
 
 # gcov.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-gcov.o += $(ZLIBINC)
diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h
index 75f16a274c7..1f7f4d65a2d 100644
--- a/gcc/gcov-io.h
+++ b/gcc/gcov-io.h
@@ -225,11 +225,7 @@ typedef uint64_t gcov_type_unsigned;
 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */
 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */
 
-/* gcov-iov.h is automatically generated by the makefile from
-   version.c, it looks like
-   	#define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef)
-*/
-#include "gcov-iov.h"
+#include "version.h"
 
 /* Convert a magic or version number to a 4 character string.  */
 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE)	\
diff --git a/gcc/gengtype-state.c b/gcc/gengtype-state.c
index 891f2e18a61..5a95455352b 100644
--- a/gcc/gengtype-state.c
+++ b/gcc/gengtype-state.c
@@ -2150,7 +2150,7 @@ read_state_options (options_p *opt)
 
 /* Read a version, and check against the version of the gengtype.  */
 static void
-read_state_version (const char *version_string)
+read_state_version (const char *ver_string)
 {
   struct state_token_st *t0 = peek_state_token (0);
   struct state_token_st *t1 = peek_state_token (1);
@@ -2166,10 +2166,10 @@ read_state_version (const char *version_string)
 	{
 	  /* Check that the read version string is the same as current
 	     version.  */
-	  if (strcmp (version_string, t0->stok_un.stok_string))
+	  if (strcmp (ver_string, t0->stok_un.stok_string))
 	    fatal_reading_state_printf (t0,
 					"version string mismatch; expecting %s but got %s",
-					version_string,
+					ver_string,
 					t0->stok_un.stok_string);
 	  next_state_tokens (2);
 	}
diff --git a/gcc/gcov-iov.c b/gcc/genversion.c
similarity index 59%
rename from gcc/gcov-iov.c
rename to gcc/genversion.c
index 32bf8dedb7c..22d8e349de5 100644
--- a/gcc/gcov-iov.c
+++ b/gcc/genversion.c
@@ -1,4 +1,4 @@
-/* Generate gcov version string from version.c. See gcov-io.h for
+/* Generate version strings. See gcov-io.h for
    description of how the version string is generated.
    Copyright (C) 2002-2021 Free Software Foundation, Inc.
    Contributed by Nathan Sidwell <nathan@codesourcery.com>
@@ -26,7 +26,7 @@ along with GCC; see the file COPYING3.  If not see
    phase (the latter may be an empty string).  */
 
 int
-main (int argc, char **argv)
+main (void)
 {
   unsigned int version = 0;
   unsigned char v[4];
@@ -34,15 +34,9 @@ main (int argc, char **argv)
   unsigned long major;
   unsigned long minor = 0;
   char phase = 0;
-  char *ptr;
+  char basever[] = BASEVER;
+  char *ptr = basever;
 
-  if (argc != 3)
-    {
-      fprintf (stderr, "usage: %s 'version' 'phase'\n", argv[0]);
-      return 1;
-    }
-
-  ptr = argv[1];
   major = strtoul (ptr, &ptr, 10);
 
   if (*ptr == '.')
@@ -53,9 +47,9 @@ main (int argc, char **argv)
      Consider both equal as patch-level releases do not change
      the GCOV version either.
      On the trunk the development phase is "experimental".  */
-  phase = argv[2][0];
+  phase = DEVPHASE[0];
   if (phase == '\0'
-      || strcmp (argv[2], "prerelease") == 0)
+      || strcmp (DEVPHASE, "prerelease") == 0)
     phase = '*';
 
   v[0] = (major / 10) + 'A';
@@ -66,12 +60,30 @@ main (int argc, char **argv)
   for (ix = 0; ix != 4; ix++)
     version = (version << 8) | v[ix];
 
-  printf ("/* Generated automatically by the program `%s'\n", argv[0]);
-  printf ("   from `%s (%lu %lu) and %s (%c)'.  */\n",
-	  argv[1], major, minor, argv[2], phase);
+  printf ("#ifndef VERSION_H\n");
+  printf ("#define VERSION_H\n\n");
+  printf ("/* Generated automatically by genversion.  */\n");
   printf ("\n");
+  printf ("#define GCC_major_version %lu\n\n", major);
+
+  printf ("/* The complete version string, assembled from several pieces.\n"
+	  "BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the\n"
+	  "Makefile.  */\n\n");
+
+  printf ("#define version_string \"" BASEVER DATESTAMP DEVPHASE REVISION "\"\n");
+  printf ("#define pkgversion_string \"" PKGVERSION "\"\n\n");
+
+  printf ("/* This is the location of the online document giving instructions for\n"
+     "reporting bugs.  If you distribute a modified version of GCC,\n"
+     "please configure with --with-bugurl pointing to a document giving\n"
+     "instructions for reporting bugs to you, not us.  (You are of course\n"
+     "welcome to forward us bugs reported to you, if you determine that\n"
+     "they are not bugs in your modifications.)  */\n\n");
+  printf ("#define bug_report_url \"" BUGURL "\"\n\n");
+
   printf ("#define GCOV_VERSION ((gcov_unsigned_t)0x%08x)  /* %.4s */\n",
 	  version, v);
+  printf ("\n#endif /* VERSION_H */\n");
 
   return 0;
 }
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 5c7cd84d46f..5f0335eb76c 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "plugin-api.h"
 #include "gcov-io.h"
 #include "diagnostic.h"
+#include "version.h"
 
 /* The encoding for a function consists of the following sections:
 
@@ -120,7 +121,7 @@ along with GCC; see the file COPYING3.  If not see
      String are represented in the table as pairs, a length in ULEB128
      form followed by the data for the string.  */
 
-#define LTO_major_version 9
+#define LTO_major_version GCC_major_version
 #define LTO_minor_version 0
 
 typedef unsigned char	lto_decl_flags_t;
diff --git a/gcc/version.c b/gcc/version.c
deleted file mode 100644
index 9415bb692ec..00000000000
--- a/gcc/version.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1997-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING3.  If not see
-<http://www.gnu.org/licenses/>.  */
-
-#include "version.h"
-
-/* This is the location of the online document giving instructions for
-   reporting bugs.  If you distribute a modified version of GCC,
-   please configure with --with-bugurl pointing to a document giving
-   instructions for reporting bugs to you, not us.  (You are of course
-   welcome to forward us bugs reported to you, if you determine that
-   they are not bugs in your modifications.)  */
-
-const char bug_report_url[] = BUGURL;
-
-/* The complete version string, assembled from several pieces.
-   BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the
-   Makefile.  */
-
-const char version_string[] = BASEVER DATESTAMP DEVPHASE REVISION;
-const char pkgversion_string[] = PKGVERSION;
diff --git a/gcc/version.h b/gcc/version.h
deleted file mode 100644
index 88919039d96..00000000000
--- a/gcc/version.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef GCC_VERSION_H
-#define GCC_VERSION_H
-extern const char version_string[];
-extern const char pkgversion_string[];
-extern const char bug_report_url[];
-#endif /* ! GCC_VERSION_H */
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index a1338b6e525..2747deff2a8 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -196,7 +196,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
   if (version != GCOV_VERSION)
     {
       char v[4], e[4];
-      char version_string[128], expected_string[128];
+      char ver_string[128], expected_string[128];
 
       GCOV_UNSIGNED2STRING (v, version);
       GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
@@ -205,7 +205,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
 		  "got %s (%.4s)\n",
 		  filename? filename : ptr->filename,
 		  gcov_version_string (expected_string, e), e,
-		  gcov_version_string (version_string, v), v);
+		  gcov_version_string (ver_string, v), v);
       return 0;
     }
   return 1;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [gcc(refs/users/marxin/heads/genversion)] Use genversion to generate version.h.
@ 2021-04-20 15:04 Martin Liska
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Liska @ 2021-04-20 15:04 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:938522790c7264fe9f48c12dc4468692e78c17a2

commit 938522790c7264fe9f48c12dc4468692e78c17a2
Author: Martin Liska <mliska@suse.cz>
Date:   Tue Apr 20 16:56:07 2021 +0200

    Use genversion to generate version.h.

Diff:
---
 c++tools/Makefile.in             |  4 +--
 gcc/Makefile.in                  | 53 ++++++++++++++--------------------------
 gcc/gcov-io.h                    |  6 +----
 gcc/gengtype-state.c             |  6 ++---
 gcc/{gcov-iov.c => genversion.c} | 35 ++++++++++++++++++--------
 gcc/lto-streamer.h               |  4 ++-
 gcc/version.c                    | 35 --------------------------
 gcc/version.h                    |  6 -----
 libgcc/libgcov-driver.c          |  4 +--
 9 files changed, 54 insertions(+), 99 deletions(-)

diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
index 9700706206d..afc87d07ad9 100644
--- a/c++tools/Makefile.in
+++ b/c++tools/Makefile.in
@@ -89,9 +89,9 @@ all::g++-mapper-server$(exeext)
 
 MAPPER.O := server.o resolver.o
 CODYLIB = ../libcody/libcody.a
-CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I.
+CXXINC += -I$(srcdir)/../libcody -I$(srcdir)/../include -I$(srcdir)/../gcc -I. -I../gcc
 g++-mapper-server$(exeext): $(MAPPER.O) $(CODYLIB)
-	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(VERSION.O) $(LIBIBERTY) $(NETLIBS)
+	+$(CXX) $(LDFLAGS) $(PIEFLAG) -o $@ $^ $(LIBIBERTY) $(NETLIBS)
 
 # copy to gcc dir so tests there can run
 all::../gcc/g++-mapper-server$(exeext)
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 8a5fb3fd99c..e5d07fb98b0 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -960,7 +960,7 @@ BASIC_BLOCK_H = basic-block.h $(PREDICT_H) $(VEC_H) $(FUNCTION_H) \
 GIMPLE_H = gimple.h gimple.def gsstruct.def $(VEC_H) \
 	$(GGC_H) $(BASIC_BLOCK_H) $(TREE_H) tree-ssa-operands.h \
 	tree-ssa-alias.h $(INTERNAL_FN_H) $(HASH_TABLE_H) is-a.h
-GCOV_IO_H = gcov-io.h gcov-iov.h auto-host.h gcov-counter.def
+GCOV_IO_H = gcov-io.h version.h auto-host.h gcov-counter.def
 RECOG_H = recog.h
 EMIT_RTL_H = emit-rtl.h
 FLAGS_H = flags.h flag-types.h $(OPTIONS_H)
@@ -1711,7 +1711,7 @@ OBJS-libcommon = diagnostic.o diagnostic-color.o diagnostic-show-locus.o \
 	edit-context.o \
 	pretty-print.o intl.o \
 	sbitmap.o \
-	vec.o input.o version.o hash-table.o ggc-none.o memory-block.o \
+	vec.o input.o hash-table.o ggc-none.o memory-block.o \
 	selftest.o selftest-diagnostic.o sort.o
 
 # Objects in libcommon-target.a, used by drivers and by the core
@@ -1763,7 +1763,7 @@ MOSTLYCLEANFILES = insn-flags.h insn-config.h insn-codes.h \
  $(EXTRA_PROGRAMS) gcc-cross$(exeext) \
  $(SPECS) collect2$(exeext) gcc-ar$(exeext) gcc-nm$(exeext) \
  gcc-ranlib$(exeext) \
- gcov-iov$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
+ genversion$(build_exeext) gcov$(exeext) gcov-dump$(exeext) \
  gcov-tool$(exeect) \
  gengtype$(exeext) *.[0-9][0-9].* *.[si] *-checksum.c libbackend.a \
  libcommon-target.a libcommon.a libgcc.mk perf.data
@@ -2144,7 +2144,7 @@ checksum-options:
 # Build libgcc.a.
 
 libgcc-support: libgcc.mvars stmp-int-hdrs $(TCONFIG_H) \
-	$(MACHMODE_H) gcov-iov.h
+	$(MACHMODE_H) version.h
 
 libgcc.mvars: config.status Makefile specs xgcc$(exeext)
 	: > tmp-libgcc.mvars
@@ -2333,12 +2333,6 @@ s-options-h: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \
 
 dumpvers: dumpvers.c
 
-CFLAGS-version.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s)
-version.o: $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-
 # lto-compress.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-lto-compress.o += $(ZLIBINC) $(ZSTD_INC)
 
@@ -2755,7 +2749,7 @@ generated_files = config.h tm.h $(TM_P_H) $(TM_D_H) $(TM_H) multilib.h \
        $(simple_generated_h) specs.h \
        tree-check.h genrtl.h insn-modes.h insn-modes-inline.h \
        tm-preds.h tm-constrs.h \
-       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h gcov-iov.h \
+       $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h version.h \
        options.h target-hooks-def.h insn-opinit.h \
        common/common-target-hooks-def.h pass-instances.def \
        c-family/c-target-hooks-def.h d/d-target-hooks-def.h \
@@ -2769,16 +2763,6 @@ build/%.o :  # dependencies provided by explicit rule later
 	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
 		-o $@ $<
 
-## build/version.o is compiled by the $(COMPILER_FOR_BUILD) but needs
-## several C macro definitions, just like version.o
-build/version.o:  version.c version.h \
-                  $(REVISION) $(DATESTAMP) $(BASEVER) $(DEVPHASE)
-	$(COMPILER_FOR_BUILD) -c $(BUILD_COMPILERFLAGS) $(BUILD_CPPFLAGS) \
-	-DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
-	-DREVISION=$(REVISION_s) \
-	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
-	-DBUGURL=$(BUGURL_s) -o $@ $<
-
 # Header dependencies for the programs that generate source code.
 # These are library modules...
 build/errors.o : errors.c $(BCONFIG_H) $(SYSTEM_H) errors.h
@@ -2957,10 +2941,10 @@ build/genmatch$(build_exeext) : $(BUILD_CPPLIB) \
 
 # These programs are not linked with the MD reader.
 build/gengtype$(build_exeext) : build/gengtype-lex.o build/gengtype-parse.o \
-              build/gengtype-state.o build/version.o build/errors.o
+              build/gengtype-state.o version.h build/errors.o
 
 gengtype$(exeext) : gengtype.o gengtype-lex.o gengtype-parse.o \
-              gengtype-state.o version.o errors.o $(LIBDEPS)
+              gengtype-state.o version.h errors.o $(LIBDEPS)
 	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
 	    $(filter-out ($LIBDEPS), $^) $(LIBS)
 
@@ -3039,20 +3023,19 @@ CFLAGS-cppdefault.o += $(PREPROCESSOR_DEFINES)
 # Note for the stamp targets, we run the program `true' instead of
 # having an empty command (nothing following the semicolon).
 
-# gcov-iov.c is run on the build machine to generate gcov-iov.h from version.c
-build/gcov-iov.o: gcov-iov.c $(BCONFIG_H) $(CORETYPES_H) $(GTM_H) \
-  $(SYSTEM_H) $(CORETYPES_H) $(TM_H)
+# genversion.c is run on the build machine to generate version.h
+CFLAGS-build/genversion.o += -DBASEVER=$(BASEVER_s) -DDATESTAMP=$(DATESTAMP_s) \
+	-DREVISION=$(REVISION_s) \
+	-DDEVPHASE=$(DEVPHASE_s) -DPKGVERSION=$(PKGVERSION_s) \
+	-DBUGURL=$(BUGURL_s)
 
-build/gcov-iov$(build_exeext): build/gcov-iov.o
-	+$(LINKER_FOR_BUILD) $(BUILD_LINKERFLAGS) $(BUILD_LDFLAGS) \
-		build/gcov-iov.o -o $@
+build/genversion.o: genversion.c $(BCONFIG_H) $(SYSTEM_H)
 
-gcov-iov.h: s-iov; @true
-s-iov: build/gcov-iov$(build_exeext) $(BASEVER) $(DEVPHASE)
-	build/gcov-iov$(build_exeext) '$(BASEVER_c)' '$(DEVPHASE_c)' \
-	    > tmp-gcov-iov.h
-	$(SHELL) $(srcdir)/../move-if-change tmp-gcov-iov.h gcov-iov.h
-	$(STAMP) s-iov
+version.h: s-version; @true
+s-version: build/genversion$(build_exeext)
+	build/genversion$(build_exeext) > tmp-version.h
+	$(SHELL) $(srcdir)/../move-if-change tmp-version.h version.h
+	$(STAMP) s-version
 
 # gcov.o needs $(ZLIBINC) added to the include flags.
 CFLAGS-gcov.o += $(ZLIBINC)
diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h
index 75f16a274c7..1f7f4d65a2d 100644
--- a/gcc/gcov-io.h
+++ b/gcc/gcov-io.h
@@ -225,11 +225,7 @@ typedef uint64_t gcov_type_unsigned;
 #define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */
 #define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */
 
-/* gcov-iov.h is automatically generated by the makefile from
-   version.c, it looks like
-   	#define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef)
-*/
-#include "gcov-iov.h"
+#include "version.h"
 
 /* Convert a magic or version number to a 4 character string.  */
 #define GCOV_UNSIGNED2STRING(ARRAY,VALUE)	\
diff --git a/gcc/gengtype-state.c b/gcc/gengtype-state.c
index 891f2e18a61..5a95455352b 100644
--- a/gcc/gengtype-state.c
+++ b/gcc/gengtype-state.c
@@ -2150,7 +2150,7 @@ read_state_options (options_p *opt)
 
 /* Read a version, and check against the version of the gengtype.  */
 static void
-read_state_version (const char *version_string)
+read_state_version (const char *ver_string)
 {
   struct state_token_st *t0 = peek_state_token (0);
   struct state_token_st *t1 = peek_state_token (1);
@@ -2166,10 +2166,10 @@ read_state_version (const char *version_string)
 	{
 	  /* Check that the read version string is the same as current
 	     version.  */
-	  if (strcmp (version_string, t0->stok_un.stok_string))
+	  if (strcmp (ver_string, t0->stok_un.stok_string))
 	    fatal_reading_state_printf (t0,
 					"version string mismatch; expecting %s but got %s",
-					version_string,
+					ver_string,
 					t0->stok_un.stok_string);
 	  next_state_tokens (2);
 	}
diff --git a/gcc/gcov-iov.c b/gcc/genversion.c
similarity index 66%
rename from gcc/gcov-iov.c
rename to gcc/genversion.c
index 32bf8dedb7c..7bfdd1fc8f4 100644
--- a/gcc/gcov-iov.c
+++ b/gcc/genversion.c
@@ -1,4 +1,4 @@
-/* Generate gcov version string from version.c. See gcov-io.h for
+/* Generate version strings. See gcov-io.h for
    description of how the version string is generated.
    Copyright (C) 2002-2021 Free Software Foundation, Inc.
    Contributed by Nathan Sidwell <nathan@codesourcery.com>
@@ -36,13 +36,7 @@ main (int argc, char **argv)
   char phase = 0;
   char *ptr;
 
-  if (argc != 3)
-    {
-      fprintf (stderr, "usage: %s 'version' 'phase'\n", argv[0]);
-      return 1;
-    }
-
-  ptr = argv[1];
+  ptr = BASEVER;
   major = strtoul (ptr, &ptr, 10);
 
   if (*ptr == '.')
@@ -53,9 +47,9 @@ main (int argc, char **argv)
      Consider both equal as patch-level releases do not change
      the GCOV version either.
      On the trunk the development phase is "experimental".  */
-  phase = argv[2][0];
+  phase = DEVPHASE[0];
   if (phase == '\0'
-      || strcmp (argv[2], "prerelease") == 0)
+      || strcmp (DEVPHASE, "prerelease") == 0)
     phase = '*';
 
   v[0] = (major / 10) + 'A';
@@ -66,12 +60,33 @@ main (int argc, char **argv)
   for (ix = 0; ix != 4; ix++)
     version = (version << 8) | v[ix];
 
+  printf ("#ifndef GCOV_IOV\n");
+  printf ("#define GCOV_IOV\n\n");
   printf ("/* Generated automatically by the program `%s'\n", argv[0]);
   printf ("   from `%s (%lu %lu) and %s (%c)'.  */\n",
 	  argv[1], major, minor, argv[2], phase);
   printf ("\n");
   printf ("#define GCOV_VERSION ((gcov_unsigned_t)0x%08x)  /* %.4s */\n",
 	  version, v);
+  printf ("#define LTO_major_version %lu\n", major);
+
+  /* The complete version string, assembled from several pieces.
+     BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the
+     Makefile.  */
+
+  printf ("#define version_string \"" BASEVER DATESTAMP DEVPHASE REVISION "\"\n");
+  printf ("#define pkgversion_string \"" PKGVERSION "\"\n");
+
+
+  /* This is the location of the online document giving instructions for
+     reporting bugs.  If you distribute a modified version of GCC,
+     please configure with --with-bugurl pointing to a document giving
+     instructions for reporting bugs to you, not us.  (You are of course
+     welcome to forward us bugs reported to you, if you determine that
+     they are not bugs in your modifications.)  */
+
+  printf ("#define bug_report_url \"" BUGURL "\"\n");
+  printf ("\n#endif\n");
 
   return 0;
 }
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 5c7cd84d46f..f2a654d7636 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -26,6 +26,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "plugin-api.h"
 #include "gcov-io.h"
 #include "diagnostic.h"
+#include "version.h"
 
 /* The encoding for a function consists of the following sections:
 
@@ -120,7 +121,8 @@ along with GCC; see the file COPYING3.  If not see
      String are represented in the table as pairs, a length in ULEB128
      form followed by the data for the string.  */
 
-#define LTO_major_version 9
+/* LTO_major_version is defined in version.h.  */
+
 #define LTO_minor_version 0
 
 typedef unsigned char	lto_decl_flags_t;
diff --git a/gcc/version.c b/gcc/version.c
deleted file mode 100644
index 9415bb692ec..00000000000
--- a/gcc/version.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright (C) 1997-2021 Free Software Foundation, Inc.
-
-This file is part of GCC.
-
-GCC is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-GCC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING3.  If not see
-<http://www.gnu.org/licenses/>.  */
-
-#include "version.h"
-
-/* This is the location of the online document giving instructions for
-   reporting bugs.  If you distribute a modified version of GCC,
-   please configure with --with-bugurl pointing to a document giving
-   instructions for reporting bugs to you, not us.  (You are of course
-   welcome to forward us bugs reported to you, if you determine that
-   they are not bugs in your modifications.)  */
-
-const char bug_report_url[] = BUGURL;
-
-/* The complete version string, assembled from several pieces.
-   BASEVER, DATESTAMP, DEVPHASE, and REVISION are defined by the
-   Makefile.  */
-
-const char version_string[] = BASEVER DATESTAMP DEVPHASE REVISION;
-const char pkgversion_string[] = PKGVERSION;
diff --git a/gcc/version.h b/gcc/version.h
deleted file mode 100644
index 88919039d96..00000000000
--- a/gcc/version.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef GCC_VERSION_H
-#define GCC_VERSION_H
-extern const char version_string[];
-extern const char pkgversion_string[];
-extern const char bug_report_url[];
-#endif /* ! GCC_VERSION_H */
diff --git a/libgcc/libgcov-driver.c b/libgcc/libgcov-driver.c
index a1338b6e525..2747deff2a8 100644
--- a/libgcc/libgcov-driver.c
+++ b/libgcc/libgcov-driver.c
@@ -196,7 +196,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
   if (version != GCOV_VERSION)
     {
       char v[4], e[4];
-      char version_string[128], expected_string[128];
+      char ver_string[128], expected_string[128];
 
       GCOV_UNSIGNED2STRING (v, version);
       GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
@@ -205,7 +205,7 @@ gcov_version (struct gcov_info *ptr, gcov_unsigned_t version,
 		  "got %s (%.4s)\n",
 		  filename? filename : ptr->filename,
 		  gcov_version_string (expected_string, e), e,
-		  gcov_version_string (version_string, v), v);
+		  gcov_version_string (ver_string, v), v);
       return 0;
     }
   return 1;


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-23 11:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 11:41 [gcc(refs/users/marxin/heads/genversion)] Use genversion to generate version.h Martin Liska
  -- strict thread matches above, loose matches on Subject: below --
2021-04-20 18:01 Martin Liska
2021-04-20 17:46 Martin Liska
2021-04-20 15:04 Martin Liska

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).