#!/bin/sh

./configure --host=arm-uclinux \
	--sysconfdir=/etc/ssh \
	--prefix= \
        --disable-largefile \
	--with-zlib=../zlib \
	--with-ssl-dir=../openssl \
	--with-libs=-lcrypt \
	--with-libs=-lpwdgrp \
	--with-libs=-lbb \
	--with-cflags="-msoft-float -march=armv5 -mtune=arm926ejs" \
	--with-ldflags="-msoft-float -march=armv5 -mtune=arm926ejs -elf2flt=elf2flt_temp -L../busybox-1.00/libpwdgrp -L../busybox-1.00/libbb"

makefiles=`find . -name "Makefile"`

for makefile in $makefiles ; do
    echo -n "Fixing $makefile..."
    cp $makefile $makefile.bak
    
    dotdot=
    
#one extra directories up
    test=`echo $makefile|grep "./.*/Makefile"`
    if [ "$test" != "" ] ; then
	dotdot=..\\/
    fi
    
#two extra directories up
    test=`echo $makefile|grep "./.*/.*/Makefile"`
    if [ "$test" != "" ] ; then
	dotdot=..\\/..\\/
    fi

    cat $makefile | sed -e "s/-O2/-Os/g" | sed -e "s/arm-uclinux-ld/arm-uclinux-gcc/g" \
	| sed -e "s/ -I\/.*linux-tools\/openssh\// -I$dotdot/g" \
	| sed -e "s/ -L\/.*linux-tools\/openssh\// -L$dotdot/g" \
	| sed -e "s/-lresolv -lresolv/-lresolv -lcrypt -lpwdgrp -lbb/g" \
	| sed -e "s/elf2flt_temp/\'-z -s 8000\'/g" > $makefile.sed
    cp $makefile.sed $makefile
    echo "done"
done
