#!/bin/bash

if [ -z "$1" ]
then
    echo "$0 must be called by Makefile only."
    exit 1
fi

TAG=$1
TMPTAG=/tmp/$(basename $TAG)

cat <<EOF > $TMPTAG
{- Automatically generated by $0. Do not modify. -}

{- PP

Copyright (C) 2015-2023 Christophe Delord

http://cdelord.fr/pp

This file is part of PP.

PP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PP.  If not, see <http://www.gnu.org/licenses/>.
-}

module Tag(describe) where

describe :: String
describe = "$(git describe --tags || awk '$1=="version:" { print $2 }' pp.cabal)"

EOF

diff -q $TMPTAG $TAG >/dev/null 2>&1 || cp $TMPTAG $TAG
