#!/bin/bash
#------------------------------------------------------------------------------
##
# \file        qbuild
# \library     bin
# \author      Chris Ahlstrom
# \date        2020-09-27 to 2023-12-24
# \version     $Revision$
# \license     GNU GPLv2 or above
#
# This script runs qmake and make, and should be run from a Qt shadow
# directory.  Look at the Bash variables below and make any changes needed for
# your setup.
#
#------------------------------------------------------------------------------

BUILDTYPE="release"
ENGINE=""
DOBUILD="yes"
QMAKER="qmake"
MAKER="make"
MAKEOPTIONS="-j 8"
MAKELOG="make.log"
QOPTIONS="-makefile -recursive -Wall"
PROJFILE="../seq66/seq66.pro"

#******************************************************************************
#  Help
#------------------------------------------------------------------------------

if [ "$1" == "--help" ] ; then

   cat << E_O_F
The qbuild script makes it easier to remember how to build Qt shadow builds for
Seq66, to generate either qpseq66 (portmidi) or qseq66 (rtmidi).  The default
is to build 'qpseq66' for release.  The build can be modified by adding the
flags 'debug' and 'rtmidi'.

    cd ..                     (parent directory of seq66)
    mkdir shadow-rtmidi       (if not already made)
    cd shadow
    rm -rf *                  (removed old junk; CAREFUL!)
    qbuild debug rtmidi
    vi make.log

This must be run from a shadow directory.  The build output is written to
make.log.  Other options are '--help' and '--dry-run'.  Please note that this
script is Bash-specific and *deprecated*. Use the qbuild.sh script instead.
E_O_F
   exit 1
fi

if [ $# -ge 1 ] ; then

   while [ "$1" != "" ] ; do

      case "$1" in

         dry | --dry-run)
            DOBUILD="no"
            ;;

         debug | --debug)
            BUILDTYPE="debug"
            ;;

         rtmidi | rt | --rtmidi)
            ENGINE="rtmidi"
            ;;

         *)
            echo "? Unsupported qbuild option; --help for more information"
            exit 1
            ;;

      esac
      shift
   done

fi

if [ "$DOBUILD" == "yes" ] ; then
   rm -f $MAKELOG
   date > $MAKELOG
   echo " " &>> $MAKELOG
   echo "  $QMAKER $QOPTIONS \""CONFIG += $BUILDTYPE $ENGINE\"" $PROJFILE" &>> $MAKELOG
   echo " " &>> $MAKELOG
   $QMAKER $QOPTIONS "CONFIG += $BUILDTYPE $ENGINE" $PROJFILE &>> $MAKELOG
   echo " " &>> $MAKELOG
   echo "  $MAKER $MAKEOPTIONS &> $MAKELOG" &>> $MAKELOG
   echo " " &>> $MAKELOG
   $MAKER $MAKEOPTIONS &>> $MAKELOG
   echo "Read $MAKELOG for build details."
else
   echo "Commands to be run:"
   echo "  rm -f $MAKELOG"
   echo "  $QMAKER $QOPTIONS \""CONFIG += $BUILDTYPE $ENGINE\"" $PROJFILE"
   echo "  $MAKER $MAKEOPTIONS &> $MAKELOG"
   echo "  $MAKELOG will contain the build details."
fi

#******************************************************************************
# qbuild (Seq66)
#------------------------------------------------------------------------------
# vim: ts=3 sw=3 wm=4 et ft=sh
#------------------------------------------------------------------------------

