# G.Landais (CDS)
# 03-apr-2020
# Manage unity lib (Norman Gray): https://code.nxg.name/nxg/unity
# unity library is used by as4 for cds-vo units conversion

PACKAGE = vizier.c.unity
VERSION = 1.1
PREFIX=/ftp/sw/cdspack_x86_64/src

UNITY_VERSION = 1.0
PRODUCT=unity-${UNITY_VERSION}
LIBDIR=$(PREFIX)/lib
INCDIR=$(PREFIX)/include

default: compile

clone:
	wget "https://code.nxg.name/nxg/downloads/unity-${UNITY_VERSION}.tar.gz"

detar:
	tar -xzvf unity-${UNITY_VERSION}.tar.gz

clean: 
	rm -rf $(PRODUCT)


prepare_makefile:
	(cd $(PRODUCT); mv Makefile.in Makefile.in.ori; sed 's/^LANGS=.*/LANGS=src\/c/g' Makefile.in.ori >Makefile.in)
#	(cd $(PRODUCT)/src/c; mv Makefile.in Makefile.in.ori; sed 's/\t\(.*unity.o -L. -lunity -lm\)/\techo "\1"/g' Makefile.in.ori >Makefile.in)


compile: clean detar prepare_makefile
	(cd $(PRODUCT); export CFLAGS="-fPIC -fcommon"; ./configure --prefix=$(PREFIX); make )

install: 
	(cd $(PRODUCT); export CFLAGS=-fPIC; make install)
	(cd $(PRODUCT); cp -p src/c/unity.h $(INCDIR)/)

.POSIX:

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 
