diff --git a/src/backend/Makefile b/src/backend/Makefile
index ec2dc7b..04385ec 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -109,19 +109,16 @@ endif
 
 endif # aix
 
-# Update the commonly used headers before building the subdirectories
-$(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/probes.h
+submake-genfiles: parser/gram.h storage/lmgr/lwlocknames.h utils/fmgroids.h utils/errcodes.h utils/probes.h catalog/schemapg.h
 
-# run this unconditionally to avoid needing to know its dependencies here:
-submake-schemapg:
-	$(MAKE) -C catalog schemapg.h
+submake-symlink: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/probes.h
 
-# src/port needs a convenient way to force errcodes.h to get built
-submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h
+submake-generate: submake-genfiles submake-symlink
 
-.PHONY: submake-schemapg submake-errcodes
+# Update the commonly used headers before building the subdirectories
+$(SUBDIRS:%=%-recursive): submake-generate
 
-catalog/schemapg.h: | submake-schemapg
+.PHONY: submake-generate
 
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
@@ -151,6 +148,9 @@ utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
 utils/probes.h: utils/probes.d
 	$(MAKE) -C utils probes.h
 
+catalog/schemapg.h:
+	$(MAKE) -C catalog schemapg.h
+
 # Make symlinks for these headers in the include directory. That way
 # we can cut down on the -I options. Also, a symlink is automatically
 # up to date when we update the base file.
@@ -188,8 +188,9 @@ $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
 	  $(LN_S) "$$prereqdir/$(notdir $<)" .
 
 $(top_builddir)/src/include/utils/probes.h: utils/probes.h
-	cd '$(dir $@)' && rm -f $(notdir $@) && \
-	    $(LN_S) "../../../$(subdir)/utils/probes.h" .
+	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
+	  cd '$(dir $@)' && rm -f $(notdir $@) && \
+	  $(LN_S) "$$prereqdir/$(notdir $<)" .
 
 
 utils/probes.o: utils/probes.d $(SUBDIROBJS)
diff --git a/src/common/Makefile b/src/common/Makefile
index 72b7369..c37aa90 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -77,12 +77,12 @@ libpgcommon_srv.a: $(OBJS_SRV)
 %_srv.o: %.c %.o
 	$(CC) $(CFLAGS) $(subst -DFRONTEND ,, $(CPPFLAGS)) -c $< -o $@
 
-$(OBJS_SRV): | submake-errcodes
+$(OBJS_SRV): | submake-generate
 
-.PHONY: submake-errcodes
+.PHONY: submake-generate
 
-submake-errcodes:
-	$(MAKE) -C ../backend submake-errcodes
+submake-generate:
+	$(MAKE) -C ../backend submake-generate
 
 # Dependencies of keywords.o need to be managed explicitly to make sure
 # that you don't get broken parsing code, even in a non-enable-depend build.
diff --git a/src/port/Makefile b/src/port/Makefile
index bc9b63a..5dbb4c3 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -79,12 +79,12 @@ libpgport_srv.a: $(OBJS_SRV)
 %_srv.o: %.c %.o
 	$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
 
-$(OBJS_SRV): | submake-errcodes
+$(OBJS_SRV): | submake-generate
 
-.PHONY: submake-errcodes
+submake-generate:
+	$(MAKE) -C ../backend submake-generate
 
-submake-errcodes:
-	$(MAKE) -C ../backend submake-errcodes
+.PHONY: submake-generate
 
 # Dependency is to ensure that path changes propagate
 
diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile
index 8926627..8f289ba 100644
--- a/src/test/modules/Makefile
+++ b/src/test/modules/Makefile
@@ -17,9 +17,11 @@ SUBDIRS = \
 		  test_shm_mq \
 		  worker_spi
 
-all: submake-errcodes
+all: submake-generate
 
-submake-errcodes:
-	$(MAKE) -C $(top_builddir)/src/backend submake-errcodes
+.PHONY: submake-generate
+
+submake-generate:
+	$(MAKE) -C $(top_builddir)/src/backend submake-generate
 
 $(recurse)
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index f5ed474..751d755 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -36,7 +36,7 @@ EXTRADEFS = '-DHOST_TUPLE="$(host_tuple)"' \
 
 all: pg_regress$(X)
 
-pg_regress$(X): pg_regress.o pg_regress_main.o $(WIN32RES) | submake-libpgport
+pg_regress$(X): pg_regress.o pg_regress_main.o $(WIN32RES) | submake-libpgport submake-generate
 	$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@
 
 # dependencies ensure that path changes propagate
