#!/bin/bash

GENERATED_FILE=$1
OUTPUT_FILE=$2

if [ ! -f $GENERATED_FILE ]; then
    cp $OUTPUT_FILE $GENERATED_FILE || exit 1
    echo "[PDF]: created $GENERATED_FILE; rebuild needed"
    exit 0
fi

diff $GENERATED_FILE $OUTPUT_FILE >/dev/null
FILE_CHANGED=$?

if [ $FILE_CHANGED = 1 ]; then
    cp $OUTPUT_FILE $GENERATED_FILE || exit 1
    echo "[PDF]: changes require a rebuild"
    exit 0
elif [ $FILE_CHANGED = 0 ]; then
    echo "[PDF]: no changes; no rebuild required"
    exit 0
fi    

