# G.Landais (CDS)
# 03-apr-2020
# Manage erfa lib (IAU)
# erfa library is used by as4 for time conversion

PACKAGE = vizier.c.erfa
VERSION = @version@
PREFIX=@prefix@

PRODUCT=erfa
LIBDIR=$(PREFIX)/lib
INCDIR=$(PREFIX)/include
DATE=`date +%Y%m`

default: compile

clone:
	git clone https://github.com/liberfa/erfa.git

pull:
	(cd $(PRODUCT); git pull)

save:
	(rm -f $(PRODUCT).$(DATE).tar.gz; tar -cvf $(PRODUCT).$(DATE).tar $(PRODUCT) ; gzip $(PRODUCT).$(DATE).tar)

clean: save
	rm -rf $(PRODUCT)

init: clone
	(cd $(PRODUCT); libtoolize --force; aclocal; autoheader; automake --force-missing --add-missing; autoconf)

compile: init
	(cd $(PRODUCT); ./configure --prefix=$(PREFIX); make clean; make install)

install: 
	(cd $(PRODUCT); cp -p src/.libs/liberfa.a $(LIBDIR)/; cp -p src/erfa.h $(INCDIR)/; cp -p src/erfam.h $(INCDIR)/)

.POSIX:
.SILENT : cvs

cvs:
	echo "obscolete, use tag"
	exit
	d=`echo $(PWD)|sed 's/^.*\///g'`; \
	if test $$d = $(PACKAGE); then \
	   d=`cvs diff configure*|wc -l` ; \
	   if test $$d -eq 0; then \
	      v=`echo $(VERSION)|sed 's/\./_/g'` ; echo "version: V$$v"; \
	      cvs tag V$$v . ; \
	   else \
	      echo "****you must commit 'configure*' before" ; \
	   fi \
	fi

tag:
	d=`echo $(PWD)|sed 's/^.*\///g'`; \
	if test $$d = $(PACKAGE); then \
	   d=`git diff configure*|wc -l` ; \
	   if test $$d -eq 0; then \
	      v=`echo $(VERSION)|sed 's/\./_/g'` ; echo "version: V$$v"; \
	      git tag -f -a V$$v -m 'version $$v' ; git push --tags ; \
	   else \
	      echo "****you must commit 'configure*' before" ; \
	   fi \
   	fi 
