if [ "$SAGE_LOCAL" = "" ]; then
   echo >&2 "SAGE_LOCAL undefined ... exiting";
   echo >&2 "Maybe run 'sage -sh'?"
   exit 1
fi

cd src

# Nauty doesn't have an install target
# passing a prefix to configure is useless
./configure
if [ $? -ne 0 ]; then
   echo >&2 "Error configuring nauty."
   exit 1
fi

$MAKE
if [ $? -ne 0 ]; then
   echo >&2 "Error building nauty."
   exit 1
fi

# No install target so we resort to manual copy
echo >&2 "Copying nauty..."
for program in addedgeg amtog biplabg catg complg converseg copyg countg cubhamg deledgeg delptg directg dreadnaut dretodot dretog \
  genbg genbgL geng genquarticg genrang genspecialg gentourng gentreeg hamheuristic labelg linegraphg listg multig newedgeg \
  pickg planarg ranlabg shortg showg subdivideg twohamg vcolg watercluster2 NRswitchg;
do
  cp -p $program "$SAGE_LOCAL"/bin/$program
  if [ $? -ne 0 ]; then
   echo >&2 "Error installing nauty."
   exit 1
  fi
done
