diff --git a/Makefile b/Makefile
index d85a386f15d2e5fdc4cab3c0999ea33e4c5a70bf..c16c03ce8d91f6fc583e1f5449f666bc4b0aa83d 100644
--- a/Makefile
+++ b/Makefile
@@ -332,6 +332,13 @@ include/asterisk/buildopts.h: menuselect.makeopts
 	fi
 	@rm -f $@.tmp
 
+include/asterisk/build.h:
+	@build_tools/make_build_h > $@.tmp
+	@if cmp -s $@.tmp $@ ; then : ; else \
+		mv $@.tmp $@ ; \
+	fi
+	@rm -f $@.tmp
+
 $(SUBDIRS_CLEAN_DEPEND):
 	@$(MAKE) --no-print-directory -C $(@:-clean-depend=) clean-depend
 
@@ -624,7 +631,7 @@ $(MOD_SUBDIRS_DEPEND):
 $(OTHER_SUBDIRS_DEPEND):
 	@ASTCFLAGS="$(OTHER_SUBDIR_CFLAGS) $(ASTCFLAGS)" $(MAKE) --no-print-directory -C $(@:-depend=) depend
 
-depend: include/asterisk/version.h include/asterisk/buildopts.h defaults.h $(SUBDIRS_DEPEND)
+depend: include/asterisk/version.h include/asterisk/buildopts.h include/asterisk/build.h defaults.h $(SUBDIRS_DEPEND)
 
 sounds:
 	$(MAKE) -C sounds all
diff --git a/main/Makefile b/main/Makefile
index c2e8ef6e0cda0c89d71deddd55f82890d9accb55..4a47104f20bd19c57f2f5b7d190886a3835e30a7 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -126,11 +126,6 @@ else
 endif
 
 asterisk: $(OBJS) editline/libedit.a db1-ast/libdb1.a $(AST_EMBED_LDSCRIPTS)
-	@$(ASTTOPDIR)/build_tools/make_build_h > $(ASTTOPDIR)/include/asterisk/build.h.tmp
-	@if cmp -s $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; then echo ; else \
-		mv $(ASTTOPDIR)/include/asterisk/build.h.tmp $(ASTTOPDIR)/include/asterisk/build.h ; \
-	fi
-	@rm -f $(ASTTOPDIR)/include/asterisk/build.h.tmp
 	@$(CC) -c -o buildinfo.o $(ASTCFLAGS) buildinfo.c
 	$(ECHO_PREFIX) echo "   [LD] $^ -> $@"
 	$(CMD_PREFIX) $(CXX) $(STATIC_BUILD) -o $@ $(ASTLINK) $(AST_EMBED_LDFLAGS) $(ASTLDFLAGS) $(H323LDFLAGS) $^ buildinfo.o $(AST_LIBS) $(AST_EMBED_LIBS) $(H323LDLIBS)