Hi,
compiling XEmacs-21.5.19 on Sun (solaris 5.8),
I get this error when gnumaking:
--------------------------------------------------
Dumping under the name xemacs
if test -f dump-size; then \
	../lib-src/insert-data-in-exec temacs xemacs.dmp xemacs ` ./temacs -si`; \
	ret=$? ; \
	if test ${ret} -eq 2; then \
		rm -f dump-size ; \
	else \
		if test ${ret} -eq 1; then \
			exit 1; \
		else \
			chmod +x xemacs ; \
		fi ; \
	fi ; \
fi
dumped_data found at offset 0x45c208, patching.
dumped_data found at offset 0x45c208, patching.
if ! test -f dump-size; then \
	../lib-src/insert-data-in-exec -s xemacs.dmp > dump-size ; \
	rm -f dump-data.o xemacs xemacs.dmp temacs;\
	gnumake  xemacs; \
fi
/bin/sh: !: not found
--------------------------------------------------
And then compilation goes on to completion....
I did set 
CONFIG_SHELL=/usr/xpg4/bin/sh
in my environment before configuring.
I found that changing
SHELL=/bin/sh
to
SHELL=/usr/xpg4/bin/sh
in src/GNUmakefile
removes the error.
It seems to me that
SHELL=/bin/sh
is hard coded in the Makefile.in.in files,
and triggers the same kind of problem as for 
the configure script.
I can provide more info if needed,
Sylvain Mazet.