Makefile: fix "make spotless"

Fix "make spotless" and some of the related targets so they actually
behave sensibly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
diff --git a/Makefile.in b/Makefile.in
index d5028a4..df04898 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -206,7 +206,7 @@
 # have Perl just to recompile NASM from the distribution.
 
 # Perl-generated source files
-PERLREQ = config/unconfig.h \
+PERLREQ_CLEANABLE = \
 	  x86/insnsb.c x86/insnsa.c x86/insnsd.c x86/insnsi.h x86/insnsn.c \
 	  x86/regs.c x86/regs.h x86/regflags.c x86/regdis.c x86/regdis.h \
 	  x86/regvals.c asm/tokhash.c asm/tokens.h asm/pptok.h asm/pptok.c \
@@ -217,10 +217,14 @@
 	  misc/nasmtok.el \
 	  version.h version.mac version.mak nsis/version.nsh
 
+# Special hack to keep config/unconfig.h from getting deleted
+# by "make spotless"...
+PERLREQ = config/unconfig.h $(PERLREQ_CLEANABLE)
+
 INSDEP = x86/insns.dat x86/insns.pl x86/insns-iflags.ph x86/iflags.ph
 
-config/unconfig.h: config/config.h.in
-	$(RUNPERL) $(tools)/unconfig.pl \
+config/unconfig.h: config/config.h.in autoconf/unconfig.pl
+	$(RUNPERL) '$(srcdir)'/autoconf/unconfig.pl \
 		'$(srcdir)' config/config.h.in config/unconfig.h
 
 x86/iflag.c: $(INSDEP)
@@ -293,7 +297,7 @@
 # changed, to avoid rebuilding everything every time. Track the actual
 # dependency by the empty file asm/warnings.time.
 .PHONY: warnings
-warnings:
+warnings: dirs
 	$(RM_F) $(WARNFILES) $(WARNTIMES) asm/warnings.time
 	$(MAKE) asm/warnings.time
 
@@ -362,7 +366,8 @@
 
 #-- End Generated File Rules --#
 
-perlreq: $(PERLREQ)
+perlreq: dirs
+	$(MAKE) $(PERLREQ)
 
 #-- Begin NSIS Rules --#
 
@@ -402,24 +407,26 @@
 	$(RM_F) nsis/arch.nsh
 	$(RM_F) perlbreq.si
 
-distclean: clean
+
+cleaner: clean
+	$(RM_F) $(PERLREQ_CL) *.1 nasm.spec
+	$(MAKE) -C doc clean
+	$(RM_F) *.dep */*.time
+
+distclean: clean | cleaner
 	for d in . $(SUBDIRS) $(XSUBDIRS); do \
 		$(RM_F) "$$d"/.\# "$$d"/\# "$$d"/*~ "$$d"/*.bak \
 			"$$d"/*.lst "$$d"/*.bin ; \
 	done
 	$(RM_F) test/*.$(O)
 	$(RM_F) *.dep
-	$(RM_F) Makefile doc/Makefile config/config.h config.log config.status
+	-sh autoconf/clean.sh || sh '$(srcdir)'/autoconf/clean.sh
 
-cleaner: clean
-	$(RM_F) $(PERLREQ) *.1 nasm.spec
-	$(MAKE) -C doc clean
-	$(RM_F) *.dep */*.time
+# This cleans up files generated by autogen.sh
+autoconf-clean: | distclean
+	$(RM_F) configure autoconf/aclocal.m4 autoconf/clean.sh
 
-makefile-clean:
-	./autogen.sh
-
-spotless: distclean cleaner makefile-clean
+spotless: cleaner distclean autoconf-clean
 
 strip:
 	$(STRIP) --strip-unneeded $(PROGS)
diff --git a/autogen.sh b/autogen.sh
index 91ebbb1..4ed675d 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -65,6 +65,7 @@
     echo 'rm -f config.log config.status'
     echo 'rm -rf autom4te.cache'
 ) > autoconf/clean.sh
+chmod +x autoconf/clean.sh
 sh autoconf/clean.sh
 
 # Try to regenerate unconfig.h if Perl is available and unconfig.pl