diff --git a/src/aclocal.m4 b/src/aclocal.m4
index 0c27ce72e834e38a65016ef4edc50ce89493ce4c..0af749954649a87ad3e661015bd99f11d0030e29 100644
--- a/src/aclocal.m4
+++ b/src/aclocal.m4
@@ -1,4 +1,4 @@
-dnl $Id: aclocal.m4,v 1.39 2002/03/06 01:01:25 mast Exp $
+dnl $Id: aclocal.m4,v 1.40 2002/03/06 20:16:43 mast Exp $
 
 dnl Some compatibility with Autoconf 2.50+. Not complete.
 dnl newer autoconf call substr m4_substr
@@ -234,7 +234,7 @@ define(PIKE_FEATURE_OK,[
 
 define([AC_LOW_MODULE_INIT],
 [
-# $Id: aclocal.m4,v 1.39 2002/03/06 01:01:25 mast Exp $
+# $Id: aclocal.m4,v 1.40 2002/03/06 20:16:43 mast Exp $
 
 MY_AC_PROG_CC
 
@@ -352,16 +352,15 @@ pushdef([AC_OUTPUT],
 
 ifdef([PIKE_INCLUDE_PATH],
 [
+  dnl Is PIKE_INCLUDE_PATH really on the ../../... form, or is this broken?
   make_variables_in=PIKE_INCLUDE_PATH/make_variables_in
 ],[
   AC_MSG_CHECKING([for the Pike base directory])
 
-  make_variables_in=make_variables.in
-
   counter=.
 
   uplevels=
-  while test ! -f "$srcdir/$uplevels$make_variables_in"
+  while test ! -f "$srcdir/${uplevels}make_variables.in"
   do
     counter=.$counter
     if test $counter = .......... ; then
@@ -373,10 +372,12 @@ ifdef([PIKE_INCLUDE_PATH],
     uplevels=../$uplevels
   done
 
-  make_variables_in=$uplevels$make_variables_in
+  make_variables_in=${uplevels}make_variables.in
   AC_MSG_RESULT(${uplevels}.)
 ])
 
+  AC_SUBST(make_variables_in)
+
   AC_SUBST_FILE(make_variables)
   make_variables=make_variables
 
diff --git a/src/make_variables.in b/src/make_variables.in
index eef45d3e0430a8b5fa697365d087059ef7daa75d..0f2bc6d4f0a281d3dd6e73bfba6cdb4fcff69314 100644
--- a/src/make_variables.in
+++ b/src/make_variables.in
@@ -1,6 +1,6 @@
 # -*- Makefile -*-
 #
-# $Id: make_variables.in,v 1.8 2002/03/06 01:08:13 mast Exp $
+# $Id: make_variables.in,v 1.9 2002/03/06 20:16:43 mast Exp $
 #
 # Note: This template is actually used only for make_variables in the
 # subdirectories; the one created in the build base dir is just an
@@ -32,3 +32,4 @@ NOOPTFLAGS=@CFLAGS@ @CPPFLAGS@ $(OSFLAGS) $(WARN) $(PROFIL)
 AR=@AR@
 SRCDIR=@srcdir@
 PMOD_TARGETS=@PMOD_TARGETS@
+make_variables_in=@make_variables_in@
diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in
index df41582af807d34f46dccf96fbd01d0c57e141a1..1b18174fc961f46277a47bd6448e977d2e62f1e9 100644
--- a/src/modules/Makefile.in
+++ b/src/modules/Makefile.in
@@ -1,4 +1,4 @@
-# $Id: Makefile.in,v 1.40 2002/03/06 01:01:26 mast Exp $
+# $Id: Makefile.in,v 1.41 2002/03/06 20:16:46 mast Exp $
 
 @make_variables@
 
@@ -38,19 +38,22 @@ linker_options: $(MODULE_LINKOPTS)
 	  done \
 	) >linker_options
 
+make_variables: $(make_variables_in) config.status
+	CONFIG_FILES="make_variables:$(make_variables_in)" CONFIG_HEADERS="" ./config.status
+
 Makefile: $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies ./config.status
 	CONFIG_FILES=Makefile CONFIG_HEADERS="" ./config.status
 	touch remake
 	@echo "Run make again" >&2
 	@exit 1
 
-$(SRCDIR)/configure: $(SRCDIR)/configure.in $(SRCDIR)/../aclocal.m4
-	cd $(SRCDIR) && autoconf --localdir=$(SRCDIR)/..
+$(SRCDIR)/configure: $(SRCDIR)/configure.in $(PIKE_SRC_DIR)/aclocal.m4
+	cd $(SRCDIR) && autoconf --localdir=$(PIKE_SRC_DIR)
 
 config.status: $(SRCDIR)/configure
 	CFLAGS="$(REAL_CFLAGS)" LDFLAGS="$(REAL_LDFLAGS)" CPPFLAGS="$(REAL_CPPFLAGS)" BUILDDIR="$(TMP_BUILDDIR)" BINDIR="$(TMP_BINDIR)" PIKE_SRC_DIR="$(PIKE_SRC_DIR)" BUILD_BASE="$(BUILD_BASE)" ./config.status --recheck
 
-depend:
+depend: Makefile
 	@for a in $(MODULES) ; do \
 	  ( cd $$a && { \
 	    rm -f remake; \
diff --git a/src/modules/dynamic_module_makefile.in b/src/modules/dynamic_module_makefile.in
index f54f31403369d47b50991b5f042f653d6ba145e6..2305ff07a04c5dbf17948bd19f8f7eeaa2694a4d 100644
--- a/src/modules/dynamic_module_makefile.in
+++ b/src/modules/dynamic_module_makefile.in
@@ -1,5 +1,5 @@
 #
-# $Id: dynamic_module_makefile.in,v 1.84 2002/03/06 01:19:48 mast Exp $
+# $Id: dynamic_module_makefile.in,v 1.85 2002/03/06 20:16:46 mast Exp $
 #
 
 
@@ -78,8 +78,8 @@ modlist_headers: Makefile
 modlist_segment: Makefile
 	@echo "" >modlist_segment
 
-make_variables: $(PIKE_SRC_DIR)/make_variables.in config.status
-	CONFIG_FILES="make_variables:$(BUILD_BASE)/make_variables.in" CONFIG_HEADERS="" ./config.status
+make_variables: $(make_variables_in) config.status
+	CONFIG_FILES="make_variables:$(make_variables_in)" CONFIG_HEADERS="" ./config.status
 
 Makefile: $(MODULE_BASE)/dynamic_module_makefile $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies $(SRCDIR)/$(CONFIG_HEADERS).in make_variables config.status
 	CONFIG_FILES=Makefile CONFIG_HEADERS="$(CONFIG_HEADERS)" ./config.status
@@ -114,7 +114,7 @@ clean:
 	@for a in '' $(MODULE_SUBDIRS) ; do if test "x$$a" = "x"; then :; else echo cleaning $$a ; ( cd $$a ; $(MAKE) $(MAKE_FLAGS) clean ) ; fi ; done
 
 
-depend: $(SRC_TARGETS) $(PMOD_TARGETS)
+depend: $(SRC_TARGETS) $(PMOD_TARGETS) Makefile
 	-@echo Fixing dependencies for $(SRCDIR)/\*.c
 	@gcc -MM $(PREFLAGS) $(SRCDIR)/*.c \
 	|sed -e "s@ $(SRCDIR)/\([-a-zA-Z0-9.,_]*\)@ \$$(SRCDIR)/\1@g" \
diff --git a/src/modules/static_module_makefile.in b/src/modules/static_module_makefile.in
index 66f09b4cfa0207f04a2e83fdf5c1a5b584a5d921..b3a74888fc2ca526dd4698c03d50de4d9d2528a6 100644
--- a/src/modules/static_module_makefile.in
+++ b/src/modules/static_module_makefile.in
@@ -1,5 +1,5 @@
 #
-# $Id: static_module_makefile.in,v 1.75 2002/03/06 01:19:49 mast Exp $
+# $Id: static_module_makefile.in,v 1.76 2002/03/06 20:16:46 mast Exp $
 #
 
 
@@ -78,8 +78,8 @@ modlist_headers: Makefile
 modlist_segment: Makefile
 	@echo >modlist_segment " ,{ \"$(MODNAME)\", pike_module_$(MODNAME)_init, pike_module_$(MODNAME)_exit } "
 
-make_variables: $(PIKE_SRC_DIR)/make_variables.in config.status
-	CONFIG_FILES="make_variables:$(BUILD_BASE)/make_variables.in" CONFIG_HEADERS="" ./config.status
+make_variables: $(make_variables_in) config.status
+	CONFIG_FILES="make_variables:$(make_variables_in)" CONFIG_HEADERS="" ./config.status
 
 Makefile: $(MODULE_BASE)/static_module_makefile $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies $(SRCDIR)/$(CONFIG_HEADERS).in make_variables config.status
 	CONFIG_FILES=Makefile CONFIG_HEADERS="$(CONFIG_HEADERS)" ./config.status
@@ -122,7 +122,7 @@ clean:
 	-rm -f *.o *.fail *.obj *.a *.so module.so module.pmod linker_options modlist_headers modlist_segment module_testsuite $(MODULE_CLEAN_EXTRA)
 	@for a in '' $(MODULE_SUBDIRS) ; do if test "x$$a" = "x"; then :; else echo cleaning $$a ; ( cd $$a ; $(MAKE) $(MAKE_FLAGS) clean ) ; fi ; done
 
-depend: $(SRC_TARGETS) $(PMOD_TARGETS)
+depend: $(SRC_TARGETS) $(PMOD_TARGETS) Makefile
 	-@echo Fixing dependencies for $(SRCDIR)/\*.c
 	@gcc -MM $(PREFLAGS) $(SRCDIR)/*.c \
 	|sed -e "s@ $(SRCDIR)/\([-a-zA-Z0-9.,_]*\)@ \$$(SRCDIR)/\1@g" \
diff --git a/src/post_modules/Makefile.in b/src/post_modules/Makefile.in
index d93906455298b1c5a24ca222d2bc918d1ac27933..f03d73722f4b6781d5fd454f97fad9b84d36d0f3 100644
--- a/src/post_modules/Makefile.in
+++ b/src/post_modules/Makefile.in
@@ -1,4 +1,4 @@
-# $Id: Makefile.in,v 1.7 2002/03/06 01:01:27 mast Exp $
+# $Id: Makefile.in,v 1.8 2002/03/06 20:16:50 mast Exp $
 
 @make_variables@
 
@@ -48,19 +48,22 @@ linker_options: $(MODULE_LINKOPTS)
 	  done \
 	) >linker_options
 
+make_variables: $(make_variables_in) config.status
+	CONFIG_FILES="make_variables:$(make_variables_in)" CONFIG_HEADERS="" ./config.status
+
 Makefile: $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies ./config.status
 	CONFIG_FILES=Makefile CONFIG_HEADERS="" ./config.status
 	touch remake
 	@echo "Run make again" >&2
 	@exit 1
 
-$(SRCDIR)/configure: $(SRCDIR)/configure.in $(SRCDIR)/../aclocal.m4
-	cd $(SRCDIR) && autoconf --localdir=$(SRCDIR)/..
+$(SRCDIR)/configure: $(SRCDIR)/configure.in $(PIKE_SRC_DIR)/aclocal.m4
+	cd $(SRCDIR) && autoconf --localdir=$(PIKE_SRC_DIR)
 
 config.status: $(SRCDIR)/configure
 	CFLAGS="$(REAL_CFLAGS)" LDFLAGS="$(REAL_LDFLAGS)" CPPFLAGS="$(REAL_CPPFLAGS)" BUILDDIR="$(TMP_BUILDDIR)" BINDIR="$(TMP_BINDIR)" PIKE_SRC_DIR="$(PIKE_SRC_DIR)" BUILD_BASE="$(BUILD_BASE)" ./config.status --recheck
 
-depend:
+depend: Makefile
 	@for a in $(MODULES) no ; do \
 	  if test "$$a" = "no"; then :; else \
 	    ( cd $$a && { \