[modula2] PR-108142 Remove empty directories created in the build directory

Message ID 87v8lyi5nn.fsf@debian
State Accepted
Headers
Series [modula2] PR-108142 Remove empty directories created in the build directory |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Gaius Mulley Dec. 26, 2022, 2:46 p.m. UTC
  Hello,

Bootstrapped on amd64 GNU/Linux.  Ok for trunk?

regards,
Gaius

--- 8< ---

PR-108142 Remove empty directories created in the build directory.

This patch removes empty directories created in the build directory.
Directories are only created if required and all modula-2 build output
is created under m2.  Add m2.stageprofile and m2.stagefeedback rules.

gcc/m2/ChangeLog:

        * PR m2/108142
	* Make-lang.in: Change build directory to m2.
        Change all rules to dynamically create subdirectories
        when required.
	(m2.stageprofile): New.
	(m2.stagefeedback): New.
	* Make-maintainer.in: Change build directory to m2.
        Change all rules to dynamically create subdirectories when
        required.
	* config-lang.in: Remove static creation of build directories.
  

Comments

Iain Sandoe Dec. 26, 2022, 8:45 p.m. UTC | #1
Hi Gaius,

I’m finding it hard to figure out how the configuration is supposed to work for cross compilers (and more so for Canadian/native crosses).

Apologies if this is already answered in other review (but maybe some notes would help in that case).

questions in-line, thanks
Iain
 
