#! /bin/sh


# Copyright (C) 2000-2019 The Xastir Group

# See README.sudo for instructions on setting up SUDO for
# Linux/Unix/MacOSX systems, specifically the /etc/sudoers file.


CYGWIN=false
uname=`uname`

case "$uname" in
    CYGWIN*)
        CYGWIN=true
        ;;
    *)
        ;;
esac


(date 2>&1)                               | tee    make.log
(git pull 2>&1)                           | tee -a make.log

echo ""                                   | tee -a make.log
echo ""                                   | tee -a make.log
(date 2>&1)                               | tee -a make.log
(./bootstrap.sh 2>&1)                     | tee -a make.log

echo ""                                   | tee -a make.log
echo ""                                   | tee -a make.log
(date 2>&1)                               | tee -a make.log
(mkdir -p build 2>&1)                     | tee -a make.log

echo ""                                   | tee -a make.log
echo ""                                   | tee -a make.log
(date 2>&1)                               | tee -a make.log
(cd build; ../configure 2>&1)             | tee -a make.log

echo ""                                   | tee -a make.log
echo ""                                   | tee -a make.log
(date 2>&1)                               | tee -a make.log


if $CYGWIN
then
    (echo "************************************") | tee -a make.log
    (echo "Building for Cygwin Operating System") | tee -a make.log
    (echo "************************************") | tee -a make.log
    (cd build; make clean 2>&1)           | tee -a make.log

    echo ""                               | tee -a make.log
    echo ""                               | tee -a make.log
    (date 2>&1)                           | tee -a make.log
    (cd build; make install 2>&1)         | tee -a make.log
#    chmod 4755 /usr/local/bin/xastir
    chmod 755 /usr/local/bin/xastir

    echo ""                               | tee -a make.log
    (date 2>&1)                           | tee -a make.log
else
    (echo "************************************************") | tee -a make.log
    (echo "Building for Unix/Linux/MacOSX Operating Systems") | tee -a make.log
    (echo "************************************************") | tee -a make.log
    (cd build; sudo make clean 2>&1)      | tee -a make.log

    echo ""                               | tee -a make.log
    echo ""                               | tee -a make.log
    (date 2>&1)                           | tee -a make.log 
    (cd build; make 2>&1)                 | tee -a make.log
    (cd build; sudo make install-strip 2>&1)    | tee -a make.log
#    sudo chmod 4755 /usr/local/bin/xastir
    sudo chmod 755 /usr/local/bin/xastir

    echo ""                               | tee -a make.log
    (date 2>&1)                           | tee -a make.log
fi


