#!/bin/sh

set -e

CG=${CG:-cargo}
CGFLAGS=${CGFLAGS:-'--release'}
SCDOC=${SCDOC:-scdoc}
CGOUT=${CGOUT:-'./target/release/stargazer'}
STRIP=${STRIP:-strip}

# Build stargazer
if [ -z $NO_AUDIT ]; then
	$CG auditable build $CGFLAGS
else
	$CG build $CGFLAGS
fi

if command -v "$STRIP" &> /dev/null; then
	"$STRIP" -s "$CGOUT"
else
	1>&2 echo 'Warning: strip not install - binary not striped'
fi

# Build docs
if command -v "$SCDOC" &> /dev/null; then
	$SCDOC < ./doc/stargazer.scd > stargazer.1
	$SCDOC < ./doc/stargazer-ini.scd > stargazer.ini.5
else
	1>&2 echo 'Warning: scdoc not install - man pages not generated'
fi
