diff --git a/ChangeLog b/ChangeLog
index d257ca8167db88345b4a3504093085dd88d39488..dcea21662bd643fccb95360556cc0a265a7c7d9f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2004-10-21  Niels Möller  <niels@s3.kth.se>
+
+	* examples/Makefile.in: Deleted all configure-related rules,
+	except the one rebuilding this Makefile. Run make at top level if
+	other configure related files change.
+	* tools/Makefile.in: Likewise.
+	* testsuite/Makefile.in: Likewise.
+
+	* configure.ac: Replaced AC_OUTPUT(list...) with an AC_OUTPUT
+	without arguments, and AC_CONFIG_FILES listing the files.
+
+	* Makefile.in: Changed the assembler rules as suffix rules.
+	Rewrote the configure-related rules, mostly based on the example
+	in the autoconf manual.
+
 2004-10-20  Niels Möller  <nisse@lysator.liu.se>
 
 	* examples/nettle-openssl.c (NCOMPAT): Disable openssl backwards
diff --git a/Makefile.in b/Makefile.in
index aa730e378a742584d59e8882fcf9e762a43ccb8f..39d8f67a36d02514786ac6192e64973b0ac84e4b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -96,7 +96,8 @@ INSTALL_HEADERS = $(HEADERS) nettle-types.h
 
 SOURCES = $(nettle_SOURCES) aesdata.c desdata.c shadata.c
 
-DISTFILES = $(SOURCES) $(HEADERS) .bootstrap aclocal.m4 configure.ac configure \
+DISTFILES = $(SOURCES) $(HEADERS) .bootstrap aclocal.m4 configure.ac \
+	configure stamp-h.in \
 	config.guess config.sub install-sh texinfo.tex \
 	config.h.in config.m4.in config.make.in	Makefile.in \
 	README AUTHORS COPYING INSTALL NEWS TODO ChangeLog \
@@ -158,24 +159,17 @@ $(des_headers): desdata.c
 
 des.o: des.c des.h $(des_headers)
 
-# FIXME: For some reason, this rule breaks builds on Tru64 5.1B (on
-# alpha), with the system make. It fails with "Don't know how to make
-# aes.asm", which is very strange, since the make program on this
-# system is not supposed to know about %-style pattern rules, and
-# "aes.asm" doesn't occur explicitly in any target or dependency.
-
-@IF_ENABLE_ASM@%.$(OBJEXT): %.asm asm.m4 machine.m4 config.m4
-@IF_ENABLE_ASM@	$(M4) $(srcdir)/asm.m4 machine.m4 config.m4 \
-@IF_ENABLE_ASM@		$< >$*.s
-@IF_ENABLE_ASM@	$(CC) $(CFLAGS) $(CCPIC_MAYBE) -c $*.s -o $@
-@IF_ENABLE_ASM@	echo >$*.d 
-
-# All assembler files should use pic-code only.
-@IF_ENABLE_ASM@%.p$(OBJEXT): %.asm asm.m4 machine.m4 config.m4
-@IF_ENABLE_ASM@	$(M4) $(srcdir)/asm.m4 machine.m4 config.m4 \
-@IF_ENABLE_ASM@		$< >$*.s
-@IF_ENABLE_ASM@	$(CC) $(CFLAGS) $(CCPIC) -c $*.s -o $@
-@IF_ENABLE_ASM@	echo >$*.d 
+.asm.$(OBJEXT):
+	$(M4) $(srcdir)/asm.m4 machine.m4 config.m4 \
+		$< >$*.s
+	$(COMPILE) $(CCPIC_MAYBE) -c $*.s
+	echo "$@ : $< $(srcdir)/asm.m4 machine.m4 config.m4" >$@.d 
+
+.asm.p$(OBJEXT):
+	$(M4) $(srcdir)/asm.m4 machine.m4 config.m4 \
+		$< >$*.s
+	$(COMPILE) $(SHLIBCFLAGS) -c $*.s -o $@
+	echo "$@ : $< $(srcdir)/asm.m4 machine.m4 config.m4" >$@.d 
 
 # Texinfo rules
 .texinfo.info:
