#!/bin/bash
#
# properly clean source tree, configure and recompile dosemu
# (this is here just for developer's convenience, not for general usage)
#
# USAGE:
#
#   rebuild [all] [inst] [static]
#
#      all    force a complete rebuild, don't rely on previous make
#      inst   test install of the binary (if running root) suid-root in $TGT
#      static build portable static binaries
#
#
TGT=/usr/bin
#

ALL=0
INST=0
PORTABLE=0

while [ -n "$1" ]; do
  case $1 in
    all)   ALL=1 ;;
    inst)  INST=1 ;;
    static) PORTABLE=1 ;;
    *) ;;
  esac
  shift
done

if [ $ALL = 1 -o ! -f Makefile ]; then
  if [ -f Makefile.conf ]; then
    make distclean
  fi
fi
if [ $PORTABLE = 1 -a ! -f Makefile.conf ]; then
  ./default-configure --enable-linkstatic
fi

make 'WAIT=' 2>&1 | tee -a gen.log
# grep 'warning' gen.log

if [ "$UID" = "0" -a $INST = 1 ]; then
  #
  # special installs
  #
  rm -f ${TGT}/dos
  install -s -m 4755 bin/dosemu.bin ${TGT}/dos
  install -s -m 4755 bin/dosdebug ${TGT}
fi
sync
