#!/bin/sh
for file do
    if test -f $file.SH; then
	mv $file.SH $file.SH.old
    fi

    cat >$file.SH <<BLURFL
case \$CONFIG in
'')
    if test ! -f config.sh; then
	ln ../config.sh . || \\
	ln ../../config.sh . || \\
	ln ../../../config.sh . || \\
	(echo "Can't find config.sh."; exit 1)
    fi
    . config.sh
    ;;
esac
: This forces SH files to create target in same directory as SH file.
: This is so that make depend always knows where to find SH derivatives.
case "\$0" in
*/*) cd \`expr X\$0 : 'X\(.*\)/'\` ;;
esac
echo "Extracting $file (with variable substitutions)"
: This section of the file will have variable substitutions done on it.
: Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
: Protect any dollar signs and backticks that you do not want interpreted
: by putting a backslash in front.  You may delete these comments.
\$spitshell >$file <<!GROK!THIS!
BLURFL

    case `head -1 $file` in
    */bin/sh) echo '$startsh' >>$file.SH ;;
    esac

    cat >>$file.SH <<BLURFL
!GROK!THIS!

: In the following dollars and backticks do not need the extra backslash.
\$spitshell >>$file <<'!NO!SUBS!'
BLURFL

    sed -e '1{' -e '/#!.*\/bin\/sh$/d' -e '}' $file >>$file.SH
    
    cat >>$file.SH <<BLURFL
!NO!SUBS!
chmod 755 $file
\$eunicefix $file
BLURFL
    chmod 755 $file.SH
done
