#!/bin/ksh
#__USAGE
##============================================================================
#@
#@  make4qnx:  Shell script that compiles 'WCD.EXE' on QNX 4.25.
#@
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##
##  o Compiles with the QNX Watcom 10.6 compiler, via the 'cc' interface.
##
##  o Leverages the 'Makefile.ncurses.gcc' file to do the work, but overrides
##    the makefile variables 'CC' and 'CFLAGS'. If this script were two lines,
##    it would be:
##
##        echo "/* */" > memory.h
##        make -f Makefile.ncurses.gcc CC='cc' CFLAGS='-wx -Ic3po -I.'  $*
##
##  USAGE:
##
##      make4qnx  [target]
##
##  WHERE  'target' is an optional "makefile" target.
##
##---------------------------------------------------------------------------
##
##  After compiling 'wcd.exe', do the following:
##
##  1) copy  wcd.exe  to your  $HOME/bin  directory.
##
##  2) Add the following function to the  $HOME/.kshrc  shell startup file:
##
##       function wcd
##       {
##           $HOME/bin/wcd.exe $*
##           . $HOME/bin/wcd.go
##       }
##
##  3) Start a new shell.
##
##============================================================================

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a dummy 'memory.h' file, if it doesn't exist.
# Why? So these files compile: wcd.c  stack.c  dosdir.c graphics.c wcddir.c
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fname=`basename $0`
grep  "^#@"     $0      # Print to stdout all lines that begin with "#@".

if [ ! -r memory.h ];  then
    echo "\n  o ${fname}: Creating dummy file 'memory.h'.\n"
    echo "/* The ${fname} script created this 'memory.h' file. */"  > memory.h
fi

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Now do the MAKE. Use the 'Makefile.ncurses.gcc' makefile.
# For MAKE to work, override two makefile variables, CC and CFLAG.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo "\n  o ${fname}: Performing ' MAKE $* ' (with Watcom 10.6 compiler).\n"

set -x
make -f Makefile.ncurses.gcc CC='cc' CFLAGS='-wx -Ic3po -I.'  $*
err=$?
set +x

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Provide Feedback about how the MAKE went (but not for 'make4qnx clean').
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ "$*" = "clean" ];  then  exit;  fi

if [ $err -gt 0 ];  then
    echo "\n  o ${fname}: ************ MAKE FAILED!! ************ \n"
else
    echo "\n  o ${fname}: ~~~~~~~~~~~~ MAKE Success ~~~~~~~~~~~~~ \n"
    if test -f wcd.exe;  then  ls -alF wcd.exe;  fi
    echo
fi
