#!/bin/sh
#
# this is a build script under Win95 w/LFN=y
#

# default variables
CC=gcc
CFLAGS="-g -O2"
RM=rm

# install check for multibyte library
if [ -f "$DJDIR/include/mbstring.h" ]; then
  MB_CFLAGS=-DUSE_MULTIBYTE
  MB_LIBS=-lmb
else
  MB_CFLAGS=
  MB_LIBS=
fi
CFLAGS="$CFLAGS $MB_CFLAGS"

# compile local patched library
LOCAL_SRCS="conio.c fixpath.c readdir.c lfnshort.c tcsetatr.c tminit.c"
LOCAL_LIBS=`echo $LOCAL_SRCS | sed -e 's/\.c/\.o/g'`
LOCAL_LIBS="$LOCAL_LIBS $MB_LIBS"
remove_bash=no
for file in $LOCAL_SRCS
do
  if [ ! -f "${file%.c}.o" -o "$file" -nt "${file%.c}.o" ]; then
    echo "Now compiling $file"
    args="$CC $CFLAGS -c \"$file\""
    echo $args; eval $args || exit 1
    remove_bash=yes
  fi
done
if [ "$remove_bash" = "yes" ]; then
  # remove for linking new object(s).
  $RM -f bash
fi

# build bash.exe
make CC=$CC CFLAGS=$CFLAGS CPPNAME='$(CC) -E' LOCAL_LIBS=$LOCAL_LIBS \
$*
status=$?

if [ $status = 0 ]; then
  stubedit bash.exe minstack=1M
fi

exit $status
