#!/bin/bash # check if inside git repository has_git=$(git rev-parse --is-inside-work-tree 2> /dev/null) # if we are in repository if [[ "$has_git" == "true" ]] then label=$(git describe --tags) # if we are not in repository, but an old version file exist elif test -f version.f90 then label=$(awk -F\' '/git_describe/{ print $2 }' version.f90) # not in a repository and no old version file else label="unknown" fi # write label into file version.f90.tmp cat version.f90.in | sed 's/unknown/'$label'/' > version.f90.tmp # check if a previous version.f90 file exists if test -f version.f90 ; then # version.f90 existing: check if new and previous files differ diff -wib version.f90.tmp version.f90 2> /dev/null > /dev/null if [ $? = 1 ] ; then # they differ: update file version.f90 mv version.f90.tmp version.f90 fi # do not update if files are the same (prevents useless recompilation) else # file version.f90 not existing: create one mv version.f90.tmp version.f90 fi