> On 26 Dec 2022, at 14:46, Gaius Mulley via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> 
> 
> Hello,
> 
> Bootstrapped on amd64 GNU/Linux.  Ok for trunk?
> 
> regards,
> Gaius
> 
> --- 8< ---
> 
> PR-108142 Remove empty directories created in the build directory.
> 
> This patch removes empty directories created in the build directory.
> Directories are only created if required and all modula-2 build output
> is created under m2.  Add m2.stageprofile and m2.stagefeedback rules.
> 
> gcc/m2/ChangeLog:
> 
>        * PR m2/108142
> 	* Make-lang.in: Change build directory to m2.
>        Change all rules to dynamically create subdirectories
>        when required.
> 	(m2.stageprofile): New.
> 	(m2.stagefeedback): New.
> 	* Make-maintainer.in: Change build directory to m2.
>        Change all rules to dynamically create subdirectories when
>        required.
> 	* config-lang.in: Remove static creation of build directories.
> 
> diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
> index a8bd7fe4d19..828eaad6285 100644
> --- a/gcc/m2/Make-lang.in
> +++ b/gcc/m2/Make-lang.in
> @@ -27,7 +27,7 @@ GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`
> 
> M2_MAINTAINER = no
> 
> -GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
> +GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g

What does “stage1” mean in the case of a cross-compiler or a —disable-bootstrap configure?

> GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ -L$(objdir)/../ld $(TFLAGS)
> 
> @@ -61,7 +61,6 @@ m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/gm2-libs.texi m2/gm2-ebnf.
> 	-cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
> 	-cp -p m2/gm2-libs.texi $(srcdir)/m2
> 	-cp -p m2/gm2-ebnf.texi $(srcdir)/m2
> -	find . -name '*.texi' -print
> else
> m2.srcextra:
> endif
> @@ -153,7 +152,7 @@ doc/m2.info: $(TEXISRC)
> 	else true; fi
> 
> $(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
> -	test -d m2/images || mkdir -p m2/images
> +	-test -d m2/images || $(mkinstalldirs) m2/images
> 	cp $(srcdir)/m2/images/gnu.eps $@
> 
> # gm2-libs.texi
> @@ -163,6 +162,9 @@ m2/gm2-libs.texi: gm2-libs.texi-check; @true
> ifeq ($(HAVE_PYTHON),yes)
> gm2-libs.texi-check: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/Builtins.texi \
>                      $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def
> +	test -d m2/gm2-libs-pim || $(mkinstalldirs) m2/gm2-libs-pim
> +	test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
> +	test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
> 	$(PYTHON) $(srcdir)/m2/tools-src/def2doc.py -t -uLibraries -s$(srcdir)/m2 -b$(objdir)/m2 -o $(objdir)/m2/gm2-libs.texi
> else
> gm2-libs.texi-check:
> @@ -279,59 +281,21 @@ Builtins.rst-check:  m2/gm2-libs/Builtins.def
> endif
> 	$(STAMP) Builtins.rst-check
> 
> -$(objdir)/m2/gm2-compiler-boot:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-boot:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libiberty:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-gcc:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-compiler:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-iso:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-min:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-compiler-paranoid:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-paranoid:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-compiler-verify:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/boot-bin:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-pim:
> -	test -d $@ || mkdir $@
> -
> -$(objdir)/m2/gm2-libs-coroutines:
> -	test -d $@ || mkdir $@
> -
> -stage1/m2:
> -	-test -d $@ || mkdir -p stage1/m2
> -
> -stage2/m2:
> -	-test -d $@ || mkdir -p stage2/m2
> -
> -stage3/m2:
> -	-test -d $@ || mkdir -p stage3/m2
> +# Stage hooks:
> +# The toplevel makefile has already created stage?/m2 at this point.
> 
> -stage4/m2:
> -	-test -d $@ || mkdir -p stage4/m2
> +m2.stage1: stage1-start
> +	-mv m2/*$(objext) stage1/m2
> +m2.stage2: stage2-start
> +	-mv m2/*$(objext) stage2/m2
> +m2.stage3: stage3-start
> +	-mv m2/*$(objext) stage3/m2
> +m2.stage4: stage4-start
> +	-mv m2/*$(objext) stage4/m2
> +m2.stageprofile: stageprofile-start
> +	-mv m2/*$(objext) stageprofile/m2
> +m2.stagefeedback: stageprofile-start
> +	-mv m2/*$(objext) stagefeedback/m2
> 
> # No gm2-specific selftests
> selftest-m2:
> @@ -408,7 +372,7 @@ m2.install-plugin: installdirs
> 
> plugin/m2rte$(exeext).so: $(srcdir)/m2/plugin/m2rte.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
>         insn-attr-common.h insn-flags.h $(generated_files)
> -	test -d plugin || mkdir plugin
> +	-test -d plugin || $(mkinstalldirs) plugin
> 	$(PLUGINCC) $(PLUGINCFLAGS) -fno-rtti -I. -I$(srcdir) -I$(srcdir)/m2 -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/../include -I$(srcdir)/../libcpp/include -Wall $(GMPINC) -Wno-literal-suffix -fPIC -c -o plugin/m2rte.o $(srcdir)/m2/plugin/m2rte.cc
> 	$(PLUGINCC) $(PLUGINCFLAGS) $(PLUGINLIBS) -fno-rtti plugin/m2rte.o -shared -o $@
> 
> @@ -428,20 +392,6 @@ m2.clean:
> m2.extraclean:
> m2.realclean:
> 
> -# Stage hooks:
> -
> -m2.stage1: stage1-start
> -	-mv m2/*$(objext) stage1/m2
> -
> -m2.stage2: stage2-start
> -	-mv m2/*$(objext) stage2/m2
> -
> -m2.stage3: stage3-start
> -	-mv m2/*$(objext) stage3/m2
> -
> -m2.stage4: stage4-start
> -	-mv m2/*$(objext) stage4/m2
> -
> quit: force
> 	echo "calling exit"
> 	exit 1
> @@ -521,12 +471,13 @@ GM2_LIBS_BOOT     = m2/gm2-compiler-boot/gm2.a \
>                     m2/gm2-libs-boot/libgm2.a \
>                     $(GM2-BOOT-O)
> 
> -cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) $(m2.prev)
> +cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) $(m2.prev)
> 	cp -p $< $@
> 
> -stage2/m2/cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(P) \
> +m2/stage2/cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(P) \
>                             $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) $(GM2_LIBS) \
>                             m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so m2/gm2-libs-boot/M2LINK.o
> +	-test -d m2/stage2 || $(mkinstalldirs) m2/stage2
> 	@$(call LINK_PROGRESS,$(INDEX.m2),start)
> 	+$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) m2/gm2-compiler/m2flex.o \
>                             attribs.o \
> @@ -535,12 +486,13 @@ stage2/m2/cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(
>                               $(BACKENDLIBS) $(LIBSTDCXX) -lm
> 	@$(call LINK_PROGRESS,$(INDEX.m2),end)
> 
> -stage1/m2/cc1gm2$(exeext): gm2$(exeext) m2/gm2-compiler-boot/m2flex.o \
> +m2/stage1/cc1gm2$(exeext): gm2$(exeext) m2/gm2-compiler-boot/m2flex.o \
>                             $(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) \
>                             $(GM2_LIBS_BOOT) $(MC_LIBS) \
>                             m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so \
>                             m2/gm2-libs-boot/M2LINK.o \
>                             $(m2.prev)
> +	-test -d m2/stage1 || $(mkinstalldirs) m2/stage1
> 	@$(call LINK_PROGRESS,$(INDEX.m2),start)
> 	+$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) m2/gm2-compiler-boot/m2flex.o \
>                             attribs.o \
> @@ -558,6 +510,7 @@ GCC_HEADER_DEPENDENCIES_FOR_M2 = $(BUILD-BOOT-H) $(TIMEVAR_H) m2/gm2config.h $(C
>         $(generated_files) insn-attr-common.h
> 
> m2/gm2-gcc/%.o: $(srcdir)/m2/gm2-gcc/%.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
> +	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
> 	$(COMPILER) -c -g $(ALL_COMPILERFLAGS) \
>              $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
> 
> @@ -565,6 +518,7 @@ m2/gm2-gcc/m2configure.o: $(srcdir)/m2/gm2-gcc/m2configure.cc \
>                $(SYSTEM_H) $(GCC_H) $(CONFIG_H) \
>                m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS) \
>                $(generated_files) $(C_TREE_H) insn-attr-common.h
> +	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
> 	$(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
>          $(DRIVER_DEFINES) \
> 		-DLIBSUBDIR=\"$(libsubdir)\" \
> @@ -585,6 +539,7 @@ m2/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
> 
> m2/gm2-gcc/rtegraph.o: $(srcdir)/m2/gm2-gcc/rtegraph.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
>                        gt-m2-rtegraph.h
> +	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
> 	$(COMPILER) -c -g -I$(GM2GCC) $(ALL_COMPILERFLAGS) \

GM2GCC = -I$(srcdir)/m2 -Im2 -I$(srcdir)/m2/gm2-gcc -Im2/gm2-gcc ?

(and in two other places).

>             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
> 
> @@ -593,6 +548,7 @@ c-family/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
>             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
> 
> m2/gm2-gcc/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-gcc/%.def $(MCDEPS)
> +	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
> 	$(MC) -o=$@ $(srcdir)/m2/gm2-gcc/$*.def
> 
> # The following tables define the source files which are translated into C using mc
> @@ -1345,15 +1301,19 @@ m2/boot-bin/mc$(exeext): $(BUILD-MC-BOOT-O) $(BUILD-MC-INTERFACE-O) \
>          mcflex.o m2/gm2-libs-boot/RTcodummy.o -lm
> 
> m2/mc-boot/$(SRC_PREFIX)%.o: m2/mc-boot/$(SRC_PREFIX)%.c
> +	-test -d m2/mc-boot || $(mkinstalldirs) m2/mc-boot
> 	$(CXX) -g -c -I. -I$(srcdir)/m2/mc-boot-ch -I$(srcdir)/m2/mc-boot -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) $< -o $@
> 
> m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/mc-boot-ch || $(mkinstalldirs) m2/mc-boot-ch
> 	$(CXX) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -Im2/gm2-libs $< -o $@
> 
> m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/mc-boot-ch || $(mkinstalldirs) m2/mc-boot-ch
> 	$(CXX) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -Im2/gm2-libs $< -o $@
> 
> m2/mc-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
> +	-test -d m2/mc-boot || $(mkinstalldirs) m2/mc-boot
> 	unset CC ; $(M2LINK) -s --langc++ --exit --name m2/mc-boot/main.c $(srcdir)/m2/init/mcinit
> 	$(CXX) -g -c -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) m2/mc-boot/main.c -o $@
> 
> @@ -1364,57 +1324,73 @@ mcflex.c: $(srcdir)/m2/mc/mc.flex
> 	flex -t $< > $@
> 
> m2/gm2-libs-boot/%.o: $(srcdir)/m2/gm2-libs-boot/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(MC) -o=m2/gm2-libs-boot/$*.c $(srcdir)/m2/gm2-libs-boot/$*.mod
> 	$(COMPILER) -c -DIN_GCC $(CFLAGS) $(MCINCLUDES) m2/gm2-libs-boot/$*.c -o $@
> 
> m2/gm2-libs-boot/%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(MC) -o=m2/gm2-libs-boot/$*.c $(srcdir)/m2/gm2-libs/$*.mod
> 	$(COMPILER) -c -DIN_GCC $(CFLAGS) -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(MCINCLUDES) $(INCLUDES) m2/gm2-libs-boot/$*.c -o $@
> 
> m2/gm2-libs-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(MC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
> 
> m2/gm2-libs-boot/RTcodummy.o: $(srcdir)/m2/gm2-libs-ch/RTcodummy.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/RTintdummy.o: $(srcdir)/m2/gm2-libs-ch/RTintdummy.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/wrapc.o: $(srcdir)/m2/gm2-libs-ch/wrapc.c m2/gm2-libs-boot/$(SRC_PREFIX)wrapc.h m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c -DHAVE_CONFIG_H $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/M2LINK.o: $(srcdir)/m2/gm2-libs-ch/M2LINK.c m2/gm2-libs-boot/$(SRC_PREFIX)M2LINK.h m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c -DHAVE_CONFIG_H $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/UnixArgs.o: $(srcdir)/m2/gm2-libs-ch/UnixArgs.cc m2/gm2-libs-boot/$(SRC_PREFIX)UnixArgs.h m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/choosetemp.o: m2/gm2-libs-ch/choosetemp.c m2/gm2-libiberty/Gchoosetemp.h m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty -I$(srcdir)/m2/gm2-libiberty/ $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/errno.o: $(srcdir)/m2/gm2-libs-ch/errno.c m2/gm2-libs-boot/$(SRC_PREFIX)errno.h m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/dtoa.o: $(srcdir)/m2/gm2-libs-ch/dtoa.cc m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/ldtoa.o: $(srcdir)/m2/gm2-libs-ch/ldtoa.cc m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/termios.o: $(srcdir)/m2/gm2-libs-ch/termios.c $(BUILD-LIBS-BOOT-H) m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/SysExceptions.o: $(srcdir)/m2/gm2-libs-ch/SysExceptions.c \
>                                   m2/gm2-libs-boot/$(SRC_PREFIX)SysExceptions.h m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-boot/SysStorage.o: $(srcdir)/m2/gm2-libs/SysStorage.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(MC) -o=m2/gm2-libs-boot/SysStorage.c $(srcdir)/m2/gm2-libs/SysStorage.mod
> 	$(COMPILER) -DIN_GCC -c $(CFLAGS) \
>           -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(MCINCLUDES) $(INCLUDES) \
>           m2/gm2-libs-boot/SysStorage.c -o m2/gm2-libs-boot/SysStorage.o
> 
> m2/gm2-compiler-boot/M2GCCDeclare.o: $(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2GCCDeclare.c $<
> 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
>             -I. -I$(srcdir)/../include -I$(srcdir) \
> @@ -1422,6 +1398,7 @@ m2/gm2-compiler-boot/M2GCCDeclare.o: $(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod
>             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/M2GCCDeclare.c -o $@
> 
> m2/gm2-compiler-boot/M2Error.o: $(srcdir)/m2/gm2-compiler/M2Error.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2Error.c $<
> 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
>             -I. -I$(srcdir)/../include -I$(srcdir) \
> @@ -1429,6 +1406,7 @@ m2/gm2-compiler-boot/M2Error.o: $(srcdir)/m2/gm2-compiler/M2Error.mod $(MCDEPS)
>             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/M2Error.c -o $@
> 
> m2/gm2-compiler-boot/%.o: $(srcdir)/m2/gm2-compiler/%.mod $(BUILD-BOOT-H) $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(MC) -o=m2/gm2-compiler-boot/$*.c $(srcdir)/m2/gm2-compiler/$*.mod
> 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
>             -I. -I$(srcdir)/../include -I$(srcdir) \
> @@ -1436,6 +1414,7 @@ m2/gm2-compiler-boot/%.o: $(srcdir)/m2/gm2-compiler/%.mod $(BUILD-BOOT-H) $(MCDE
>             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/$*.c -o $@
> 
> m2/gm2-compiler-boot/%.o: m2/gm2-compiler-boot/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(MC) -o=m2/gm2-compiler-boot/$*.c m2/gm2-compiler-boot/$*.mod
> 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
>             -I. -I$(srcdir)/../include -I$(srcdir) \
> @@ -1443,37 +1422,46 @@ m2/gm2-compiler-boot/%.o: m2/gm2-compiler-boot/%.mod $(MCDEPS) $(BUILD-BOOT-H)
>             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/$*.c -o $@
> 
> m2/gm2-compiler-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-compiler/%.def $(MCDEPS)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(MC) -o=$@ $(srcdir)/m2/gm2-compiler/$*.def
> 
> m2/gm2-compiler-boot/m2flex.o: m2/gm2-compiler/m2flex.c $(BUILD-BOOT-H) $(TIMEVAR_H) \
>         $(BUILD-LIBS-BOOT-H)  m2/gm2-compiler-boot/$(SRC_PREFIX)NameKey.h \
>         $(CONFIG_H) m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(COMPILER) -c -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
>           $(GM2GCC) $(INCLUDES) -I$(srcdir)/m2 \
>           -Im2 -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
> 
> m2/gm2-compiler/m2flex.c: $(srcdir)/m2/m2.flex $(TIMEVAR_H) insn-attr-common.h
> +	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
> 	flex -t $< | sed -e 's/ malloc/ xmalloc/' | sed -e 's/ realloc/ xrealloc/' > $@
> 
> m2/gm2-libiberty/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libiberty/%.def $(MCDEPS)
> +	-test -d m2/gm2-libiberty || $(mkinstalldirs) m2/gm2-libiberty
> 	$(MC) -o=$@ $(srcdir)/m2/gm2-libiberty/$*.def
> 
> # The rules to build objects in gm2-compiler and gm2-libs directories.
> 
> m2/gm2-compiler/%.o: $(srcdir)/m2/gm2-compiler/%.mod
> +	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
> 	$(GM2_1) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler/m2flex.o: m2/gm2-compiler/m2flex.c m2/gm2-libs/gm2-libs-host.h $(TIMEVAR_H)
> +	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
> 	$(COMPILER) -c -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
>           $(GM2GCC) -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
> 
> m2/gm2-compiler/%.o: m2/gm2-compiler/%.mod
> +	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
> 	$(GM2_1) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
> 	$(CXX) -DBUILD_GM2_LIBS_TARGET -DBUILD_GM2_LIBS -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.mod
> +	-test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
> 	$(GM2_1) $(GM2_ISO_FLAGS) -c -B./ -Im2/gm2-libs-iso:$(srcdir)/m2/gm2-libs-iso -I$(srcdir)/m2/gm2-libs $< -o $@
> 
> 
> @@ -1481,6 +1469,7 @@ m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.mod
> # again using itself.
> 
> m2/gm2-libs/gm2-libs-host.h:
> +	-test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
> 	echo "Configuring to build libraries using native compiler" ; \
>         NEW_SRCDIR=`${srcdir}/m2/tools-src/calcpath ../../ ${srcdir} m2/gm2-libs` ; \
>         export NEW_SRCDIR ; \
> @@ -1512,6 +1501,7 @@ m2/gm2config.h:
>         fi
> 
> $(objdir)/m2/gm2-libs-min/SYSTEM.def: $(GM2_PROG_DEP)
> +	-test -d m2/gm2-libs-min || $(mkinstalldirs) m2/gm2-libs-min
> 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fpim \
>              $(srcdir)/m2/gm2-libs-min/SYSTEM.def \
>              $(srcdir)/m2/gm2-libs-min/SYSTEM.mod \
> @@ -1519,6 +1509,7 @@ $(objdir)/m2/gm2-libs-min/SYSTEM.def: $(GM2_PROG_DEP)
>              "$(GM2_FOR_TARGET)" $@
> 
> $(objdir)/m2/gm2-libs/SYSTEM.def: $(GM2_PROG_DEP)
> +	-test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
> 	echo "GM2_FOR_TARGET $(GM2_FOR_TARGET)"
> 	echo "GCC_FOR_TARGET $(GCC_FOR_TARGET)"
> 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fpim \
> @@ -1528,6 +1519,7 @@ $(objdir)/m2/gm2-libs/SYSTEM.def: $(GM2_PROG_DEP)
>              "$(GM2_FOR_TARGET)" $@
> 
> $(objdir)/m2/gm2-libs-iso/SYSTEM.def: $(GM2_PROG_DEP)
> +	-test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
> 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fiso \
>              $(srcdir)/m2/gm2-libs-iso/SYSTEM.def \
>              $(srcdir)/m2/gm2-libs-iso/SYSTEM.mod \
> @@ -1535,6 +1527,7 @@ $(objdir)/m2/gm2-libs-iso/SYSTEM.def: $(GM2_PROG_DEP)
>              "$(GM2_FOR_TARGET)" $@
> 
> $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def: $(GM2_PROG_DEP)
> +	-test -d m2/gm2-libs-coroutines || $(mkinstalldirs) m2/gm2-libs-coroutines
> 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fpim \
>              $(srcdir)/m2/gm2-libs-coroutines/SYSTEM.def \
>              $(srcdir)/m2/gm2-libs-coroutines/SYSTEM.mod \
> @@ -1546,11 +1539,13 @@ build-compiler: $(GM2-COMP-MODS:%.mod=m2/gm2-compiler/%.o) \
>                 m2/gm2-compiler/m2flex.o
> 
> m2/gm2-compiler/gm2.a: build-compiler gm2$(exeext)
> +	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
> 	$(AR_FOR_TARGET) cr $@ $(GM2-COMP-MODS:%.mod=m2/gm2-compiler/%.o) \
>                     $(GM2-AUTO-MODS:%.mod=m2/gm2-compiler/%.o)
> 	$(RANLIB) $@
> 
> m2/gm2-libs-boot/libgm2.a: m2/boot-bin/mc$(exeext) $(BUILD-LIBS-BOOT)
> +	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
> 	$(AR) cr $@ $(GM2-LIBS-BOOT-MODS:%.mod=m2/gm2-libs-boot/%.o) \
>                     $(GM2-LIBS-BOOT-CC:%.cc=m2/gm2-libs-boot/%.o) \
>                     $(GM2-LIBS-BOOT-C:%.c=m2/gm2-libs-boot/%.o)
> @@ -1558,6 +1553,7 @@ m2/gm2-libs-boot/libgm2.a: m2/boot-bin/mc$(exeext) $(BUILD-LIBS-BOOT)
> 
> m2/gm2-compiler-boot/gm2.a: m2/boot-bin/mc$(exeext) m2/boot-bin/mklink$(exeext) \
>                          $(BUILD-LIBS-BOOT) $(BUILD-COMPILER-BOOT)
> +	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
> 	$(AR) cr $@ $(GM2-COMP-BOOT-MODS:%.mod=m2/gm2-compiler-boot/%.o) \
>                     $(GM2-AUTO-MODS:%.mod=m2/gm2-compiler-boot/%.o)
> 	$(RANLIB) $@
> @@ -1565,15 +1561,19 @@ m2/gm2-compiler-boot/gm2.a: m2/boot-bin/mc$(exeext) m2/boot-bin/mklink$(exeext)
> m2/gm2-compiler-boot/gm2.a: m2/boot-bin/mc$(exeext)
> 
> m2/boot-bin/mklink$(exeext): $(srcdir)/m2/tools-src/mklink.c
> +	-test -d m2/boot-bin || $(mkinstalldirs) m2/boot-bin
> 	$(CXX) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-compiler-boot -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) $< -o $@
> 
> m2/gm2-compiler-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-compiler-boot/%.def $(MCDEPS)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(MC) --quiet -o=$@ $(srcdir)/m2/gm2-compiler-boot/$*.def
> 
> m2/gm2-compiler/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
> +	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
> 	$(PGE) -k -l $< -o $@
> 
> m2/gm2-compiler-boot/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
> +	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
> 	$(PGE) -k -l $< -o $@
> 
> check-m2: check-gm2
> @@ -1642,9 +1642,11 @@ ifeq ($(M2_MAINTAINER),yes)
> include m2/Make-maintainer
> else
> m2/pge-boot/%.o: m2/pge-boot/%.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/pge-boot ||$(mkinstalldirs) m2/pge-boot
> 	$(CXX) $(INCLUDES) -I$(srcdir)/m2/pge-boot -Im2/gm2-libs -g -c $< -o $@
> 
> m2/pge-boot/%.o: m2/pge-boot/%.cc m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/pge-boot || $(mkinstalldirs) m2/pge-boot
> 	$(CXX) $(INCLUDES) -I$(srcdir)/m2/pge-boot -Im2/gm2-libs -g -c $< -o $@
> 
> $(PGE): $(BUILD-PGE-O)
> diff --git a/gcc/m2/Make-maintainer.in b/gcc/m2/Make-maintainer.in
> index 2460b979207..79caba4649b 100644
> --- a/gcc/m2/Make-maintainer.in
> +++ b/gcc/m2/Make-maintainer.in
> @@ -96,21 +96,26 @@ BUILD-PPG-LIBS-H = $(PPG-LIB-DEFS:%.def=m2/gm2-ppg-boot/$(SRC_PREFIX)%.h)
> BUILD-PPG-H = m2/boot-bin/mc$(exeext) $(BUILD-PPG-LIBS-H)
> 
> m2/gm2-ppg-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
> +	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
> 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
> 
> m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
> 	$(MCC) -o=m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
>               -Im2/gm2-ppg-boot -I$(srcdir)/m2/mc-boot -Im2/gm2-libs-boot \
>               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c -o $@
> 
> m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
> 	$(MCC) -o=m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
>               -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
> @@ -124,12 +129,13 @@ m2/ppg$(exeext): m2/boot-bin/mc $(BUILD-PPG-O) $(BUILD-MC-INTERFACE-O) m2/gm2-pp
>                  m2/gm2-libs-boot/M2LINK.o -lm
> 
> m2/gm2-ppg-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
> +	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
> 	unset CC ; $(M2LINK) -s --langc++ --exit --name mainppginit.c $(srcdir)/m2/init/ppginit
> 	mv mainppginit.c m2/gm2-ppg-boot/main.c
> 	$(CXX) $(INCLUDES) -g -c -o $@ m2/gm2-ppg-boot/main.c
> 
> m2/gm2-auto:
> -	test -d $@ || mkdir -p $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> # m2/pg$(exext) is the 2nd generation parser generator built from ebnf
> # without error recovery
> @@ -143,15 +149,19 @@ BUILD-PG-O = $(PPG-INTERFACE-C:%.c=m2/gm2-pg-boot/$(SRC_PREFIX)%.o) \
>              $(PG-SRC:%.mod=m2/gm2-pg-boot/$(SRC_PREFIX)%.o)
> 
> m2/gm2-pg-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
> +	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
> 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
> 
> m2/gm2-pg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
> 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pg-boot	-I$(srcdir)/m2/mc-boot \
>                -I$(srcdir)/m2/mc-boot-ch \
> @@ -159,11 +169,13 @@ m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-B
>               -g -c m2/gm2-pg-boot/$(SRC_PREFIX)$*.c -o $@
> 
> m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
> 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
>               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-pg-boot/$(SRC_PREFIX)$*.c -o $@
> 
> m2/gm2-pg-boot/$(SRC_PREFIX)pg.o:  m2/gm2-auto/pg.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
> 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)pg.c m2/gm2-auto/pg.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
>               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-pg-boot/$(SRC_PREFIX)pg.c -o $@
> @@ -181,6 +193,7 @@ m2/gm2-auto/pginit:
> 	sed -e 's/ppg/pg/' < $(srcdir)/m2/init/ppginit > $@
> 
> m2/gm2-pg-boot/main.o: m2/gm2-auto/pginit $(M2LINK)
> +	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
> 	unset CC ; $(M2LINK) -s --langc++ --exit --name mainpginit.c m2/gm2-auto/pginit
> 	mv mainpginit.c m2/gm2-pg-boot/main.c
> 	$(CXX) $(INCLUDES) -g -c -o $@ m2/gm2-pg-boot/main.c
> @@ -196,6 +209,7 @@ m2/pg-e$(exeext): m2/pg$(exeext)
> 	$(RM) m2/gm2-auto/t.bnf m2/gm2-auto/t.mod
> 
> m2/gm2-auto/pg.mod: m2/ppg$(exeext)
> +	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
> 	$(SHELL) $(srcdir)/m2/tools-src/buildpg $(srcdir)/m2/gm2-compiler/ppg.mod pg -e > m2/gm2-auto/pg.bnf
> 	./m2/ppg$(exeext) -e -l m2/gm2-auto/pg.bnf > m2/gm2-auto/pg.mod
> 
> @@ -210,58 +224,74 @@ BUILD-PGE-O = $(PPG-INTERFACE-C:%.c=m2/gm2-pge-boot/$(SRC_PREFIX)%.o) \
>               $(PGE-SRC:%.mod=m2/gm2-pge-boot/$(SRC_PREFIX)%.o)
> 
> m2/gm2-auto/pge.mod: m2/pg$(exeext)
> +	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
> 	$(SHELL) $(srcdir)/m2/tools-src/buildpg $(srcdir)/m2/gm2-compiler/ppg.mod pge > m2/gm2-auto/pge.bnf
> 	./m2/pg$(exeext) -l m2/gm2-auto/pge.bnf -o m2/gm2-auto/pge.mod
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)libc.o: $(srcdir)/m2/mc-boot-ch/Glibc.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)mcrts.o:  $(srcdir)/m2/mc-boot-ch/Gmcrts.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)UnixArgs.o:  $(srcdir)/m2/mc-boot-ch/GUnixArgs.cc
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)Selective.o:  $(srcdir)/m2/mc-boot-ch/GSelective.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -Im2/gm2-libs -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)termios.o:  $(srcdir)/m2/mc-boot-ch/Gtermios.cc m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)SysExceptions.o:  $(srcdir)/m2/mc-boot-ch/GSysExceptions.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)ldtoa.o:  $(srcdir)/m2/mc-boot-ch/Gldtoa.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)dtoa.o:  $(srcdir)/m2/mc-boot-ch/Gdtoa.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)wrapc.o:  $(srcdir)/m2/mc-boot-ch/Gwrapc.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)SYSTEM.o:  $(srcdir)/m2/mc-boot-ch/GSYSTEM.c
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)errno.o:  $(srcdir)/m2/mc-boot-ch/Gerrno.c
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c $< -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pge-boot -I$(srcdir)/m2/mc-boot \
>               -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs-boot \
>               $(INCLUDES) -g -c m2/gm2-pge-boot/$(SRC_PREFIX)$*.c -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot \
>               -Im2/gm2-libs-boot \
>               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-pge-boot/$(SRC_PREFIX)$*.c -o $@
> 
> m2/gm2-pge-boot/$(SRC_PREFIX)pge.o:  m2/gm2-auto/pge.mod $(MCDEPS) $(BUILD-BOOT-H)
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)pge.c m2/gm2-auto/pge.mod
> 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
>               -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
> @@ -285,27 +315,31 @@ m2/pge$(exeext): m2/boot-bin/mc \
> 	$(RM) m2/gm2-auto/t.mod m2/gm2-auto/t1.mod m2/gm2-auto/t2.mod
> 
> m2/gm2-auto/pgeinit:
> +	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
> 	sed -e 's/ppg/pge/' < $(srcdir)/m2/init/ppginit > $@
> 
> m2/gm2-pge-boot/main.o: m2/gm2-auto/pgeinit $(M2LINK)
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	unset CC ; $(M2LINK) -s --langc++ --exit --name mainpgeinit.c m2/gm2-auto/pgeinit
> 	mv mainpgeinit.c m2/gm2-pge-boot/main.c
> 	$(CXX) $(INCLUDES) -g -c -o $@ m2/gm2-pge-boot/main.c
> 
> $(objdir)/m2/gm2-ppg-boot:
> -	test -d $@ || mkdir $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> $(objdir)/m2/gm2-pg-boot:
> -	test -d $@ || mkdir $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> $(objdir)/m2/gm2-pge-boot:
> -	test -d $@ || mkdir $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> m2/gm2-auto/pg.o: m2/gm2-auto/pg.mod $(MCDEPS)
> +	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
> 	$(MC) --quiet -o=m2/gm2-auto/pg.c m2/gm2-auto/pg.mod
> 	$(COMPILER) -c $(CFLAGS) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-compiler-boot -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) m2/gm2-auto/pg.c -o $@
> 
> m2/gm2-auto/pge.o: m2/gm2-auto/pge.mod $(MCDEPS)
> +	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
> 	$(MC) --quiet -o=m2/gm2-auto/pge.c m2/gm2-auto/pge.mod
> 	$(COMPILER) -c $(CFLAGS) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-compiler-boot -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) m2/gm2-auto/pge.c -o $@
> 
> @@ -400,7 +434,7 @@ mc-help:  force
> 	@echo "m2/pge          build the parser generator (needed by mc-maintainer)"
> 
> m2/mc-obj:
> -	mkdir $@
> +	$(mkinstalldirs) $@
> 
> mc-verify:  mc-clean mc-bootstrap mc
> 	mv mc m2/boot-bin/mc.m2
> @@ -442,7 +476,7 @@ m2/boot-bin/mc-devel$(exeext): m2/mc-obj/mcp1.mod \
>                                mcflex.c \
>                                m2/mc-boot-ch/Gabort.o
> 	$(RM) -rf mc-obj
> -	mkdir mc-obj
> +	$(mkinstalldirs) mc-obj
> 	$(CC) -I$(srcdir)/m2/mc -c -g mcflex.c -o mc-obj/mcflex.o
> 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) $(srcdir)/m2/mc/decl.mod -o mc-obj/decl.o
> 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) $(srcdir)/m2/mc/mcStream.mod -o mc-obj/mcStream.o
> @@ -484,13 +518,16 @@ m2/boot-bin/mc-opt$(exeext): m2/mc-obj/mcp1.mod \
>                              m2/mc-obj/mcp4.mod \
>                              m2/mc-obj/mcp5.mod \
>                              mcflex.c
> +	-test -d m2/boot-bin || $(mkinstalldirs) m2/boot-bin
> 	g++ -I$(srcdir)/m2/mc -c -g mcflex.c
> 	$(BOOTGM2) -fsources -fm2-whole-program -g -I$(srcdir)/m2/mc:$(objdir)/m2/mc-obj:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/mc $(srcdir)/m2/mc/top.mod
> 
> m2/mc/decl.o:  $(srcdir)/m2/mc/decl.mod
> +	-test -d m2/mc || $(mkinstalldirs) m2/mc
> 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) -o $@ $(srcdir)/m2/mc/decl.mod
> 
> m2/mc-obj/%.mod: $(srcdir)/m2/mc/%.bnf $(PGE)
> +	-test -d m2/mc-obj || $(mkinstalldirs) m2/mc-obj
> 	$(PGE) -l $< -o $@
> 
> gm2-bootstrap: mc-devel
> @@ -500,16 +537,16 @@ gm2-bootstrap: mc-devel
> 
> 
> $(objdir)/plugin:
> -	test -d $@ || mkdir -p $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> $(objdir)/m2/mc-boot:
> -	test -d $@ || mkdir -p $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> $(objdir)/m2/mc-boot-ch:
> -	test -d $@ || mkdir -p $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> $(objdir)/m2/mc-boot-gen:
> -	test -d $@ || mkdir -p $@
> +	-test -d $@ || $(mkinstalldirs) $@
> 
> mc-autogen: mc-clean mc-devel \
>             $(BUILD-MC-BOOT-H) $(BUILD-MC-BOOT-C) \
> @@ -528,24 +565,31 @@ EXTENDED_OPAQUE =
> MC_OPTIONS = $(MC_COPYRIGHT) --gcc-config-system --olang=c++
> 
> m2/mc-boot-gen/$(SRC_PREFIX)%.h: $(srcdir)/m2/mc/%.def
> +	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
> 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
> 
> m2/mc-boot-gen/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def
> +	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
> 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
> 
> m2/mc-boot-gen/$(SRC_PREFIX)decl.c: $(srcdir)/m2/mc/decl.mod
> +	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
> 	./mc $(MC_OPTIONS) --extended-opaque -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
> 
> m2/mc-boot-gen/$(SRC_PREFIX)%.c: $(srcdir)/m2/mc/%.mod
> +	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
> 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
> 
> m2/mc-boot-gen/$(SRC_PREFIX)%.c: $(srcdir)/m2/gm2-libs/%.mod
> +	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
> 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
> 
> m2/mc-boot-gen/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs-iso/%.def
> +	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
> 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
> 
> m2/mc-boot-gen/$(SRC_PREFIX)%.c: m2/mc-obj/%.mod
> +	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
> 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
> 
> # mc-bootstrap compiles mc using the C version previously generated by mc-autogen.
> @@ -608,11 +652,12 @@ GM2-VERIFY-AUTO    = P1Build.mod       P2Build.mod     PCBuild.mod     P3Build.m
> GM2_LIBS_PARANOID = m2/gm2-compiler-paranoid/gm2.a \
>                     m2/gm2-libs-paranoid/libgm2.a                       # build it again using GM2_LIBS
> 
> -gm2.paranoid: stage3/m2/cc1gm2$(exeext) gm2.verifyparanoid
> +gm2.paranoid: m2/stage3/cc1gm2$(exeext) gm2.verifyparanoid
> 
> -stage3/m2/cc1gm2$(exeext): stage2/m2/cc1gm2$(exeext) m2/gm2-compiler-paranoid/m2flex.o \
> +m2/stage3/cc1gm2$(exeext): m2/stage2/cc1gm2$(exeext) m2/gm2-compiler-paranoid/m2flex.o \
>                             $(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) $(GM2_LIBS_PARANOID) \
>                             m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so m2/gm2-libs-boot/M2LINK.o
> +	-test -d m2/stage3 || $(mkinstalldirs) m2/stage3
> 	@$(call LINK_PROGRESS,$(INDEX.m2),start)
> 	+$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) m2/gm2-compiler-paranoid/m2flex.o \
>                             attribs.o \
> @@ -624,7 +669,7 @@ stage3/m2/cc1gm2$(exeext): stage2/m2/cc1gm2$(exeext) m2/gm2-compiler-paranoid/m2
> 
> # gm2.verifyparanoid diffs the output of all three compilers with the compiler source code
> 
> -gm2.verifyparanoid: stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext) stage3/m2/cc1gm2$(exeext) force
> +gm2.verifyparanoid: m2/stage1/cc1gm2$(exeext) m2/stage2/cc1gm2$(exeext) m2/stage3/cc1gm2$(exeext) force
> 	@echo "verifying the three generations of GNU Modula-2 compilers - it may take some time.."
> 	$(QUIAT)for i in $(GM2-VERIFY-MODS) ; do \
>            echo -n "$$i " ; \
> @@ -678,7 +723,7 @@ gm2.verifyparanoid: stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext) stage3/m
> 
> # gm2.verifystage12 diffs the output of the stage1 and stage2 compilers with the compiler source code
> 
> -gm2.verifystage12: force stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext)
> +gm2.verifystage12: force m2/stage1/cc1gm2$(exeext) m2/stage2/cc1gm2$(exeext)
> 	@echo "verifying stage1 and stage2 generations of GNU Modula-2 compilers - it may take some time.."
> 	$(QUIAT)for i in $(GM2-VERIFY-MODS) ; do \
>            echo -n "$$i " ; \
> @@ -717,78 +762,99 @@ gm2.verifystage12: force stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext)
> # The rules which build objects in the gm2-compiler-paranoid gm2-libs-paranoid directories.
> 
> m2/gm2-libs-paranoid/%.o: m2/gm2-libs-ch/%.c
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(XGCC) -c -g $(GM2_O_S3) $(GM2_O) -I./ -Im2/gm2-libs -Wall $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/%.o: $(srcdir)/m2/gm2-libs/%.mod
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-libs-iso -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/%.o: $(srcdir)/m2/gm2-compiler/%.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/%.o: m2/gm2-compiler-paranoid/%.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/P0SyntaxCheck.o: m2/gm2-compiler-paranoid/P0SyntaxCheck.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/P1Build.o: m2/gm2-compiler-paranoid/P1Build.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/P2Build.o: m2/gm2-compiler-paranoid/P2Build.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/P3Build.o: m2/gm2-compiler-paranoid/P3Build.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/PHBuild.o: m2/gm2-compiler-paranoid/PHBuild.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-compiler-paranoid/PCBuild.o: m2/gm2-compiler-paranoid/PCBuild.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
> 
> m2/gm2-libs-paranoid/host.o: $(srcdir)/m2/gm2-libs-ch/host.c m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/wrapc.o: $(srcdir)/m2/gm2-libs-ch/wrapc.c m2/gm2-libs-boot/$(SRC_PREFIX)wrapc.h m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/UnixArgs.o: $(srcdir)/m2/gm2-libs-ch/UnixArgs.cc \
>                                   m2/gm2-libs-boot/$(SRC_PREFIX)UnixArgs.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/errno.o: $(srcdir)/m2/gm2-libs-ch/errno.c \
>                                    m2/gm2-libs-boot/$(SRC_PREFIX)errno.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/Selective.o: $(srcdir)/m2/gm2-libs-ch/Selective.c \
>                                    m2/gm2-libs-boot/$(SRC_PREFIX)Selective.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(COMPILER) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/choosetemp.o: $(srcdir)/m2/gm2-libs-ch/choosetemp.c \
>                                     m2/gm2-libiberty/$(SRC_PREFIX)choosetemp.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/SysExceptions.o: $(srcdir)/m2/gm2-libs-ch/SysExceptions.c \
>                                   m2/gm2-libs-boot/$(SRC_PREFIX)SysExceptions.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
> 
> m2/gm2-compiler-paranoid/m2flex.o: m2/gm2-compiler/m2flex.c $(TIMEVAR_H)
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(COMPILER) -c $(GM2_O_S3) -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
>           $(GM2GCC) -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
> 
> m2/gm2-libs-paranoid/dtoa.o: $(srcdir)/m2/gm2-libs-ch/dtoa.cc \
>                               m2/gm2-libs-boot/$(SRC_PREFIX)dtoa.h \
>                               m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/ldtoa.o: $(srcdir)/m2/gm2-libs-ch/ldtoa.cc \
>                                m2/gm2-libs-boot/$(SRC_PREFIX)ldtoa.h \
>                                m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
> 
> m2/gm2-libs-paranoid/termios.o: $(srcdir)/m2/gm2-libs-ch/termios.c \
>                                m2/gm2-libs-boot/$(SRC_PREFIX)termios.h \
>                                m2/gm2-libs/gm2-libs-host.h
> +	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
> 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
> 
> 
> @@ -818,12 +884,15 @@ m2/gm2-compiler-paranoid/gm2.a: \
> 	$(RANLIB) $@
> 
> m2/gm2-compiler-paranoid/M2Version.mod:
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(SHELL) $(srcdir)/m2/tools-src/makeversion -m $(srcdir) m2/gm2-compiler-paranoid
> 
> m2/gm2-compiler-paranoid/M2Version.o: m2/gm2-compiler-paranoid/M2Version.mod
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(GM2_2) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc $< -o $@
> 
> m2/gm2-compiler-paranoid/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
> +	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
> 	$(PGE) -k -l $< -o $@
> 
> # Recreate the target independent copies of the documentation which is
> diff --git a/gcc/m2/config-lang.in b/gcc/m2/config-lang.in
> index 68bb525355a..d2afff2f23f 100644
> --- a/gcc/m2/config-lang.in
> +++ b/gcc/m2/config-lang.in
> @@ -52,32 +52,3 @@ gtfiles="\$(srcdir)/m2/gm2-lang.cc \
> outputs="m2/config-make \
>          m2/Make-maintainer \
>         "
> -
> -mkdir -p m2/gm2-compiler-boot
> -mkdir -p m2/gm2-libs-boot
> -mkdir -p m2/gm2-ici-boot
> -mkdir -p m2/gm2-libiberty
> -mkdir -p m2/gm2-gcc
> -mkdir -p m2/gm2-compiler
> -mkdir -p m2/gm2-libs
> -mkdir -p m2/gm2-libs-iso
> -mkdir -p m2/gm2-compiler-paranoid
> -mkdir -p m2/gm2-libs-paranoid
> -mkdir -p m2/gm2-compiler-verify
> -mkdir -p m2/boot-bin
> -mkdir -p m2/gm2-libs-pim
> -mkdir -p m2/gm2-libs-coroutines
> -mkdir -p m2/gm2-libs-min
> -mkdir -p m2/pge-boot
> -mkdir -p plugin
> -mkdir -p stage1/m2 stage2/m2 stage3/m2 stage4/m2
> -
> -# directories used by Make-maintainer
> -
> -mkdir -p m2/gm2-auto
> -mkdir -p m2/gm2-pg-boot
> -mkdir -p m2/gm2-pge-boot
> -mkdir -p m2/gm2-ppg-boot
> -mkdir -p m2/mc-boot
> -mkdir -p m2/mc-boot-ch
> -mkdir -p m2/mc-boot-gen
  
Gaius Mulley Dec. 29, 2022, 11:56 a.m. UTC | #2
Iain Sandoe <idsandoe@googlemail.com> writes:

> Hi Gaius,
>
> I’m finding it hard to figure out how the configuration is supposed to work for cross compilers (and more so for Canadian/native crosses).
>
> Apologies if this is already answered in other review (but maybe some notes would help in that case).
>
> questions in-line, thanks
> Iain

Hi Iain,

many thanks for the comments.  The patch only addresses the empty
directories issue.  I take your point about Canadian cross compiler
problems.  I think there is confusion in my use of stage1, stage2,
stage3 directory names which perhaps should be renamed cxxobj1, m2obj2,
m2obj3.  All objects in cxxobj1 are created by 'mc' and 'g++' and this
would occur if the compiler is built native or in any cross
configuration.

The m2obj2 objects would be built from modula-2 sources using cxxobj1
and would be a developer/maintainer enabled option principally used for
debugging.  Finally m2obj3 is also used by developers to allow the
compiler generations output to be compared (cxxobj1 vs m2obj2 vs
m2obj3).  

This could coexist with the standard stage1, stage2, stage3 of gcc.  The
gcc stage check would only check cxxobj1 having been rebuilt by the
relevant g++/gcc.

I propose to rework the patch (renaming the directories) and ensure that
Canadian cross works (currently it doesn't) - although it was tested for
classic cross (build == host != target).

regards,
Gaius


>> On 26 Dec 2022, at 14:46, Gaius Mulley via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>>
>>
>> Hello,
>>
>> Bootstrapped on amd64 GNU/Linux.  Ok for trunk?
>>
>> regards,
>> Gaius
>>
>> --- 8< ---
>>
>> PR-108142 Remove empty directories created in the build directory.
>>
>> This patch removes empty directories created in the build directory.
>> Directories are only created if required and all modula-2 build output
>> is created under m2.  Add m2.stageprofile and m2.stagefeedback rules.
>>
>> gcc/m2/ChangeLog:
>>
>>        * PR m2/108142
>> 	* Make-lang.in: Change build directory to m2.
>>        Change all rules to dynamically create subdirectories
>>        when required.
>> 	(m2.stageprofile): New.
>> 	(m2.stagefeedback): New.
>> 	* Make-maintainer.in: Change build directory to m2.
>>        Change all rules to dynamically create subdirectories when
>>        required.
>> 	* config-lang.in: Remove static creation of build directories.
>>
>> diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
>> index a8bd7fe4d19..828eaad6285 100644
>> --- a/gcc/m2/Make-lang.in
>> +++ b/gcc/m2/Make-lang.in
>> @@ -27,7 +27,7 @@ GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`
>>
>> M2_MAINTAINER = no
>>
>> -GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
>> +GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g
>
> What does “stage1” mean in the case of a cross-compiler or a
> —disable-bootstrap configure?

