Index: /trunk/debbuild
===================================================================
--- /trunk/debbuild	(revision 118)
+++ /trunk/debbuild	(revision 119)
@@ -481,4 +481,20 @@
     next if /^#/ && $stage eq 'preamble';       # Ignore comments...
     next if /^\s*$/ && $stage eq 'preamble';    # ... and blank lines.
+
+# no sense in continuing if we find something we don't grok
+    # Yes, this is really horribly fugly.  But it's a cheap crosscheck against invalid
+    # %-tags which also make rpmbuild barf.  In theory.
+# notes:  some of these are not *entirely* case-sensitive (%ifxxx), but most are.
+    # Extracted from the Maximum RPM online doc via:
+    # grep -h %[a-z] *|perl -e 'while (<>) { /\%([a-z0-9]+)\b/; print "$1|\n"; }'|sort -u
+    if (/^%[a-z]/ &&
+		$_ !~ /^%(?:attr|build|check|clean|config|configure|defattr|define|description|
+		dir|doc|docdir|else|endif|files|ghost|if|ifarch|ifn|ifnarch|ifnos|ifnxxx|fos|ifxxx|
+		install|package|patch|post|postun|pre|prep|preun|readme|setup|
+		triggerin|triggerpostun|triggerun|verify|verifyscript)\b/x
+	) {
+	my ($badtag) = (/^%([a-z]+)/i);
+	die "Unknown tag \%$badtag at line $. of $specfile\n";
+    }
 
 # preprocess %define's
