This patch fixes a building annoyance that I had when building on a new
machine (an x86_64 gnu/linux box).
The building failed. It was down to two problems:
* due to how I got a copy of the GCC source code on the machine, the timestamp
of each source file was the timestamp of when it was copied to the machine (ie,
a random timestamp from the point of view of the building system). This caused
the build system to decide that $(srcdir)/cp/cfns.h needed to be rebuilt from
$(srcdir)/cp/cfns.gperf (it didn't, obviously; the source code was trunk with
no changes).
* when the automated rebuild failed because gperf was not there, it also
created
an empty cp/cfns.h, basically corrupting my source tree. Further attempts to
rebuild (with or without gperf) would then fail due to a missing definition of
"libc_name_p" (because cp/cfns.h now existed, and was newer than cp/cfns.gperf,
it wouldn't be rebuilt, and I was stuck with the empty cp/cfns.h). Searching
on the internet, I found that a number of people got stuck at this stage and
couldn't finish their build. So, rather than just manually fixing my source
tree, I'm posting a patch that will remove the problems at the root.
This patch fixes both problems, making the build more robust:
* it only rebuilds cp/cfns.h when a specific command ("make rebuild-cp-cfns")
is used.
According to the ChangeLogs, cp/cfns.gperf was edited about 5 times in 10
years,
so it does not seem unreasonable to require developers/maintainers to use an
explicit
command to rebuild cp/cfns.h from cp/cfns.gperf for the once-every-two-years
occasion when
it is changed. I documented the process clearly in cfns.gperf itself.
This makes the build more robust for end users, who are not bugged by
timestamp
issues in the source tree causing unexpected rebuilds or complications
requiring
gperf.
In general, I personally feel that the building system should not depend on
the relative
timestamps of source files unless it's doing something in "maintainer mode"
where it's being
explicitly asked to rebuild one source file from the other. The average
user who downloads
the GCC source code to build it should not be expected to keep the
timestamps of each
source file religiously unchanged! Timestamps may change as the source code
is moved
around by users and the building system should not have a problem with that.
* it fails gracefully when the rebuild is triggered and gperf is not
available. Instead
of creating en empty cp/cfns.h file, it creates no file at all, so that if
you then install
gperf, it will rebuild cp/cfns.h correctly, and if you don't, you'll keep
getting the
error the gperf is not available (not an error about libc_name_p not being
defined),
which is the correct one.
Ok to commit ?
Thanks
Index: cfns.gperf
===================================================================
--- cfns.gperf (revision 172858)
+++ cfns.gperf (working copy)
@@ -15,7 +15,18 @@ 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/>. */
+<http://www.gnu.org/licenses/>.
+
+You need to use gperf to generate cfns.h from cfns.gperf. This is
+the process:
+
+ have a GCC source/build tree already checked out
+ edit cfns.gperf
+ cd $(buildir)/gcc
+ make rebuild-cp-cfns
+
+Alternatively, just look into cp/Make-lang.in and run the gperf
+command in the rebuild-cp-cfns rule manually. */
#ifdef __GNUC__
__inline
#endif
Index: Make-lang.in
===================================================================
--- Make-lang.in (revision 172858)
+++ Make-lang.in (working copy)
@@ -104,11 +104,19 @@ cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $
+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
$(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
-# Special build rules.
-$(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf
+# Special build rule. This is a maintainer rule, that needs to be
+# invoked manually (as in "cd $(builddir)/gcc; make rebuild-cp-cfns")
+# to rebuild cfns.h from cfns.gperf any time that cfns.gperf is
+# edited. We don't trigger it automatically when
+# $(srcdir)/cp/cfns.gperf is newer than $(srcdir)/cp/cfns.h because we
+# don't want to depend on users getting the source code with
+# particular timestamps.
+rebuild-cp-cfns:
gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L ANSI-C \
- $(srcdir)/cp/cfns.gperf > $(srcdir)/cp/cfns.h
+ $(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h
+.PHONY: rebuild-cp-cfns
+
#^L
# Build hooks:
Index: ChangeLog
===================================================================
--- ChangeLog (revision 172858)
+++ ChangeLog (working copy)
@@ -1,3 +1,13 @@
+2011-04-22 Nicola Pero <[email protected]>
+
+ * Make-lang.in (rebuild-cp-cfns): New rule replacing the one to
+ build $(srcdir)/cp/cfns.h to prevent unwanted rebuilds. Use
+ --output-file option of gperf instead of > to prevent creating an
+ empty cp/cfns.h when gperf is not available.
+ (.PHONY): New, to make rebuild-cp-cfns as phony.
+ * cfns.gperf: Explain how to run 'make rebuild-cp-cfns'.
+ * cfns.h: Regenerated
+
2011-04-20 Jason Merrill <[email protected]>
* semantics.c (finish_compound_literal): Don't put an array
Index: cfns.h
===================================================================
--- cfns.h (revision 172858)
+++ cfns.h (working copy)
@@ -1,5 +1,5 @@
/* ANSI-C code produced by gperf version 3.0.3 */
-/* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L ANSI-C
cfns.gperf */
+/* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L ANSI-C
--output-file ../../trunk2/gcc/cp/cfns.h ../../trunk2/gcc/cp/cfns.gperf */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
@@ -28,7 +28,7 @@
#error "gperf generated tables don't work with this execution character set.
Please report a bug to <[email protected]>."
#endif
-#line 1 "cfns.gperf"
+#line 1 "../../trunk2/gcc/cp/cfns.gperf"
/* Copyright (C) 2000, 2003 Free Software Foundation, Inc.
@@ -46,7 +46,18 @@ 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/>. */
+<http://www.gnu.org/licenses/>.
+
+You need to use gperf to generate cfns.h from cfns.gperf. This is
+the process:
+
+ have a GCC source/build tree already checked out
+ edit cfns.gperf
+ cd $(buildir)/gcc
+ make rebuild-cfns
+
+Alternatively, just look into cp/Make-lang.in and run the gperf
+command in the rebuild-cfns rule manually. */
#ifdef __GNUC__
__inline
#endif