diff --git a/.gitattributes b/.gitattributes
index e390a9696d73a4012c45a9f5ff1733a5c6bf7310..e49bb4ded23f5ec4e625316728c98fc3ea9a38bc 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -80,6 +80,7 @@ testfont binary
 /man/pike.1 foreign_ident
 /src/Makefile.in foreign_ident
 /src/acconfig.h foreign_ident
+/src/aclocal.m4 foreign_ident
 /src/alloca.c foreign_ident
 /src/array.c foreign_ident
 /src/array.h foreign_ident
diff --git a/src/Makefile.in b/src/Makefile.in
index 982d4a4bbe6a82e4ffa325803afc56808b3649ff..31a36f7b4ebf91fc57120a3afbb8660055c16f9a 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,5 +1,5 @@
 #
-# $Id: Makefile.in,v 1.116 1998/09/05 15:20:39 grubba Exp $
+# $Id: Makefile.in,v 1.117 1998/09/20 08:30:31 hubbe Exp $
 #
 
 # This line is needed on some machines.
@@ -201,7 +201,7 @@ interpret.o: $(SRCDIR)/interpret.c
 force :
 
 # install
-install: pike hilfe
+install: pike hilfe pike-module aclocal
 	@echo
 	@echo Installing Pike...
 	@echo
@@ -260,12 +260,29 @@ install: pike hilfe
 	    chmod u+w "$(exec_prefix)/hilfe"; \
 	  fi; \
 	else : ; fi