@@ -183,40 +177,35 @@ des.o: des.c des.h $(des_headers)
 	&& test -s $@T && mv -f $@T $@
 
 .texinfo.html:
-	cd $(srcdir) && $(MAKEINFO) --html --no-split --output $@T `basename $<` \
-	&& test -s $@T && mv -f $@T $@
-
-# Configure-related rules
+	cd $(srcdir) && $(MAKEINFO) --html --no-split \
+	  --output $@T `basename $<` \
+	  && test -s $@T && mv -f $@T $@
 
-.PRECIOUS: Makefile
-Makefile: $(srcdir)/Makefile.in config.status
-	$(SHELL) ./config.status $@
+# Configure-related rules, mostly copied from the autoconf manual. No
+# $(srcdir) prefixes on the targets, though.
 
-config.make: $(srcdir)/config.make.in config.status
-	$(SHELL) ./config.status $@
+configure: configure.ac aclocal.m4
+	cd $(srcdir) && $(AUTOCONF)
 
-config.status: $(srcdir)/configure
-	$(SHELL) ./config.status --recheck
+# autoheader might not change config.h.in, so touch a stamp file.
+config.h.in: stamp-h.in
+stamp-h.in: configure.ac aclocal.m4
+	cd $(srcdir) && autoheader
+	echo timestamp > $(srcdir)/stamp-h.in
 
-config.m4: config.status $(srcdir)/config.m4.in
-	$(SHELL) ./config.status $@
+config.status: configure
+	./config.status --recheck
 
-configure: $(srcdir)/configure.ac $(srcdir)/aclocal.m4
-	cd $(srcdir) && $(AUTOCONF)
+config.h: stamp-h
+stamp-h: config.h.in config.status
+	./config.status config.h
+	echo timestamp > stamp-h
 
-config.h: stamp-h1
-	@if test ! -f $@; then \
-	  rm -f stamp-h1; \
-	  $(MAKE) stamp-h1; \
-	else :; fi
+Makefile: Makefile.in config.status
+	./config.status $@
 
-stamp-h1: $(srcdir)/config.h.in config.status
-	@rm -f stamp-h1
-	$(SHELL) ./config.status config.h
-$(srcdir)/config.h.in: $(srcdir)/configure.ac
-	cd $(srcdir) && $(AUTOHEADER)
-	rm -f stamp-h1
-	touch $@
+config.make: config.make.in config.status
+	./config.status $@
 
 # Installation
 install-here: install-info install-headers libnettle.a $(SHLIBINSTALL)
@@ -331,7 +320,7 @@ clean-here:
 	-rm -f $(TARGETS) *.$(OBJEXT) *.p$(OBJEXT) *.d
 
 distclean-here: clean-here
-	-rm -f config.h stamp-h1 config.log config.status \
+	-rm -f config.h stamp-h config.log config.status \
 	config.make config.m4 Makefile nettle-types.h
 
 -include $(SOURCES:.c=.$(OBJEXT).d) $(SOURCES:.c=.p$(OBJEXT).d)
diff --git a/configure.ac b/configure.ac
index 7ff158ca2a156d16cf5d8fa16c77734f1dc03f76..4dac9083007fb6ac69612a415cfcf8d4455418ee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -240,5 +240,8 @@ if test x$GCC = xyes ; then
 # inttypes.h.
 fi
 
-AC_OUTPUT(Makefile config.make config.m4 tools/Makefile testsuite/Makefile examples/Makefile)
+AC_CONFIG_FILES([config.make config.m4 Makefile])
+AC_CONFIG_FILES([tools/Makefile testsuite/Makefile examples/Makefile])
+
+AC_OUTPUT