#++++++++++++++++
#.IDENTIFICATION Makefile
#.LANGUAGE       Make (makefile script)
#.AUTHOR         Francois Ochsenbein [CDS]
#.ENVIRONMENT    Unix
#.KEYWORDS
#.VERSION  1.0   20-Jul-1992
#.VERSION  1.1   21-Oct-1994: Use $MACHINE
#.VERSION  1.2   13-Dec-2005: Standardized
#.PURPOSE        (Re)Create dependent files in this Directory
#.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  = /ftp/sw/cdspack_x86_64/src
PACKAGE = vizier.c.tex
VERSION = 2.4
DISTRIB = $(PACKAGE)-$(VERSION)
#################################################################

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

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

# PROGRAMS      --------------------------------
#        Possible alternatives are commented out.
CC     = gcc
RANLIB = ranlib
STRIP  = strip
COPY   = cp -p
RM     = rm -f
AWK    = gawk
TEXMAN = texroff          # Transform .tex into Roff

# C options     --------------------------------
DEBUG = -O
C_OPT = 
SYS =
CFLAGS = $(C_OPT) $(DEBUG) $(SYS) -I.

# Files:
UTILS   = buffer.c error.c hash.c str1.c osc.c
PGMS    = texroff tex2a
DEF     = texroff.def
TEX     = texroff.tex manpage.tex
MAN     = texroff.1
VERFILE = $(PREFIX)/versions

EXPORT  = tex2a.c tex.c atex.c texroff.c $(UTILS) $(TEX) $(MAN) *.h texroff.def

# Rules
.SUFFIXES: .o .c .tex .1
.c.o:
	$(CC) $(CFLAGS) -c $<
.tex.1:
	texroff $<

# DEPENDENCIES:
defaut: $(PGMS) $(MAN)

tex2a:	tex2a.c tex.c atex.c $(UTILS)
	$(CC) $(CFLAGS) $@.c tex.c atex.c $(UTILS) -o $@
	$(STRIP) $@

texroff: texroff.c
	$(CC) $(CFLAGS) -Ddef='"'$(BINDIR)/$@'"' \
	  texroff.c tex.c atex.c $(UTILS) -o $@
	$(STRIP) $@

texroff.1: texroff.tex
	texroff texroff > $@

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

install: install_pgm install_man install_info

install_pgm: $(PGMS) $(DEF)
	$(COPY) $(PGMS) $(DEF) $(BINDIR)

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

install_info:
	touch $(VERFILE)
	v=`grep -w '$(PACKAGE)' $(VERFILE) |wc -l` ; \
	if test $$v -eq 0 ; then \
	  echo "$(PACKAGE):V$(VERSION)">>$(VERFILE); \
	else \
	  sed "s/^\($(PACKAGE)\):V.*/\1:V$(VERSION)/g" $(VERFILE) >version.tmp;\
	  cat version.tmp > $(VERFILE); \
	  rm -f version.tmp; \
	fi

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

CLEAN:  clean

clean:
	$(RM) *.dvi *.ps *.aux *lis *.log *.o a.out core
	$(RM) $(PGMS)

export: /tmp/$(DISTRIB).tar

tar: /tmp/$(DISTRIB).tar


/tmp/$(DISTRIB).tar: $(EXPORT) Makefile.in
	$(MAKE) clean
	-test -d /tmp/$(DISTRIB) && rm -rf /tmp/$(DISTRIB)
	autoconf
	mkdir /tmp/$(DISTRIB)
	cp -p $(EXPORT) /tmp/$(DISTRIB)
	cp -p Makefile.in configure /tmp/$(DISTRIB)
	cd /tmp && tar cf $@ $(DISTRIB)
	rm -rf /tmp/$(DISTRIB)
	gzip -v9 $@


.POSIX:
.SILENT : cvs

cvs:
	echo "obscolete, use tag"
	exit
	d=`echo $(PWD)|sed 's/^.*\///g'`; \
	if test $$d = "tex"; 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 