+	@if [ -f ./pike-module ]; then \
+	  echo ; echo "Installing pike-module..."; \
+	  if cmp "$(exec_prefix)/pike-module" ./pike-module >/dev/null 2>&1 ; \
+	  then \
+	    echo "$(exec_prefix)/pike-module already installed." ; \
+	  else \
+	    if [ -f "$(exec_prefix)/pike-module" ]; then \
+	      mv "$(exec_prefix)/pike-module" "$(exec_prefix)/pike-module.old" || exit 1; \
+	    else : ; fi; \
+	    echo "$(exec_prefix)/pike-module"; \
+	    $(INSTALL) ./pike-module "$(exec_prefix)" || exit 1; \
+	    chmod a+rx "$(exec_prefix)/pike-module"; \
+	    chmod u+w "$(exec_prefix)/pike-module"; \
+	  fi; \
+	else : ; fi
 	@echo ; echo "Installing header-files..."; \
 	for a in $(SRCDIR)/*.h *.h ; do \
 	  $(INSTALL) $$a "$(prefix)/include/pike" || exit 1; \
 	  chmod a+r "$(prefix)/include/pike" ; \
 	  chmod u+w "$(prefix)/include/pike" ; \
 	done
+	@$(INSTALL) modules/dynamic_module_makefile $(prefix)/include/pike/dynamic_module_makefile
+	@$(INSTALL) ./aclocal $(prefix)/include/pike/aclocal.m4
 	@echo ; echo "Installing modules written in Pike..."; \
 	for f in `cd "$(LIBDIR_SRC)"; find . -type f -print | grep -v '/CVS/'`; do \
 	  if cmp "$(share_prefix)/$$f" "$(LIBDIR_SRC)/$$f" >/dev/null 2>&1 ; \
@@ -408,6 +425,19 @@ master.pike: $(LIBDIR_SRC)/master.pike.in Makefile
 	sed -e 's!¤lib_prefix¤!$(TMP_LIBDIR)!' <$(LIBDIR_SRC)/master.pike.in \
 	  | sed -e 's!¤share_prefix¤!$(LIBDIR_SRC)!' >master.pike
 
+pike-module: $(SRCDIR)/pike-module.in Makefile ./pike
+	$(RUNPIKE) $(SRCDIR)/pike-module.in --fixate=$(SRCDIR)/pike-module.in \
+	   --set='make=$(MAKE)' --set='make_flags=$(MAKE_FLAGS)' \
+	   --set='prefix=$(prefix)' --set='pike=$(exec_prefix)/pike' \
+	   --set='include_path=$(prefix)/include/pike' \
+	   --set='lib_prefix=$(TMP_LIBDIR)' --set='share_prefix=$(LIBDIR_SRC)' \
+           --output=pike-module
+	-@chmod +x pike-module
+
+aclocal: $(SRCDIR)/aclocal.m4
+	echo >aclocal "define(PIKE_INCLUDE_PATH,$(prefix)/include/pike)"
+	cat >>aclocal $(SRCDIR)/aclocal.m4
+
 # make export archive (requires compiled Pike)
 # Do not compile in source tree if you want to use this!
 # Beware that export archive this includes bison/yacc/byacc source
diff --git a/src/aclocal.m4 b/src/aclocal.m4
new file mode 100644
index 0000000000000000000000000000000000000000..65498892a02963b25d3985d4778f5e141a3723f7
--- /dev/null
+++ b/src/aclocal.m4
@@ -0,0 +1,41 @@
+define([AC_LOW_MODULE_INIT],
+[
+# $Id: aclocal.m4,v 1.1 1998/09/20 08:30:31 hubbe Exp $
+
+AC_PROG_CC
+AC_DEFINE(POSIX_SOURCE)
+AC_SUBST_FILE(dependencies)
+dependencies=$srcdir/dependencies
+
+AC_SUBST_FILE(dynamic_module_makefile)
+AC_SUBST_FILE(static_module_makefile)
+])
+
+
+define([AC_MODULE_INIT],
+[
+AC_LOW_MODULE_INIT()
+
+ifdef([PIKE_INCLUDE_PATH],
+[
+dynamic_module_makefile=PIKE_INCLUDE_PATH/dynamic_module_makefile
+static_module_makefile=PIKE_INCLUDE_PATH/dynamic_module_makefile
+],[
+dynamic_module_makefile=../dynamic_module_makefile
+static_module_makefile=../static_module_makefile
+
+counter=.
+
+while test ! -f "$dynamic_module_makefile"
+do
+  counter=.$counter
+  if test $counter = .......... ; then
+    exit 1
+  else
+    :
+  fi
+  dynamic_module_makefile=../$dynamic_module_makefile
+  static_module_makefile=../$static_module_makefile
+done
+])
+])
diff --git a/src/modules/Gdbm/configure.in b/src/modules/Gdbm/configure.in
index 2758d4d9d9eb34740c6f91d6948318a03b2c133a..fbb93589582ccf4b547459cc1d8bbd24ddbb0e00 100644
--- a/src/modules/Gdbm/configure.in
+++ b/src/modules/Gdbm/configure.in
@@ -1,10 +1,10 @@
-# $Id: configure.in,v 1.2 1998/03/28 14:55:20 grubba Exp $
+# $Id: configure.in,v 1.3 1998/09/20 08:30:50 hubbe Exp $
 AC_INIT(gdbmmod.c)
 AC_CONFIG_HEADER(gdbm_machine.h)
 
 AC_ARG_WITH(gdbm,    [  --with(out)-gdbm       GNU database manager support ],[],[with_gdbm=yes])
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 if test x$with_gdbm = xyes; then
   AC_CHECK_HEADERS(gdbm.h)
diff --git a/src/modules/Gmp/configure.in b/src/modules/Gmp/configure.in
index 11e1abb2db5b31fde0a97979aef6c41d9baa6e00..fb900b77dd66f1309221ff3e82c2b753ad41b2b5 100644
--- a/src/modules/Gmp/configure.in
+++ b/src/modules/Gmp/configure.in
@@ -1,9 +1,9 @@
-# $Id: configure.in,v 1.3 1998/07/11 15:56:18 grubba Exp $
+# $Id: configure.in,v 1.4 1998/09/20 08:30:58 hubbe Exp $
 AC_INIT(mpz_glue.c)
 AC_CONFIG_HEADER(gmp_machine.h)
 AC_ARG_WITH(gmp,     [  --with(out)-gmp        Support bignums],[],[with_gmp=yes])
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 if test x$with_gmp = xyes ; then
   AC_CHECK_HEADERS(gmp2/gmp.h)
diff --git a/src/modules/Gz/configure.in b/src/modules/Gz/configure.in
index ad6c26a4ef46d5c610040bb3d618c047e6782379..b2d7046ede9edb8c6c395e8985d9382d1bf3af38 100644
--- a/src/modules/Gz/configure.in
+++ b/src/modules/Gz/configure.in
@@ -1,9 +1,9 @@
-# $Id: configure.in,v 1.11 1998/07/18 00:07:05 grubba Exp $
+# $Id: configure.in,v 1.12 1998/09/20 08:31:07 hubbe Exp $
 AC_INIT(zlibmod.c)
 AC_CONFIG_HEADER(zlib_machine.h)
 AC_ARG_WITH(zlib,     [  --with(out)-zlib       Support gzip compression],[],[with_zlib=yes])
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 if test x$with_zlib = xyes ; then
   AC_CHECK_HEADERS(zlib.h)
diff --git a/src/modules/Image/configure.in b/src/modules/Image/configure.in
index dbbae9f19bf992f435d685d9fd13da189c307dde..8fccaa233b50af0948f4701e54128a62fef588b1 100644
--- a/src/modules/Image/configure.in
+++ b/src/modules/Image/configure.in
@@ -1,10 +1,10 @@
-# $Id: configure.in,v 1.8 1998/03/28 14:48:42 grubba Exp $
+# $Id: configure.in,v 1.9 1998/09/20 08:31:15 hubbe Exp $
 AC_INIT(image.c)
 AC_CONFIG_HEADER(config.h)
 
 AC_SET_MAKE
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_FUNC_MMAP
 
diff --git a/src/modules/Image/encodings/configure.in b/src/modules/Image/encodings/configure.in
index 739e1faa1fb8fbfca78423224341b8accd218345..c1f24fade4edd4eaf2b00f9b8c75ff243d29ac49 100644
--- a/src/modules/Image/encodings/configure.in
+++ b/src/modules/Image/encodings/configure.in
@@ -1,9 +1,9 @@
-# $Id: configure.in,v 1.4 1998/03/28 14:47:34 grubba Exp $
+# $Id: configure.in,v 1.5 1998/09/20 08:31:22 hubbe Exp $
 AC_INIT(gif.c)
 
 AC_SET_MAKE
 
-sinclude(../../module_configure.in)
+AC_MODULE_INIT()
 
 AC_PROG_RANLIB
 AC_SUBST(RANLIB)
diff --git a/src/modules/MIME/configure.in b/src/modules/MIME/configure.in
index 6aed4d1fc68883110d6396f8b07b5d9085ada7db..fa32795d82dcf90c02e5957d1cdc90910f453f50 100644
--- a/src/modules/MIME/configure.in
+++ b/src/modules/MIME/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.3 1998/03/28 14:46:31 grubba Exp $
+# $Id: configure.in,v 1.4 1998/09/20 08:31:29 hubbe Exp $
 AC_INIT(mime.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_C_CHAR_UNSIGNED
 
diff --git a/src/modules/Msql/configure.in b/src/modules/Msql/configure.in
index a265f6f88620f2c522104cc6d562e72d3cc3335a..570d887513b1eb893c8ccc454438c1c95b35299d 100644
--- a/src/modules/Msql/configure.in
+++ b/src/modules/Msql/configure.in
@@ -1,4 +1,4 @@
-dnl $Id: configure.in,v 1.3 1998/07/15 19:03:07 grubba Exp $
+dnl $Id: configure.in,v 1.4 1998/09/20 08:31:37 hubbe Exp $
 dnl (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
 
 AC_INIT(msqlmod.c)
@@ -9,7 +9,7 @@ AC_ARG_WITH(msql,    [  --with(out)-msql      mSQL Database engine support ],[]
 
 echo "Configuring msql module, (C) 1996,1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>"
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 dnl set up "reasonable" search paths
 pike_msql_reasonable_prefixes="/usr/local /usr /opt"
diff --git a/src/modules/Mysql/configure.in b/src/modules/Mysql/configure.in
index 99c2eee07599d56caa3fdf5318fa45ac431fa419..5f95e0af28d95bc3c6f20a712721cfe1bf7c8705 100644
--- a/src/modules/Mysql/configure.in
+++ b/src/modules/Mysql/configure.in
@@ -1,5 +1,5 @@
 #
-# $Id: configure.in,v 1.5 1998/09/01 17:01:04 hubbe Exp $
+# $Id: configure.in,v 1.6 1998/09/20 08:31:46 hubbe Exp $
 #
 # Configure script for the mysql-module
 #
@@ -20,7 +20,7 @@
 AC_INIT(mysql.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 OLD_LIBS=$LIBS
 OLD_LDFLAGS=$LDFLAGS
diff --git a/src/modules/Odbc/configure.in b/src/modules/Odbc/configure.in
index daa9d3073cc571e9d6d556cd7e1c9bb74d7401f0..12296ec412750a2ffaf9e688e163bed034942229 100644
--- a/src/modules/Odbc/configure.in
+++ b/src/modules/Odbc/configure.in
@@ -1,5 +1,5 @@
 #
-# $Id: configure.in,v 1.10 1998/07/13 02:01:40 mast Exp $
+# $Id: configure.in,v 1.11 1998/09/20 08:31:55 hubbe Exp $
 #
 # Configure script for the odbc-module
 #
@@ -9,7 +9,7 @@
 AC_INIT(odbc.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 OLD_LIBS=$LIBS
 OLD_LDFLAGS=$LDFLAGS
diff --git a/src/modules/Oracle/configure.in b/src/modules/Oracle/configure.in
index df1d4dd7dd414ce15a3d2dd630b13ba8c829b397..691145b093dc37eda9a984ecb0147bc5da325124 100755
--- a/src/modules/Oracle/configure.in
+++ b/src/modules/Oracle/configure.in
@@ -1,5 +1,5 @@
 #
-# $Id: configure.in,v 1.11 1998/05/23 23:10:02 grubba Exp $
+# $Id: configure.in,v 1.12 1998/09/20 08:32:03 hubbe Exp $
 #
 # Configure script for the oracle module
 #
@@ -7,7 +7,7 @@
 AC_INIT(oracle.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 ORACLE_LIBS=""
 
diff --git a/src/modules/Pipe/configure.in b/src/modules/Pipe/configure.in
index bf51a9807ead5f50945eca3ae5c24c77894000c3..ae4a007364b0a8fd7d94f438399ca55a60e13728 100644
--- a/src/modules/Pipe/configure.in
+++ b/src/modules/Pipe/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.5 1998/05/17 18:53:28 grubba Exp $
+# $Id: configure.in,v 1.6 1998/09/20 08:32:11 hubbe Exp $
 AC_INIT(pipe.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_HAVE_HEADERS(sys/mman.h linux/mman.h sys/file.h)
 AC_HAVE_FUNCS(mmap munmap geteuid seteuid setresuid madvise)
diff --git a/src/modules/Postgres/configure.in b/src/modules/Postgres/configure.in
index 08c2a8c2375a05614b621402afee470f08e71709..3ee9ef3d08a45030b121e5d579e6205b22f4b4e0 100644
--- a/src/modules/Postgres/configure.in
+++ b/src/modules/Postgres/configure.in
@@ -1,4 +1,4 @@
-dnl $Id: configure.in,v 1.7 1998/08/25 13:11:50 grubba Exp $
+dnl $Id: configure.in,v 1.8 1998/09/20 08:32:20 hubbe Exp $
 dnl (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
 
 AC_INIT(postgres.c)
@@ -16,7 +16,7 @@ AC_ARG_WITH(libpq-dir,
 	[  --with-libpq-dir=dir               look for library-files in dir],
 	[pike_postgres_user_lib_directory=$withval])
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 ac_pike_postgres_skip=no
 
diff --git a/src/modules/Regexp/configure.in b/src/modules/Regexp/configure.in
index 00a5fb4802adbe5f3af2f2cc1a5f482bdcbf8dbc..9dd3089e8feec16d71a252a78409761b99094b6d 100644
--- a/src/modules/Regexp/configure.in
+++ b/src/modules/Regexp/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.5 1998/03/28 14:37:15 grubba Exp $
+# $Id: configure.in,v 1.6 1998/09/20 08:32:28 hubbe Exp $
 AC_INIT(pike_regexp.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_HAVE_HEADERS(string.h)
 dnl
diff --git a/src/modules/Ssleay/configure.in b/src/modules/Ssleay/configure.in
index 66f1735040aa9742d4e8d4c4cb62f56aa9d2595e..3ba09fd86ba3164ad831df0ce396e92d2c638a95 100644
--- a/src/modules/Ssleay/configure.in
+++ b/src/modules/Ssleay/configure.in
@@ -1,9 +1,9 @@
-# $Id: configure.in,v 1.4 1998/03/28 14:33:55 grubba Exp $
+# $Id: configure.in,v 1.5 1998/09/20 08:32:36 hubbe Exp $
 AC_INIT(ssleay.c)
 
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_ARG_WITH(ssleay,  [  --with-ssleay       enable the ssleay-module],[],[with_ssleay=no])
 
diff --git a/src/modules/Yp/configure.in b/src/modules/Yp/configure.in
index 48f77797b53ece4e36fa73ad58206a3030f0b1c9..d93e49a98576bd7788a4243a294c495da8a4f538 100644
--- a/src/modules/Yp/configure.in
+++ b/src/modules/Yp/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.7 1998/08/08 20:28:50 grubba Exp $
+# $Id: configure.in,v 1.8 1998/09/20 08:32:45 hubbe Exp $
 AC_INIT(yp.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_CHECK_LIB(nsl, gethostbyname)
 
diff --git a/src/modules/_Crypto/configure.in b/src/modules/_Crypto/configure.in
index 15acbc837628dfd69f61cb8d66533a7982f05412..0ad5279dde5380334acd4b354fdd69dbfaf9288c 100755
--- a/src/modules/_Crypto/configure.in
+++ b/src/modules/_Crypto/configure.in
@@ -1,9 +1,9 @@
-# $Id: configure.in,v 1.5 1998/03/28 14:28:56 grubba Exp $
+# $Id: configure.in,v 1.6 1998/09/20 08:32:53 hubbe Exp $
 AC_INIT(crypto.c)
 
 AC_SET_MAKE
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_CONFIG_SUBDIRS(lib)
 
diff --git a/src/modules/_Image_JPEG/configure.in b/src/modules/_Image_JPEG/configure.in
index 2d5a5c502b3548aa43d00e0840fe9ad20e528a28..694914cac9344936e502809049dcec25fa062953 100644
--- a/src/modules/_Image_JPEG/configure.in
+++ b/src/modules/_Image_JPEG/configure.in
@@ -1,11 +1,11 @@
 #
-# $Id: configure.in,v 1.3 1998/03/28 13:44:57 grubba Exp $
+# $Id: configure.in,v 1.4 1998/09/20 08:33:00 hubbe Exp $
 #
 AC_INIT(image_jpeg.c)
 AC_CONFIG_HEADER(config.h)
 AC_ARG_WITH(jpeglib,     [  --with(out)-jpeglib       Support JPEG (Image.JPEG)],[],[with_jpeglib=yes])
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 if test x$with_jpeglib = xyes ; then
   AC_CHECK_HEADERS(jpeglib.h)
diff --git a/src/modules/_Image_XFace/configure.in b/src/modules/_Image_XFace/configure.in
index 4c0910b87d13ea7e9670dcffd3b2f70fe30ccf4c..076ba28010ff53247f28e12c9d2c0419776a40da 100755
--- a/src/modules/_Image_XFace/configure.in
+++ b/src/modules/_Image_XFace/configure.in
@@ -1,9 +1,9 @@
-# $Id: configure.in,v 1.2 1998/03/28 14:54:37 grubba Exp $
+# $Id: configure.in,v 1.3 1998/09/20 08:33:08 hubbe Exp $
 AC_INIT(image_xface.c)
 AC_CONFIG_HEADER(config.h)
 AC_ARG_WITH(gmp,     [  --with(out)-gmp        Support bignums],[],[with_gmp=yes])
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 if test x$with_gmp = xyes ; then
   AC_CHECK_HEADERS(gmp.h)
diff --git a/src/modules/call_out/configure.in b/src/modules/call_out/configure.in
index ac84937bd9e0691de748760befa370d0dd6ff487..dd92e0762b98b9cd0873c7424abcf2cc417bb0b0 100644
--- a/src/modules/call_out/configure.in
+++ b/src/modules/call_out/configure.in
@@ -1,7 +1,7 @@
-# $Id: configure.in,v 1.5 1998/03/28 14:01:02 grubba Exp $
+# $Id: configure.in,v 1.6 1998/09/20 08:33:16 hubbe Exp $
 AC_INIT(call_out.c)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_HAVE_HEADERS(sys/time.h)
 
diff --git a/src/modules/dynamic_module_makefile.in b/src/modules/dynamic_module_makefile.in
index 90b3d0006cddd0343de2e329964d6823d3e1007c..4033c7795f60f1738c2f5e2b3577e861f984de4a 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.43 1998/08/02 11:53:50 grubba Exp $
+# $Id: dynamic_module_makefile.in,v 1.44 1998/09/20 08:30:42 hubbe Exp $
 #
 
 
@@ -8,7 +8,12 @@ CPP=@CPP@
 AR=@AR@
 LIBGCC=@LIBGCC@
 
-PREFLAGS=-I. -I$(SRCDIR) -I$(SRCDIR)/../.. -I../.. -I. $(MODULE_CPPFLAGS) $(DEFINES) -DDYNAMIC_MODULE
+PIKE_SRC_DIR=$(SRCDIR)/../..
+BUILD_BASE=../..
+MODULE_BASE=..
+PIKE_INCLUDES=-I$(PIKE_SRC_DIR) -I$(BUILD_BASE)
+
+PREFLAGS=-I. -I$(SRCDIR) $(PIKE_INCLUDES) -I. $(MODULE_CPPFLAGS) $(DEFINES) -DDYNAMIC_MODULE
 CFLAGS=$(PREFLAGS) $(OTHERFLAGS) @CCSHARED@ $(MODULE_CFLAGS)
 
 MAKE_FLAGS = "prefix=$(prefix)" "exec_prefix=$(exec_prefix)" "CC=$(CC) @CCSHARED@" "OTHERFLAGS=$(OTHERFLAGS)" "TMP_BINDIR=$(TMP_BINDIR)" "DEFINES=$(DEFINES)" "TMP_LIBDIR=$(TMP_LIBDIR)" "RUNPIKE=$(RUNPIKE)" "INSTALL=$(INSTALL)" "AR=$(AR)" $(MODULE_MAKE_FLAGS)
@@ -33,14 +38,14 @@ modlist_headers: Makefile
 modlist_segment: Makefile
 	echo "" >modlist_segment
 
-Makefile: ../dynamic_module_makefile $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies config.status
+Makefile: $(MODULE_BASE)/dynamic_module_makefile $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies config.status
 	CONFIG_FILES=Makefile CONFIG_HEADERS="" ./config.status
 	touch remake
 	@echo "Run make again"
 	@exit 1
 
-$(SRCDIR)/configure: $(SRCDIR)/configure.in $(SRCDIR)/../module_configure.in
-	cd $(SRCDIR) && autoconf
+$(SRCDIR)/configure: $(SRCDIR)/configure.in $(PIKE_SRC_DIR)/aclocal.m4
+	cd $(SRCDIR) && autoconf --localdir=$(PIKE_SRC_DIR)
 	if [ -f $(SRCDIR)/acconfig.h ]; then \
 	  cd $(SRCDIR) && autoheader; \
 	else :; fi
@@ -58,7 +63,11 @@ clean:
 
 
 depend:
-	gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR)
+	gcc -MM $(PREFLAGS) $(SRCDIR)/*.c \
+	|sed -e "s@ $(PIKE_SRC_DIR)/\([-a-zA-Z0-9.,_]*\)@ \$$(PIKE_SRC_DIR)/\1@g" \
+	|sed -e "s@ $(SRCDIR)/\([-a-zA-Z0-9.,_]*\)@ \$$(SRCDIR)/\1@g" \
+	|sed -e "s@ $(BUILD_BASE)/\([-a-zA-Z0-9.,_]*\)@ \$$(BUILD_BASE)/\1@g" \
+	>$(SRCDIR)/dependencies
 	for a in '' $(MODULE_SUBDIRS) ; do if test "x$$a" = "x"; then :; else echo making depend in $$a ; ( cd $$a ; $(MAKE) $(MAKE_FLAGS) depend ) ; fi ; done
 
 #verify / debug
diff --git a/src/modules/files/configure.in b/src/modules/files/configure.in
index 45156da374ec4656426969238e9d5ec8e481dfe8..538e5a6811e015a3eed472b0c2e8dae4dc727b3f 100644
--- a/src/modules/files/configure.in
+++ b/src/modules/files/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.58 1998/08/07 00:21:33 grubba Exp $
+# $Id: configure.in,v 1.59 1998/09/20 08:33:25 hubbe Exp $
 AC_INIT(file.c)
 AC_CONFIG_HEADER(file_machine.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_HAVE_HEADERS(sys/types.h arpa/inet.h sys/socketvar.h netinet/in.h \
  sys/mount.h ustat.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/param.h \
diff --git a/src/modules/math/configure.in b/src/modules/math/configure.in
index 82d9a86c44b887cd64004c8fa273daa1de2713f7..da42d743c1a7df6da052471f837aeb5893418f25 100644
--- a/src/modules/math/configure.in
+++ b/src/modules/math/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.6 1998/07/23 00:13:12 hubbe Exp $
+# $Id: configure.in,v 1.7 1998/09/20 08:33:34 hubbe Exp $
 AC_INIT(math.c)
 
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_CHECK_LIB(m, floor)
 if test "${ac_cv_lib_m}" = "no" -a "${pike_cv_sys_os}" = "Linux"; then
diff --git a/src/modules/readline/configure.in b/src/modules/readline/configure.in
index b261ddc11effab7592383fe53d56ab753403316f..3f50a2174310a9a3740f2bdee65d02ec463dbd3d 100644
--- a/src/modules/readline/configure.in
+++ b/src/modules/readline/configure.in
@@ -1,9 +1,9 @@
-# $Id: configure.in,v 1.3 1998/08/02 19:20:22 grubba Exp $
+# $Id: configure.in,v 1.4 1998/09/20 08:33:42 hubbe Exp $
 AC_INIT(readlinemod.c)
 AC_CONFIG_HEADER(readline_machine.h)
 AC_ARG_WITH(readline,[  --with(out)-readline   support command line editing],[],[with_readline=yes])
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 if test x$with_readline = xyes ; then
   AC_MSG_CHECKING(Checking for GNU directory)
diff --git a/src/modules/spider/configure.in b/src/modules/spider/configure.in
index 847767dadb6024a01ac57686df26ce5035248468..596e36051e55cdb79f2a8a4239e757fba4ddb7ef 100644
--- a/src/modules/spider/configure.in
+++ b/src/modules/spider/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.23 1998/03/28 13:52:29 grubba Exp $
+# $Id: configure.in,v 1.24 1998/09/20 08:33:50 hubbe Exp $
 AC_INIT(spider.c)
 AC_CONFIG_HEADER(config.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_ARG_WITH(streamed_parser, [ --with-streamed-parser	Enable the streamed-parser module.], [AC_DEFINE(ENABLE_STREAMED_PARSER)], [])
 
diff --git a/src/modules/sprintf/configure.in b/src/modules/sprintf/configure.in
index 73f335cab1ef4197c022ed335de6a652501aa14f..0d86e80d468e50ef7117241563c7d9c25bc4be65 100644
--- a/src/modules/sprintf/configure.in
+++ b/src/modules/sprintf/configure.in
@@ -1,7 +1,7 @@
-# $Id: configure.in,v 1.4 1998/03/28 13:48:43 grubba Exp $
+# $Id: configure.in,v 1.5 1998/09/20 08:33:58 hubbe Exp $
 AC_INIT(sprintf.c)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_OUTPUT(Makefile,echo FOO >stamp-h )
 
diff --git a/src/modules/static_module_makefile.in b/src/modules/static_module_makefile.in
index c8c97652e52aa3329812964e3a401a97bfd80eeb..015b932317d622978b4aa35dba3789b5f74cb95f 100644
--- a/src/modules/static_module_makefile.in
+++ b/src/modules/static_module_makefile.in
@@ -1,11 +1,12 @@
 #
-# $Id: static_module_makefile.in,v 1.36 1998/08/02 11:53:28 grubba Exp $
+# $Id: static_module_makefile.in,v 1.37 1998/09/20 08:30:42 hubbe Exp $
 #
 
 
 CC=@CC@
 CPP=@CPP@
 AR=@AR@
+PIKE_SRC_DIR=$(SRCDIR)/../..
 
 PREFLAGS=-I. -I$(SRCDIR) -I$(SRCDIR)/../.. -I../.. -I. -Dpike_module_init=pike_module_$(MODNAME)_init -Dpike_module_exit=pike_module_$(MODNAME)_exit $(MODULE_CPPFLAGS) $(DEFINES) 
 CFLAGS=$(PREFLAGS) $(OTHERFLAGS) $(MODULE_CFLAGS)
@@ -49,8 +50,8 @@ Makefile: ../static_module_makefile $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies
 	@echo "Run make again"
 	@exit 1
 
-$(SRCDIR)/configure: $(SRCDIR)/configure.in $(SRCDIR)/../module_configure.in
-	cd $(SRCDIR) && autoconf
+$(SRCDIR)/configure: $(SRCDIR)/configure.in $(PIKE_SRC_DIR)/aclocal.m4
+	cd $(SRCDIR) && autoconf --localdir=$(PIKE_SRC_DIR)
 	if [ -f $(SRCDIR)/acconfig.h ]; then \
 	  cd $(SRCDIR) && autoheader; \
 	else :; fi
diff --git a/src/modules/system/configure.in b/src/modules/system/configure.in
index b5b28552cbfd93d3413c177d46f0c96fd90a7328..d7c9c8793b44a10a766be3487519abb9dc7f6d82 100644
--- a/src/modules/system/configure.in
+++ b/src/modules/system/configure.in
@@ -1,8 +1,8 @@
-# $Id: configure.in,v 1.27 1998/08/04 23:25:35 grubba Exp $
+# $Id: configure.in,v 1.28 1998/09/20 08:34:06 hubbe Exp $
 AC_INIT(system.c)
 AC_CONFIG_HEADER(system_machine.h)
 
-sinclude(../module_configure.in)
+AC_MODULE_INIT()
 
 AC_CHECK_LIB(bind, __inet_ntoa)
 AC_CHECK_LIB(socket, socket)
diff --git a/src/pike-module.in b/src/pike-module.in
new file mode 100644
index 0000000000000000000000000000000000000000..8fc99459d20247d0bb08874de568304bccc6bc52
--- /dev/null
+++ b/src/pike-module.in
@@ -0,0 +1,221 @@
+#!¤pike¤
+
+// Source directory
+string srcdir;
+string prefix="¤prefix¤";
+string lib_prefix="¤lib_prefix¤";
+string share_prefix="¤share_prefix¤";
+string make="¤make¤";
+string make_flags="¤make_flags¤";
+string include_path="¤include_path¤";
+string configure_command="configure";
+
+
+#define NOT 0
+#define AUTO 1
+#define ALWAYS 2
+
+mapping(string:int) run=
+([
+  "automake":AUTO,
+  "autoheader":AUTO,
+  "autoconf":AUTO,
+  "configure":AUTO,
+  "make":AUTO,
+  ]);
+
+string fix(string path)
+{
+  if(search(path,"$src")==-1) return path;
+  if(!srcdir)
+  {
+    string s=Stdio.read_file("Makefile");
+    if(s)
+    {
+      sscanf(s,"%*s\nSRCDIR=%s\n",srcdir);
+    }
+    if(!srcdir && file_stat("configure.in"))
+    {
+      srcdir=".";
+    }
+    
+    if(!srcdir)
+    {
+      werror("You must provide --source=<source dir>\n");
+      exit(1);
+    }
+  }
+  return replace(path,"$src",srcdir);
+}
+
+void do_zero()
+{
+  foreach(indices(run), string x) if(run[x]==1) m_delete(run,x);
+}
+
+int max_time_of_files(string ... a)
+{
+  int t=0;
+  foreach(a,string file)
+    {
+      mixed s=file_stat(fix(file));
+      if(!s) return 0;
+      t=max(t,s[3]);
+    }
+  return t;
+}
+
+
+int just_run(mapping options, string ... cmd)
+{
+  werror(" %s\n",cmd*" ");
+  return Process.create_process(cmd,options)->wait();
+}
+
+void run_or_fail(mapping options,string ... cmd)
+{
+  werror(" %s\n",cmd*" ");
+  int ret=Process.create_process(cmd,options)->wait();
+  if(ret)
+    exit(ret);
+}
+
+
+int main(int argc, string *argv)
+{
+  foreach(Getopt.find_all_options(argv,aggregate(
+    ({"fixate",Getopt.NO_ARG,({"--fixate"}) }),
+    ({"set",Getopt.NO_ARG,({"--set"}) }),
+    ({"output",Getopt.NO_ARG,({"--output"}) }),
+    ({"autoconf",Getopt.NO_ARG,({"--autoconf"}) }),
+    ({"configure",Getopt.NO_ARG,({"--configure"}) }),
+    ({"autoheader",Getopt.NO_ARG,({"--autoheader"}) }),
+    ({"automake",Getopt.NO_ARG,({"--automake"}) }),
+    ({"all",Getopt.NO_ARG,({"--all"}) }),
+    ({"make",Getopt.NO_ARG,({"--make"}) }),
+    ({"auto",Getopt.NO_ARG,({"--auto"}) }),
+    ({"source",Getopt.HAS_ARG,({"--source"}) }),
+    )),array opt)
+    {
+      switch(opt[0])
+      {
+	case "fixate":
+	  string file=Stdio.read_file(opt[1]);
+	  break;
+	case "set":
+	  if(sscanf(opt[1],"%s=%s",string var, string value))
+	  {
+	    file=replace(file,"¤"+var+"¤",
+			 replace(value,"\"","\\\""));
+	  }
+	  break;
+	  
+	case "output":
+	  rm(opt[1]);
+	  Stdio.write_file(opt[1],file);
+	  exit(0);
+	  
+	case "source": srcdir=opt[1]; break;
+	case "automake": run->automake=ALWAYS; do_zero(); break;
+	case "autoheader": run->autoheader=ALWAYS; do_zero(); break;
+	case "autoconf": run->autoconf=ALWAYS; do_zero(); break;
+	case "configure": run->configure=ALWAYS; do_zero(); break;
+	case "make": run->make=ALWAYS; do_zero(); break;
+	  
+	case "all": 
+	  run->autoheader=run->autoconf=run->configure=run->make-ALWAYS;
+	  break;
+	  
+	case "auto":
+	  run->autoheader=run->autoconf=run->configure=run->make=1;
+	  break;
+      }
+    }
+
+  argv=Getopt.get_args(argv);
+  
+  int tmp1;
+  if(run->automake)
+  {
+    if(tmp1=max_time_of_files("$src/Makefile.am","$src/configure.in"))
+    {
+      if(run->automake == ALWAYS ||
+	 max_time_of_files("$src/Makefile.in") < tmp1)
+      {
+	run_or_fail((["dir":srcdir]),"aclocal");
+	run_or_fail((["dir":srcdir]),"automake");
+	rm(fix("$src/stamp-h.in"));
+      }
+    }
+  }
+
+  if(run->autoheader)
+  {
+    if(tmp1=max_time_of_files("$src/acconfig.h","$src/configure.in"))
+    {
+      if(run->autoheader==ALWAYS ||
+	 max_time_of_files("$src/stamp-h.in") <= tmp1)
+      {
+	run_or_fail((["dir":srcdir]),"autoheader");
+	rm(fix("$src/stamp-h.in"));
+	Stdio.write_file(fix("$src/stamp-h.in"),"foo\n");
+      }
+    }
+  }
+
+  if(run->autoconf)
+  {
+    if(tmp1=max_time_of_files("$src/configure.in"))
+    {
+      if(run->autoconf==ALWAYS ||
+	 max_time_of_files("$src/configure") <= tmp1)
+      {
+	run_or_fail((["dir":srcdir]),"autoconf","--localdir="+include_path);
+      }
+    }
+  }
+
+  if(run->configure)
+  {
+    // If there is a makefile, we can use the auto-run-configure
+    // feature...
+    if(run->configure == ALWAYS || !max_time_of_files("Makefile"))
+    {
+      if(max_time_of_files("$src/configure"))
+      {
+	if(!max_time_of_files("config.cache") &&
+	   max_time_of_files(include_path+"/config.cache"))
+	{
+	  Stdio.cp(include_path+"/config.cache","config.cache");
+	}
+	run_or_fail(([]),srcdir+"/"+configure_command);
+      }
+    }
+  }
+
+  if(run->make)
+  {
+    string *makecmd=({make})+
+      Process.split_quoted_string(make_flags)-({""})+
+	({"PIKE_INCLUDES=-I"+include_path,
+	    "PIKE_SRC_DIR="+include_path,
+	    "BUILD_BASE="+include_path,
+	    "MODULE_BASE="+include_path,
+	    })+
+	argv[1..];
+    if(tmp1=max_time_of_files("Makefile"))
+    {
+      rm("remake");
+      tmp1=just_run(([]),@makecmd);
+      if(tmp1)
+      {
+	if(max_time_of_files("remake"))
+	{
+	  run_or_fail(([]),@makecmd);
+	}else{
+	  exit(tmp1);
+	}
+      }
+    }
+  }
+}
diff --git a/src/run_autoconfig b/src/run_autoconfig
index d74107cf8c05c3309a9000b350cc2e348dc8b8b5..52bd3bd464751f788c9c468209c9227452adc915 100755
--- a/src/run_autoconfig
+++ b/src/run_autoconfig
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $Id: run_autoconfig,v 1.22 1998/04/03 14:00:10 grubba Exp $
+# $Id: run_autoconfig,v 1.23 1998/09/20 08:30:32 hubbe Exp $
 #
 # Bootstrap script
 
@@ -15,14 +15,16 @@ else
   cd "$1"
 fi
 
+localdir=`pwd`
+
 find . -type d -print|egrep -v '/(CVS)|(RCS)$'| while read dir; do
 
   if [ -f $dir/Makefile.am -a -f $dir/configure.in ]; then
     # aclocal needs to be run before autoconf
     echo "Running aclocal in $dir"
-    (cd $dir ; aclocal)
+    (cd $dir ; aclocal )
     echo "Running automake in $dir"
-    (cd $dir ; automake)
+    (cd $dir ; automake )
   fi
 
   if [ -f $dir/acconfig.h -a $dir/configure.in ]; then
@@ -33,7 +35,7 @@ find . -type d -print|egrep -v '/(CVS)|(RCS)$'| while read dir; do
   if [ -f $dir/configure.in ]; then
     if grep AC_INIT $dir/configure.in >/dev/null; then
       echo "Running autoconf in $dir"
-      ( cd $dir ; autoconf )
+      ( cd $dir ; autoconf --localdir=$localdir )
     else
       echo "$dir seems to use Cygnus-configure."
     fi