#!/bin/sh

## Initialisation
##---------------

## latekmk options
opts='-shell-escape -quiet'

## Default selection for models
if   [ "$1" = 'all' ]; then
	models='NEMO SI3 TOP'
elif [ "$1" =    '' ]; then
	models='NEMO'
else
	models=$*
fi

## Avoid the use of shell builtin echo (for -e option)
alias echo='/bin/echo -e'

# Source shared functions
. tools/shr_func.sh


## Check dependancies
##-------------------

## LaTeX installation, find latexmk should be enough
[ -z $( which latexmk ) ] && { echo 'latexmk binary is not present => QUIT'; exit 2; }

## Retrieve figures if not already there
if [ ! -d latex/figures ]; then
	echo "Downloading of shared figures and logos\n"
	svn co https://forge.ipsl.jussieu.fr/nemo/svn/utils/figures latex/figures > /dev/null
fi

## Pygments package for syntax highlighting of source code (namelists & snippets)
[ -n "$( ./tools/check_pkg.py pygments )" ] && { exit 2; }


## Loop on the models
##-------------------

for model in $models; do
	echo $model"\n"
	clean $model; build $model
	echo "\t"'¤ End of build run'
	echo "\t\t"'The export should be available at root'
	echo "\t\t"'If not check LaTeX log in ./latex/'$model'/main/'$model'_manual.log'"\n"
done

exit 0
