Interestingly enough, when I configure 4.0.16 like this it builds ok:
./configure --prefix=/usr/local --sysconfdir=/ --enable-shared
--with-server-suffix=-imax-G5 --with-mysqld-user=mysql --with-comment
--with-query-cache --without-docs --with-innodb
--enable-thread-safe-client --with-bench -
source='sort.c' object='sort.o' libtool=no \
depfile='.deps/sort.Po' tmpdepfile='.deps/sort.TPo' \
depmode=gcc3 /bin/sh ../depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I.. -I./../include -I../include -O3
-DDBUG_OFF -c `test -f sort.c || echo './'`sort.c
/bin/sh ../libtool --mode=link gcc -O3 -DDB