c++tools: Fix Makefile to properly clean and rebuild [PR101834]

Message ID 20230330121546.1454231-1-jwakely@redhat.com
State Committed
Headers
Series c++tools: Fix Makefile to properly clean and rebuild [PR101834] |

Commit Message

Jonathan Wakely March 30, 2023, 12:15 p.m. UTC
  Tested with various combinations of 'make clean all' etc.

OK for trunk?

And backport to gcc-12 and gcc-11 after some soak time on trunk?

-- >8 --

The c++tools makefile doesn't remove progressively more files in each of
mostlyclean, clean, and distclean. Instead, each removes a different set
of files (and some files are not removed by any target). Use
prerequisites so that everything is removed.

Also, building in the $objdir/c++tools directory doesn't work, because
the INSTALL variable is never set. It works when building from the
top-level because INSTALL is set in the environment when recursively
invoking make for sub-directories.

c++tools/ChangeLog:

	PR bootstrap/101834
	* Makefile.in (INSTALL): Set variable.
	(mostlyclean): Mark as a phony target.
	(clean): Add mostlyclean as a prerequisite.
	(distclean): Add clean as a prerequisite and remove more files.
	(maintainer-clean): Add distclean as a prerequisite.
---
 c++tools/Makefile.in | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Segher Boessenkool March 30, 2023, 4:22 p.m. UTC | #1
On Thu, Mar 30, 2023 at 01:15:46PM +0100, Jonathan Wakely wrote:
> The c++tools makefile doesn't remove progressively more files in each of
> mostlyclean, clean, and distclean. Instead, each removes a different set
> of files (and some files are not removed by any target). Use
> prerequisites so that everything is removed.

This solves the PR (PR101834).  Thanks!


Segher
  
Jason Merrill March 30, 2023, 9:55 p.m. UTC | #2
On 3/30/23 08:15, Jonathan Wakely wrote:
> Tested with various combinations of 'make clean all' etc.
> 
> OK for trunk?
> 
> And backport to gcc-12 and gcc-11 after some soak time on trunk?

OK.

> -- >8 --
> 
> The c++tools makefile doesn't remove progressively more files in each of
> mostlyclean, clean, and distclean. Instead, each removes a different set
> of files (and some files are not removed by any target). Use
> prerequisites so that everything is removed.
> 
> Also, building in the $objdir/c++tools directory doesn't work, because
> the INSTALL variable is never set. It works when building from the
> top-level because INSTALL is set in the environment when recursively
> invoking make for sub-directories.
> 
> c++tools/ChangeLog:
> 
> 	PR bootstrap/101834
> 	* Makefile.in (INSTALL): Set variable.
> 	(mostlyclean): Mark as a phony target.
> 	(clean): Add mostlyclean as a prerequisite.
> 	(distclean): Add clean as a prerequisite and remove more files.
> 	(maintainer-clean): Add distclean as a prerequisite.
> ---
>   c++tools/Makefile.in | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
> index 56cba090135..77bda3d56dc 100644
> --- a/c++tools/Makefile.in
> +++ b/c++tools/Makefile.in
> @@ -22,6 +22,7 @@ libexecdir := @libexecdir@
>   target_noncanonical := @target_noncanonical@
>   gcc_version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER)
>   libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
> +INSTALL := @INSTALL@
>   INSTALL_PROGRAM := @INSTALL_PROGRAM@
>   INSTALL_STRIP_PROGRAM := $(srcdir)/../install-sh -c -s
>   AUTOCONF := @AUTOCONF@
> @@ -41,13 +42,14 @@ all::
>   mostlyclean::
>   	rm -f $(MAPPER.O)
>   
> -clean::
> +clean:: mostlyclean
>   	rm -f g++-mapper-server$(exeext)
>   
> -distclean::
> -	rm -f config.log config.status config.h
> +distclean:: clean
> +	rm -f config.log config.status config.h config.cache Makefile
> +	rm -f $(MAPPER.O:%.o=%.d)
>   
> -maintainer-clean::
> +maintainer-clean:: distclean
>   
>   install::
>   
> @@ -132,6 +134,6 @@ config.h: config.status config.h.in
>   config.status: $(srcdir)/configure $(srcdir)/config.h.in
>   	if test -x $@; then ./$@ -recheck; else $< @configure_args@; fi
>   
> -.PHONY: all check clean distclean maintainer-clean
> +.PHONY: all check mostlyclean clean distclean maintainer-clean
>   
>   -include $(MAPPER.O:.o=.d)
  

Patch

diff --git a/c++tools/Makefile.in b/c++tools/Makefile.in
index 56cba090135..77bda3d56dc 100644
--- a/c++tools/Makefile.in
+++ b/c++tools/Makefile.in
@@ -22,6 +22,7 @@  libexecdir := @libexecdir@
 target_noncanonical := @target_noncanonical@
 gcc_version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER)
 libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+INSTALL := @INSTALL@
 INSTALL_PROGRAM := @INSTALL_PROGRAM@
 INSTALL_STRIP_PROGRAM := $(srcdir)/../install-sh -c -s
 AUTOCONF := @AUTOCONF@
@@ -41,13 +42,14 @@  all::
 mostlyclean::
 	rm -f $(MAPPER.O)
 
-clean::
+clean:: mostlyclean
 	rm -f g++-mapper-server$(exeext)
 
-distclean::
-	rm -f config.log config.status config.h
+distclean:: clean
+	rm -f config.log config.status config.h config.cache Makefile
+	rm -f $(MAPPER.O:%.o=%.d)
 
-maintainer-clean::
+maintainer-clean:: distclean
 
 install::
 
@@ -132,6 +134,6 @@  config.h: config.status config.h.in
 config.status: $(srcdir)/configure $(srcdir)/config.h.in
 	if test -x $@; then ./$@ -recheck; else $< @configure_args@; fi
 
-.PHONY: all check clean distclean maintainer-clean
+.PHONY: all check mostlyclean clean distclean maintainer-clean
 
 -include $(MAPPER.O:.o=.d)