#++++++++++++++++
#.IDENTIFICATION Makefile.src
#.LANGUAGE       Make (makefile script)
#.AUTHOR         Francois Ochsenbein [CDS]
#.ENVIRONMENT    Unix
#.KEYWORDS       
#.VERSION  1.0   03-Oct-1991
#.VERSION  1.1   31-Oct-2003: with Configure
#.PURPOSE        Template Makefile for Portable Packages
#       The "install" option in the Makefile copies the executables and
#       man pages to public directories. Just edit the Makefile, and modify
#       the definitions according to your installation.
#       Some alternatives are proposed as comments.
#.COMMENTS       
#----------------

SHELL=/bin/sh
# ------------------------------------------
# DIRECTORIES (SHSDIR for Shell Scripts)
#   We assume here a general installation;
#   other choice may e.g. be
#################################################################
# For a system-wide installation, suggested to use /usr/local
# For your own installation, we propose your ~/lib ~/bin ~/man ..
#    i.e.  run ./configure -prefix=$HOME
#################################################################
#PREFIX  = /usr/local
#PREFIX  = $(HOME)
PREFIX  = @prefix@
PACKAGE = viier.c.acut
VERSION = @version@
DISTRIB = $(PACKAGE)-$(VERSION)
#################################################################

INCDIR  = $(PREFIX)/include
LIBDIR  = $(PREFIX)/lib
BINDIR  = $(PREFIX)/bin
SHSDIR  = $(PREFIX)/bin
MANDIR  = $(PREFIX)/man
EXPORT_CVS_OPT = @EXPORT_CVS_OPT@

###########
# NOTE: The definition below is required only on SOLARIS
#       Comment the following line if required
###########
#LIBSYS  = -lsocket -lnsl
LIBSYS = @LIBS@ -lm

# PROGRAMS	--------------------------------
#	 Possible alternatives are commented out.
CC     = @CC@ @cc_opt@
RANLIB = @RANLIB@
STRIP  = @STRIP@
COPY   = cp -p
RM     = rm
int4   = @int4@
int8   = @int8@
AWK    = @AWK@
TEXMAN = texroff          # Transform .tex into Roff

# C options	--------------------------------
DEBUG = -O
C_OPT = -Dint8="$(int8)" -Dint4="$(int4)"
SYS = 
CFLAGS = $(C_OPT) $(DEBUG) $(SYS) -I.

# FILES		--------------------------------
VERFILE = $(PREFIX)/versions
BIN = acut trcol reformat trim
SRC = acut.c trcol.c reformat.c trim.c regexp.h
SHS = reshape
MAN = acut.1 trcol.1 reformat.1 trim.1 \
      acut.tex man.tex reformat.tex trcol.tex trim.tex

# RULES		--------------------------------
.SUFFIXES: .o .c 
.c.o:
	$(CC) $(CFLAGS) -c $<
.SUFFIXES: .tex .1
.tex.1:
	$(TEXMAN) $< > $@
.tex.3:
	$(TEXMAN) $< > $@

# DEPENDENCIES	--------------------------------

default: $(BIN) $(MAN)

acut: acut.c
	$(CC) $(CFLAGS) acut.c -o $@ -lm
	$(STRIP) $@

trcol: trcol.c
	$(CC) $(CFLAGS) trcol.c -o $@
	$(STRIP) $@

reformat: reformat.c
	$(CC) $(CFLAGS) reformat.c -o $@
	$(STRIP) $@

trim: trim.c
	$(CC) $(CFLAGS) trim.c -o $@
	$(STRIP) $@

#################################################################
#  	Install the sw
#################################################################

install: install_bin install_man install_shs install_info

install_bin: $(BIN)
	test -d $(BINDIR) || mkdir $(BINDIR)
	$(COPY) $(BIN) $(BINDIR)

install_shs: $(SHS)
	test -d $(SHSDIR) || mkdir $(SHSDIR)
	$(COPY) $(SHS) $(SHSDIR)

install_man: $(MAN)
	test -d $(MANDIR) || mkdir $(MANDIR)
	for f in $? ; do \
	    mandir=$(MANDIR)/man`echo $$f | cut -d. -f2`; \
	    $(COPY) $(MAN) $(MANDIR)/man`echo $$f | cut -d. -f2`; \
	done

install_info:
	touch $(VERFILE)
	(cat $(VERFILE); echo  "$(PACKAGE):V$(VERSION)"; \
	 for  f in $(BIN); do \
	 ./$$f -version | $(AWK) '{printf "-%s:%s\n", $$1, $$NF}'; done ) \
	| $(AWK) -F: '{n++; P[n]=$$1; V[$$1]=$$2}END{for(i=1;i<=n;i++) { \
	  p=P[i]; v=V[p]; if(v!="") print p ":" v; V[p]="" }}' > version.tmp
	test -s version.tmp && cat version.tmp > $(VERFILE) \
	    && rm -f version.tmp 

#################################################################
#  	Clean and Export
#################################################################

clean:
	rm -f *.o *.log *.aux *.dvi *.lis .*.swp *.ps a.out core
	rm -f $(BIN)

export: /tmp/$(DISTRIB).tar

tar: /tmp/$(DISTRIB).tar

export_licence:
	cvs $(EXPORT_CVS_OPT) co -p vizier/cdsclient/COPYING >COPYING
	cvs $(EXPORT_CVS_OPT) co -p vizier/cdsclient/add_license >add_license
	chmod +x add_license

#	cp -p $(SRC) $(INC) $(MAN) $(SHS) /tmp/$(DISTRIB)
#	cp -p Makefile.in configure /tmp/$(DISTRIB)
/tmp/$(DISTRIB).tar: export_licence $(SRC) $(SHS) Makefile.in *.c
	$(MAKE) clean
	-test -d /tmp/$(DISTRIB) && rm -rf /tmp/$(DISTRIB)
	autoconf
	mkdir /tmp/$(DISTRIB)
	cp -p COPYRIGHT COPYING /tmp/$(DISTRIB)
	for f in $(SRC) $(INC) $(MAN) $(SHS) Makefile.in configure ; do \
	    cp -p $$f /tmp/$(DISTRIB); \
	    add_license $$f > /tmp/$(DISTRIB)/$$f; done
	rm -f /tmp/$(DISTRIB)/add_license
	cd /tmp && tar cf $@ $(DISTRIB)
	rm -rf /tmp/$(DISTRIB)
	gzip -v9 $@


.POSIX:
.SILENT : cvs

cvs:
	echo "OBSOLETE , use git"
	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 

git:
	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"; \
	      git tag -a V$$v -m 'version $$v' ; git push --tags \
	   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 