stage1 (or the proposed newly named cxxobj1) is created when the first
generation modula-2 compiler is built (using mc/g++).

>> GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ -L$(objdir)/../ld $(TFLAGS)
>>
>> @@ -61,7 +61,6 @@ m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/gm2-libs.texi m2/gm2-ebnf.
>> 	-cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
>> 	-cp -p m2/gm2-libs.texi $(srcdir)/m2
>> 	-cp -p m2/gm2-ebnf.texi $(srcdir)/m2
>> -	find . -name '*.texi' -print
>> else
>> m2.srcextra:
>> endif

<snip>

>> @@ -565,6 +518,7 @@ m2/gm2-gcc/m2configure.o: $(srcdir)/m2/gm2-gcc/m2configure.cc \
>>                $(SYSTEM_H) $(GCC_H) $(CONFIG_H) \
>>                m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS) \
>>                $(generated_files) $(C_TREE_H) insn-attr-common.h
>> +	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
>> 	$(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
>>          $(DRIVER_DEFINES) \
>> 		-DLIBSUBDIR=\"$(libsubdir)\" \
>> @@ -585,6 +539,7 @@ m2/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
>>
>> m2/gm2-gcc/rtegraph.o: $(srcdir)/m2/gm2-gcc/rtegraph.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
>>                        gt-m2-rtegraph.h
>> +	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
>> 	$(COMPILER) -c -g -I$(GM2GCC) $(ALL_COMPILERFLAGS) \
>
> GM2GCC = -I$(srcdir)/m2 -Im2 -I$(srcdir)/m2/gm2-gcc -Im2/gm2-gcc ?

allows g++ to pick up the mc translated definition modules in the build
directory gcc/m2/gm2-gcc/G*.h.  Maybe I've misunderstood the question?
There is some redundancy when this macro is used within some rules (I'll
reduce the paths), thanks for spotting it!

> (and in two other places).
>
>>             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
>>
>> @@ -593,6 +548,7 @@ c-family/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
>>             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
>>

<snip>
  

Patch

diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index a8bd7fe4d19..828eaad6285 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -27,7 +27,7 @@  GM2_CROSS_NAME = `echo gm2|sed '$(program_transform_cross_name)'`
 
 M2_MAINTAINER = no
 
-GM2_1 = ./gm2 -B./stage1/m2 -g -fm2-g
+GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g
 
 GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ -L$(objdir)/../ld $(TFLAGS)
 
@@ -61,7 +61,6 @@  m2.srcextra: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/gm2-libs.texi m2/gm2-ebnf.
 	-cp -p m2/SYSTEM-iso.texi $(srcdir)/m2
 	-cp -p m2/gm2-libs.texi $(srcdir)/m2
 	-cp -p m2/gm2-ebnf.texi $(srcdir)/m2
-	find . -name '*.texi' -print
 else
 m2.srcextra:
 endif
@@ -153,7 +152,7 @@  doc/m2.info: $(TEXISRC)
 	else true; fi
 
 $(objdir)/m2/images/gnu.eps: $(srcdir)/m2/images/gnupng
-	test -d m2/images || mkdir -p m2/images
+	-test -d m2/images || $(mkinstalldirs) m2/images
 	cp $(srcdir)/m2/images/gnu.eps $@
 
 # gm2-libs.texi
@@ -163,6 +162,9 @@  m2/gm2-libs.texi: gm2-libs.texi-check; @true
 ifeq ($(HAVE_PYTHON),yes)
 gm2-libs.texi-check: m2/SYSTEM-pim.texi m2/SYSTEM-iso.texi m2/Builtins.texi \
                      $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def
+	test -d m2/gm2-libs-pim || $(mkinstalldirs) m2/gm2-libs-pim
+	test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
+	test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
 	$(PYTHON) $(srcdir)/m2/tools-src/def2doc.py -t -uLibraries -s$(srcdir)/m2 -b$(objdir)/m2 -o $(objdir)/m2/gm2-libs.texi
 else
 gm2-libs.texi-check:
@@ -279,59 +281,21 @@  Builtins.rst-check:  m2/gm2-libs/Builtins.def
 endif
 	$(STAMP) Builtins.rst-check
 
-$(objdir)/m2/gm2-compiler-boot:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-boot:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libiberty:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-gcc:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-iso:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-min:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler-paranoid:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-paranoid:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-compiler-verify:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/boot-bin:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-pim:
-	test -d $@ || mkdir $@
-
-$(objdir)/m2/gm2-libs-coroutines:
-	test -d $@ || mkdir $@
-
-stage1/m2:
-	-test -d $@ || mkdir -p stage1/m2
-
-stage2/m2:
-	-test -d $@ || mkdir -p stage2/m2
-
-stage3/m2:
-	-test -d $@ || mkdir -p stage3/m2
+# Stage hooks:
+# The toplevel makefile has already created stage?/m2 at this point.
 
-stage4/m2:
-	-test -d $@ || mkdir -p stage4/m2
+m2.stage1: stage1-start
+	-mv m2/*$(objext) stage1/m2
+m2.stage2: stage2-start
+	-mv m2/*$(objext) stage2/m2
+m2.stage3: stage3-start
+	-mv m2/*$(objext) stage3/m2
+m2.stage4: stage4-start
+	-mv m2/*$(objext) stage4/m2
+m2.stageprofile: stageprofile-start
+	-mv m2/*$(objext) stageprofile/m2
+m2.stagefeedback: stageprofile-start
+	-mv m2/*$(objext) stagefeedback/m2
 
 # No gm2-specific selftests
 selftest-m2:
@@ -408,7 +372,7 @@  m2.install-plugin: installdirs
 
 plugin/m2rte$(exeext).so: $(srcdir)/m2/plugin/m2rte.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
         insn-attr-common.h insn-flags.h $(generated_files)
-	test -d plugin || mkdir plugin
+	-test -d plugin || $(mkinstalldirs) plugin
 	$(PLUGINCC) $(PLUGINCFLAGS) -fno-rtti -I. -I$(srcdir) -I$(srcdir)/m2 -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/../include -I$(srcdir)/../libcpp/include -Wall $(GMPINC) -Wno-literal-suffix -fPIC -c -o plugin/m2rte.o $(srcdir)/m2/plugin/m2rte.cc
 	$(PLUGINCC) $(PLUGINCFLAGS) $(PLUGINLIBS) -fno-rtti plugin/m2rte.o -shared -o $@
 
@@ -428,20 +392,6 @@  m2.clean:
 m2.extraclean:
 m2.realclean:
 
-# Stage hooks:
-
-m2.stage1: stage1-start
-	-mv m2/*$(objext) stage1/m2
-
-m2.stage2: stage2-start
-	-mv m2/*$(objext) stage2/m2
-
-m2.stage3: stage3-start
-	-mv m2/*$(objext) stage3/m2
-
-m2.stage4: stage4-start
-	-mv m2/*$(objext) stage4/m2
-
 quit: force
 	echo "calling exit"
 	exit 1
@@ -521,12 +471,13 @@  GM2_LIBS_BOOT     = m2/gm2-compiler-boot/gm2.a \
                     m2/gm2-libs-boot/libgm2.a \
                     $(GM2-BOOT-O)
 
-cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) $(m2.prev)
+cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) $(m2.prev)
 	cp -p $< $@
 
-stage2/m2/cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(P) \
+m2/stage2/cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(P) \
                             $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) $(GM2_LIBS) \
                             m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so m2/gm2-libs-boot/M2LINK.o
+	-test -d m2/stage2 || $(mkinstalldirs) m2/stage2
 	@$(call LINK_PROGRESS,$(INDEX.m2),start)
 	+$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) m2/gm2-compiler/m2flex.o \
                             attribs.o \
@@ -535,12 +486,13 @@  stage2/m2/cc1gm2$(exeext): stage1/m2/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(
                               $(BACKENDLIBS) $(LIBSTDCXX) -lm
 	@$(call LINK_PROGRESS,$(INDEX.m2),end)
 
-stage1/m2/cc1gm2$(exeext): gm2$(exeext) m2/gm2-compiler-boot/m2flex.o \
+m2/stage1/cc1gm2$(exeext): gm2$(exeext) m2/gm2-compiler-boot/m2flex.o \
                             $(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) \
                             $(GM2_LIBS_BOOT) $(MC_LIBS) \
                             m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so \
                             m2/gm2-libs-boot/M2LINK.o \
                             $(m2.prev)
+	-test -d m2/stage1 || $(mkinstalldirs) m2/stage1
 	@$(call LINK_PROGRESS,$(INDEX.m2),start)
 	+$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) m2/gm2-compiler-boot/m2flex.o \
                             attribs.o \
@@ -558,6 +510,7 @@  GCC_HEADER_DEPENDENCIES_FOR_M2 = $(BUILD-BOOT-H) $(TIMEVAR_H) m2/gm2config.h $(C
         $(generated_files) insn-attr-common.h
 
 m2/gm2-gcc/%.o: $(srcdir)/m2/gm2-gcc/%.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
+	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
 	$(COMPILER) -c -g $(ALL_COMPILERFLAGS) \
              $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
@@ -565,6 +518,7 @@  m2/gm2-gcc/m2configure.o: $(srcdir)/m2/gm2-gcc/m2configure.cc \
                $(SYSTEM_H) $(GCC_H) $(CONFIG_H) \
                m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS) \
                $(generated_files) $(C_TREE_H) insn-attr-common.h
+	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
 	$(COMPILER) $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
          $(DRIVER_DEFINES) \
 		-DLIBSUBDIR=\"$(libsubdir)\" \
@@ -585,6 +539,7 @@  m2/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
 
 m2/gm2-gcc/rtegraph.o: $(srcdir)/m2/gm2-gcc/rtegraph.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
                        gt-m2-rtegraph.h
+	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
 	$(COMPILER) -c -g -I$(GM2GCC) $(ALL_COMPILERFLAGS) \
             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
@@ -593,6 +548,7 @@  c-family/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 m2/gm2-gcc/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-gcc/%.def $(MCDEPS)
+	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
 	$(MC) -o=$@ $(srcdir)/m2/gm2-gcc/$*.def
 
 # The following tables define the source files which are translated into C using mc
@@ -1345,15 +1301,19 @@  m2/boot-bin/mc$(exeext): $(BUILD-MC-BOOT-O) $(BUILD-MC-INTERFACE-O) \
          mcflex.o m2/gm2-libs-boot/RTcodummy.o -lm
 
 m2/mc-boot/$(SRC_PREFIX)%.o: m2/mc-boot/$(SRC_PREFIX)%.c
+	-test -d m2/mc-boot || $(mkinstalldirs) m2/mc-boot
 	$(CXX) -g -c -I. -I$(srcdir)/m2/mc-boot-ch -I$(srcdir)/m2/mc-boot -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) $< -o $@
 
 m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/mc-boot-ch || $(mkinstalldirs) m2/mc-boot-ch
 	$(CXX) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -Im2/gm2-libs $< -o $@
 
 m2/mc-boot-ch/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/mc-boot-ch || $(mkinstalldirs) m2/mc-boot-ch
 	$(CXX) -DHAVE_CONFIG_H -g -c -I. -Im2/gm2-libs -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -Im2/gm2-libs $< -o $@
 
 m2/mc-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
+	-test -d m2/mc-boot || $(mkinstalldirs) m2/mc-boot
 	unset CC ; $(M2LINK) -s --langc++ --exit --name m2/mc-boot/main.c $(srcdir)/m2/init/mcinit
 	$(CXX) -g -c -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) m2/mc-boot/main.c -o $@
 
@@ -1364,57 +1324,73 @@  mcflex.c: $(srcdir)/m2/mc/mc.flex
 	flex -t $< > $@
 
 m2/gm2-libs-boot/%.o: $(srcdir)/m2/gm2-libs-boot/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(MC) -o=m2/gm2-libs-boot/$*.c $(srcdir)/m2/gm2-libs-boot/$*.mod
 	$(COMPILER) -c -DIN_GCC $(CFLAGS) $(MCINCLUDES) m2/gm2-libs-boot/$*.c -o $@
 
 m2/gm2-libs-boot/%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(MC) -o=m2/gm2-libs-boot/$*.c $(srcdir)/m2/gm2-libs/$*.mod
 	$(COMPILER) -c -DIN_GCC $(CFLAGS) -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(MCINCLUDES) $(INCLUDES) m2/gm2-libs-boot/$*.c -o $@
 
 m2/gm2-libs-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(MC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-libs-boot/RTcodummy.o: $(srcdir)/m2/gm2-libs-ch/RTcodummy.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/RTintdummy.o: $(srcdir)/m2/gm2-libs-ch/RTintdummy.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/wrapc.o: $(srcdir)/m2/gm2-libs-ch/wrapc.c m2/gm2-libs-boot/$(SRC_PREFIX)wrapc.h m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c -DHAVE_CONFIG_H $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/M2LINK.o: $(srcdir)/m2/gm2-libs-ch/M2LINK.c m2/gm2-libs-boot/$(SRC_PREFIX)M2LINK.h m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c -DHAVE_CONFIG_H $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/UnixArgs.o: $(srcdir)/m2/gm2-libs-ch/UnixArgs.cc m2/gm2-libs-boot/$(SRC_PREFIX)UnixArgs.h m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c -DIN_GCC $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/choosetemp.o: m2/gm2-libs-ch/choosetemp.c m2/gm2-libiberty/Gchoosetemp.h m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty -I$(srcdir)/m2/gm2-libiberty/ $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/errno.o: $(srcdir)/m2/gm2-libs-ch/errno.c m2/gm2-libs-boot/$(SRC_PREFIX)errno.h m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/dtoa.o: $(srcdir)/m2/gm2-libs-ch/dtoa.cc m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/ldtoa.o: $(srcdir)/m2/gm2-libs-ch/ldtoa.cc m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/termios.o: $(srcdir)/m2/gm2-libs-ch/termios.c $(BUILD-LIBS-BOOT-H) m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/SysExceptions.o: $(srcdir)/m2/gm2-libs-ch/SysExceptions.c \
                                   m2/gm2-libs-boot/$(SRC_PREFIX)SysExceptions.h m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(CXX) -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-boot/SysStorage.o: $(srcdir)/m2/gm2-libs/SysStorage.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(MC) -o=m2/gm2-libs-boot/SysStorage.c $(srcdir)/m2/gm2-libs/SysStorage.mod
 	$(COMPILER) -DIN_GCC -c $(CFLAGS) \
           -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(MCINCLUDES) $(INCLUDES) \
           m2/gm2-libs-boot/SysStorage.c -o m2/gm2-libs-boot/SysStorage.o
 
 m2/gm2-compiler-boot/M2GCCDeclare.o: $(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2GCCDeclare.c $<
 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
             -I. -I$(srcdir)/../include -I$(srcdir) \
@@ -1422,6 +1398,7 @@  m2/gm2-compiler-boot/M2GCCDeclare.o: $(srcdir)/m2/gm2-compiler/M2GCCDeclare.mod
             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/M2GCCDeclare.c -o $@
 
 m2/gm2-compiler-boot/M2Error.o: $(srcdir)/m2/gm2-compiler/M2Error.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(MC) --extended-opaque -o=m2/gm2-compiler-boot/M2Error.c $<
 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
             -I. -I$(srcdir)/../include -I$(srcdir) \
@@ -1429,6 +1406,7 @@  m2/gm2-compiler-boot/M2Error.o: $(srcdir)/m2/gm2-compiler/M2Error.mod $(MCDEPS)
             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/M2Error.c -o $@
 
 m2/gm2-compiler-boot/%.o: $(srcdir)/m2/gm2-compiler/%.mod $(BUILD-BOOT-H) $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(MC) -o=m2/gm2-compiler-boot/$*.c $(srcdir)/m2/gm2-compiler/$*.mod
 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
             -I. -I$(srcdir)/../include -I$(srcdir) \
@@ -1436,6 +1414,7 @@  m2/gm2-compiler-boot/%.o: $(srcdir)/m2/gm2-compiler/%.mod $(BUILD-BOOT-H) $(MCDE
             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/$*.c -o $@
 
 m2/gm2-compiler-boot/%.o: m2/gm2-compiler-boot/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(MC) -o=m2/gm2-compiler-boot/$*.c m2/gm2-compiler-boot/$*.mod
 	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(GM2GCC) \
             -I. -I$(srcdir)/../include -I$(srcdir) \
@@ -1443,37 +1422,46 @@  m2/gm2-compiler-boot/%.o: m2/gm2-compiler-boot/%.mod $(MCDEPS) $(BUILD-BOOT-H)
             -I$(srcdir)/m2/gm2-libiberty $(MCINCLUDES) $(INCLUDES) m2/gm2-compiler-boot/$*.c -o $@
 
 m2/gm2-compiler-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-compiler/%.def $(MCDEPS)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(MC) -o=$@ $(srcdir)/m2/gm2-compiler/$*.def
 
 m2/gm2-compiler-boot/m2flex.o: m2/gm2-compiler/m2flex.c $(BUILD-BOOT-H) $(TIMEVAR_H) \
         $(BUILD-LIBS-BOOT-H)  m2/gm2-compiler-boot/$(SRC_PREFIX)NameKey.h \
         $(CONFIG_H) m2/gm2config.h $(TARGET_H) $(PLUGIN_HEADERS)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(COMPILER) -c -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
           $(GM2GCC) $(INCLUDES) -I$(srcdir)/m2 \
           -Im2 -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
 
 m2/gm2-compiler/m2flex.c: $(srcdir)/m2/m2.flex $(TIMEVAR_H) insn-attr-common.h
+	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
 	flex -t $< | sed -e 's/ malloc/ xmalloc/' | sed -e 's/ realloc/ xrealloc/' > $@
 
 m2/gm2-libiberty/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libiberty/%.def $(MCDEPS)
+	-test -d m2/gm2-libiberty || $(mkinstalldirs) m2/gm2-libiberty
 	$(MC) -o=$@ $(srcdir)/m2/gm2-libiberty/$*.def
 
 # The rules to build objects in gm2-compiler and gm2-libs directories.
 
 m2/gm2-compiler/%.o: $(srcdir)/m2/gm2-compiler/%.mod
+	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
 	$(GM2_1) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler/m2flex.o: m2/gm2-compiler/m2flex.c m2/gm2-libs/gm2-libs-host.h $(TIMEVAR_H)
+	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
 	$(COMPILER) -c -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
           $(GM2GCC) -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
 
 m2/gm2-compiler/%.o: m2/gm2-compiler/%.mod
+	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
 	$(GM2_1) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
 	$(CXX) -DBUILD_GM2_LIBS_TARGET -DBUILD_GM2_LIBS -c $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.mod
+	-test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
 	$(GM2_1) $(GM2_ISO_FLAGS) -c -B./ -Im2/gm2-libs-iso:$(srcdir)/m2/gm2-libs-iso -I$(srcdir)/m2/gm2-libs $< -o $@
 
 
@@ -1481,6 +1469,7 @@  m2/gm2-libs-iso/%.o: $(srcdir)/m2/gm2-libs-iso/%.mod
 # again using itself.
 
 m2/gm2-libs/gm2-libs-host.h:
+	-test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
 	echo "Configuring to build libraries using native compiler" ; \
         NEW_SRCDIR=`${srcdir}/m2/tools-src/calcpath ../../ ${srcdir} m2/gm2-libs` ; \
         export NEW_SRCDIR ; \
@@ -1512,6 +1501,7 @@  m2/gm2config.h:
         fi
 
 $(objdir)/m2/gm2-libs-min/SYSTEM.def: $(GM2_PROG_DEP)
+	-test -d m2/gm2-libs-min || $(mkinstalldirs) m2/gm2-libs-min
 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fpim \
              $(srcdir)/m2/gm2-libs-min/SYSTEM.def \
              $(srcdir)/m2/gm2-libs-min/SYSTEM.mod \
@@ -1519,6 +1509,7 @@  $(objdir)/m2/gm2-libs-min/SYSTEM.def: $(GM2_PROG_DEP)
              "$(GM2_FOR_TARGET)" $@
 
 $(objdir)/m2/gm2-libs/SYSTEM.def: $(GM2_PROG_DEP)
+	-test -d m2/gm2-libs || $(mkinstalldirs) m2/gm2-libs
 	echo "GM2_FOR_TARGET $(GM2_FOR_TARGET)"
 	echo "GCC_FOR_TARGET $(GCC_FOR_TARGET)"
 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fpim \
@@ -1528,6 +1519,7 @@  $(objdir)/m2/gm2-libs/SYSTEM.def: $(GM2_PROG_DEP)
              "$(GM2_FOR_TARGET)" $@
 
 $(objdir)/m2/gm2-libs-iso/SYSTEM.def: $(GM2_PROG_DEP)
+	-test -d m2/gm2-libs-iso || $(mkinstalldirs) m2/gm2-libs-iso
 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fiso \
              $(srcdir)/m2/gm2-libs-iso/SYSTEM.def \
              $(srcdir)/m2/gm2-libs-iso/SYSTEM.mod \
@@ -1535,6 +1527,7 @@  $(objdir)/m2/gm2-libs-iso/SYSTEM.def: $(GM2_PROG_DEP)
              "$(GM2_FOR_TARGET)" $@
 
 $(objdir)/m2/gm2-libs-coroutines/SYSTEM.def: $(GM2_PROG_DEP)
+	-test -d m2/gm2-libs-coroutines || $(mkinstalldirs) m2/gm2-libs-coroutines
 	$(SHELL) $(srcdir)/m2/tools-src/makeSystem -fpim \
              $(srcdir)/m2/gm2-libs-coroutines/SYSTEM.def \
              $(srcdir)/m2/gm2-libs-coroutines/SYSTEM.mod \
@@ -1546,11 +1539,13 @@  build-compiler: $(GM2-COMP-MODS:%.mod=m2/gm2-compiler/%.o) \
                 m2/gm2-compiler/m2flex.o
 
 m2/gm2-compiler/gm2.a: build-compiler gm2$(exeext)
+	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
 	$(AR_FOR_TARGET) cr $@ $(GM2-COMP-MODS:%.mod=m2/gm2-compiler/%.o) \
                     $(GM2-AUTO-MODS:%.mod=m2/gm2-compiler/%.o)
 	$(RANLIB) $@
 
 m2/gm2-libs-boot/libgm2.a: m2/boot-bin/mc$(exeext) $(BUILD-LIBS-BOOT)
+	-test -d m2/gm2-libs-boot || $(mkinstalldirs) m2/gm2-libs-boot
 	$(AR) cr $@ $(GM2-LIBS-BOOT-MODS:%.mod=m2/gm2-libs-boot/%.o) \
                     $(GM2-LIBS-BOOT-CC:%.cc=m2/gm2-libs-boot/%.o) \
                     $(GM2-LIBS-BOOT-C:%.c=m2/gm2-libs-boot/%.o)
@@ -1558,6 +1553,7 @@  m2/gm2-libs-boot/libgm2.a: m2/boot-bin/mc$(exeext) $(BUILD-LIBS-BOOT)
 
 m2/gm2-compiler-boot/gm2.a: m2/boot-bin/mc$(exeext) m2/boot-bin/mklink$(exeext) \
                          $(BUILD-LIBS-BOOT) $(BUILD-COMPILER-BOOT)
+	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
 	$(AR) cr $@ $(GM2-COMP-BOOT-MODS:%.mod=m2/gm2-compiler-boot/%.o) \
                     $(GM2-AUTO-MODS:%.mod=m2/gm2-compiler-boot/%.o)
 	$(RANLIB) $@
@@ -1565,15 +1561,19 @@  m2/gm2-compiler-boot/gm2.a: m2/boot-bin/mc$(exeext) m2/boot-bin/mklink$(exeext)
 m2/gm2-compiler-boot/gm2.a: m2/boot-bin/mc$(exeext)
 
 m2/boot-bin/mklink$(exeext): $(srcdir)/m2/tools-src/mklink.c
+	-test -d m2/boot-bin || $(mkinstalldirs) m2/boot-bin
 	$(CXX) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-compiler-boot -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) $< -o $@
 
 m2/gm2-compiler-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-compiler-boot/%.def $(MCDEPS)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(MC) --quiet -o=$@ $(srcdir)/m2/gm2-compiler-boot/$*.def
 
 m2/gm2-compiler/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
+	-test -d m2/gm2-compiler || $(mkinstalldirs) m2/gm2-compiler
 	$(PGE) -k -l $< -o $@
 
 m2/gm2-compiler-boot/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
+	-test -d m2/gm2-compiler-boot || $(mkinstalldirs) m2/gm2-compiler-boot
 	$(PGE) -k -l $< -o $@
 
 check-m2: check-gm2
@@ -1642,9 +1642,11 @@  ifeq ($(M2_MAINTAINER),yes)
 include m2/Make-maintainer
 else
 m2/pge-boot/%.o: m2/pge-boot/%.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/pge-boot ||$(mkinstalldirs) m2/pge-boot
 	$(CXX) $(INCLUDES) -I$(srcdir)/m2/pge-boot -Im2/gm2-libs -g -c $< -o $@
 
 m2/pge-boot/%.o: m2/pge-boot/%.cc m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/pge-boot || $(mkinstalldirs) m2/pge-boot
 	$(CXX) $(INCLUDES) -I$(srcdir)/m2/pge-boot -Im2/gm2-libs -g -c $< -o $@
 
 $(PGE): $(BUILD-PGE-O)
diff --git a/gcc/m2/Make-maintainer.in b/gcc/m2/Make-maintainer.in
index 2460b979207..79caba4649b 100644
--- a/gcc/m2/Make-maintainer.in
+++ b/gcc/m2/Make-maintainer.in
@@ -96,21 +96,26 @@  BUILD-PPG-LIBS-H = $(PPG-LIB-DEFS:%.def=m2/gm2-ppg-boot/$(SRC_PREFIX)%.h)
 BUILD-PPG-H = m2/boot-bin/mc$(exeext) $(BUILD-PPG-LIBS-H)
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
+	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
 	$(MCC) -o=m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
               -Im2/gm2-ppg-boot -I$(srcdir)/m2/mc-boot -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-ppg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
 	$(MCC) -o=m2/gm2-ppg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
               -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
@@ -124,12 +129,13 @@  m2/ppg$(exeext): m2/boot-bin/mc $(BUILD-PPG-O) $(BUILD-MC-INTERFACE-O) m2/gm2-pp
                  m2/gm2-libs-boot/M2LINK.o -lm
 
 m2/gm2-ppg-boot/main.o: $(M2LINK) $(srcdir)/m2/init/mcinit
+	-test -d m2/gm2-ppg-boot || $(mkinstalldirs) m2/gm2-ppg-boot
 	unset CC ; $(M2LINK) -s --langc++ --exit --name mainppginit.c $(srcdir)/m2/init/ppginit
 	mv mainppginit.c m2/gm2-ppg-boot/main.c
 	$(CXX) $(INCLUDES) -g -c -o $@ m2/gm2-ppg-boot/main.c
 
 m2/gm2-auto:
-	test -d $@ || mkdir -p $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 # m2/pg$(exext) is the 2nd generation parser generator built from ebnf
 # without error recovery
@@ -143,15 +149,19 @@  BUILD-PG-O = $(PPG-INTERFACE-C:%.c=m2/gm2-pg-boot/$(SRC_PREFIX)%.o) \
              $(PG-SRC:%.mod=m2/gm2-pg-boot/$(SRC_PREFIX)%.o)
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
+	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.o: m2/mc-boot-ch/$(SRC_PREFIX)%.cc m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pg-boot	-I$(srcdir)/m2/mc-boot \
                -I$(srcdir)/m2/mc-boot-ch \
@@ -159,11 +169,13 @@  m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-B
               -g -c m2/gm2-pg-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pg-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-pg-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pg-boot/$(SRC_PREFIX)pg.o:  m2/gm2-auto/pg.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
 	$(MCC) -o=m2/gm2-pg-boot/$(SRC_PREFIX)pg.c m2/gm2-auto/pg.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-pg-boot/$(SRC_PREFIX)pg.c -o $@
@@ -181,6 +193,7 @@  m2/gm2-auto/pginit:
 	sed -e 's/ppg/pg/' < $(srcdir)/m2/init/ppginit > $@
 
 m2/gm2-pg-boot/main.o: m2/gm2-auto/pginit $(M2LINK)
+	-test -d m2/gm2-pg-boot || $(mkinstalldirs) m2/gm2-pg-boot
 	unset CC ; $(M2LINK) -s --langc++ --exit --name mainpginit.c m2/gm2-auto/pginit
 	mv mainpginit.c m2/gm2-pg-boot/main.c
 	$(CXX) $(INCLUDES) -g -c -o $@ m2/gm2-pg-boot/main.c
@@ -196,6 +209,7 @@  m2/pg-e$(exeext): m2/pg$(exeext)
 	$(RM) m2/gm2-auto/t.bnf m2/gm2-auto/t.mod
 
 m2/gm2-auto/pg.mod: m2/ppg$(exeext)
+	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
 	$(SHELL) $(srcdir)/m2/tools-src/buildpg $(srcdir)/m2/gm2-compiler/ppg.mod pg -e > m2/gm2-auto/pg.bnf
 	./m2/ppg$(exeext) -e -l m2/gm2-auto/pg.bnf > m2/gm2-auto/pg.mod
 
@@ -210,58 +224,74 @@  BUILD-PGE-O = $(PPG-INTERFACE-C:%.c=m2/gm2-pge-boot/$(SRC_PREFIX)%.o) \
               $(PGE-SRC:%.mod=m2/gm2-pge-boot/$(SRC_PREFIX)%.o)
 
 m2/gm2-auto/pge.mod: m2/pg$(exeext)
+	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
 	$(SHELL) $(srcdir)/m2/tools-src/buildpg $(srcdir)/m2/gm2-compiler/ppg.mod pge > m2/gm2-auto/pge.bnf
 	./m2/pg$(exeext) -l m2/gm2-auto/pge.bnf -o m2/gm2-auto/pge.mod
 
 m2/gm2-pge-boot/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def $(MCDEPS)
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(MCC) -o=$@ $(srcdir)/m2/gm2-libs/$*.def
 
 m2/gm2-pge-boot/$(SRC_PREFIX)libc.o: $(srcdir)/m2/mc-boot-ch/Glibc.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)mcrts.o:  $(srcdir)/m2/mc-boot-ch/Gmcrts.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) $(INCLUDES) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)UnixArgs.o:  $(srcdir)/m2/mc-boot-ch/GUnixArgs.cc
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)Selective.o:  $(srcdir)/m2/mc-boot-ch/GSelective.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -Im2/gm2-libs -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)termios.o:  $(srcdir)/m2/mc-boot-ch/Gtermios.cc m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)SysExceptions.o:  $(srcdir)/m2/mc-boot-ch/GSysExceptions.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)ldtoa.o:  $(srcdir)/m2/mc-boot-ch/Gldtoa.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)dtoa.o:  $(srcdir)/m2/mc-boot-ch/Gdtoa.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)wrapc.o:  $(srcdir)/m2/mc-boot-ch/Gwrapc.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)SYSTEM.o:  $(srcdir)/m2/mc-boot-ch/GSYSTEM.c
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)errno.o:  $(srcdir)/m2/mc-boot-ch/Gerrno.c
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c $< -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-libs/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-libs/$*.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/gm2-pge-boot -I$(srcdir)/m2/mc-boot \
               -I$(srcdir)/m2/mc-boot-ch -Im2/gm2-libs-boot \
               $(INCLUDES) -g -c m2/gm2-pge-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)%.o: $(srcdir)/m2/gm2-compiler/%.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)$*.c $(srcdir)/m2/gm2-compiler/$*.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) -Im2/mc-boot -Im2/gm2-compiler-boot \
               -Im2/gm2-libs-boot \
               -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) -g -c m2/gm2-pge-boot/$(SRC_PREFIX)$*.c -o $@
 
 m2/gm2-pge-boot/$(SRC_PREFIX)pge.o:  m2/gm2-auto/pge.mod $(MCDEPS) $(BUILD-BOOT-H)
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(MCC) -o=m2/gm2-pge-boot/$(SRC_PREFIX)pge.c m2/gm2-auto/pge.mod
 	$(CXX) -I. -I$(srcdir)/../include -I$(srcdir) \
               -Im2/mc-boot -Im2/gm2-compiler-boot -Im2/gm2-libs-boot \
@@ -285,27 +315,31 @@  m2/pge$(exeext): m2/boot-bin/mc \
 	$(RM) m2/gm2-auto/t.mod m2/gm2-auto/t1.mod m2/gm2-auto/t2.mod
 
 m2/gm2-auto/pgeinit:
+	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
 	sed -e 's/ppg/pge/' < $(srcdir)/m2/init/ppginit > $@
 
 m2/gm2-pge-boot/main.o: m2/gm2-auto/pgeinit $(M2LINK)
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	unset CC ; $(M2LINK) -s --langc++ --exit --name mainpgeinit.c m2/gm2-auto/pgeinit
 	mv mainpgeinit.c m2/gm2-pge-boot/main.c
 	$(CXX) $(INCLUDES) -g -c -o $@ m2/gm2-pge-boot/main.c
 
 $(objdir)/m2/gm2-ppg-boot:
-	test -d $@ || mkdir $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 $(objdir)/m2/gm2-pg-boot:
-	test -d $@ || mkdir $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 $(objdir)/m2/gm2-pge-boot:
-	test -d $@ || mkdir $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 m2/gm2-auto/pg.o: m2/gm2-auto/pg.mod $(MCDEPS)
+	-test -d m2/gm2-pge-boot || $(mkinstalldirs) m2/gm2-pge-boot
 	$(MC) --quiet -o=m2/gm2-auto/pg.c m2/gm2-auto/pg.mod
 	$(COMPILER) -c $(CFLAGS) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-compiler-boot -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) m2/gm2-auto/pg.c -o $@
 
 m2/gm2-auto/pge.o: m2/gm2-auto/pge.mod $(MCDEPS)
+	-test -d m2/gm2-auto || $(mkinstalldirs) m2/gm2-auto
 	$(MC) --quiet -o=m2/gm2-auto/pge.c m2/gm2-auto/pge.mod
 	$(COMPILER) -c $(CFLAGS) -I. -I$(srcdir)/../include -I$(srcdir) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-compiler-boot -I$(srcdir)/m2/mc-boot-ch $(INCLUDES) m2/gm2-auto/pge.c -o $@
 
@@ -400,7 +434,7 @@  mc-help:  force
 	@echo "m2/pge          build the parser generator (needed by mc-maintainer)"
 
 m2/mc-obj:
-	mkdir $@
+	$(mkinstalldirs) $@
 
 mc-verify:  mc-clean mc-bootstrap mc
 	mv mc m2/boot-bin/mc.m2
@@ -442,7 +476,7 @@  m2/boot-bin/mc-devel$(exeext): m2/mc-obj/mcp1.mod \
                                mcflex.c \
                                m2/mc-boot-ch/Gabort.o
 	$(RM) -rf mc-obj
-	mkdir mc-obj
+	$(mkinstalldirs) mc-obj
 	$(CC) -I$(srcdir)/m2/mc -c -g mcflex.c -o mc-obj/mcflex.o
 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) $(srcdir)/m2/mc/decl.mod -o mc-obj/decl.o
 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) $(srcdir)/m2/mc/mcStream.mod -o mc-obj/mcStream.o
@@ -484,13 +518,16 @@  m2/boot-bin/mc-opt$(exeext): m2/mc-obj/mcp1.mod \
                              m2/mc-obj/mcp4.mod \
                              m2/mc-obj/mcp5.mod \
                              mcflex.c
+	-test -d m2/boot-bin || $(mkinstalldirs) m2/boot-bin
 	g++ -I$(srcdir)/m2/mc -c -g mcflex.c
 	$(BOOTGM2) -fsources -fm2-whole-program -g -I$(srcdir)/m2/mc:$(objdir)/m2/mc-obj:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/mc $(srcdir)/m2/mc/top.mod
 
 m2/mc/decl.o:  $(srcdir)/m2/mc/decl.mod
+	-test -d m2/mc || $(mkinstalldirs) m2/mc
 	$(BOOTGM2) $(MCOPTIONS) -I$(GM2PATH) -o $@ $(srcdir)/m2/mc/decl.mod
 
 m2/mc-obj/%.mod: $(srcdir)/m2/mc/%.bnf $(PGE)
+	-test -d m2/mc-obj || $(mkinstalldirs) m2/mc-obj
 	$(PGE) -l $< -o $@
 
 gm2-bootstrap: mc-devel
@@ -500,16 +537,16 @@  gm2-bootstrap: mc-devel
 
 
 $(objdir)/plugin:
-	test -d $@ || mkdir -p $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 $(objdir)/m2/mc-boot:
-	test -d $@ || mkdir -p $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 $(objdir)/m2/mc-boot-ch:
-	test -d $@ || mkdir -p $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 $(objdir)/m2/mc-boot-gen:
-	test -d $@ || mkdir -p $@
+	-test -d $@ || $(mkinstalldirs) $@
 
 mc-autogen: mc-clean mc-devel \
             $(BUILD-MC-BOOT-H) $(BUILD-MC-BOOT-C) \
@@ -528,24 +565,31 @@  EXTENDED_OPAQUE =
 MC_OPTIONS = $(MC_COPYRIGHT) --gcc-config-system --olang=c++
 
 m2/mc-boot-gen/$(SRC_PREFIX)%.h: $(srcdir)/m2/mc/%.def
+	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 m2/mc-boot-gen/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs/%.def
+	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 m2/mc-boot-gen/$(SRC_PREFIX)decl.c: $(srcdir)/m2/mc/decl.mod
+	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
 	./mc $(MC_OPTIONS) --extended-opaque -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 m2/mc-boot-gen/$(SRC_PREFIX)%.c: $(srcdir)/m2/mc/%.mod
+	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 m2/mc-boot-gen/$(SRC_PREFIX)%.c: $(srcdir)/m2/gm2-libs/%.mod
+	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 m2/mc-boot-gen/$(SRC_PREFIX)%.h: $(srcdir)/m2/gm2-libs-iso/%.def
+	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 m2/mc-boot-gen/$(SRC_PREFIX)%.c: m2/mc-obj/%.mod
+	-test -d m2/mc-boot-gen || $(mkinstalldirs) m2/mc-boot-gen
 	./mc $(MC_OPTIONS) -I$(srcdir)/m2/mc:$(srcdir)/m2/gm2-libs:$(srcdir)/m2/gm2-libs-iso $(EXTENDED_OPAQUE) --h-file-prefix=$(SRC_PREFIX) -o=$@ $<
 
 # mc-bootstrap compiles mc using the C version previously generated by mc-autogen.
@@ -608,11 +652,12 @@  GM2-VERIFY-AUTO    = P1Build.mod       P2Build.mod     PCBuild.mod     P3Build.m
 GM2_LIBS_PARANOID = m2/gm2-compiler-paranoid/gm2.a \
                     m2/gm2-libs-paranoid/libgm2.a                       # build it again using GM2_LIBS
 
-gm2.paranoid: stage3/m2/cc1gm2$(exeext) gm2.verifyparanoid
+gm2.paranoid: m2/stage3/cc1gm2$(exeext) gm2.verifyparanoid
 
-stage3/m2/cc1gm2$(exeext): stage2/m2/cc1gm2$(exeext) m2/gm2-compiler-paranoid/m2flex.o \
+m2/stage3/cc1gm2$(exeext): m2/stage2/cc1gm2$(exeext) m2/gm2-compiler-paranoid/m2flex.o \
                             $(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) $(GM2_LIBS_PARANOID) \
                             m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so m2/gm2-libs-boot/M2LINK.o
+	-test -d m2/stage3 || $(mkinstalldirs) m2/stage3
 	@$(call LINK_PROGRESS,$(INDEX.m2),start)
 	+$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) m2/gm2-compiler-paranoid/m2flex.o \
                             attribs.o \
@@ -624,7 +669,7 @@  stage3/m2/cc1gm2$(exeext): stage2/m2/cc1gm2$(exeext) m2/gm2-compiler-paranoid/m2
 
 # gm2.verifyparanoid diffs the output of all three compilers with the compiler source code
 
-gm2.verifyparanoid: stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext) stage3/m2/cc1gm2$(exeext) force
+gm2.verifyparanoid: m2/stage1/cc1gm2$(exeext) m2/stage2/cc1gm2$(exeext) m2/stage3/cc1gm2$(exeext) force
 	@echo "verifying the three generations of GNU Modula-2 compilers - it may take some time.."
 	$(QUIAT)for i in $(GM2-VERIFY-MODS) ; do \
            echo -n "$$i " ; \
@@ -678,7 +723,7 @@  gm2.verifyparanoid: stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext) stage3/m
 
 # gm2.verifystage12 diffs the output of the stage1 and stage2 compilers with the compiler source code
 
-gm2.verifystage12: force stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext)
+gm2.verifystage12: force m2/stage1/cc1gm2$(exeext) m2/stage2/cc1gm2$(exeext)
 	@echo "verifying stage1 and stage2 generations of GNU Modula-2 compilers - it may take some time.."
 	$(QUIAT)for i in $(GM2-VERIFY-MODS) ; do \
            echo -n "$$i " ; \
@@ -717,78 +762,99 @@  gm2.verifystage12: force stage1/m2/cc1gm2$(exeext) stage2/m2/cc1gm2$(exeext)
 # The rules which build objects in the gm2-compiler-paranoid gm2-libs-paranoid directories.
 
 m2/gm2-libs-paranoid/%.o: m2/gm2-libs-ch/%.c
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(XGCC) -c -g $(GM2_O_S3) $(GM2_O) -I./ -Im2/gm2-libs -Wall $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/%.o: $(srcdir)/m2/gm2-libs/%.mod
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-libs-iso -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/%.o: $(srcdir)/m2/gm2-compiler/%.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/%.o: m2/gm2-compiler-paranoid/%.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/P0SyntaxCheck.o: m2/gm2-compiler-paranoid/P0SyntaxCheck.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/P1Build.o: m2/gm2-compiler-paranoid/P1Build.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/P2Build.o: m2/gm2-compiler-paranoid/P2Build.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/P3Build.o: m2/gm2-compiler-paranoid/P3Build.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/PHBuild.o: m2/gm2-compiler-paranoid/PHBuild.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-compiler-paranoid/PCBuild.o: m2/gm2-compiler-paranoid/PCBuild.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_O_S3) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/m2/gm2-libiberty $< -o $@
 
 m2/gm2-libs-paranoid/host.o: $(srcdir)/m2/gm2-libs-ch/host.c m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/wrapc.o: $(srcdir)/m2/gm2-libs-ch/wrapc.c m2/gm2-libs-boot/$(SRC_PREFIX)wrapc.h m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/UnixArgs.o: $(srcdir)/m2/gm2-libs-ch/UnixArgs.cc \
                                   m2/gm2-libs-boot/$(SRC_PREFIX)UnixArgs.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/errno.o: $(srcdir)/m2/gm2-libs-ch/errno.c \
                                    m2/gm2-libs-boot/$(SRC_PREFIX)errno.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/Selective.o: $(srcdir)/m2/gm2-libs-ch/Selective.c \
                                    m2/gm2-libs-boot/$(SRC_PREFIX)Selective.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(COMPILER) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/choosetemp.o: $(srcdir)/m2/gm2-libs-ch/choosetemp.c \
                                     m2/gm2-libiberty/$(SRC_PREFIX)choosetemp.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot -Im2/gm2-libiberty $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/SysExceptions.o: $(srcdir)/m2/gm2-libs-ch/SysExceptions.c \
                                   m2/gm2-libs-boot/$(SRC_PREFIX)SysExceptions.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c -DIN_GCC $(GM2_O_S3) $(CFLAGS) -Im2/gm2-libs -I$(srcdir)/m2 -Im2 -I. -Im2/gm2-libs-boot $(INCLUDES) $< -o $@
 
 m2/gm2-compiler-paranoid/m2flex.o: m2/gm2-compiler/m2flex.c $(TIMEVAR_H)
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(COMPILER) -c $(GM2_O_S3) -g $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
           $(GM2GCC) -Im2/gm2-compiler-boot -Im2/gm2-libs-boot $< -o $@
 
 m2/gm2-libs-paranoid/dtoa.o: $(srcdir)/m2/gm2-libs-ch/dtoa.cc \
                               m2/gm2-libs-boot/$(SRC_PREFIX)dtoa.h \
                               m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/ldtoa.o: $(srcdir)/m2/gm2-libs-ch/ldtoa.cc \
                                m2/gm2-libs-boot/$(SRC_PREFIX)ldtoa.h \
                                m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 m2/gm2-libs-paranoid/termios.o: $(srcdir)/m2/gm2-libs-ch/termios.c \
                                m2/gm2-libs-boot/$(SRC_PREFIX)termios.h \
                                m2/gm2-libs/gm2-libs-host.h
+	-test -d m2/gm2-libs-paranoid || $(mkinstalldirs) m2/gm2-libs-paranoid
 	$(CXX) -c $(GM2_O_S3) $(CFLAGS) -I$(srcdir)/m2 -Im2/gm2-libs-boot -Im2/gm2-libs $(INCLUDES) $< -o $@
 
 
@@ -818,12 +884,15 @@  m2/gm2-compiler-paranoid/gm2.a: \
 	$(RANLIB) $@
 
 m2/gm2-compiler-paranoid/M2Version.mod:
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(SHELL) $(srcdir)/m2/tools-src/makeversion -m $(srcdir) m2/gm2-compiler-paranoid
 
 m2/gm2-compiler-paranoid/M2Version.o: m2/gm2-compiler-paranoid/M2Version.mod
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(GM2_2) $(GM2_FLAGS) -c -I$(srcdir)/m2/gm2-compiler -I$(srcdir)/m2/gm2-libs -I$(srcdir)/m2/gm2-gcc $< -o $@
 
 m2/gm2-compiler-paranoid/%.mod: $(srcdir)/m2/gm2-compiler/%.bnf $(PGE)
+	-test -d m2/gm2-compiler-paranoid || $(mkinstalldirs) m2/gm2-compiler-paranoid
 	$(PGE) -k -l $< -o $@
 
 # Recreate the target independent copies of the documentation which is
diff --git a/gcc/m2/config-lang.in b/gcc/m2/config-lang.in
index 68bb525355a..d2afff2f23f 100644
--- a/gcc/m2/config-lang.in
+++ b/gcc/m2/config-lang.in
@@ -52,32 +52,3 @@  gtfiles="\$(srcdir)/m2/gm2-lang.cc \
 outputs="m2/config-make \
          m2/Make-maintainer \
         "
-
-mkdir -p m2/gm2-compiler-boot
-mkdir -p m2/gm2-libs-boot
-mkdir -p m2/gm2-ici-boot
-mkdir -p m2/gm2-libiberty
-mkdir -p m2/gm2-gcc
-mkdir -p m2/gm2-compiler
-mkdir -p m2/gm2-libs
-mkdir -p m2/gm2-libs-iso
-mkdir -p m2/gm2-compiler-paranoid
-mkdir -p m2/gm2-libs-paranoid
-mkdir -p m2/gm2-compiler-verify
-mkdir -p m2/boot-bin
-mkdir -p m2/gm2-libs-pim
-mkdir -p m2/gm2-libs-coroutines
-mkdir -p m2/gm2-libs-min
-mkdir -p m2/pge-boot
-mkdir -p plugin
-mkdir -p stage1/m2 stage2/m2 stage3/m2 stage4/m2
-
-# directories used by Make-maintainer
-
-mkdir -p m2/gm2-auto
-mkdir -p m2/gm2-pg-boot
-mkdir -p m2/gm2-pge-boot
-mkdir -p m2/gm2-ppg-boot
-mkdir -p m2/mc-boot
-mkdir -p m2/mc-boot-ch
-mkdir -p m2/mc-boot-gen