#! /bin/sh 
#
# BUILD SCRIPT v2.0: 
#
# This is a bootstrap builder to build the amc tool.
# It requires either bash or korn shell. 
#
#
#

PRGNAME=amc

echo "Building AMC (Build v2.0;${PRGNAME})"

PATH=$PATH:.
export PATH

if [ ! -f defaults ]
then
   setup.script
fi

. defaults

#############################################################################
# Build all the subsystems                                                  #
#############################################################################

if [ x"${1}" = x ]; then    # Use default list of subsystems
  SUBSYSTEMS="compile corelib error files hash main "
  SUBSYSTEMS="${SUBSYSTEMS} native parse project system"  
  SUBSYSTEMS="${SUBSYSTEMS} ldbm cgl"
  DOLINK=yes
else
  SUBSYSTEMS="$*"
  DOLINK=no
fi

#############################################################################

rm -rf ${BINLOC}/*.o 2>/dev/null

for i in ${SUBSYSTEMS}; 
do
  echo "------------------------ Making ${i} ------------------------"
  cd ${SRCLOC}/${i}
  if ${MAKE} ${MAKEFLAGS} all; then
   echo "*** ${i} compiled ok."
  else
   echo "*** ${i} failed compilation."
   exit 1
  fi
done

echo "------------------------ Linking ${PRGNAME} ------------------------"
 cd ${BINLOC}
 
 chmod 644 *.o  # HP-UX has a wierd effect of chmod 0 sometimes..
 if [ ${DOLINK} = "yes" ]; then
   ${LINKER} -o ${PRGNAME} *.o ${LINKSFX} #../libefence.a
   if [ -f ${PRGNAME} ]; then
     echo "Built:"
     ls -l ${PRGNAME}
   else
     echo
     echo "*** Build failed."
   fi
 else
  echo "*** Linking deferred (not all subsystems built)"
 fi

exit 1
