#
# strip-exec: Try to build the smallest executable possible from the current
# source.
#

#
# Slack 3.4 standard gcc -- change if you need to, but gcc 2.7.2.3 typically
# generates much smaller code than egcs/pgcc
#
CC="gcc -V2.7.2.3 -bi486-unknown-linux-gnulibc1"
CFLAGS="-O2 -fomit-frame-pointer -m486"
SECTIONS=".note.ABI-tag .gnu.version .rel.got .fini .dtors .comment .note"
EXEC=betaftpd

rm -f *.s

#
# Compile
#
make distclean
CC="$CC" CFLAGS="$CFLAGS" ./configure --disable-xferlog --disable-fullscreen --disable-upload --disable-shadow --disable-fork
make assembly-files

#
# -malign-* doesn't remove _all_ .align occurrences :-)
#
for FILE in *.s; do
	echo "Removing alignment from $FILE..."
	grep -v .align < $FILE > `basename $FILE .s`2.s
	mv `basename $FILE .s`2.s $FILE
done

make betaftpd-from-assembly-files
strip --strip-all $EXEC

for SECTION in $SECTIONS; do
	echo Stripping $SECTION...
	strip --remove-section=$SECTION $EXEC
done

upx --best betaftpd
ls -l betaftpd

